@snowtop/ent 0.1.0-alpha1 → 0.1.0-alpha100

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 (172) hide show
  1. package/action/action.d.ts +38 -30
  2. package/action/action.js +22 -7
  3. package/action/executor.d.ts +4 -4
  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 +48 -16
  10. package/action/orchestrator.js +343 -81
  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 +54 -27
  18. package/core/base.js +23 -1
  19. package/core/clause.d.ts +105 -3
  20. package/core/clause.js +563 -30
  21. package/core/config.d.ts +30 -1
  22. package/core/config.js +24 -1
  23. package/core/context.d.ts +5 -3
  24. package/core/context.js +20 -2
  25. package/core/convert.d.ts +1 -1
  26. package/core/date.js +1 -5
  27. package/core/db.d.ts +14 -11
  28. package/core/db.js +22 -8
  29. package/core/ent.d.ts +82 -28
  30. package/core/ent.js +692 -202
  31. package/core/loaders/assoc_count_loader.d.ts +3 -2
  32. package/core/loaders/assoc_count_loader.js +10 -2
  33. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  34. package/core/loaders/assoc_edge_loader.js +13 -15
  35. package/core/loaders/index.d.ts +1 -1
  36. package/core/loaders/index.js +1 -3
  37. package/core/loaders/index_loader.d.ts +2 -2
  38. package/core/loaders/index_loader.js +1 -0
  39. package/core/loaders/loader.js +5 -5
  40. package/core/loaders/object_loader.d.ts +13 -7
  41. package/core/loaders/object_loader.js +95 -32
  42. package/core/loaders/query_loader.d.ts +6 -12
  43. package/core/loaders/query_loader.js +52 -11
  44. package/core/loaders/raw_count_loader.d.ts +2 -2
  45. package/core/loaders/raw_count_loader.js +5 -1
  46. package/core/logger.d.ts +1 -1
  47. package/core/logger.js +1 -0
  48. package/core/privacy.d.ts +26 -25
  49. package/core/privacy.js +23 -24
  50. package/core/query/assoc_query.d.ts +7 -6
  51. package/core/query/assoc_query.js +9 -1
  52. package/core/query/custom_clause_query.d.ts +26 -0
  53. package/core/query/custom_clause_query.js +78 -0
  54. package/core/query/custom_query.d.ts +20 -5
  55. package/core/query/custom_query.js +87 -12
  56. package/core/query/index.d.ts +1 -0
  57. package/core/query/index.js +3 -1
  58. package/core/query/query.d.ts +8 -4
  59. package/core/query/query.js +101 -53
  60. package/core/query/shared_assoc_test.d.ts +2 -1
  61. package/core/query/shared_assoc_test.js +35 -45
  62. package/core/query/shared_test.d.ts +8 -1
  63. package/core/query/shared_test.js +469 -236
  64. package/core/viewer.d.ts +4 -3
  65. package/core/viewer.js +5 -1
  66. package/graphql/builtins/connection.js +3 -3
  67. package/graphql/builtins/edge.js +2 -2
  68. package/graphql/builtins/node.js +1 -1
  69. package/graphql/graphql.d.ts +17 -9
  70. package/graphql/graphql.js +47 -30
  71. package/graphql/index.d.ts +1 -1
  72. package/graphql/index.js +3 -4
  73. package/graphql/mutations/union.d.ts +2 -0
  74. package/graphql/mutations/union.js +35 -0
  75. package/graphql/node_resolver.d.ts +0 -1
  76. package/graphql/query/connection_type.d.ts +9 -9
  77. package/graphql/query/connection_type.js +6 -6
  78. package/graphql/query/edge_connection.d.ts +9 -9
  79. package/graphql/query/page_info.d.ts +1 -1
  80. package/graphql/query/page_info.js +4 -4
  81. package/graphql/query/shared_assoc_test.js +3 -3
  82. package/graphql/query/shared_edge_connection.js +1 -19
  83. package/graphql/scalars/time.d.ts +1 -1
  84. package/imports/index.d.ts +6 -1
  85. package/imports/index.js +19 -4
  86. package/index.d.ts +23 -1
  87. package/index.js +32 -6
  88. package/package.json +18 -17
  89. package/parse_schema/parse.d.ts +45 -8
  90. package/parse_schema/parse.js +193 -15
  91. package/schema/base_schema.d.ts +38 -1
  92. package/schema/base_schema.js +53 -2
  93. package/schema/field.d.ts +75 -21
  94. package/schema/field.js +185 -72
  95. package/schema/index.d.ts +4 -2
  96. package/schema/index.js +15 -2
  97. package/schema/json_field.d.ts +13 -1
  98. package/schema/json_field.js +28 -1
  99. package/schema/schema.d.ts +125 -10
  100. package/schema/schema.js +133 -5
  101. package/schema/struct_field.d.ts +27 -0
  102. package/schema/struct_field.js +138 -0
  103. package/schema/union_field.d.ts +23 -0
  104. package/schema/union_field.js +79 -0
  105. package/scripts/custom_compiler.js +10 -6
  106. package/scripts/custom_graphql.js +224 -36
  107. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  108. package/scripts/migrate_v0.1.js +36 -0
  109. package/scripts/move_types.d.ts +1 -0
  110. package/scripts/move_types.js +117 -0
  111. package/scripts/read_schema.js +35 -6
  112. package/testutils/action/complex_schemas.d.ts +69 -0
  113. package/testutils/action/complex_schemas.js +398 -0
  114. package/testutils/builder.d.ts +52 -49
  115. package/testutils/builder.js +143 -44
  116. package/testutils/context/test_context.d.ts +2 -2
  117. package/testutils/context/test_context.js +7 -1
  118. package/testutils/db/fixture.d.ts +10 -0
  119. package/testutils/db/fixture.js +26 -0
  120. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +26 -9
  121. package/testutils/db/{test_db.js → temp_db.js} +190 -46
  122. package/testutils/db/value.d.ts +7 -0
  123. package/testutils/db/value.js +251 -0
  124. package/testutils/db_mock.d.ts +16 -4
  125. package/testutils/db_mock.js +51 -6
  126. package/testutils/db_time_zone.d.ts +4 -0
  127. package/testutils/db_time_zone.js +41 -0
  128. package/testutils/ent-graphql-tests/index.d.ts +9 -1
  129. package/testutils/ent-graphql-tests/index.js +53 -25
  130. package/testutils/fake_data/const.d.ts +2 -1
  131. package/testutils/fake_data/const.js +3 -0
  132. package/testutils/fake_data/fake_contact.d.ts +10 -10
  133. package/testutils/fake_data/fake_contact.js +23 -21
  134. package/testutils/fake_data/fake_event.d.ts +8 -9
  135. package/testutils/fake_data/fake_event.js +25 -28
  136. package/testutils/fake_data/fake_tag.d.ts +36 -0
  137. package/testutils/fake_data/fake_tag.js +89 -0
  138. package/testutils/fake_data/fake_user.d.ts +10 -11
  139. package/testutils/fake_data/fake_user.js +20 -23
  140. package/testutils/fake_data/index.js +5 -1
  141. package/testutils/fake_data/internal.d.ts +2 -0
  142. package/testutils/fake_data/internal.js +7 -1
  143. package/testutils/fake_data/tag_query.d.ts +13 -0
  144. package/testutils/fake_data/tag_query.js +43 -0
  145. package/testutils/fake_data/test_helpers.d.ts +11 -4
  146. package/testutils/fake_data/test_helpers.js +29 -13
  147. package/testutils/fake_data/user_query.d.ts +13 -6
  148. package/testutils/fake_data/user_query.js +54 -22
  149. package/testutils/fake_log.d.ts +3 -3
  150. package/testutils/parse_sql.d.ts +6 -0
  151. package/testutils/parse_sql.js +16 -2
  152. package/testutils/test_edge_global_schema.d.ts +15 -0
  153. package/testutils/test_edge_global_schema.js +62 -0
  154. package/testutils/write.d.ts +2 -2
  155. package/testutils/write.js +33 -7
  156. package/tsc/ast.d.ts +44 -0
  157. package/tsc/ast.js +277 -0
  158. package/tsc/compilerOptions.d.ts +6 -0
  159. package/tsc/compilerOptions.js +45 -2
  160. package/tsc/move_generated.d.ts +1 -0
  161. package/tsc/move_generated.js +164 -0
  162. package/tsc/transform.d.ts +22 -0
  163. package/tsc/transform.js +181 -0
  164. package/tsc/transform_action.d.ts +22 -0
  165. package/tsc/transform_action.js +183 -0
  166. package/tsc/transform_ent.d.ts +17 -0
  167. package/tsc/transform_ent.js +59 -0
  168. package/tsc/transform_schema.d.ts +27 -0
  169. package/tsc/transform_schema.js +383 -0
  170. package/graphql/enums.d.ts +0 -3
  171. package/graphql/enums.js +0 -25
  172. package/scripts/transform_schema.js +0 -288
