@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha73

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 (112) hide show
  1. package/action/action.d.ts +28 -24
  2. package/action/executor.d.ts +4 -4
  3. package/action/executor.js +2 -2
  4. package/action/experimental_action.d.ts +29 -22
  5. package/action/experimental_action.js +29 -6
  6. package/action/orchestrator.d.ts +44 -16
  7. package/action/orchestrator.js +287 -73
  8. package/action/privacy.d.ts +2 -2
  9. package/core/base.d.ts +35 -23
  10. package/core/base.js +16 -0
  11. package/core/clause.d.ts +69 -3
  12. package/core/clause.js +420 -5
  13. package/core/config.d.ts +26 -0
  14. package/core/config.js +17 -0
  15. package/core/context.d.ts +2 -2
  16. package/core/context.js +2 -2
  17. package/core/convert.d.ts +1 -1
  18. package/core/db.d.ts +3 -4
  19. package/core/db.js +2 -0
  20. package/core/ent.d.ts +62 -27
  21. package/core/ent.js +272 -63
  22. package/core/loaders/assoc_count_loader.d.ts +2 -2
  23. package/core/loaders/assoc_count_loader.js +6 -1
  24. package/core/loaders/assoc_edge_loader.d.ts +3 -3
  25. package/core/loaders/assoc_edge_loader.js +5 -4
  26. package/core/loaders/index_loader.js +1 -0
  27. package/core/loaders/loader.js +5 -5
  28. package/core/loaders/object_loader.d.ts +10 -5
  29. package/core/loaders/object_loader.js +58 -4
  30. package/core/loaders/query_loader.d.ts +2 -2
  31. package/core/loaders/raw_count_loader.d.ts +2 -2
  32. package/core/logger.d.ts +1 -1
  33. package/core/logger.js +1 -0
  34. package/core/privacy.d.ts +25 -25
  35. package/core/privacy.js +5 -5
  36. package/core/query/assoc_query.d.ts +6 -6
  37. package/core/query/custom_query.d.ts +5 -5
  38. package/core/query/query.d.ts +1 -1
  39. package/core/query/shared_assoc_test.d.ts +1 -1
  40. package/core/query/shared_assoc_test.js +17 -5
  41. package/core/query/shared_test.d.ts +3 -0
  42. package/core/query/shared_test.js +95 -17
  43. package/core/viewer.d.ts +4 -3
  44. package/core/viewer.js +4 -0
  45. package/graphql/builtins/connection.js +3 -3
  46. package/graphql/builtins/edge.js +2 -2
  47. package/graphql/builtins/node.js +1 -1
  48. package/graphql/graphql.d.ts +3 -2
  49. package/graphql/graphql.js +30 -23
  50. package/graphql/node_resolver.d.ts +0 -1
  51. package/graphql/query/connection_type.js +6 -6
  52. package/graphql/query/edge_connection.d.ts +9 -9
  53. package/graphql/query/page_info.d.ts +1 -1
  54. package/graphql/query/page_info.js +4 -4
  55. package/graphql/query/shared_assoc_test.js +2 -2
  56. package/graphql/scalars/time.d.ts +1 -1
  57. package/index.d.ts +21 -1
  58. package/index.js +24 -5
  59. package/package.json +3 -3
  60. package/parse_schema/parse.d.ts +24 -5
  61. package/parse_schema/parse.js +90 -8
  62. package/schema/base_schema.d.ts +36 -1
  63. package/schema/base_schema.js +51 -2
  64. package/schema/field.d.ts +34 -6
  65. package/schema/field.js +67 -2
  66. package/schema/index.d.ts +2 -2
  67. package/schema/index.js +8 -1
  68. package/schema/schema.d.ts +100 -2
  69. package/schema/schema.js +127 -5
  70. package/scripts/custom_graphql.js +127 -16
  71. package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
  72. package/scripts/migrate_v0.1.js +36 -0
  73. package/scripts/read_schema.js +25 -2
  74. package/testutils/builder.d.ts +36 -22
  75. package/testutils/builder.js +110 -13
  76. package/testutils/context/test_context.d.ts +2 -2
  77. package/testutils/context/test_context.js +7 -1
  78. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
  79. package/testutils/db/{test_db.js → temp_db.js} +76 -19
  80. package/testutils/ent-graphql-tests/index.d.ts +2 -0
  81. package/testutils/ent-graphql-tests/index.js +26 -17
  82. package/testutils/fake_data/fake_contact.d.ts +5 -9
  83. package/testutils/fake_data/fake_contact.js +17 -21
  84. package/testutils/fake_data/fake_event.d.ts +5 -9
  85. package/testutils/fake_data/fake_event.js +24 -28
  86. package/testutils/fake_data/fake_user.d.ts +6 -10
  87. package/testutils/fake_data/fake_user.js +25 -29
  88. package/testutils/fake_data/test_helpers.d.ts +2 -2
  89. package/testutils/fake_data/test_helpers.js +6 -6
  90. package/testutils/fake_data/user_query.d.ts +2 -2
  91. package/testutils/fake_log.d.ts +3 -3
  92. package/testutils/parse_sql.d.ts +6 -0
  93. package/testutils/parse_sql.js +16 -2
  94. package/testutils/test_edge_global_schema.d.ts +15 -0
  95. package/testutils/test_edge_global_schema.js +58 -0
  96. package/testutils/write.d.ts +2 -2
  97. package/testutils/write.js +3 -3
  98. package/tsc/ast.d.ts +44 -0
  99. package/tsc/ast.js +267 -0
  100. package/tsc/compilerOptions.d.ts +6 -0
  101. package/tsc/compilerOptions.js +40 -1
  102. package/tsc/move_generated.d.ts +1 -0
  103. package/tsc/move_generated.js +160 -0
  104. package/tsc/transform.d.ts +21 -0
  105. package/tsc/transform.js +167 -0
  106. package/tsc/transform_action.d.ts +22 -0
  107. package/tsc/transform_action.js +179 -0
  108. package/tsc/transform_ent.d.ts +17 -0
  109. package/tsc/transform_ent.js +59 -0
  110. package/tsc/transform_schema.d.ts +27 -0
  111. package/tsc/transform_schema.js +379 -0
  112. package/scripts/transform_schema.js +0 -288
