@snowtop/ent 0.1.11 → 0.1.13

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 (47) hide show
  1. package/action/experimental_action.js +2 -2
  2. package/action/operations.js +4 -2
  3. package/core/base.d.ts +12 -10
  4. package/core/clause.d.ts +4 -3
  5. package/core/clause.js +98 -43
  6. package/core/config.d.ts +6 -0
  7. package/core/context.d.ts +6 -14
  8. package/core/context.js +9 -4
  9. package/core/db.js +1 -1
  10. package/core/ent.d.ts +1 -0
  11. package/core/ent.js +30 -11
  12. package/core/loaders/assoc_count_loader.js +1 -1
  13. package/core/loaders/assoc_edge_loader.d.ts +3 -0
  14. package/core/loaders/assoc_edge_loader.js +18 -0
  15. package/core/loaders/object_loader.js +2 -2
  16. package/core/loaders/query_loader.d.ts +3 -3
  17. package/core/loaders/query_loader.js +2 -1
  18. package/core/loaders/raw_count_loader.js +1 -1
  19. package/core/query/assoc_query.d.ts +22 -0
  20. package/core/query/assoc_query.js +101 -2
  21. package/core/query/custom_query.js +2 -9
  22. package/core/query/query.d.ts +1 -0
  23. package/core/query/query.js +72 -11
  24. package/core/query/shared_assoc_test.js +404 -7
  25. package/core/query/shared_test.js +9 -37
  26. package/core/query_impl.d.ts +2 -1
  27. package/core/query_impl.js +25 -7
  28. package/graphql/query/edge_connection.js +2 -2
  29. package/package.json +2 -2
  30. package/parse_schema/parse.d.ts +4 -3
  31. package/parse_schema/parse.js +4 -3
  32. package/schema/base_schema.d.ts +3 -0
  33. package/schema/base_schema.js +2 -0
  34. package/schema/schema.d.ts +1 -0
  35. package/schema/struct_field.d.ts +4 -2
  36. package/schema/struct_field.js +33 -4
  37. package/scripts/custom_graphql.js +1 -1
  38. package/testutils/builder.d.ts +1 -1
  39. package/testutils/builder.js +4 -4
  40. package/testutils/ent-graphql-tests/index.js +2 -2
  41. package/testutils/fake_data/fake_contact.js +1 -1
  42. package/testutils/fake_data/fake_event.js +1 -1
  43. package/testutils/fake_data/test_helpers.js +2 -2
  44. package/testutils/fake_data/user_query.js +1 -1
  45. package/testutils/query.d.ts +9 -0
  46. package/testutils/query.js +45 -0
  47. package/testutils/write.js +3 -3
@@ -20,13 +20,14 @@ interface TransformFlags {
20
20
  transformsInsert?: boolean;
21
21
  transformsUpdate?: boolean;
22
22
  }
23
- type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields"> & TransformFlags & {
23
+ type ProcessedSchema = Omit<Schema, "edges" | "actions" | "edgeGroups" | "fields" | "defaultActionPrivacy"> & TransformFlags & {
24
24
  actions: OutputAction[];
25
25
  assocEdges: ProcessedAssocEdge[];
26
26
  assocEdgeGroups: ProcessedAssocEdgeGroup[];
27
27
  fields: ProcessedField[];
28
28
  schemaPath?: string;
29
29
  patternNames?: string[];
30
+ hasDefaultActionPrivacy?: boolean;
30
31
  };
