@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101

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 (158) hide show
  1. package/action/action.d.ts +37 -31
  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 +40 -16
  10. package/action/orchestrator.js +230 -62
  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 +49 -26
  18. package/core/base.js +7 -1
  19. package/core/clause.d.ts +88 -7
  20. package/core/clause.js +355 -63
  21. package/core/config.d.ts +12 -1
  22. package/core/config.js +7 -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 +11 -8
  28. package/core/db.js +20 -8
  29. package/core/ent.d.ts +81 -25
  30. package/core/ent.js +636 -193
  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 +2 -2
  34. package/core/loaders/assoc_edge_loader.js +8 -11
  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/loader.js +5 -5
  39. package/core/loaders/object_loader.d.ts +6 -5
  40. package/core/loaders/object_loader.js +67 -59
  41. package/core/loaders/query_loader.d.ts +6 -12
  42. package/core/loaders/query_loader.js +52 -11
  43. package/core/loaders/raw_count_loader.d.ts +2 -2
  44. package/core/loaders/raw_count_loader.js +5 -1
  45. package/core/logger.d.ts +1 -1
  46. package/core/logger.js +1 -0
  47. package/core/privacy.d.ts +25 -24
  48. package/core/privacy.js +21 -25
  49. package/core/query/assoc_query.d.ts +7 -6
  50. package/core/query/assoc_query.js +9 -1
  51. package/core/query/custom_clause_query.d.ts +26 -0
  52. package/core/query/custom_clause_query.js +78 -0
  53. package/core/query/custom_query.d.ts +20 -5
  54. package/core/query/custom_query.js +87 -12
  55. package/core/query/index.d.ts +1 -0
  56. package/core/query/index.js +3 -1
  57. package/core/query/query.d.ts +8 -4
  58. package/core/query/query.js +101 -53
  59. package/core/query/shared_assoc_test.d.ts +2 -1
  60. package/core/query/shared_assoc_test.js +35 -45
  61. package/core/query/shared_test.d.ts +8 -1
  62. package/core/query/shared_test.js +469 -236
  63. package/core/viewer.d.ts +3 -3
  64. package/core/viewer.js +1 -1
  65. package/graphql/graphql.d.ts +14 -7
  66. package/graphql/graphql.js +23 -7
  67. package/graphql/index.d.ts +0 -1
  68. package/graphql/index.js +1 -4
  69. package/graphql/query/connection_type.d.ts +9 -9
  70. package/graphql/query/edge_connection.d.ts +9 -9
  71. package/graphql/query/page_info.d.ts +1 -1
  72. package/graphql/query/shared_assoc_test.js +1 -1
  73. package/graphql/query/shared_edge_connection.js +1 -19
  74. package/imports/index.d.ts +6 -1
  75. package/imports/index.js +19 -4
  76. package/index.d.ts +12 -5
  77. package/index.js +20 -7
  78. package/package.json +17 -16
  79. package/parse_schema/parse.d.ts +29 -9
  80. package/parse_schema/parse.js +118 -11
  81. package/schema/base_schema.d.ts +5 -3
  82. package/schema/base_schema.js +5 -0
  83. package/schema/field.d.ts +74 -20
  84. package/schema/field.js +174 -69
  85. package/schema/index.d.ts +2 -2
  86. package/schema/index.js +5 -1
  87. package/schema/json_field.d.ts +13 -1
  88. package/schema/json_field.js +28 -1
  89. package/schema/schema.d.ts +81 -18
  90. package/schema/schema.js +24 -17
  91. package/schema/struct_field.d.ts +11 -1
  92. package/schema/struct_field.js +57 -21
  93. package/scripts/custom_compiler.js +10 -6
  94. package/scripts/custom_graphql.js +117 -30
  95. package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
  96. package/scripts/migrate_v0.1.js +36 -0
  97. package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
  98. package/scripts/move_types.js +117 -0
  99. package/scripts/read_schema.js +20 -5
  100. package/testutils/action/complex_schemas.d.ts +69 -0
  101. package/testutils/action/complex_schemas.js +398 -0
  102. package/testutils/builder.d.ts +46 -47
  103. package/testutils/builder.js +108 -65
  104. package/testutils/db/fixture.d.ts +10 -0
  105. package/testutils/db/fixture.js +26 -0
  106. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
  107. package/testutils/db/{test_db.js → temp_db.js} +179 -44
  108. package/testutils/db/value.d.ts +7 -0
  109. package/testutils/db/value.js +251 -0
  110. package/testutils/db_mock.d.ts +16 -4
  111. package/testutils/db_mock.js +51 -6
  112. package/testutils/db_time_zone.d.ts +4 -0
  113. package/testutils/db_time_zone.js +41 -0
  114. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  115. package/testutils/ent-graphql-tests/index.js +27 -8
  116. package/testutils/fake_data/const.d.ts +2 -1
  117. package/testutils/fake_data/const.js +3 -0
  118. package/testutils/fake_data/fake_contact.d.ts +7 -3
  119. package/testutils/fake_data/fake_contact.js +15 -8
  120. package/testutils/fake_data/fake_event.d.ts +5 -2
  121. package/testutils/fake_data/fake_event.js +9 -7
  122. package/testutils/fake_data/fake_tag.d.ts +36 -0
  123. package/testutils/fake_data/fake_tag.js +89 -0
  124. package/testutils/fake_data/fake_user.d.ts +7 -4
  125. package/testutils/fake_data/fake_user.js +18 -16
  126. package/testutils/fake_data/index.js +5 -1
  127. package/testutils/fake_data/internal.d.ts +2 -0
  128. package/testutils/fake_data/internal.js +7 -1
  129. package/testutils/fake_data/tag_query.d.ts +13 -0
  130. package/testutils/fake_data/tag_query.js +43 -0
  131. package/testutils/fake_data/test_helpers.d.ts +11 -4
  132. package/testutils/fake_data/test_helpers.js +28 -12
  133. package/testutils/fake_data/user_query.d.ts +13 -6
  134. package/testutils/fake_data/user_query.js +54 -22
  135. package/testutils/fake_log.d.ts +3 -3
  136. package/testutils/parse_sql.d.ts +6 -0
  137. package/testutils/parse_sql.js +16 -2
  138. package/testutils/test_edge_global_schema.d.ts +15 -0
  139. package/testutils/test_edge_global_schema.js +62 -0
  140. package/testutils/write.d.ts +2 -2
  141. package/testutils/write.js +33 -7
  142. package/tsc/ast.d.ts +26 -2
  143. package/tsc/ast.js +163 -17
  144. package/tsc/compilerOptions.d.ts +2 -1
  145. package/tsc/compilerOptions.js +11 -2
  146. package/tsc/move_generated.d.ts +1 -0
  147. package/tsc/move_generated.js +164 -0
  148. package/tsc/transform.d.ts +22 -0
  149. package/tsc/transform.js +181 -0
  150. package/tsc/transform_action.d.ts +22 -0
  151. package/tsc/transform_action.js +183 -0
  152. package/tsc/transform_ent.d.ts +17 -0
  153. package/tsc/transform_ent.js +59 -0
  154. package/tsc/transform_schema.d.ts +27 -0
  155. package/{scripts → tsc}/transform_schema.js +145 -119
  156. package/graphql/enums.d.ts +0 -3
  157. package/graphql/enums.js +0 -25
  158. package/scripts/transform_code.js +0 -114