package/core/base.d.ts CHANGED
@@ -30,27 +30,27 @@ interface queryOptions {
30
30
  clause: clause.Clause;
31
31
  orderby?: string;
32
32
  }
33
- export interface Context {
34
- getViewer(): Viewer;
33
+ export interface Context<TViewer extends Viewer = Viewer> {
34
+ getViewer(): TViewer;
35
35
  cache?: cache;
36
36
  }
37
- export interface Viewer {
38
- viewerID: ID | null;
39
- viewer: () => Promise<Ent | null>;
37
+ export interface Viewer<TEnt extends any = Ent<any> | null, TID extends any = ID | null> {
38
+ viewerID: TID;
39
+ viewer: () => Promise<TEnt>;
40
40
  instanceKey: () => string;
41
- context?: Context;
41
+ context?: Context<any>;
42
42
  }
43
- export interface Ent {
43
+ export interface Ent<TViewer extends Viewer = Viewer> {
44
44
  id: ID;
45
- viewer: Viewer;
46
- privacyPolicy: PrivacyPolicy<this>;
45
+ viewer: TViewer;
46
+ getPrivacyPolicy(): PrivacyPolicy<this, TViewer>;
47
47
  nodeType: string;
48
48
  }
49
49
  export declare type Data = {
50
50
  [key: string]: any;
51
51
  };
52
- export interface EntConstructor<T extends Ent> {
53
- new (viewer: Viewer, data: Data): T;
52
+ export interface EntConstructor<TEnt extends Ent, TViewer extends Viewer = Viewer> {
53
+ new (viewer: TViewer, data: Data): TEnt;
54
54
  }
55
55
  export declare type ID = string | number;
56
56
  export interface DataOptions {
@@ -62,6 +62,7 @@ export interface SelectBaseDataOptions extends DataOptions {
62
62
  }
63
63
  export interface SelectDataOptions extends SelectBaseDataOptions {
64
64
  key: string;
65
+ clause?: clause.Clause | (() => clause.Clause | undefined);
65
66
  }
66
67
  export interface QueryableDataOptions extends SelectBaseDataOptions, QueryDataOptions {
67
68
  }
@@ -71,6 +72,7 @@ export interface QueryDataOptions {
71
72
  orderby?: string;
72
73
  groupby?: string;
73
74
  limit?: number;
75
+ disableTransformations?: boolean;
74
76
  }
75
77
  export interface LoadRowOptions extends QueryableDataOptions {
76
78
  }
@@ -81,16 +83,25 @@ export interface CreateRowOptions extends DataOptions {
81
83
  fieldsToLog?: Data;
82
84
  }
83
85
  export interface EditRowOptions extends CreateRowOptions {
84
- key: string;
86
+ whereClause: clause.Clause;
85
87
  }
86
- interface LoadableEntOptions<T extends Ent> {
87
- loaderFactory: LoaderFactory<any, Data | null>;
88
- ent: EntConstructor<T>;
88
+ interface LoadableEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> {
89
+ loaderFactory: LoaderFactoryWithOptions;
90
+ ent: EntConstructor<TEnt, TViewer>;
91
+ }
92
+ interface LoaderFactoryWithOptions extends LoaderFactory<any, Data | null> {
93
+ options?: SelectDataOptions;
94
+ }
95
+ export interface LoadEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends LoadableEntOptions<TEnt, TViewer>, SelectBaseDataOptions {
96
+ fieldPrivacy?: Map<string, PrivacyPolicy>;
89
97
  }
90
- export interface LoadEntOptions<T extends Ent> extends LoadableEntOptions<T>, SelectBaseDataOptions {
98
+ export interface SelectCustomDataOptions extends SelectBaseDataOptions {
99
+ clause?: clause.Clause;
100
+ loaderFactory?: LoaderFactoryWithOptions;
91
101
  }
92
- export interface LoadCustomEntOptions<T extends Ent> extends SelectBaseDataOptions {
93
- ent: EntConstructor<T>;
102
+ export interface LoadCustomEntOptions<TEnt extends Ent, TViewer extends Viewer = Viewer> extends SelectCustomDataOptions {
103
+ ent: EntConstructor<TEnt, TViewer>;
104
+ fieldPrivacy?: Map<string, PrivacyPolicy>;
94
105
  }
95
106
  export interface LoaderInfo {
96
107
  tableName: string;
@@ -108,6 +119,7 @@ declare enum privacyResult {
108
119
  export interface PrivacyResult {
109
120
  result: privacyResult;
110
121
  error?: PrivacyError;
122
+ getError?(policy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent): PrivacyError;
111
123
  }
112
124
  export interface PrivacyError extends Error {
113
125
  privacyPolicy: PrivacyPolicy<Ent>;
@@ -116,11 +128,11 @@ export interface PrivacyError extends Error {
116
128
  export declare function Allow(): PrivacyResult;
117
129
  export declare function Skip(): PrivacyResult;
118
130
  export declare function Deny(): PrivacyResult;
119
- export declare function DenyWithReason(e: PrivacyError): PrivacyResult;
120
- export interface PrivacyPolicyRule<TEnt extends Ent = Ent> {
121
- apply(v: Viewer, ent?: TEnt): Promise<PrivacyResult>;
131
+ export declare function DenyWithReason(e: PrivacyError | string): PrivacyResult;
132
+ export interface PrivacyPolicyRule<TEnt extends Ent = Ent, TViewer = Viewer> {
133
+ apply(v: TViewer, ent?: TEnt): Promise<PrivacyResult>;
122
134
  }
123
- export interface PrivacyPolicy<TEnt extends Ent = Ent> {
124
- rules: PrivacyPolicyRule<TEnt>[];
135
+ export interface PrivacyPolicy<TEnt extends Ent = Ent, TViewer = Viewer> {
136
+ rules: PrivacyPolicyRule<TEnt, TViewer>[];
125
137
  }
126
138
  export {};
package/core/base.js CHANGED
@@ -30,7 +30,23 @@ function Deny() {
30
30
  return deny;
31
31
  }
32
32
  exports.Deny = Deny;
33
+ class DenyWithReasonError extends Error {
34
+ constructor(privacyPolicy, rule, msg, ent) {
35
+ super(msg);
36
+ this.privacyPolicy = privacyPolicy;
37
+ this.privacyRule = rule;
38
+ this.ent = ent;
39
+ }
40
+ }
33
41
  function DenyWithReason(e) {
42
+ if (typeof e === "string") {
43
+ return {
44
+ result: privacyResult.Deny,
45
+ getError(policy, rule, ent) {
46
+ return new DenyWithReasonError(policy, rule, e, ent);
47
+ },
48
+ };
49
+ }
34
50
  return {
35
51
  result: privacyResult.Deny,
36
52
  error: e,
package/core/clause.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export interface Clause {
2
2
  clause(idx: number): string;
3
+ columns(): string[];
3
4
  values(): any[];
4
5
  instanceKey(): string;
5
6
  logValues(): any[];
@@ -12,8 +13,11 @@ declare class simpleClause implements Clause {
12
13
  protected col: string;
13
14
  private value;
14
15
  private op;
15
- constructor(col: string, value: any, op: string);
16
+ private handleNull?;
17
+ constructor(col: string, value: any, op: string, handleNull?: Clause | undefined);
16
18
  clause(idx: number): string;
19
+ private nullClause;
20
+ columns(): string[];
17
21
  values(): any[];
18
22
  logValues(): any[];
19
23
  instanceKey(): string;
@@ -23,18 +27,80 @@ declare class compositeClause implements Clause {
23
27
  private sep;
24
28
  constructor(clauses: Clause[], sep: string);
25
29
  clause(idx: number): string;
30
+ columns(): string[];
26
31
  values(): any[];
27
32
  logValues(): any[];
28
33
  instanceKey(): string;
29
34
  }
30
- export declare function Eq(col: string, value: any): simpleClause;
31
- export declare function NotEq(col: string, value: any): simpleClause;
35
+ /**
36
+ * creates a clause to determine if the given value is contained in the array stored in the column in the db
37
+ * only works with postgres gin indexes
38
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
39
+ */
40
+ export declare function PostgresArrayContainsValue(col: string, value: any): Clause;
41
+ /**
42
+ * creates a clause to determine if every item in the list is stored in the array stored in the column in the db
43
+ * only works with postgres gin indexes
44
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
45
+ */
46
+ export declare function PostgresArrayContains(col: string, value: any[]): Clause;
47
+ /**
48
+ * creates a clause to determine if the given value is NOT contained in the array stored in the column in the db
49
+ * only works with postgres gin indexes
50
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
51
+ */
52
+ export declare function PostgresArrayNotContainsValue(col: string, value: any): Clause;
53
+ /**
54
+ * creates a clause to determine if every item in the list is NOT stored in the array stored in the column in the db
55
+ * only works with postgres gin indexes
56
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
57
+ */
58
+ export declare function PostgresArrayNotContains(col: string, value: any[]): Clause;
59
+ /**
60
+ * creates a clause to determine if the arrays overlap, that is, do they have any elements in common
61
+ * only works with postgres gin indexes
62
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
63
+ */
64
+ export declare function PostgresArrayOverlaps(col: string, value: any[]): Clause;
65
+ /**
66
+ * creates a clause to determine if the arrays do not overlap, that is, do they have any elements in common
67
+ * only works with postgres gin indexes
68
+ * https://www.postgresql.org/docs/current/indexes-types.html#INDEXES-TYPES-GIN
69
+ */
70
+ export declare function PostgresArrayNotOverlaps(col: string, value: any[]): Clause;
71
+ /**
72
+ * @deprecated use PostgresArrayContainsValue
73
+ */
74
+ export declare function ArrayEq(col: string, value: any): Clause;
75
+ /**
76
+ * @deprecated use PostgresNotArrayContains
77
+ */
78
+ export declare function ArrayNotEq(col: string, value: any): Clause;
79
+ export declare function Eq(col: string, value: any): Clause;
80
+ export declare function NotEq(col: string, value: any): Clause;
32
81
  export declare function Greater(col: string, value: any): simpleClause;
33
82
  export declare function Less(col: string, value: any): simpleClause;
34
83
  export declare function GreaterEq(col: string, value: any): simpleClause;
35
84
  export declare function LessEq(col: string, value: any): simpleClause;
36
85
  export declare function And(...args: Clause[]): compositeClause;
86
+ export declare function AndOptional(...args: (Clause | undefined)[]): Clause;
37
87
  export declare function Or(...args: Clause[]): compositeClause;
38
88
  export declare function In(col: string, ...values: any): Clause;
89
+ interface TsQuery {
90
+ language: "english" | "french" | "german" | "simple";
91
+ value: string;
92
+ }
93
+ export declare function TsQuery(col: string, val: string | TsQuery): Clause;
94
+ export declare function PlainToTsQuery(col: string, val: string | TsQuery): Clause;
95
+ export declare function PhraseToTsQuery(col: string, val: string | TsQuery): Clause;
96
+ export declare function WebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
97
+ export declare function TsVectorColTsQuery(col: string, val: string | TsQuery): Clause;
98
+ export declare function TsVectorPlainToTsQuery(col: string, val: string | TsQuery): Clause;
99
+ export declare function TsVectorPhraseToTsQuery(col: string, val: string | TsQuery): Clause;
100
+ export declare function TsVectorWebsearchToTsQuery(col: string, val: string | TsQuery): Clause;
39
101
  export declare function sensitiveValue(val: any): SensitiveValue;
102
+ export declare function JSONObjectFieldKeyASJSON(col: string, field: string): string;
103
+ export declare function JSONObjectFieldKeyAsText(col: string, field: string): string;
104
+ declare type predicate = "==" | ">" | "<" | "!=" | ">=" | "<=";
105
+ export declare function JSONPathValuePredicate(dbCol: string, path: string, val: any, pred: predicate): Clause;
40
106
  export {};