@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
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.
- package/action/action.d.ts +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
|
@@ -8,9 +8,10 @@ const schema_1 = require("../../schema");
|
|
|
8
8
|
const internal_1 = require("./internal");
|
|
9
9
|
const const_1 = require("./const");
|
|
10
10
|
const viewer_1 = require("../../core/viewer");
|
|
11
|
-
const
|
|
11
|
+
const temp_db_1 = require("../db/temp_db");
|
|
12
12
|
const loaders_1 = require("../../core/loaders");
|
|
13
13
|
const convert_1 = require("../../core/convert");
|
|
14
|
+
const action_1 = require("../../action");
|
|
14
15
|
class ViewerWithAccessToken extends viewer_1.IDViewer {
|
|
15
16
|
constructor(viewerID, opts) {
|
|
16
17
|
super(viewerID, opts);
|
|
@@ -26,7 +27,18 @@ class FakeUser {
|
|
|
26
27
|
constructor(viewer, data) {
|
|
27
28
|
this.viewer = viewer;
|
|
28
29
|
this.nodeType = const_1.NodeType.FakeUser;
|
|
29
|
-
this.
|
|
30
|
+
this.data = data;
|
|
31
|
+
this.id = data.id;
|
|
32
|
+
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
33
|
+
this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
|
|
34
|
+
this.firstName = data.first_name;
|
|
35
|
+
this.lastName = data.last_name;
|
|
36
|
+
this.emailAddress = data.email_address;
|
|
37
|
+
this.phoneNumber = data.phone_number;
|
|
38
|
+
this.password = data.password;
|
|
39
|
+
}
|
|
40
|
+
getPrivacyPolicy() {
|
|
41
|
+
return {
|
|
30
42
|
rules: [
|
|
31
43
|
privacy_1.AllowIfViewerRule,
|
|
32
44
|
//can view user if friends
|
|
@@ -48,15 +60,6 @@ class FakeUser {
|
|
|
48
60
|
privacy_1.AlwaysDenyRule,
|
|
49
61
|
],
|
|
50
62
|
};
|
|
51
|
-
this.data = data;
|
|
52
|
-
this.id = data.id;
|
|
53
|
-
this.createdAt = (0, convert_1.convertDate)(data.created_at);
|
|
54
|
-
this.updatedAt = (0, convert_1.convertDate)(data.updated_at);
|
|
55
|
-
this.firstName = data.first_name;
|
|
56
|
-
this.lastName = data.last_name;
|
|
57
|
-
this.emailAddress = data.email_address;
|
|
58
|
-
this.phoneNumber = data.phone_number;
|
|
59
|
-
this.password = data.password;
|
|
60
63
|
}
|
|
61
64
|
static getFields() {
|
|
62
65
|
return [
|
|
@@ -71,7 +74,7 @@ class FakeUser {
|
|
|
71
74
|
];
|
|
72
75
|
}
|
|
73
76
|
static getTestTable() {
|
|
74
|
-
return (0,
|
|
77
|
+
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"));
|
|
75
78
|
}
|
|
76
79
|
static loaderOptions() {
|
|
77
80
|
return {
|
|
@@ -89,22 +92,15 @@ class FakeUser {
|
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
exports.FakeUser = FakeUser;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
password: (0, schema_1.StringType)({
|
|
102
|
-
nullable: true,
|
|
103
|
-
}),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.FakeUserSchema = FakeUserSchema;
|
|
95
|
+
exports.FakeUserSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
96
|
+
firstName: (0, schema_1.StringType)(),
|
|
97
|
+
lastName: (0, schema_1.StringType)(),
|
|
98
|
+
emailAddress: (0, schema_1.StringType)(),
|
|
99
|
+
phoneNumber: (0, schema_1.StringType)(),
|
|
100
|
+
password: (0, schema_1.StringType)({
|
|
101
|
+
nullable: true,
|
|
102
|
+
}),
|
|
103
|
+
}, FakeUser);
|
|
108
104
|
function getUserBuilder(viewer, input) {
|
|
109
105
|
const action = getUserAction(viewer, input);
|
|
110
106
|
return action.builder;
|
|
@@ -115,7 +111,7 @@ function getUserAction(viewer, input) {
|
|
|
115
111
|
for (const key in input) {
|
|
116
112
|
m.set(key, input[key]);
|
|
117
113
|
}
|
|
118
|
-
const action = new builder_1.SimpleAction(viewer,
|
|
114
|
+
const action = new builder_1.SimpleAction(viewer, exports.FakeUserSchema, m, action_1.WriteOperation.Insert, null);
|
|
119
115
|
action.viewerForEntLoad = (data) => {
|
|
120
116
|
// load the created ent using a VC of the newly created user.
|
|
121
117
|
return new viewer_1.IDViewer(data.id);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Data, Ent } from "../../core/base";
|
|
2
2
|
import { AssocEdge } from "../../core/ent";
|
|
3
|
-
import { TempDB } from "../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/
|
|
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
|
|
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");
|
|
@@ -107,7 +107,7 @@ async function createUserPlusFriendRequests(input, slice) {
|
|
|
107
107
|
return createTestUser(input);
|
|
108
108
|
}));
|
|
109
109
|
expect(friendRequests.length).toBe(userInputs.length);
|
|
110
|
-
await addEdge(user,
|
|
110
|
+
await addEdge(user, _1.FakeUserSchema, _1.EdgeType.UserToFriendRequests, true, ...friendRequests);
|
|
111
111
|
return [user, friendRequests];
|
|
112
112
|
}
|
|
113
113
|
exports.createUserPlusFriendRequests = createUserPlusFriendRequests;
|
|
@@ -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
|
|
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,
|
|
224
|
+
(0, temp_db_1.assoc_edge_config_table)(),
|
|
225
225
|
];
|
|
226
|
-
edgeTableNames().forEach((tableName) => tables.push((0,
|
|
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;
|
|
@@ -53,7 +53,7 @@ export declare class UserToFriendRequestsQuery extends AssocEdgeQueryBase<FakeUs
|
|
|
53
53
|
}
|
|
54
54
|
export declare class UserToIncomingFriendRequestsQuery extends AssocEdgeQueryBase<FakeUser, FakeUser, AssocEdge> {
|
|
55
55
|
constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>);
|
|
56
|
-
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent
|
|
56
|
+
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
57
57
|
sourceEnt(id: ID): Promise<FakeUser | null>;
|
|
58
58
|
static query(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>): UserToIncomingFriendRequestsQuery;
|
|
59
59
|
queryContacts(): UserToContactsQuery;
|
|
@@ -90,7 +90,7 @@ export declare class UserToEventsInNextWeekQuery extends CustomEdgeQueryBase<Fak
|
|
|
90
90
|
constructor(viewer: Viewer, src: ID | FakeUser);
|
|
91
91
|
static query(viewer: Viewer, src: FakeUser | ID): UserToEventsInNextWeekQuery;
|
|
92
92
|
sourceEnt(id: ID): Promise<FakeUser | null>;
|
|
93
|
-
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent
|
|
93
|
+
getPrivacyPolicy(): import("../../core/base").PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
94
94
|
}
|
|
95
95
|
export declare class UserToFollowingQuery extends AssocEdgeQueryBase<FakeUser, Ent, AssocEdge> {
|
|
96
96
|
constructor(viewer: Viewer, src: EdgeQuerySource<FakeUser, FakeUser>);
|
package/testutils/fake_log.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ent } from "../core/base";
|
|
1
|
+
import { Ent, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "./../action";
|
|
3
3
|
export declare class FakeLogger {
|
|
4
4
|
private static logs;
|
|
@@ -8,6 +8,6 @@ export declare class FakeLogger {
|
|
|
8
8
|
static contains(line: string): boolean;
|
|
9
9
|
static clear(): void;
|
|
10
10
|
}
|
|
11
|
-
export declare class EntCreationObserver<
|
|
12
|
-
observe(builder: Builder<
|
|
11
|
+
export declare class EntCreationObserver<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
12
|
+
observe(builder: Builder<TEnt, TViewer>): Promise<void>;
|
|
13
13
|
}
|
package/testutils/parse_sql.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export declare class EqOp {
|
|
|
9
9
|
constructor(col: string, value: any);
|
|
10
10
|
apply(data: Data): boolean;
|
|
11
11
|
}
|
|
12
|
+
export declare class NotEqOp {
|
|
13
|
+
private col;
|
|
14
|
+
private value;
|
|
15
|
+
constructor(col: string, value: any);
|
|
16
|
+
apply(data: Data): boolean;
|
|
17
|
+
}
|
|
12
18
|
export declare class GreaterOp {
|
|
13
19
|
private col;
|
|
14
20
|
private value;
|
package/testutils/parse_sql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.performQuery = exports.OrOp = exports.AndOp = exports.InOp = exports.LessEqOp = exports.GreaterEqOp = exports.LessOp = exports.GreaterOp = exports.EqOp = exports.getDataToReturn = void 0;
|
|
3
|
+
exports.performQuery = exports.OrOp = exports.AndOp = exports.InOp = exports.LessEqOp = exports.GreaterEqOp = exports.LessOp = exports.GreaterOp = exports.NotEqOp = exports.EqOp = exports.getDataToReturn = void 0;
|
|
4
4
|
const node_sql_parser_1 = require("node-sql-parser");
|
|
5
5
|
function getTableName(table) {
|
|
6
6
|
if (Array.isArray(table)) {
|
|
@@ -184,6 +184,16 @@ class EqOp {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
exports.EqOp = EqOp;
|
|
187
|
+
class NotEqOp {
|
|
188
|
+
constructor(col, value) {
|
|
189
|
+
this.col = col;
|
|
190
|
+
this.value = value;
|
|
191
|
+
}
|
|
192
|
+
apply(data) {
|
|
193
|
+
return data[this.col] !== this.value;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.NotEqOp = NotEqOp;
|
|
187
197
|
class GreaterOp {
|
|
188
198
|
constructor(col, value) {
|
|
189
199
|
this.col = col;
|
|
@@ -307,8 +317,12 @@ function getOp(where, values) {
|
|
|
307
317
|
return new AndOp([getOp(where.left, values), getOp(where.right, values)]);
|
|
308
318
|
case "OR":
|
|
309
319
|
return new OrOp([getOp(where.left, values), getOp(where.right, values)]);
|
|
320
|
+
case "IS":
|
|
321
|
+
return new EqOp(getColumnFromRef(where.left), where.right?.value);
|
|
322
|
+
case "IS NOT":
|
|
323
|
+
return new NotEqOp(getColumnFromRef(where.left), where.right?.value);
|
|
310
324
|
default:
|
|
311
|
-
console.
|
|
325
|
+
console.debug(where);
|
|
312
326
|
throw new Error(`unsupported op ${where.operator}`);
|
|
313
327
|
}
|
|
314
328
|
}
|
|
@@ -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
|
+
};
|
package/testutils/write.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EditRowOptions, Data,
|
|
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,
|
|
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>;
|
package/testutils/write.js
CHANGED
|
@@ -22,13 +22,13 @@ async function createRowForTest(options, suffix) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.createRowForTest = createRowForTest;
|
|
25
|
-
async function editRowForTest(options,
|
|
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,
|
|
29
|
+
return (0, ent_1.editRowSync)(client, options, suffix || "");
|
|
30
30
|
}
|
|
31
|
-
return await (0, ent_1.editRow)(client, options,
|
|
31
|
+
return await (0, ent_1.editRow)(client, options, suffix);
|
|
32
32
|
}
|
|
33
33
|
finally {
|
|
34
34
|
client.release();
|
package/tsc/ast.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export declare function getPreText(fileContents: string, node: ts.Node, sourceFile: ts.SourceFile): string;
|
|
3
|
+
export interface ClassInfo {
|
|
4
|
+
extends?: string;
|
|
5
|
+
comment: string;
|
|
6
|
+
name: string;
|
|
7
|
+
export?: boolean;
|
|
8
|
+
default?: boolean;
|
|
9
|
+
implements?: string[];
|
|
10
|
+
wrapClassContents(inner: string): string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getClassInfo(fileContents: string, sourceFile: ts.SourceFile, node: ts.ClassDeclaration): ClassInfo | undefined;
|
|
13
|
+
declare type transformImportFn = (imp: string) => string;
|
|
14
|
+
interface transformOpts {
|
|
15
|
+
removeImports?: string[];
|
|
16
|
+
newImports?: string[];
|
|
17
|
+
transform?: transformImportFn;
|
|
18
|
+
transformPath: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function transformImport(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, opts: transformOpts): string | undefined;
|
|
21
|
+
export declare function updateImportPath(fileContents: string, importNode: ts.ImportDeclaration, sourceFile: ts.SourceFile, newPath: string): string | undefined;
|
|
22
|
+
export declare function isRelativeImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
|
|
23
|
+
export declare function isRelativeGeneratedImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
|
|
24
|
+
export declare function isSrcGeneratedImport(node: ts.ImportDeclaration, sourceFile: ts.SourceFile): boolean;
|
|
25
|
+
interface importInfo {
|
|
26
|
+
imports: string[];
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
importText: string;
|
|
30
|
+
importPath: string;
|
|
31
|
+
default?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function getImportInfo(imp: ts.ImportDeclaration, sourceFile: ts.SourceFile): importInfo | undefined;
|
|
34
|
+
export declare function transformRelative(file: string, importPath: string, relative?: boolean): string;
|
|
35
|
+
export interface customInfo {
|
|
36
|
+
viewerInfo: {
|
|
37
|
+
path: string;
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
40
|
+
relativeImports?: boolean;
|
|
41
|
+
globalSchemaPath?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function getCustomInfo(): customInfo;
|
|
44
|
+
export {};
|
package/tsc/ast.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.getCustomInfo = exports.transformRelative = exports.getImportInfo = exports.isSrcGeneratedImport = exports.isRelativeGeneratedImport = exports.isRelativeImport = exports.updateImportPath = exports.transformImport = exports.getClassInfo = exports.getPreText = void 0;
|
|
26
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const js_yaml_1 = require("js-yaml");
|
|
29
|
+
const fs = __importStar(require("fs"));
|
|
30
|
+
function getPreText(fileContents, node, sourceFile) {
|
|
31
|
+
return fileContents.substring(node.getFullStart(), node.getStart(sourceFile));
|
|
32
|
+
}
|
|
33
|
+
exports.getPreText = getPreText;
|
|
34
|
+
function getClassInfo(fileContents, sourceFile, node) {
|
|
35
|
+
let className = node.name?.text;
|
|
36
|
+
let classExtends;
|
|
37
|
+
let impl = [];
|
|
38
|
+
if (node.heritageClauses) {
|
|
39
|
+
for (const hc of node.heritageClauses) {
|
|
40
|
+
switch (hc.token) {
|
|
41
|
+
case typescript_1.default.SyntaxKind.ImplementsKeyword:
|
|
42
|
+
for (const type of hc.types) {
|
|
43
|
+
impl.push(type.expression.getText(sourceFile));
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case typescript_1.default.SyntaxKind.ExtendsKeyword:
|
|
47
|
+
// can only extend one class
|
|
48
|
+
for (const type of hc.types) {
|
|
49
|
+
const text = type.expression.getText(sourceFile);
|
|
50
|
+
classExtends = text;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!className) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
let hasExport = false;
|
|
60
|
+
let hasDefault = false;
|
|
61
|
+
let comment = getPreText(fileContents, node, sourceFile);
|
|
62
|
+
const wrapClassContents = (inner) => {
|
|
63
|
+
let ret = `${comment}`;
|
|
64
|
+
if (hasExport) {
|
|
65
|
+
ret += "export ";
|
|
66
|
+
}
|
|
67
|
+
if (hasDefault) {
|
|
68
|
+
ret += "default ";
|
|
69
|
+
}
|
|
70
|
+
ret += `class ${className} `;
|
|
71
|
+
if (classExtends) {
|
|
72
|
+
ret += `extends ${classExtends} `;
|
|
73
|
+
}
|
|
74
|
+
if (impl.length) {
|
|
75
|
+
ret += `implements ${impl.join(", ")}`;
|
|
76
|
+
}
|
|
77
|
+
return `${ret}{
|
|
78
|
+
${inner}
|
|
79
|
+
}`;
|
|
80
|
+
};
|
|
81
|
+
if (node.modifiers) {
|
|
82
|
+
for (const mod of node.modifiers) {
|
|
83
|
+
const text = mod.getText(sourceFile);
|
|
84
|
+
if (text === "export") {
|
|
85
|
+
hasExport = true;
|
|
86
|
+
}
|
|
87
|
+
else if (text === "default") {
|
|
88
|
+
hasDefault = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
name: className,
|
|
94
|
+
extends: classExtends,
|
|
95
|
+
comment,
|
|
96
|
+
implements: impl,
|
|
97
|
+
wrapClassContents,
|
|
98
|
+
export: hasExport,
|
|
99
|
+
default: hasDefault,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.getClassInfo = getClassInfo;
|
|
103
|
+
function transformImport(fileContents, importNode, sourceFile, opts) {
|
|
104
|
+
// remove quotes too
|
|
105
|
+
const text = importNode.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
106
|
+
if (text != opts.transformPath) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const impInfo = getImportInfo(importNode, sourceFile);
|
|
110
|
+
if (!impInfo) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let { imports, start, end, importText, default: def } = impInfo;
|
|
114
|
+
let removeImportsMap = {};
|
|
115
|
+
if (opts?.removeImports) {
|
|
116
|
+
opts.removeImports.forEach((imp) => {
|
|
117
|
+
removeImportsMap[imp] = true;
|
|
118
|
+
if (def === imp) {
|
|
119
|
+
def = "";
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
let finalImports = new Set();
|
|
124
|
+
for (let i = 0; i < imports.length; i++) {
|
|
125
|
+
let imp = imports[i].trim();
|
|
126
|
+
if (imp === "") {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (opts?.transform) {
|
|
130
|
+
imp = opts.transform(imp);
|
|
131
|
+
}
|
|
132
|
+
if (removeImportsMap[imp]) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
finalImports.add(imp);
|
|
136
|
+
}
|
|
137
|
+
if (opts?.newImports) {
|
|
138
|
+
opts.newImports.forEach((imp) => finalImports.add(imp));
|
|
139
|
+
}
|
|
140
|
+
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
141
|
+
return (comment +
|
|
142
|
+
"import " +
|
|
143
|
+
// add default
|
|
144
|
+
(def || "") +
|
|
145
|
+
// should probably always be "{" now that we support default
|
|
146
|
+
(start >= 0 ? importText.substring(0, start + 1) : "{") +
|
|
147
|
+
Array.from(finalImports).join(", ") +
|
|
148
|
+
// should probably always be "}"
|
|
149
|
+
(end >= 0 ? importText.substring(end) : "}") +
|
|
150
|
+
' from "' +
|
|
151
|
+
text +
|
|
152
|
+
'";');
|
|
153
|
+
}
|
|
154
|
+
exports.transformImport = transformImport;
|
|
155
|
+
function updateImportPath(fileContents, importNode, sourceFile, newPath) {
|
|
156
|
+
const comment = getPreText(fileContents, importNode, sourceFile);
|
|
157
|
+
// all this copied from above...
|
|
158
|
+
const importText = importNode.importClause?.getText(sourceFile) || "";
|
|
159
|
+
const start = importText.indexOf("{");
|
|
160
|
+
const end = importText.lastIndexOf("}");
|
|
161
|
+
if (start === -1 || end === -1) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const imports = importText
|
|
165
|
+
.substring(start + 1, end)
|
|
166
|
+
// .trim()
|
|
167
|
+
.split(",");
|
|
168
|
+
return (comment +
|
|
169
|
+
"import " +
|
|
170
|
+
importText.substring(0, start + 1) +
|
|
171
|
+
Array.from(imports).join(", ") +
|
|
172
|
+
importText.substring(end) +
|
|
173
|
+
' from "' +
|
|
174
|
+
newPath +
|
|
175
|
+
'";');
|
|
176
|
+
}
|
|
177
|
+
exports.updateImportPath = updateImportPath;
|
|
178
|
+
function isRelativeImport(node, sourceFile) {
|
|
179
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
180
|
+
return text.startsWith("..") || text.startsWith("./");
|
|
181
|
+
}
|
|
182
|
+
exports.isRelativeImport = isRelativeImport;
|
|
183
|
+
function isRelativeGeneratedImport(node, sourceFile) {
|
|
184
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
185
|
+
return ((text.startsWith("..") || text.startsWith("./")) &&
|
|
186
|
+
text.indexOf("/generated") !== -1);
|
|
187
|
+
}
|
|
188
|
+
exports.isRelativeGeneratedImport = isRelativeGeneratedImport;
|
|
189
|
+
function isSrcGeneratedImport(node, sourceFile) {
|
|
190
|
+
const text = node.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
191
|
+
return text.startsWith("src") && text.includes("/generated");
|
|
192
|
+
}
|
|
193
|
+
exports.isSrcGeneratedImport = isSrcGeneratedImport;
|
|
194
|
+
// TODO doesn't support default + {} yet
|
|
195
|
+
function getImportInfo(imp, sourceFile) {
|
|
196
|
+
const importText = imp.importClause?.getText(sourceFile) || "";
|
|
197
|
+
const start = importText.indexOf("{");
|
|
198
|
+
const end = importText.lastIndexOf("}");
|
|
199
|
+
const text = imp.moduleSpecifier.getText(sourceFile).slice(1, -1);
|
|
200
|
+
if ((start === -1 || end === -1) && !importText.length) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
let imports = [];
|
|
204
|
+
let def;
|
|
205
|
+
if (start !== -1 && end !== -1) {
|
|
206
|
+
imports = importText
|
|
207
|
+
.substring(start + 1, end)
|
|
208
|
+
//.trim()
|
|
209
|
+
.split(",");
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
def = importText;
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
importPath: text,
|
|
216
|
+
importText,
|
|
217
|
+
start,
|
|
218
|
+
end,
|
|
219
|
+
imports,
|
|
220
|
+
default: def,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
exports.getImportInfo = getImportInfo;
|
|
224
|
+
function transformRelative(file, importPath, relative) {
|
|
225
|
+
if (!relative || !importPath.startsWith("src")) {
|
|
226
|
+
return importPath;
|
|
227
|
+
}
|
|
228
|
+
const fileFullPath = path.join(process.cwd(), file);
|
|
229
|
+
const impFullPath = path.join(process.cwd(), importPath);
|
|
230
|
+
// relative path is from directory
|
|
231
|
+
return normalizePath(path.relative(path.dirname(fileFullPath), impFullPath));
|
|
232
|
+
}
|
|
233
|
+
exports.transformRelative = transformRelative;
|
|
234
|
+
function normalizePath(p) {
|
|
235
|
+
if (p.endsWith("..")) {
|
|
236
|
+
return p + "/";
|
|
237
|
+
}
|
|
238
|
+
return p;
|
|
239
|
+
}
|
|
240
|
+
// also used in parse schema logic
|
|
241
|
+
function getCustomInfo() {
|
|
242
|
+
let yaml = {};
|
|
243
|
+
let relativeImports = false;
|
|
244
|
+
try {
|
|
245
|
+
yaml = (0, js_yaml_1.load)(fs.readFileSync(path.join(process.cwd(), "ent.yml"), {
|
|
246
|
+
encoding: "utf8",
|
|
247
|
+
}));
|
|
248
|
+
relativeImports = yaml?.codegen?.relativeImports || false;
|
|
249
|
+
if (yaml?.codegen?.templatizedViewer) {
|
|
250
|
+
return {
|
|
251
|
+
viewerInfo: yaml.codegen.templatizedViewer,
|
|
252
|
+
relativeImports,
|
|
253
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (e) { }
|
|
258
|
+
return {
|
|
259
|
+
viewerInfo: {
|
|
260
|
+
path: "@snowtop/ent",
|
|
261
|
+
name: "Viewer",
|
|
262
|
+
},
|
|
263
|
+
relativeImports,
|
|
264
|
+
globalSchemaPath: yaml.globalSchemaPath,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
exports.getCustomInfo = getCustomInfo;
|
package/tsc/compilerOptions.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
export declare function readCompilerOptions(filePath: string): ts.CompilerOptions;
|
|
3
|
+
export declare function getTarget(target?: string): ts.ScriptTarget;
|
|
4
|
+
export declare function getTargetFromCurrentDir(): ts.ScriptTarget;
|
|
5
|
+
export declare function createSourceFile(target: ts.ScriptTarget, file: string): {
|
|
6
|
+
contents: string;
|
|
7
|
+
sourceFile: ts.SourceFile;
|
|
8
|
+
};
|