@snowtop/ent 0.1.0-alpha13 → 0.1.0-alpha130

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 (173) hide show
  1. package/action/action.d.ts +33 -29
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +8 -3
  5. package/action/experimental_action.d.ts +32 -22
  6. package/action/experimental_action.js +35 -9
  7. package/action/index.d.ts +2 -0
  8. package/action/index.js +7 -1
  9. package/action/orchestrator.d.ts +32 -15
  10. package/action/orchestrator.js +249 -53
  11. package/action/privacy.d.ts +2 -2
  12. package/action/relative_value.d.ts +47 -0
  13. package/action/relative_value.js +125 -0
  14. package/action/transaction.d.ts +10 -0
  15. package/action/transaction.js +23 -0
  16. package/auth/auth.d.ts +1 -1
  17. package/core/base.d.ts +61 -37
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +85 -40
  20. package/core/clause.js +375 -64
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -1
  23. package/core/const.d.ts +3 -0
  24. package/core/const.js +6 -0
  25. package/core/context.d.ts +6 -4
  26. package/core/context.js +20 -2
  27. package/core/convert.d.ts +1 -1
  28. package/core/date.js +1 -5
  29. package/core/db.d.ts +11 -8
  30. package/core/db.js +20 -8
  31. package/core/ent.d.ts +86 -30
  32. package/core/ent.js +626 -197
  33. package/core/global_schema.d.ts +7 -0
  34. package/core/global_schema.js +51 -0
  35. package/core/loaders/assoc_count_loader.d.ts +3 -2
  36. package/core/loaders/assoc_count_loader.js +10 -2
  37. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  38. package/core/loaders/assoc_edge_loader.js +8 -11
  39. package/core/loaders/index.d.ts +1 -1
  40. package/core/loaders/index.js +1 -3
  41. package/core/loaders/index_loader.d.ts +3 -3
  42. package/core/loaders/loader.d.ts +2 -2
  43. package/core/loaders/loader.js +5 -5
  44. package/core/loaders/object_loader.d.ts +32 -11
  45. package/core/loaders/object_loader.js +225 -78
  46. package/core/loaders/query_loader.d.ts +7 -13
  47. package/core/loaders/query_loader.js +52 -11
  48. package/core/loaders/raw_count_loader.d.ts +2 -2
  49. package/core/loaders/raw_count_loader.js +5 -1
  50. package/core/logger.d.ts +1 -1
  51. package/core/logger.js +1 -0
  52. package/core/privacy.d.ts +25 -24
  53. package/core/privacy.js +21 -25
  54. package/core/query/assoc_query.d.ts +7 -6
  55. package/core/query/assoc_query.js +9 -1
  56. package/core/query/custom_clause_query.d.ts +27 -0
  57. package/core/query/custom_clause_query.js +84 -0
  58. package/core/query/custom_query.d.ts +20 -5
  59. package/core/query/custom_query.js +87 -12
  60. package/core/query/index.d.ts +1 -0
  61. package/core/query/index.js +3 -1
  62. package/core/query/query.d.ts +8 -4
  63. package/core/query/query.js +101 -53
  64. package/core/query/shared_assoc_test.d.ts +2 -1
  65. package/core/query/shared_assoc_test.js +35 -45
  66. package/core/query/shared_test.d.ts +8 -1
  67. package/core/query/shared_test.js +470 -236
  68. package/core/viewer.d.ts +3 -3
  69. package/core/viewer.js +1 -1
  70. package/graphql/graphql.d.ts +51 -19
  71. package/graphql/graphql.js +160 -136
  72. package/graphql/graphql_field_helpers.d.ts +7 -1
  73. package/graphql/graphql_field_helpers.js +21 -1
  74. package/graphql/index.d.ts +2 -2
  75. package/graphql/index.js +3 -5
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/edge_connection.d.ts +9 -9
  78. package/graphql/query/page_info.d.ts +1 -1
  79. package/graphql/query/shared_assoc_test.js +1 -1
  80. package/graphql/query/shared_edge_connection.js +1 -19
  81. package/graphql/scalars/orderby_direction.d.ts +2 -0
  82. package/graphql/scalars/orderby_direction.js +15 -0
  83. package/imports/dataz/example1/_auth.js +128 -47
  84. package/imports/dataz/example1/_viewer.js +87 -39
  85. package/imports/index.d.ts +6 -1
  86. package/imports/index.js +19 -4
  87. package/index.d.ts +13 -5
  88. package/index.js +21 -7
  89. package/package.json +17 -17
  90. package/parse_schema/parse.d.ts +31 -9
  91. package/parse_schema/parse.js +155 -13
  92. package/schema/base_schema.d.ts +5 -3
  93. package/schema/base_schema.js +6 -0
  94. package/schema/field.d.ts +78 -21
  95. package/schema/field.js +231 -71
  96. package/schema/index.d.ts +2 -2
  97. package/schema/index.js +5 -1
  98. package/schema/json_field.d.ts +16 -4
  99. package/schema/json_field.js +32 -2
  100. package/schema/schema.d.ts +89 -19
  101. package/schema/schema.js +11 -13
  102. package/schema/struct_field.d.ts +15 -3
  103. package/schema/struct_field.js +117 -22
  104. package/schema/union_field.d.ts +1 -1
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +128 -31
  107. package/scripts/migrate_v0.1.js +36 -0
  108. package/scripts/move_types.js +120 -0
  109. package/scripts/read_schema.js +20 -5
  110. package/testutils/action/complex_schemas.d.ts +69 -0
  111. package/testutils/action/complex_schemas.js +398 -0
  112. package/testutils/builder.d.ts +41 -47
  113. package/testutils/builder.js +76 -49
  114. package/testutils/db/fixture.d.ts +10 -0
  115. package/testutils/db/fixture.js +26 -0
  116. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  117. package/testutils/db/{test_db.js → temp_db.js} +182 -45
  118. package/testutils/db/value.d.ts +7 -0
  119. package/testutils/db/value.js +251 -0
  120. package/testutils/db_mock.d.ts +16 -4
  121. package/testutils/db_mock.js +52 -7
  122. package/testutils/db_time_zone.d.ts +4 -0
  123. package/testutils/db_time_zone.js +41 -0
  124. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  125. package/testutils/ent-graphql-tests/index.js +52 -23
  126. package/testutils/fake_comms.js +1 -1
  127. package/testutils/fake_data/const.d.ts +2 -1
  128. package/testutils/fake_data/const.js +3 -0
  129. package/testutils/fake_data/fake_contact.d.ts +7 -3
  130. package/testutils/fake_data/fake_contact.js +13 -7
  131. package/testutils/fake_data/fake_event.d.ts +4 -1
  132. package/testutils/fake_data/fake_event.js +7 -6
  133. package/testutils/fake_data/fake_tag.d.ts +36 -0
  134. package/testutils/fake_data/fake_tag.js +89 -0
  135. package/testutils/fake_data/fake_user.d.ts +8 -5
  136. package/testutils/fake_data/fake_user.js +16 -15
  137. package/testutils/fake_data/index.js +5 -1
  138. package/testutils/fake_data/internal.d.ts +2 -0
  139. package/testutils/fake_data/internal.js +7 -1
  140. package/testutils/fake_data/tag_query.d.ts +13 -0
  141. package/testutils/fake_data/tag_query.js +43 -0
  142. package/testutils/fake_data/test_helpers.d.ts +11 -4
  143. package/testutils/fake_data/test_helpers.js +28 -12
  144. package/testutils/fake_data/user_query.d.ts +13 -6
  145. package/testutils/fake_data/user_query.js +54 -22
  146. package/testutils/fake_log.d.ts +3 -3
  147. package/testutils/fake_log.js +1 -1
  148. package/testutils/parse_sql.d.ts +6 -0
  149. package/testutils/parse_sql.js +16 -2
  150. package/testutils/test_edge_global_schema.d.ts +15 -0
  151. package/testutils/test_edge_global_schema.js +62 -0
  152. package/testutils/write.d.ts +2 -2
  153. package/testutils/write.js +33 -7
  154. package/tsc/ast.d.ts +25 -2
  155. package/tsc/ast.js +141 -17
  156. package/tsc/compilerOptions.js +5 -1
  157. package/tsc/move_generated.d.ts +1 -0
  158. package/tsc/move_generated.js +164 -0
  159. package/tsc/transform.d.ts +22 -0
  160. package/tsc/transform.js +181 -0
  161. package/tsc/transform_action.d.ts +22 -0
  162. package/tsc/transform_action.js +183 -0
  163. package/tsc/transform_ent.d.ts +17 -0
  164. package/tsc/transform_ent.js +60 -0
  165. package/tsc/transform_schema.d.ts +27 -0
  166. package/{scripts → tsc}/transform_schema.js +146 -117
  167. package/graphql/enums.d.ts +0 -3
  168. package/graphql/enums.js +0 -25
  169. package/scripts/move_generated.js +0 -142
  170. package/scripts/transform_code.js +0 -113
  171. package/scripts/transform_schema.d.ts +0 -1
  172. /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
  173. /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeConvertRelativeInputPlusExpressions = exports.convertRelativeInput = exports.NumberOps = void 0;
