@snowtop/ent 0.1.0-alpha116 → 0.1.0-alpha117

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/core/base.d.ts CHANGED
@@ -75,11 +75,11 @@ export interface SelectDataOptions extends SelectBaseDataOptions {
75
75
  }
76
76
  export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
77
77
  }
78
- export interface QueryDataOptions {
78
+ export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
79
79
  distinct?: boolean;
80
- clause: clause.Clause;
80
+ clause: clause.Clause<T, K>;
81
81
  orderby?: string;
82
- groupby?: string;
82
+ groupby?: K;
83
83
  limit?: number;
84
84
  disableTransformations?: boolean;
85
85
  }
package/core/clause.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export interface Clause {
1
+ import { Data } from "./base";
2
+ export interface Clause<T extends Data = Data, K = keyof T> {
2
3
  clause(idx: number): string;
3
- columns(): string[];
4
+ columns(): K[];
4
5
  values(): any[];
5
6
  instanceKey(): string;
6
7
  logValues(): any[];
@@ -10,38 +11,25 @@ export interface SensitiveValue {
10
11
  value(): any;
11
12
  logValue(): any;
12
13
  }
13
- declare class simpleClause implements Clause {
14
- protected col: string;
15
- private value;
16
- private op;
17
- private handleNull?;
18
- constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
19
- clause(idx: number): string;
20
- private nullClause;
21
- columns(): string[];
22
- values(): any[];
23
- logValues(): any[];
24
- instanceKey(): string;
25
- }
26
- export declare class inClause implements Clause {
14
+ export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
27
15
  private col;
28
16
  private value;
29
17
  private type;
30
18
  static getPostgresInClauseValuesThreshold(): number;
31
- constructor(col: string, value: any[], type?: string);
19
+ constructor(col: K, value: any[], type?: string);
32
20
  clause(idx: number): string;
33
- columns(): string[];
21
+ columns(): K[];
34
22
  values(): any[];
35
23
  logValues(): any[];
36
24
  instanceKey(): string;
37
25
  }
38
- declare class compositeClause implements Clause {
26
+ declare class compositeClause<T extends Data, K = keyof T> implements Clause<T, K> {
39
27
  private clauses;
40
28
  private sep;
41
29
  compositeOp: string;
42
- constructor(clauses: Clause[], sep: string);
30
+ constructor(clauses: Clause<T, K>[], sep: string);
43
31
  clause(idx: number): string;
44
- columns(): string[];
32
+ columns(): K[];
45
33
  values(): any[];
46
34
  logValues(): any[];
47
35
  instanceKey(): string;
@@ -51,92 +39,92 @@ declare class compositeClause implements Clause {
51
39
  * only works with postgres gin indexes
52
40
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
53
41
  */
54
- export declare function PostgresArrayContainsValue(col: string, value: any): Clause;
42
+ export declare function PostgresArrayContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
55
43
  /**
56
44
  * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
57
45
  * only works with postgres gin indexes
58
46
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
59
47
  */
60
- export declare function PostgresArrayContains(col: string, value: any[]): Clause;
48
+ export declare function PostgresArrayContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
61
49
  /**
62
50
  * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
63
51
  * only works with postgres gin indexes
64
52
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
65
53
  */
66
- export declare function PostgresArrayNotContainsValue(col: string, value: any): Clause;
54
+ export declare function PostgresArrayNotContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
67
55
  /**
68
56
  * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
69
57
  * only works with postgres gin indexes
70
58
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
71
59
  */
72
- export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
60
+ export declare function PostgresArrayNotContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
73
61
  /**
74
62
  * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
75
63
  * only works with postgres gin indexes
76
64
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
77
65
  */
78
- export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
66
+ export declare function PostgresArrayOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
79
67
  /**
80
68
  * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
81
69
  * only works with postgres gin indexes
82
70
  * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
83
71
  */
84
- export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
72
+ export declare function PostgresArrayNotOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
85
73
  /**
86
74
  * @deprecated use PostgresArrayContainsValue
87
75
  */
88
- export declare function ArrayEq(col: string, value: any): Clause;
76
+ export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
89
77
  /**
90
78
  * @deprecated use PostgresNotArrayContains
91
79
  */
92
- export declare function ArrayNotEq(col: string, value: any): Clause;
93
- export declare function Eq(col: string, value: any): Clause;
94
- export declare function NotEq(col: string, value: any): Clause;
95
- export declare function Greater(col: string, value: any): simpleClause;
96
- export declare function Less(col: string, value: any): simpleClause;
97
- export declare function GreaterEq(col: string, value: any): simpleClause;
98
- export declare function LessEq(col: string, value: any): simpleClause;
99
- export declare function And(...args: Clause[]): compositeClause;
100
- export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
101
- export declare function Or(...args: Clause[]): compositeClause;
102
- export declare function OrOptional(...args: (Clause | undefined)[]): Clause;
103
- export declare function In(col: string, ...values: any): Clause;
104
- export declare function In(col: string, values: any[], type?: string): Clause;
80
+ export declare function ArrayNotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
81
+ export declare function Eq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
82
+ export declare function NotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
83
+ export declare function Greater<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
84
+ export declare function Less<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
85
+ export declare function GreaterEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
86
+ export declare function LessEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
87
+ export declare function And<T extends Data, K = keyof T>(...args: Clause<T, K>[]): compositeClause<T, K>;
88
+ export declare function AndOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
89
+ export declare function Or<T extends Data, K = keyof T>(...args: Clause<T, K>[]): compositeClause<T, K>;
90
+ export declare function OrOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
91
+ export declare function In<T extends Data, K = keyof T>(col: K, ...values: any): Clause<T, K>;
92
+ export declare function In<T extends Data, K = keyof T>(col: K, values: any[], type?: string): Clause<T, K>;
105
93
  interface TsQuery {
106
94
  language: "english" | "french" | "german" | "simple";
107
95
  value: string;
108
96
  }
109
- export declare function TsQuery(col: string, val: string | TsQuery): Clause;
110
- export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
111
- export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
112
- export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
113
- export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
114
- export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
115
- export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
116
- export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
97
+ export declare function TsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
98
+ export declare function PlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
99
+ export declare function PhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
100
+ export declare function WebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
101
+ export declare function TsVectorColTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
102
+ export declare function TsVectorPlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
103
+ export declare function TsVectorPhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
104
+ export declare function TsVectorWebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
117
105
  export declare function sensitiveValue(val: any): SensitiveValue;
118
- export declare function JSONObjectFieldKeyASJSON(col: string, field: string): string;
119
- export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
106
+ export declare function JSONObjectFieldKeyASJSON<T extends Data, K = keyof T>(col: K, field: string): string;
107
+ export declare function JSONObjectFieldKeyAsText<T extends Data, K = keyof T>(col: K, field: string): string;
120
108
  type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
121
- export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
122
- declare class paginationMultipleColumnsSubQueryClause implements Clause {
109
+ export declare function JSONPathValuePredicate<T extends Data, K = keyof T>(dbCol: K, path: string, val: any, pred: predicate): Clause<T, K>;
110
+ declare class paginationMultipleColumnsSubQueryClause<T extends Data, K = keyof T> implements Clause<T, K> {
123
111
  private col;
124
112
  private op;
125
113
  private tableName;
126
114
  private uniqueCol;
127
115
  private val;
128
- constructor(col: string, op: string, tableName: string, uniqueCol: string, val: any);
116
+ constructor(col: K, op: string, tableName: string, uniqueCol: K, val: any);
129
117
  private buildSimpleQuery;
130
118
  clause(idx: number): string;
131
- columns(): string[];
119
+ columns(): K[];
132
120
  values(): any[];
133
121
  logValues(): any[];
134
122
  instanceKey(): string;
135
123
  }
136
- export declare function PaginationMultipleColsSubQuery(col: string, op: string, tableName: string, uniqueCol: string, val: any): paginationMultipleColumnsSubQueryClause;
137
- export declare function Add(col: string, value: any): Clause;
138
- export declare function Subtract(col: string, value: any): Clause;
139
- export declare function Multiply(col: string, value: any): Clause;
140
- export declare function Divide(col: string, value: any): Clause;
141
- export declare function Modulo(col: string, value: any): Clause;
124
+ export declare function PaginationMultipleColsSubQuery<T extends Data, K = keyof T>(col: K, op: string, tableName: string, uniqueCol: K, val: any): paginationMultipleColumnsSubQueryClause<Data, K>;
125
+ export declare function Add<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
126
+ export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
127
+ export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
128
+ export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
129
+ export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
142
130
  export {};
package/core/clause.js CHANGED
@@ -94,7 +94,7 @@ class isNullClause {
94
94
  constructor(col) {
95
95
  this.col = col;
96
96
  }
97
- clause(idx) {
97
+ clause(_idx) {
98
98
  return `${this.col} IS NULL`;
99
99
  }
100
100
  columns() {
package/core/ent.d.ts CHANGED
@@ -24,13 +24,13 @@ export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends
24
24
  * @deperecated use loadCustomEnts
25
25
  */
26
26
  export declare function loadEntsFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, clause: clause.Clause, options: LoadEntOptions<TEnt, TViewer>): Promise<Map<ID, TEnt>>;
27
- export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery): Promise<TEnt[]>;
27
+ export declare function loadCustomEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer, TQueryData extends Data = Data, TResultData extends Data = TQueryData, TKey = keyof TQueryData>(viewer: TViewer, options: LoadCustomEntOptions<TEnt, TViewer>, query: CustomQuery<TQueryData, TKey>): Promise<TEnt[]>;
28
28
  interface parameterizedQueryOptions {
29
29
  query: string;
30
30
  values?: any[];
31
31
  logValues?: any[];
32
32
  }
33
- export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
33
+ export type CustomQuery<T extends Data = Data, K = keyof T> = string | parameterizedQueryOptions | clause.Clause<T, K> | QueryDataOptions;
34
34
  /**
35
35
  * Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
36
36
  * either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
@@ -55,10 +55,10 @@ export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | Q
55
55
  * disableTransformations: false
56
56
  * }) // doesn't change the query
57
57
  */
58
- export declare function loadCustomData(options: SelectCustomDataOptions, query: CustomQuery, context: Context | undefined): Promise<Data[]>;
58
+ export declare function loadCustomData<TQueryData extends Data = Data, TResultData extends Data = TQueryData, K = keyof TQueryData>(options: SelectCustomDataOptions, query: CustomQuery<TQueryData, K>, context: Context | undefined): Promise<TResultData[]>;
59
59
  interface CustomCountOptions extends DataOptions {
60
60
  }
61
- export declare function loadCustomCount(options: CustomCountOptions, query: CustomQuery, context: Context | undefined): Promise<number>;
61
+ export declare function loadCustomCount<T extends Data = Data, K = keyof T>(options: CustomCountOptions, query: CustomQuery<T, K>, context: Context | undefined): Promise<number>;
62
62
  export declare function loadDerivedEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt | null>;
63
63
  export declare function loadDerivedEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, data: Data, loader: new (viewer: TViewer, data: Data) => TEnt): Promise<TEnt>;
64
64
  export declare function logQuery(query: string, logValues: any[]): void;
@@ -68,16 +68,16 @@ export declare function ___setLogQueryErrorWithError(val: boolean | undefined):
68
68
  export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
69
69
  export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
70
70
  export declare function buildQuery(options: QueryableDataOptions): string;
71
- interface GroupQueryOptions {
71
+ interface GroupQueryOptions<T extends Data, K = keyof T> {
72
72
  tableName: string;
73
- clause?: clause.Clause;
74
- groupColumn: string;
75
- fields: string[];
73
+ clause?: clause.Clause<T, K>;
74
+ groupColumn: K;
75
+ fields: K[];
76
76
  values: any[];
77
77
  orderby?: string;
78
78
  limit: number;
79
79
  }
80
- export declare function buildGroupQuery(options: GroupQueryOptions): [string, clause.Clause];
80
+ export declare function buildGroupQuery<T extends Data = Data, K = keyof T>(options: GroupQueryOptions<T, K>): [string, clause.Clause<T, K>];
81
81
  export interface DataOperation<T extends Ent = Ent> {
82
82
  preFetch?(queryer: Queryer, context?: Context): Promise<void>;
83
83
  performWriteSync(queryer: SyncQueryer, context?: Context): void;
@@ -217,7 +217,7 @@ interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
217
217
  export declare const DefaultLimit = 1000;
218
218
  export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
219
219
  export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
220
- cls: clause.Clause;
220
+ cls: clause.Clause<Data, string | number>;
221
221
  fields: string[];
222
222
  };
223
223
  export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
package/core/ent.js CHANGED
@@ -437,11 +437,13 @@ async function loadCustomDataImpl(options, query, context) {
437
437
  if (!optClause) {
438
438
  return cls;
439
439
  }
440
+ // @ts-expect-error string|ID mismatch
440
441
  return clause.And(cls, optClause);
441
442
  }
442
443
  if (typeof query === "string") {
443
444
  // no caching, perform raw query
444
445
  return performRawQuery(query, [], []);
446
+ // @ts-ignore
445
447
  }
446
448
  else if (isClause(query)) {
447
449
  // if a Clause is passed in and we have a default clause
@@ -451,6 +453,7 @@ async function loadCustomDataImpl(options, query, context) {
451
453
  // this will have rudimentary caching but nothing crazy
452
454
  return loadRows({
453
455
  ...options,
456
+ // @ts-ignore
454
457
  clause: getClause(query),
455
458
  context: context,
456
459
  });
@@ -462,6 +465,7 @@ async function loadCustomDataImpl(options, query, context) {
462
465
  else {
463
466
  let cls = query.clause;
464
467
  if (!query.disableTransformations) {
468
+ // @ts-ignore
465
469
  cls = getClause(cls);
466
470
  }
467
471
  // this will have rudimentary caching but nothing crazy
@@ -762,6 +766,7 @@ class EditNodeOperation {
762
766
  optionClause = opts.clause;
763
767
  }
764
768
  if (optionClause) {
769
+ // @ts-expect-error ID|string mismatch
765
770
  cls = clause.And(cls, optionClause);
766
771
  }
767
772
  }
@@ -45,6 +45,7 @@ async function loadRowsForLoader(options, ids, context) {
45
45
  optionClause = options.clause;
46
46
  }
47
47
  if (optionClause) {
48
+ // @ts-expect-error id/string mismatch
48
49
  cls = clause.And(cls, optionClause);
49
50
  }
50
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha116",
3
+ "version": "0.1.0-alpha117",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",