@snowtop/ent 0.1.0-alpha56 → 0.1.0-alpha58

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 (38) hide show
  1. package/action/orchestrator.js +21 -0
  2. package/core/base.d.ts +1 -1
  3. package/core/clause.d.ts +6 -3
  4. package/core/clause.js +39 -14
  5. package/core/config.d.ts +5 -2
  6. package/core/ent.d.ts +16 -3
  7. package/core/ent.js +147 -35
  8. package/core/loaders/assoc_count_loader.js +6 -1
  9. package/core/query/shared_assoc_test.d.ts +1 -1
  10. package/core/query/shared_assoc_test.js +17 -5
  11. package/core/query/shared_test.d.ts +3 -0
  12. package/core/query/shared_test.js +95 -17
  13. package/index.d.ts +1 -1
  14. package/index.js +3 -2
  15. package/package.json +1 -1
  16. package/parse_schema/parse.d.ts +8 -2
  17. package/parse_schema/parse.js +22 -2
  18. package/schema/index.d.ts +1 -1
  19. package/schema/schema.d.ts +15 -0
  20. package/scripts/custom_graphql.js +1 -1
  21. package/scripts/read_schema.js +10 -1
  22. package/testutils/db/{test_db.d.ts → temp_db.d.ts} +4 -2
  23. package/testutils/db/{test_db.js → temp_db.js} +16 -5
  24. package/testutils/fake_data/fake_contact.d.ts +1 -1
  25. package/testutils/fake_data/fake_contact.js +2 -2
  26. package/testutils/fake_data/fake_event.d.ts +1 -1
  27. package/testutils/fake_data/fake_event.js +3 -3
  28. package/testutils/fake_data/fake_user.d.ts +1 -1
  29. package/testutils/fake_data/fake_user.js +2 -2
  30. package/testutils/fake_data/test_helpers.d.ts +2 -2
  31. package/testutils/fake_data/test_helpers.js +5 -5
  32. package/testutils/parse_sql.js +4 -0
  33. package/testutils/test_edge_global_schema.d.ts +15 -0
  34. package/testutils/test_edge_global_schema.js +58 -0
  35. package/testutils/write.d.ts +2 -2
  36. package/testutils/write.js +3 -3
  37. package/tsc/ast.d.ts +1 -0
  38. package/tsc/ast.js +3 -0
@@ -1,6 +1,6 @@
1
1
  import { Data, Ent } from "../../core/base";
2
2
  import { AssocEdge } from "../../core/ent";
3
- import { TempDB } from "../db/test_db";
3
+ import { TempDB } from "../db/temp_db";
4
4
  import { FakeUser, UserCreateInput, ContactCreateInput, FakeContact } from ".";
5
5
  import { EventCreateInput, FakeEvent } from "./fake_event";
6
6
  import { BuilderSchema } from "../builder";
@@ -20,7 +20,7 @@ export declare function createEdges(): Promise<void>;
20
20
  export declare function edgeTableNames(): string[];
21
21
  export declare function createTestEvent(user: FakeUser, input?: Partial<EventCreateInput>): Promise<FakeEvent>;
22
22
  export declare function setupTempDB(): Promise<TempDB>;
