@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha91

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 (135) hide show
  1. package/action/action.d.ts +36 -31
  2. package/action/action.js +2 -6
  3. package/action/executor.d.ts +3 -3
  4. package/action/executor.js +2 -2
  5. package/action/experimental_action.d.ts +29 -22
  6. package/action/experimental_action.js +29 -6
  7. package/action/orchestrator.d.ts +38 -16
  8. package/action/orchestrator.js +223 -61
  9. package/action/privacy.d.ts +2 -2
  10. package/core/base.d.ts +45 -24
  11. package/core/base.js +7 -1
  12. package/core/clause.d.ts +83 -7
  13. package/core/clause.js +334 -63
  14. package/core/config.d.ts +8 -0
  15. package/core/config.js +5 -1
  16. package/core/context.d.ts +5 -3
  17. package/core/context.js +20 -2
  18. package/core/convert.d.ts +1 -1
  19. package/core/db.d.ts +2 -2
  20. package/core/db.js +6 -2
  21. package/core/ent.d.ts +79 -24
  22. package/core/ent.js +527 -176
  23. package/core/loaders/assoc_count_loader.d.ts +3 -2
  24. package/core/loaders/assoc_count_loader.js +14 -2
  25. package/core/loaders/assoc_edge_loader.d.ts +2 -2
  26. package/core/loaders/assoc_edge_loader.js +5 -1
  27. package/core/loaders/index.d.ts +1 -1
  28. package/core/loaders/index.js +1 -3
  29. package/core/loaders/index_loader.d.ts +2 -2
  30. package/core/loaders/loader.js +5 -5
  31. package/core/loaders/object_loader.d.ts +6 -5
  32. package/core/loaders/object_loader.js +67 -59
  33. package/core/loaders/query_loader.d.ts +6 -12
  34. package/core/loaders/query_loader.js +52 -11
  35. package/core/loaders/raw_count_loader.d.ts +2 -2
  36. package/core/loaders/raw_count_loader.js +5 -1
  37. package/core/logger.d.ts +1 -1
  38. package/core/logger.js +1 -0
  39. package/core/privacy.d.ts +26 -25
  40. package/core/privacy.js +21 -25
  41. package/core/query/assoc_query.d.ts +7 -6
  42. package/core/query/assoc_query.js +9 -1
  43. package/core/query/custom_clause_query.d.ts +26 -0
  44. package/core/query/custom_clause_query.js +78 -0
  45. package/core/query/custom_query.d.ts +20 -5
  46. package/core/query/custom_query.js +87 -12
  47. package/core/query/index.d.ts +1 -0
  48. package/core/query/index.js +3 -1
  49. package/core/query/query.d.ts +8 -4
  50. package/core/query/query.js +101 -53
  51. package/core/query/shared_assoc_test.d.ts +2 -1
  52. package/core/query/shared_assoc_test.js +34 -43
  53. package/core/query/shared_test.d.ts +8 -1
  54. package/core/query/shared_test.js +470 -236
  55. package/core/viewer.d.ts +3 -3
  56. package/core/viewer.js +1 -1
  57. package/graphql/graphql.js +16 -6
  58. package/graphql/query/edge_connection.d.ts +9 -9
  59. package/graphql/query/page_info.d.ts +1 -1
  60. package/graphql/query/shared_edge_connection.js +1 -15
  61. package/imports/index.js +5 -1
  62. package/index.d.ts +11 -5
  63. package/index.js +20 -7
  64. package/package.json +1 -1
  65. package/parse_schema/parse.d.ts +12 -3
  66. package/parse_schema/parse.js +70 -11
  67. package/schema/base_schema.js +3 -0
  68. package/schema/field.d.ts +44 -8
  69. package/schema/field.js +136 -10
  70. package/schema/index.d.ts +2 -2
  71. package/schema/index.js +5 -1
  72. package/schema/json_field.d.ts +13 -1
  73. package/schema/json_field.js +28 -1
  74. package/schema/schema.d.ts +66 -11
  75. package/schema/schema.js +18 -4
  76. package/schema/struct_field.d.ts +11 -1
  77. package/schema/struct_field.js +44 -5
  78. package/scripts/custom_compiler.js +10 -6
  79. package/scripts/custom_graphql.js +13 -4
  80. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  81. package/scripts/migrate_v0.1.js +36 -0
  82. package/scripts/read_schema.js +20 -5
  83. package/testutils/builder.d.ts +31 -21
  84. package/testutils/builder.js +83 -29
  85. package/testutils/db/fixture.d.ts +10 -0
  86. package/testutils/db/fixture.js +26 -0
  87. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +20 -7
  88. package/testutils/db/{test_db.js → temp_db.js} +102 -36
  89. package/testutils/db/value.d.ts +6 -0
  90. package/testutils/db/value.js +251 -0
  91. package/testutils/db_mock.js +3 -1
  92. package/testutils/db_time_zone.d.ts +4 -0
  93. package/testutils/db_time_zone.js +41 -0
  94. package/testutils/ent-graphql-tests/index.js +8 -1
  95. package/testutils/fake_data/const.d.ts +2 -1
  96. package/testutils/fake_data/const.js +3 -0
  97. package/testutils/fake_data/fake_contact.d.ts +7 -4
  98. package/testutils/fake_data/fake_contact.js +14 -6
  99. package/testutils/fake_data/fake_event.d.ts +5 -3
  100. package/testutils/fake_data/fake_event.js +8 -5
  101. package/testutils/fake_data/fake_tag.d.ts +35 -0
  102. package/testutils/fake_data/fake_tag.js +88 -0
  103. package/testutils/fake_data/fake_user.d.ts +6 -4
  104. package/testutils/fake_data/fake_user.js +16 -13
  105. package/testutils/fake_data/index.js +5 -1
  106. package/testutils/fake_data/internal.d.ts +2 -0
  107. package/testutils/fake_data/internal.js +7 -1
  108. package/testutils/fake_data/tag_query.d.ts +13 -0
  109. package/testutils/fake_data/tag_query.js +43 -0
  110. package/testutils/fake_data/test_helpers.d.ts +11 -4
  111. package/testutils/fake_data/test_helpers.js +28 -12
  112. package/testutils/fake_data/user_query.d.ts +13 -6
  113. package/testutils/fake_data/user_query.js +54 -22
  114. package/testutils/fake_log.d.ts +3 -3
  115. package/testutils/parse_sql.d.ts +6 -0
  116. package/testutils/parse_sql.js +16 -2
  117. package/testutils/test_edge_global_schema.d.ts +15 -0
  118. package/testutils/test_edge_global_schema.js +62 -0
  119. package/testutils/write.d.ts +2 -2
  120. package/testutils/write.js +33 -7
  121. package/tsc/ast.d.ts +44 -0
  122. package/tsc/ast.js +271 -0
  123. package/tsc/compilerOptions.d.ts +6 -0
  124. package/tsc/compilerOptions.js +45 -2
  125. package/tsc/move_generated.d.ts +1 -0
  126. package/tsc/move_generated.js +164 -0
  127. package/tsc/transform.d.ts +21 -0
  128. package/tsc/transform.js +171 -0
  129. package/tsc/transform_action.d.ts +22 -0
  130. package/tsc/transform_action.js +183 -0
  131. package/tsc/transform_ent.d.ts +17 -0
  132. package/tsc/transform_ent.js +59 -0
  133. package/tsc/transform_schema.d.ts +27 -0
  134. package/tsc/transform_schema.js +383 -0
  135. package/scripts/transform_schema.js +0 -445
