@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101
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 +37 -31
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +40 -16
- package/action/orchestrator.js +230 -62
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +49 -26
- package/core/base.js +7 -1
- package/core/clause.d.ts +88 -7
- package/core/clause.js +355 -63
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +81 -25
- package/core/ent.js +636 -193
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +67 -59
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -24
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +14 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +1 -4
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +12 -5
- package/index.js +20 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +29 -9
- package/parse_schema/parse.js +118 -11
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +5 -0
- package/schema/field.d.ts +74 -20
- package/schema/field.js +174 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +81 -18
- package/schema/schema.js +24 -17
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +57 -21
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +117 -30
- package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +46 -47
- package/testutils/builder.js +108 -65
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +179 -44
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +27 -8
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +7 -3
- package/testutils/fake_data/fake_contact.js +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +7 -4
- package/testutils/fake_data/fake_user.js +18 -16
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +28 -12
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- 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 +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +26 -2
- package/tsc/ast.js +163 -17
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +11 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -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/{scripts → tsc}/transform_schema.js +145 -119
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_code.js +0 -114
package/testutils/builder.js
CHANGED
|
@@ -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.getTableName = exports.getSchemaName = exports.getBuilderSchemaTZFromFields = exports.getBuilderSchemaFromFields = exports.getBuilderSchema = exports.Address = exports.Message = exports.Group = exports.Contact = exports.Event = exports.User = void 0;
|
|
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;
|
|
7
7
|
const privacy_1 = require("../core/privacy");
|
|
8
8
|
const orchestrator_1 = require("../action/orchestrator");
|
|
9
9
|
const action_1 = require("../action");
|
|
@@ -15,89 +15,90 @@ const loaders_1 = require("../core/loaders");
|
|
|
15
15
|
const convert_1 = require("../core/convert");
|
|
16
16
|
const camel_case_1 = require("camel-case");
|
|
17
17
|
const base_schema_1 = require("../schema/base_schema");
|
|
18
|
-
|
|
18
|
+
const schema_2 = require("../schema/schema");
|
|
19
|
+
class BaseEnt {
|
|
19
20
|
constructor(viewer, data) {
|
|
20
21
|
this.viewer = viewer;
|
|
21
22
|
this.data = data;
|
|
22
|
-
this.accountID = "";
|
|
23
|
-
this.nodeType = "User";
|
|
24
23
|
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
25
24
|
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
26
|
-
this.id = data.
|
|
27
|
-
|
|
25
|
+
this.id = data[this.getKey()];
|
|
26
|
+
}
|
|
27
|
+
getKey() {
|
|
28
|
+
return "id";
|
|
28
29
|
}
|
|
29
30
|
getPrivacyPolicy() {
|
|
30
31
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
31
32
|
}
|
|
33
|
+
__setRawDBData(data) {
|
|
34
|
+
// doesn't apply here so ignore...
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
|
-
exports.
|
|
34
|
-
class
|
|
37
|
+
exports.BaseEnt = BaseEnt;
|
|
38
|
+
class User extends BaseEnt {
|
|
35
39
|
constructor(viewer, data) {
|
|
40
|
+
super(viewer, data);
|
|
36
41
|
this.viewer = viewer;
|
|
37
42
|
this.data = data;
|
|
38
43
|
this.accountID = "";
|
|
39
|
-
this.nodeType = "
|
|
40
|
-
this.
|
|
44
|
+
this.nodeType = "User";
|
|
45
|
+
this.firstName = data.first_name;
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
}
|
|
48
|
+
exports.User = User;
|
|
49
|
+
class Event extends BaseEnt {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(...arguments);
|
|
52
|
+
this.accountID = "";
|
|
53
|
+
this.nodeType = "Event";
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
exports.Event = Event;
|
|
47
|
-
class Contact {
|
|
48
|
-
constructor(
|
|
49
|
-
|
|
50
|
-
this.data = data;
|
|
57
|
+
class Contact extends BaseEnt {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(...arguments);
|
|
51
60
|
this.accountID = "";
|
|
52
61
|
this.nodeType = "Contact";
|
|
53
|
-
this.data.created_at = (0, convert_1.convertDate)(data.created_at);
|
|
54
|
-
this.data.updated_at = (0, convert_1.convertDate)(data.updated_at);
|
|
55
|
-
this.id = data.id;
|
|
56
62
|
}
|
|
57
63
|
getPrivacyPolicy() {
|
|
58
64
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
exports.Contact = Contact;
|
|
62
|
-
class Group {
|
|
63
|
-
constructor(
|
|
64
|
-
|
|
65
|
-
this.data = data;
|
|
68
|
+
class Group extends BaseEnt {
|
|
69
|
+
constructor() {
|
|
70
|
+
super(...arguments);
|
|
66
71
|
this.accountID = "";
|
|
67
72
|
this.nodeType = "Group";
|
|
68
|
-
this.id = data.id;
|
|
69
73
|
}
|
|
70
74
|
getPrivacyPolicy() {
|
|
71
75
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
exports.Group = Group;
|
|
75
|
-
class Message {
|
|
76
|
-
constructor(
|
|
77
|
-
|
|
78
|
-
this.data = data;
|
|
79
|
+
class Message extends BaseEnt {
|
|
80
|
+
constructor() {
|
|
81
|
+
super(...arguments);
|
|
79
82
|
this.accountID = "";
|
|
80
83
|
this.nodeType = "Message";
|
|
81
|
-
this.id = data.id;
|
|
82
|
-
}
|
|
83
|
-
getPrivacyPolicy() {
|
|
84
|
-
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
86
|
exports.Message = Message;
|
|
88
|
-
class Address {
|
|
89
|
-
constructor(
|
|
90
|
-
|
|
91
|
-
this.data = data;
|
|
87
|
+
class Address extends BaseEnt {
|
|
88
|
+
constructor() {
|
|
89
|
+
super(...arguments);
|
|
92
90
|
this.accountID = "";
|
|
93
91
|
this.nodeType = "Address";
|
|
94
|
-
this.id = data.id;
|
|
95
|
-
}
|
|
96
|
-
getPrivacyPolicy() {
|
|
97
|
-
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
98
92
|
}
|
|
99
93
|
}
|
|
100
94
|
exports.Address = Address;
|
|
95
|
+
class EntBuilderSchema extends base_schema_1.EntSchema {
|
|
96
|
+
constructor(ent, cfg) {
|
|
97
|
+
super(cfg);
|
|
98
|
+
this.ent = ent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.EntBuilderSchema = EntBuilderSchema;
|
|
101
102
|
function getBuilderSchema(cfg, ent) {
|
|
102
103
|
return {
|
|
103
104
|
...new base_schema_1.EntSchema(cfg),
|
|
@@ -105,9 +106,9 @@ function getBuilderSchema(cfg, ent) {
|
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
exports.getBuilderSchema = getBuilderSchema;
|
|
108
|
-
function getBuilderSchemaFromFields(fields, ent) {
|
|
109
|
+
function getBuilderSchemaFromFields(fields, ent, opts) {
|
|
109
110
|
return {
|
|
110
|
-
...new base_schema_1.EntSchema({ fields }),
|
|
111
|
+
...new base_schema_1.EntSchema({ ...opts, fields }),
|
|
111
112
|
ent,
|
|
112
113
|
};
|
|
113
114
|
}
|
|
@@ -130,13 +131,27 @@ exports.getTableName = getTableName;
|
|
|
130
131
|
function randomNum() {
|
|
131
132
|
return Math.random().toString(10).substring(2);
|
|
132
133
|
}
|
|
134
|
+
function getFieldInfo(value) {
|
|
135
|
+
const fields = (0, schema_1.getFields)(value);
|
|
136
|
+
let ret = {};
|
|
137
|
+
for (const [k, f] of fields) {
|
|
138
|
+
ret[k] = {
|
|
139
|
+
dbCol: (0, schema_2.getStorageKey)(f, k),
|
|
140
|
+
// in tests (anything using SimpleBuilder), make it be the same as the fieldName
|
|
141
|
+
inputKey: k,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return ret;
|
|
145
|
+
}
|
|
146
|
+
exports.getFieldInfo = getFieldInfo;
|
|
133
147
|
// reuses orchestrator and standard things
|
|
134
148
|
class SimpleBuilder {
|
|
135
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
149
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt, action, expressions) {
|
|
136
150
|
this.viewer = viewer;
|
|
137
151
|
this.schema = schema;
|
|
138
152
|
this.operation = operation;
|
|
139
153
|
this.existingEnt = existingEnt;
|
|
154
|
+
this.m = new Map();
|
|
140
155
|
// create dynamic placeholder
|
|
141
156
|
// TODO: do we need to use this as the node when there's an existingEnt
|
|
142
157
|
// same for generated builders.
|
|
@@ -162,11 +177,13 @@ class SimpleBuilder {
|
|
|
162
177
|
this.ent = schema.ent;
|
|
163
178
|
const tableName = getTableName(schema);
|
|
164
179
|
this.nodeType = (0, camel_case_1.camelCase)(schema.ent.name);
|
|
180
|
+
const fieldInfo = getFieldInfo(schema);
|
|
165
181
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
166
182
|
viewer: this.viewer,
|
|
167
183
|
operation: operation,
|
|
168
184
|
tableName: tableName,
|
|
169
185
|
key,
|
|
186
|
+
fieldInfo,
|
|
170
187
|
loaderOptions: {
|
|
171
188
|
loaderFactory: new loaders_1.ObjectLoaderFactory({
|
|
172
189
|
tableName: tableName,
|
|
@@ -176,10 +193,11 @@ class SimpleBuilder {
|
|
|
176
193
|
ent: schema.ent,
|
|
177
194
|
tableName: tableName,
|
|
178
195
|
fields: [],
|
|
179
|
-
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema),
|
|
196
|
+
fieldPrivacy: (0, schema_1.getFieldsWithPrivacy)(schema, fieldInfo),
|
|
180
197
|
},
|
|
181
198
|
builder: this,
|
|
182
199
|
action: action,
|
|
200
|
+
expressions,
|
|
183
201
|
schema: this.schema,
|
|
184
202
|
editedFields: () => {
|
|
185
203
|
// to simulate what we do in generated builders where we return a new Map
|
|
@@ -189,24 +207,40 @@ class SimpleBuilder {
|
|
|
189
207
|
}
|
|
190
208
|
return m;
|
|
191
209
|
},
|
|
192
|
-
updateInput: (
|
|
193
|
-
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
194
|
-
for (const k in input) {
|
|
195
|
-
if (knownFields.has(k)) {
|
|
196
|
-
this.fields.set(k, input[k]);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
200
|
-
// we do camelCase in
|
|
201
|
-
const sc = (0, snake_case_1.snakeCase)(k);
|
|
202
|
-
if (knownFields.has(sc)) {
|
|
203
|
-
this.fields.set(sc, input[k]);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
210
|
+
updateInput: this.updateInput.bind(this),
|
|
208
211
|
});
|
|
209
212
|
}
|
|
213
|
+
getInput() {
|
|
214
|
+
let ret = {};
|
|
215
|
+
for (const [k, v] of this.fields) {
|
|
216
|
+
ret[k] = v;
|
|
217
|
+
}
|
|
218
|
+
return ret;
|
|
219
|
+
}
|
|
220
|
+
updateInput(input) {
|
|
221
|
+
const knownFields = (0, schema_1.getFields)(this.schema);
|
|
222
|
+
for (const k in input) {
|
|
223
|
+
if (knownFields.has(k)) {
|
|
224
|
+
this.fields.set(k, input[k]);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// related to #510. we do camelCase to pass fields in here but fields may be snakeCase and we want that to pass in tests
|
|
228
|
+
// we do camelCase in
|
|
229
|
+
const sc = (0, snake_case_1.snakeCase)(k);
|
|
230
|
+
if (knownFields.has(sc)) {
|
|
231
|
+
this.fields.set(sc, input[k]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// store data in Builder that can be retrieved by another validator, trigger, observer later in the action
|
|
237
|
+
storeData(k, v) {
|
|
238
|
+
this.m.set(k, v);
|
|
239
|
+
}
|
|
240
|
+
// retrieve data stored in this Builder with key
|
|
241
|
+
getStoredData(k) {
|
|
242
|
+
return this.m.get(k);
|
|
243
|
+
}
|
|
210
244
|
build() {
|
|
211
245
|
return this.orchestrator.build();
|
|
212
246
|
}
|
|
@@ -231,13 +265,19 @@ class SimpleBuilder {
|
|
|
231
265
|
}
|
|
232
266
|
exports.SimpleBuilder = SimpleBuilder;
|
|
233
267
|
class SimpleAction {
|
|
234
|
-
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt
|
|
268
|
+
constructor(viewer, schema, fields, operation = action_1.WriteOperation.Insert, existingEnt, expressions) {
|
|
235
269
|
this.viewer = viewer;
|
|
236
270
|
this.fields = fields;
|
|
237
|
-
this.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
271
|
+
this.builder = new SimpleBuilder(this.viewer, schema, fields, operation, existingEnt, this, expressions);
|
|
272
|
+
}
|
|
273
|
+
getTriggers() {
|
|
274
|
+
return [];
|
|
275
|
+
}
|
|
276
|
+
getValidators() {
|
|
277
|
+
return [];
|
|
278
|
+
}
|
|
279
|
+
getObservers() {
|
|
280
|
+
return [];
|
|
241
281
|
}
|
|
242
282
|
getPrivacyPolicy() {
|
|
243
283
|
return privacy_1.AlwaysAllowPrivacyPolicy;
|
|
@@ -258,6 +298,9 @@ class SimpleAction {
|
|
|
258
298
|
validX() {
|
|
259
299
|
return this.builder.orchestrator.validX();
|
|
260
300
|
}
|
|
301
|
+
validWithErrors() {
|
|
302
|
+
return this.builder.orchestrator.validWithErrors();
|
|
303
|
+
}
|
|
261
304
|
async save() {
|
|
262
305
|
await (0, action_1.saveBuilder)(this.builder);
|
|
263
306
|
if (this.builder.operation !== action_1.WriteOperation.Delete) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Client } from "pg";
|
|
2
|
+
import { Data } from "../../core/base";
|
|
3
|
+
import { Schema } from "../../schema";
|
|
4
|
+
interface Options {
|
|
5
|
+
overrides?: Data;
|
|
6
|
+
client: Client;
|
|
7
|
+
tableName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function writeFixture(schema: Schema, opts: Options): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFixture = void 0;
|
|
4
|
+
const schema_1 = require("../../schema");
|
|
5
|
+
const value_1 = require("./value");
|
|
6
|
+
const ent_1 = require("../../core/ent");
|
|
7
|
+
async function writeFixture(schema, opts) {
|
|
8
|
+
const fields = (0, schema_1.getFields)(schema);
|
|
9
|
+
const d = {};
|
|
10
|
+
for (const [fieldName, field] of fields) {
|
|
11
|
+
const col = (0, schema_1.getStorageKey)(field, fieldName);
|
|
12
|
+
const val = (0, value_1.getDefaultValue)(field, col);
|
|
13
|
+
d[col] = val;
|
|
14
|
+
}
|
|
15
|
+
if (opts.overrides) {
|
|
16
|
+
for (const k in opts.overrides) {
|
|
17
|
+
d[k] = opts.overrides[k];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const q = (0, ent_1.buildInsertQuery)({
|
|
21
|
+
tableName: opts.tableName,
|
|
22
|
+
fields: d,
|
|
23
|
+
});
|
|
24
|
+
await opts.client.query(q[0], q[1]);
|
|
25
|
+
}
|
|
26
|
+
exports.writeFixture = writeFixture;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Client as PGClient } from "pg";
|
|
2
2
|
import { Dialect } from "../../core/db";
|
|
3
3
|
import { Database as SqliteDatabase } from "better-sqlite3";
|
|
4
|
+
import { Field } from "../../schema";
|
|
4
5
|
import { BuilderSchema } from "../builder";
|
|
5
6
|
import { Ent } from "../../core/base";
|
|
6
7
|
interface SchemaItem {
|
|
@@ -12,6 +13,7 @@ interface Column extends SchemaItem {
|
|
|
12
13
|
primaryKey?: boolean;
|
|
13
14
|
unique?: boolean;
|
|
14
15
|
default?: string;
|
|
16
|
+
index?: boolean | indexOptions;
|
|
15
17
|
foreignKey?: {
|
|
16
18
|
table: string;
|
|
17
19
|
col: string;
|
|
@@ -20,22 +22,32 @@ interface Column extends SchemaItem {
|
|
|
20
22
|
interface Constraint extends SchemaItem {
|
|
21
23
|
generate(): string;
|
|
22
24
|
}
|
|
25
|
+
interface Index extends SchemaItem {
|
|
26
|
+
generate(): string;
|
|
27
|
+
postCreate?(): boolean;
|
|
28
|
+
}
|
|
23
29
|
export interface CoreConcept {
|
|
24
30
|
name: string;
|
|
25
31
|
create(): string;
|
|
32
|
+
postCreate?(): string[];
|
|
26
33
|
drop(): string;
|
|
27
34
|
}
|
|
28
35
|
export interface Table extends CoreConcept {
|
|
29
36
|
columns: Column[];
|
|
30
37
|
constraints?: Constraint[];
|
|
31
38
|
}
|
|
32
|
-
|
|
39
|
+
type options = Pick<Column, "nullable" | "primaryKey" | "default" | "foreignKey" | "unique" | "index">;
|
|
33
40
|
export declare function primaryKey(name: string, cols: string[]): Constraint;
|
|
34
41
|
export declare function foreignKey(name: string, cols: string[], fkey: {
|
|
35
42
|
table: string;
|
|
36
43
|
cols: string[];
|
|
37
44
|
}): Constraint;
|
|
38
|
-
export declare function
|
|
45
|
+
export declare function check(name: string, condition: string): Constraint;
|
|
46
|
+
interface indexOptions {
|
|
47
|
+
type?: string;
|
|
48
|
+
unique?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare function index(tableName: string, cols: string[], opts?: indexOptions): Index;
|
|
39
51
|
export declare function uuid(name: string, opts?: options): Column;
|
|
40
52
|
export declare function text(name: string, opts?: options): Column;
|
|
41
53
|
export declare function enumCol(name: string, type: string): Column;
|
|
@@ -67,11 +79,12 @@ export declare class TempDB {
|
|
|
67
79
|
private tables;
|
|
68
80
|
private dialect;
|
|
69
81
|
private sqlite;
|
|
70
|
-
|
|
71
|
-
constructor(
|
|
82
|
+
private setTables;
|
|
83
|
+
constructor(dialect: Dialect, tables?: CoreConcept[] | (() => CoreConcept[]));
|
|
72
84
|
getDialect(): Dialect;
|
|
73
|
-
|
|
85
|
+
__getTables(): Map<string, CoreConcept>;
|
|
74
86
|
beforeAll(setupConnString?: boolean): Promise<void>;
|
|
87
|
+
createImpl(table: CoreConcept): Promise<void>;
|
|
75
88
|
getSqliteClient(): SqliteDatabase;
|
|
76
89
|
getPostgresClient(): PGClient;
|
|
77
90
|
afterAll(): Promise<void>;
|
|
@@ -81,10 +94,13 @@ export declare class TempDB {
|
|
|
81
94
|
create(...tables: CoreConcept[]): Promise<void>;
|
|
82
95
|
}
|
|
83
96
|
export declare function assoc_edge_config_table(): Table;
|
|
84
|
-
export declare function assoc_edge_table(name: string): Table;
|
|
85
|
-
interface
|
|
97
|
+
export declare function assoc_edge_table(name: string, global?: boolean): Table;
|
|
98
|
+
interface setupOptions {
|
|
86
99
|
disableDeleteAfterEachTest?: boolean;
|
|
87
100
|
}
|
|
88
|
-
export declare function setupSqlite(connString: string, tables: () => Table[], opts?:
|
|
101
|
+
export declare function setupSqlite(connString: string, tables: () => Table[], opts?: setupOptions): TempDB;
|
|
102
|
+
export declare function setupPostgres(tables: () => Table[], opts?: setupOptions): void;
|
|
103
|
+
export declare function doSQLiteTestFromSchemas(schemas: BuilderSchema<Ent>[], doTest: () => Promise<void>, db?: string): Promise<TempDB>;
|
|
89
104
|
export declare function getSchemaTable(schema: BuilderSchema<Ent>, dialect: Dialect): Table;
|
|
105
|
+
export declare function getColumnFromField(fieldName: string, f: Field, dialect: Dialect): Column;
|
|
90
106
|
export {};
|