23
- export declare function tempDBTables(): import("../db/test_db").Table[];
23
+ export declare function tempDBTables(global?: boolean): import("../db/temp_db").Table[];
24
24
  interface options {
25
25
  howMany: number;
26
26
  interval: number;
@@ -6,7 +6,7 @@ const viewer_1 = require("../../core/viewer");
6
6
  const ent_1 = require("../../core/ent");
7
7
  const snake_case_1 = require("snake-case");
8
8
  const write_1 = require("../write");
9
- const test_db_1 = require("../db/test_db");
9
+ const temp_db_1 = require("../db/temp_db");
10
10
  const _1 = require(".");
11
11
  const fake_event_1 = require("./fake_event");
12
12
  const const_1 = require("./const");
@@ -209,21 +209,21 @@ async function createTestEvent(user, input) {
209
209
  }
210
210
  exports.createTestEvent = createTestEvent;
211
211
  async function setupTempDB() {
212
- const tdb = new test_db_1.TempDB(tempDBTables());
212
+ const tdb = new temp_db_1.TempDB(tempDBTables());
213
213
  await tdb.beforeAll();
214
214
  // create once
215
215
  await createEdges();
216
216
  return tdb;
217
217
  }
218
218
  exports.setupTempDB = setupTempDB;
219
- function tempDBTables() {
219
+ function tempDBTables(global = false) {
220
220
  const tables = [
221
221
  _1.FakeUser.getTestTable(),
222
222
  _1.FakeContact.getTestTable(),
223
223
  fake_event_1.FakeEvent.getTestTable(),
224
- (0, test_db_1.assoc_edge_config_table)(),
224
+ (0, temp_db_1.assoc_edge_config_table)(),
225
225
  ];
226
- edgeTableNames().forEach((tableName) => tables.push((0, test_db_1.assoc_edge_table)(tableName)));
226
+ edgeTableNames().forEach((tableName) => tables.push((0, temp_db_1.assoc_edge_table)(tableName, global)));
227
227
  return tables;
228
228
  }
229
229
  exports.tempDBTables = tempDBTables;
@@ -307,6 +307,10 @@ function getOp(where, values) {
307
307
  return new AndOp([getOp(where.left, values), getOp(where.right, values)]);
308
308
  case "OR":
309
309
  return new OrOp([getOp(where.left, values), getOp(where.right, values)]);
310
+ case "IS":
311
+ if (where.right?.value === null) {
312
+ return new EqOp(getColumnFromRef(where.left), null);
313
+ }
310
314
  default:
311
315
  console.log(where);
312
316
  throw new Error(`unsupported op ${where.operator}`);
@@ -0,0 +1,15 @@
1
+ import { EdgeUpdateOperation, TransformedEdgeUpdateOperation } from "../schema";
2
+ import * as clause from "../core/clause";
3
+ import { AssocEdge } from "../core/ent";
4
+ import { Data } from "../core/base";
5
+ export declare class EdgeWithDeletedAt extends AssocEdge {
6
+ deletedAt: Date | null;
7
+ constructor(data: Data);
8
+ }
9
+ export declare const testEdgeGlobalSchema: {
10
+ extraEdgeFields: {
11
+ deletedAt: import("../schema").TimestampField;
12
+ };
13
+ transformEdgeRead(): clause.Clause;
14
+ transformEdgeWrite(stmt: EdgeUpdateOperation): TransformedEdgeUpdateOperation | null;
15
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.testEdgeGlobalSchema = exports.EdgeWithDeletedAt = void 0;
23
+ const schema_1 = require("../schema");
24
+ const clause = __importStar(require("../core/clause"));
25
+ const ent_1 = require("../core/ent");
26
+ class EdgeWithDeletedAt extends ent_1.AssocEdge {
27
+ constructor(data) {
28
+ super(data);
29
+ this.deletedAt = data.deleted_at;
30
+ }
31
+ }
32
+ exports.EdgeWithDeletedAt = EdgeWithDeletedAt;
33
+ exports.testEdgeGlobalSchema = {
34
+ extraEdgeFields: {
35
+ // need this to be lowerCamelCase because we do this based on field name
36
+ // #510
37
+ deletedAt: (0, schema_1.TimestampType)({
38
+ nullable: true,
39
+ index: true,
40
+ defaultValueOnCreate: () => null,
41
+ }),
42
+ },
43
+ transformEdgeRead() {
44
+ return clause.Eq("deleted_at", null);
45
+ },
46
+ transformEdgeWrite(stmt) {
47
+ switch (stmt.op) {
48
+ case schema_1.SQLStatementOperation.Delete:
49
+ return {
50
+ op: schema_1.SQLStatementOperation.Update,
51
+ data: {
52
+ deleted_at: new Date(),
53
+ },
54
+ };
55
+ }
56
+ return null;
57
+ },
58
+ };
@@ -1,5 +1,5 @@
1
- import { EditRowOptions, Data, ID, DataOptions, CreateRowOptions } from "../core/base";
1
+ import { EditRowOptions, Data, DataOptions, CreateRowOptions } from "../core/base";
2
2
  import * as clause from "../core/clause";
3
3
  export declare function createRowForTest(options: CreateRowOptions, suffix?: string): Promise<Data | null>;
4
- export declare function editRowForTest(options: EditRowOptions, id: ID, suffix?: string): Promise<Data | null>;
4
+ export declare function editRowForTest(options: EditRowOptions, suffix?: string): Promise<Data | null>;
5
5
  export declare function deleteRowsForTest(options: DataOptions, cls: clause.Clause): Promise<void>;
@@ -22,13 +22,13 @@ async function createRowForTest(options, suffix) {
22
22
  }
23
23
  }
24
24
  exports.createRowForTest = createRowForTest;
25
- async function editRowForTest(options, id, suffix) {
25
+ async function editRowForTest(options, suffix) {
26
26
  const client = await db_1.default.getInstance().getNewClient();
27
27
  try {
28
28
  if (isSyncClient(client)) {
29
- return (0, ent_1.editRowSync)(client, options, id, suffix || "");
29
+ return (0, ent_1.editRowSync)(client, options, suffix || "");
30
30
  }
31
- return await (0, ent_1.editRow)(client, options, id, suffix);
31
+ return await (0, ent_1.editRow)(client, options, suffix);
32
32
  }
33
33
  finally {
34
34
  client.release();
package/tsc/ast.d.ts CHANGED
@@ -38,6 +38,7 @@ export interface customInfo {
38
38
  name: string;
39
39
  };
40
40
  relativeImports?: boolean;
41
+ globalSchemaPath?: string;
41
42
  }
42
43
  export declare function getCustomInfo(): customInfo;
43
44
  export {};
package/tsc/ast.js CHANGED
@@ -237,6 +237,7 @@ function normalizePath(p) {
237
237
  }
238
238
  return p;
239
239
  }
240
+ // also used in parse schema logic
240
241
  function getCustomInfo() {
241
242
  let yaml = {};
242
243
  let relativeImports = false;
@@ -249,6 +250,7 @@ function getCustomInfo() {
249
250
  return {
250
251
  viewerInfo: yaml.codegen.templatizedViewer,
251
252
  relativeImports,
253
+ globalSchemaPath: yaml.globalSchemaPath,
252
254
  };
253
255
  }
254
256
  }
@@ -259,6 +261,7 @@ function getCustomInfo() {
259
261
  name: "Viewer",
260
262
  },
261
263
  relativeImports,
264
+ globalSchemaPath: yaml.globalSchemaPath,
262
265
  };
263
266
  }
264
267
  exports.getCustomInfo = getCustomInfo;