4
+ const clause_1 = require("../core/clause");
5
+ function addNumber(delta) {
6
+ return {
7
+ delta,
8
+ sqlExpression(col) {
9
+ return (0, clause_1.Add)(col, delta);
10
+ },
11
+ eval(curr) {
12
+ // @ts-expect-error
13
+ return curr + delta;
14
+ },
15
+ };
16
+ }
17
+ function subtractNumber(delta) {
18
+ return {
19
+ delta,
20
+ sqlExpression(col) {
21
+ return (0, clause_1.Subtract)(col, delta);
22
+ },
23
+ eval(curr) {
24
+ // @ts-expect-error
25
+ return curr - delta;
26
+ },
27
+ };
28
+ }
29
+ function multiplyNumber(delta) {
30
+ return {
31
+ delta,
32
+ sqlExpression(col) {
33
+ return (0, clause_1.Multiply)(col, delta);
34
+ },
35
+ eval(curr) {
36
+ // @ts-expect-error
37
+ return curr * delta;
38
+ },
39
+ };
40
+ }
41
+ function divideNumber(delta) {
42
+ return {
43
+ delta,
44
+ sqlExpression(col) {
45
+ return (0, clause_1.Divide)(col, delta);
46
+ },
47
+ eval(curr) {
48
+ // @ts-expect-error
49
+ return curr / delta;
50
+ },
51
+ };
52
+ }
53
+ function moduloNumber(delta) {
54
+ return {
55
+ delta,
56
+ sqlExpression(col) {
57
+ return (0, clause_1.Modulo)(col, delta);
58
+ },
59
+ eval(curr) {
60
+ // @ts-expect-error
61
+ return curr % delta;
62
+ },
63
+ };
64
+ }
65
+ exports.NumberOps = {
66
+ addNumber,
67
+ moduloNumber,
68
+ divideNumber,
69
+ subtractNumber,
70
+ multiplyNumber,
71
+ };
72
+ function convertRelativeInput(rel, col, existing) {
73
+ if (Object.keys(rel).length !== 1) {
74
+ throw new Error(`only 1 key is expected. ${Object.keys(rel).length} given`);
75
+ }
76
+ const ret = (relField) => {
77
+ return {
78
+ value: relField.eval(existing),
79
+ clause: relField.sqlExpression(col),
80
+ };
81
+ };
82
+ if (rel.add !== undefined) {
83
+ // @ts-expect-error
84
+ return ret(addNumber(rel.add));
85
+ }
86
+ if (rel.subtract !== undefined) {
87
+ // @ts-expect-error
88
+ return ret(subtractNumber(rel.subtract));
89
+ }
90
+ if (rel.multiply !== undefined) {
91
+ // @ts-expect-error
92
+ return ret(multiplyNumber(rel.multiply));
93
+ }
94
+ if (rel.divide !== undefined) {
95
+ // @ts-expect-error
96
+ return ret(divideNumber(rel.divide));
97
+ }
98
+ if (rel.modulo !== undefined) {
99
+ // @ts-expect-error
100
+ return ret(moduloNumber(rel.modulo));
101
+ }
102
+ throw new Error(`error in convertRelativeInput. shouldn't have gotten here`);
103
+ }
104
+ exports.convertRelativeInput = convertRelativeInput;
105
+ function maybeConvertRelativeInputPlusExpressions(rel, col, existing, expressions) {
106
+ if (rel === null) {
107
+ return rel;
108
+ }
109
+ if (rel === undefined) {
110
+ return rel;
111
+ }
112
+ if (typeof rel === "bigint" || typeof rel === "number") {
113
+ return rel;
114
+ }
115
+ // // TODO is this the behavior we want? should we coalesce as 0?
116
+ // if (existing === null) {
117
+ // throw new Error(`cannot perform a relative operation on null`);
118
+ // }
119
+ // @ts-ignore
120
+ // shouldn't be failing like it currently is. it thinks rel can be bigint and it shouldn't be???
121
+ const { clause, value } = convertRelativeInput(rel, col, existing);
122
+ expressions.set(col, clause);
123
+ return value;
124
+ }
125
+ exports.maybeConvertRelativeInputPlusExpressions = maybeConvertRelativeInputPlusExpressions;
@@ -0,0 +1,10 @@
1
+ import { Ent, Viewer } from "../core/base";
2
+ import { Action, Builder } from "./action";
3
+ type ActionAny = Action<Ent<Viewer<any, any>>, Builder<Ent<Viewer<any, any>>, Viewer<any, any>, any>, Viewer<any, any>, any, any>;
4
+ export declare class Transaction {
5
+ private viewer;
6
+ private actions;
7
+ constructor(viewer: Viewer, actions: ActionAny[]);
8
+ run(): Promise<void>;
9
+ }
10
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transaction = void 0;
4
+ const executor_1 = require("./executor");
5
+ class Transaction {
6
+ constructor(viewer,
7
+ // independent operations
8
+ actions) {
9
+ this.viewer = viewer;
10
+ this.actions = actions;
11
+ }
12
+ async run() {
13
+ const changesets = [];
14
+ await Promise.all(this.actions.map(async (action) => {
15
+ const c = await action.changeset();
16
+ changesets.push(c);
17
+ }));
18
+ const executor = new executor_1.ComplexExecutor(this.viewer, "", // no placeholder, no opers
19
+ [], new Map(), changesets);
20
+ await executor.execute();
21
+ }
22
+ }
23
+ exports.Transaction = Transaction;
package/auth/auth.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Viewer } from "../core/base";
3
3
  import { RequestContext } from "../core/context";
