@snowtop/ent 0.1.26 → 0.2.0-alpha.2
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/names/names.d.ts +10 -0
- package/names/names.js +157 -0
- package/package.json +1 -1
- package/schema/base_schema.js +2 -2
- package/schema/field.d.ts +1 -1
- package/schema/field.js +9 -8
- package/schema/schema.d.ts +0 -3
- package/schema/schema.js +2 -5
- package/schema/struct_field.js +12 -9
- package/scripts/read_schema.js +2 -2
- package/testutils/builder.js +7 -9
- package/testutils/db/temp_db.js +2 -2
- package/testutils/fake_data/fake_contact.js +2 -2
- package/testutils/fake_data/fake_event.js +1 -1
- package/testutils/fake_data/test_helpers.js +3 -3
- package/testutils/soft_delete.js +0 -4
- package/testutils/test_edge_global_schema.js +0 -2
- package/tsc/transform_action.js +2 -2
package/names/names.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function toDBColumnOrTable(...strs: string[]): string;
|
|
2
|
+
export declare function toFilePath(s: string): string;
|
|
3
|
+
export declare function toFieldName(...strs: string[]): string;
|
|
4
|
+
export declare function toClassName(str: string): string;
|
|
5
|
+
interface splitResult {
|
|
6
|
+
s: string;
|
|
7
|
+
type: "lower" | "upper" | "digit" | "other";
|
|
8
|
+
}
|
|
9
|
+
export declare function _splitCamelCase(s: string): splitResult[];
|
|
10
|
+
export {};
|
package/names/names.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._splitCamelCase = exports.toClassName = exports.toFieldName = exports.toFilePath = exports.toDBColumnOrTable = void 0;
|
|
4
|
+
const camel_case_1 = require("camel-case");
|
|
5
|
+
const pascal_case_1 = require("pascal-case");
|
|
6
|
+
const snake_case_1 = require("snake-case");
|
|
7
|
+
// TODO tests and update functionality to match golang
|
|
8
|
+
function toDBColumnOrTable(...strs) {
|
|
9
|
+
let name = "";
|
|
10
|
+
for (let i = 0; i < strs.length; i++) {
|
|
11
|
+
const s = strs[i];
|
|
12
|
+
// this is to handle userIDs -> user_ids
|
|
13
|
+
const split = _splitCamelCase(s);
|
|
14
|
+
if (split.length > 2) {
|
|
15
|
+
const last = split[split.length - 1];
|
|
16
|
+
const nextLast = split[split.length - 2];
|
|
17
|
+
if (last.s === "s" && nextLast.type === "upper") {
|
|
18
|
+
// get the first n-2 words
|
|
19
|
+
name += (0, snake_case_1.snakeCase)(split
|
|
20
|
+
.map((v) => v.s)
|
|
21
|
+
.slice(0, split.length - 2)
|
|
22
|
+
.join(""));
|
|
23
|
+
name += "_";
|
|
24
|
+
// combine the last two
|
|
25
|
+
name += (0, snake_case_1.snakeCase)(nextLast.s);
|
|
26
|
+
name += last.s;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
name += (0, snake_case_1.snakeCase)(s);
|
|
31
|
+
if (i !== strs.length - 1) {
|
|
32
|
+
name += "_";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return name;
|
|
36
|
+
}
|
|
37
|
+
exports.toDBColumnOrTable = toDBColumnOrTable;
|
|
38
|
+
function toFilePath(s) {
|
|
39
|
+
return (0, snake_case_1.snakeCase)(s);
|
|
40
|
+
}
|
|
41
|
+
exports.toFilePath = toFilePath;
|
|
42
|
+
function toFieldName(...strs) {
|
|
43
|
+
let name = "";
|
|
44
|
+
let hasDoneLower = false;
|
|
45
|
+
for (const s of strs) {
|
|
46
|
+
// same logic in toDBColumnOrTable
|
|
47
|
+
const split = _splitCamelCase(s);
|
|
48
|
+
if (split.length > 2) {
|
|
49
|
+
const last = split[split.length - 1];
|
|
50
|
+
const nextLast = split[split.length - 2];
|
|
51
|
+
if (last.s === "s" && nextLast.type === "upper") {
|
|
52
|
+
// get the first n-2 words
|
|
53
|
+
name += (0, camel_case_1.camelCase)(split
|
|
54
|
+
.map((v) => v.s)
|
|
55
|
+
.slice(0, split.length - 2)
|
|
56
|
+
.join(""));
|
|
57
|
+
// combine the last two
|
|
58
|
+
name += (0, pascal_case_1.pascalCase)(nextLast.s);
|
|
59
|
+
name += last.s;
|
|
60
|
+
hasDoneLower = true;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!hasDoneLower) {
|
|
65
|
+
name += (0, camel_case_1.camelCase)(s);
|
|
66
|
+
hasDoneLower = true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
name += (0, pascal_case_1.pascalCase)(s);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return name;
|
|
73
|
+
}
|
|
74
|
+
exports.toFieldName = toFieldName;
|
|
75
|
+
function toClassName(str) {
|
|
76
|
+
return (0, pascal_case_1.pascalCase)(str);
|
|
77
|
+
}
|
|
78
|
+
exports.toClassName = toClassName;
|
|
79
|
+
function isUpper(s) {
|
|
80
|
+
for (const c of s) {
|
|
81
|
+
if (!(c >= "A" && c <= "Z")) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
function isLower(s) {
|
|
88
|
+
for (const c of s) {
|
|
89
|
+
if (!(c >= "a" && c <= "z")) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function isDigit(s) {
|
|
96
|
+
return /^\d+$/.test(s);
|
|
97
|
+
}
|
|
98
|
+
// ported from golang in internal/names/names.go
|
|
99
|
+
function _splitCamelCase(s) {
|
|
100
|
+
const results = [];
|
|
101
|
+
let lastType;
|
|
102
|
+
let type;
|
|
103
|
+
for (let i = 0; i < s.length; i++) {
|
|
104
|
+
const c = s[i];
|
|
105
|
+
if (isLower(c)) {
|
|
106
|
+
type = "lower";
|
|
107
|
+
}
|
|
108
|
+
else if (isUpper(c)) {
|
|
109
|
+
type = "upper";
|
|
110
|
+
}
|
|
111
|
+
else if (isDigit(c)) {
|
|
112
|
+
type = "digit";
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
type = "other";
|
|
116
|
+
}
|
|
117
|
+
if (lastType == type) {
|
|
118
|
+
results[results.length - 1].s += c;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
results.push({ s: c, type });
|
|
122
|
+
}
|
|
123
|
+
lastType = type;
|
|
124
|
+
}
|
|
125
|
+
// this is for handling the userIDs -> "user", "ID", "s" case
|
|
126
|
+
const isPlural = function (curr, next) {
|
|
127
|
+
return curr.length > 1 && next === "s";
|
|
128
|
+
};
|
|
129
|
+
for (let i = 0; i < results.length - 1; i++) {
|
|
130
|
+
if (isUpper(results[i].s[0]) &&
|
|
131
|
+
isLower(results[i + 1].s[0]) &&
|
|
132
|
+
!isPlural(results[i].s, results[i + 1].s)) {
|
|
133
|
+
// get last item from results[i] and add to front of results[i+1]
|
|
134
|
+
results[i + 1].s =
|
|
135
|
+
results[i].s[results[i].s.length - 1] + results[i + 1].s;
|
|
136
|
+
// now has a prefix and is not all of one case
|
|
137
|
+
results[i + 1].type = "other";
|
|
138
|
+
// remove last character from results[i]
|
|
139
|
+
results[i].s = results[i].s.slice(0, results[i].s.length - 1);
|
|
140
|
+
}
|
|
141
|
+
else if (isDigit(results[i].s[0]) && isLower(results[i + 1].s[0])) {
|
|
142
|
+
results[i].s = results[i].s + results[i + 1].s;
|
|
143
|
+
results[i].type = "other";
|
|
144
|
+
// remove
|
|
145
|
+
results[i + 1].s = "";
|
|
146
|
+
i++;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (let i = 0; i < results.length; i++) {
|
|
150
|
+
if (results[i].s === "") {
|
|
151
|
+
results.splice(i, 1);
|
|
152
|
+
i--;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return results;
|
|
156
|
+
}
|
|
157
|
+
exports._splitCamelCase = _splitCamelCase;
|
package/package.json
CHANGED
package/schema/base_schema.js
CHANGED
|
@@ -37,12 +37,12 @@ let nodeField = (0, field_1.UUIDType)({
|
|
|
37
37
|
});
|
|
38
38
|
let nodeFields = {
|
|
39
39
|
// inconsistent naming :(
|
|
40
|
-
|
|
40
|
+
id: nodeField,
|
|
41
41
|
...tsFields,
|
|
42
42
|
};
|
|
43
43
|
let nodeFieldsWithTZ = {
|
|
44
44
|
// inconsistent naming :(
|
|
45
|
-
|
|
45
|
+
id: nodeField,
|
|
46
46
|
createdAt: (0, field_1.TimestampType)({
|
|
47
47
|
hideFromGraphQL: true,
|
|
48
48
|
disableUserEditable: true,
|
package/schema/field.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ interface PolymorphicStringOptions extends StringOptions {
|
|
|
100
100
|
}
|
|
101
101
|
export declare class PolymorphicStringField extends StringField {
|
|
102
102
|
private opts;
|
|
103
|
-
private
|
|
103
|
+
private fieldNameValues;
|
|
104
104
|
constructor(opts: PolymorphicStringOptions);
|
|
105
105
|
validateWithFullData(val: any, b: Builder<any>): boolean;
|
|
106
106
|
valid(val: any): boolean;
|
package/schema/field.js
CHANGED
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.UUIDListType = exports.IntegerEnumListType = exports.EnumListType = exports.DateListType = exports.TimetzListType = exports.TimeListType = exports.TimestamptzListType = exports.TimestampListType = exports.BooleanListType = exports.BigIntegerListType = exports.FloatListType = exports.IntegerListType = exports.IntListType = exports.StringListType = exports.ListField = exports.IntegerEnumType = exports.IntegerEnumField = exports.EnumType = exports.StringEnumField = exports.EnumField = exports.DateType = exports.DateField = exports.TimetzType = exports.TimeType = exports.TimeField = exports.leftPad = exports.TimestamptzType = exports.TimestampType = exports.TimestampField = exports.StringType = exports.PolymorphicStringField = exports.StringField = exports.BooleanType = exports.BooleanField = exports.FloatType = exports.FloatField = exports.BigIntegerType = exports.BigIntegerField = exports.IntegerType = exports.IntegerField = exports.NumberField = exports.UUIDType = exports.UUIDField = exports.BaseField = void 0;
|
|
27
27
|
const luxon_1 = require("luxon");
|
|
28
|
-
const camel_case_1 = require("camel-case");
|
|
29
28
|
const types_1 = require("util/types");
|
|
30
29
|
const uuid_1 = require("uuid");
|
|
31
30
|
const base_1 = require("../core/base");
|
|
@@ -33,6 +32,7 @@ const db_1 = __importStar(require("../core/db"));
|
|
|
33
32
|
const schema_1 = require("./schema");
|
|
34
33
|
const global_schema_1 = require("../core/global_schema");
|
|
35
34
|
const logger_1 = require("../core/logger");
|
|
35
|
+
const names_1 = require("../names/names");
|
|
36
36
|
class BaseField {
|
|
37
37
|
logValue(val) {
|
|
38
38
|
if (this.sensitive) {
|
|
@@ -57,6 +57,7 @@ class UUIDField extends BaseField {
|
|
|
57
57
|
const polymorphic = this.options?.polymorphic;
|
|
58
58
|
if (polymorphic) {
|
|
59
59
|
let name = "";
|
|
60
|
+
// TODO followup to https://github.com/lolopinto/ent/pull/1757
|
|
60
61
|
if (fieldName.endsWith("_id")) {
|
|
61
62
|
let idx = fieldName.indexOf("_id");
|
|
62
63
|
name = fieldName.substring(0, idx) + "_type";
|
|
@@ -328,7 +329,7 @@ class PolymorphicStringField extends StringField {
|
|
|
328
329
|
super(opts);
|
|
329
330
|
this.opts = opts;
|
|
330
331
|
if (opts.types) {
|
|
331
|
-
this.
|
|
332
|
+
this.fieldNameValues = opts.types.map((v) => (0, names_1.toFieldName)(v));
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
335
|
validateWithFullData(val, b) {
|
|
@@ -347,19 +348,19 @@ class PolymorphicStringField extends StringField {
|
|
|
347
348
|
return true;
|
|
348
349
|
}
|
|
349
350
|
valid(val) {
|
|
350
|
-
if (!this.
|
|
351
|
+
if (!this.fieldNameValues) {
|
|
351
352
|
return true;
|
|
352
353
|
}
|
|
353
|
-
let str = (0,
|
|
354
|
+
let str = (0, names_1.toFieldName)(String(val));
|
|
354
355
|
// allow different cases because it could be coming from different clients who don't have strong typing
|
|
355
|
-
return this.
|
|
356
|
+
return this.fieldNameValues.some((value) => value === str);
|
|
356
357
|
}
|
|
357
358
|
format(val) {
|
|
358
|
-
if (!this.
|
|
359
|
+
if (!this.fieldNameValues) {
|
|
359
360
|
return val;
|
|
360
361
|
}
|
|
361
|
-
const converted = (0,
|
|
362
|
-
for (const v of this.
|
|
362
|
+
const converted = (0, names_1.toFieldName)(String(val));
|
|
363
|
+
for (const v of this.fieldNameValues) {
|
|
363
364
|
if (v === val) {
|
|
364
365
|
return val;
|
|
365
366
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -270,9 +270,6 @@ export interface SchemaConstructor {
|
|
|
270
270
|
export type SchemaInputType = Schema | SchemaConstructor;
|
|
271
271
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
272
272
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
273
|
-
/**
|
|
274
|
-
* @deprecated should only be used by tests
|
|
275
|
-
*/
|
|
276
273
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
277
274
|
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
278
275
|
export declare function getFieldsWithEditPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
package/schema/schema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsForCreateAction = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
|
-
const
|
|
4
|
+
const names_1 = require("../names/names");
|
|
5
5
|
// we also want this transformation to exist on a per-action basis
|
|
6
6
|
// if it exists on an action, we don't do the global schema transformation
|
|
7
7
|
var SQLStatementOperation;
|
|
@@ -79,11 +79,8 @@ function getFields(value) {
|
|
|
79
79
|
return m;
|
|
80
80
|
}
|
|
81
81
|
exports.getFields = getFields;
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated should only be used by tests
|
|
84
|
-
*/
|
|
85
82
|
function getStorageKey(field, fieldName) {
|
|
86
|
-
return field.storageKey || (0,
|
|
83
|
+
return field.storageKey || (0, names_1.toDBColumnOrTable)(fieldName);
|
|
87
84
|
}
|
|
88
85
|
exports.getStorageKey = getStorageKey;
|
|
89
86
|
// returns a mapping of storage key to field privacy
|
package/schema/struct_field.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StructTypeAsList = exports.StructListType = exports.StructType = exports.StructField = void 0;
|
|
4
|
-
const camel_case_1 = require("camel-case");
|
|
5
4
|
const field_1 = require("./field");
|
|
6
5
|
const schema_1 = require("./schema");
|
|
7
6
|
const global_schema_1 = require("../core/global_schema");
|
|
8
7
|
const logger_1 = require("../core/logger");
|
|
8
|
+
const names_1 = require("../names/names");
|
|
9
9
|
class StructField extends field_1.BaseField {
|
|
10
10
|
constructor(options, jsonAsList) {
|
|
11
11
|
super();
|
|
@@ -40,10 +40,14 @@ class StructField extends field_1.BaseField {
|
|
|
40
40
|
const field = this.options.fields[k];
|
|
41
41
|
// check two values
|
|
42
42
|
// store in dbKey format
|
|
43
|
-
//
|
|
43
|
+
// check both fieldName and dbKey and store in dbKey for
|
|
44
|
+
// serialization to db
|
|
45
|
+
// we should only have if it in fieldName format for non-tests
|
|
46
|
+
// but checking for backwards compatibility and to make
|
|
47
|
+
// sure we don't break anything
|
|
44
48
|
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
45
|
-
let
|
|
46
|
-
let val = obj[
|
|
49
|
+
let fieldName = (0, names_1.toFieldName)(k);
|
|
50
|
+
let val = obj[fieldName];
|
|
47
51
|
if (val === undefined && obj[dbKey] !== undefined) {
|
|
48
52
|
val = obj[dbKey];
|
|
49
53
|
}
|
|
@@ -114,20 +118,19 @@ class StructField extends field_1.BaseField {
|
|
|
114
118
|
let valid = true;
|
|
115
119
|
for (const k in this.options.fields) {
|
|
116
120
|
const field = this.options.fields[k];
|
|
117
|
-
// TODO more #510
|
|
118
121
|
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
119
|
-
let
|
|
120
|
-
let val = obj[
|
|
122
|
+
let fieldName = (0, names_1.toFieldName)(k);
|
|
123
|
+
let val = obj[fieldName];
|
|
121
124
|
let uniqueKeyField = false;
|
|
122
125
|
if (this.validateUniqueKey !== undefined &&
|
|
123
|
-
(
|
|
126
|
+
(fieldName === this.validateUniqueKey ||
|
|
124
127
|
k === this.validateUniqueKey ||
|
|
125
128
|
dbKey === this.validateUniqueKey)) {
|
|
126
129
|
// this.validateUniqueKey = camelKey;
|
|
127
130
|
uniqueKeyField = true;
|
|
128
131
|
}
|
|
129
132
|
if (uniqueKeyField && this.checkUniqueKey) {
|
|
130
|
-
this.validateUniqueKey =
|
|
133
|
+
this.validateUniqueKey = fieldName;
|
|
131
134
|
}
|
|
132
135
|
if (val === undefined && obj[dbKey] !== undefined) {
|
|
133
136
|
if (uniqueKeyField && this.checkUniqueKey) {
|
package/scripts/read_schema.js
CHANGED
|
@@ -28,10 +28,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const glob = __importStar(require("glob"));
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
|
-
const pascal_case_1 = require("pascal-case");
|
|
32
31
|
const minimist_1 = __importDefault(require("minimist"));
|
|
33
32
|
const parse_1 = require("../parse_schema/parse");
|
|
34
33
|
const ast_1 = require("../tsc/ast");
|
|
34
|
+
const names_1 = require("../names/names");
|
|
35
35
|
function main() {
|
|
36
36
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
37
37
|
if (!options.path) {
|
|
@@ -70,7 +70,7 @@ function main() {
|
|
|
70
70
|
if (relativePath !== undefined) {
|
|
71
71
|
s.schemaPath = relativePath;
|
|
72
72
|
}
|
|
73
|
-
potentialSchemas[(0,
|
|
73
|
+
potentialSchemas[(0, names_1.toClassName)(schema)] = s;
|
|
74
74
|
}
|
|
75
75
|
// console.log(potentialSchemas);
|
|
76
76
|
// NB: do not change this to async/await
|
package/testutils/builder.js
CHANGED
|
@@ -10,12 +10,11 @@ const action_1 = require("../action");
|
|
|
10
10
|
const schema_1 = require("../schema");
|
|
11
11
|
const db_mock_1 = require("./db_mock");
|
|
12
12
|
const pluralize_1 = __importDefault(require("pluralize"));
|
|
13
|
-
const snake_case_1 = require("snake-case");
|
|
14
13
|
const loaders_1 = require("../core/loaders");
|
|
15
14
|
const convert_1 = require("../core/convert");
|
|
16
|
-
const camel_case_1 = require("camel-case");
|
|
17
15
|
const base_schema_1 = require("../schema/base_schema");
|
|
18
16
|
const schema_2 = require("../schema/schema");
|
|
17
|
+
const names_1 = require("../names/names");
|
|
19
18
|
class BaseEnt {
|
|
20
19
|
constructor(viewer, data) {
|
|
21
20
|
this.viewer = viewer;
|
|
@@ -157,7 +156,7 @@ function getSchemaName(value) {
|
|
|
157
156
|
}
|
|
158
157
|
exports.getSchemaName = getSchemaName;
|
|
159
158
|
function getTableName(value) {
|
|
160
|
-
return (0, pluralize_1.default)((0,
|
|
159
|
+
return (0, pluralize_1.default)((0, names_1.toDBColumnOrTable)(value.ent.name)).toLowerCase();
|
|
161
160
|
}
|
|
162
161
|
exports.getTableName = getTableName;
|
|
163
162
|
const getDbFields = (schema) => {
|
|
@@ -212,17 +211,17 @@ class SimpleBuilder {
|
|
|
212
211
|
for (const [name, f] of schemaFields) {
|
|
213
212
|
dbFields.push((0, schema_2.getStorageKey)(f, name));
|
|
214
213
|
}
|
|
215
|
-
if (!schemaFields.has("id")
|
|
214
|
+
if (!schemaFields.has("id")) {
|
|
216
215
|
if (schemaFields.size !== 1) {
|
|
217
216
|
throw new Error(`no id field and multiple fields so can't deduce key. add an id field to schema`);
|
|
218
217
|
}
|
|
219
218
|
for (const [name, _] of fields) {
|
|
220
|
-
key = (0,
|
|
219
|
+
key = (0, names_1.toDBColumnOrTable)(name);
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
222
|
this.ent = schema.ent;
|
|
224
223
|
const tableName = getTableName(schema);
|
|
225
|
-
this.nodeType = (0,
|
|
224
|
+
this.nodeType = (0, names_1.toFieldName)(schema.ent.name);
|
|
226
225
|
const fieldInfo = getFieldInfo(schema);
|
|
227
226
|
this.orchestrator = new orchestrator_1.Orchestrator({
|
|
228
227
|
viewer: this.viewer,
|
|
@@ -270,9 +269,8 @@ class SimpleBuilder {
|
|
|
270
269
|
this.fields.set(k, input[k]);
|
|
271
270
|
}
|
|
272
271
|
else {
|
|
273
|
-
//
|
|
274
|
-
|
|
275
|
-
const sc = (0, snake_case_1.snakeCase)(k);
|
|
272
|
+
// TODO: ola 2/18/2024. we may not need both anymore?
|
|
273
|
+
const sc = (0, names_1.toDBColumnOrTable)(k);
|
|
276
274
|
if (knownFields.has(sc)) {
|
|
277
275
|
this.fields.set(sc, input[k]);
|
|
278
276
|
}
|
package/testutils/db/temp_db.js
CHANGED
|
@@ -34,9 +34,9 @@ const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
|
34
34
|
const config_1 = require("../../core/config");
|
|
35
35
|
const fs = __importStar(require("fs"));
|
|
36
36
|
const schema_1 = require("../../schema");
|
|
37
|
-
const snake_case_1 = require("snake-case");
|
|
38
37
|
const builder_1 = require("../builder");
|
|
39
38
|
const test_edge_global_schema_1 = require("../test_edge_global_schema");
|
|
39
|
+
const names_1 = require("../../names/names");
|
|
40
40
|
function primaryKey(name, cols) {
|
|
41
41
|
return {
|
|
42
42
|
name: name,
|
|
@@ -790,7 +790,7 @@ function storageKey(fieldName, f) {
|
|
|
790
790
|
if (f.storageKey) {
|
|
791
791
|
return f.storageKey;
|
|
792
792
|
}
|
|
793
|
-
return (0,
|
|
793
|
+
return (0, names_1.toDBColumnOrTable)(fieldName);
|
|
794
794
|
}
|
|
795
795
|
function isSyncClient(client) {
|
|
796
796
|
return client.execSync !== undefined;
|
|
@@ -130,7 +130,7 @@ exports.FakeContactSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
|
130
130
|
lastName: (0, schema_1.StringType)(),
|
|
131
131
|
emailAddress: (0, schema_1.StringType)(),
|
|
132
132
|
userID: (0, schema_1.UUIDType)({
|
|
133
|
-
foreignKey: { schema: "User", column: "
|
|
133
|
+
foreignKey: { schema: "User", column: "id" },
|
|
134
134
|
}),
|
|
135
135
|
}, FakeContact);
|
|
136
136
|
exports.FakeContactSchemaWithDeletedAt = (0, builder_1.getBuilderSchemaFromFields)({
|
|
@@ -138,7 +138,7 @@ exports.FakeContactSchemaWithDeletedAt = (0, builder_1.getBuilderSchemaFromField
|
|
|
138
138
|
lastName: (0, schema_1.StringType)(),
|
|
139
139
|
emailAddress: (0, schema_1.StringType)(),
|
|
140
140
|
userID: (0, schema_1.UUIDType)({
|
|
141
|
-
foreignKey: { schema: "User", column: "
|
|
141
|
+
foreignKey: { schema: "User", column: "id" },
|
|
142
142
|
}),
|
|
143
143
|
}, FakeContact, {
|
|
144
144
|
patterns: [new soft_delete_1.DeletedAtPattern()],
|
|
@@ -132,7 +132,7 @@ exports.FakeEventSchema = (0, builder_1.getBuilderSchemaFromFields)({
|
|
|
132
132
|
nullable: true,
|
|
133
133
|
}),
|
|
134
134
|
userID: (0, schema_1.UUIDType)({
|
|
135
|
-
foreignKey: { schema: "User", column: "
|
|
135
|
+
foreignKey: { schema: "User", column: "id" },
|
|
136
136
|
}),
|
|
137
137
|
}, FakeEvent);
|
|
138
138
|
function getEventBuilder(viewer, input) {
|
|
@@ -4,7 +4,6 @@ exports.createAllEvents = exports.tempDBTables = exports.setupTempDB = exports.c
|
|
|
4
4
|
const jest_date_mock_1 = require("jest-date-mock");
|
|
5
5
|
const viewer_1 = require("../../core/viewer");
|
|
6
6
|
const ent_1 = require("../../core/ent");
|
|
7
|
-
const snake_case_1 = require("snake-case");
|
|
8
7
|
const write_1 = require("../write");
|
|
9
8
|
const temp_db_1 = require("../db/temp_db");
|
|
10
9
|
const _1 = require(".");
|
|
@@ -15,6 +14,7 @@ const builder_1 = require("../builder");
|
|
|
15
14
|
const action_1 = require("../../action");
|
|
16
15
|
const fake_tag_1 = require("./fake_tag");
|
|
17
16
|
const db_1 = require("../../core/db");
|
|
17
|
+
const names_1 = require("../../names/names");
|
|
18
18
|
function getContactInput(user, input) {
|
|
19
19
|
return {
|
|
20
20
|
firstName: "Jon",
|
|
@@ -190,7 +190,7 @@ async function createEdges() {
|
|
|
190
190
|
await (0, write_1.createRowForTest)({
|
|
191
191
|
tableName: "assoc_edge_config",
|
|
192
192
|
fields: {
|
|
193
|
-
edge_table: (0,
|
|
193
|
+
edge_table: (0, names_1.toDBColumnOrTable)(edge, "table"),
|
|
194
194
|
symmetric_edge: _1.SymmetricEdges.has(edge),
|
|
195
195
|
inverse_edge_type: _1.InverseEdges.get(edge) || null,
|
|
196
196
|
edge_type: edge,
|
|
@@ -206,7 +206,7 @@ async function createEdges() {
|
|
|
206
206
|
exports.createEdges = createEdges;
|
|
207
207
|
function edgeTableNames() {
|
|
208
208
|
const edges = Object.values(_1.EdgeType);
|
|
209
|
-
return edges.map((edge) => (0,
|
|
209
|
+
return edges.map((edge) => (0, names_1.toDBColumnOrTable)(edge, "table"));
|
|
210
210
|
}
|
|
211
211
|
exports.edgeTableNames = edgeTableNames;
|
|
212
212
|
async function createTestEvent(user, input) {
|
package/testutils/soft_delete.js
CHANGED
|
@@ -33,8 +33,6 @@ class DeletedAtPattern {
|
|
|
33
33
|
constructor() {
|
|
34
34
|
this.name = "deleted_at";
|
|
35
35
|
this.fields = {
|
|
36
|
-
// need this to be lowerCamelCase because we do this based on field name
|
|
37
|
-
// #510
|
|
38
36
|
deletedAt: (0, field_1.TimestampType)({
|
|
39
37
|
nullable: true,
|
|
40
38
|
index: true,
|
|
@@ -95,8 +93,6 @@ class DeletedAtPatternWithExtraWrites {
|
|
|
95
93
|
constructor() {
|
|
96
94
|
this.name = "deleted_at";
|
|
97
95
|
this.fields = {
|
|
98
|
-
// need this to be lowerCamelCase because we do this based on field name
|
|
99
|
-
// #510
|
|
100
96
|
deletedAt: (0, field_1.TimestampType)({
|
|
101
97
|
nullable: true,
|
|
102
98
|
index: true,
|
|
@@ -36,8 +36,6 @@ class EdgeWithDeletedAt extends ent_1.AssocEdge {
|
|
|
36
36
|
exports.EdgeWithDeletedAt = EdgeWithDeletedAt;
|
|
37
37
|
exports.testEdgeGlobalSchema = {
|
|
38
38
|
extraEdgeFields: {
|
|
39
|
-
// need this to be lowerCamelCase because we do this based on field name
|
|
40
|
-
// #510
|
|
41
39
|
deletedAt: (0, schema_1.TimestampType)({
|
|
42
40
|
nullable: true,
|
|
43
41
|
index: true,
|
package/tsc/transform_action.js
CHANGED
|
@@ -31,7 +31,7 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
31
31
|
const ast_1 = require("../tsc/ast");
|
|
32
32
|
const viewer_1 = require("../core/viewer");
|
|
33
33
|
const path = __importStar(require("path"));
|
|
34
|
-
const
|
|
34
|
+
const names_1 = require("../names/names");
|
|
35
35
|
// returns input and importPath
|
|
36
36
|
function getBaseFileInfo(file, classInfo, sourceFile) {
|
|
37
37
|
// @ts-ignore
|
|
@@ -155,7 +155,7 @@ class TransformAction {
|
|
|
155
155
|
klassContents += mm.getFullText(sourceFile);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
const builderPath = `src/ent/generated/${(0,
|
|
158
|
+
const builderPath = `src/ent/generated/${(0, names_1.toFilePath)(nodeName)}/actions/${(0, names_1.toFilePath)(builder)}`;
|
|
159
159
|
let imports = new Map([
|
|
160
160
|
[
|
|
161
161
|
(0, ast_1.transformRelative)(file, this.customInfo.viewerInfo.path, this.customInfo.relativeImports),
|