31
32
  type ProcessedAssocEdgeGroup = Omit<AssocEdgeGroup, "edgeAction"> & {
32
33
  edgeAction?: OutputAction;
@@ -68,14 +69,14 @@ interface Result {
68
69
  patterns: patternsDict;
69
70
  globalSchema?: ProcessedGlobalSchema;
70
71
  config?: {
71
- rome?: RomeConfig;
72
+ rome?: BiomeConfig;
72
73
  };
73
74
  }
74
75
  declare type PotentialSchemas = {
75
76
  [key: string]: any;
76
77
  };
77
78
  export declare function parseSchema(potentialSchemas: PotentialSchemas, globalSchema?: GlobalSchema): Promise<Result>;
78
- interface RomeConfig {
79
+ interface BiomeConfig {
79
80
  indentStyle?: string;
80
81
  lineWidth?: number;
81
82
  indentSize?: number;
@@ -278,6 +278,7 @@ async function parseSchema(potentialSchemas, globalSchema) {
278
278
  supportUpsert: schema.supportUpsert,
279
279
  showCanViewerSee: schema.showCanViewerSee,
280
280
  showCanViewerEdit: schema.showCanViewerEdit,
281
+ hasDefaultActionPrivacy: schema.defaultActionPrivacy !== undefined,
281
282
  };
282
283
  // let's put patterns first just so we have id, created_at, updated_at first
283
284
  // ¯\_(ツ)_/¯
@@ -316,13 +317,13 @@ async function parseSchema(potentialSchemas, globalSchema) {
316
317
  }
317
318
  schemas[key] = processedSchema;
318
319
  }
319
- const rome = translatePrettier();
320
+ const biome = translatePrettier();
320
321
  return {
321
322
  schemas,
322
323
  patterns,
323
324
  globalSchema: parsedGlobalSchema,
324
325
  config: {
325
- rome,
326
+ rome: biome,
326
327
  },
327
328
  };
328
329
  }
@@ -353,7 +354,7 @@ function translatePrettier() {
353
354
  }
354
355
  if (r.config.quoteProps !== undefined) {
355
356
  if (r.config.quoteProps === "consistent") {
356
- // rome doesn't support this
357
+ // biome doesn't support this
357
358
  ret.quoteProperties = "as-needed";
358
359
  }
359
360
  else {
@@ -1,5 +1,6 @@
1
1
  import { FieldMap, Pattern, FieldOverrideMap } from "./schema";
2
2
  import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
3
+ import { PrivacyPolicy } from "../core/base";
3
4
  export declare const Timestamps: Pattern;
4
5
  export declare const Node: Pattern;
5
6
  export interface SchemaConfig extends Schema {
@@ -23,6 +24,7 @@ export declare class EntSchema implements Schema {
23
24
  supportUpsert?: boolean | undefined;
24
25
  showCanViewerSee?: boolean | undefined;
25
26
  showCanViewerEdit?: boolean | undefined;
27
+ defaultActionPrivacy?: PrivacyPolicy | (() => PrivacyPolicy);
26
28
  constructor(cfg: SchemaConfig);
27
29
  }
28
30
  export declare class EntSchemaWithTZ implements Schema {
@@ -44,6 +46,7 @@ export declare class EntSchemaWithTZ implements Schema {
44
46
  supportUpsert?: boolean | undefined;
45
47
  showCanViewerSee?: boolean | undefined;
46
48
  showCanViewerEdit?: boolean | undefined;
49
+ defaultActionPrivacy?: PrivacyPolicy | (() => PrivacyPolicy);
47
50
  constructor(cfg: SchemaConfig);
48
51
  }
49
52
  export declare abstract class BaseEntSchema {
@@ -93,6 +93,7 @@ class EntSchema {
93
93
  this.supportUpsert = cfg.supportUpsert;
94
94
  this.showCanViewerSee = cfg.showCanViewerSee;
95
95
  this.showCanViewerEdit = cfg.showCanViewerEdit;
96
+ this.defaultActionPrivacy = cfg.defaultActionPrivacy;
96
97
  }
97
98
  }
98
99
  exports.EntSchema = EntSchema;
@@ -125,6 +126,7 @@ class EntSchemaWithTZ {
125
126
  this.supportUpsert = cfg.supportUpsert;
126
127
  this.showCanViewerSee = cfg.showCanViewerSee;
127
128
  this.showCanViewerEdit = cfg.showCanViewerEdit;
129
+ this.defaultActionPrivacy = cfg.defaultActionPrivacy;
128
130
  }
129
131
  }
130
132
  exports.EntSchemaWithTZ = EntSchemaWithTZ;
@@ -42,6 +42,7 @@ export default interface Schema {
42
42
  supportUpsert?: boolean;
43
43
  showCanViewerSee?: boolean;
44
44
  showCanViewerEdit?: boolean;
45
+ defaultActionPrivacy?: PrivacyPolicy | (() => PrivacyPolicy);
45
46
  }
46
47
  export interface AssocEdge {
47
48
  name: string;
@@ -17,16 +17,18 @@ export declare class StructField extends BaseField implements Field {
17
17
  private options;
18
18
  private jsonAsList?;
19
19
  type: Type;
20
+ private validateUniqueKey?;
21
+ private checkUniqueKey;
20
22
  constructor(options: StructOptions, jsonAsList?: boolean | undefined);
21
23
  formatImpl(obj: any, nested?: boolean): string | Object;
22
24
  format(obj: any, nested?: boolean): any;
23
25
  private validImpl;
24
26
  valid(obj: any): Promise<boolean>;
25
27
  }
26
- export declare function StructType(options: StructOptions): StructField & StructOptions;
28
+ export declare function StructType(options: StructOptions): (StructField & structFieldOptions) | (StructField & GlobalStructOptions);
27
29
  /**
28
30
  * @deprecated use StructTypeAsList
29
31
  */
30
32
  export declare function StructListType(options: StructOptions): ListField;
31
- export declare function StructTypeAsList(options: StructOptions): StructField & StructOptions;
33
+ export declare function StructTypeAsList(options: StructOptions): (StructField & structFieldOptions) | (StructField & GlobalStructOptions);
32
34
  export {};
@@ -26,6 +26,10 @@ class StructField extends field_1.BaseField {
26
26
  dbType: schema_1.DBType.JSONB,
27
27
  };
28
28
  }
29
+ if (options.validateUniqueKey) {
30
+ this.validateUniqueKey = options.validateUniqueKey;
31
+ this.checkUniqueKey = true;
32
+ }
29
33
  }
30
34
  formatImpl(obj, nested) {
31
35
  if (!(obj instanceof Object)) {
@@ -113,9 +117,27 @@ class StructField extends field_1.BaseField {
113
117
  let dbKey = (0, schema_1.getStorageKey)(field, k);
114
118
  let camelKey = (0, camel_case_1.camelCase)(k);
115
119
  let val = obj[camelKey];
120
+ let uniqueKeyField = false;
121
+ if (this.validateUniqueKey !== undefined &&
122
+ (camelKey === this.validateUniqueKey ||
123
+ k === this.validateUniqueKey ||
124
+ dbKey === this.validateUniqueKey)) {
125
+ // this.validateUniqueKey = camelKey;
126
+ uniqueKeyField = true;
127
+ }
128
+ if (uniqueKeyField && this.checkUniqueKey) {
129
+ this.validateUniqueKey = camelKey;
130
+ }
116
131
  if (val === undefined && obj[dbKey] !== undefined) {
132
+ if (uniqueKeyField && this.checkUniqueKey) {
133
+ this.validateUniqueKey = dbKey;
134
+ }
117
135
  val = obj[dbKey];
118
136
  }
137
+ // we've processed this once and no need to process this again
138
+ if (uniqueKeyField && this.checkUniqueKey) {
139
+ this.checkUniqueKey = false;
140
+ }
119
141
  if (val === undefined || val === null) {
120
142
  // nullable, nothing to do here
121
143
  if (field.nullable) {
@@ -168,16 +190,23 @@ class StructField extends field_1.BaseField {
168
190
  if (!Array.isArray(obj)) {
169
191
  return false;
170
192
  }
193
+ // hmm shared instance across tests means this is needed.
194
+ // are there other places that have an issue like this???
195
+ this.checkUniqueKey = true;
171
196
  const unique = new Set();
172
- const valid = await Promise.all(obj.map((v) => {
173
- if (this.options.validateUniqueKey) {
174
- const value = v[this.options.validateUniqueKey];
197
+ const valid = await Promise.all(obj.map(async (v) => {
198
+ const valid = await this.validImpl(v);
199
+ if (!valid) {
200
+ return false;
201
+ }
202
+ if (this.validateUniqueKey) {
203
+ let value = v[this.validateUniqueKey];
175
204
  if (unique.has(value)) {
176
205
  return false;
177
206
  }
178
207
  unique.add(value);
179
208
  }
180
- return this.validImpl(v);
209
+ return true;
181
210
  }));
182
211
  return valid.every((b) => b);
183
212
  }
@@ -43,7 +43,7 @@ const const_1 = require("../core/const");
43
43
  // life is hard
44
44
  const MODULE_PATH = const_1.GRAPHQL_PATH;
45
45
  async function readInputs() {
46
- return await new Promise((resolve) => {
46
+ return new Promise((resolve) => {
47
47
  const rl = readline.createInterface({
48
48
  input: process.stdin,
49
49
  // output: process.stdout,
@@ -4,7 +4,7 @@ import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observe
4
4
  import { FieldMap, Schema } from "../schema";
5
5
  import { SchemaConfig, EntSchema } from "../schema/base_schema";
6
6
  import { FieldInfoMap } from "../schema/schema";
7
- import { Clause } from "src/core/clause";
7
+ import { Clause } from "../core/clause";
8
8
  import { ChangesetOptions } from "../action/action";
9
9
  export declare class BaseEnt {
10
10
  viewer: Viewer;
@@ -248,10 +248,10 @@ class SimpleBuilder {
248
248
  return this.orchestrator.buildWithOptions_BETA(options);
249
249
  }
250
250
  async editedEnt() {
251
- return await this.orchestrator.editedEnt();
251
+ return this.orchestrator.editedEnt();
252
252
  }
253
253
  async editedEntX() {
254
- return await this.orchestrator.editedEntX();
254
+ return this.orchestrator.editedEntX();
255
255
  }
256
256
  async save() {
257
257
  await (0, action_1.saveBuilder)(this);
@@ -260,10 +260,10 @@ class SimpleBuilder {
260
260
  await (0, action_1.saveBuilderX)(this);
261
261
  }
262
262
  async valid() {
263
- return await this.orchestrator.valid();
263
+ return this.orchestrator.valid();
264
264
  }
265
265
  async validX() {
266
- return await this.orchestrator.validX();
266
+ return this.orchestrator.validX();
267
267
  }
268
268
  }
269
269
  exports.SimpleBuilder = SimpleBuilder;
@@ -275,7 +275,7 @@ function expectQueryResult(schema, fieldType, ...options) {
275
275
  }
276
276
  async function expectQueryFromRoot(config, ...options // TODO queries? expected values
277
277
  ) {
278
- return await expectFromRoot({
278
+ return expectFromRoot({
279
279
  ...config,
280
280
  queryPrefix: "query",
281
281
  querySuffix: "Query",
@@ -292,7 +292,7 @@ async function expectMutation(config, ...options) {
292
292
  input: args,
293
293
  };
294
294
  }
295
- return await expectFromRoot({
295
+ return expectFromRoot({
296
296
  ...config,
297
297
  args: args,
298
298
  root: config.mutation,
@@ -89,7 +89,7 @@ function getContactBuilder(viewer, input) {
89
89
  exports.getContactBuilder = getContactBuilder;
90
90
  async function createContact(viewer, input) {
91
91
  const builder = getContactBuilder(viewer, input);
92
- return await builder.saveX();
92
+ return builder.saveX();
93
93
  }
94
94
  exports.createContact = createContact;
95
95
  exports.contactLoader = new loaders_1.ObjectLoaderFactory({
@@ -93,6 +93,6 @@ function getEventBuilder(viewer, input) {
93
93
  exports.getEventBuilder = getEventBuilder;
94
94
  async function createEvent(viewer, input) {
95
95
  const builder = getEventBuilder(viewer, input);
96
- return await builder.saveX();
96
+ return builder.saveX();
97
97
  }
98
98
  exports.createEvent = createEvent;
@@ -110,7 +110,7 @@ async function createAllContacts(opts) {
110
110
  time: new Date(), // set time to advanceBy time
111
111
  });
112
112
  await builder.saveX();
113
- return await builder.editedEntX();
113
+ return builder.editedEntX();
114
114
  }));
115
115
  expect(contacts.length).toBe(userInputs.length);
116
116
  return [userr, contacts];
@@ -221,7 +221,7 @@ async function createTestEvent(user, input) {
221
221
  });
222
222
  builder.orchestrator.addOutboundEdge(user.id, _1.EdgeType.EventToHosts, "User");
223
223
  await builder.saveX();
224
- return await builder.editedEntX();
224
+ return builder.editedEntX();
225
225
  }
226
226
  exports.createTestEvent = createTestEvent;
227
227
  async function setupTempDB(global = false) {
@@ -158,7 +158,7 @@ class CustomEdge extends ent_1.AssocEdge {
158
158
  this.deleted_at = data.deleted_at;
159
159
  }
160
160
  async loadUser(viewer) {
161
- return await internal_1.FakeUser.load(viewer, this.id2);
161
+ return internal_1.FakeUser.load(viewer, this.id2);
162
162
  }
163
163
  }
164
164
  exports.CustomEdge = CustomEdge;
@@ -0,0 +1,9 @@
1
+ import { Data, Ent, Viewer } from "../core/base";
2
+ import { FakeUser } from "./fake_data";
3
+ import { EdgeQuery } from "../core/query";
4
+ import { MockLogs } from "./mock_log";
5
+ export declare function getVerifyAfterEachCursorGeneric<TSource extends Ent<Viewer>, TDest extends Ent<Viewer>, TData extends Data>(edges: TData[], pageLength: number, user: FakeUser, getQuery: () => EdgeQuery<TSource, TDest, TData>, ml: MockLogs, verifyQuery?: (query: EdgeQuery<TSource, TDest, TData>, cursor: string | undefined) => void): {
6
+ verify: (i: number, hasEdge: boolean, hasNextPage: boolean | undefined, cursor?: string) => Promise<void>;
7
+ getCursor: (edge: TData) => string;
8
+ };
9
+ export declare function getWhereClause(query: any): any;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWhereClause = exports.getVerifyAfterEachCursorGeneric = void 0;
4
+ function getVerifyAfterEachCursorGeneric(edges, pageLength, user, getQuery, ml, verifyQuery) {
5
+ let query;
6
+ async function verify(i, hasEdge, hasNextPage, cursor) {
7
+ ml.clear();
8
+ query = getQuery();
9
+ const newEdges = await query.first(pageLength, cursor).queryEdges();
10
+ const pagination = query.paginationInfo().get(user.id);
11
+ if (hasEdge) {
12
+ expect(newEdges[0], `${i}`).toEqual(edges[i]);
13
+ expect(newEdges.length, `${i}`).toBe(edges.length - i >= pageLength ? pageLength : edges.length - i);
14
+ // verify items are the same in order
15
+ expect(newEdges, `${i}`).toEqual(edges.slice(i, i + newEdges.length));
16
+ }
17
+ else {
18
+ expect(newEdges.length, `${i}`).toBe(0);
19
+ }
20
+ if (hasNextPage) {
21
+ expect(pagination?.hasNextPage, `${i}`).toBe(true);
22
+ expect(pagination?.hasPreviousPage, `${i}`).toBe(false);
23
+ }
24
+ else {
25
+ expect(pagination?.hasPreviousPage, `${i}`).toBeFalsy();
26
+ expect(pagination?.hasNextPage, `${i}`).toBeFalsy();
27
+ }
28
+ if (verifyQuery) {
29
+ verifyQuery(query, cursor);
30
+ }
31
+ }
32
+ function getCursor(edge) {
33
+ return query.getCursor(edge);
34
+ }
35
+ return { verify, getCursor };
36
+ }
37
+ exports.getVerifyAfterEachCursorGeneric = getVerifyAfterEachCursorGeneric;
38
+ function getWhereClause(query) {
39
+ const idx = query.query.indexOf("WHERE");
40
+ if (idx !== -1) {
41
+ return query.query.substr(idx + 6);
42
+ }
43
+ return null;
44
+ }
45
+ exports.getWhereClause = getWhereClause;
@@ -41,7 +41,7 @@ async function createRowForTest(options, suffix) {
41
41
  if (isSyncClient(client)) {
42
42
  return (0, ent_1.createRowSync)(client, options, suffix || "");
43
43
  }
44
- return await (0, ent_1.createRow)(client, options, suffix || "");
44
+ return (0, ent_1.createRow)(client, options, suffix || "");
45
45
  }
46
46
  finally {
47
47
  client.release();
@@ -54,7 +54,7 @@ async function editRowForTest(options, suffix) {
54
54
  if (isSyncClient(client)) {
55
55
  return (0, ent_1.editRowSync)(client, options, suffix || "");
56
56
  }
57
- return await (0, ent_1.editRow)(client, options, suffix);
57
+ return (0, ent_1.editRow)(client, options, suffix);
58
58
  }
59
59
  finally {
60
60
  client.release();
@@ -67,7 +67,7 @@ async function deleteRowsForTest(options, cls) {
67
67
  if (isSyncClient(client)) {
68
68
  return (0, ent_1.deleteRowsSync)(client, options, cls);
69
69
  }
70
- return await (0, ent_1.deleteRows)(client, options, cls);
70
+ return (0, ent_1.deleteRows)(client, options, cls);
71
71
  }
72
72
  finally {
73
73
  client.release();