package/core/viewer.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ID, Ent, Viewer, Context } from "./base";
2
2
  export declare class LoggedOutViewer implements Viewer {
3
- context?: Context | undefined;
4
- constructor(context?: Context | undefined);
3
+ context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined;
4
+ constructor(context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined);
5
5
  viewerID: null;
6
6
  viewer(): Promise<null>;
7
7
  instanceKey(): string;
@@ -18,6 +18,6 @@ export declare class IDViewer implements Viewer {
18
18
  constructor(viewerID: ID, opts?: Partial<IDViewerOptions>);
19
19
  constructor(opts: IDViewerOptions);
20
20
  setContext(ctx: Context): this;
21
- viewer(): Promise<Ent | null>;
21
+ viewer(): Promise<Ent<Viewer<Ent<any> | null, ID | null>> | null>;
22
22
  instanceKey(): string;
23
23
  }
package/core/viewer.js CHANGED
@@ -35,7 +35,7 @@ class IDViewer {
35
35
  return this.ent;
36
36
  }
37
37
  instanceKey() {
38
- return `idViewer: ${this.viewerID}`;
38
+ return `idViewer:${this.viewerID}`;
39
39
  }
40
40
  }
41
41
  exports.IDViewer = IDViewer;
@@ -63,11 +63,9 @@ const isGraphQLScalarType = (type) => {
63
63
  };
