@snowtop/ent 0.1.17 → 0.1.19-test2

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.
@@ -65,6 +65,7 @@ export declare class EditNodeOperation<TEnt extends Ent<TViewer>, TViewer extend
65
65
  performWrite(queryer: Queryer, context?: Context): Promise<void>;
66
66
  private buildReloadQuery;
67
67
  private reloadRow;
68
+ private getReturning;
68
69
  performWriteSync(queryer: SyncQueryer, context?: Context): void;
69
70
  returnedRow(): Data | null;
70
71
  createdEnt(viewer: Viewer): TEnt | null;
@@ -154,7 +154,7 @@ class EditNodeOperation {
154
154
  if (this.hasData(options.fields)) {
155
155
  // even this with returning * may not always work if transformed...
156
156
  // we can have a transformed flag to see if it should be returned?
157
- this.row = await (0, ent_1.editRow)(queryer, options, "RETURNING *");
157
+ this.row = await (0, ent_1.editRow)(queryer, options, this.getReturning());
158
158
  }
159
159
  else {
160
160
  // @ts-ignore
@@ -164,7 +164,7 @@ class EditNodeOperation {
164
164
  else {
165
165
  // TODO: eventually, when we officially support auto-increment ids. need to make sure/test that this works
166
166
  // https://github.com/lolopinto/ent/issues/1431
167
- this.row = await (0, ent_1.createRow)(queryer, options, "RETURNING *");
167
+ this.row = await (0, ent_1.createRow)(queryer, options, this.getReturning());
168
168
  const key = this.options.key;
169
169
  if (this.row && this.row[key] !== this.options.fields[key]) {
170
170
  this.updatedOp = {
@@ -222,6 +222,12 @@ class EditNodeOperation {
222
222
  this.row = r.rows[0];
223
223
  }
224
224
  }
225
+ getReturning() {
226
+ if (this.options.loadEntOptions.fields.length) {
227
+ return `RETURNING ${this.options.loadEntOptions.fields.join(",")}`;
228
+ }
229
+ return `RETURNING *`;
230
+ }
225
231
  performWriteSync(queryer, context) {
226
232
  let options = {
227
233
  ...this.options,
@@ -229,7 +235,7 @@ class EditNodeOperation {
229
235
  };
230
236
  if (this.existingEnt) {
231
237
  if (this.hasData(this.options.fields)) {
232
- (0, ent_1.editRowSync)(queryer, options, "RETURNING *");
238
+ (0, ent_1.editRowSync)(queryer, options, this.getReturning());
233
239
  this.reloadRow(queryer, this.existingEnt.id, options);
234
240
  }
235
241
  else {
@@ -238,7 +244,7 @@ class EditNodeOperation {
238
244
  }
239
245
  }
240
246
  else {
241
- (0, ent_1.createRowSync)(queryer, options, "RETURNING *");
247
+ (0, ent_1.createRowSync)(queryer, options, this.getReturning());
242
248
  const id = options.fields[options.key];
243
249
  this.reloadRow(queryer, id, options);
244
250
  const key = this.options.key;
package/core/clause.d.ts CHANGED
@@ -73,6 +73,12 @@ export declare function ArrayEq<T extends Data, K = keyof T>(col: K, value: any)
73
73
  */
74
74
  export declare function ArrayNotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
75
75
  export declare function Eq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
76
+ export declare function StartsWith<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
77
+ export declare function EndsWith<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
78
+ export declare function Contains<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
79
+ export declare function StartsWithIgnoreCase<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
80
+ export declare function EndsWithIgnoreCase<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
81
+ export declare function ContainsIgnoreCase<T extends Data, K = keyof T>(col: K, value: string): Clause<T, K>;
76
82
  export declare function NotEq<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
77
83
  export declare function Greater<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
78
84
  export declare function Less<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
@@ -125,5 +131,6 @@ export declare function Multiply<T extends Data, K = keyof T>(col: K, value: any
125
131
  export declare function Divide<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
126
132
  export declare function Modulo<T extends Data, K = keyof T>(col: K, value: any): Clause<T, K>;
127
133
  export declare function getCombinedClause<V extends Data = Data, K = keyof V>(options: Pick<SelectDataOptions, "clause">, cls: Clause<V, K>, checkIntersection?: boolean): Clause<V, K>;
134
+ export declare function getCombinedClause<V extends Data = Data, K = keyof V>(options: Pick<SelectDataOptions, "clause">, cls: Clause<V, K> | undefined, checkIntersection?: boolean): Clause<V, K> | undefined;
128
135
  export declare function Expression<T extends Data, K = keyof T>(expression: string): Clause<T, K>;
129
136
  export {};
package/core/clause.js CHANGED
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONKeyInList = exports.JSONBKeyInList = exports.JSONKeyExists = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
27
- exports.Expression = exports.getCombinedClause = void 0;
26
+ exports.JSONKeyInList = exports.JSONBKeyInList = exports.JSONKeyExists = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.ContainsIgnoreCase = exports.EndsWithIgnoreCase = exports.StartsWithIgnoreCase = exports.Contains = exports.EndsWith = exports.StartsWith = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
27
+ exports.Expression = exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = void 0;
28
28
  const db_1 = __importStar(require("./db"));
29
29
  const query_impl_1 = require("./query_impl");
30
30
  function isSensitive(val) {
@@ -566,6 +566,30 @@ function Eq(col, value) {
566
566
  return new simpleClause(col, value, "=", new isNullClause(col));
567
567
  }
568
568
  exports.Eq = Eq;
569
+ function StartsWith(col, value) {
570
+ return new simpleClause(col, `${value}%`, "LIKE");
571
+ }
572
+ exports.StartsWith = StartsWith;
573
+ function EndsWith(col, value) {
574
+ return new simpleClause(col, `%${value}`, "LIKE");
575
+ }
576
+ exports.EndsWith = EndsWith;
577
+ function Contains(col, value) {
578
+ return new simpleClause(col, `%${value}%`, "LIKE");
579
+ }
580
+ exports.Contains = Contains;
581
+ function StartsWithIgnoreCase(col, value) {
582
+ return new simpleClause(col, `${value}%`, "ILIKE");
583
+ }
584
+ exports.StartsWithIgnoreCase = StartsWithIgnoreCase;
585
+ function EndsWithIgnoreCase(col, value) {
586
+ return new simpleClause(col, `%${value}`, "ILIKE");
587
+ }
588
+ exports.EndsWithIgnoreCase = EndsWithIgnoreCase;
589
+ function ContainsIgnoreCase(col, value) {
590
+ return new simpleClause(col, `%${value}%`, "ILIKE");
591
+ }
592
+ exports.ContainsIgnoreCase = ContainsIgnoreCase;
569
593
  function NotEq(col, value) {
570
594
  return new simpleClause(col, value, "!=", new isNotNullClause(col));
571
595
  }
@@ -886,7 +910,7 @@ function getCombinedClause(options, cls, checkIntersection = false) {
886
910
  if (checkIntersection) {
887
911
  // this should be the smaller one
888
912
  const transformedCols = new Set(optionClause.columns());
889
- const queriedCols = cls.columns();
913
+ const queriedCols = cls?.columns() ?? [];
890
914
  const has = new Set();
891
915
  for (const col of queriedCols) {
892
916
  if (transformedCols.has(col)) {
@@ -897,7 +921,7 @@ function getCombinedClause(options, cls, checkIntersection = false) {
897
921
  }
898
922
  if (and) {
899
923
  // @ts-expect-error different types
900
- cls = And(cls, optionClause);
924
+ cls = AndOptional(cls, optionClause);
901
925
  }
902
926
  }
903
927
  }
package/core/ent.d.ts CHANGED
@@ -130,7 +130,7 @@ export declare class AssocEdge {
130
130
  __getRawData(): Data;
131
131
  getCursor(): string;
132
132
  }
133
- interface cursorOptions {
133
+ export interface cursorOptions {
134
134
  row: Data;
135
135
  col: string;
136
136
  cursorKey?: string;
@@ -7,7 +7,7 @@ const loaders_1 = require("../loaders");
7
7
  const query_1 = require("./query");
8
8
  function getClause(opts) {
9
9
  let cls = opts.clause;
10
- if (opts.disableTransformations || !cls) {
10
+ if (opts.disableTransformations) {
11
11
  return cls;
12
12
  }
13
13
  return (0, clause_1.getCombinedClause)(opts.loadEntOptions.loaderFactory?.options, cls, true);
@@ -21,6 +21,7 @@ function getRawCountLoader(viewer, opts) {
21
21
  });
22
22
  }
23
23
  const name = `custom_query_count_loader:${opts.name}`;
24
+ console.debug(opts.name);
24
25
  return viewer.context.cache.getLoader(name, () => new loaders_1.RawCountLoader({
25
26
  tableName: opts.loadEntOptions.tableName,
26
27
  groupCol: opts.groupCol,
@@ -1,6 +1,7 @@
1
- import { Data, Viewer } from "../base";
1
+ import { Data, ID, Viewer } from "../base";
2
2
  import { FakeUser, FakeContact } from "../../testutils/fake_data/index";
3
3
  import { EdgeQuery } from "./query";
4
+ import { BuilderSchema } from "../../testutils/builder";
4
5
  import { MockLogs } from "../../testutils/mock_log";
5
6
  import { Clause } from "../clause";
6
7
  import { OrderBy } from "../query_impl";
@@ -16,6 +17,9 @@ interface options<TData extends Data> {
16
17
  globalSchema?: boolean;
17
18
  orderby: OrderBy;
18
19
  rawDataVerify?(user: FakeUser): Promise<void>;
20
+ loadEnt?(v: Viewer, id: ID): Promise<FakeContact>;
21
+ loadRawData?(id: ID, context: any): Promise<Data | null>;
22
+ contactSchemaForDeletionTest?: BuilderSchema<FakeContact>;
19
23
  }
20
24
  export declare const commonTests: <TData extends Data>(opts: options<TData>) => void;
21
25
  export {};
@@ -26,7 +26,9 @@ const commonTests = (opts) => {
26
26
  // TODO sad not generic enough
27
27
  return (q instanceof index_1.UserToContactsFkeyQuery ||
28
28
  q instanceof index_1.UserToContactsFkeyQueryDeprecated ||
29
- q instanceof index_1.UserToContactsFkeyQueryAsc);
29
+ q instanceof index_1.UserToContactsFkeyQueryAsc ||
30
+ q instanceof index_1.UserToContactsFkeyQueryDeletedAt ||
31
+ q instanceof index_1.UserToContactsFkeyQueryDeletedAtAsc);
30
32
  }
31
33
  class TestQueryFilter {
32
34
  constructor(filter, newQuery, ents, defaultViewer) {
@@ -98,7 +100,7 @@ const commonTests = (opts) => {
98
100
  const ents = await this.testEnts(v);
99
101
  expect(ml.logs.length).toBe(1);
100
102
  expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
101
- await Promise.all(ents.map((ent) => index_1.FakeContact.loadX(v, ent.id)));
103
+ await Promise.all(ents.map((ent) => opts.loadEnt ? opts.loadEnt(v, ent.id) : index_1.FakeContact.loadX(v, ent.id)));
102
104
  expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
103
105
  for (const log of ml.logs.slice(1)) {
104
106
  expect(log["ent-cache-hit"]).toBeDefined();
@@ -115,7 +117,9 @@ const commonTests = (opts) => {
115
117
  const ents = await this.testEnts(v);
116
118
  expect(ml.logs.length).toBe(1);
117
119
  expect(ml.logs[0].query).toMatch(/SELECT (.+) FROM /);
118
- await Promise.all(ents.map((ent) => index_1.FakeContact.loadRawData(ent.id, v.context)));
120
+ await Promise.all(ents.map((ent) => opts.loadRawData
121
+ ? opts.loadRawData(ent.id, v.context)
122
+ : index_1.FakeContact.loadRawData(ent.id, v.context)));
119
123
  expect(ml.logs.length).toBe(this.filteredContacts.length + 1);
120
124
  for (const log of ml.logs.slice(1)) {
121
125
  expect(log["dataloader-cache-hit"]).toBeDefined();
@@ -166,7 +170,9 @@ const commonTests = (opts) => {
166
170
  const uniqCol = isCustomQuery(filter) ? "id" : "id2";
167
171
  let parts = opts.clause.clause(1).split(" AND ");
168
172
  const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(opts.orderby[0].column, opts.orderby[0].direction === "DESC" ? "<" : ">", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
169
- if (parts[parts.length - 1] === "deleted_at IS NULL") {
173
+ // order of parts is different in custom query seemingly
174
+ const customQuery = isCustomQuery(filter);
175
+ if (!customQuery && parts[parts.length - 1] === "deleted_at IS NULL") {
170
176
  parts = parts
171
177
  .slice(0, parts.length - 1)
172
178
  .concat([cmp, "deleted_at IS NULL"]);
@@ -182,7 +188,9 @@ const commonTests = (opts) => {
182
188
  const uniqCol = isCustomQuery(filter) ? "id" : "id2";
183
189
  let parts = opts.clause.clause(1).split(" AND ");
184
190
  const cmp = (0, clause_1.PaginationMultipleColsSubQuery)(orderby[0].column, orderby[0].direction === "ASC" ? ">" : "<", opts.tableName, uniqCol, "").clause(opts.clause.values().length + 1);
185
- if (parts[parts.length - 1] === "deleted_at IS NULL") {
191
+ // order of parts is different in custom query seemingly
192
+ const customQuery = isCustomQuery(filter);
193
+ if (!customQuery && parts[parts.length - 1] === "deleted_at IS NULL") {
186
194
  parts = parts
187
195
  .slice(0, parts.length - 1)
188
196
  .concat([cmp, "deleted_at IS NULL"]);
@@ -398,7 +406,7 @@ const commonTests = (opts) => {
398
406
  const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
399
407
  await Promise.all(filter.allContacts.map(async (contact) => {
400
408
  action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
401
- const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
409
+ const action2 = new builder_1.SimpleAction(filter.user.viewer, opts.contactSchemaForDeletionTest ?? index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
402
410
  await action2.save();
403
411
  }));
404
412
  await action.save();
@@ -4,6 +4,7 @@ exports.commonTests = void 0;
4
4
  const viewer_1 = require("../../core/viewer");
5
5
  const ent_1 = require("../../core/ent");
6
6
  const edge_connection_1 = require("./edge_connection");
7
+ const index_1 = require("../../testutils/fake_data/index");
7
8
  const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
8
9
  class TestConnection {
9
10
  constructor(getQuery, ents, filter) {
@@ -43,11 +44,35 @@ class TestConnection {
43
44
  }
44
45
  }
45
46
  const commonTests = (opts) => {
46
- function getCursorFrom(contacts, idx) {
47
- return (0, ent_1.getCursor)({
48
- row: contacts[idx],
49
- col: "id",
50
- });
47
+ function isCustomQuery(q) {
48
+ // TODO sad not generic enough
49
+ return (q instanceof index_1.UserToContactsFkeyQuery ||
50
+ q instanceof index_1.UserToContactsFkeyQueryDeprecated ||
51
+ q instanceof index_1.UserToContactsFkeyQueryAsc ||
52
+ q instanceof index_1.UserToContactsFkeyQueryDeletedAt ||
53
+ q instanceof index_1.UserToContactsFkeyQueryDeletedAtAsc);
54
+ }
55
+ function getCursorFrom(q, contacts, idx) {
56
+ let opts;
57
+ if (isCustomQuery(q)) {
58
+ opts = {
59
+ row: contacts[idx],
60
+ col: "id",
61
+ // keys: ["id"],
62
+ };
63
+ }
64
+ else {
65
+ // for assoc queries, we're getting the value from 'id' field but the edge
66
+ // is from assoc_edge table id2 field and so cursor takes it from there
67
+ opts = {
68
+ row: contacts[idx],
69
+ col: "id",
70
+ cursorKey: "id2",
71
+ // keys: ["id2"],
72
+ // cursorKeys: ["id"],
73
+ };
74
+ }
75
+ return (0, ent_1.getCursor)(opts);
51
76
  }
52
77
  describe("no filters", () => {
53
78
  const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts);
@@ -103,7 +128,7 @@ const commonTests = (opts) => {
103
128
  const filter = new TestConnection((v, user) => opts.getQuery(v, user),
104
129
  // get the next 2
105
130
  (contacts) => contacts.slice(idx + 1, idx + N), (conn, user, contacts) => {
106
- const cursor = getCursorFrom(contacts, idx);
131
+ const cursor = getCursorFrom(conn.query, contacts, idx);
107
132
  conn.first(2, cursor);
108
133
  });
109
134
  beforeEach(async () => {
@@ -133,7 +158,7 @@ const commonTests = (opts) => {
133
158
  describe("filters. before cursor", () => {
134
159
  const filter = new TestConnection((v, user) => opts.getQuery(v, user), (contacts) => contacts.slice(2, 4).reverse(), (conn, user, contacts) => {
135
160
  // get the 2 before it
136
- const cursor = getCursorFrom(contacts, 4);
161
+ const cursor = getCursorFrom(conn.query, contacts, 4);
137
162
  conn.last(2, cursor);
138
163
  });
139
164
  beforeEach(async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.17",
3
+ "version": "0.1.19-test2",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -57,6 +57,7 @@ export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldM
57
57
  export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
58
58
  export declare function getSchemaName(value: BuilderSchema<Ent>): string;
59
59
  export declare function getTableName(value: BuilderSchema<Ent>): string;
60
+ export declare const getDbFields: (schema: BuilderSchema<Ent>) => string[];
60
61
  export declare function getFieldInfo(value: BuilderSchema<Ent>): FieldInfoMap;
61
62
  type MaybeNull<T extends Ent> = T | null;
62
63
  type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.EntBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = exports.BaseEnt = void 0;
6
+ exports.SimpleAction = exports.SimpleBuilder = exports.getFieldInfo = exports.getDbFields = exports.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.EntBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = exports.BaseEnt = void 0;
7
7
  const privacy_1 = require("../core/privacy");
8
8
  const orchestrator_1 = require("../action/orchestrator");
9
9
  const action_1 = require("../action");
@@ -128,6 +128,15 @@ function getTableName(value) {
128
128
  return (0, pluralize_1.default)((0, snake_case_1.snakeCase)(value.ent.name)).toLowerCase();
129
129
  }
130
130
  exports.getTableName = getTableName;
131
+ const getDbFields = (schema) => {
132
+ const fields = (0, schema_1.getFields)(schema);
133
+ const dbFields = [];
134
+ for (const [fieldName, field] of fields) {
135
+ dbFields.push((0, schema_2.getStorageKey)(field, fieldName));
136
+ }
137
+ return dbFields;
138
+ };
139
+ exports.getDbFields = getDbFields;
131
140
  function randomNum() {
132
141
  return Math.random().toString(10).substring(2);
133
142
  }
@@ -166,6 +175,10 @@ class SimpleBuilder {
166
175
  this.fields = fields;
167
176
  const schemaFields = (0, schema_1.getFields)(schema);
168
177
  let key = "id";
178
+ const dbFields = [];
179
+ for (const [name, f] of schemaFields) {
180
+ dbFields.push((0, schema_2.getStorageKey)(f, name));
181
+ }
169
182
  if (!schemaFields.has("id") && !schemaFields.has("ID")) {
170
183
  if (schemaFields.size !== 1) {
171
184
  throw new Error(`no id field and multiple fields so can't deduce key. add an id field to schema`);
@@ -187,12 +200,12 @@ class SimpleBuilder {
187
200
  loaderOptions: {
188
201
  loaderFactory: new loaders_1.ObjectLoaderFactory({
189
202
  tableName: tableName,
190
- fields: [],
203
+ fields: dbFields,
191
204
  key,
192
205
  }),
193
206
  ent: schema.ent,
194
207
  tableName: tableName,
195
- fields: [],
208
+ fields: dbFields,
196
209
  fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
197
210
  },
198
211
  builder: this,
@@ -13,17 +13,25 @@ export declare class FakeContact implements Ent {
13
13
  readonly lastName: string;
14
14
  readonly emailAddress: string;
15
15
  readonly userID: ID;
16
+ readonly deletedAt: Date | null;
16
17
  getPrivacyPolicy(): PrivacyPolicy<this>;
17
18
  constructor(viewer: Viewer, data: Data);
18
19
  __setRawDBData(data: Data): void;
19
20
  static getFields(): string[];
21
+ static getFieldsWithDeletedAt(): string[];
20
22
  static getTestTable(): import("../db/temp_db").Table;
23
+ static getTestTableWithDeletedAt(): import("../db/temp_db").Table;
21
24
  static loaderOptions(): LoadEntOptions<FakeContact>;
25
+ static loaderOptionsWithDeletedAt(): LoadEntOptions<FakeContact>;
22
26
  static load(v: Viewer, id: ID): Promise<FakeContact | null>;
23
27
  static loadX(v: Viewer, id: ID): Promise<FakeContact>;
28
+ static loadWithDeletedAt(v: Viewer, id: ID): Promise<FakeContact | null>;
29
+ static loadXWithDeletedAt(v: Viewer, id: ID): Promise<FakeContact>;
24
30
  static loadRawData(id: ID, context?: Context): Promise<Data | null>;
31
+ static loadRawDataWithDeletedAt(id: ID, context?: Context): Promise<Data | null>;
25
32
  }
26
33
  export declare const FakeContactSchema: import("../builder").BuilderSchema<FakeContact>;
34
+ export declare const FakeContactSchemaWithDeletedAt: import("../builder").BuilderSchema<FakeContact>;
27
35
  export interface ContactCreateInput {
28
36
  firstName: string;
29
37
  lastName: string;
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contactLoader = exports.createContact = exports.getContactBuilder = exports.FakeContactSchema = exports.FakeContact = void 0;
26
+ exports.contactLoader = exports.createContact = exports.getContactBuilder = exports.FakeContactSchemaWithDeletedAt = exports.FakeContactSchema = exports.FakeContact = void 0;
4
27
  const ent_1 = require("../../core/ent");
28
+ const clause = __importStar(require("../../core/clause"));
5
29
  const privacy_1 = require("../../core/privacy");
6
30
  const builder_1 = require("../builder");
7
31
  const schema_1 = require("../../schema");
@@ -10,6 +34,7 @@ const temp_db_1 = require("../db/temp_db");
10
34
  const loaders_1 = require("../../core/loaders");
11
35
  const convert_1 = require("../../core/convert");
12
36
  const action_1 = require("../../action");
37
+ const soft_delete_1 = require("../soft_delete");
13
38
  class FakeContact {
14
39
  getPrivacyPolicy() {
15
40
  return {
@@ -27,6 +52,7 @@ class FakeContact {
27
52
  this.lastName = data.last_name;
28
53
  this.emailAddress = data.email_address;
29
54
  this.userID = data.user_id;
55
+ this.deletedAt = data.deleted_at ? (0, convert_1.convertDate)(data.deleted_at) : null;
30
56
  }
31
57
  __setRawDBData(data) { }
32
58
  static getFields() {
@@ -40,9 +66,15 @@ class FakeContact {
40
66
  "user_id",
41
67
  ];
42
68
  }
69
+ static getFieldsWithDeletedAt() {
70
+ return [...FakeContact.getFields(), "deleted_at"];
71
+ }
43
72
  static getTestTable() {
44
73
  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"));
45
74
  }
75
+ static getTestTableWithDeletedAt() {
76
+ 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"), (0, temp_db_1.timestamptz)("deleted_at", { nullable: true }));
77
+ }
46
78
  static loaderOptions() {
47
79
  return {
48
80
  tableName: "fake_contacts",
@@ -55,17 +87,42 @@ class FakeContact {
55
87
  }),
56
88
  };
57
89
  }
90
+ static loaderOptionsWithDeletedAt() {
91
+ return {
92
+ tableName: "fake_contacts",
93
+ fields: FakeContact.getFieldsWithDeletedAt(),
94
+ ent: this,
95
+ loaderFactory: new loaders_1.ObjectLoaderFactory({
96
+ tableName: "fake_contacts",
97
+ key: "id",
98
+ fields: FakeContact.getFieldsWithDeletedAt(),
99
+ clause: clause.Eq("deleted_at", null),
100
+ instanceKey: "fake_contacts:transformedReadClause",
101
+ }),
102
+ };
103
+ }
58
104
  static async load(v, id) {
59
105
  return (0, ent_1.loadEnt)(v, id, FakeContact.loaderOptions());
60
106
  }
61
107
  static async loadX(v, id) {
62
108
  return (0, ent_1.loadEntX)(v, id, FakeContact.loaderOptions());
63
109
  }
110
+ static async loadWithDeletedAt(v, id) {
111
+ return (0, ent_1.loadEnt)(v, id, FakeContact.loaderOptionsWithDeletedAt());
112
+ }
113
+ static async loadXWithDeletedAt(v, id) {
114
+ return (0, ent_1.loadEntX)(v, id, FakeContact.loaderOptionsWithDeletedAt());
115
+ }
64
116
  static async loadRawData(id, context) {
65
117
  return FakeContact.loaderOptions()
66
118
  .loaderFactory.createLoader(context)
67
119
  .load(id);
68
120
  }
121
+ static async loadRawDataWithDeletedAt(id, context) {
122
+ return FakeContact.loaderOptionsWithDeletedAt()
123
+ .loaderFactory.createLoader(context)
124
+ .load(id);
125
+ }
69
126
  }
70
127
  exports.FakeContact = FakeContact;
71
128
  exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
@@ -76,6 +133,16 @@ exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
76
133
  foreignKey: { schema: "User", column: "ID" },
77
134
  }),
78
135
  }, FakeContact);
136
+ exports.FakeContactSchemaWithDeletedAt = (0, builder_1.getBuilderSchemaFromFields)({
137
+ firstName: (0, schema_1.StringType)(),
138
+ lastName: (0, schema_1.StringType)(),
139
+ emailAddress: (0, schema_1.StringType)(),
140
+ userID: (0, schema_1.UUIDType)({
141
+ foreignKey: { schema: "User", column: "ID" },
142
+ }),
143
+ }, FakeContact, {
144
+ patterns: [new soft_delete_1.DeletedAtPattern()],
145
+ });
79
146
  function getContactBuilder(viewer, input) {
80
147
  const m = new Map();
81
148
  for (const key in input) {
@@ -14,14 +14,20 @@ export declare class FakeEvent implements Ent {
14
14
  readonly title: string;
15
15
  readonly description: string | null;
16
16
  readonly userID: ID;
17
+ readonly deletedAt: Date | null;
17
18
  getPrivacyPolicy(): PrivacyPolicy<this>;
18
19
  constructor(viewer: Viewer, data: Data);
19
20
  __setRawDBData(data: Data): void;
20
21
  private static getFields;
22
+ private static getFieldsWithDeletedAt;
21
23
  static getTestTable(): import("../db/temp_db").Table;
24
+ static getTestTableWithDeletedAt(): import("../db/temp_db").Table;
22
25
  static loaderOptions(): LoadEntOptions<FakeEvent>;
26
+ static loaderOptionsWithDeletedAt(): LoadEntOptions<FakeEvent>;
23
27
  static load(v: Viewer, id: ID): Promise<FakeEvent | null>;
24
28
  static loadX(v: Viewer, id: ID): Promise<FakeEvent>;
29
+ static loadWithDeletedAt(v: Viewer, id: ID): Promise<FakeEvent | null>;
30
+ static loadWithDeletedAtX(v: Viewer, id: ID): Promise<FakeEvent>;
25
31
  }
26
32
  export declare const FakeEventSchema: import("../builder").BuilderSchema<FakeEvent>;
27
33
  export interface EventCreateInput {
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.createEvent = exports.getEventBuilder = exports.FakeEventSchema = exports.FakeEvent = void 0;
4
27
  const ent_1 = require("../../core/ent");
28
+ const clause = __importStar(require("../../core/clause"));
5
29
  const privacy_1 = require("../../core/privacy");
6
30
  const builder_1 = require("../builder");
7
31
  const schema_1 = require("../../schema");
@@ -42,11 +66,19 @@ class FakeEvent {
42
66
  "user_id",
43
67
  ];
44
68
  }
69
+ static getFieldsWithDeletedAt() {
70
+ return [...FakeEvent.getFields(), "deleted_at"];
71
+ }
45
72
  static getTestTable() {
46
73
  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"),
47
74
  // TODO index:true
48
75
  (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"));
49
76
  }
77
+ static getTestTableWithDeletedAt() {
78
+ 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"),
79
+ // TODO index:true
80
+ (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"), (0, temp_db_1.timestamptz)("deleted_at", { nullable: true }));
81
+ }
50
82
  static loaderOptions() {
51
83
  return {
52
84
  tableName: "fake_events",
@@ -59,12 +91,32 @@ class FakeEvent {
59
91
  }),
60
92
  };
61
93
  }
94
+ static loaderOptionsWithDeletedAt() {
95
+ return {
96
+ tableName: "fake_events",
97
+ fields: FakeEvent.getFields(),
98
+ ent: this,
99
+ loaderFactory: new loaders_1.ObjectLoaderFactory({
100
+ tableName: "fake_events",
101
+ key: "id",
102
+ fields: FakeEvent.getFieldsWithDeletedAt(),
103
+ clause: clause.Eq("deleted_at", null),
104
+ instanceKey: "fake_events:transformedReadClause",
105
+ }),
106
+ };
107
+ }
62
108
  static async load(v, id) {
63
109
  return (0, ent_1.loadEnt)(v, id, FakeEvent.loaderOptions());
64
110
  }
65
111
  static async loadX(v, id) {
66
112
  return (0, ent_1.loadEntX)(v, id, FakeEvent.loaderOptions());
67
113
  }
114
+ static async loadWithDeletedAt(v, id) {
115
+ return (0, ent_1.loadEnt)(v, id, FakeEvent.loaderOptionsWithDeletedAt());
116
+ }
117
+ static async loadWithDeletedAtX(v, id) {
118
+ return (0, ent_1.loadEntX)(v, id, FakeEvent.loaderOptionsWithDeletedAt());
119
+ }
68
120
  }
69
121
  exports.FakeEvent = FakeEvent;
70
122
  exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
@@ -12,12 +12,16 @@ export declare class FakeTag implements Ent {
12
12
  readonly displayName: string;
13
13
  readonly canonicalName: string;
14
14
  readonly ownerID: string;
15
+ readonly deletedAt: Date | null;
15
16
  getPrivacyPolicy(): PrivacyPolicy<this>;
16
17
  constructor(viewer: Viewer, data: Data);
17
18
  __setRawDBData(data: Data): void;
18
19
  static getFields(): string[];
20
+ static getFieldsWithDeletedAt(): string[];
19
21
  static getTestTable(): import("../db/temp_db").Table;
22
+ static getTestTableWithDeletedAt(): import("../db/temp_db").Table;
20
23
  static loaderOptions(): LoadEntOptions<FakeTag>;
24
+ static loaderOptionsWithDeletedAt(): LoadEntOptions<FakeTag>;
21
25
  static load(v: Viewer, id: ID): Promise<FakeTag | null>;
22
26
  static loadX(v: Viewer, id: ID): Promise<FakeTag>;
23
27
  }
@@ -34,3 +38,4 @@ export declare function getTagBuilder(viewer: Viewer, input: TagCreateInput): im
34
38
  export declare function getTagAction(viewer: Viewer, input: TagCreateInput): SimpleAction<FakeTag, null>;
35
39
  export declare function createTag(viewer: Viewer, input: TagCreateInput): Promise<FakeTag>;
36
40
  export declare const tagLoader: ObjectLoaderFactory<Data>;
41
+ export declare const tagLoaderWithDeletedAt: ObjectLoaderFactory<Data>;
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tagLoader = exports.createTag = exports.getTagAction = exports.getTagBuilder = exports.FakeTagSchema = exports.FakeTag = void 0;
26
+ exports.tagLoaderWithDeletedAt = exports.tagLoader = exports.createTag = exports.getTagAction = exports.getTagBuilder = exports.FakeTagSchema = exports.FakeTag = void 0;
4
27
  const ent_1 = require("../../core/ent");
28
+ const clause = __importStar(require("../../core/clause"));
5
29
  const privacy_1 = require("../../core/privacy");
6
30
  const builder_1 = require("../builder");
7
31
  const schema_1 = require("../../schema");
@@ -26,6 +50,7 @@ class FakeTag {
26
50
  this.displayName = data.display_name;
27
51
  this.canonicalName = data.canonical_name;
28
52
  this.ownerID = data.owner_id;
53
+ this.deletedAt = data.deleted_at ? (0, convert_1.convertDate)(data.deleted_at) : null;
29
54
  }
30
55
  __setRawDBData(data) { }
31
56
  static getFields() {
@@ -38,10 +63,19 @@ class FakeTag {
38
63
  "owner_id",
39
64
  ];
40
65
  }
66
+ static getFieldsWithDeletedAt() {
67
+ return [...FakeTag.getFields(), "deleted_at"];
68
+ }
41
69
  static getTestTable() {
42
70
  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
71
  (0, temp_db_1.index)("fake_tags", ["canonical_name", "owner_id"], { unique: true }));
44
72
  }
73
+ static getTestTableWithDeletedAt() {
74
+ 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?
75
+ (0, temp_db_1.index)("fake_tags", ["canonical_name", "owner_id"], { unique: true }), (0, temp_db_1.timestamptz)("deleted_at", {
76
+ nullable: true,
77
+ }));
78
+ }
45
79
  static loaderOptions() {
46
80
  return {
47
81
  tableName: "fake_tags",
@@ -50,6 +84,14 @@ class FakeTag {
50
84
  loaderFactory: exports.tagLoader,
51
85
  };
52
86
  }
87
+ static loaderOptionsWithDeletedAt() {
88
+ return {
89
+ tableName: "fake_tags",
90
+ fields: FakeTag.getFields(),
91
+ ent: this,
92
+ loaderFactory: exports.tagLoader,
93
+ };
94
+ }
53
95
  static async load(v, id) {
54
96
  return (0, ent_1.loadEnt)(v, id, FakeTag.loaderOptions());
55
97
  }
@@ -87,3 +129,10 @@ exports.tagLoader = new loaders_1.ObjectLoaderFactory({
87
129
  fields: FakeTag.getFields(),
88
130
  key: "id",
89
131
  });
132
+ exports.tagLoaderWithDeletedAt = new loaders_1.ObjectLoaderFactory({
133
+ tableName: "fake_tags",
134
+ fields: FakeTag.getFieldsWithDeletedAt(),
135
+ key: "id",
136
+ clause: clause.Eq("deleted_at", null),
137
+ instanceKey: "fake_tags:transformedReadClause",
138
+ });
@@ -23,14 +23,20 @@ export declare class FakeUser implements Ent {
23
23
  readonly emailAddress: string;
24
24
  readonly phoneNumber: string | null;
25
25
  protected readonly password: string | null;
26
+ readonly deletedAt: Date | null;
26
27
  getPrivacyPolicy(): PrivacyPolicy<this>;
27
28
  constructor(viewer: Viewer, data: Data);
28
29
  __setRawDBData(data: Data): void;
29
30
  static getFields(): string[];
31
+ static getFieldsWithDeletedAt(): string[];
30
32
  static getTestTable(): import("../db/temp_db").Table;
33
+ static getTestTableWithDeletedAt(): import("../db/temp_db").Table;
31
34
  static loaderOptions(): LoadEntOptions<FakeUser>;
35
+ static loaderOptionsWithDeletedAt(): LoadEntOptions<FakeUser>;
32
36
  static load(v: Viewer, id: ID): Promise<FakeUser | null>;
33
37
  static loadX(v: Viewer, id: ID): Promise<FakeUser>;
38
+ static loadWithDeletedAt(v: Viewer, id: ID): Promise<FakeUser | null>;
39
+ static loadWithDeletedAtX(v: Viewer, id: ID): Promise<FakeUser>;
34
40
  }
35
41
  export declare const FakeUserSchema: import("../builder").BuilderSchema<FakeUser>;
36
42
  export interface UserCreateInput {
@@ -47,6 +53,7 @@ export declare function getUserBuilder(viewer: Viewer, input: UserCreateInput):
47
53
  export declare function getUserAction(viewer: Viewer, input: UserCreateInput): SimpleAction<FakeUser, null>;
48
54
  export declare function createUser(viewer: Viewer, input: UserCreateInput): Promise<FakeUser>;
49
55
  export declare const userLoader: ObjectLoaderFactory<Data>;
56
+ export declare const userLoaderWithDeletedAt: ObjectLoaderFactory<Data>;
50
57
  export declare const userEmailLoader: ObjectLoaderFactory<Data>;
51
58
  export declare const userPhoneNumberLoader: ObjectLoaderFactory<Data>;
52
59
  export {};
@@ -1,8 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.userPhoneNumberLoader = exports.userEmailLoader = exports.userLoader = exports.createUser = exports.getUserAction = exports.getUserBuilder = exports.FakeUserSchema = exports.FakeUser = exports.ViewerWithAccessToken = void 0;
26
+ exports.userPhoneNumberLoader = exports.userEmailLoader = exports.userLoaderWithDeletedAt = exports.userLoader = exports.createUser = exports.getUserAction = exports.getUserBuilder = exports.FakeUserSchema = exports.FakeUser = exports.ViewerWithAccessToken = void 0;
4
27
  const base_1 = require("../../core/base");
5
28
  const ent_1 = require("../../core/ent");
29
+ const clause = __importStar(require("../../core/clause"));
6
30
  const privacy_1 = require("../../core/privacy");
7
31
  const builder_1 = require("../builder");
8
32
  const schema_1 = require("../../schema");
@@ -69,6 +93,7 @@ class FakeUser {
69
93
  this.emailAddress = data.email_address;
70
94
  this.phoneNumber = data.phone_number;
71
95
  this.password = data.password;
96
+ this.deletedAt = data.deleted_at ? (0, convert_1.convertDate)(data.deleted_at) : null;
72
97
  }
73
98
  __setRawDBData(data) { }
74
99
  static getFields() {
@@ -83,9 +108,27 @@ class FakeUser {
83
108
  "password",
84
109
  ];
85
110
  }
111
+ static getFieldsWithDeletedAt() {
112
+ return [
113
+ "id",
114
+ "created_at",
115
+ "updated_at",
116
+ "first_name",
117
+ "last_name",
118
+ "email_address",
119
+ "phone_number",
120
+ "password",
121
+ "deleted_at",
122
+ ];
123
+ }
86
124
  static getTestTable() {
87
125
  return (0, temp_db_1.table)("fake_users", (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.text)("phone_number"), (0, temp_db_1.text)("password"));
88
126
  }
127
+ static getTestTableWithDeletedAt() {
128
+ return (0, temp_db_1.table)("fake_users", (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.text)("phone_number"), (0, temp_db_1.text)("password"), (0, temp_db_1.timestamptz)("deleted_at", {
129
+ nullable: true,
130
+ }));
131
+ }
89
132
  static loaderOptions() {
90
133
  return {
91
134
  tableName: "fake_users",
@@ -94,12 +137,26 @@ class FakeUser {
94
137
  loaderFactory: exports.userLoader,
95
138
  };
96
139
  }
140
+ static loaderOptionsWithDeletedAt() {
141
+ return {
142
+ tableName: "fake_users",
143
+ fields: FakeUser.getFields(),
144
+ ent: this,
145
+ loaderFactory: exports.userLoaderWithDeletedAt,
146
+ };
147
+ }
97
148
  static async load(v, id) {
98
149
  return (0, ent_1.loadEnt)(v, id, FakeUser.loaderOptions());
99
150
  }
100
151
  static async loadX(v, id) {
101
152
  return (0, ent_1.loadEntX)(v, id, FakeUser.loaderOptions());
102
153
  }
154
+ static async loadWithDeletedAt(v, id) {
155
+ return (0, ent_1.loadEnt)(v, id, FakeUser.loaderOptionsWithDeletedAt());
156
+ }
157
+ static async loadWithDeletedAtX(v, id) {
158
+ return (0, ent_1.loadEntX)(v, id, FakeUser.loaderOptionsWithDeletedAt());
159
+ }
103
160
  }
104
161
  exports.FakeUser = FakeUser;
105
162
  exports.FakeUserSchema = (0, builder_1.getBuilderSchemaFromFields)({
@@ -141,6 +198,13 @@ exports.userLoader = new loaders_1.ObjectLoaderFactory({
141
198
  fields: FakeUser.getFields(),
142
199
  key: "id",
143
200
  });
201
+ exports.userLoaderWithDeletedAt = new loaders_1.ObjectLoaderFactory({
202
+ tableName: "fake_users",
203
+ fields: FakeUser.getFieldsWithDeletedAt(),
204
+ key: "id",
205
+ clause: clause.Eq("deleted_at", null),
206
+ instanceKey: "fake_users:transformedReadClause",
207
+ });
144
208
  exports.userEmailLoader = new loaders_1.ObjectLoaderFactory({
145
209
  tableName: "fake_users",
146
210
  fields: FakeUser.getFields(),
@@ -234,10 +234,10 @@ async function setupTempDB(global = false) {
234
234
  exports.setupTempDB = setupTempDB;
235
235
  function tempDBTables(global = false) {
236
236
  const tables = [
237
- _1.FakeUser.getTestTable(),
238
- _1.FakeContact.getTestTable(),
239
- fake_event_1.FakeEvent.getTestTable(),
240
- fake_tag_1.FakeTag.getTestTable(),
237
+ _1.FakeUser.getTestTableWithDeletedAt(),
238
+ _1.FakeContact.getTestTableWithDeletedAt(),
239
+ fake_event_1.FakeEvent.getTestTableWithDeletedAt(),
240
+ fake_tag_1.FakeTag.getTestTableWithDeletedAt(),
241
241
  (0, temp_db_1.assoc_edge_config_table)(),
242
242
  ];
243
243
  edgeTableNames().forEach((tableName) => tables.push((0, temp_db_1.assoc_edge_table)(tableName, global)));
@@ -23,11 +23,21 @@ export declare class UserToContactsFkeyQuery extends CustomEdgeQueryBase<FakeUse
23
23
  static query(viewer: Viewer, src: FakeUser | ID): UserToContactsFkeyQuery;
24
24
  sourceEnt(id: ID): Promise<FakeUser | null>;
25
25
  }
26
+ export declare class UserToContactsFkeyQueryDeletedAt extends CustomEdgeQueryBase<FakeUser, FakeContact> {
27
+ constructor(viewer: Viewer, src: ID | FakeUser);
28
+ static query(viewer: Viewer, src: FakeUser | ID): UserToContactsFkeyQuery;
29
+ sourceEnt(id: ID): Promise<FakeUser | null>;
30
+ }
26
31
  export declare class UserToContactsFkeyQueryAsc extends CustomEdgeQueryBase<FakeUser, FakeContact> {
27
32
  constructor(viewer: Viewer, src: ID | FakeUser);
28
33
  static query(viewer: Viewer, src: FakeUser | ID): UserToContactsFkeyQuery;
29
34
  sourceEnt(id: ID): Promise<FakeUser | null>;
30
35
  }
36
+ export declare class UserToContactsFkeyQueryDeletedAtAsc extends CustomEdgeQueryBase<FakeUser, FakeContact> {
37
+ constructor(viewer: Viewer, src: ID | FakeUser);
38
+ static query(viewer: Viewer, src: FakeUser | ID): UserToContactsFkeyQuery;
39
+ sourceEnt(id: ID): Promise<FakeUser | null>;
40
+ }
31
41
  export declare class UserToFriendsQuery extends AssocEdgeQueryBase<FakeUser, FakeUser, AssocEdge> {
32
42
  constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser>);
33
43
  static query(viewer: Viewer, src: EdgeQuerySource<FakeUser>): UserToFriendsQuery;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.UserToFollowingQuery = exports.UserToEventsInNextWeekQuery = exports.getCompleteClause = exports.getNextWeekClause = exports.UserToHostedEventsQuery = exports.UserToEventsAttendingQuery = exports.UserToIncomingFriendRequestsQuery = exports.UserToFriendRequestsQuery = exports.UserToCustomEdgeQuery = exports.CustomEdge = exports.UserToFriendsQuery = exports.UserToContactsFkeyQueryAsc = exports.UserToContactsFkeyQuery = exports.UserToContactsFkeyQueryDeprecated = exports.userToContactsDataLoaderFactory = exports.userToContactsCountLoaderFactory = exports.UserToContactsQuery = void 0;
26
+ exports.UserToFollowingQuery = exports.UserToEventsInNextWeekQuery = exports.getCompleteClause = exports.getNextWeekClause = exports.UserToHostedEventsQuery = exports.UserToEventsAttendingQuery = exports.UserToIncomingFriendRequestsQuery = exports.UserToFriendRequestsQuery = exports.UserToCustomEdgeQuery = exports.CustomEdge = exports.UserToFriendsQuery = exports.UserToContactsFkeyQueryDeletedAtAsc = exports.UserToContactsFkeyQueryAsc = exports.UserToContactsFkeyQueryDeletedAt = exports.UserToContactsFkeyQuery = exports.UserToContactsFkeyQueryDeprecated = exports.userToContactsDataLoaderFactory = exports.userToContactsCountLoaderFactory = exports.UserToContactsQuery = void 0;
27
27
  const custom_query_1 = require("../../core/query/custom_query");
28
28
  const ent_1 = require("../../core/ent");
29
29
  const clause = __importStar(require("../../core/clause"));
@@ -100,13 +100,32 @@ class UserToContactsFkeyQuery extends custom_query_1.CustomEdgeQueryBase {
100
100
  }
101
101
  }
102
102
  exports.UserToContactsFkeyQuery = UserToContactsFkeyQuery;
103
+ class UserToContactsFkeyQueryDeletedAt extends custom_query_1.CustomEdgeQueryBase {
104
+ constructor(viewer, src) {
105
+ super(viewer, {
106
+ src,
107
+ loadEntOptions: internal_1.FakeContact.loaderOptionsWithDeletedAt(),
108
+ groupCol: "user_id",
109
+ name: "user_to_contacts_deleted_at",
110
+ // instead of the id col...
111
+ sortColumn: "created_at",
112
+ });
113
+ }
114
+ static query(viewer, src) {
115
+ return new UserToContactsFkeyQueryDeletedAt(viewer, src);
116
+ }
117
+ sourceEnt(id) {
118
+ return internal_1.FakeUser.load(this.viewer, id);
119
+ }
120
+ }
121
+ exports.UserToContactsFkeyQueryDeletedAt = UserToContactsFkeyQueryDeletedAt;
103
122
  class UserToContactsFkeyQueryAsc extends custom_query_1.CustomEdgeQueryBase {
104
123
  constructor(viewer, src) {
105
124
  super(viewer, {
106
125
  src,
107
126
  loadEntOptions: internal_1.FakeContact.loaderOptions(),
108
127
  groupCol: "user_id",
109
- name: "user_to_contacts",
128
+ name: "user_to_contacts_asc",
110
129
  orderby: [
111
130
  {
112
131
  column: "created_at",
@@ -123,6 +142,29 @@ class UserToContactsFkeyQueryAsc extends custom_query_1.CustomEdgeQueryBase {
123
142
  }
124
143
  }
125
144
  exports.UserToContactsFkeyQueryAsc = UserToContactsFkeyQueryAsc;
145
+ class UserToContactsFkeyQueryDeletedAtAsc extends custom_query_1.CustomEdgeQueryBase {
146
+ constructor(viewer, src) {
147
+ super(viewer, {
148
+ src,
149
+ loadEntOptions: internal_1.FakeContact.loaderOptionsWithDeletedAt(),
150
+ groupCol: "user_id",
151
+ name: "user_to_contacts_deleted_at_asc",
152
+ orderby: [
153
+ {
154
+ column: "created_at",
155
+ direction: "ASC",
156
+ },
157
+ ],
158
+ });
159
+ }
160
+ static query(viewer, src) {
161
+ return new UserToContactsFkeyQueryDeletedAtAsc(viewer, src);
162
+ }
163
+ sourceEnt(id) {
164
+ return internal_1.FakeUser.load(this.viewer, id);
165
+ }
166
+ }
167
+ exports.UserToContactsFkeyQueryDeletedAtAsc = UserToContactsFkeyQueryDeletedAtAsc;
126
168
  class UserToFriendsQuery extends assoc_query_1.AssocEdgeQueryBase {
127
169
  constructor(viewer, src) {
128
170
  super(viewer, src, new assoc_count_loader_1.AssocEdgeCountLoaderFactory(internal_1.EdgeType.UserToFriends), new assoc_edge_loader_1.AssocEdgeLoaderFactory(internal_1.EdgeType.UserToFriends, ent_1.AssocEdge), internal_1.FakeUser.loaderOptions());
@@ -0,0 +1,26 @@
1
+ import { Ent, Viewer } from "../core/base";
2
+ import { Pattern, UpdateOperation, TransformedUpdateOperation } from "../schema";
3
+ import * as clause from "../core/clause";
4
+ import { FieldMap } from "../schema";
5
+ interface CustomViewer extends Viewer {
6
+ marker: string;
7
+ }
8
+ export declare class DeletedAtPattern implements Pattern {
9
+ name: string;
10
+ fields: FieldMap;
11
+ transformRead(): clause.Clause;
12
+ transformWrite<T extends Ent>(stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
13
+ }
14
+ export declare class DeletedAtSnakeCasePattern implements Pattern {
15
+ name: string;
16
+ fields: FieldMap;
17
+ transformRead(): clause.Clause;
18
+ transformWrite<T extends Ent>(stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
19
+ }
20
+ export declare class DeletedAtPatternWithExtraWrites implements Pattern {
21
+ name: string;
22
+ fields: FieldMap;
23
+ transformRead(): clause.Clause;
24
+ transformWrite<T extends Ent<TViewer>, TViewer extends Viewer = CustomViewer>(stmt: UpdateOperation<T, TViewer>): TransformedUpdateOperation<T, TViewer> | null;
25
+ }
26
+ export {};
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.DeletedAtPatternWithExtraWrites = exports.DeletedAtSnakeCasePattern = exports.DeletedAtPattern = void 0;
27
+ const orchestrator_1 = require("../action/orchestrator");
28
+ const field_1 = require("../schema/field");
29
+ const schema_1 = require("../schema");
30
+ const clause = __importStar(require("../core/clause"));
31
+ const db_1 = __importStar(require("../core/db"));
32
+ class DeletedAtPattern {
33
+ constructor() {
34
+ this.name = "deleted_at";
35
+ this.fields = {
36
+ // need this to be lowerCamelCase because we do this based on field name
37
+ // #510
38
+ deletedAt: (0, field_1.TimestampType)({
39
+ nullable: true,
40
+ index: true,
41
+ defaultValueOnCreate: () => null,
42
+ }),
43
+ };
44
+ }
45
+ transformRead() {
46
+ // this is based on sql. other is based on field
47
+ return clause.Eq("deleted_at", null);
48
+ }
49
+ transformWrite(stmt) {
50
+ switch (stmt.op) {
51
+ case schema_1.SQLStatementOperation.Delete:
52
+ return {
53
+ op: schema_1.SQLStatementOperation.Update,
54
+ data: {
55
+ // this should return field, it'll be formatted as needed
56
+ deletedAt: new Date(),
57
+ },
58
+ };
59
+ }
60
+ return null;
61
+ }
62
+ }
63
+ exports.DeletedAtPattern = DeletedAtPattern;
64
+ class DeletedAtSnakeCasePattern {
65
+ constructor() {
66
+ this.name = "deleted_at";
67
+ this.fields = {
68
+ deleted_at: (0, field_1.TimestampType)({
69
+ nullable: true,
70
+ index: true,
71
+ defaultValueOnCreate: () => null,
72
+ }),
73
+ };
74
+ }
75
+ transformRead() {
76
+ // this is based on sql. other is based on field
77
+ return clause.Eq("deleted_at", null);
78
+ }
79
+ transformWrite(stmt) {
80
+ switch (stmt.op) {
81
+ case schema_1.SQLStatementOperation.Delete:
82
+ return {
83
+ op: schema_1.SQLStatementOperation.Update,
84
+ data: {
85
+ // this should return field, it'll be formatted as needed
86
+ deleted_at: new Date(),
87
+ },
88
+ };
89
+ }
90
+ return null;
91
+ }
92
+ }
93
+ exports.DeletedAtSnakeCasePattern = DeletedAtSnakeCasePattern;
94
+ class DeletedAtPatternWithExtraWrites {
95
+ constructor() {
96
+ this.name = "deleted_at";
97
+ this.fields = {
98
+ // need this to be lowerCamelCase because we do this based on field name
99
+ // #510
100
+ deletedAt: (0, field_1.TimestampType)({
101
+ nullable: true,
102
+ index: true,
103
+ defaultValueOnCreate: () => null,
104
+ }),
105
+ };
106
+ }
107
+ transformRead() {
108
+ // this is based on sql. other is based on field
109
+ return clause.Eq("deleted_at", null);
110
+ }
111
+ transformWrite(stmt) {
112
+ switch (stmt.op) {
113
+ case schema_1.SQLStatementOperation.Delete:
114
+ return {
115
+ op: schema_1.SQLStatementOperation.Update,
116
+ data: {
117
+ // this should return field, it'll be formatted as needed
118
+ deletedAt: new Date(),
119
+ },
120
+ changeset: () => orchestrator_1.EntChangeset.changesetFromQueries(stmt.builder, [
121
+ `DELETE FROM edge_table WHERE id1 = '${stmt.builder.existingEnt?.id}'`,
122
+ `DELETE FROM inverse_edge_table WHERE id1 = '${stmt.builder.existingEnt?.id}'`,
123
+ `DELETE FROM symmetric_edge_table WHERE id1 = '${stmt.builder.existingEnt?.id}'`,
124
+ {
125
+ query: `DELETE FROM edge_table WHERE id2 = ${db_1.default.getDialect() === db_1.Dialect.Postgres ? "$1" : "?"}`,
126
+ values: [stmt.builder.existingEnt?.id],
127
+ },
128
+ {
129
+ query: `DELETE FROM inverse_edge_table WHERE id2 = ${db_1.default.getDialect() === db_1.Dialect.Postgres ? "$1" : "?"}`,
130
+ values: [stmt.builder.existingEnt?.id],
131
+ },
132
+ {
133
+ query: `DELETE FROM symmetric_edge_table WHERE id2 = ${db_1.default.getDialect() === db_1.Dialect.Postgres ? "$1" : "?"}`,
134
+ values: [stmt.builder.existingEnt?.id],
135
+ },
136
+ ]),
137
+ };
138
+ }
139
+ return null;
140
+ }
141
+ }
142
+ exports.DeletedAtPatternWithExtraWrites = DeletedAtPatternWithExtraWrites;