@decaf-ts/for-couchdb 0.10.0 → 0.11.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/adapter.cjs +38 -32
- package/lib/cjs/adapter.cjs.map +1 -0
- package/lib/cjs/constants.cjs +1 -0
- package/lib/cjs/constants.cjs.map +1 -0
- package/lib/cjs/decorators.cjs +1 -0
- package/lib/cjs/decorators.cjs.map +1 -0
- package/lib/cjs/errors.cjs +1 -0
- package/lib/cjs/errors.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/indexes/generator.cjs +17 -16
- package/lib/cjs/indexes/generator.cjs.map +1 -0
- package/lib/cjs/indexes/index.cjs +1 -0
- package/lib/cjs/indexes/index.cjs.map +1 -0
- package/lib/cjs/metadata.cjs +1 -0
- package/lib/cjs/metadata.cjs.map +1 -0
- package/lib/cjs/query/Paginator.cjs +1 -0
- package/lib/cjs/query/Paginator.cjs.map +1 -0
- package/lib/cjs/query/Statement.cjs +37 -36
- package/lib/cjs/query/Statement.cjs.map +1 -0
- package/lib/cjs/query/constants.cjs +1 -0
- package/lib/cjs/query/constants.cjs.map +1 -0
- package/lib/cjs/query/index.cjs +1 -0
- package/lib/cjs/query/index.cjs.map +1 -0
- package/lib/cjs/query/translate.cjs +3 -2
- package/lib/cjs/query/translate.cjs.map +1 -0
- package/lib/cjs/repository.cjs +8 -7
- package/lib/cjs/repository.cjs.map +1 -0
- package/lib/cjs/types.cjs +1 -0
- package/lib/cjs/types.cjs.map +1 -0
- package/lib/cjs/utils.cjs +9 -8
- package/lib/cjs/utils.cjs.map +1 -0
- package/lib/cjs/views/generator.cjs +9 -8
- package/lib/cjs/views/generator.cjs.map +1 -0
- package/lib/cjs/views/index.cjs +1 -0
- package/lib/cjs/views/index.cjs.map +1 -0
- package/lib/cjs/views/types.cjs +1 -0
- package/lib/cjs/views/types.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/adapter.d.cts +296 -0
- package/lib/types/adapter.d.mts +296 -0
- package/lib/types/constants.d.cts +42 -0
- package/lib/types/constants.d.mts +42 -0
- package/lib/types/decorators.d.cts +8 -0
- package/lib/types/decorators.d.mts +8 -0
- package/lib/types/errors.d.cts +21 -0
- package/lib/types/errors.d.mts +21 -0
- package/lib/types/index.d.cts +28 -0
- package/lib/types/index.d.mts +28 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/indexes/generator.d.cts +51 -0
- package/lib/types/indexes/generator.d.mts +51 -0
- package/lib/types/indexes/index.d.cts +1 -0
- package/lib/types/indexes/index.d.mts +1 -0
- package/lib/types/metadata.d.cts +4 -0
- package/lib/types/metadata.d.mts +4 -0
- package/lib/types/query/Paginator.d.cts +105 -0
- package/lib/types/query/Paginator.d.mts +105 -0
- package/lib/types/query/Statement.d.cts +195 -0
- package/lib/types/query/Statement.d.mts +195 -0
- package/lib/types/query/constants.d.cts +47 -0
- package/lib/types/query/constants.d.mts +47 -0
- package/lib/types/query/index.d.cts +4 -0
- package/lib/types/query/index.d.mts +4 -0
- package/lib/types/query/translate.d.cts +34 -0
- package/lib/types/query/translate.d.mts +34 -0
- package/lib/types/repository.d.cts +39 -0
- package/lib/types/repository.d.mts +39 -0
- package/lib/types/types.d.cts +166 -0
- package/lib/types/types.d.mts +166 -0
- package/lib/types/utils.d.cts +112 -0
- package/lib/types/utils.d.mts +112 -0
- package/lib/types/views/generator.d.cts +13 -0
- package/lib/types/views/generator.d.mts +13 -0
- package/lib/types/views/index.d.cts +2 -0
- package/lib/types/views/index.d.mts +2 -0
- package/lib/types/views/types.d.cts +30 -0
- package/lib/types/views/types.d.mts +30 -0
- package/package.json +4 -4
- package/lib/cjs/adapter.js.map +0 -1
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/decorators.js.map +0 -1
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/indexes/generator.js.map +0 -1
- package/lib/cjs/indexes/index.js.map +0 -1
- package/lib/cjs/metadata.js.map +0 -1
- package/lib/cjs/query/Paginator.js.map +0 -1
- package/lib/cjs/query/Statement.js.map +0 -1
- package/lib/cjs/query/constants.js.map +0 -1
- package/lib/cjs/query/index.js.map +0 -1
- package/lib/cjs/query/translate.js.map +0 -1
- package/lib/cjs/repository.js.map +0 -1
- package/lib/cjs/types.js.map +0 -1
- package/lib/cjs/utils.js.map +0 -1
- package/lib/cjs/views/generator.js.map +0 -1
- package/lib/cjs/views/index.js.map +0 -1
- package/lib/cjs/views/types.js.map +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Condition } from "@decaf-ts/core";
|
|
2
|
+
import { AggregateOptions, CouchDBViewOptions } from "./views/index.cjs";
|
|
3
|
+
export declare function groupBy(compositionsOrOptions?: string[] | string | CouchDBViewOptions, nameOrOptions?: string | CouchDBViewOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
4
|
+
export declare function count(valueOrCondition?: any | Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
5
|
+
export declare function sum(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
6
|
+
export declare function max(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
7
|
+
export declare function min(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
8
|
+
export declare function distinct(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Condition } from "@decaf-ts/core";
|
|
2
|
+
import { AggregateOptions, CouchDBViewOptions } from "./views/index.js";
|
|
3
|
+
export declare function groupBy(compositionsOrOptions?: string[] | string | CouchDBViewOptions, nameOrOptions?: string | CouchDBViewOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
4
|
+
export declare function count(valueOrCondition?: any | Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
5
|
+
export declare function sum(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
6
|
+
export declare function max(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
7
|
+
export declare function min(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
8
|
+
export declare function distinct(conditionOrOptions?: Condition<any> | AggregateOptions, options?: AggregateOptions): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
2
|
+
/**
|
|
3
|
+
* @description Error thrown when there is an issue with CouchDB indexes
|
|
4
|
+
* @summary Represents an error related to CouchDB index operations
|
|
5
|
+
* @param {string|Error} msg - The error message or Error object
|
|
6
|
+
* @class
|
|
7
|
+
* @category Errors
|
|
8
|
+
* @example
|
|
9
|
+
* // Example of using IndexError
|
|
10
|
+
* try {
|
|
11
|
+
* // Some code that might throw an index error
|
|
12
|
+
* throw new IndexError("Index not found");
|
|
13
|
+
* } catch (error) {
|
|
14
|
+
* if (error instanceof IndexError) {
|
|
15
|
+
* console.error("Index error occurred:", error.message);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare class IndexError extends BaseError {
|
|
20
|
+
constructor(msg: string | Error);
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
2
|
+
/**
|
|
3
|
+
* @description Error thrown when there is an issue with CouchDB indexes
|
|
4
|
+
* @summary Represents an error related to CouchDB index operations
|
|
5
|
+
* @param {string|Error} msg - The error message or Error object
|
|
6
|
+
* @class
|
|
7
|
+
* @category Errors
|
|
8
|
+
* @example
|
|
9
|
+
* // Example of using IndexError
|
|
10
|
+
* try {
|
|
11
|
+
* // Some code that might throw an index error
|
|
12
|
+
* throw new IndexError("Index not found");
|
|
13
|
+
* } catch (error) {
|
|
14
|
+
* if (error instanceof IndexError) {
|
|
15
|
+
* console.error("Index error occurred:", error.message);
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare class IndexError extends BaseError {
|
|
20
|
+
constructor(msg: string | Error);
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from "./indexes/index.cjs";
|
|
2
|
+
export * from "./repository.cjs";
|
|
3
|
+
export * from "./adapter.cjs";
|
|
4
|
+
export * from "./constants.cjs";
|
|
5
|
+
export * from "./errors.cjs";
|
|
6
|
+
export * from "./metadata.cjs";
|
|
7
|
+
export * from "./decorators.cjs";
|
|
8
|
+
export * from "./types.cjs";
|
|
9
|
+
export * from "./utils.cjs";
|
|
10
|
+
export * from "./query/index.cjs";
|
|
11
|
+
export * from "./views/index.cjs";
|
|
12
|
+
/**
|
|
13
|
+
* @description CouchDB adapter for Decaf.ts
|
|
14
|
+
* @summary A TypeScript adapter for CouchDB database operations, providing a seamless integration with the Decaf.ts framework. This module includes classes, interfaces, and utilities for working with CouchDB databases, including support for Mango queries, document operations, and sequence management.
|
|
15
|
+
* @module for-couchdb
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @description Stores the current package version
|
|
19
|
+
* @summary The version string of the for-couchdb package
|
|
20
|
+
* @const VERSION
|
|
21
|
+
*/
|
|
22
|
+
export declare const VERSION = "0.10.0";
|
|
23
|
+
/**
|
|
24
|
+
* @description Stores the current package name
|
|
25
|
+
* @summary The version string of the for-couchdb package
|
|
26
|
+
* @const PACKAGE_NAME
|
|
27
|
+
*/
|
|
28
|
+
export declare const PACKAGE_NAME = "@decaf-ts/for-couchdb";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from "./indexes/index.js";
|
|
2
|
+
export * from "./repository.js";
|
|
3
|
+
export * from "./adapter.js";
|
|
4
|
+
export * from "./constants.js";
|
|
5
|
+
export * from "./errors.js";
|
|
6
|
+
export * from "./metadata.js";
|
|
7
|
+
export * from "./decorators.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./utils.js";
|
|
10
|
+
export * from "./query/index.js";
|
|
11
|
+
export * from "./views/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* @description CouchDB adapter for Decaf.ts
|
|
14
|
+
* @summary A TypeScript adapter for CouchDB database operations, providing a seamless integration with the Decaf.ts framework. This module includes classes, interfaces, and utilities for working with CouchDB databases, including support for Mango queries, document operations, and sequence management.
|
|
15
|
+
* @module for-couchdb
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* @description Stores the current package version
|
|
19
|
+
* @summary The version string of the for-couchdb package
|
|
20
|
+
* @const VERSION
|
|
21
|
+
*/
|
|
22
|
+
export declare const VERSION = "0.10.0";
|
|
23
|
+
/**
|
|
24
|
+
* @description Stores the current package name
|
|
25
|
+
* @summary The version string of the for-couchdb package
|
|
26
|
+
* @const PACKAGE_NAME
|
|
27
|
+
*/
|
|
28
|
+
export declare const PACKAGE_NAME = "@decaf-ts/for-couchdb";
|
package/lib/types/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export * from "./views";
|
|
|
19
19
|
* @summary The version string of the for-couchdb package
|
|
20
20
|
* @const VERSION
|
|
21
21
|
*/
|
|
22
|
-
export declare const VERSION = "0.
|
|
22
|
+
export declare const VERSION = "0.10.0";
|
|
23
23
|
/**
|
|
24
24
|
* @description Stores the current package name
|
|
25
25
|
* @summary The version string of the for-couchdb package
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { CreateIndexRequest } from "../types.cjs";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
/**
|
|
5
|
+
* @description Generates CouchDB index configurations for models
|
|
6
|
+
* @summary Creates a set of CouchDB index configurations based on the metadata of the provided models
|
|
7
|
+
* @template M - The model type that extends Model
|
|
8
|
+
* @param models - Array of model constructors to generate indexes for
|
|
9
|
+
* @return {CreateIndexRequest[]} Array of CouchDB index configurations
|
|
10
|
+
* @function generateIndexes
|
|
11
|
+
* @memberOf module:for-couchdb
|
|
12
|
+
* @mermaid
|
|
13
|
+
* sequenceDiagram
|
|
14
|
+
* participant Caller
|
|
15
|
+
* participant generateIndexes
|
|
16
|
+
* participant generateIndexName
|
|
17
|
+
* participant Repository
|
|
18
|
+
*
|
|
19
|
+
* Caller->>generateIndexes: models
|
|
20
|
+
*
|
|
21
|
+
* Note over generateIndexes: Create base table index
|
|
22
|
+
* generateIndexes->>generateIndexName: [CouchDBKeys.TABLE]
|
|
23
|
+
* generateIndexName-->>generateIndexes: tableName
|
|
24
|
+
* generateIndexes->>generateIndexes: Create table index config
|
|
25
|
+
*
|
|
26
|
+
* loop For each model
|
|
27
|
+
* generateIndexes->>Repository: Get indexes metadata
|
|
28
|
+
* Repository-->>generateIndexes: index metadata
|
|
29
|
+
*
|
|
30
|
+
* loop For each index in metadata
|
|
31
|
+
* Note over generateIndexes: Extract index properties
|
|
32
|
+
* generateIndexes->>Repository: Get table name
|
|
33
|
+
* Repository-->>generateIndexes: tableName
|
|
34
|
+
*
|
|
35
|
+
* Note over generateIndexes: Define nested generate function
|
|
36
|
+
*
|
|
37
|
+
* generateIndexes->>generateIndexes: Call generate() for default order
|
|
38
|
+
* Note over generateIndexes: Create index name and config
|
|
39
|
+
*
|
|
40
|
+
* alt Has directions
|
|
41
|
+
* loop For each direction
|
|
42
|
+
* generateIndexes->>generateIndexes: Call generate(direction)
|
|
43
|
+
* Note over generateIndexes: Create ordered index config
|
|
44
|
+
* end
|
|
45
|
+
* end
|
|
46
|
+
* end
|
|
47
|
+
* end
|
|
48
|
+
*
|
|
49
|
+
* generateIndexes-->>Caller: Array of index configurations
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateIndexes<M extends Model>(models: Constructor<M>[]): CreateIndexRequest[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { CreateIndexRequest } from "../types.js";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
/**
|
|
5
|
+
* @description Generates CouchDB index configurations for models
|
|
6
|
+
* @summary Creates a set of CouchDB index configurations based on the metadata of the provided models
|
|
7
|
+
* @template M - The model type that extends Model
|
|
8
|
+
* @param models - Array of model constructors to generate indexes for
|
|
9
|
+
* @return {CreateIndexRequest[]} Array of CouchDB index configurations
|
|
10
|
+
* @function generateIndexes
|
|
11
|
+
* @memberOf module:for-couchdb
|
|
12
|
+
* @mermaid
|
|
13
|
+
* sequenceDiagram
|
|
14
|
+
* participant Caller
|
|
15
|
+
* participant generateIndexes
|
|
16
|
+
* participant generateIndexName
|
|
17
|
+
* participant Repository
|
|
18
|
+
*
|
|
19
|
+
* Caller->>generateIndexes: models
|
|
20
|
+
*
|
|
21
|
+
* Note over generateIndexes: Create base table index
|
|
22
|
+
* generateIndexes->>generateIndexName: [CouchDBKeys.TABLE]
|
|
23
|
+
* generateIndexName-->>generateIndexes: tableName
|
|
24
|
+
* generateIndexes->>generateIndexes: Create table index config
|
|
25
|
+
*
|
|
26
|
+
* loop For each model
|
|
27
|
+
* generateIndexes->>Repository: Get indexes metadata
|
|
28
|
+
* Repository-->>generateIndexes: index metadata
|
|
29
|
+
*
|
|
30
|
+
* loop For each index in metadata
|
|
31
|
+
* Note over generateIndexes: Extract index properties
|
|
32
|
+
* generateIndexes->>Repository: Get table name
|
|
33
|
+
* Repository-->>generateIndexes: tableName
|
|
34
|
+
*
|
|
35
|
+
* Note over generateIndexes: Define nested generate function
|
|
36
|
+
*
|
|
37
|
+
* generateIndexes->>generateIndexes: Call generate() for default order
|
|
38
|
+
* Note over generateIndexes: Create index name and config
|
|
39
|
+
*
|
|
40
|
+
* alt Has directions
|
|
41
|
+
* loop For each direction
|
|
42
|
+
* generateIndexes->>generateIndexes: Call generate(direction)
|
|
43
|
+
* Note over generateIndexes: Create ordered index config
|
|
44
|
+
* end
|
|
45
|
+
* end
|
|
46
|
+
* end
|
|
47
|
+
* end
|
|
48
|
+
*
|
|
49
|
+
* generateIndexes-->>Caller: Array of index configurations
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateIndexes<M extends Model>(models: Constructor<M>[]): CreateIndexRequest[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generator.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generator.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
export declare function setMetadata<M extends Model>(model: M, metadata: any): void;
|
|
3
|
+
export declare function getMetadata<M extends Model>(model: M): any;
|
|
4
|
+
export declare function removeMetadata<M extends Model>(model: M): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
+
export declare function setMetadata<M extends Model>(model: M, metadata: any): void;
|
|
3
|
+
export declare function getMetadata<M extends Model>(model: M): any;
|
|
4
|
+
export declare function removeMetadata<M extends Model>(model: M): void;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { MaybeContextualArg, Paginator } from "@decaf-ts/core";
|
|
2
|
+
import { MangoQuery } from "../types.cjs";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { CouchDBAdapter } from "../adapter.cjs";
|
|
5
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
+
/**
|
|
7
|
+
* @description Paginator for ConuchDB query results
|
|
8
|
+
* @summary Implements pagination for CouchDB queries using bookmarks for efficient navigation through result sets
|
|
9
|
+
* @template M - The model type that extends Model
|
|
10
|
+
* @template R - The result type
|
|
11
|
+
* @param {CouchDBAdapter<any, any, any>} adapter - The CouchDB adapter
|
|
12
|
+
* @param {MangoQuery} query - The Mango query to paginate
|
|
13
|
+
* @param {number} size - The page size
|
|
14
|
+
* @param {Constructor<M>} clazz - The model constructor
|
|
15
|
+
* @class CouchDBPaginator
|
|
16
|
+
* @example
|
|
17
|
+
* // Example of using CouchDBPaginator
|
|
18
|
+
* const adapter = new MyCouchDBAdapter(scope);
|
|
19
|
+
* const query = { selector: { type: "user" } };
|
|
20
|
+
* const paginator = new CouchDBPaginator(adapter, query, 10, User);
|
|
21
|
+
*
|
|
22
|
+
* // Get the first page
|
|
23
|
+
* const page1 = await paginator.page(1);
|
|
24
|
+
*
|
|
25
|
+
* // Get the next page
|
|
26
|
+
* const page2 = await paginator.page(2);
|
|
27
|
+
*/
|
|
28
|
+
export declare class CouchDBPaginator<M extends Model> extends Paginator<M, M[], MangoQuery> {
|
|
29
|
+
/**
|
|
30
|
+
* @description Creates a new CouchDBPaginator instance
|
|
31
|
+
* @summary Initializes a paginator for CouchDB query results
|
|
32
|
+
* @param {CouchDBAdapter<any, any, any, any>} adapter - The CouchDB adapter
|
|
33
|
+
* @param {MangoQuery} query - The Mango query to paginate
|
|
34
|
+
* @param {number} size - The page size
|
|
35
|
+
* @param {Constructor<M>} clazz - The model constructor
|
|
36
|
+
*/
|
|
37
|
+
constructor(adapter: CouchDBAdapter<any, any, any>, query: MangoQuery, size: number, clazz: Constructor<M>);
|
|
38
|
+
/**
|
|
39
|
+
* @description Prepares a query for pagination
|
|
40
|
+
* @summary Modifies the raw query to include pagination parameters
|
|
41
|
+
* @param {MangoQuery} rawStatement - The original Mango query
|
|
42
|
+
* @return {MangoQuery} The prepared query with pagination parameters
|
|
43
|
+
*/
|
|
44
|
+
protected prepare(rawStatement: MangoQuery): MangoQuery;
|
|
45
|
+
/**
|
|
46
|
+
* @description Retrieves a specific page of results
|
|
47
|
+
* @summary Executes the query with pagination and processes the results
|
|
48
|
+
* @param {number} [page=1] - The page number to retrieve
|
|
49
|
+
* @return {Promise<R[]>} A promise that resolves to an array of results
|
|
50
|
+
* @throws {PagingError} If trying to access a page other than the first without a bookmark, or if no class is defined
|
|
51
|
+
* @mermaid
|
|
52
|
+
* sequenceDiagram
|
|
53
|
+
* participant Client
|
|
54
|
+
* participant CouchDBPaginator
|
|
55
|
+
* participant Adapter
|
|
56
|
+
* participant CouchDB
|
|
57
|
+
*
|
|
58
|
+
* Client->>CouchDBPaginator: page(pageNumber)
|
|
59
|
+
* Note over CouchDBPaginator: Clone statement
|
|
60
|
+
* CouchDBPaginator->>CouchDBPaginator: validatePage(page)
|
|
61
|
+
*
|
|
62
|
+
* alt page !== 1
|
|
63
|
+
* CouchDBPaginator->>CouchDBPaginator: Check bookmark
|
|
64
|
+
* alt No bookmark
|
|
65
|
+
* CouchDBPaginator-->>Client: Throw PagingError
|
|
66
|
+
* else Has bookmark
|
|
67
|
+
* CouchDBPaginator->>CouchDBPaginator: Add bookmark to statement
|
|
68
|
+
* end
|
|
69
|
+
* end
|
|
70
|
+
*
|
|
71
|
+
* CouchDBPaginator->>Adapter: raw(statement, false)
|
|
72
|
+
* Adapter->>CouchDB: Execute query
|
|
73
|
+
* CouchDB-->>Adapter: Return results
|
|
74
|
+
* Adapter-->>CouchDBPaginator: Return MangoResponse
|
|
75
|
+
*
|
|
76
|
+
* Note over CouchDBPaginator: Process results
|
|
77
|
+
*
|
|
78
|
+
* alt Has warning
|
|
79
|
+
* CouchDBPaginator->>CouchDBPaginator: Log warning
|
|
80
|
+
* end
|
|
81
|
+
*
|
|
82
|
+
* CouchDBPaginator->>CouchDBPaginator: Check for clazz
|
|
83
|
+
*
|
|
84
|
+
* alt No clazz
|
|
85
|
+
* CouchDBPaginator-->>Client: Throw PagingError
|
|
86
|
+
* else Has clazz
|
|
87
|
+
* CouchDBPaginator->>CouchDBPaginator: Find primary key
|
|
88
|
+
*
|
|
89
|
+
* alt Has fields in statement
|
|
90
|
+
* CouchDBPaginator->>CouchDBPaginator: Use docs directly
|
|
91
|
+
* else No fields
|
|
92
|
+
* CouchDBPaginator->>CouchDBPaginator: Process each document
|
|
93
|
+
* loop For each document
|
|
94
|
+
* CouchDBPaginator->>CouchDBPaginator: Extract original ID
|
|
95
|
+
* CouchDBPaginator->>Adapter: revert(doc, clazz, pkDef.id, parsedId)
|
|
96
|
+
* end
|
|
97
|
+
* end
|
|
98
|
+
*
|
|
99
|
+
* CouchDBPaginator->>CouchDBPaginator: Store bookmark
|
|
100
|
+
* CouchDBPaginator->>CouchDBPaginator: Update currentPage
|
|
101
|
+
* CouchDBPaginator-->>Client: Return results
|
|
102
|
+
* end
|
|
103
|
+
*/
|
|
104
|
+
page(page?: number | undefined, bookmark?: any, ...args: MaybeContextualArg<any>): Promise<M[]>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { MaybeContextualArg, Paginator } from "@decaf-ts/core";
|
|
2
|
+
import { MangoQuery } from "../types.js";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { CouchDBAdapter } from "../adapter.js";
|
|
5
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
+
/**
|
|
7
|
+
* @description Paginator for ConuchDB query results
|
|
8
|
+
* @summary Implements pagination for CouchDB queries using bookmarks for efficient navigation through result sets
|
|
9
|
+
* @template M - The model type that extends Model
|
|
10
|
+
* @template R - The result type
|
|
11
|
+
* @param {CouchDBAdapter<any, any, any>} adapter - The CouchDB adapter
|
|
12
|
+
* @param {MangoQuery} query - The Mango query to paginate
|
|
13
|
+
* @param {number} size - The page size
|
|
14
|
+
* @param {Constructor<M>} clazz - The model constructor
|
|
15
|
+
* @class CouchDBPaginator
|
|
16
|
+
* @example
|
|
17
|
+
* // Example of using CouchDBPaginator
|
|
18
|
+
* const adapter = new MyCouchDBAdapter(scope);
|
|
19
|
+
* const query = { selector: { type: "user" } };
|
|
20
|
+
* const paginator = new CouchDBPaginator(adapter, query, 10, User);
|
|
21
|
+
*
|
|
22
|
+
* // Get the first page
|
|
23
|
+
* const page1 = await paginator.page(1);
|
|
24
|
+
*
|
|
25
|
+
* // Get the next page
|
|
26
|
+
* const page2 = await paginator.page(2);
|
|
27
|
+
*/
|
|
28
|
+
export declare class CouchDBPaginator<M extends Model> extends Paginator<M, M[], MangoQuery> {
|
|
29
|
+
/**
|
|
30
|
+
* @description Creates a new CouchDBPaginator instance
|
|
31
|
+
* @summary Initializes a paginator for CouchDB query results
|
|
32
|
+
* @param {CouchDBAdapter<any, any, any, any>} adapter - The CouchDB adapter
|
|
33
|
+
* @param {MangoQuery} query - The Mango query to paginate
|
|
34
|
+
* @param {number} size - The page size
|
|
35
|
+
* @param {Constructor<M>} clazz - The model constructor
|
|
36
|
+
*/
|
|
37
|
+
constructor(adapter: CouchDBAdapter<any, any, any>, query: MangoQuery, size: number, clazz: Constructor<M>);
|
|
38
|
+
/**
|
|
39
|
+
* @description Prepares a query for pagination
|
|
40
|
+
* @summary Modifies the raw query to include pagination parameters
|
|
41
|
+
* @param {MangoQuery} rawStatement - The original Mango query
|
|
42
|
+
* @return {MangoQuery} The prepared query with pagination parameters
|
|
43
|
+
*/
|
|
44
|
+
protected prepare(rawStatement: MangoQuery): MangoQuery;
|
|
45
|
+
/**
|
|
46
|
+
* @description Retrieves a specific page of results
|
|
47
|
+
* @summary Executes the query with pagination and processes the results
|
|
48
|
+
* @param {number} [page=1] - The page number to retrieve
|
|
49
|
+
* @return {Promise<R[]>} A promise that resolves to an array of results
|
|
50
|
+
* @throws {PagingError} If trying to access a page other than the first without a bookmark, or if no class is defined
|
|
51
|
+
* @mermaid
|
|
52
|
+
* sequenceDiagram
|
|
53
|
+
* participant Client
|
|
54
|
+
* participant CouchDBPaginator
|
|
55
|
+
* participant Adapter
|
|
56
|
+
* participant CouchDB
|
|
57
|
+
*
|
|
58
|
+
* Client->>CouchDBPaginator: page(pageNumber)
|
|
59
|
+
* Note over CouchDBPaginator: Clone statement
|
|
60
|
+
* CouchDBPaginator->>CouchDBPaginator: validatePage(page)
|
|
61
|
+
*
|
|
62
|
+
* alt page !== 1
|
|
63
|
+
* CouchDBPaginator->>CouchDBPaginator: Check bookmark
|
|
64
|
+
* alt No bookmark
|
|
65
|
+
* CouchDBPaginator-->>Client: Throw PagingError
|
|
66
|
+
* else Has bookmark
|
|
67
|
+
* CouchDBPaginator->>CouchDBPaginator: Add bookmark to statement
|
|
68
|
+
* end
|
|
69
|
+
* end
|
|
70
|
+
*
|
|
71
|
+
* CouchDBPaginator->>Adapter: raw(statement, false)
|
|
72
|
+
* Adapter->>CouchDB: Execute query
|
|
73
|
+
* CouchDB-->>Adapter: Return results
|
|
74
|
+
* Adapter-->>CouchDBPaginator: Return MangoResponse
|
|
75
|
+
*
|
|
76
|
+
* Note over CouchDBPaginator: Process results
|
|
77
|
+
*
|
|
78
|
+
* alt Has warning
|
|
79
|
+
* CouchDBPaginator->>CouchDBPaginator: Log warning
|
|
80
|
+
* end
|
|
81
|
+
*
|
|
82
|
+
* CouchDBPaginator->>CouchDBPaginator: Check for clazz
|
|
83
|
+
*
|
|
84
|
+
* alt No clazz
|
|
85
|
+
* CouchDBPaginator-->>Client: Throw PagingError
|
|
86
|
+
* else Has clazz
|
|
87
|
+
* CouchDBPaginator->>CouchDBPaginator: Find primary key
|
|
88
|
+
*
|
|
89
|
+
* alt Has fields in statement
|
|
90
|
+
* CouchDBPaginator->>CouchDBPaginator: Use docs directly
|
|
91
|
+
* else No fields
|
|
92
|
+
* CouchDBPaginator->>CouchDBPaginator: Process each document
|
|
93
|
+
* loop For each document
|
|
94
|
+
* CouchDBPaginator->>CouchDBPaginator: Extract original ID
|
|
95
|
+
* CouchDBPaginator->>Adapter: revert(doc, clazz, pkDef.id, parsedId)
|
|
96
|
+
* end
|
|
97
|
+
* end
|
|
98
|
+
*
|
|
99
|
+
* CouchDBPaginator->>CouchDBPaginator: Store bookmark
|
|
100
|
+
* CouchDBPaginator->>CouchDBPaginator: Update currentPage
|
|
101
|
+
* CouchDBPaginator-->>Client: Return results
|
|
102
|
+
* end
|
|
103
|
+
*/
|
|
104
|
+
page(page?: number | undefined, bookmark?: any, ...args: MaybeContextualArg<any>): Promise<M[]>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Adapter, AdapterFlags, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
|
|
2
|
+
import { MangoQuery, MangoSelector, ViewResponse } from "../types.cjs";
|
|
3
|
+
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
+
import { CouchDBViewMetadata } from "../views/types.cjs";
|
|
5
|
+
import { CouchDBAdapter } from "../adapter.cjs";
|
|
6
|
+
type CouchDBViewDescriptor = {
|
|
7
|
+
ddoc: string;
|
|
8
|
+
view: string;
|
|
9
|
+
options: Record<string, any>;
|
|
10
|
+
};
|
|
11
|
+
type CouchDBAggregateInfo = {
|
|
12
|
+
kind: ViewKind;
|
|
13
|
+
meta: CouchDBViewMetadata;
|
|
14
|
+
descriptor: CouchDBViewDescriptor;
|
|
15
|
+
countDistinct?: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "avg";
|
|
18
|
+
attribute: string;
|
|
19
|
+
sumDescriptor: CouchDBViewDescriptor;
|
|
20
|
+
countDescriptor: CouchDBViewDescriptor;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @description Statement builder for CouchDB Mango queries
|
|
24
|
+
* @summary Provides a fluent interface for building CouchDB Mango queries with type safety
|
|
25
|
+
* @template M - The model type that extends Model
|
|
26
|
+
* @template R - The result type
|
|
27
|
+
* @param adapter - The CouchDB adapter
|
|
28
|
+
* @class CouchDBStatement
|
|
29
|
+
* @example
|
|
30
|
+
* // Example of using CouchDBStatement
|
|
31
|
+
* const adapter = new MyCouchDBAdapter(scope);
|
|
32
|
+
* const statement = new CouchDBStatement<User, User[]>(adapter);
|
|
33
|
+
*
|
|
34
|
+
* // Build a query
|
|
35
|
+
* const users = await statement
|
|
36
|
+
* .from(User)
|
|
37
|
+
* .where(Condition.attribute<User>('age').gt(18))
|
|
38
|
+
* .orderBy('lastName', 'asc')
|
|
39
|
+
* .limit(10)
|
|
40
|
+
* .execute();
|
|
41
|
+
*/
|
|
42
|
+
export declare class CouchDBStatement<M extends Model, A extends Adapter<any, any, MangoQuery, any>, R> extends Statement<M, A, R, MangoQuery> {
|
|
43
|
+
protected manualAggregation?: CouchDBAggregateInfo;
|
|
44
|
+
protected attributeTypeCache: Map<string, string | undefined>;
|
|
45
|
+
constructor(adapter: A, overrides?: Partial<AdapterFlags>);
|
|
46
|
+
/**
|
|
47
|
+
* @description Builds a CouchDB Mango query from the statement
|
|
48
|
+
* @summary Converts the statement's conditions, selectors, and options into a CouchDB Mango query
|
|
49
|
+
* @return {MangoQuery} The built Mango query
|
|
50
|
+
* @throws {Error} If there are invalid query conditions
|
|
51
|
+
* @mermaid
|
|
52
|
+
* sequenceDiagram
|
|
53
|
+
* participant Statement
|
|
54
|
+
* participant Repository
|
|
55
|
+
* participant parseCondition
|
|
56
|
+
*
|
|
57
|
+
* Statement->>Statement: build()
|
|
58
|
+
* Note over Statement: Initialize selectors
|
|
59
|
+
* Statement->>Repository: Get table name
|
|
60
|
+
* Repository-->>Statement: Return table name
|
|
61
|
+
* Statement->>Statement: Create base query
|
|
62
|
+
*
|
|
63
|
+
* alt Has selectSelector
|
|
64
|
+
* Statement->>Statement: Add fields to query
|
|
65
|
+
* end
|
|
66
|
+
*
|
|
67
|
+
* alt Has whereCondition
|
|
68
|
+
* Statement->>Statement: Create combined condition with table
|
|
69
|
+
* Statement->>parseCondition: Parse condition
|
|
70
|
+
* parseCondition-->>Statement: Return parsed condition
|
|
71
|
+
*
|
|
72
|
+
* alt Is group operator
|
|
73
|
+
* alt Is AND operator
|
|
74
|
+
* Statement->>Statement: Flatten nested AND conditions
|
|
75
|
+
* else Is OR operator
|
|
76
|
+
* Statement->>Statement: Combine with table condition
|
|
77
|
+
* else
|
|
78
|
+
* Statement->>Statement: Throw error
|
|
79
|
+
* end
|
|
80
|
+
* else
|
|
81
|
+
* Statement->>Statement: Merge conditions with existing selector
|
|
82
|
+
* end
|
|
83
|
+
* end
|
|
84
|
+
*
|
|
85
|
+
* alt Has orderBySelector
|
|
86
|
+
* Statement->>Statement: Add sort to query
|
|
87
|
+
* Statement->>Statement: Ensure field exists in selector
|
|
88
|
+
* end
|
|
89
|
+
*
|
|
90
|
+
* alt Has limitSelector
|
|
91
|
+
* Statement->>Statement: Set limit
|
|
92
|
+
* else
|
|
93
|
+
* Statement->>Statement: Use default limit
|
|
94
|
+
* end
|
|
95
|
+
*
|
|
96
|
+
* alt Has offsetSelector
|
|
97
|
+
* Statement->>Statement: Set skip
|
|
98
|
+
* end
|
|
99
|
+
*
|
|
100
|
+
* Statement-->>Statement: Return query
|
|
101
|
+
*/
|
|
102
|
+
protected build(): MangoQuery;
|
|
103
|
+
protected attachDefaultQueryIndex(query: MangoQuery): void;
|
|
104
|
+
protected collectStartsWithRangeAttrs(selector: MangoSelector): Set<string>;
|
|
105
|
+
/**
|
|
106
|
+
* @description Processes a record from CouchDB
|
|
107
|
+
* @summary Extracts the ID from a CouchDB document and reverts it to a model instance
|
|
108
|
+
* @param {any} r - The raw record from CouchDB
|
|
109
|
+
* @param pkAttr - The primary key attribute of the model
|
|
110
|
+
* @param {"Number" | "BigInt" | undefined} sequenceType - The type of the sequence
|
|
111
|
+
* @return {any} The processed record
|
|
112
|
+
*/
|
|
113
|
+
protected processRecord(record: any, ctx: ContextOf<A>): M;
|
|
114
|
+
/**
|
|
115
|
+
* @description Executes a raw Mango query
|
|
116
|
+
* @summary Sends a raw Mango query to CouchDB and processes the results
|
|
117
|
+
* @template R - The result type
|
|
118
|
+
* @param {MangoQuery} rawInput - The raw Mango query to execute
|
|
119
|
+
* @return {Promise<R>} A promise that resolves to the query results
|
|
120
|
+
*/
|
|
121
|
+
raw<R>(rawInput: MangoQuery, ...args: any[]): Promise<R>;
|
|
122
|
+
/**
|
|
123
|
+
* @description Parses a condition into a CouchDB Mango query selector
|
|
124
|
+
* @summary Converts a Condition object into a CouchDB Mango query selector structure
|
|
125
|
+
* @param {Condition<M>} condition - The condition to parse
|
|
126
|
+
* @return {MangoQuery} The Mango query with the parsed condition as its selector
|
|
127
|
+
* @mermaid
|
|
128
|
+
* sequenceDiagram
|
|
129
|
+
* participant Statement
|
|
130
|
+
* participant translateOperators
|
|
131
|
+
* participant merge
|
|
132
|
+
*
|
|
133
|
+
* Statement->>Statement: parseCondition(condition)
|
|
134
|
+
*
|
|
135
|
+
* Note over Statement: Extract condition parts
|
|
136
|
+
*
|
|
137
|
+
* alt Simple comparison operator
|
|
138
|
+
* Statement->>translateOperators: translateOperators(operator)
|
|
139
|
+
* translateOperators-->>Statement: Return CouchDB operator
|
|
140
|
+
* Statement->>Statement: Create selector with attribute and operator
|
|
141
|
+
* else NOT operator
|
|
142
|
+
* Statement->>Statement: parseCondition(attr1)
|
|
143
|
+
* Statement->>translateOperators: translateOperators(Operator.NOT)
|
|
144
|
+
* translateOperators-->>Statement: Return CouchDB NOT operator
|
|
145
|
+
* Statement->>Statement: Create negated selector
|
|
146
|
+
* else AND/OR operator
|
|
147
|
+
* Statement->>Statement: parseCondition(attr1)
|
|
148
|
+
* Statement->>Statement: parseCondition(comparison)
|
|
149
|
+
* Statement->>translateOperators: translateOperators(operator)
|
|
150
|
+
* translateOperators-->>Statement: Return CouchDB group operator
|
|
151
|
+
* Statement->>merge: merge(operator, op1, op2)
|
|
152
|
+
* merge-->>Statement: Return merged selector
|
|
153
|
+
* end
|
|
154
|
+
*
|
|
155
|
+
* Statement-->>Statement: Return query with selector
|
|
156
|
+
*/
|
|
157
|
+
protected buildAggregateInfo(): CouchDBAggregateInfo | undefined;
|
|
158
|
+
protected createAggregateDescriptor(kind: ViewKind, attribute?: string): Extract<CouchDBAggregateInfo, {
|
|
159
|
+
kind: ViewKind;
|
|
160
|
+
}> | undefined;
|
|
161
|
+
protected createAggregateQuery(info: CouchDBAggregateInfo): MangoQuery & {
|
|
162
|
+
aggregate: true;
|
|
163
|
+
aggregateInfo: CouchDBAggregateInfo;
|
|
164
|
+
};
|
|
165
|
+
protected shouldUseManualAggregation(): boolean;
|
|
166
|
+
protected executeAggregate<R>(info: CouchDBAggregateInfo, ctx: ContextOf<A>): Promise<R>;
|
|
167
|
+
protected handleAverage<R>(info: CouchDBAggregateInfo, ctx: ContextOf<A>): Promise<R>;
|
|
168
|
+
protected executeManualAggregation<R>(docs: any[], info: CouchDBAggregateInfo, ctx: ContextOf<A>): R;
|
|
169
|
+
protected computeCount<R>(docs: any[], attribute?: string): R;
|
|
170
|
+
protected computeDistinctCount<R>(docs: any[], attribute?: string): R;
|
|
171
|
+
protected computeDistinctValues<R>(docs: any[], attribute?: string): R;
|
|
172
|
+
protected computeSum<R>(docs: any[], attribute?: string): R;
|
|
173
|
+
protected computeAverage<R>(docs: any[], attribute?: string): R;
|
|
174
|
+
protected computeMinMax<R>(docs: any[], attribute: string | undefined, mode: "min" | "max"): R;
|
|
175
|
+
protected computeGroupBy<R>(docs: any[], attribute: string): R;
|
|
176
|
+
protected groupSelectResults(docs: any[]): Record<string, any[]>;
|
|
177
|
+
protected collectValues(docs: any[], attribute: string): any[];
|
|
178
|
+
protected convertValueByAttribute(attribute: string, value: any): any;
|
|
179
|
+
protected getAttributeType(attribute?: string): string | undefined;
|
|
180
|
+
protected normalizeMetaType(metaType: any): string | undefined;
|
|
181
|
+
protected normalizeComparable(value: any): number | null;
|
|
182
|
+
protected groupKey(value: any): string;
|
|
183
|
+
protected toNumericValue(value: any, field: string, context: string): number;
|
|
184
|
+
protected convertAggregateValue(attribute: string | undefined, value: any): any;
|
|
185
|
+
protected resolveSelectorAttribute(selector?: SelectSelector<M> | null): string | undefined;
|
|
186
|
+
protected missingDecorator(kind: ViewKind | "avg", attribute?: string): UnsupportedError;
|
|
187
|
+
protected decoratorForKind(kind: ViewKind | "avg"): string;
|
|
188
|
+
protected processViewResponse<R>(info: CouchDBAggregateInfo, response: ViewResponse): R;
|
|
189
|
+
protected isViewAggregate(info: CouchDBAggregateInfo): info is Extract<CouchDBAggregateInfo, {
|
|
190
|
+
kind: ViewKind;
|
|
191
|
+
}>;
|
|
192
|
+
protected getCouchAdapter(): CouchDBAdapter<any, any, any>;
|
|
193
|
+
protected parseCondition(condition: Condition<M>): MangoQuery;
|
|
194
|
+
}
|
|
195
|
+
export {};
|