package/core/config.d.ts CHANGED
@@ -1,12 +1,28 @@
1
1
  /// <reference types="node" />
2
2
  import { Database, DBDict } from "./db";
3
- declare type logType = "query" | "warn" | "info" | "error" | "debug";
3
+ type logType = "query" | "warn" | "info" | "error" | "debug";
4
+ declare enum graphqlMutationName {
5
+ NOUN_VERB = "NounVerb",
6
+ VERB_NOUN = "VerbNoun"
7
+ }
8
+ declare enum graphQLFieldFormat {
9
+ LOWER_CAMEL = "lowerCamel",
10
+ SNAKE_CASE = "snake_case"
11
+ }
12
+ declare enum fieldPrivacyEvaluated {
13
+ AT_ENT_LOAD = "at_ent_load",
14
+ ON_DEMAND = "on_demand"
15
+ }
4
16
  export interface Config {
5
17
  dbConnectionString?: string;
6
18
  dbFile?: string;
7
19
  db?: Database | DBDict;
8
20
  log?: logType | logType[];
9
21
  codegen?: CodegenConfig;
22
+ logQueryWithError?: boolean;
23
+ customGraphQLJSONPath?: string;
24
+ dynamicScriptCustomGraphQLJSONPath?: string;
25
+ globalSchemaPath?: string;
10
26
  }
