@snowtop/ent 0.1.0-alpha95 → 0.1.0-alpha96

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 (63) hide show
  1. package/action/action.d.ts +3 -3
  2. package/action/executor.js +6 -1
  3. package/action/experimental_action.d.ts +5 -2
  4. package/action/experimental_action.js +15 -12
  5. package/action/index.d.ts +2 -0
  6. package/action/index.js +7 -1
  7. package/action/orchestrator.d.ts +4 -2
  8. package/action/orchestrator.js +6 -0
  9. package/action/relative_value.d.ts +47 -0
  10. package/action/relative_value.js +125 -0
  11. package/action/transaction.d.ts +10 -0
  12. package/action/transaction.js +23 -0
  13. package/auth/auth.d.ts +1 -1
  14. package/core/base.d.ts +4 -2
  15. package/core/clause.d.ts +6 -1
  16. package/core/clause.js +25 -4
  17. package/core/config.d.ts +2 -1
  18. package/core/config.js +2 -0
  19. package/core/date.js +1 -5
  20. package/core/db.d.ts +9 -6
  21. package/core/db.js +14 -6
  22. package/core/ent.d.ts +3 -1
  23. package/core/ent.js +76 -26
  24. package/core/logger.d.ts +1 -1
  25. package/core/query/assoc_query.d.ts +2 -2
  26. package/core/query/shared_assoc_test.js +1 -2
  27. package/core/query/shared_test.js +0 -1
  28. package/graphql/graphql.d.ts +6 -6
  29. package/graphql/graphql.js +1 -0
  30. package/graphql/query/connection_type.d.ts +1 -1
  31. package/graphql/query/shared_assoc_test.js +1 -1
  32. package/graphql/query/shared_edge_connection.js +0 -4
  33. package/imports/index.d.ts +6 -1
  34. package/imports/index.js +14 -3
  35. package/index.d.ts +1 -0
  36. package/package.json +16 -16
  37. package/parse_schema/parse.d.ts +7 -7
  38. package/schema/base_schema.d.ts +3 -3
  39. package/schema/field.js +2 -2
  40. package/schema/schema.d.ts +11 -10
  41. package/schema/schema.js +3 -13
  42. package/scripts/custom_graphql.js +30 -4
  43. package/testutils/action/complex_schemas.d.ts +69 -0
  44. package/testutils/action/complex_schemas.js +398 -0
  45. package/testutils/builder.d.ts +21 -36
  46. package/testutils/builder.js +39 -45
  47. package/testutils/db/temp_db.d.ts +6 -3
  48. package/testutils/db/temp_db.js +79 -7
  49. package/testutils/db/value.d.ts +1 -0
  50. package/testutils/db/value.js +2 -2
  51. package/testutils/db_mock.d.ts +16 -4
  52. package/testutils/db_mock.js +48 -5
  53. package/testutils/ent-graphql-tests/index.d.ts +7 -1
  54. package/testutils/ent-graphql-tests/index.js +17 -5
  55. package/testutils/fake_data/fake_contact.d.ts +1 -0
  56. package/testutils/fake_data/fake_contact.js +6 -5
  57. package/testutils/fake_data/fake_event.d.ts +1 -0
  58. package/testutils/fake_data/fake_event.js +4 -3
  59. package/testutils/fake_data/fake_tag.d.ts +2 -1
  60. package/testutils/fake_data/fake_tag.js +6 -5
  61. package/testutils/fake_data/fake_user.d.ts +2 -1
  62. package/testutils/fake_data/fake_user.js +14 -13
  63. package/tsc/ast.d.ts +1 -1
@@ -35,6 +35,7 @@ const graphql_1 = require("graphql");
35
35
  const auth_1 = require("../../auth");
36
36
  const supertest_1 = __importDefault(require("supertest"));
37
37
  const fs = __importStar(require("fs"));
38
+ const util_1 = require("util");
38
39
  function server(config) {
39
40
  const viewer = config.viewer;
40
41
  if (viewer) {
@@ -115,17 +116,23 @@ function makeGraphQLRequest(config, query, fieldArgs) {
115
116
  }
116
117
  }
117
118
  });
