@decaf-ts/for-couchdb 0.14.0 → 0.14.1

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.
Files changed (69) hide show
  1. package/dist/for-couchdb.cjs +1 -1
  2. package/dist/for-couchdb.cjs.map +1 -1
  3. package/dist/for-couchdb.js +1 -1
  4. package/dist/for-couchdb.js.map +1 -1
  5. package/lib/cjs/adapter.cjs +6 -12
  6. package/lib/cjs/adapter.cjs.map +1 -1
  7. package/lib/cjs/{errors.cjs → errors/IndexError.cjs} +2 -2
  8. package/lib/cjs/errors/IndexError.cjs.map +1 -0
  9. package/lib/cjs/errors/IndexPlanningError.cjs +15 -0
  10. package/lib/cjs/errors/IndexPlanningError.cjs.map +1 -0
  11. package/lib/cjs/errors/index.cjs +20 -0
  12. package/lib/cjs/errors/index.cjs.map +1 -0
  13. package/lib/cjs/index.cjs +10 -6
  14. package/lib/cjs/index.cjs.map +1 -1
  15. package/lib/cjs/indexes/generator.cjs +13 -9
  16. package/lib/cjs/indexes/generator.cjs.map +1 -1
  17. package/lib/cjs/query/Paginator.cjs +32 -16
  18. package/lib/cjs/query/Paginator.cjs.map +1 -1
  19. package/lib/cjs/query/Statement.cjs +13 -8
  20. package/lib/cjs/query/Statement.cjs.map +1 -1
  21. package/lib/cjs/query/index.cjs +1 -0
  22. package/lib/cjs/query/index.cjs.map +1 -1
  23. package/lib/cjs/query/planner.cjs +431 -0
  24. package/lib/cjs/query/planner.cjs.map +1 -0
  25. package/lib/esm/adapter.js +1 -7
  26. package/lib/esm/adapter.js.map +1 -1
  27. package/lib/esm/{errors.js → errors/IndexError.js} +1 -1
  28. package/lib/esm/errors/IndexError.js.map +1 -0
  29. package/lib/esm/errors/IndexPlanningError.js +10 -0
  30. package/lib/esm/errors/IndexPlanningError.js.map +1 -0
  31. package/lib/esm/errors/index.js +3 -0
  32. package/lib/esm/errors/index.js.map +1 -0
  33. package/lib/esm/index.js +5 -5
  34. package/lib/esm/index.js.map +1 -1
  35. package/lib/esm/indexes/generator.js +12 -10
  36. package/lib/esm/indexes/generator.js.map +1 -1
  37. package/lib/esm/query/Paginator.js +32 -16
  38. package/lib/esm/query/Paginator.js.map +1 -1
  39. package/lib/esm/query/Statement.js +14 -9
  40. package/lib/esm/query/Statement.js.map +1 -1
  41. package/lib/esm/query/index.js +1 -0
  42. package/lib/esm/query/index.js.map +1 -1
  43. package/lib/esm/query/planner.js +413 -0
  44. package/lib/esm/query/planner.js.map +1 -0
  45. package/lib/types/adapter.d.cts +3 -3
  46. package/lib/types/adapter.d.mts +3 -3
  47. package/lib/types/errors/IndexPlanningError.d.cts +17 -0
  48. package/lib/types/errors/IndexPlanningError.d.mts +17 -0
  49. package/lib/types/errors/index.d.cts +2 -0
  50. package/lib/types/errors/index.d.mts +2 -0
  51. package/lib/types/index.d.cts +5 -5
  52. package/lib/types/index.d.mts +5 -5
  53. package/lib/types/indexes/generator.d.cts +13 -0
  54. package/lib/types/indexes/generator.d.mts +13 -0
  55. package/lib/types/query/Paginator.d.cts +3 -0
  56. package/lib/types/query/Paginator.d.mts +3 -0
  57. package/lib/types/query/Statement.d.cts +3 -2
  58. package/lib/types/query/Statement.d.mts +3 -2
  59. package/lib/types/query/index.d.cts +1 -0
  60. package/lib/types/query/index.d.mts +1 -0
  61. package/lib/types/query/planner.d.cts +64 -0
  62. package/lib/types/query/planner.d.mts +64 -0
  63. package/lib/types/types.d.cts +8 -0
  64. package/lib/types/types.d.mts +8 -0
  65. package/package.json +1 -1
  66. package/lib/cjs/errors.cjs.map +0 -1
  67. package/lib/esm/errors.js.map +0 -1
  68. /package/lib/types/{errors.d.cts → errors/IndexError.d.cts} +0 -0
  69. /package/lib/types/{errors.d.mts → errors/IndexError.d.mts} +0 -0