11
27
  interface CodegenConfig {
12
28
  defaultEntPolicy?: PrivacyConfig;
@@ -17,6 +33,14 @@ interface CodegenConfig {
17
33
  generatedHeader?: string;
18
34
  disableBase64Encoding?: boolean;
19
35
  generateRootResolvers?: boolean;
36
+ defaultGraphQLMutationName?: graphqlMutationName;
37
+ defaultGraphQLFieldFormat?: graphQLFieldFormat;
38
+ schemaSQLFilePath?: boolean;
39
+ databaseToCompareTo?: string;
40
+ fieldPrivacyEvaluated?: fieldPrivacyEvaluated;
41
+ templatizedViewer?: importedObject;
42
+ customAssocEdgePath?: importedObject;
43
+ globalImportPath?: string;
20
44
  }
21
45
  interface PrettierConfig {
22
46
  custom?: boolean;
@@ -27,5 +51,10 @@ interface PrivacyConfig {
27
51
  policyName: string;
28
52
  class?: boolean;
29
53
  }
54
+ interface importedObject {
55
+ path: string;
56
+ name: string;
57
+ alias?: string;
58
+ }
30
59
  export declare function loadConfig(file?: string | Buffer | Config): void;
31
60
  export {};
package/core/config.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -28,6 +32,24 @@ const js_yaml_1 = require("js-yaml");
28
32
  const db_1 = __importDefault(require("./db"));
29
33
  const path = __importStar(require("path"));
30
34
  const logger_1 = require("./logger");
35
+ const ent_1 = require("./ent");
36
+ // ent.config.ts eventually. for now ent.yml
37
+ // or ent.yml?
38
+ var graphqlMutationName;
39
+ (function (graphqlMutationName) {
40
+ graphqlMutationName["NOUN_VERB"] = "NounVerb";
41
+ graphqlMutationName["VERB_NOUN"] = "VerbNoun";
42
+ })(graphqlMutationName || (graphqlMutationName = {}));
43
+ var graphQLFieldFormat;
44
+ (function (graphQLFieldFormat) {
45
+ graphQLFieldFormat["LOWER_CAMEL"] = "lowerCamel";
46
+ graphQLFieldFormat["SNAKE_CASE"] = "snake_case";
47
+ })(graphQLFieldFormat || (graphQLFieldFormat = {}));
48
+ var fieldPrivacyEvaluated;
49
+ (function (fieldPrivacyEvaluated) {
50
+ fieldPrivacyEvaluated["AT_ENT_LOAD"] = "at_ent_load";
51
+ fieldPrivacyEvaluated["ON_DEMAND"] = "on_demand";
52
+ })(fieldPrivacyEvaluated || (fieldPrivacyEvaluated = {}));
31
53
  function setConfig(cfg) {
32
54
  if (cfg.log) {
33
55
  (0, logger_1.setLogLevels)(cfg.log);
@@ -39,6 +61,7 @@ function setConfig(cfg) {
39
61
  db: cfg.db,
40
62
  });
41
63
  }
64
+ (0, ent_1.___setLogQueryErrorWithError)(cfg.logQueryWithError);
42
65
  }
43
66
  function isBuffer(b) {
44
67
  return b.write !== undefined;
package/core/context.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  /// <reference types="node" />
2
- import { Viewer, Data, Loader } from "./base";
2
+ import { Viewer, Data, Loader, LoaderWithLoadMany } from "./base";
3
3
  import { IncomingMessage, ServerResponse } from "http";
4
4
  import * as clause from "./clause";
5
5
  import { Context } from "./base";
6
- export interface RequestContext extends Context {
7
- authViewer(viewer: Viewer): Promise<void>;
6
+ export interface RequestContext<TViewer extends Viewer = Viewer> extends Context<TViewer> {
7
+ authViewer(viewer: TViewer): Promise<void>;
8
8
  logout(): Promise<void>;
9
9
  request: IncomingMessage;
10
10
  response: ServerResponse;
11
11
  }
12
12
  export declare class ContextCache {
13
13
  loaders: Map<string, Loader<any, any>>;
14
+ loaderWithLoadMany: Map<string, LoaderWithLoadMany<any, any>>;
14
15
  getLoader<T, V>(name: string, create: () => Loader<T, V>): Loader<T, V>;
16
+ getLoaderWithLoadMany<T, V>(name: string, create: () => LoaderWithLoadMany<T, V>): LoaderWithLoadMany<T, V>;
15
17
  private itemMap;
16
18
  private listMap;
17
19
  private getkey;
package/core/context.js CHANGED
@@ -5,6 +5,8 @@ const logger_1 = require("./logger");
5
5
  class ContextCache {
6
6
  constructor() {
7
7
  this.loaders = new Map();
8
+ // we should eventually combine the two but better for typing to be separate for now
9
+ this.loaderWithLoadMany = new Map();
8
10
  // we have a per-table map to make it easier to purge and have less things to compare with
9
11
  this.itemMap = new Map();
10
12
  this.listMap = new Map();
@@ -19,6 +21,16 @@ class ContextCache {
19
21
  this.loaders.set(name, l);
20
22
  return l;
21
23
  }
24
+ getLoaderWithLoadMany(name, create) {
25
+ let l = this.loaderWithLoadMany.get(name);
26
+ if (l) {
27
+ return l;
28
+ }
29
+ (0, logger_1.log)("debug", `new context-aware loader created for ${name}`);
30
+ l = create();
31
+ this.loaderWithLoadMany.set(name, l);
32
+ return l;
33
+ }
22
34
  // tableName is ignored bcos already indexed on that
23
35
  // maybe we just want to store sql queries???
24
36
  getkey(options) {
@@ -39,7 +51,7 @@ class ContextCache {
39
51
  const key = this.getkey(options);
40
52
  let rows = m.get(key);
41
53
  if (rows) {
42
- (0, logger_1.log)("query", {
54
+ (0, logger_1.log)("cache", {
43
55
  "cache-hit": key,
44
56
  "tableName": options.tableName,
45
57
  });
@@ -54,7 +66,7 @@ class ContextCache {
54
66
  const key = this.getkey(options);
55
67
  let row = m.get(key);
56
68
  if (row) {
57
- (0, logger_1.log)("query", {
69
+ (0, logger_1.log)("cache", {
58
70
  "cache-hit": key,
59
71
  "tableName": options.tableName,
60
72
  });
@@ -79,7 +91,13 @@ class ContextCache {
79
91
  // but may have some benefits by explicitily doing so?
80
92
  loader.clearAll();
81
93
  }
94
+ for (const [_key, loader] of this.loaderWithLoadMany) {
95
+ // may not need this since we're clearing the loaders themselves...
96
+ // but may have some benefits by explicitily doing so?
97
+ loader.clearAll();
98
+ }
82
99
  this.loaders.clear();
100
+ this.loaderWithLoadMany.clear();
83
101
  this.itemMap.clear();
84
102
  this.listMap.clear();
85
103
  }
package/core/convert.d.ts CHANGED
@@ -10,5 +10,5 @@ export declare function convertBoolList(val: any): boolean[];
10
10
  export declare function convertNullableBoolList(val: any): boolean[] | null;
11
11
  export declare function convertJSON(val: any): any;
12
12
  export declare function convertNullableJSON(val: any): any | null;
13
- export declare function convertJSONList(val: any): boolean[];
13
+ export declare function convertJSONList(val: any): any[];
14
14
  export declare function convertNullableJSONList(val: any): any[] | null;
package/core/date.js CHANGED
@@ -10,11 +10,7 @@ function parseDate(val, throwErr) {
10
10
  else if (typeof val === "string") {
11
11
  dt = luxon_1.DateTime.fromISO(val);
12
12
  if (!dt.isValid) {
13
- let ms = Date.parse(val);
14
- if (ms === NaN) {
15
- throw throwErr(`invalid input for type Time ${val}`);
16
- }
17
- dt = luxon_1.DateTime.fromMillis(ms);
13
+ dt = luxon_1.DateTime.fromMillis(Date.parse(val));
18
14
  }
19
15
  }
20
16
  else if (val instanceof Date) {
package/core/db.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import { Pool, ClientConfig, PoolClient } from "pg";
2
- export interface Database {
1
+ import { Pool, PoolClient, PoolConfig } from "pg";
2
+ export interface Database extends PoolConfig {
3
3
  database?: string;
4
4
  user?: string;
5
5
  password?: string;
6
6
  host?: string;
7
7
  port?: number;
8
- ssl?: boolean;
9
8
  sslmode?: string;
10
9
  }
11
- export declare type env = "production" | "test" | "development";
10
+ export type env = "production" | "test" | "development";
12
11
  export declare type DBDict = Partial<Record<env, Database>>;
13
12
  export declare enum Dialect {
14
13
  Postgres = "postgres",
@@ -16,9 +15,14 @@ export declare enum Dialect {
16
15
  }
17
16
  interface DatabaseInfo {
18
17
  dialect: Dialect;
19
- config: ClientConfig;
18
+ config: PoolConfig;
20
19
  filePath?: string;
21
20
  }
21
+ interface clientConfigArgs {
22
+ connectionString?: string;
23
+ dbFile?: string;
24
+ db?: Database | DBDict;
25
+ }
22
26
  export default class DB {
23
27
  db: DatabaseInfo;
24
28
  static instance: DB;
@@ -29,15 +33,12 @@ export default class DB {
29
33
  getConnection(): Connection;
30
34
  getPool(): Queryer;
31
35
  getNewClient(): Promise<Client>;
32
- getSQLiteClient(): Promise<Sqlite>;
36
+ getSQLiteClient(): Sqlite;
33
37
  endPool(): Promise<void>;
38
+ emitsExplicitTransactionStatements(): boolean;
34
39
  static getInstance(): DB;
35
40
  static getDialect(): Dialect;
36
- static initDB(args?: {
37
- connectionString?: string;
38
- dbFile?: string;
39
- db?: Database | DBDict;
40
- }): void;
41
+ static initDB(args?: clientConfigArgs): void;
41
42
  }
42
43
  export declare const defaultTimestampParser: any;
43
44
  export interface Queryer {
@@ -54,6 +55,7 @@ export interface Connection extends Queryer {
54
55
  self(): Queryer;
55
56
  newClient(): Promise<Client>;
56
57
  close(): Promise<void>;
58
+ runInTransaction?(cb: () => void | Promise<void>): any;
57
59
  }
58
60
  export interface QueryResultRow {
59
61
  [column: string]: any;
@@ -78,6 +80,7 @@ interface SqliteRunResult {
78
80
  }
79
81
  interface SqliteDatabase {
80
82
  memory: boolean;
83
+ exec(query: string): SqliteStatement;
81
84
  prepare(query: string): SqliteStatement;
82
85
  close(): void;
83
86
  transaction(fn: (...params: any[]) => any): SqliteTransaction;
package/core/db.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -35,13 +39,16 @@ var Dialect;
35
39
  Dialect["Postgres"] = "postgres";
36
40
  Dialect["SQLite"] = "sqlite";
37
41
  })(Dialect = exports.Dialect || (exports.Dialect = {}));
38
- function parseConnectionString(str) {
42
+ function parseConnectionString(str, args) {
39
43
  if (str.startsWith("sqlite:///")) {
40
44
  let filePath = str.substr(10);
41
45
  return {
42
46
  dialect: Dialect.SQLite,
43
47
  config: {
44
48
  connectionString: str,
49
+ // TODO would like to do this for other args e.g. max being set but would have to update tests
50
+ // e.g. src/core/config.test.ts which tests this
51
+ // ...args?.db,
45
52
  },
46
53
  filePath,
47
54
  };
@@ -50,6 +57,9 @@ function parseConnectionString(str) {
50
57
  dialect: Dialect.Postgres,
51
58
  config: {
52
59
  connectionString: str,
60
+ // TODO would like to do this for other args e.g. max being set but would have to update tests
61
+ // e.g. src/core/config.test.ts which tests this
62
+ // ...args?.db,
53
63
  },
54
64
  };
55
65
  }
@@ -63,12 +73,12 @@ function getClientConfig(args) {
63
73
  // if there's a db connection string, use that first
64
74
  const str = process.env.DB_CONNECTION_STRING;
65
75
  if (str) {
66
- return parseConnectionString(str);
76
+ return parseConnectionString(str, args);
67
77
  }
68
78
  let file = "config/database.yml";
69
79
  if (args) {
70
80
  if (args.connectionString) {
71
- return parseConnectionString(args.connectionString);
81
+ return parseConnectionString(args.connectionString, args);
72
82
  }
73
83
  if (args.db) {
74
84
  let db;
@@ -109,6 +119,8 @@ function getClientConfig(args) {
109
119
  host: cfg.host,
110
120
  port: cfg.port,
111
121
  ssl: cfg.sslmode == "enable",
122
+ // max, min, etc
123
+ ...cfg,
112
124
  },
113
125
  };
114
126
  }
@@ -146,7 +158,7 @@ class DB {
146
158
  async getNewClient() {
147
159
  return this.q.newClient();
148
160
  }
149
- async getSQLiteClient() {
161
+ getSQLiteClient() {
150
162
  if (this.db.dialect == Dialect.Postgres) {
151
163
  throw new Error(`can't call getSQLiteClient when dialect is postgres`);
152
164
  }
@@ -156,6 +168,10 @@ class DB {
156
168
  async endPool() {
157
169
  return this.q.close();
158
170
  }
171
+ emitsExplicitTransactionStatements() {
172
+ const instance = DB.getInstance();
173
+ return instance.q.runInTransaction === undefined;
174
+ }
159
175
  // throws if invalid
160
176
  static getInstance() {
161
177
  if (DB.instance) {
@@ -190,8 +206,6 @@ exports.defaultTimestampParser = pg_1.default.types.getTypeParser(pg_1.default.t
190
206
  // it's parsed as UTC time as opposed to the local time
191
207
  pg_1.default.types.setTypeParser(pg_1.default.types.builtins.TIMESTAMP, function (val) {
192
208
  return luxon_1.DateTime.fromSQL(val + "Z").toJSDate();
193
- // let d = new Date(val + "Z");
194
- // return d;
195
209
  });
196
210
  class Sqlite {
197
211
  constructor(db) {
@@ -310,7 +324,7 @@ class Postgres {
310
324
  };
311
325
  }
312
326
  async close() {
313
- return this.pool.end();
327
+ return await this.pool.end();
314
328
  }
315
329
  }
316
330
  exports.Postgres = Postgres;
package/core/ent.d.ts CHANGED
@@ -1,32 +1,70 @@
1
1
  import { Queryer, SyncQueryer } from "./db";
2
- import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context, SelectBaseDataOptions, CreateRowOptions, QueryDataOptions, EntConstructor } from "./base";
2
+ import { Viewer, Ent, ID, LoadRowsOptions, LoadRowOptions, Data, DataOptions, QueryableDataOptions, EditRowOptions, LoadEntOptions, LoadCustomEntOptions, EdgeQueryableDataOptions, Context, CreateRowOptions, QueryDataOptions, SelectCustomDataOptions } from "./base";
3
3
  import { Executor } from "../action/action";
4
4
  import * as clause from "./clause";
5
5
  import { Builder } from "../action";
6
6
  import DataLoader from "dataloader";
7
- export declare function loadEnt<T extends Ent>(viewer: Viewer, id: ID, options: LoadEntOptions<T>): Promise<T | null>;
8
- export declare function loadEntViaKey<T extends Ent>(viewer: Viewer, key: any, options: LoadEntOptions<T>): Promise<T | null>;
9
- export declare function loadEntX<T extends Ent>(viewer: Viewer, id: ID, options: LoadEntOptions<T>): Promise<T>;
10
- export declare function loadEntXViaKey<T extends Ent>(viewer: Viewer, key: any, options: LoadEntOptions<T>): Promise<T>;
11
- export declare function loadEntFromClause<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, clause: clause.Clause): Promise<T | null>;
12
- export declare function loadEntXFromClause<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, clause: clause.Clause): Promise<T>;
13
- export declare function loadEnts<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, ...ids: ID[]): Promise<Map<ID, T>>;
14
- export declare function loadEntsList<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, ...ids: ID[]): Promise<T[]>;
15
- export declare function loadEntsFromClause<T extends Ent>(viewer: Viewer, clause: clause.Clause, options: LoadEntOptions<T>): Promise<Map<ID, T>>;
16
- export declare function loadCustomEnts<T extends Ent>(viewer: Viewer, options: LoadCustomEntOptions<T>, query: CustomQuery): Promise<T[]>;
17
- interface rawQueryOptions {
7
+ import { GlobalSchema } from "../schema/";
8
+ export declare function getEntKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): string;
9
+ export declare function loadEnt<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
10
+ export declare function loadEntViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
11
+ export declare function loadEntX<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id: ID, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
12
+ export declare function loadEntXViaKey<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, key: any, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt>;
13
+ /**
14
+ * @deprecated use loadCustomEnts
15
+ */
16
+ export declare function loadEntFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt | null>;
17
+ /**
18
+ * @deprecated use loadCustomEnts
19
+ */
20
+ export declare function loadEntXFromClause<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, clause: clause.Clause): Promise<TEnt>;
21
+ export declare function loadEnts<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<Map<ID, TEnt>>;
22
+ export declare function loadEntsList<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, ...ids: ID[]): Promise<TEnt[]>;
23
+ /**
24
+ * @deperecated use loadCustomEnts
25
+ */
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[]>;
28
+ interface parameterizedQueryOptions {
18
29
  query: string;
19
30
  values?: any[];
20
31
  logValues?: any[];
21
32
  }
22
- export declare type CustomQuery = string | rawQueryOptions | clause.Clause | QueryDataOptions;
23
- export declare function loadCustomData(options: SelectBaseDataOptions, query: CustomQuery, context: Context | undefined): Promise<Data[]>;
24
- export declare function loadDerivedEnt<T extends Ent>(viewer: Viewer, data: Data, loader: new (viewer: Viewer, data: Data) => T): Promise<T | null>;
25
- export declare function loadDerivedEntX<T extends Ent>(viewer: Viewer, data: Data, loader: new (viewer: Viewer, data: Data) => T): Promise<T>;
26
- export declare function applyPrivacyPolicyForEnt<T extends Ent>(viewer: Viewer, ent: T | null): Promise<T | null>;
27
- export declare function applyPrivacyPolicyForEntX<T extends Ent>(viewer: Viewer, ent: T): Promise<T>;
33
+ export type CustomQuery = string | parameterizedQueryOptions | clause.Clause | QueryDataOptions;
34
+ /**
35
+ * Note that if there's default read transformations (e.g. soft delete) and a clause is passed in
36
+ * either as Clause or QueryDataOptions without {disableTransformations: true}, the default transformation
37
+ * (e.g. soft delete) is applied.
38
+ *
39
+ * Passing a full SQL string or Paramterized SQL string doesn't apply it and the given string is sent to the
40
+ * database as written.
41
+ *
42
+ * e.g.
43
+ * Foo.loadCustom(opts, 'SELECT * FROM foo') // doesn't change the query
44
+ * Foo.loadCustom(opts, { query: 'SELECT * FROM foo WHERE id = ?', values: [1]}) // doesn't change the query
45
+ * Foo.loadCustom(opts, query.Eq('time', Date.now())) // changes the query
46
+ * Foo.loadCustom(opts, {
47
+ * clause: query.LessEq('time', Date.now()),
48
+ * limit: 100,
49
+ * orderby: 'time',
50
+ * }) // changes the query
51
+ * Foo.loadCustom(opts, {
52
+ * clause: query.LessEq('time', Date.now()),
53
+ * limit: 100,
54
+ * orderby: 'time',
55
+ * disableTransformations: false
56
+ * }) // doesn't change the query
57
+ */
58
+ export declare function loadCustomData(options: SelectCustomDataOptions, query: CustomQuery, context: Context | undefined): Promise<Data[]>;
59
+ interface CustomCountOptions extends DataOptions {
60
+ }
61
+ export declare function loadCustomCount(options: CustomCountOptions, query: CustomQuery, context: Context | undefined): Promise<number>;
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
+ 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
+ export declare function logQuery(query: string, logValues: any[]): void;
28
65
  export declare function loadRowX(options: LoadRowOptions): Promise<Data>;
29
66
  export declare function loadRow(options: LoadRowOptions): Promise<Data | null>;
67
+ export declare function ___setLogQueryErrorWithError(val: boolean | undefined): void;
30
68
  export declare function performRawQuery(query: string, values: any[], logValues?: any[]): Promise<Data[]>;
31
69
  export declare function loadRows(options: LoadRowsOptions): Promise<Data[]>;
32
70
  export declare function buildQuery(options: QueryableDataOptions): string;
@@ -52,8 +90,15 @@ export interface DataOperation<T extends Ent = Ent> {
52
90
  }
53
91
  export interface EditNodeOptions<T extends Ent> extends EditRowOptions {
54
92
  fieldsToResolve: string[];
55
- ent: EntConstructor<T>;
93
+ loadEntOptions: LoadEntOptions<T>;
56
94
  placeholderID?: ID;
95
+ key: string;
96
+ }
97
+ export declare class RawQueryOperation implements DataOperation {
98
+ private queries;
99
+ constructor(queries: (string | parameterizedQueryOptions)[]);
100
+ performWrite(queryer: Queryer, context?: Context): Promise<void>;
101
+ performWriteSync(queryer: SyncQueryer, context?: Context): void;
57
102
  }
58
103
  export declare class EditNodeOperation<T extends Ent> implements DataOperation {
59
104
  options: EditNodeOptions<T>;
@@ -69,7 +114,11 @@ export declare class EditNodeOperation<T extends Ent> implements DataOperation {
69
114
  returnedRow(): Data | null;
70
115
  createdEnt(viewer: Viewer): T | null;
71
116
  }
117
+ export declare function setGlobalSchema(val: GlobalSchema): void;
118
+ export declare function clearGlobalSchema(): void;
119
+ export declare function __hasGlobalSchema(): boolean;
72
120
  export declare class EdgeOperation implements DataOperation {
121
+ private builder;
73
122
  edgeInput: AssocEdgeInput;
74
123
  private options;
75
124
  private edgeData;
@@ -98,9 +147,9 @@ export declare class EdgeOperation implements DataOperation {
98
147
  export declare function buildInsertQuery(options: CreateRowOptions, suffix?: string): [string, string[], string[]];
99
148
  export declare function createRow(queryer: Queryer, options: CreateRowOptions, suffix: string): Promise<Data | null>;
100
149
  export declare function createRowSync(queryer: SyncQueryer, options: CreateRowOptions, suffix: string): Data | null;
101
- export declare function buildUpdateQuery(options: EditRowOptions, id: ID, suffix?: string): [string, any[], any[]];
102
- export declare function editRow(queryer: Queryer, options: EditRowOptions, id: ID, suffix?: string): Promise<Data | null>;
103
- export declare function editRowSync(queryer: SyncQueryer, options: EditRowOptions, id: ID, suffix?: string): Data | null;
150
+ export declare function buildUpdateQuery(options: EditRowOptions, suffix?: string): [string, any[], any[]];
151
+ export declare function editRow(queryer: Queryer, options: EditRowOptions, suffix?: string): Promise<Data | null>;
152
+ export declare function editRowSync(queryer: SyncQueryer, options: EditRowOptions, suffix?: string): Data | null;
104
153
  export declare function deleteRows(queryer: Queryer, options: DataOptions, cls: clause.Clause): Promise<void>;
105
154
  export declare function deleteRowsSync(queryer: SyncQueryer, options: DataOptions, cls: clause.Clause): void;
106
155
  export declare class DeleteNodeOperation implements DataOperation {
@@ -118,7 +167,9 @@ export declare class AssocEdge {
118
167
  id2Type: string;
119
168
  time: Date;
120
169
  data?: string | null;
170
+ private rawData;
121
171
  constructor(data: Data);
172
+ __getRawData(): Data;
122
173
  getCursor(): string;
123
174
  }
124
175
  interface cursorOptions {
@@ -147,7 +198,7 @@ export declare class AssocEdgeData {
147
198
  edgeTable: string;
148
199
  constructor(data: Data);
149
200
  }
150
- export declare const assocEdgeLoader: DataLoader<any, any, any>;
201
+ export declare const assocEdgeLoader: DataLoader<ID, Data | null, ID>;
151
202
  export declare function loadEdgeData(edgeType: string): Promise<AssocEdgeData | null>;
152
203
  export declare function loadEdgeDatas(...edgeTypes: string[]): Promise<Map<string, AssocEdgeData>>;
153
204
  export interface AssocEdgeConstructor<T extends AssocEdge> {
@@ -158,24 +209,27 @@ interface loadEdgesOptions {
158
209
  edgeType: string;
159
210
  context?: Context;
160
211
  queryOptions?: EdgeQueryableDataOptions;
212
+ disableTransformations?: boolean;
161
213
  }
162
214
  interface loadCustomEdgesOptions<T extends AssocEdge> extends loadEdgesOptions {
163
215
  ctr: AssocEdgeConstructor<T>;
164
216
  }
165
217
  export declare const DefaultLimit = 1000;
166
- export declare function defaultEdgeQueryOptions(id1: ID, edgeType: string): EdgeQueryableDataOptions;
167
218
  export declare function loadEdges(options: loadEdgesOptions): Promise<AssocEdge[]>;
219
+ export declare function getEdgeClauseAndFields(cls: clause.Clause, options: Pick<loadEdgesOptions, "disableTransformations">): {
220
+ cls: clause.Clause;
221
+ fields: string[];
222
+ };
168
223
  export declare function loadCustomEdges<T extends AssocEdge>(options: loadCustomEdgesOptions<T>): Promise<T[]>;
169
224
  export declare function loadUniqueEdge(options: loadEdgesOptions): Promise<AssocEdge | null>;
170
- export declare function loadUniqueNode<T extends Ent>(viewer: Viewer, id1: ID, edgeType: string, options: LoadEntOptions<T>): Promise<T | null>;
225
+ export declare function loadUniqueNode<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, id1: ID, edgeType: string, options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt | null>;
171
226
  export declare function loadRawEdgeCountX(options: loadEdgesOptions): Promise<number>;
172
227
  interface loadEdgeForIDOptions<T extends AssocEdge> extends loadCustomEdgesOptions<T> {
173
228
  id2: ID;
174
229
  }
175
230
  export declare function loadEdgeForID2<T extends AssocEdge>(options: loadEdgeForIDOptions<T>): Promise<T | undefined>;
176
231
  export declare function loadNodesByEdge<T extends Ent>(viewer: Viewer, id1: ID, edgeType: string, options: LoadEntOptions<T>): Promise<T[]>;
177
- export declare function applyPrivacyPolicyForRow<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, row: Data | null): Promise<T | null>;
178
- export declare function applyPrivacyPolicyForRowX<T extends Ent>(viewer: Viewer, options: LoadEntOptions<T>, row: Data): Promise<T>;
179
- export declare function applyPrivacyPolicyForRows<T extends Ent>(viewer: Viewer, rows: Data[], options: LoadEntOptions<T>): Promise<Map<ID, T>>;
232
+ export declare function applyPrivacyPolicyForRow<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, options: LoadEntOptions<TEnt, TViewer>, row: Data): Promise<TEnt | null>;
233
+ export declare function applyPrivacyPolicyForRows<TEnt extends Ent<TViewer>, TViewer extends Viewer>(viewer: TViewer, rows: Data[], options: LoadEntOptions<TEnt, TViewer>): Promise<TEnt[]>;
180
234
  export declare function getEdgeTypeInGroup<T extends string>(viewer: Viewer, id1: ID, id2: ID, m: Map<T, string>): Promise<[T, AssocEdge] | undefined>;
181
235
  export {};