@@ -29,7 +29,11 @@ var queryType;
29
29
  queryType[queryType["BEGIN"] = 3] = "BEGIN";
30
30
  queryType[queryType["COMMIT"] = 4] = "COMMIT";
31
31
  queryType[queryType["ROLLBACK"] = 5] = "ROLLBACK";
32
+ queryType[queryType["DELETE"] = 6] = "DELETE";
32
33
  })(queryType = exports.queryType || (exports.queryType = {}));
34
+ /**
35
+ * @deprecated
36
+ */
33
37
  class QueryRecorder {
34
38
  // TODO kill use AST or just throw away
35
39
  static getQueryStructure(query) {
@@ -76,6 +80,36 @@ class QueryRecorder {
76
80
  };
77
81
  }
78
82
  }
83
+ if (/^DELETE/.test(query)) {
84
+ // regex can't do returning
85
+ let execArray = /^DELETE FROM (.+) WHERE (.+) /.exec(query);
86
+ if (execArray) {
87
+ return {
88
+ tableName: execArray[1],
89
+ whereClause: execArray[2],
90
+ type: queryType.DELETE,
91
+ query: execArray[0],
92
+ };
93
+ }
94
+ }
95
+ if (/^BEGIN/.test(query)) {
96
+ return {
97
+ type: queryType.BEGIN,
98
+ query: query,
99
+ };
100
+ }
101
+ if (/^COMMIT/.test(query)) {
102
+ return {
103
+ type: queryType.COMMIT,
104
+ query: query,
105
+ };
106
+ }
107
+ if (/^ROLLBACK/.test(query)) {
108
+ return {
109
+ type: queryType.ROLLBACK,
110
+ query: query,
111
+ };
112
+ }
79
113
  return null;