@@ -26,6 +26,8 @@ import { Constructor } from "@decaf-ts/decoration";
26
26
  * const page2 = await paginator.page(2);
27
27
  */
28
28
  export declare class CouchDBPaginator<M extends Model> extends Paginator<M, M[], MangoQuery> {
29
+ protected _bookmarks: Map<number, string>;
30
+ protected _knownLastPage?: number;
29
31
  /**
30
32
  * @description Creates a new CouchDBPaginator instance
31
33
  * @summary Initializes a paginator for CouchDB query results
@@ -35,6 +37,7 @@ export declare class CouchDBPaginator<M extends Model> extends Paginator<M, M[],
35
37
  * @param {Constructor<M>} clazz - The model constructor
36
38
  */
37
39
  constructor(adapter: CouchDBAdapter<any, any, any>, query: MangoQuery, size: number, clazz: Constructor<M>);
40
+ private isValidBookmark;
38
41
  /**
39
42
  * @description Prepares a query for pagination
40
43
  * @summary Modifies the raw query to include pagination parameters
@@ -1,8 +1,9 @@
1
- import { Adapter, AdapterFlags, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
1
+ import { Adapter, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
2
2
  import { MangoQuery, MangoSelector, ViewResponse } from "../types.d.cts";
3
3
  import { Model } from "@decaf-ts/decorator-validation";
4
4
  import { CouchDBViewMetadata } from "../views/types.d.cts";
5
5
  import { CouchDBAdapter } from "../adapter.d.cts";
6
+ import { CouchDBFlags } from "../types.d.cts";
6
7
  type CouchDBViewDescriptor = {
7
8
  ddoc: string;
8
9
  view: string;
@@ -42,7 +43,7 @@ type CouchDBAggregateInfo = {
42
43
  export declare class CouchDBStatement<M extends Model, A extends Adapter<any, any, MangoQuery, any>, R> extends Statement<M, A, R, MangoQuery> {
43
44
  protected manualAggregation?: CouchDBAggregateInfo;
44
45
  protected attributeTypeCache: Map<string, string | undefined>;
45
- constructor(adapter: A, overrides?: Partial<AdapterFlags>);
46
+ constructor(adapter: A, overrides?: Partial<CouchDBFlags>);
46
47
  /**
47
48
  * @description Builds a CouchDB Mango query from the statement
48
49
  * @summary Converts the statement's conditions, selectors, and options into a CouchDB Mango query
@@ -1,8 +1,9 @@
1
- import { Adapter, AdapterFlags, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
1
+ import { Adapter, Condition, ContextOf, SelectSelector, Statement, UnsupportedError, ViewKind } from "@decaf-ts/core";
2
2
  import { MangoQuery, MangoSelector, ViewResponse } from "../types.d.mts";
3
3
  import { Model } from "@decaf-ts/decorator-validation";
4
4
  import { CouchDBViewMetadata } from "../views/types.d.mts";
5
5
  import { CouchDBAdapter } from "../adapter.d.mts";
6
+ import { CouchDBFlags } from "../types.d.mts";
6
7
  type CouchDBViewDescriptor = {
7
8
  ddoc: string;
8
9
  view: string;
@@ -42,7 +43,7 @@ type CouchDBAggregateInfo = {
42
43
  export declare class CouchDBStatement<M extends Model, A extends Adapter<any, any, MangoQuery, any>, R> extends Statement<M, A, R, MangoQuery> {
43
44
  protected manualAggregation?: CouchDBAggregateInfo;
44
45
  protected attributeTypeCache: Map<string, string | undefined>;
45
- constructor(adapter: A, overrides?: Partial<AdapterFlags>);
46
+ constructor(adapter: A, overrides?: Partial<CouchDBFlags>);
46
47
  /**
47
48
  * @description Builds a CouchDB Mango query from the statement
48
49
  * @summary Converts the statement's conditions, selectors, and options into a CouchDB Mango query
@@ -2,3 +2,4 @@ export * from "./constants.d.cts";
2
2
  export * from "./Paginator.d.cts";
3
3
  export * from "./Statement.d.cts";
4
4
  export * from "./translate.d.cts";
5
+ export * from "./planner.d.cts";
@@ -2,3 +2,4 @@ export * from "./constants.d.mts";
2
2
  export * from "./Paginator.d.mts";
3
3
  export * from "./Statement.d.mts";
4
4
  export * from "./translate.d.mts";
5
+ export * from "./planner.d.mts";
@@ -0,0 +1,64 @@
1
+ import { OrderDirection } from "@decaf-ts/core";
2
+ import { Constructor } from "@decaf-ts/decoration";
3
+ import { MangoQuery, MangoSelector, SortOrder } from "../types.d.cts";
4
+ export type MangoIndexCandidate = {
5
+ name: string;
6
+ ddoc: string;
7
+ fields: string[];
8
+ direction?: OrderDirection;
9
+ source: "table" | "defaultQuery" | "index";
10
+ };
11
+ export type MangoIndexResolution = {
12
+ candidate: MangoIndexCandidate;
13
+ use_index: string | [string, string];
14
+ };
15
+ export type MangoPlannerLog = {
16
+ debug?: (message: string) => void;
17
+ warn?: (message: string) => void;
18
+ };
19
+ export type RequiredMangoIndexShape = {
20
+ tableName: string;
21
+ modelName: string;
22
+ equalityFields: string[];
23
+ rangeFields: string[];
24
+ sortFields: string[];
25
+ sortDirection?: OrderDirection;
26
+ requiredFields: string[];
27
+ };
28
+ export type ReversedIndexDeclaration = {
29
+ attribute: string;
30
+ compositions: string[];
31
+ directions: OrderDirection[];
32
+ name: string;
33
+ ddoc: string;
34
+ fields: Array<string | Record<string, OrderDirection>>;
35
+ decorator: string;
36
+ };
37
+ export declare function normalizeSortField(entry: SortOrder): {
38
+ field: string;
39
+ direction?: OrderDirection;
40
+ } | undefined;
41
+ export declare function getSortFields(query: MangoQuery): string[];
42
+ export declare function getSortDirection(query: MangoQuery): OrderDirection | undefined;
43
+ export declare function getEqualitySelectorFields(selector?: MangoSelector): Set<string>;
44
+ export declare function getRangeSelectorFields(selector?: MangoSelector): Set<string>;
45
+ export declare function buildGeneratedIndexCandidates(clazz: Constructor): MangoIndexCandidate[];
46
+ export declare function findGeneratedIndexCandidateByName(clazz: Constructor, expectedName: string): MangoIndexCandidate | undefined;
47
+ export declare function resolveGeneratedIndexForQuery(clazz: Constructor, query: MangoQuery, options?: {
48
+ preserveDefaultQuery?: boolean;
49
+ requireSortCoverage?: boolean;
50
+ }): MangoIndexResolution | undefined;
51
+ export declare function getRequiredMangoIndexShape(clazz: Constructor, query: MangoQuery): RequiredMangoIndexShape;
52
+ export declare function reverseRequiredShapeToIndexDeclaration(clazz: Constructor, query: MangoQuery): ReversedIndexDeclaration;
53
+ export declare function attachGeneratedUseIndex(clazz: Constructor | undefined, query: MangoQuery, log?: MangoPlannerLog, options?: {
54
+ preserveDefaultQuery?: boolean;
55
+ requireSortCoverage?: boolean;
56
+ requireIndex?: boolean;
57
+ forceNamedIndexes?: boolean;
58
+ }): void;
59
+ export declare function requireGeneratedUseIndex(clazz: Constructor, query: MangoQuery, log?: MangoPlannerLog, options?: {
60
+ requireSortCoverage?: boolean;
61
+ }): void;
62
+ export declare function warnScanProneMangoOperators(selector: unknown, log?: MangoPlannerLog, path?: string): void;
63
+ export declare function ensureDeterministicSort(query: MangoQuery, tieBreaker: string, direction?: OrderDirection): void;
64
+ export declare function enableMangoExecutionStats(query: MangoQuery): void;
@@ -0,0 +1,64 @@
1
+ import { OrderDirection } from "@decaf-ts/core";
2
+ import { Constructor } from "@decaf-ts/decoration";
3
+ import { MangoQuery, MangoSelector, SortOrder } from "../types.d.mts";
4
+ export type MangoIndexCandidate = {
5
+ name: string;
6
+ ddoc: string;
7
+ fields: string[];
8
+ direction?: OrderDirection;
9
+ source: "table" | "defaultQuery" | "index";
10
+ };
11
+ export type MangoIndexResolution = {
12
+ candidate: MangoIndexCandidate;
13
+ use_index: string | [string, string];
14
+ };
15
+ export type MangoPlannerLog = {
16
+ debug?: (message: string) => void;
17
+ warn?: (message: string) => void;
18
+ };
19
+ export type RequiredMangoIndexShape = {
20
+ tableName: string;
21
+ modelName: string;
22
+ equalityFields: string[];
23
+ rangeFields: string[];
24
+ sortFields: string[];
25
+ sortDirection?: OrderDirection;
26
+ requiredFields: string[];
27
+ };
28
+ export type ReversedIndexDeclaration = {
29
+ attribute: string;
30
+ compositions: string[];
31
+ directions: OrderDirection[];
32
+ name: string;
33
+ ddoc: string;
34
+ fields: Array<string | Record<string, OrderDirection>>;
35
+ decorator: string;
36
+ };
37
+ export declare function normalizeSortField(entry: SortOrder): {
38
+ field: string;
39
+ direction?: OrderDirection;
40
+ } | undefined;
41
+ export declare function getSortFields(query: MangoQuery): string[];
42
+ export declare function getSortDirection(query: MangoQuery): OrderDirection | undefined;
43
+ export declare function getEqualitySelectorFields(selector?: MangoSelector): Set<string>;
44
+ export declare function getRangeSelectorFields(selector?: MangoSelector): Set<string>;
45
+ export declare function buildGeneratedIndexCandidates(clazz: Constructor): MangoIndexCandidate[];
46
+ export declare function findGeneratedIndexCandidateByName(clazz: Constructor, expectedName: string): MangoIndexCandidate | undefined;
47
+ export declare function resolveGeneratedIndexForQuery(clazz: Constructor, query: MangoQuery, options?: {
48
+ preserveDefaultQuery?: boolean;
49
+ requireSortCoverage?: boolean;
50
+ }): MangoIndexResolution | undefined;
51
+ export declare function getRequiredMangoIndexShape(clazz: Constructor, query: MangoQuery): RequiredMangoIndexShape;
52
+ export declare function reverseRequiredShapeToIndexDeclaration(clazz: Constructor, query: MangoQuery): ReversedIndexDeclaration;
53
+ export declare function attachGeneratedUseIndex(clazz: Constructor | undefined, query: MangoQuery, log?: MangoPlannerLog, options?: {
54
+ preserveDefaultQuery?: boolean;
55
+ requireSortCoverage?: boolean;
56
+ requireIndex?: boolean;
57
+ forceNamedIndexes?: boolean;
58
+ }): void;
59
+ export declare function requireGeneratedUseIndex(clazz: Constructor, query: MangoQuery, log?: MangoPlannerLog, options?: {
60
+ requireSortCoverage?: boolean;
61
+ }): void;
62
+ export declare function warnScanProneMangoOperators(selector: unknown, log?: MangoPlannerLog, path?: string): void;
63
+ export declare function ensureDeterministicSort(query: MangoQuery, tieBreaker: string, direction?: OrderDirection): void;
64
+ export declare function enableMangoExecutionStats(query: MangoQuery): void;
@@ -1,3 +1,4 @@
1
+ import { AdapterFlags } from "@decaf-ts/core";
1
2
  /**
2
3
  * @description Response from a CouchDB Mango query
3
4
  * @summary Contains the matching documents and additional metadata about the query execution
@@ -164,3 +165,10 @@ export interface ViewResponse<D = any> {
164
165
  offset?: number;
165
166
  rows: ViewRow<D>[];
166
167
  }
168
+ export interface CouchDBFlags extends Partial<AdapterFlags> {
169
+ /**
170
+ * When true, non-default Mango queries try to attach a generated named index.
171
+ * Default-query index selection remains unchanged.
172
+ */
173
+ forceNamedIndexes?: boolean;
174
+ }
@@ -1,3 +1,4 @@
1
+ import { AdapterFlags } from "@decaf-ts/core";
1
2
  /**
2
3
  * @description Response from a CouchDB Mango query
3
4
  * @summary Contains the matching documents and additional metadata about the query execution
@@ -164,3 +165,10 @@ export interface ViewResponse<D = any> {
164
165
  offset?: number;
165
166
  rows: ViewRow<D>[];
166
167
  }
168
+ export interface CouchDBFlags extends Partial<AdapterFlags> {
169
+ /**
170
+ * When true, non-default Mango queries try to attach a generated named index.
171
+ * Default-query index selection remains unchanged.
172
+ */
173
+ forceNamedIndexes?: boolean;
174
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decaf-ts/for-couchdb",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "decaf-ts couchdb wrappers",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.js"],"names":[],"mappings":";;;AAAA,2DAAoD;AACpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,UAAW,SAAQ,yBAAS;IACrC,YAAY,GAAG;QACX,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;CACJ;AAJD,gCAIC;AACD,kCAAkC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,YAAY,GAAmB;QAC7B,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;CACF"}