119
+ let variables = {
120
+ ...config.args,
121
+ };
122
+ for (const k in config.extraVariables) {
123
+ variables[k] = config.extraVariables[k].value;
124
+ }
118
125
  if (files.size) {
119
126
  let ret = test
120
127
  .post(config.graphQLPath || "/graphql")
121
128
  .set(config.headers || {});
122
129
  ret.field("operations", JSON.stringify({
123
130
  query: query,
124
- variables: config.args,
131
+ variables: variables,
125
132
  }));
126
133
  let m = {};
127
134
  let idx = 0;
128
- for (const [key, val] of files) {
135
+ for (const [key] of files) {
129
136
  m[idx] = [`variables.${key}`];
130
137
  idx++;
131
138
  }
@@ -148,7 +155,7 @@ function makeGraphQLRequest(config, query, fieldArgs) {
148
155
  .set(config.headers || {})
149
156
  .send({
150
157
  query: query,
151
- variables: JSON.stringify(config.args),
158
+ variables: JSON.stringify(variables),
152
159
  }),
153
160
  ];
154
161
  }
@@ -309,13 +316,18 @@ async function expectFromRoot(config, ...options) {
309
316
  let fieldArgs = field.args;
310
317
  let queryParams = [];
311
318
  fieldArgs.forEach((fieldArg) => {
312
- let arg = config.args[fieldArg.name];
319
+ const arg = config.args[fieldArg.name];
313
320
  // let the graphql runtime handle this (it may be optional for example)
314
321
  if (arg === undefined) {
315
322
  return;
316
323
  }
317
324
  queryParams.push(`$${fieldArg.name}: ${fieldArg.type}`);
318
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
+ }
319
331
  let params = [];
320
332
  for (let key in config.args) {
321
333
  params.push(`${key}: $${key}`);
@@ -354,7 +366,7 @@ async function expectFromRoot(config, ...options) {
354
366
  let [st, temp] = makeGraphQLRequest(config, q, fieldArgs);
355
367
  const res = await temp.expect("Content-Type", /json/);
356
368
  if (config.debugMode) {
357
- console.log(res.body);
369
+ console.log((0, util_1.inspect)(res.body, false, 3));
358
370
  }
359
371
  // if there's a callback, let everything be done there and we're done
360
372
  if (config.callback) {
@@ -15,6 +15,7 @@ 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
20
  static getTestTable(): import("../db/temp_db").Table;
20
21
  static loaderOptions(): LoadEntOptions<FakeContact>;
@@ -11,6 +11,11 @@ const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
12
  const action_1 = require("../../action");
13
13
  class FakeContact {
14
+ getPrivacyPolicy() {
15
+ return {
16
+ rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
17
+ };
18
+ }
14
19
  constructor(viewer, data) {
15
20
  this.viewer = viewer;
16
21
  this.nodeType = const_1.NodeType.FakeContact;
@@ -23,11 +28,7 @@ class FakeContact {
23
28
  this.emailAddress = data.email_address;
24
29
  this.userID = data.user_id;
25
30
  }
26
- getPrivacyPolicy() {
27
- return {
28
- rules: [new privacy_1.AllowIfViewerIsRule("userID"), privacy_1.AlwaysDenyRule],
29
- };
30
- }
31
+ __setRawDBData(data) { }
31
32
  static getFields() {
32
33
  return [
33
34
  "id",
@@ -16,6 +16,7 @@ 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
21
  static getTestTable(): import("../db/temp_db").Table;
21
22
  static loaderOptions(): LoadEntOptions<FakeEvent>;
@@ -11,6 +11,9 @@ const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
12
  const action_1 = require("../../action");
13
13
  class FakeEvent {
14
+ getPrivacyPolicy() {
15
+ return privacy_1.AlwaysAllowPrivacyPolicy;
16
+ }
14
17
  constructor(viewer, data) {
15
18
  this.viewer = viewer;
16
19
  this.nodeType = const_1.NodeType.FakeEvent;
@@ -25,9 +28,7 @@ class FakeEvent {
25
28
  this.description = data.description;
26
29
  this.userID = data.user_id;
27
30
  }
28
- getPrivacyPolicy() {
29
- return privacy_1.AlwaysAllowPrivacyPolicy;
30
- }
31
+ __setRawDBData(data) { }
31
32
  static getFields() {
32
33
  return [
33
34
  "id",
@@ -14,6 +14,7 @@ export declare class FakeTag implements Ent {
14
14
  readonly ownerID: string;
15
15
  getPrivacyPolicy(): PrivacyPolicy<this>;
16
16
  constructor(viewer: Viewer, data: Data);
17
+ __setRawDBData(data: Data): void;
17
18
  static getFields(): string[];
18
19
  static getTestTable(): import("../db/temp_db").Table;
19
20
  static loaderOptions(): LoadEntOptions<FakeTag>;
@@ -28,7 +29,7 @@ export interface TagCreateInput {
28
29
  createdAt?: Date;
29
30
  updatedAt?: Date;
30
31
  }
31
- export declare type TagEditInput = Partial<TagCreateInput>;
32
+ export type TagEditInput = Partial<TagCreateInput>;
32
33
  export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): import("../builder").SimpleBuilder<FakeTag, null>;
33
34
  export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
34
35
  export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
@@ -11,6 +11,11 @@ const loaders_1 = require("../../core/loaders");
11
11
  const convert_1 = require("../../core/convert");
12
12
  const action_1 = require("../../action");
13
13
  class FakeTag {
14
+ getPrivacyPolicy() {
15
+ return {
16
+ rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
17
+ };
18
+ }
14
19
  constructor(viewer, data) {
15
20
  this.viewer = viewer;
16
21
  this.nodeType = const_1.NodeType.FakeUser;
@@ -22,11 +27,7 @@ class FakeTag {
22
27
  this.canonicalName = data.canonical_name;
23
28
  this.ownerID = data.owner_id;
24
29
  }
25
- getPrivacyPolicy() {
26
- return {
27
- rules: [new privacy_1.AllowIfViewerIsEntPropertyRule("ownerID"), privacy_1.AlwaysDenyRule],
28
- };
29
- }
30
+ __setRawDBData(data) { }
30
31
  static getFields() {
31
32
  return [
32
33
  "id",
@@ -25,6 +25,7 @@ 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
30
  static getTestTable(): import("../db/temp_db").Table;
30
31
  static loaderOptions(): LoadEntOptions<FakeUser>;
@@ -41,7 +42,7 @@ export interface UserCreateInput {
41
42
  createdAt?: Date;
42
43
  updatedAt?: Date;
43
44
  }
44
- export declare type UserEditInput = Partial<UserCreateInput>;
45
+ export type UserEditInput = Partial<UserCreateInput>;
45
46
  export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput): import("../builder").SimpleBuilder<FakeUser, null>;
46
47
  export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
47
48
  export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
@@ -24,19 +24,6 @@ class ViewerWithAccessToken extends viewer_1.IDViewer {
24
24
  }
25
25
  exports.ViewerWithAccessToken = ViewerWithAccessToken;
26
26
  class FakeUser {
27
- constructor(viewer, data) {
28
- this.viewer = viewer;
29
- this.nodeType = const_1.NodeType.FakeUser;
30
- this.data = data;
31
- this.id = data.id;
32
- this.createdAt = (0, convert_1.convertDate)(data.created_at);
33
- this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
34
- this.firstName = data.first_name;
35
- this.lastName = data.last_name;
36
- this.emailAddress = data.email_address;
37
- this.phoneNumber = data.phone_number;
38
- this.password = data.password;
39
- }
40
27
  getPrivacyPolicy() {
41
28
  return {
42
29
  rules: [
@@ -61,6 +48,20 @@ class FakeUser {
61
48
  ],
62
49
  };
63
50
  }
51
+ constructor(viewer, data) {
52
+ this.viewer = viewer;
53
+ this.nodeType = const_1.NodeType.FakeUser;
54
+ this.data = data;
55
+ this.id = data.id;
56
+ this.createdAt = (0, convert_1.convertDate)(data.created_at);
57
+ this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
58
+ this.firstName = data.first_name;
59
+ this.lastName = data.last_name;
60
+ this.emailAddress = data.email_address;
61
+ this.phoneNumber = data.phone_number;
62
+ this.password = data.password;
63
+ }
64
+ __setRawDBData(data) { }
64
65
  static getFields() {
65
66
  return [
66
67
  "id",
package/tsc/ast.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface ClassInfo {
10
10
  wrapClassContents(inner: string): string;
11
11
  }
12
12
  export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration): ClassInfo | undefined;
13
- declare type transformImportFn = (imp: string) => string;
13
+ type transformImportFn = (imp: string) => string;
14
14
  interface transformOpts {
15
15
  removeImports?: string[];
16
16
  newImports?: string[];