64
64
  const addCustomType = (type) => {
65
65
  // TODO these should return ReadOnly objects...
66
- const customType = GQLCapture.getCustomTypes().get(type.type);
67
- if (customType && customType !== type) {
68
- throw new Error(`cannot add multiple custom types of name ${type.type}`);
69
- }
70
- if (customType) {
66
+ const customTypes = GQLCapture.getCustomTypes();
67
+ const customType = customTypes.get(type.type);
68
+ if (customType && customType === type) {
71
69
  return;
72
70
  }
73
71
  try {
@@ -85,9 +83,21 @@ const addCustomType = (type) => {
85
83
  }
86
84
  }
87
85
  catch (e) {
86
+ if (type.secondaryImportPath) {
87
+ (0, exports.addCustomType)({
88
+ ...type,
89
+ importPath: type.secondaryImportPath,
90
+ });
91
+ }
92
+ return;
93
+ }
94
+ if (customType) {
95
+ if (JSON.stringify(customType) !== JSON.stringify(type)) {
96
+ throw new Error(`cannot add multiple custom types of name ${type.type}`);
97
+ }
88
98
  return;
89
99
  }
90
- GQLCapture.getCustomTypes().set(type.type, type);
100
+ customTypes.set(type.type, type);
91
101
  };
92
102
  exports.addCustomType = addCustomType;
93
103
  const getType = (typ, result) => {
@@ -1,30 +1,30 @@
1
1
  import { EdgeQuery, PaginationInfo } from "../../core/query/query";
2
- import { Data, Ent, Viewer } from "../../core/base";
2
+ import { Data, Ent, ID, Viewer } from "../../core/base";
3
3
  export interface GraphQLEdge<T extends Data> {
4
4
  edge: T;
5
5
  node: Ent;
6
6
  cursor: string;
7
7
  }
8
- interface edgeQueryCtr<T extends Ent, TEdge extends Data> {
9
- (v: Viewer, src: T): EdgeQuery<T, Ent, TEdge>;
8
+ interface edgeQueryCtr<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
9
+ (v: TViewer, src: T): EdgeQuery<T, Ent, TEdge>;
10
10
  }
11
- interface edgeQueryCtr2<T extends Ent, TEdge extends Data> {
12
- (v: Viewer): EdgeQuery<T, Ent, TEdge>;
11
+ interface edgeQueryCtr2<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
12
+ (v: TViewer): EdgeQuery<T, Ent, TEdge>;
13
13
  }
14
- export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data> {
14
+ export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data, TViewer extends Viewer = Viewer> {
15
15
  query: EdgeQuery<TSource, Ent, TEdge>;
16
16
  private results;
17
17
  private viewer;
18
18
  private source?;
19
19
  private args?;
20
- constructor(viewer: Viewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge>, args?: Data);
21
- constructor(viewer: Viewer, getQuery: edgeQueryCtr2<TSource, TEdge>, args?: Data);
20
+ constructor(viewer: TViewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge, TViewer>, args?: Data);
21
+ constructor(viewer: TViewer, getQuery: edgeQueryCtr2<TSource, TEdge, TViewer>, args?: Data);
22
22
  first(limit: number, cursor?: string): void;
23
23
  last(limit: number, cursor?: string): void;
24
24
  modifyQuery(fn: (query: EdgeQuery<TSource, Ent, TEdge>) => EdgeQuery<TSource, Ent, TEdge>): void;
25
25
  queryTotalCount(): Promise<number>;
26
26
  queryEdges(): Promise<GraphQLEdge<TEdge>[]>;
27
- queryNodes(): Promise<Ent[]>;
27
+ queryNodes(): Promise<Ent<Viewer<Ent<any> | null, ID | null>>[]>;
28
28
  private defaultPageInfo;
29
29
  queryPageInfo(): Promise<PaginationInfo>;
30
30
  private queryData;
@@ -1,4 +1,4 @@
1
1
  import { GraphQLObjectType } from "graphql";
2
2
  import { RequestContext } from "../../core/context";
3
3
  import { PaginationInfo } from "../../core/query/query";
4
- export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext>;
4
+ export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext<import("../..").Viewer<import("../..").Ent<any> | null, import("../..").ID | null>>>;
@@ -48,23 +48,9 @@ class TestConnection {
48
48
  }
49
49
  const commonTests = (opts) => {
50
50
  function getCursorFrom(contacts, idx) {
51
- // we depend on the fact that the same time is used for the edge and created_at
52
- // based on getContactBuilder
53
- // so regardless of if we're doing assoc or custom queries, we can get the time
54
- // from the created_at field
55
51
  return (0, ent_1.getCursor)({
56
52
  row: contacts[idx],
57
- col: "createdAt",
58
- conv: (t) => {
59
- //sqlite
60
- if (typeof t === "string") {
61
- return Date.parse(t);
62
- }
63
- return t.getTime();
64
- },
65
- // we want the right column to be encoded in the cursor as opposed e.g. time for
66
- // assoc queries, created_at for index/custom queries
67
- cursorKey: opts.sortCol,
53
+ col: "id",
68
54
  });
69
55
  }
70
56
  describe("no filters", () => {
package/imports/index.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];
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./core/base";
2
- export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, } from "./core/ent";
2
+ export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
3
3
  import DB from "./core/db";
4
4
  export * from "./core/loaders";
5
5
  export { DB };
@@ -13,6 +13,7 @@ declare const query: {
13
13
  And: typeof q.And;
14
14
  AndOptional: typeof q.AndOptional;
15
15
  Or: typeof q.Or;
16
+ OrOptional: typeof q.OrOptional;
16
17
  In: typeof q.In;
17
18
  Greater: typeof q.Greater;
18
19
  Less: typeof q.Less;
@@ -20,10 +21,15 @@ declare const query: {
20
21
  LessEq: typeof q.LessEq;
21
22
  ArrayEq: typeof q.ArrayEq;
22
23
  ArrayNotEq: typeof q.ArrayNotEq;
23
- ArrayGreater: typeof q.ArrayGreater;
24
- ArrayLess: typeof q.ArrayLess;
25
- ArrayGreaterEq: typeof q.ArrayGreaterEq;
26
- ArrayLessEq: typeof q.ArrayLessEq;
24
+ PostgresArrayContainsValue: typeof q.PostgresArrayContainsValue;
25
+ PostgresArrayContains: typeof q.PostgresArrayContains;
26
+ PostgresArrayNotContainsValue: typeof q.PostgresArrayNotContainsValue;
27
+ PostgresArrayNotContains: typeof q.PostgresArrayNotContains;
28
+ PostgresArrayOverlaps: typeof q.PostgresArrayOverlaps;
29
+ PostgresArrayNotOverlaps: typeof q.PostgresArrayNotOverlaps;
30
+ JSONPathValuePredicate: typeof q.JSONPathValuePredicate;
31
+ JSONObjectFieldKeyASJSON: typeof q.JSONObjectFieldKeyASJSON;
32
+ JSONObjectFieldKeyAsText: typeof q.JSONObjectFieldKeyAsText;
27
33
  TsQuery: typeof q.TsQuery;
28
34
  PlainToTsQuery: typeof q.PlainToTsQuery;
29
35
  PhraseToTsQuery: typeof q.PhraseToTsQuery;
package/index.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];
@@ -25,13 +29,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
30
  };
27
31
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
29
- exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = void 0;
32
+ exports.DenyIfViewerInboundEdgeExistsRule = exports.DenyIfEdgeExistsRule = exports.AllowIfViewerOutboundEdgeExistsRule = exports.AllowIfViewerInboundEdgeExistsRule = exports.AllowIfEdgeExistsRule = exports.DenyIfViewerEqualsRule = exports.AllowIfViewerEqualsRule = exports.DenyIfEntPropertyIsRule = exports.AllowIfEntPropertyIsRule = exports.AllowIfViewerIsEntPropertyRule = exports.AllowIfViewerIsRule = exports.AllowIfFuncRule = exports.AllowIfViewerRule = exports.AllowIfHasIdentity = exports.DenyIfLoggedOutRule = exports.DenyIfLoggedInRule = exports.AlwaysDenyRule = exports.AlwaysAllowRule = exports.EntPrivacyError = exports.DB = exports.setGlobalSchema = exports.getEdgeTypeInGroup = exports.loadNodesByEdge = exports.loadEdgeForID2 = exports.loadRawEdgeCountX = exports.loadUniqueNode = exports.loadUniqueEdge = exports.loadEdges = exports.loadEdgeDatas = exports.loadEdgeData = exports.AssocEdgeData = exports.AssocEdge = exports.DeleteNodeOperation = exports.EdgeOperation = exports.RawQueryOperation = exports.EditNodeOperation = exports.loadRows = exports.loadRow = exports.loadRowX = exports.performRawQuery = exports.loadEntXViaKey = exports.loadEntViaKey = exports.loadDerivedEntX = exports.loadDerivedEnt = exports.loadEnts = exports.loadEntX = exports.loadCustomCount = exports.loadCustomEnts = exports.loadCustomData = exports.loadEnt = void 0;
33
+ exports.setLogLevels = exports.loadConfig = exports.LoggedOutViewer = exports.IDViewer = exports.ContextCache = exports.query = exports.AllowIfViewerHasIdentityPrivacyPolicy = exports.AllowIfViewerPrivacyPolicy = exports.AllowIfSubPolicyAllowsRule = exports.AllowIfConditionAppliesRule = exports.AlwaysDenyPrivacyPolicy = exports.AlwaysAllowPrivacyPolicy = exports.applyPrivacyPolicyX = exports.applyPrivacyPolicy = exports.DelayedResultRule = exports.DenyIfEntIsVisiblePolicy = exports.AllowIfEntIsVisiblePolicy = exports.DenyIfEntIsNotVisibleRule = exports.DenyIfEntIsVisibleRule = exports.AllowIfEntIsNotVisibleRule = exports.AllowIfEntIsVisibleRule = exports.DenyIfViewerOutboundEdgeDoesNotExistRule = exports.DenyIfViewerInboundEdgeDoesNotExistRule = exports.DenyIfEdgeDoesNotExistRule = exports.DenyIfViewerOutboundEdgeExistsRule = void 0;
30
34
  __exportStar(require("./core/base"), exports);
31
35
  var ent_1 = require("./core/ent");
32
36
  Object.defineProperty(exports, "loadEnt", { enumerable: true, get: function () { return ent_1.loadEnt; } });
33
37
  Object.defineProperty(exports, "loadCustomData", { enumerable: true, get: function () { return ent_1.loadCustomData; } });
34
38
  Object.defineProperty(exports, "loadCustomEnts", { enumerable: true, get: function () { return ent_1.loadCustomEnts; } });
39
+ Object.defineProperty(exports, "loadCustomCount", { enumerable: true, get: function () { return ent_1.loadCustomCount; } });
35
40
  Object.defineProperty(exports, "loadEntX", { enumerable: true, get: function () { return ent_1.loadEntX; } });
36
41
  Object.defineProperty(exports, "loadEnts", { enumerable: true, get: function () { return ent_1.loadEnts; } });
37
42
  Object.defineProperty(exports, "loadDerivedEnt", { enumerable: true, get: function () { return ent_1.loadDerivedEnt; } });
@@ -44,6 +49,7 @@ Object.defineProperty(exports, "loadRowX", { enumerable: true, get: function ()
44
49
  Object.defineProperty(exports, "loadRow", { enumerable: true, get: function () { return ent_1.loadRow; } });
45
50
  Object.defineProperty(exports, "loadRows", { enumerable: true, get: function () { return ent_1.loadRows; } });
46
51
  Object.defineProperty(exports, "EditNodeOperation", { enumerable: true, get: function () { return ent_1.EditNodeOperation; } });
52
+ Object.defineProperty(exports, "RawQueryOperation", { enumerable: true, get: function () { return ent_1.RawQueryOperation; } });
47
53
  Object.defineProperty(exports, "EdgeOperation", { enumerable: true, get: function () { return ent_1.EdgeOperation; } });
48
54
  Object.defineProperty(exports, "DeleteNodeOperation", { enumerable: true, get: function () { return ent_1.DeleteNodeOperation; } });
49
55
  Object.defineProperty(exports, "AssocEdge", { enumerable: true, get: function () { return ent_1.AssocEdge; } });
@@ -57,6 +63,7 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
57
63
  Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
58
64
  Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
59
65
  Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
66
+ Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
60
67
  const db_1 = __importDefault(require("./core/db"));
61
68
  exports.DB = db_1.default;
62
69
  __exportStar(require("./core/loaders"), exports);
@@ -109,6 +116,7 @@ const query = {
109
116
  And: q.And,
110
117
  AndOptional: q.AndOptional,
111
118
  Or: q.Or,
119
+ OrOptional: q.OrOptional,
112
120
  In: q.In,
113
121
  Greater: q.Greater,
114
122
  Less: q.Less,
@@ -116,10 +124,15 @@ const query = {
116
124
  LessEq: q.LessEq,
117
125
  ArrayEq: q.ArrayEq,
118
126
  ArrayNotEq: q.ArrayNotEq,
119
- ArrayGreater: q.ArrayGreater,
120
- ArrayLess: q.ArrayLess,
121
- ArrayGreaterEq: q.ArrayGreaterEq,
122
- ArrayLessEq: q.ArrayLessEq,
127
+ PostgresArrayContainsValue: q.PostgresArrayContainsValue,
128
+ PostgresArrayContains: q.PostgresArrayContains,
129
+ PostgresArrayNotContainsValue: q.PostgresArrayNotContainsValue,
130
+ PostgresArrayNotContains: q.PostgresArrayNotContains,
131
+ PostgresArrayOverlaps: q.PostgresArrayOverlaps,
132
+ PostgresArrayNotOverlaps: q.PostgresArrayNotOverlaps,
133
+ JSONPathValuePredicate: q.JSONPathValuePredicate,
134
+ JSONObjectFieldKeyASJSON: q.JSONObjectFieldKeyASJSON,
135
+ JSONObjectFieldKeyAsText: q.JSONObjectFieldKeyAsText,
123
136
  TsQuery: q.TsQuery,
124
137
  PlainToTsQuery: q.PlainToTsQuery,
125
138
  PhraseToTsQuery: q.PhraseToTsQuery,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha9",
3
+ "version": "0.1.0-alpha91",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { Schema, Field, AssocEdge, AssocEdgeGroup, Action } from "../schema";
2
- import { ActionField, Type } from "../schema/schema";
2
+ import { ActionField, Type, GlobalSchema } from "../schema/schema";
3
3
  declare enum NullableResult {
4
4
  CONTENTS = "contents",
5
5
  CONTENTS_AND_LIST = "contentsAndList",
@@ -24,6 +24,7 @@ declare type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" |
24
24
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
25
25
  fields: ProcessedField[];
26
26
  schemaPath?: string;
27
+ patternNames?: string[];
27
28
  };
28
29
  declare type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
29
30
  edgeAction?: OutputAction;
@@ -38,13 +39,14 @@ interface ProcessedPattern {
38
39
  name: string;
39
40
  assocEdges: ProcessedAssocEdge[];
40
41
  fields: ProcessedField[];
42
+ disableMixin?: boolean;
41
43
  }
42
44
  declare type ProcessedType = Omit<Type, "subFields" | "listElemType" | "unionFields"> & {
43
45
  subFields?: ProcessedField[];
44
46
  listElemType?: ProcessedType;
45
47
  unionFields?: ProcessedField[];
46
48
  };
47
- declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type"> & {
49
+ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOnCreate" | "privacyPolicy" | "type" | "serverDefault"> & {
48
50
  name: string;
49
51
  hasDefaultValueOnCreate?: boolean;
50
52
  hasDefaultValueOnEdit?: boolean;
@@ -52,6 +54,7 @@ declare type ProcessedField = Omit<Field, "defaultValueOnEdit" | "defaultValueOn
52
54
  hasFieldPrivacy?: boolean;
53
55
  derivedFields?: ProcessedField[];
54
56
  type: ProcessedType;
57
+ serverDefault?: string;
55
58
  };
56
59
  interface patternsDict {
57
60
  [key: string]: ProcessedPattern;
@@ -59,9 +62,15 @@ interface patternsDict {
59
62
  interface Result {
60
63
  schemas: schemasDict;
61
64
  patterns: patternsDict;
65
+ globalSchema?: ProcessedGlobalSchema;
62
66
  }
63
67
  declare type PotentialSchemas = {
64
68
  [key: string]: any;
65
69
  };
66
- export declare function parseSchema(potentialSchemas: PotentialSchemas): Result;
70
+ export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
71
+ interface ProcessedGlobalSchema {
72
+ globalEdges: ProcessedAssocEdge[];
73
+ extraEdgeFields: ProcessedField[];
74
+ initForEdges?: boolean;
75
+ }
67
76
  export {};
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSchema = void 0;
4
- function processFields(src, patternName) {
4
+ async function processFields(src, patternName) {
5
5
  const ret = [];
6
6
  let m = {};
7
7
  if (Array.isArray(src)) {
@@ -36,6 +36,19 @@ function processFields(src, patternName) {
36
36
  else {
37
37
  delete f.polymorphic;
38
38
  }
39
+ if (field.private) {
40
+ // convert boolean into object
41
+ // we keep boolean as an option to keep API simple
42
+ if (typeof field.private === "boolean") {
43
+ f.private = {};
44
+ }
45
+ else {
46
+ f.private = field.private;
47
+ }
48
+ }
49
+ else {
50
+ delete f.private;
51
+ }
39
52
  // convert string to object to make API consumed by go simple
40
53
  if (f.fieldEdge && f.fieldEdge.inverseEdge) {
41
54
  if (typeof f.fieldEdge.inverseEdge === "string") {
@@ -47,26 +60,48 @@ function processFields(src, patternName) {
47
60
  if (patternName) {
48
61
  f.patternName = patternName;
49
62
  }
63
+ if (field.serverDefault !== undefined) {
64
+ f.serverDefault = await transformServerDefault(name, field, field.serverDefault);
65
+ }
50
66
  transformType(field.type);
51
67
  if (field.getDerivedFields) {
52
- f.derivedFields = processFields(field.getDerivedFields(name));
68
+ f.derivedFields = await processFields(field.getDerivedFields(name));
53
69
  }
54
70
  if (field.type.subFields) {
55
- f.type.subFields = processFields(field.type.subFields);
71
+ f.type.subFields = await processFields(field.type.subFields);
56
72
  }
57
73
  if (field.type.unionFields) {
58
- f.type.unionFields = processFields(field.type.unionFields);
74
+ f.type.unionFields = await processFields(field.type.unionFields);
59
75
  }
60
76
  if (field.type.listElemType &&
61
77
  field.type.listElemType.subFields &&
62
78
  // check to avoid ts-ignore below. exists just for tsc
63
79
  f.type.listElemType) {
64
- f.type.listElemType.subFields = processFields(field.type.listElemType.subFields);
80
+ f.type.listElemType.subFields = await processFields(field.type.listElemType.subFields);
65
81
  }
66
82
  ret.push(f);
67
83
  }
68
84
  return ret;
69
85
  }
86
+ async function transformServerDefault(name, f, value) {
87
+ if (f.valid) {
88
+ if (!(await f.valid(value))) {
89
+ throw new Error(`invalid value ${value} passed to field ${name}`);
90
+ }
91
+ }
92
+ if (f.format) {
93
+ value = await f.format(value);
94
+ }
95
+ switch (typeof value) {
96
+ case "boolean":
97
+ case "number":
98
+ case "bigint":
99
+ case "string":
100
+ return `${value}`;
101
+ default:
102
+ throw new Error(`invalid value ${value} passed to field ${name}`);
103
+ }
104
+ }
70
105
  function transformImportType(typ) {
71
106
  if (!typ.importType) {
72
107
  return;
@@ -108,12 +143,12 @@ function processEdgeGroups(processedSchema, edgeGroups) {
108
143
  processedSchema.assocEdgeGroups.push(group2);
109
144
  }
110
145
  }
111
- function processPattern(patterns, pattern, processedSchema) {
146
+ async function processPattern(patterns, pattern, processedSchema) {
112
147
  let ret = {
113
148
  ...pattern,
114
149
  };
115
150
  const name = pattern.name;
116
- const fields = processFields(pattern.fields, pattern.name);
151
+ const fields = await processFields(pattern.fields, pattern.name);
117
152
  processedSchema.fields.push(...fields);
118
153
  if (pattern.edges) {
119
154
  const edges = processEdges(pattern.edges, pattern.name);
@@ -130,6 +165,7 @@ function processPattern(patterns, pattern, processedSchema) {
130
165
  name: pattern.name,
131
166
  assocEdges: edges,
132
167
  fields: fields,
168
+ disableMixin: pattern.disableMixin,
133
169
  };
134
170
  }
135
171
  else {
@@ -171,9 +207,13 @@ function processAction(action) {
171
207
  ret.actionOnlyFields = actionOnlyFields;
172
208
  return ret;
173
209
  }
174
- function parseSchema(potentialSchemas) {
210
+ async function parseSchema(potentialSchemas, globalSchema) {
175
211
  let schemas = {};
176
212
  let patterns = {};
213
+ let parsedGlobalSchema;
214
+ if (globalSchema) {
215
+ parsedGlobalSchema = await parseGlobalSchema(globalSchema);
216
+ }
177
217
  for (const key in potentialSchemas) {
178
218
  const value = potentialSchemas[key];
179
219
  let schema;
@@ -202,9 +242,11 @@ function parseSchema(potentialSchemas) {
202
242
  };
203
243
  // let's put patterns first just so we have id, created_at, updated_at first
204
244
  // ¯\_(ツ)_/¯
245
+ let patternNames = [];
205
246
  if (schema.patterns) {
206
247
  for (const pattern of schema.patterns) {
207
- const ret = processPattern(patterns, pattern, processedSchema);
248
+ const ret = await processPattern(patterns, pattern, processedSchema);
249
+ patternNames.push(pattern.name);
208
250
  if (ret.transformsSelect) {
209
251
  if (processedSchema.transformsSelect) {
210
252
  throw new Error(`can only have one pattern which transforms default querying behavior`);
@@ -219,8 +261,9 @@ function parseSchema(potentialSchemas) {
219
261
  }
220
262
  }
221
263
  }
222
- const fields = processFields(schema.fields);
264
+ const fields = await processFields(schema.fields);
223
265
  processedSchema.fields.push(...fields);
266
+ processedSchema.patternNames = patternNames;
224
267
  if (schema.edges) {
225
268
  const edges = processEdges(schema.edges);
226
269
  processedSchema.assocEdges.push(...edges);
@@ -230,6 +273,22 @@ function parseSchema(potentialSchemas) {
230
273
  }
231
274
  schemas[key] = processedSchema;
232
275
  }
233
- return { schemas, patterns };
276
+ return { schemas, patterns, globalSchema: parsedGlobalSchema };
234
277
  }
235
278
  exports.parseSchema = parseSchema;
279
+ async function parseGlobalSchema(s) {
280
+ const ret = {
281
+ globalEdges: [],
282
+ extraEdgeFields: [],
283
+ initForEdges: !!s.extraEdgeFields ||
284
+ s.transformEdgeRead !== undefined ||
285
+ s.transformEdgeWrite !== undefined,
286
+ };
287
+ if (s.extraEdgeFields) {
288
+ ret.extraEdgeFields = await processFields(s.extraEdgeFields);
289
+ }
290
+ if (s.edges) {
291
+ ret.globalEdges = processEdges(s.edges);
292
+ }
293
+ return ret;
294
+ }
@@ -66,6 +66,7 @@ let nodeFieldsWithTZ = {
66
66
  exports.Node = {
67
67
  name: "node",
68
68
  fields: nodeFields,
69
+ disableMixin: true,
69
70
  };
70
71
  // Ent schema. has Node Pattern by default.
71
72
  // exists just to have less typing and easier for clients to implement
@@ -95,6 +96,7 @@ class EntSchemaWithTZ {
95
96
  // default schema added
96
97
  name: "nodeWithTZ",
97
98
  fields: nodeFieldsWithTZ,
99
+ disableMixin: true,
98
100
  },
99
101
  ];
100
102
  this.fields = cfg.fields;
@@ -131,6 +133,7 @@ class BaseEntSchemaWithTZ {
131
133
  // default schema added
132
134
  name: "nodeWithTZ",
133
135
  fields: nodeFieldsWithTZ,
136
+ disableMixin: true,
134
137
  },
135
138
  ];
136
139
  }
package/schema/field.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare function IntegerType(options?: IntegerOptions): IntegerField;
44
44
  export declare class BigIntegerField extends BaseField implements Field {
45
45
  type: Type;
46
46
  }
47
- export declare function BigIntegerType(options: FieldOptions): BigIntegerField;
47
+ export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
48
48
  export declare class FloatField extends BaseField implements Field {
49
49
  type: Type;
50
50
  }
@@ -118,31 +118,66 @@ export declare class DateField extends BaseField implements Field {
118
118
  format(val: any): any;
119
119
  }
120
120
  export declare function DateType(options?: FieldOptions): DateField;
121
- declare type EnumMap = {
121
+ declare type StringEnumMap = {
122
122
  [key: string]: string;
123
123
  };
124
+ /**
125
+ * @deprecated use StringEnumOptions
126
+ */
124
127
  export interface EnumOptions extends FieldOptions {
125
128
  values?: string[];
126
- map?: EnumMap;
129
+ map?: StringEnumMap;
127
130
  tsType?: string;
128
131
  graphQLType?: string;
129
132
  createEnumType?: boolean;
130
133
  }
134
+ /**
135
+ * @deprecated Use StringEnumField
136
+ */
131
137
  export declare class EnumField extends BaseField implements Field {
132
138
  type: Type;
133
139
  private values?;
134
140
  private map?;
135
- constructor(options: EnumOptions);
141
+ constructor(options: StringEnumOptions);
136
142
  convertForGQL(value: string): string;
137
143
  valid(val: any): boolean;
138
144
  format(val: any): any;
139
145
  }
140
- export declare function EnumType(options: EnumOptions): EnumField;
146
+ export declare class StringEnumField extends EnumField {
147
+ }
148
+ export interface PolymorphicStringEnumOptions extends EnumOptions {
149
+ parentFieldToValidate: string;
150
+ }
151
+ export interface StringEnumOptions extends EnumOptions {
152
+ }
153
+ export declare function EnumType(options: StringEnumOptions): EnumField;
154
+ declare type IntEnumMap = {
155
+ [key: string]: number;
156
+ };
157
+ export interface IntegerEnumOptions extends FieldOptions {
158
+ map: IntEnumMap;
159
+ deprecated?: IntEnumMap;
160
+ tsType?: string;
161
+ graphQLType?: string;
162
+ }
163
+ export declare class IntegerEnumField extends BaseField implements Field {
164
+ type: Type;
165
+ private map;
166
+ constructor(options: IntegerEnumOptions);
167
+ valid(val: any): boolean;
168
+ format(val: any): any;
169
+ }
170
+ export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
171
+ interface ListOptions extends FieldOptions {
172
+ disableJSONStringify?: boolean;
173
+ }
141
174
  export declare class ListField extends BaseField {
142
175
  private field;
176
+ private options?;
143
177
  type: Type;
144
178
  private validators;
145
- constructor(field: Field, options?: FieldOptions);
179
+ constructor(field: Field, options?: ListOptions | undefined);
180
+ __getElemField(): Field;
146
181
  validate(validator: (val: any[]) => boolean): this;
147
182
  valid(val: any): Promise<boolean>;
148
183
  private postgresVal;
@@ -153,7 +188,7 @@ export declare class ListField extends BaseField {
153
188
  range(start: any, stop: any): this;
154
189
  }
155
190
  export declare function StringListType(options?: StringOptions): ListField;
156
- export declare function IntListType(options: FieldOptions): ListField;
191
+ export declare function IntListType(options?: FieldOptions): ListField;
157
192
  export declare function IntegerListType(options?: FieldOptions): ListField;
158
193
  export declare function FloatListType(options?: FieldOptions): ListField;
159
194
  export declare function BigIntegerListType(options: FieldOptions): ListField;
@@ -163,6 +198,7 @@ export declare function TimestamptzListType(options?: TimestampOptions): ListFie
163
198
  export declare function TimeListType(options?: TimeOptions): ListField;
164
199
  export declare function TimetzListType(options: TimeOptions): ListField;
165
200
  export declare function DateListType(options?: FieldOptions): ListField;
166
- export declare function EnumListType(options: EnumOptions): ListField;
201
+ export declare function EnumListType(options: StringEnumOptions): ListField;
202
+ export declare function IntegerEnumListType(options: IntegerEnumOptions): ListField;
167
203
  export declare function UUIDListType(options?: FieldOptions): ListField;
168
204
  export {};