@decaf-ts/for-couchdb 0.11.0 → 0.13.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/adapter.d.cts +2 -2
- package/lib/types/adapter.d.mts +2 -2
- package/lib/types/decorators.d.cts +1 -1
- package/lib/types/decorators.d.mts +1 -1
- package/lib/types/index.d.cts +12 -12
- package/lib/types/index.d.mts +12 -12
- package/lib/types/indexes/generator.d.cts +1 -1
- package/lib/types/indexes/generator.d.mts +1 -1
- package/lib/types/indexes/index.d.cts +1 -1
- package/lib/types/indexes/index.d.mts +1 -1
- package/lib/types/query/Paginator.d.cts +2 -2
- package/lib/types/query/Paginator.d.mts +2 -2
- package/lib/types/query/Statement.d.cts +3 -3
- package/lib/types/query/Statement.d.mts +3 -3
- package/lib/types/query/constants.d.cts +1 -1
- package/lib/types/query/constants.d.mts +1 -1
- package/lib/types/query/index.d.cts +4 -4
- package/lib/types/query/index.d.mts +4 -4
- package/lib/types/query/translate.d.cts +1 -1
- package/lib/types/query/translate.d.mts +1 -1
- package/lib/types/repository.d.cts +1 -1
- package/lib/types/repository.d.mts +1 -1
- package/lib/types/utils.d.cts +1 -1
- package/lib/types/utils.d.mts +1 -1
- package/lib/types/views/generator.d.cts +2 -2
- package/lib/types/views/generator.d.mts +2 -2
- package/lib/types/views/index.d.cts +2 -2
- package/lib/types/views/index.d.mts +2 -2
- package/package.json +1 -1
- package/lib/types/adapter.d.ts +0 -296
- package/lib/types/constants.d.ts +0 -42
- package/lib/types/decorators.d.ts +0 -8
- package/lib/types/errors.d.ts +0 -21
- package/lib/types/index.d.ts +0 -28
- package/lib/types/indexes/generator.d.ts +0 -51
- package/lib/types/indexes/index.d.ts +0 -1
- package/lib/types/metadata.d.ts +0 -4
- package/lib/types/query/Paginator.d.ts +0 -105
- package/lib/types/query/Statement.d.ts +0 -195
- package/lib/types/query/constants.d.ts +0 -47
- package/lib/types/query/index.d.ts +0 -4
- package/lib/types/query/translate.d.ts +0 -34
- package/lib/types/repository.d.ts +0 -39
- package/lib/types/types.d.ts +0 -166
- package/lib/types/utils.d.ts +0 -112
- package/lib/types/views/generator.d.ts +0 -13
- package/lib/types/views/index.d.ts +0 -2
- package/lib/types/views/types.d.ts +0 -30
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { Adapter, AdapterFlags, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
|
|
2
|
-
import { MangoQuery, MangoSelector, ViewResponse } from "../types";
|
|
3
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
4
|
-
import { CouchDBViewMetadata } from "../views/types";
|
|
5
|
-
import { CouchDBAdapter } from "../adapter";
|
|
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 {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { MangoOperator } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* @description Default query limit for CouchDB queries
|
|
4
|
-
* @summary Maximum number of documents to return in a single query
|
|
5
|
-
* @const CouchDBQueryLimit
|
|
6
|
-
* @memberOf module:for-couchdb
|
|
7
|
-
*/
|
|
8
|
-
export declare const CouchDBQueryLimit = 250;
|
|
9
|
-
/**
|
|
10
|
-
* @description Mapping of operator names to CouchDB Mango query operators
|
|
11
|
-
* @summary Constants for CouchDB comparison operators used in Mango queries
|
|
12
|
-
* @typedef {Object} CouchDBOperatorType
|
|
13
|
-
* @property {string} EQUAL - Equality operator ($eq)
|
|
14
|
-
* @property {string} DIFFERENT - Inequality operator ($ne)
|
|
15
|
-
* @property {string} BIGGER - Greater than operator ($gt)
|
|
16
|
-
* @property {string} BIGGER_EQ - Greater than or equal operator ($gte)
|
|
17
|
-
* @property {string} SMALLER - Less than operator ($lt)
|
|
18
|
-
* @property {string} SMALLER_EQ - Less than or equal operator ($lte)
|
|
19
|
-
* @property {string} NOT - Negation operator ($not)
|
|
20
|
-
* @property {string} IN - In array operator ($in)
|
|
21
|
-
* @property {string} REGEXP - Regular expression operator ($regex)
|
|
22
|
-
* @const CouchDBOperator
|
|
23
|
-
* @type {CouchDBOperatorType}
|
|
24
|
-
* @memberOf module:for-couchdb
|
|
25
|
-
*/
|
|
26
|
-
export declare const CouchDBOperator: Record<string, MangoOperator>;
|
|
27
|
-
/**
|
|
28
|
-
* @description Mapping of logical operator names to CouchDB Mango query operators
|
|
29
|
-
* @summary Constants for CouchDB logical operators used in Mango queries
|
|
30
|
-
* @typedef {Object} CouchDBGroupOperatorType
|
|
31
|
-
* @property {string} AND - Logical AND operator ($and)
|
|
32
|
-
* @property {string} OR - Logical OR operator ($or)
|
|
33
|
-
* @const CouchDBGroupOperator
|
|
34
|
-
* @type {CouchDBGroupOperatorType}
|
|
35
|
-
* @memberOf module:for-couchdb
|
|
36
|
-
*/
|
|
37
|
-
export declare const CouchDBGroupOperator: Record<string, MangoOperator>;
|
|
38
|
-
/**
|
|
39
|
-
* @description Special constant values used in CouchDB queries
|
|
40
|
-
* @summary String constants representing special values in CouchDB
|
|
41
|
-
* @typedef {Object} CouchDBConstType
|
|
42
|
-
* @property {string} NULL - String representation of null value
|
|
43
|
-
* @const CouchDBConst
|
|
44
|
-
* @type {CouchDBConstType}
|
|
45
|
-
* @memberOf module:for-couchdb
|
|
46
|
-
*/
|
|
47
|
-
export declare const CouchDBConst: Record<string, string>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { GroupOperator, Operator } from "@decaf-ts/core";
|
|
2
|
-
import { MangoOperator } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Translates core operators to CouchDB Mango operators
|
|
5
|
-
* @summary Converts Decaf.ts core operators to their equivalent CouchDB Mango query operators
|
|
6
|
-
* @param {GroupOperator | Operator} operator - The core operator to translate
|
|
7
|
-
* @return {MangoOperator} The equivalent CouchDB Mango operator
|
|
8
|
-
* @throws {QueryError} If no translation exists for the given operator
|
|
9
|
-
* @function translateOperators
|
|
10
|
-
* @memberOf module:for-couchdb
|
|
11
|
-
* @mermaid
|
|
12
|
-
* sequenceDiagram
|
|
13
|
-
* participant Caller
|
|
14
|
-
* participant translateOperators
|
|
15
|
-
* participant CouchDBOperator
|
|
16
|
-
* participant CouchDBGroupOperator
|
|
17
|
-
*
|
|
18
|
-
* Caller->>translateOperators: operator
|
|
19
|
-
*
|
|
20
|
-
* translateOperators->>CouchDBOperator: Check for match
|
|
21
|
-
* alt Found in CouchDBOperator
|
|
22
|
-
* CouchDBOperator-->>translateOperators: Return matching operator
|
|
23
|
-
* translateOperators-->>Caller: Return MangoOperator
|
|
24
|
-
* else Not found
|
|
25
|
-
* translateOperators->>CouchDBGroupOperator: Check for match
|
|
26
|
-
* alt Found in CouchDBGroupOperator
|
|
27
|
-
* CouchDBGroupOperator-->>translateOperators: Return matching operator
|
|
28
|
-
* translateOperators-->>Caller: Return MangoOperator
|
|
29
|
-
* else Not found
|
|
30
|
-
* translateOperators-->>Caller: Throw QueryError
|
|
31
|
-
* end
|
|
32
|
-
* end
|
|
33
|
-
*/
|
|
34
|
-
export declare function translateOperators(operator: GroupOperator | Operator): MangoOperator;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { MaybeContextualArg, Repository } from "@decaf-ts/core";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
-
import type { CouchDBAdapter } from "./adapter";
|
|
5
|
-
import { ContextOf } from "@decaf-ts/core";
|
|
6
|
-
import type { PrimaryKeyType } from "@decaf-ts/db-decorators";
|
|
7
|
-
export declare class CouchDBRepository<M extends Model, A extends CouchDBAdapter<any, any, any>> extends Repository<M, A> {
|
|
8
|
-
constructor(adapter: A, model: Constructor<M>, force?: boolean);
|
|
9
|
-
protected assignMetadata(model: M, source?: M): M;
|
|
10
|
-
protected assignMetadata(models: M[], source?: M[]): M[];
|
|
11
|
-
create(model: M, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M>;
|
|
12
|
-
createAll(models: M[], ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
13
|
-
read(id: PrimaryKeyType, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M>;
|
|
14
|
-
readAll(ids: PrimaryKeyType[], ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
15
|
-
update(model: M, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M>;
|
|
16
|
-
updateAll(models: M[], ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
17
|
-
delete(id: PrimaryKeyType, ...args: MaybeContextualArg<ContextOf<A>>): Promise<M>;
|
|
18
|
-
deleteAll(ids: PrimaryKeyType[], ...args: MaybeContextualArg<ContextOf<A>>): Promise<M[]>;
|
|
19
|
-
/**
|
|
20
|
-
* @description Prepares a model for update.
|
|
21
|
-
* @summary Validates the model and prepares it for update in the database.
|
|
22
|
-
* @param {M} model - The model to update.
|
|
23
|
-
* @param {...any[]} args - Additional arguments.
|
|
24
|
-
* @return The prepared model and context arguments.
|
|
25
|
-
* @throws {InternalError} If the model has no primary key value.
|
|
26
|
-
* @throws {ValidationError} If the model fails validation.
|
|
27
|
-
*/
|
|
28
|
-
protected updatePrefix(model: M, ...args: MaybeContextualArg<ContextOf<A>>): Promise<[M, ...args: any[], ContextOf<A>, M | undefined]>;
|
|
29
|
-
/**
|
|
30
|
-
* @description Prepares multiple models for update.
|
|
31
|
-
* @summary Validates multiple models and prepares them for update in the database.
|
|
32
|
-
* @param {M[]} models - The models to update.
|
|
33
|
-
* @param {...any[]} args - Additional arguments.
|
|
34
|
-
* @return {Promise<any[]>} The prepared models and context arguments.
|
|
35
|
-
* @throws {InternalError} If any model has no primary key value.
|
|
36
|
-
* @throws {ValidationError} If any model fails validation.
|
|
37
|
-
*/
|
|
38
|
-
protected updateAllPrefix(models: M[], ...args: MaybeContextualArg<ContextOf<A>>): Promise<[M[], ...args: any[], ContextOf<A>, M[] | undefined]>;
|
|
39
|
-
}
|
package/lib/types/types.d.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Response from a CouchDB Mango query
|
|
3
|
-
* @summary Contains the matching documents and additional metadata about the query execution
|
|
4
|
-
* @interface MangoResponse
|
|
5
|
-
* @template D - The document type
|
|
6
|
-
* @memberOf module:for-couchdb
|
|
7
|
-
* @see Docs: {@link https://docs.couchdb.org/en/latest/api/database/find.html#db-find}
|
|
8
|
-
*/
|
|
9
|
-
export interface MangoResponse<D> {
|
|
10
|
-
/** Array of documents matching the search.
|
|
11
|
-
*
|
|
12
|
-
* In each matching document, the fields specified in the fields part of the request body are listed, along with
|
|
13
|
-
* their values. */
|
|
14
|
-
docs: (D & {
|
|
15
|
-
_id: string;
|
|
16
|
-
_rev: string;
|
|
17
|
-
})[];
|
|
18
|
-
/** A string that enables you to specify which page of results you require.
|
|
19
|
-
*
|
|
20
|
-
* Used for paging through result sets. */
|
|
21
|
-
bookmark?: string;
|
|
22
|
-
/** Execution warnings */
|
|
23
|
-
warning?: string;
|
|
24
|
-
/** Basic execution statistics for a specific request. */
|
|
25
|
-
execution_stats?: MangoExecutionStats;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @description Statistics about the execution of a Mango query
|
|
29
|
-
* @summary Provides detailed metrics about query execution including document and key examination counts
|
|
30
|
-
* @interface MangoExecutionStats
|
|
31
|
-
* @memberOf module:for-couchdb
|
|
32
|
-
* @see Docs: {@link http://docs.couchdb.org/en/latest/api/database/find.html#execution-statistics}
|
|
33
|
-
*/
|
|
34
|
-
export interface MangoExecutionStats {
|
|
35
|
-
/** Number of index keys examined. Currently always 0. */
|
|
36
|
-
total_keys_examined: number;
|
|
37
|
-
/** Number of documents fetched from the database / index.
|
|
38
|
-
*
|
|
39
|
-
* Equivalent to using include_docs = true in a view. */
|
|
40
|
-
total_docs_examined: number;
|
|
41
|
-
/** Number of documents fetched from the database using an out-of-band document fetch.
|
|
42
|
-
*
|
|
43
|
-
* This is only non-zero when read quorum > 1 is specified in the query parameters. */
|
|
44
|
-
total_quorum_docs_examined: number;
|
|
45
|
-
/** Number of results returned from the query. */
|
|
46
|
-
results_returned: number;
|
|
47
|
-
/** Total execution time in milliseconds as measured by the database. */
|
|
48
|
-
execution_time_ms: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @description Parameters for creating a CouchDB Mango index
|
|
52
|
-
* @summary Defines the structure and configuration for a new Mango index
|
|
53
|
-
* @interface CreateIndexRequest
|
|
54
|
-
* @memberOf module:for-couchdb
|
|
55
|
-
* @see Docs: {@link http://docs.couchdb.org/en/latest/api/database/find.html#db-index}
|
|
56
|
-
*/
|
|
57
|
-
export interface CreateIndexRequest {
|
|
58
|
-
/** JSON object describing the index to create */
|
|
59
|
-
index: {
|
|
60
|
-
/** Array of field names following the sort syntax. */
|
|
61
|
-
fields: SortOrder[];
|
|
62
|
-
/** A selector to apply to documents at indexing time, creating a partial index. */
|
|
63
|
-
partial_filter_selector?: MangoSelector;
|
|
64
|
-
};
|
|
65
|
-
/** Name of the design document in which the index will be created. */
|
|
66
|
-
ddoc?: string;
|
|
67
|
-
/** Name of the index. If no name is provided, a name will be generated automatically. */
|
|
68
|
-
name?: string;
|
|
69
|
-
/** Can be "json" or "text".
|
|
70
|
-
*
|
|
71
|
-
* @default "json" */
|
|
72
|
-
type?: "json" | "text";
|
|
73
|
-
/** This field sets whether the created index will be a partitioned or global index. */
|
|
74
|
-
partitioned?: boolean;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @description Represents the possible value types in a Mango query
|
|
78
|
-
* @summary Union type of all possible value types that can be used in Mango queries
|
|
79
|
-
* @typedef {(number|string|Date|boolean|object|null)} MangoValue
|
|
80
|
-
* @memberOf module:for-couchdb
|
|
81
|
-
*/
|
|
82
|
-
export type MangoValue = number | string | Date | boolean | object | null;
|
|
83
|
-
/**
|
|
84
|
-
* @description Operators available in Mango queries
|
|
85
|
-
* @summary Union type of all possible operators that can be used in Mango queries
|
|
86
|
-
* @typedef {string} MangoOperator
|
|
87
|
-
* @memberOf module:for-couchdb
|
|
88
|
-
*/
|
|
89
|
-
export type MangoOperator = "$lt" | "$lte" | "$eq" | "$ne" | "$gte" | "$gt" | "$exists" | "$type" | "$in" | "$nin" | "$size" | "$mod" | "$regex" | "$or" | "$and" | "$nor" | "$not" | "$all" | "$allMatch" | "$elemMatch";
|
|
90
|
-
/**
|
|
91
|
-
* @description Represents a CouchDB Mango query selector
|
|
92
|
-
* @summary Type for defining query conditions in Mango queries
|
|
93
|
-
* @typedef {Object} MangoSelector
|
|
94
|
-
* @memberOf module:for-couchdb
|
|
95
|
-
* @see Docs: {@link http://docs.couchdb.org/en/latest/api/database/find.html#selector-syntax}
|
|
96
|
-
*/
|
|
97
|
-
export type MangoSelector = {
|
|
98
|
-
[K in MangoOperator | string]: MangoSelector | MangoSelector[] | MangoValue | MangoValue[];
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* @description Represents a sort order specification in Mango queries
|
|
102
|
-
* @summary Type for defining sort order in Mango queries
|
|
103
|
-
* @typedef {(string|string[]|Object)} SortOrder
|
|
104
|
-
* @memberOf module:for-couchdb
|
|
105
|
-
* @see Docs: {@link http://docs.couchdb.org/en/latest/api/database/find.html#sort-syntax}
|
|
106
|
-
*/
|
|
107
|
-
export type SortOrder = string | string[] | {
|
|
108
|
-
[key: string]: "asc" | "desc";
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* @description Represents a CouchDB Mango query
|
|
112
|
-
* @summary Interface for defining complete Mango queries with selectors, sorting, pagination, and other options
|
|
113
|
-
* @interface MangoQuery
|
|
114
|
-
* @memberOf module:for-couchdb
|
|
115
|
-
* @see Docs: {@link https://docs.couchdb.org/en/latest/api/database/find.html#db-find}
|
|
116
|
-
*/
|
|
117
|
-
export interface MangoQuery {
|
|
118
|
-
/** JSON object describing criteria used to select documents. */
|
|
119
|
-
selector: MangoSelector;
|
|
120
|
-
/** Maximum number of results returned. @default 25 */
|
|
121
|
-
limit?: number;
|
|
122
|
-
/** Skip the first 'n' results, where 'n' is the value specified. */
|
|
123
|
-
skip?: number;
|
|
124
|
-
/** JSON array following sort syntax. */
|
|
125
|
-
sort?: SortOrder[];
|
|
126
|
-
/** JSON array specifying which fields of each object should be returned.
|
|
127
|
-
*
|
|
128
|
-
* If it is omitted, the entire object is returned.
|
|
129
|
-
*
|
|
130
|
-
* @see Docs: {@link http://docs.couchdb.org/en/latest/api/database/find.html#filtering-fields} */
|
|
131
|
-
fields?: string[];
|
|
132
|
-
use_index?: string | [string, string];
|
|
133
|
-
/** Read quorum needed for the result.
|
|
134
|
-
*
|
|
135
|
-
* @default 1 */
|
|
136
|
-
r?: number;
|
|
137
|
-
/** A string that enables you to specify which page of results you require.
|
|
138
|
-
*
|
|
139
|
-
* Used for paging through result sets. */
|
|
140
|
-
bookmark?: string;
|
|
141
|
-
/** Whether to update the index prior to returning the result.
|
|
142
|
-
*
|
|
143
|
-
* @default true */
|
|
144
|
-
update?: boolean;
|
|
145
|
-
/** Whether or not the view results should be returned from a “stable” set of shards. */
|
|
146
|
-
stable?: boolean;
|
|
147
|
-
/** Combination of update = false and stable = true options.
|
|
148
|
-
*
|
|
149
|
-
* Possible options: "ok", false (default). */
|
|
150
|
-
stale?: "ok" | false;
|
|
151
|
-
/** Include execution statistics in the query response.
|
|
152
|
-
*
|
|
153
|
-
* Optional, default: false. */
|
|
154
|
-
execution_stats?: boolean;
|
|
155
|
-
}
|
|
156
|
-
export interface ViewRow<D = any> {
|
|
157
|
-
id?: string;
|
|
158
|
-
key?: any;
|
|
159
|
-
value?: any;
|
|
160
|
-
doc?: D;
|
|
161
|
-
}
|
|
162
|
-
export interface ViewResponse<D = any> {
|
|
163
|
-
total_rows?: number;
|
|
164
|
-
offset?: number;
|
|
165
|
-
rows: ViewRow<D>[];
|
|
166
|
-
}
|
package/lib/types/utils.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { OrderDirection } from "@decaf-ts/core";
|
|
2
|
-
import { CreateIndexRequest } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Re-authenticates a connection to CouchDB
|
|
5
|
-
* @summary Refreshes the authentication for a CouchDB connection using the provided credentials
|
|
6
|
-
* @param {any} con - The CouchDB connection object
|
|
7
|
-
* @param {string} user - The username for authentication
|
|
8
|
-
* @param {string} pass - The password for authentication
|
|
9
|
-
* @return {Promise<any>} A promise that resolves to the authentication result
|
|
10
|
-
* @function reAuth
|
|
11
|
-
* @memberOf module:for-couchdb
|
|
12
|
-
*/
|
|
13
|
-
export declare function reAuth(con: any, user: string, pass: string): Promise<any>;
|
|
14
|
-
/**
|
|
15
|
-
* @description Wraps a CouchDB database connection with automatic re-authentication
|
|
16
|
-
* @summary Creates a proxy around a CouchDB database connection that automatically re-authenticates before each operation
|
|
17
|
-
* @param {any} con - The CouchDB connection object
|
|
18
|
-
* @param {string} dbName - The name of the database to use
|
|
19
|
-
* @param {string} user - The username for authentication
|
|
20
|
-
* @param {string} pass - The password for authentication
|
|
21
|
-
* @return {any} The wrapped database connection object
|
|
22
|
-
* @function wrapDocumentScope
|
|
23
|
-
* @memberOf module:for-couchdb
|
|
24
|
-
* @mermaid
|
|
25
|
-
* sequenceDiagram
|
|
26
|
-
* participant Client
|
|
27
|
-
* participant wrapDocumentScope
|
|
28
|
-
* participant DB
|
|
29
|
-
* participant reAuth
|
|
30
|
-
*
|
|
31
|
-
* Client->>wrapDocumentScope: con, dbName, user, pass
|
|
32
|
-
* wrapDocumentScope->>DB: con.use(dbName)
|
|
33
|
-
* Note over wrapDocumentScope: Wrap DB methods with re-auth
|
|
34
|
-
*
|
|
35
|
-
* loop For each method (insert, get, put, destroy, find)
|
|
36
|
-
* wrapDocumentScope->>wrapDocumentScope: Store original method
|
|
37
|
-
* wrapDocumentScope->>wrapDocumentScope: Define new method with re-auth
|
|
38
|
-
* end
|
|
39
|
-
*
|
|
40
|
-
* wrapDocumentScope->>wrapDocumentScope: Add NATIVE property with con value
|
|
41
|
-
* wrapDocumentScope-->>Client: Return wrapped DB
|
|
42
|
-
*
|
|
43
|
-
* Note over Client: Later when client uses DB methods
|
|
44
|
-
* Client->>DB: Any wrapped method call
|
|
45
|
-
* DB->>reAuth: Authenticate before operation
|
|
46
|
-
* reAuth-->>DB: Authentication complete
|
|
47
|
-
* DB->>DB: Call original method
|
|
48
|
-
* DB-->>Client: Return result
|
|
49
|
-
*/
|
|
50
|
-
export declare function wrapDocumentScope(con: any, dbName: string, user: string, pass: string): any;
|
|
51
|
-
/**
|
|
52
|
-
* @description Tests if an attribute name is reserved in CouchDB
|
|
53
|
-
* @summary Checks if an attribute name starts with an underscore, which indicates it's a reserved attribute in CouchDB
|
|
54
|
-
* @param {string} attr - The attribute name to test
|
|
55
|
-
* @return {RegExpMatchArray|null} The match result or null if no match
|
|
56
|
-
* @function testReservedAttributes
|
|
57
|
-
* @memberOf module:for-couchdb
|
|
58
|
-
*/
|
|
59
|
-
export declare function testReservedAttributes(attr: string): RegExpMatchArray | null;
|
|
60
|
-
/**
|
|
61
|
-
* @description Generates a name for a CouchDB index
|
|
62
|
-
* @summary Creates a standardized name for a CouchDB index based on the table, attribute, compositions, and order
|
|
63
|
-
* @param {string} attribute - The primary attribute for the index
|
|
64
|
-
* @param {string} tableName - The name of the table
|
|
65
|
-
* @param {string[]} [compositions] - Optional additional attributes to include in the index
|
|
66
|
-
* @param {OrderDirection} [order] - Optional sort order for the index
|
|
67
|
-
* @param {string} [separator=DefaultSeparator] - The separator to use between parts of the index name
|
|
68
|
-
* @return {string} The generated index name
|
|
69
|
-
* @function generateIndexName
|
|
70
|
-
* @memberOf module:for-couchdb
|
|
71
|
-
*/
|
|
72
|
-
export declare function generateIndexName(attribute: string, tableName: string, compositions?: string[], order?: OrderDirection, separator?: string): string;
|
|
73
|
-
/**
|
|
74
|
-
* @description Generates a CouchDB index configuration
|
|
75
|
-
* @summary Creates a complete CreateIndexRequest object for defining a CouchDB index based on specified parameters
|
|
76
|
-
* @param {string} attribute - The primary attribute for the index
|
|
77
|
-
* @param {string} tableName - The name of the table
|
|
78
|
-
* @param {string[]} [compositions] - Optional additional attributes to include in the index
|
|
79
|
-
* @param {OrderDirection} [order] - Optional sort order for the index
|
|
80
|
-
* @param {string} [separator=DefaultSeparator] - The separator to use between parts of the index name
|
|
81
|
-
* @return {CreateIndexRequest} The complete index configuration object
|
|
82
|
-
* @function generateIndexDoc
|
|
83
|
-
* @memberOf module:for-couchdb
|
|
84
|
-
* @mermaid
|
|
85
|
-
* sequenceDiagram
|
|
86
|
-
* participant Caller
|
|
87
|
-
* participant generateIndexDoc
|
|
88
|
-
* participant generateIndexName
|
|
89
|
-
*
|
|
90
|
-
* Caller->>generateIndexDoc: attribute, tableName, compositions, order, separator
|
|
91
|
-
*
|
|
92
|
-
* Note over generateIndexDoc: Create partial filter selector
|
|
93
|
-
* generateIndexDoc->>generateIndexDoc: Set up filter for tableName
|
|
94
|
-
*
|
|
95
|
-
* alt order is specified
|
|
96
|
-
* Note over generateIndexDoc: Create ordered fields array
|
|
97
|
-
* generateIndexDoc->>generateIndexDoc: Create orderProp for attribute
|
|
98
|
-
* generateIndexDoc->>generateIndexDoc: Map compositions to ordered props
|
|
99
|
-
* generateIndexDoc->>generateIndexDoc: Create sortedTable for table field
|
|
100
|
-
* generateIndexDoc->>generateIndexDoc: Combine all ordered fields
|
|
101
|
-
* else
|
|
102
|
-
* Note over generateIndexDoc: Create simple fields array
|
|
103
|
-
* generateIndexDoc->>generateIndexDoc: Use attribute, compositions, and table as strings
|
|
104
|
-
* end
|
|
105
|
-
*
|
|
106
|
-
* generateIndexDoc->>generateIndexName: Generate index name
|
|
107
|
-
* generateIndexName-->>generateIndexDoc: Return name
|
|
108
|
-
*
|
|
109
|
-
* Note over generateIndexDoc: Create final index request
|
|
110
|
-
* generateIndexDoc-->>Caller: Return CreateIndexRequest
|
|
111
|
-
*/
|
|
112
|
-
export declare function generateIndexDoc(attribute: string, tableName: string, compositions?: string[], order?: OrderDirection, separator?: string): CreateIndexRequest;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ViewKind } from "@decaf-ts/core";
|
|
2
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
-
import { CreateIndexRequest } from "../types";
|
|
5
|
-
import { Operator } from "@decaf-ts/core";
|
|
6
|
-
import { CouchDBDesignDoc, CouchDBViewMetadata, ViewIndexDefinition } from "./types";
|
|
7
|
-
export declare function generateViewName(tableName: string, attr: string, kind: ViewKind, meta: CouchDBViewMetadata, separator?: string): string;
|
|
8
|
-
export declare function generateDesignDocName(tableName: string, viewName: string, separator?: string): string;
|
|
9
|
-
export declare function findViewMetadata<M extends Model>(model: Constructor<M>, kind: ViewKind, attribute?: string): CouchDBViewMetadata[];
|
|
10
|
-
export declare function collectViewMetadata(model: Constructor<Model>, key: Operator, kind: ViewKind): CouchDBViewMetadata[];
|
|
11
|
-
export declare function generateViews<M extends Model>(models: Constructor<M>[]): CouchDBDesignDoc[];
|
|
12
|
-
export declare function generateViewIndexes<M extends Model>(models: Constructor<M>[]): CreateIndexRequest[];
|
|
13
|
-
export declare function viewIndexDefinition(meta: CouchDBViewMetadata): ViewIndexDefinition;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { OrderDirection, ViewOptions, ViewKey, ViewKind } from "@decaf-ts/core";
|
|
2
|
-
export interface CouchDBViewOptions extends ViewOptions {
|
|
3
|
-
ddoc?: string;
|
|
4
|
-
value?: ViewKey | "doc" | null;
|
|
5
|
-
map?: string | ((doc: any) => void);
|
|
6
|
-
reduce?: string | ((keys: any, values: any, rereduce: boolean) => any);
|
|
7
|
-
returnDocs?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface CouchDBViewMetadata extends CouchDBViewOptions {
|
|
10
|
-
kind: ViewKind;
|
|
11
|
-
attribute: string;
|
|
12
|
-
}
|
|
13
|
-
export interface CouchDBViewDefinition {
|
|
14
|
-
map: string;
|
|
15
|
-
reduce?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface AggregateOptions extends CouchDBViewOptions {
|
|
18
|
-
value?: any;
|
|
19
|
-
}
|
|
20
|
-
export interface CouchDBDesignDoc {
|
|
21
|
-
_id: string;
|
|
22
|
-
_rev?: string;
|
|
23
|
-
language?: "javascript";
|
|
24
|
-
views: Record<string, CouchDBViewDefinition>;
|
|
25
|
-
}
|
|
26
|
-
export interface ViewIndexDefinition {
|
|
27
|
-
attribute: string;
|
|
28
|
-
compositions?: string[];
|
|
29
|
-
directions?: OrderDirection[];
|
|
30
|
-
}
|