4
4
  import { IncomingMessage, ServerResponse } from "http";
5
- export declare type AuthViewer = Viewer | null;
5
+ export type AuthViewer = Viewer | null;
6
6
  export interface AuthHandler {
7
7
  authViewer(ctx: RequestContext): AuthViewer | Promise<AuthViewer>;
8
8
  }
package/core/base.d.ts CHANGED
@@ -1,23 +1,32 @@
1
1
  import * as clause from "./clause";
2
- export interface Loader<T, V> {
2
+ import { ObjectLoaderFactory } from "./loaders";
3
+ export interface Loader<K, V> {
3
4
  context?: Context;
4
- load(key: T): Promise<V>;
5
- loadMany?(keys: T[]): Promise<(V | null)[]>;
5
+ load(key: K): Promise<V>;
6
+ loadMany?(keys: K[]): Promise<(V | null)[]>;
6
7
  clearAll(): any;
7
8
  }
8
- export interface LoaderFactory<T, V> {
9
+ export interface LoaderWithLoadMany<T, V> extends Loader<T, V> {
10
+ loadMany(keys: T[]): Promise<V[]>;
11
+ }
12
+ export interface LoaderFactory<K, V> {
9
13
  name: string;
10
- createLoader(context?: Context): Loader<T, V>;
14
+ createLoader(context?: Context): Loader<K, V>;
15
+ }
16
+ interface LoaderFactoryWithLoaderMany<T, V> extends LoaderFactory<T, V> {
17
+ createLoader(context?: Context): LoaderWithLoadMany<T, V>;
11
18
  }
12
19
  export interface ConfigurableLoaderFactory<T, V> extends LoaderFactory<T, V> {
13
20
  createConfigurableLoader(options: EdgeQueryableDataOptions, context?: Context): Loader<T, V>;
14
21
  }
15
- export declare type EdgeQueryableDataOptions = Partial<Pick<QueryableDataOptions, "limit" | "orderby" | "clause">>;
16
- export interface PrimableLoader<T, V> extends Loader<T, V> {
17
- prime(d: Data): void;
22
+ export type EdgeQueryableDataOptions = Partial<Pick<QueryableDataOptions, "limit" | "orderby" | "clause">>;
23
+ export interface PrimableLoader<K, V> extends Loader<K, V> {
24
+ prime(d: V): void;
25
+ primeAll?(d: V): void;
18
26
  }
19
27
  interface cache {
20
- getLoader<T, V>(name: string, create: () => Loader<T, V>): Loader<T, V>;
28
+ getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
29
+ getLoaderWithLoadMany<K, V>(name: string, create: () => LoaderWithLoadMany<K, V>): LoaderWithLoadMany<K, V>;
21
30
  getCachedRows(options: queryOptions): Data[] | null;
22
31
  getCachedRow(options: queryOptions): Data | null;
23
32
  primeCache(options: queryOptions, rows: Data[]): void;
@@ -30,29 +39,30 @@ interface queryOptions {
30
39
  clause: clause.Clause;
31
40
  orderby?: string;
32
41
  }
33
- export interface Context {
34
- getViewer(): Viewer;
42
+ export interface Context<TViewer extends Viewer = Viewer> {
43
+ getViewer(): TViewer;
35
44
  cache?: cache;
36
45
  }
37
- export interface Viewer {
38
- viewerID: ID | null;
39
- viewer: () => Promise<Ent | null>;
46
+ export interface Viewer<TEnt extends any = Ent<any> | null, TID extends any = ID | null> {
47
+ viewerID: TID;
48
+ viewer: () => Promise<TEnt>;
40
49
  instanceKey: () => string;
41
- context?: Context;
50
+ context?: Context<any>;
42
51
  }
43
- export interface Ent {
52
+ export interface Ent<TViewer extends Viewer = Viewer> {
44
53
  id: ID;
45
- viewer: Viewer;
46
- getPrivacyPolicy(): PrivacyPolicy<this>;
54
+ viewer: TViewer;
55
+ getPrivacyPolicy(): PrivacyPolicy<this, TViewer>;
47
56
  nodeType: string;
57
+ __setRawDBData<T extends Data = Data>(data: T): any;
48
58
  }
49
59
  export declare type Data = {
50
60
  [key: string]: any;
51
61
  };
52
- export interface EntConstructor<T extends Ent> {
53
- new (viewer: Viewer, data: Data): T;
62
+ export interface EntConstructor<TEnt extends Ent, TViewer extends Viewer = Viewer> {
63
+ new (viewer: TViewer, data: Data): TEnt;
54
64
  }
55
- export declare type ID = string | number;
65
+ export type ID = string | number;
56
66
  export interface DataOptions {
57
67
  tableName: string;
58
68
  context?: Context;
@@ -66,12 +76,13 @@ export interface SelectDataOptions extends SelectBaseDataOptions {
66
76
  }
67
77
  export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
68
78
  }
69
- export interface QueryDataOptions {
79
+ export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
70
80
  distinct?: boolean;
71
- clause: clause.Clause;
81
+ clause: clause.Clause<T, K>;
72
82
  orderby?: string;
73
- groupby?: string;
83
+ groupby?: K;
74
84
  limit?: number;
85
+ disableTransformations?: boolean;
75
86
  }
76
87
  export interface LoadRowOptions extends QueryableDataOptions {
77
88
  }
@@ -82,24 +93,32 @@ export interface CreateRowOptions extends DataOptions {
82
93
  fieldsToLog?: Data;
83
94
  }
84
95
  export interface EditRowOptions extends CreateRowOptions {
85
- key: string;
96
+ whereClause: clause.Clause;
97
+ expressions?: Map<string, clause.Clause>;
98
+ }
99
+ interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> {
100
+ loaderFactory: ObjectLoaderFactory<TData>;
101
+ ent: EntConstructor<TEnt, TViewer>;
86
102
  }
87
- interface LoadableEntOptions<T extends Ent> {
88
- loaderFactory: LoaderFactory<any, Data | null>;
89
- ent: EntConstructor<T>;
103
+ export interface LoaderFactoryWithOptions<T extends Data = Data> extends LoaderFactoryWithLoaderMany<any, T | null> {
104
+ options?: SelectDataOptions;
90
105
  }
91
- export interface LoadEntOptions<T extends Ent> extends LoadableEntOptions<T>, SelectBaseDataOptions {
106
+ export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends LoadableEntOptions<TEnt, TViewer, TData>, SelectBaseDataOptions {
92
107
  fieldPrivacy?: Map<string, PrivacyPolicy>;
93
108
  }
94
- export interface LoadCustomEntOptions<T extends Ent> extends SelectBaseDataOptions {
95
- ent: EntConstructor<T>;
109
+ export interface SelectCustomDataOptions<T extends Data = Data> extends SelectBaseDataOptions {
110
+ loaderFactory: ObjectLoaderFactory<T>;
111
+ prime?: boolean;
112
+ }
113
+ export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer, TData extends Data = Data> extends SelectCustomDataOptions<TData> {
114
+ ent: EntConstructor<TEnt, TViewer>;
96
115
  fieldPrivacy?: Map<string, PrivacyPolicy>;
97
116
  }
98
- export interface LoaderInfo {
117
+ export interface LoaderInfo<T = Data> {
99
118
  tableName: string;
100
119
  fields: string[];
101
120
  nodeType: string;
102
- loaderFactory: LoaderFactory<any, Data | null>;
121
+ loaderFactory: LoaderFactory<ID, T | null>;
103
122
  }
104
123
  export interface EditEntOptions<T extends Ent> extends LoadableEntOptions<T>, EditRowOptions {
105
124
  }
@@ -121,10 +140,15 @@ export declare function Allow(): PrivacyResult;
121
140
  export declare function Skip(): PrivacyResult;
122
141
  export declare function Deny(): PrivacyResult;
123
142
  export declare function DenyWithReason(e: PrivacyError | string): PrivacyResult;
124
- export interface PrivacyPolicyRule<TEnt extends Ent = Ent> {
125
- apply(v: Viewer, ent?: TEnt): Promise<PrivacyResult>;
143
+ export interface PrivacyPolicyRule<TEnt extends Ent = Ent, TViewer = Viewer> {
144
+ apply(v: TViewer, ent?: TEnt): Promise<PrivacyResult>;
145
+ }
146
+ export interface PrivacyPolicy<TEnt extends Ent = Ent, TViewer = Viewer> {
147
+ rules: PrivacyPolicyRule<TEnt, TViewer>[];
126
148
  }
127
- export interface PrivacyPolicy<TEnt extends Ent = Ent> {
128
- rules: PrivacyPolicyRule<TEnt>[];
149
+ export declare enum WriteOperation {
150
+ Insert = "insert",
151
+ Edit = "edit",
152
+ Delete = "delete"
129
153
  }
130
154
  export {};
package/core/base.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DenyWithReason = exports.Deny = exports.Skip = exports.Allow = void 0;
3
+ exports.WriteOperation = exports.DenyWithReason = exports.Deny = exports.Skip = exports.Allow = void 0;
4
4
  // Privacy
5
5
  var privacyResult;
6
6
  (function (privacyResult) {
@@ -53,3 +53,9 @@ function DenyWithReason(e) {
53
53
  };
54
54
  }
55
55
  exports.DenyWithReason = DenyWithReason;
56
+ var WriteOperation;
57
+ (function (WriteOperation) {
58
+ WriteOperation["Insert"] = "insert";
59
+ WriteOperation["Edit"] = "edit";
60
+ WriteOperation["Delete"] = "delete";
61
+ })(WriteOperation = exports.WriteOperation || (exports.WriteOperation = {}));
package/core/clause.d.ts CHANGED
@@ -1,61 +1,106 @@
1
- export interface Clause {
1
+ import { Data, SelectDataOptions } from "./base";
2
+ export interface Clause<T extends Data = Data, K = keyof T> {
2
3
  clause(idx: number): string;
4
+ columns(): K[];
3
5
  values(): any[];
4
6
  instanceKey(): string;
5
7
  logValues(): any[];
8
+ compositeOp?: string;
6
9
  }
7
10
  export interface SensitiveValue {
8
11
  value(): any;
9
12
  logValue(): any;
10
13
  }
11
- declare class simpleClause implements Clause {
12
- protected col: string;
14
+ export declare class inClause<T extends Data, K = keyof T> implements Clause<T, K> {
15
+ private col;
13
16
  private value;
14
- private op;
15
- private handleSqliteNull?;
16
- constructor(col: string, value: any, op: string, handleSqliteNull?: Clause | undefined);
17
+ private type;
18
+ static getPostgresInClauseValuesThreshold(): number;
19
+ constructor(col: K, value: any[], type?: string);
17
20
  clause(idx: number): string;
18
- private sqliteNull;
21
+ columns(): K[];
19
22
  values(): any[];
20
23
  logValues(): any[];
21
24
  instanceKey(): string;
22
25
  }
23
- declare class compositeClause implements Clause {
24
- private clauses;
25
- private sep;
26
- constructor(clauses: Clause[], sep: string);
27
- clause(idx: number): string;
28
- values(): any[];
29
- logValues(): any[];
30
- instanceKey(): string;
31
- }
32
- export declare function ArrayEq(col: string, value: any): Clause;
33
- export declare function ArrayNotEq(col: string, value: any): Clause;
34
- export declare function ArrayGreater(col: string, value: any): Clause;
35
- export declare function ArrayLess(col: string, value: any): Clause;
36
- export declare function ArrayGreaterEq(col: string, value: any): Clause;
37
- export declare function ArrayLessEq(col: string, value: any): Clause;
38
- export declare function Eq(col: string, value: any): Clause;
39
- export declare function NotEq(col: string, value: any): Clause;
40
- export declare function Greater(col: string, value: any): simpleClause;
41
- export declare function Less(col: string, value: any): simpleClause;
42
- export declare function GreaterEq(col: string, value: any): simpleClause;
43
- export declare function LessEq(col: string, value: any): simpleClause;
44
- export declare function And(...args: Clause[]): compositeClause;
45
- export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
46
- export declare function Or(...args: Clause[]): compositeClause;
47
- export declare function In(col: string, ...values: any): Clause;
26
+ /**
27
+ * creates a clause to determine if the given value is contained in the array stored in the column in the db
28
+ * only works with postgres gin indexes
29
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
30
+ */
31
+ export declare function PostgresArrayContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
32
+ /**
33
+ * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
34
+ * only works with postgres gin indexes
35
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
36
+ */
37
+ export declare function PostgresArrayContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
38
+ /**
39
+ * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
40
+ * only works with postgres gin indexes
41
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
42
+ */
43
+ export declare function PostgresArrayNotContainsValue<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
44
+ /**
45
+ * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
46
+ * only works with postgres gin indexes
47
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
48
+ */
49
+ export declare function PostgresArrayNotContains<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
50
+ /**
51
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
52
+ * only works with postgres gin indexes
53
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
54
+ */
55
+ export declare function PostgresArrayOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
56
+ /**
57
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
58
+ * only works with postgres gin indexes
59
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
60
+ */
61
+ export declare function PostgresArrayNotOverlaps<T extends Data, K = keyof T>(col: K, value: any[]): Clause<T, K>;
62
+ /**
63
+ * @deprecated use PostgresArrayContainsValue
64
+ */
65
+ export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
66
+ /**
67
+ * @deprecated use PostgresNotArrayContains
68
+ */
69
+ export declare function ArrayNotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
70
+ export declare function Eq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
71
+ export declare function NotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
72
+ export declare function Greater<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
73
+ export declare function Less<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
74
+ export declare function GreaterEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
75
+ export declare function LessEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
76
+ export declare function And<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
77
+ export declare function AndOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
78
+ export declare function Or<T extends Data, K = keyof T>(...args: Clause<T, K>[]): Clause<T, K>;
79
+ export declare function OrOptional<T extends Data, K = keyof T>(...args: (Clause<T, K> | undefined)[]): Clause<T, K>;
80
+ export declare function In<T extends Data, K = keyof T>(col: K, ...values: any): Clause<T, K>;
81
+ export declare function In<T extends Data, K = keyof T>(col: K, values: any[], type?: string): Clause<T, K>;
48
82
  interface TsQuery {
49
83
  language: "english" | "french" | "german" | "simple";
50
84
  value: string;
51
85
  }
52
- export declare function TsQuery(col: string, val: string | TsQuery): Clause;
53
- export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
54
- export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
55
- export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
56
- export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
57
- export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
58
- export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
59
- export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
86
+ export declare function TsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
87
+ export declare function PlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
88
+ export declare function PhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
89
+ export declare function WebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
90
+ export declare function TsVectorColTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
91
+ export declare function TsVectorPlainToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
92
+ export declare function TsVectorPhraseToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
93
+ export declare function TsVectorWebsearchToTsQuery<T extends Data, K = keyof T>(col: K, val: string | TsQuery): Clause<T, K>;
60
94
  export declare function sensitiveValue(val: any): SensitiveValue;
95
+ export declare function JSONObjectFieldKeyASJSON<T extends Data, K = keyof T>(col: K, field: string): keyof T;
96
+ export declare function JSONObjectFieldKeyAsText<T extends Data, K = keyof T>(col: K, field: string): keyof T;
97
+ type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
98
+ export declare function JSONPathValuePredicate<T extends Data, K = keyof T>(dbCol: K, path: string, val: any, pred: predicate): Clause<T, K>;
99
+ export declare function PaginationMultipleColsSubQuery<T extends Data, K = keyof T>(col: K, op: string, tableName: string, uniqueCol: K, val: any): Clause<T, K>;
100
+ export declare function Add<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
101
+ export declare function Subtract<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
102
+ export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
103
+ export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
104
+ export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
105
+ export declare function getCombinedClause<V extends Data = Data, K = keyof V>(options: Omit<SelectDataOptions, "key">, cls: Clause<V, K>): Clause<V, K>;
61
106
  export {};