80
114
  }
81
115
  static recordQuery(query, values) {
@@ -131,7 +165,12 @@ class QueryRecorder {
131
165
  static getCurrentQueries() {
132
166
  return QueryRecorder.queries;
133
167
  }
134
- static validateQueryStructuresFromLogs(ml, expected, skipSelect) {
168
+ /**
169
+ * @deprecated will keep this since it's just using ml.logs
170
+ * which we still want around (I think) but we should eventually
171
+ * probably stop using this
172
+ */
173
+ static validateQueryStructuresFromLogs(ml, expected, opts) {
135
174
  const queries = ml.logs.map((log) => {
136
175
  const qs = QueryRecorder.getQueryStructure(log.query);
137
176
  if (!qs) {
@@ -142,12 +181,16 @@ class QueryRecorder {
142
181
  qs,
143
182
  };
144
183
  });
145
- QueryRecorder.validateQuryStructuresImpl(expected, queries, skipSelect);
184
+ QueryRecorder.validateQueryStructuresImpl(expected, queries, opts);
146
185
  }
147
- static validateQuryStructuresImpl(expected, queries, skipSelect) {
148
- if (skipSelect) {
186
+ static validateQueryStructuresImpl(expected, queries, opts) {
187
+ if (opts?.skipSelect) {
149
188
  queries = queries.filter((query) => query.qs?.type !== queryType.SELECT);
150
189
  }
190
+ if (!opts?.flagBeginCommit) {
191
+ queries = queries.filter((query) => query.qs?.type !== queryType.BEGIN &&
192
+ query.qs?.type !== queryType.COMMIT);
193
+ }
151
194
  // console.log(queries, expected);
152
195
  expect(queries.length).toBe(expected.length);
153
196
  for (let i = 0; i < expected.length; i++) {
@@ -167,7 +210,7 @@ class QueryRecorder {
167
210
  expect(query.values).toBe(undefined);
168
211
  break;
169
212
  case queryType.SELECT:
170
- if (!skipSelect) {
213
+ if (!opts?.skipSelect) {
171
214
  console.error("validating select query structure not supported yet");
172
215
  }
173
216
  // TODO INSERT and UPDATE tests here...
@@ -185,7 +228,9 @@ class QueryRecorder {
185
228
  }
186
229
  }
187
230
  static mockPool(pool) {
188
- const mockedPool = (0, jest_mock_1.mocked)(pool, true);
231
+ const mockedPool = (0, jest_mock_1.mocked)(pool);
232
+ // @ts-ignore
233
+ // TODO what changed in mockImplementation?
189
234
  mockedPool.mockImplementation(() => {
190
235
  return {
191
236
  totalCount: 1,
@@ -0,0 +1,4 @@
1
+ export declare class DBTimeZone {
2
+ private static getVal;
3
+ static getDateOffset(d: Date): Promise<string>;
4
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DBTimeZone = void 0;
7
+ const luxon_1 = require("luxon");
8
+ const schema_1 = require("../schema");
9
+ const db_1 = __importDefault(require("../core/db"));
10
+ let dbCurrentZone = undefined;
11
+ class DBTimeZone {
12
+ static async getVal() {
13
+ if (dbCurrentZone !== undefined) {
14
+ return dbCurrentZone;
15
+ }
16
+ const r = await db_1.default.getInstance()
17
+ .getPool()
18
+ .query("SELECT current_setting('TIMEZONE');");
19
+ if (r.rows.length) {
20
+ dbCurrentZone = r.rows[0].current_setting;
21
+ }
22
+ else {
23
+ dbCurrentZone = null;
24
+ }
25
+ return dbCurrentZone;
26
+ }
27
+ static async getDateOffset(d) {
28
+ let zone = await DBTimeZone.getVal();
29
+ let dt = luxon_1.DateTime.fromJSDate(d);
30
+ if (zone) {
31
+ dt = dt.setZone(zone);
32
+ }
33
+ // use
34
+ const val = (0, schema_1.leftPad)(dt.get("offset") / 60);
35
+ if (val == "00") {
36
+ return "+00";
37
+ }
38
+ return val;
39
+ }
40
+ }
41
+ exports.DBTimeZone = DBTimeZone;
@@ -2,7 +2,7 @@ import { Express, RequestHandler } from "express";
2
2
  import { Viewer } from "../../core/base";
3
3
  import { GraphQLSchema } from "graphql";
4
4
  import supertest from "supertest";
5
- export declare type Option = [string, any];
5
+ export type Option = [string, any];
6
6
  interface queryConfig {
7
7
  viewer?: Viewer;
8
8
  init?: (app: Express) => void;
@@ -11,6 +11,12 @@ interface queryConfig {
11
11
  headers?: object;
12
12
  debugMode?: boolean;
13
13
  args: {};
14
+ extraVariables?: {
15
+ [key: string]: {
16
+ graphqlType: string;
17
+ value: string;
18
+ };
19
+ };
14
20
  expectedStatus?: number;
15
21
  expectedError?: string | RegExp;
16
22
  callback?: (res: supertest.Response) => void;
@@ -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];
@@ -31,6 +35,7 @@ const graphql_1 = require("graphql");
31
35
  const auth_1 = require("../../auth");
32
36
  const supertest_1 = __importDefault(require("supertest"));
33
37
  const fs = __importStar(require("fs"));
38
+ const util_1 = require("util");
34
39
  function server(config) {
35
40
  const viewer = config.viewer;
36
41
  if (viewer) {
@@ -45,6 +50,7 @@ function server(config) {
45
50
  if (config.init) {
46
51
  config.init(app);
47
52
  }
53
+ // @ts-ignore something changed. come back
48
54
  app.use(express_1.default.json());
49
55
  let handlers = config.customHandlers || [];
50
56
  handlers.push(async (req, res) => {
@@ -56,9 +62,11 @@ function server(config) {
56
62
  request: req,
57
63
  schema: config.schema,
58
64
  contextFactory: async (executionContext) => {
65
+ // @ts-ignore something changed. come back
59
66
  return (0, auth_1.buildContext)(req, res);
60
67
  },
61
68
  });
69
+ // @ts-ignore something changed. come back
62
70
  await (0, graphql_helix_1.sendResult)(result, res);
63
71
  });
64
72
  app.use(config.graphQLPath || "/graphql", ...handlers);
@@ -108,17 +116,23 @@ function makeGraphQLRequest(config, query, fieldArgs) {
108
116
  }
109
117
  }
110
118
  });
119
+ let variables = {
120
+ ...config.args,
121
+ };
122
+ for (const k in config.extraVariables) {
123
+ variables[k] = config.extraVariables[k].value;
124
+ }
111
125
  if (files.size) {
112
126
  let ret = test
113
127
  .post(config.graphQLPath || "/graphql")
114
128
  .set(config.headers || {});
115
129
  ret.field("operations", JSON.stringify({
116
130
  query: query,
117
- variables: config.args,
131
+ variables: variables,
118
132
  }));
119
133
  let m = {};
120
134
  let idx = 0;
121
- for (const [key, val] of files) {
135
+ for (const [key] of files) {
122
136
  m[idx] = [`variables.${key}`];
123
137
  idx++;
124
138
  }
@@ -141,7 +155,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
141
155
  .set(config.headers || {})
142
156
  .send({
143
157
  query: query,
144
- variables: JSON.stringify(config.args),
158
+ variables: JSON.stringify(variables),
145
159
  }),
146
160
  ];
147
161
  }
@@ -157,7 +171,7 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
157
171
  let parts = [];
158
172
  let match = fragmentRegex.exec(path);
159
173
  if (match) {
160
- // fragment, keep the part of the fragment e.g. ...onUser, and then split the rest....
174
+ // fragment, keep the part of the fragment e.g. `...on User`, and then split the rest....
161
175
  parts = [match[0], ...match[2].split(".")];
162
176
  const typ = schema.getType(match[1]);
163
177
  if (!typ) {
@@ -216,7 +230,7 @@ function buildTreeFromQueryPaths(schema, fieldType, ...options) {
216
230
  }
217
231
  // only spread out if an object
218
232
  const [typ, _] = getInnerType(subField.type, true);
219
- return (0, graphql_1.isScalarType)(typ);
233
+ return (0, graphql_1.isScalarType)(typ) || (0, graphql_1.isEnumType)(typ);
220
234
  }
221
235
  if (i === parts.length - 1 && typeof option[1] === "object") {
222
236
  if (!isScalarField(part)) {
@@ -302,13 +316,18 @@ async function expectFromRoot(config, ...options) {
302
316
  let fieldArgs = field.args;
303
317
  let queryParams = [];
304
318
  fieldArgs.forEach((fieldArg) => {
305
- let arg = config.args[fieldArg.name];
319
+ const arg = config.args[fieldArg.name];
306
320
  // let the graphql runtime handle this (it may be optional for example)
307
321
  if (arg === undefined) {
308
322
  return;
309
323
  }
310
324
  queryParams.push(`$${fieldArg.name}: ${fieldArg.type}`);
311
325
  });
326
+ // add extra variables in queryArgs...
327
+ for (const key in config.extraVariables) {
328
+ const v = config.extraVariables[key];
329
+ queryParams.push(`$${key}: ${v.graphqlType}`);
330
+ }
312
331
  let params = [];
313
332
  for (let key in config.args) {
314
333
  params.push(`${key}: $${key}`);
@@ -347,7 +366,7 @@ async function expectFromRoot(config, ...options) {
347
366
  let [st, temp] = makeGraphQLRequest(config, q, fieldArgs);
348
367
  const res = await temp.expect("Content-Type", /json/);
349
368
  if (config.debugMode) {
350
- console.log(res.body);
369
+ console.log((0, util_1.inspect)(res.body, false, 3));
351
370
  }
352
371
  // if there's a callback, let everything be done there and we're done
353
372
  if (config.callback) {
@@ -18,7 +18,8 @@ export declare enum EdgeType {
18
18
  export declare enum NodeType {
19
19
  FakeUser = "user",
20
20
  FakeContact = "contact",
21
- FakeEvent = "event"
21
+ FakeEvent = "event",
22
+ FakeTag = "tag"
22
23
  }
23
24
  export declare const SymmetricEdges: Set<string>;
24
25
  export declare const InverseEdges: Map<EdgeType, EdgeType>;
@@ -27,6 +27,7 @@ var NodeType;
27
27
  NodeType["FakeUser"] = "user";
28
28
  NodeType["FakeContact"] = "contact";
29
29
  NodeType["FakeEvent"] = "event";
30
+ NodeType["FakeTag"] = "tag";
30
31
  })(NodeType = exports.NodeType || (exports.NodeType = {}));
31
32
  exports.SymmetricEdges = new Set();
32
33
  exports.SymmetricEdges.add(EdgeType.UserToFriends);
@@ -48,6 +49,8 @@ function getLoaderOptions(type) {
48
49
  return internal_1.FakeUser.loaderOptions();
49
50
  case NodeType.FakeEvent:
50
51
  return internal_1.FakeEvent.loaderOptions();
52
+ case NodeType.FakeTag:
53
+ return internal_1.FakeTag.loaderOptions();
51
54
  }
52
55
  }
53
56
  exports.getLoaderOptions = getLoaderOptions;
@@ -1,4 +1,4 @@
1
- import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
1
+ import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy, Context } from "../../core/base";
2
2
  import { SimpleBuilder } from "../builder";
3
3
  import { NodeType } from "./const";
4
4
  import { ObjectLoaderFactory } from "../../core/loaders";
@@ -15,11 +15,13 @@ export declare class FakeContact implements Ent {
15
15
  readonly userID: ID;
16
16
  getPrivacyPolicy(): PrivacyPolicy<this>;
17
17
  constructor(viewer: Viewer, data: Data);
18
+ __setRawDBData(data: Data): void;
18
19
  static getFields(): string[];
19
- static getTestTable(): import("../db/test_db").Table;
20
+ static getTestTable(): import("../db/temp_db").Table;
20
21
  static loaderOptions(): LoadEntOptions<FakeContact>;
21
22
  static load(v: Viewer, id: ID): Promise<FakeContact | null>;
22
23
  static loadX(v: Viewer, id: ID): Promise<FakeContact>;
24
+ static loadRawData(id: ID, context?: Context): Promise<Data | null>;
23
25
  }
24
26
  export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
25
27
  export interface ContactCreateInput {
@@ -27,7 +29,9 @@ export interface ContactCreateInput {
27
29
  lastName: string;
28
30
  emailAddress: string;
29
31
  userID: ID;
32
+ createdAt?: Date;
33
+ updatedAt?: Date;
30
34
  }
31
- export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact>;
35
+ export declare function getContactBuilder(viewer: Viewer, input: ContactCreateInput): SimpleBuilder<FakeContact, null>;
32
36
  export declare function createContact(viewer: Viewer, input: ContactCreateInput): Promise<void>;
33
37
  export declare const contactLoader: ObjectLoaderFactory<unknown>;
@@ -6,10 +6,16 @@ const privacy_1 = require("../../core/privacy");
6
6
  const builder_1 = require("../builder");
7
7
  const schema_1 = require("../../schema");
8
8
  const const_1 = require("./const");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
+ const action_1 = require("../../action");
12
13
  class FakeContact {
14
+ getPrivacyPolicy() {
15
+ return {
16
+ rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
17
+ };
18
+ }
13
19
  constructor(viewer, data) {
14
20
  this.viewer = viewer;
15
21
  this.nodeType = const_1.NodeType.FakeContact;
@@ -22,11 +28,7 @@ class FakeContact {
22
28
  this.emailAddress = data.email_address;
23
29
  this.userID = data.user_id;
24
30
  }
25
- getPrivacyPolicy() {
26
- return {
27
- rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
28
- };
29
- }
31
+ __setRawDBData(data) { }
30
32
  static getFields() {
31
33
  return [
32
34
  "id",
@@ -39,7 +41,7 @@ class FakeContact {
39
41
  ];
40
42
  }
41
43
  static getTestTable() {
42
- return (0, test_db_1.table)("fake_contacts", (0, test_db_1.uuid)("id", { primaryKey: true }), (0, test_db_1.timestamptz)("created_at"), (0, test_db_1.timestamptz)("updated_at"), (0, test_db_1.text)("first_name"), (0, test_db_1.text)("last_name"), (0, test_db_1.text)("email_address"), (0, test_db_1.uuid)("user_id"));
44
+ return (0, temp_db_1.table)("fake_contacts", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("first_name"), (0, temp_db_1.text)("last_name"), (0, temp_db_1.text)("email_address"), (0, temp_db_1.uuid)("user_id"));
43
45
  }
44
46
  static loaderOptions() {
45
47
  return {
@@ -59,6 +61,11 @@ class FakeContact {
59
61
  static async loadX(v, id) {
60
62
  return (0, ent_1.loadEntX)(v, id, FakeContact.loaderOptions());
61
63
  }
64
+ static async loadRawData(id, context) {
65
+ return FakeContact.loaderOptions()
66
+ .loaderFactory.createLoader(context)
67
+ .load(id);
68
+ }
62
69
  }
63
70
  exports.FakeContact = FakeContact;
64
71
  exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
@@ -77,7 +84,7 @@ function getContactBuilder(viewer, input) {
77
84
  //To lock in the value of Date now incase of advanceTo/advanceBy
78
85
  m.set("createdAt", new Date());
79
86
  m.set("updatedAt", new Date());
80
- return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m);
87
+ return new builder_1.SimpleBuilder(viewer, exports.FakeContactSchema, m, action_1.WriteOperation.Insert, null);
81
88
  }
82
89
  exports.getContactBuilder = getContactBuilder;
83
90
  async function createContact(viewer, input) {
@@ -16,14 +16,17 @@ export declare class FakeEvent implements Ent {
16
16
  readonly userID: ID;
17
17
  getPrivacyPolicy(): PrivacyPolicy<this>;
18
18
  constructor(viewer: Viewer, data: Data);
19
+ __setRawDBData(data: Data): void;
19
20
  private static getFields;
20
- static getTestTable(): import("../db/test_db").Table;
21
+ static getTestTable(): import("../db/temp_db").Table;
21
22
  static loaderOptions(): LoadEntOptions<FakeEvent>;
22
23
  static load(v: Viewer, id: ID): Promise<FakeEvent | null>;
23
24
  static loadX(v: Viewer, id: ID): Promise<FakeEvent>;
24
25
  }
25
26
  export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
26
27
  export interface EventCreateInput {
28
+ createdAt?: Date;
29
+ updatedAt?: Date;
27
30
  startTime: Date;
28
31
  endTime?: Date | null;
29
32
  location: string;
@@ -31,5 +34,5 @@ export interface EventCreateInput {
31
34
  description?: string | null;
32
35
  userID: ID;
33
36
  }
34
- export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent>;
37
+ export declare function getEventBuilder(viewer: Viewer, input: EventCreateInput): SimpleBuilder<FakeEvent, null>;
35
38
  export declare function createEvent(viewer: Viewer, input: EventCreateInput): Promise<void>;
@@ -6,10 +6,14 @@ const privacy_1 = require("../../core/privacy");
6
6
  const builder_1 = require("../builder");
7
7
  const schema_1 = require("../../schema");
8
8
  const const_1 = require("./const");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
+ const action_1 = require("../../action");
12
13
  class FakeEvent {
14
+ getPrivacyPolicy() {
15
+ return privacy_1.AlwaysAllowPrivacyPolicy;
16
+ }
13
17
  constructor(viewer, data) {
14
18
  this.viewer = viewer;
15
19
  this.nodeType = const_1.NodeType.FakeEvent;
@@ -24,9 +28,7 @@ class FakeEvent {
24
28
  this.description = data.description;
25
29
  this.userID = data.user_id;
26
30
  }
27
- getPrivacyPolicy() {
28
- return privacy_1.AlwaysAllowPrivacyPolicy;
29
- }
31
+ __setRawDBData(data) { }
30
32
  static getFields() {
31
33
  return [
32
34
  "id",
@@ -41,9 +43,9 @@ class FakeEvent {
41
43
  ];
42
44
  }
43
45
  static getTestTable() {
44
- return (0, test_db_1.table)("fake_events", (0, test_db_1.uuid)("id", { primaryKey: true }), (0, test_db_1.timestamptz)("created_at"), (0, test_db_1.timestamptz)("updated_at"),
46
+ return (0, temp_db_1.table)("fake_events", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"),
45
47
  // TODO index:true
46
- (0, test_db_1.timestamptz)("start_time"), (0, test_db_1.timestamptz)("end_time", { nullable: true }), (0, test_db_1.text)("location"), (0, test_db_1.text)("title"), (0, test_db_1.text)("description", { nullable: true }), (0, test_db_1.uuid)("user_id"));
48
+ (0, temp_db_1.timestamptz)("start_time"), (0, temp_db_1.timestamptz)("end_time", { nullable: true }), (0, temp_db_1.text)("location"), (0, temp_db_1.text)("title"), (0, temp_db_1.text)("description", { nullable: true }), (0, temp_db_1.uuid)("user_id"));
47
49
  }
48
50
  static loaderOptions() {
49
51
  return {
@@ -86,7 +88,7 @@ function getEventBuilder(viewer, input) {
86
88
  for (const key in input) {
87
89
  m.set(key, input[key]);
88
90
  }
89
- return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m);
91
+ return new builder_1.SimpleBuilder(viewer, exports.FakeEventSchema, m, action_1.WriteOperation.Insert, null);
90
92
  }
91
93
  exports.getEventBuilder = getEventBuilder;
92
94
  async function createEvent(viewer, input) {
@@ -0,0 +1,36 @@
1
+ import { ID, Ent, Viewer, Data, LoadEntOptions, PrivacyPolicy } from "../../core/base";
2
+ import { SimpleAction } from "../builder";
3
+ import { NodeType } from "./const";
4
+ import { ObjectLoaderFactory } from "../../core/loaders";
5
+ export declare class FakeTag implements Ent {
6
+ viewer: Viewer;
7
+ readonly id: ID;
8
+ readonly data: Data;
9
+ readonly nodeType = NodeType.FakeUser;
10
+ readonly createdAt: Date;
11
+ readonly updatedAt: Date;
12
+ readonly displayName: string;
13
+ readonly canonicalName: string;
14
+ readonly ownerID: string;
15
+ getPrivacyPolicy(): PrivacyPolicy<this>;
16
+ constructor(viewer: Viewer, data: Data);
17
+ __setRawDBData(data: Data): void;
18
+ static getFields(): string[];
19
+ static getTestTable(): import("../db/temp_db").Table;
20
+ static loaderOptions(): LoadEntOptions<FakeTag>;
21
+ static load(v: Viewer, id: ID): Promise<FakeTag | null>;
22
+ static loadX(v: Viewer, id: ID): Promise<FakeTag>;
23
+ }
24
+ export declare const FakeTagSchema: import("../builder").BuilderSchema<FakeTag>;
25
+ export interface TagCreateInput {
26
+ displayName: string;
27
+ canonicalName: string;
28
+ ownerID: ID;
29
+ createdAt?: Date;
30
+ updatedAt?: Date;
31
+ }
32
+ export type TagEditInput = Partial<TagCreateInput>;
33
+ export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): import("../builder").SimpleBuilder<FakeTag, null>;
34
+ export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
35
+ export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
36
+ export declare const tagLoader: ObjectLoaderFactory<unknown>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tagLoader = exports.createTag = exports.getTagAction = exports.getTagBuilder = exports.FakeTagSchema = exports.FakeTag = void 0;
4
+ const ent_1 = require("../../core/ent");
5
+ const privacy_1 = require("../../core/privacy");
6
+ const builder_1 = require("../builder");
7
+ const schema_1 = require("../../schema");
8
+ const const_1 = require("./const");
9
+ const temp_db_1 = require("../db/temp_db");
10
+ const loaders_1 = require("../../core/loaders");
11
+ const convert_1 = require("../../core/convert");
12
+ const action_1 = require("../../action");
13
+ class FakeTag {
14
+ getPrivacyPolicy() {
15
+ return {
16
+ rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
17
+ };
18
+ }
19
+ constructor(viewer, data) {
20
+ this.viewer = viewer;
21
+ this.nodeType = const_1.NodeType.FakeUser;
22
+ this.data = data;
23
+ this.id = data.id;
24
+ this.createdAt = (0, convert_1.convertDate)(data.created_at);
25
+ this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
26
+ this.displayName = data.display_name;
27
+ this.canonicalName = data.canonical_name;
28
+ this.ownerID = data.owner_id;
29
+ }
30
+ __setRawDBData(data) { }
31
+ static getFields() {
32
+ return [
33
+ "id",
34
+ "created_at",
35
+ "updated_at",
36
+ "display_name",
37
+ "canonical_name",
38
+ "owner_id",
39
+ ];
40
+ }
41
+ static getTestTable() {
42
+ return (0, temp_db_1.table)("fake_tags", (0, temp_db_1.uuid)("id", { primaryKey: true }), (0, temp_db_1.timestamptz)("created_at"), (0, temp_db_1.timestamptz)("updated_at"), (0, temp_db_1.text)("display_name"), (0, temp_db_1.text)("canonical_name"), (0, temp_db_1.uuid)("owner_id"), // TODO index: true sqlite broken?
43
+ (0, temp_db_1.index)("fake_tags", ["canonical_name", "owner_id"], { unique: true }));
44
+ }
45
+ static loaderOptions() {
46
+ return {
47
+ tableName: "fake_tags",
48
+ fields: FakeTag.getFields(),
49
+ ent: this,
50
+ loaderFactory: exports.tagLoader,
51
+ };
52
+ }
53
+ static async load(v, id) {
54
+ return (0, ent_1.loadEnt)(v, id, FakeTag.loaderOptions());
55
+ }
56
+ static async loadX(v, id) {
57
+ return (0, ent_1.loadEntX)(v, id, FakeTag.loaderOptions());
58
+ }
59
+ }
60
+ exports.FakeTag = FakeTag;
61
+ exports.FakeTagSchema = (0, builder_1.getBuilderSchemaFromFields)({
62
+ displayName: (0, schema_1.StringType)(),
63
+ canonicalName: (0, schema_1.StringType)().trim().toLowerCase(),
64
+ ownerID: (0, schema_1.UUIDType)({}),
65
+ }, FakeTag);
66
+ function getTagBuilder(viewer, input) {
67
+ const action = getTagAction(viewer, input);
68
+ return action.builder;
69
+ }
70
+ exports.getTagBuilder = getTagBuilder;
71
+ function getTagAction(viewer, input) {
72
+ const m = new Map();
73
+ for (const key in input) {
74
+ m.set(key, input[key]);
75
+ }
76
+ const action = new builder_1.SimpleAction(viewer, exports.FakeTagSchema, m, action_1.WriteOperation.Insert, null);
77
+ return action;
78
+ }
79
+ exports.getTagAction = getTagAction;
80
+ async function createTag(viewer, input) {
81
+ const action = getTagAction(viewer, input);
82
+ return action.saveX();
83
+ }
84
+ exports.createTag = createTag;
85
+ exports.tagLoader = new loaders_1.ObjectLoaderFactory({
86
+ tableName: "fake_tags",
87
+ fields: FakeTag.getFields(),
88
+ key: "id",
89
+ });
@@ -25,8 +25,9 @@ export declare class FakeUser implements Ent {
25
25
  protected readonly password: string | null;
26
26
  getPrivacyPolicy(): PrivacyPolicy<this>;
27
27
  constructor(viewer: Viewer, data: Data);
28
+ __setRawDBData(data: Data): void;
28
29
  static getFields(): string[];
29
- static getTestTable(): import("../db/test_db").Table;
30
+ static getTestTable(): import("../db/temp_db").Table;
30
31
  static loaderOptions(): LoadEntOptions<FakeUser>;
31
32
  static load(v: Viewer, id: ID): Promise<FakeUser | null>;
32
33
  static loadX(v: Viewer, id: ID): Promise<FakeUser>;
@@ -38,10 +39,12 @@ export interface UserCreateInput {
38
39
  emailAddress: string;
39
40
  phoneNumber: string | null;
40
41
  password: string | null;
42
+ createdAt?: Date;
43
+ updatedAt?: Date;
41
44
  }
42
- export declare type UserEditInput = Partial<UserCreateInput>;
43
- export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser>;
44
- export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser>;
45
+ export type UserEditInput = Partial<UserCreateInput>;
46
+ export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
47
+ export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
45
48
  export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
46
49
  export declare const userLoader: ObjectLoaderFactory<unknown>;
47
50
  export declare const userEmailLoader: ObjectLoaderFactory<unknown>;