@snowtop/ent 0.1.0-alpha6 → 0.1.0-alpha63
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 +26 -22
- package/core/base.js +16 -0
- package/core/clause.d.ts +65 -3
- package/core/clause.js +368 -5
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/context.js +2 -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 +35 -24
- package/core/ent.js +223 -60
- 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 +10 -5
- package/core/loaders/object_loader.js +58 -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 +25 -25
- package/core/privacy.js +3 -0
- 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 +4 -0
- 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 +18 -1
- package/index.js +21 -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 +68 -3
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +95 -2
- package/schema/schema.js +127 -5
- 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} +75 -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.js +4 -0
- 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
package/schema/schema.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
1
|
+
import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
|
+
import { Clause } from "../core/clause";
|
|
4
|
+
import { AssocEdgeInput } from "../core/ent";
|
|
3
5
|
export declare type FieldMap = {
|
|
4
6
|
[key: string]: Field;
|
|
5
7
|
};
|
|
8
|
+
interface FieldInfo {
|
|
9
|
+
dbCol: string;
|
|
10
|
+
inputKey: string;
|
|
11
|
+
}
|
|
12
|
+
export declare type FieldInfoMap = {
|
|
13
|
+
[key: string]: FieldInfo;
|
|
14
|
+
};
|
|
15
|
+
export interface GlobalSchema {
|
|
16
|
+
edges?: Edge[];
|
|
17
|
+
extraEdgeFields?: FieldMap;
|
|
18
|
+
transformEdgeRead?: () => Clause;
|
|
19
|
+
transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
|
|
20
|
+
}
|
|
6
21
|
export default interface Schema {
|
|
7
22
|
fields: FieldMap | Field[];
|
|
8
23
|
tableName?: string;
|
|
@@ -61,7 +76,37 @@ export declare type Edge = AssocEdge;
|
|
|
61
76
|
export interface Pattern {
|
|
62
77
|
name: string;
|
|
63
78
|
fields: FieldMap | Field[];
|
|
79
|
+
disableMixin?: boolean;
|
|
64
80
|
edges?: Edge[];
|
|
81
|
+
transformRead?: () => Clause;
|
|
82
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
|
|
83
|
+
transformsDelete?: boolean;
|
|
84
|
+
transformsInsert?: boolean;
|
|
85
|
+
transformsUpdate?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export declare enum SQLStatementOperation {
|
|
88
|
+
Insert = "insert",
|
|
89
|
+
Update = "update",
|
|
90
|
+
Delete = "delete"
|
|
91
|
+
}
|
|
92
|
+
export interface EdgeUpdateOperation {
|
|
93
|
+
op: SQLStatementOperation;
|
|
94
|
+
edge: AssocEdgeInput;
|
|
95
|
+
}
|
|
96
|
+
export interface TransformedEdgeUpdateOperation {
|
|
97
|
+
op: SQLStatementOperation;
|
|
98
|
+
data?: Data;
|
|
99
|
+
}
|
|
100
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
101
|
+
op: SQLStatementOperation;
|
|
102
|
+
builder: Builder<TEnt, TViewer>;
|
|
103
|
+
input: Data;
|
|
104
|
+
data?: Map<string, any>;
|
|
105
|
+
}
|
|
106
|
+
export interface TransformedUpdateOperation<T extends Ent> {
|
|
107
|
+
op: SQLStatementOperation;
|
|
108
|
+
data?: Data;
|
|
109
|
+
existingEnt?: T | null;
|
|
65
110
|
}
|
|
66
111
|
export declare enum DBType {
|
|
67
112
|
UUID = "UUID",
|
|
@@ -77,6 +122,7 @@ export declare enum DBType {
|
|
|
77
122
|
JSONB = "JSONB",
|
|
78
123
|
Enum = "Enum",
|
|
79
124
|
StringEnum = "StringEnum",
|
|
125
|
+
IntEnum = "IntEnum",
|
|
80
126
|
Date = "Date",
|
|
81
127
|
Time = "Time",
|
|
82
128
|
Timetz = "Timetz",
|
|
@@ -85,10 +131,14 @@ export declare enum DBType {
|
|
|
85
131
|
export interface ImportType {
|
|
86
132
|
path: string;
|
|
87
133
|
type: string;
|
|
134
|
+
[x: string]: any;
|
|
88
135
|
}
|
|
89
136
|
declare type EnumMap = {
|
|
90
137
|
[key: string]: string;
|
|
91
138
|
};
|
|
139
|
+
declare type IntEnumMap = {
|
|
140
|
+
[key: string]: number;
|
|
141
|
+
};
|
|
92
142
|
export interface Type {
|
|
93
143
|
dbType: DBType;
|
|
94
144
|
listElemType?: Type;
|
|
@@ -96,9 +146,12 @@ export interface Type {
|
|
|
96
146
|
graphQLType?: string;
|
|
97
147
|
values?: string[];
|
|
98
148
|
enumMap?: EnumMap;
|
|
149
|
+
intEnumMap?: IntEnumMap;
|
|
150
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
99
151
|
importType?: ImportType;
|
|
100
152
|
subFields?: FieldMap;
|
|
101
153
|
unionFields?: FieldMap;
|
|
154
|
+
[x: string]: any;
|
|
102
155
|
}
|
|
103
156
|
export interface ForeignKey {
|
|
104
157
|
schema: string;
|
|
@@ -106,6 +159,7 @@ export interface ForeignKey {
|
|
|
106
159
|
name?: string;
|
|
107
160
|
disableIndex?: boolean;
|
|
108
161
|
disableBuilderType?: boolean;
|
|
162
|
+
[x: string]: any;
|
|
109
163
|
}
|
|
110
164
|
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
111
165
|
export interface InverseFieldEdge {
|
|
@@ -121,13 +175,16 @@ export interface FieldEdge {
|
|
|
121
175
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
122
176
|
disableBuilderType?: boolean;
|
|
123
177
|
}
|
|
178
|
+
interface PrivateOptions {
|
|
179
|
+
exposeToActions?: boolean;
|
|
180
|
+
}
|
|
124
181
|
export interface FieldOptions {
|
|
125
182
|
nullable?: boolean;
|
|
126
183
|
storageKey?: string;
|
|
127
184
|
serverDefault?: any;
|
|
128
185
|
unique?: boolean;
|
|
129
186
|
hideFromGraphQL?: boolean;
|
|
130
|
-
private?: boolean;
|
|
187
|
+
private?: boolean | PrivateOptions;
|
|
131
188
|
sensitive?: boolean;
|
|
132
189
|
graphqlName?: string;
|
|
133
190
|
index?: boolean;
|
|
@@ -135,11 +192,13 @@ export interface FieldOptions {
|
|
|
135
192
|
fieldEdge?: FieldEdge;
|
|
136
193
|
primaryKey?: boolean;
|
|
137
194
|
disableUserEditable?: boolean;
|
|
195
|
+
disableUserGraphQLEditable?: boolean;
|
|
138
196
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
139
197
|
defaultToViewerOnCreate?: boolean;
|
|
140
198
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
141
199
|
derivedWhenEmbedded?: boolean;
|
|
142
200
|
polymorphic?: boolean | PolymorphicOptions;
|
|
201
|
+
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
143
202
|
getDerivedFields?(name: string): FieldMap;
|
|
144
203
|
[x: string]: any;
|
|
145
204
|
}
|
|
@@ -158,7 +217,20 @@ export interface SchemaConstructor {
|
|
|
158
217
|
new (): Schema;
|
|
159
218
|
}
|
|
160
219
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
220
|
+
export declare function getSchema(value: SchemaInputType): Schema;
|
|
161
221
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
222
|
+
/**
|
|
223
|
+
* @deprecated should only be used by tests
|
|
224
|
+
*/
|
|
225
|
+
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
226
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
227
|
+
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
228
|
+
interface objectLoaderOptions {
|
|
229
|
+
clause?: () => Clause | undefined;
|
|
230
|
+
instanceKey?: string;
|
|
231
|
+
}
|
|
232
|
+
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
233
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
162
234
|
export declare enum ActionOperation {
|
|
163
235
|
Create = 1,
|
|
164
236
|
Edit = 2,
|
|
@@ -177,6 +249,7 @@ export interface ActionField {
|
|
|
177
249
|
list?: boolean;
|
|
178
250
|
actionName?: string;
|
|
179
251
|
excludedFields?: string[];
|
|
252
|
+
[x: string]: any;
|
|
180
253
|
}
|
|
181
254
|
export interface Action {
|
|
182
255
|
operation: ActionOperation;
|
|
@@ -190,6 +263,7 @@ export interface Action {
|
|
|
190
263
|
optionalFields?: string[];
|
|
191
264
|
requiredFields?: string[];
|
|
192
265
|
noFields?: boolean;
|
|
266
|
+
[x: string]: any;
|
|
193
267
|
}
|
|
194
268
|
export declare const NoFields = "__NO_FIELDS__";
|
|
195
269
|
export declare function requiredField(field: string): string;
|
|
@@ -200,16 +274,35 @@ export interface Constraint {
|
|
|
200
274
|
columns: string[];
|
|
201
275
|
fkey?: ForeignKeyInfo;
|
|
202
276
|
condition?: string;
|
|
277
|
+
[x: string]: any;
|
|
278
|
+
}
|
|
279
|
+
export interface FullTextWeight {
|
|
280
|
+
A?: string[];
|
|
281
|
+
B?: string[];
|
|
282
|
+
C?: string[];
|
|
283
|
+
D?: string[];
|
|
284
|
+
}
|
|
285
|
+
export interface FullText {
|
|
286
|
+
generatedColumnName?: string;
|
|
287
|
+
language?: "english" | "french" | "german" | "simple";
|
|
288
|
+
languageColumn?: string;
|
|
289
|
+
indexType?: "gin" | "gist";
|
|
290
|
+
weights?: FullTextWeight;
|
|
291
|
+
[x: string]: any;
|
|
203
292
|
}
|
|
204
293
|
export interface Index {
|
|
205
294
|
name: string;
|
|
206
295
|
columns: string[];
|
|
207
296
|
unique?: boolean;
|
|
297
|
+
fulltext?: FullText;
|
|
298
|
+
indexType?: "gin" | "btree";
|
|
299
|
+
[x: string]: any;
|
|
208
300
|
}
|
|
209
301
|
export interface ForeignKeyInfo {
|
|
210
302
|
tableName: string;
|
|
211
303
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
212
304
|
columns: string[];
|
|
305
|
+
[x: string]: any;
|
|
213
306
|
}
|
|
214
307
|
export declare enum ConstraintType {
|
|
215
308
|
PrimaryKey = "primary",
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
|
+
const snake_case_1 = require("snake-case");
|
|
5
|
+
// we also want this transformation to exist on a per-action basis
|
|
6
|
+
// if it exists on an action, we don't do the global schema transformation
|
|
7
|
+
var SQLStatementOperation;
|
|
8
|
+
(function (SQLStatementOperation) {
|
|
9
|
+
// transform insert e.g. to an update based on whatever logic
|
|
10
|
+
SQLStatementOperation["Insert"] = "insert";
|
|
11
|
+
// // transform select e.g. deleted_at. can't change from select to different query type
|
|
12
|
+
// // but can change the query
|
|
13
|
+
// Select = "select",
|
|
14
|
+
// e.g. change updated value
|
|
15
|
+
SQLStatementOperation["Update"] = "update";
|
|
16
|
+
// delete -> update theoretically e.g. deleted_at
|
|
17
|
+
SQLStatementOperation["Delete"] = "delete";
|
|
18
|
+
})(SQLStatementOperation = exports.SQLStatementOperation || (exports.SQLStatementOperation = {}));
|
|
4
19
|
// we want --strictNullChecks flag so nullable is used to type graphql, ts, db
|
|
5
20
|
// should eventually generate (boolean | null) etc
|
|
6
21
|
// supported db types
|
|
@@ -20,6 +35,7 @@ var DBType;
|
|
|
20
35
|
DBType["JSONB"] = "JSONB";
|
|
21
36
|
DBType["Enum"] = "Enum";
|
|
22
37
|
DBType["StringEnum"] = "StringEnum";
|
|
38
|
+
DBType["IntEnum"] = "IntEnum";
|
|
23
39
|
DBType["Date"] = "Date";
|
|
24
40
|
DBType["Time"] = "Time";
|
|
25
41
|
DBType["Timetz"] = "Timetz";
|
|
@@ -28,14 +44,17 @@ var DBType;
|
|
|
28
44
|
function isSchema(value) {
|
|
29
45
|
return value.fields !== undefined;
|
|
30
46
|
}
|
|
31
|
-
function
|
|
32
|
-
let schema;
|
|
47
|
+
function getSchema(value) {
|
|
33
48
|
if (isSchema(value)) {
|
|
34
|
-
|
|
49
|
+
return value;
|
|
35
50
|
}
|
|
36
51
|
else {
|
|
37
|
-
|
|
52
|
+
return new value();
|
|
38
53
|
}
|
|
54
|
+
}
|
|
55
|
+
exports.getSchema = getSchema;
|
|
56
|
+
function getFields(value) {
|
|
57
|
+
const schema = getSchema(value);
|
|
39
58
|
function addFields(fields) {
|
|
40
59
|
if (Array.isArray(fields)) {
|
|
41
60
|
for (const field of fields) {
|
|
@@ -68,6 +87,109 @@ function getFields(value) {
|
|
|
68
87
|
return m;
|
|
69
88
|
}
|
|
70
89
|
exports.getFields = getFields;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated should only be used by tests
|
|
92
|
+
*/
|
|
93
|
+
function getStorageKey(field, fieldName) {
|
|
94
|
+
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
95
|
+
}
|
|
96
|
+
exports.getStorageKey = getStorageKey;
|
|
97
|
+
// returns a mapping of storage key to field privacy
|
|
98
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
99
|
+
const schema = getSchema(value);
|
|
100
|
+
function addFields(fields) {
|
|
101
|
+
if (Array.isArray(fields)) {
|
|
102
|
+
for (const field of fields) {
|
|
103
|
+
const name = field.name;
|
|
104
|
+
if (!field.name) {
|
|
105
|
+
throw new Error(`name required`);
|
|
106
|
+
}
|
|
107
|
+
if (field.getDerivedFields !== undefined) {
|
|
108
|
+
addFields(field.getDerivedFields(name));
|
|
109
|
+
}
|
|
110
|
+
if (field.privacyPolicy) {
|
|
111
|
+
let privacyPolicy;
|
|
112
|
+
if (typeof field.privacyPolicy === "function") {
|
|
113
|
+
privacyPolicy = field.privacyPolicy();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
privacyPolicy = field.privacyPolicy;
|
|
117
|
+
}
|
|
118
|
+
const info = fieldMap[name];
|
|
119
|
+
if (!info) {
|
|
120
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
121
|
+
}
|
|
122
|
+
m.set(info.dbCol, privacyPolicy);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (const name in fields) {
|
|
128
|
+
const field = fields[name];
|
|
129
|
+
if (field.getDerivedFields !== undefined) {
|
|
130
|
+
addFields(field.getDerivedFields(name));
|
|
131
|
+
}
|
|
132
|
+
if (field.privacyPolicy) {
|
|
133
|
+
let privacyPolicy;
|
|
134
|
+
if (typeof field.privacyPolicy === "function") {
|
|
135
|
+
privacyPolicy = field.privacyPolicy();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
privacyPolicy = field.privacyPolicy;
|
|
139
|
+
}
|
|
140
|
+
const info = fieldMap[name];
|
|
141
|
+
if (!info) {
|
|
142
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
143
|
+
}
|
|
144
|
+
m.set(info.dbCol, privacyPolicy);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let m = new Map();
|
|
149
|
+
if (schema.patterns) {
|
|
150
|
+
for (const pattern of schema.patterns) {
|
|
151
|
+
addFields(pattern.fields);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
addFields(schema.fields);
|
|
155
|
+
return m;
|
|
156
|
+
}
|
|
157
|
+
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
158
|
+
function getTransformedReadClause(value) {
|
|
159
|
+
const schema = getSchema(value);
|
|
160
|
+
if (!schema.patterns) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
for (const p of schema.patterns) {
|
|
164
|
+
// e.g. discarded_at, deleted_at, etc
|
|
165
|
+
if (p.transformRead) {
|
|
166
|
+
// return clause.Eq('deleted_at', null);
|
|
167
|
+
return p.transformRead();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
exports.getTransformedReadClause = getTransformedReadClause;
|
|
173
|
+
function getObjectLoaderProperties(value, tableName) {
|
|
174
|
+
return {
|
|
175
|
+
clause: () => getTransformedReadClause(value),
|
|
176
|
+
instanceKey: `${tableName}:transformedReadClause`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
180
|
+
function getTransformedUpdateOp(value, stmt) {
|
|
181
|
+
const schema = getSchema(value);
|
|
182
|
+
if (!schema.patterns) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
for (const p of schema.patterns) {
|
|
186
|
+
if (p.transformWrite) {
|
|
187
|
+
return p.transformWrite(stmt);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
71
193
|
// this maps to ActionOperation in ent/action.go
|
|
72
194
|
var ActionOperation;
|
|
73
195
|
(function (ActionOperation) {
|
|
@@ -24,6 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const glob_1 = __importDefault(require("glob"));
|
|
27
|
+
const json5_1 = __importDefault(require("json5"));
|
|
27
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
28
29
|
const graphql_1 = require("../graphql/graphql");
|
|
29
30
|
const readline = __importStar(require("readline"));
|
|
@@ -53,7 +54,103 @@ async function readInputs() {
|
|
|
53
54
|
});
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
function processCustomObjects(l, gqlCapture, input) {
|
|
58
|
+
let m;
|
|
59
|
+
if (input) {
|
|
60
|
+
m = gqlCapture.getCustomInputObjects();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
m = gqlCapture.getCustomObjects();
|
|
64
|
+
}
|
|
65
|
+
for (const input of l) {
|
|
66
|
+
m.set(input.name, {
|
|
67
|
+
nodeName: input.graphQLName || input.name,
|
|
68
|
+
className: input.name,
|
|
69
|
+
});
|
|
70
|
+
if (input.fields) {
|
|
71
|
+
processCustomFields(input.fields, gqlCapture, input.name);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function transformArgs(f) {
|
|
76
|
+
return (f.args || []).map((v) => {
|
|
77
|
+
const ret = {
|
|
78
|
+
...v,
|
|
79
|
+
};
|
|
80
|
+
// duplicated from getType in graphql.ts
|
|
81
|
+
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
82
|
+
ret.type = v.type.type;
|
|
83
|
+
(0, graphql_1.addCustomType)(v.type);
|
|
84
|
+
}
|
|
85
|
+
// scalar types not supported for now
|
|
86
|
+
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
87
|
+
return ret;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function transformResultType(f) {
|
|
91
|
+
return f.resultType
|
|
92
|
+
? [
|
|
93
|
+
{
|
|
94
|
+
name: "",
|
|
95
|
+
type: f.resultType,
|
|
96
|
+
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
|
+
list: f.list,
|
|
98
|
+
nullable: f.nullable,
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
: [];
|
|
102
|
+
}
|
|
103
|
+
function processTopLevel(l, l2) {
|
|
104
|
+
for (const custom of l) {
|
|
105
|
+
l2.push({
|
|
106
|
+
nodeName: custom.class,
|
|
107
|
+
functionName: custom.functionName || custom.name,
|
|
108
|
+
gqlName: custom.graphQLName || custom.name,
|
|
109
|
+
fieldType: custom.fieldType,
|
|
110
|
+
args: transformArgs(custom),
|
|
111
|
+
results: transformResultType(custom),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function processCustomFields(fields, gqlCapture, nodeName) {
|
|
116
|
+
const m = gqlCapture.getCustomFields();
|
|
117
|
+
let results = [];
|
|
118
|
+
for (const f of fields) {
|
|
119
|
+
results.push({
|
|
120
|
+
nodeName: nodeName,
|
|
121
|
+
gqlName: f.graphQLName || f.name,
|
|
122
|
+
functionName: f.functionName || f.name,
|
|
123
|
+
fieldType: f.fieldType,
|
|
124
|
+
args: transformArgs(f),
|
|
125
|
+
results: transformResultType(f),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
m.set(nodeName, results);
|
|
129
|
+
}
|
|
130
|
+
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
131
|
+
if (jsonPath !== undefined) {
|
|
132
|
+
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
133
|
+
encoding: "utf8",
|
|
134
|
+
}));
|
|
135
|
+
if (json.fields) {
|
|
136
|
+
for (const k in json.fields) {
|
|
137
|
+
processCustomFields(json.fields[k], gqlCapture, k);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (json.inputs) {
|
|
141
|
+
processCustomObjects(json.inputs, gqlCapture, true);
|
|
142
|
+
}
|
|
143
|
+
if (json.objects) {
|
|
144
|
+
processCustomObjects(json.objects, gqlCapture);
|
|
145
|
+
}
|
|
146
|
+
if (json.queries) {
|
|
147
|
+
processTopLevel(json.queries, gqlCapture.getCustomQueries());
|
|
148
|
+
}
|
|
149
|
+
if (json.mutations) {
|
|
150
|
+
processTopLevel(json.mutations, gqlCapture.getCustomMutations());
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
57
154
|
if (filesCsv !== undefined) {
|
|
58
155
|
let files = filesCsv.split(",");
|
|
59
156
|
for (let i = 0; i < files.length; i++) {
|
|
@@ -138,7 +235,11 @@ async function main() {
|
|
|
138
235
|
// if this list grows too long, need to build this into golang types and passed here
|
|
139
236
|
// TODO foreign non-scalars eventually
|
|
140
237
|
(0, graphql_1.addCustomType)({
|
|
141
|
-
importPath:
|
|
238
|
+
importPath: MODULE_PATH,
|
|
239
|
+
// for go tests...
|
|
240
|
+
// TODO need a flag that only does this for go tests
|
|
241
|
+
// breaks when running locally sometimes...
|
|
242
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
142
243
|
type: "GraphQLTime",
|
|
143
244
|
});
|
|
144
245
|
(0, graphql_1.addCustomType)({
|
|
@@ -153,15 +254,25 @@ async function main() {
|
|
|
153
254
|
if (!gqlPath) {
|
|
154
255
|
throw new Error("could not find graphql path");
|
|
155
256
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
257
|
+
// use different variable so that we use the correct GQLCapture as needed
|
|
258
|
+
// for local dev, get the one from the file system. otherwise, get the one
|
|
259
|
+
// from node_modules
|
|
260
|
+
let gqlCapture;
|
|
261
|
+
if (process.env.LOCAL_SCRIPT_PATH) {
|
|
262
|
+
const r = require("../graphql/graphql");
|
|
263
|
+
gqlCapture = r.GQLCapture;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const r = require(gqlPath);
|
|
267
|
+
if (!r.GQLCapture) {
|
|
268
|
+
throw new Error("could not find GQLCapture in module");
|
|
269
|
+
}
|
|
270
|
+
gqlCapture = r.GQLCapture;
|
|
271
|
+
gqlCapture.enable(true);
|
|
159
272
|
}
|
|
160
|
-
const GQLCapture = r.GQLCapture;
|
|
161
|
-
GQLCapture.enable(true);
|
|
162
273
|
const [inputsRead, _, imports] = await Promise.all([
|
|
163
274
|
readInputs(),
|
|
164
|
-
captureCustom(options.path, options.files),
|
|
275
|
+
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
165
276
|
parseImports(options.path),
|
|
166
277
|
]);
|
|
167
278
|
const { nodes, nodesMap } = inputsRead;
|
|
@@ -172,14 +283,14 @@ async function main() {
|
|
|
172
283
|
}
|
|
173
284
|
return result;
|
|
174
285
|
}
|
|
175
|
-
|
|
176
|
-
let args = fromMap(
|
|
177
|
-
let inputs = fromMap(
|
|
178
|
-
let fields =
|
|
179
|
-
let queries =
|
|
180
|
-
let mutations =
|
|
181
|
-
let objects = fromMap(
|
|
182
|
-
let customTypes = fromMap(
|
|
286
|
+
gqlCapture.resolve(nodes);
|
|
287
|
+
let args = fromMap(gqlCapture.getCustomArgs());
|
|
288
|
+
let inputs = fromMap(gqlCapture.getCustomInputObjects());
|
|
289
|
+
let fields = gqlCapture.getProcessedCustomFields();
|
|
290
|
+
let queries = gqlCapture.getProcessedCustomQueries();
|
|
291
|
+
let mutations = gqlCapture.getProcessedCustomMutations();
|
|
292
|
+
let objects = fromMap(gqlCapture.getCustomObjects());
|
|
293
|
+
let customTypes = fromMap(gqlCapture.getCustomTypes());
|
|
183
294
|
let classes = {};
|
|
184
295
|
let allFiles = {};
|
|
185
296
|
const buildClasses2 = (args) => {
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const transform_1 = require("../tsc/transform");
|
|
7
|
+
const transform_schema_1 = require("../tsc/transform_schema");
|
|
8
|
+
const transform_ent_1 = require("../tsc/transform_ent");
|
|
9
|
+
const move_generated_1 = require("../tsc/move_generated");
|
|
10
|
+
const transform_action_1 = require("../tsc/transform_action");
|
|
11
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
12
|
+
const ast_1 = require("../tsc/ast");
|
|
13
|
+
// todo-sqlite
|
|
14
|
+
// ts-node-script --swc --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/migrate_v0.1.ts --transform_schema --old_base_class BaseEntTodoSchema --new_schema_class TodoEntSchema --transform_path src/schema/patterns/base
|
|
15
|
+
function main() {
|
|
16
|
+
const customInfo = (0, ast_1.getCustomInfo)();
|
|
17
|
+
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
18
|
+
// install 0.1.x dependencies
|
|
19
|
+
// maybe provide options to make this easier if someone wants to do this in steps to see what's happening
|
|
20
|
+
if (options.move_generated) {
|
|
21
|
+
(0, move_generated_1.moveGenerated)(customInfo.relativeImports);
|
|
22
|
+
}
|
|
23
|
+
// codegen write-all --disable-custom-graphql
|
|
24
|
+
if (options.transform_schema) {
|
|
25
|
+
(0, transform_1.transform)(new transform_schema_1.TransformSchema(customInfo.relativeImports, options.old_base_class, options.new_schema_class, options.transform_path));
|
|
26
|
+
}
|
|
27
|
+
// codegen write-all --disable-custom-graphql
|
|
28
|
+
if (options.transform_ent) {
|
|
29
|
+
(0, transform_1.transform)(new transform_ent_1.TransformEnt());
|
|
30
|
+
}
|
|
31
|
+
if (options.transform_action) {
|
|
32
|
+
(0, transform_1.transform)(new transform_action_1.TransformAction(customInfo));
|
|
33
|
+
}
|
|
34
|
+
// codegen write-all
|
|
35
|
+
}
|
|
36
|
+
main();
|
package/scripts/read_schema.js
CHANGED
|
@@ -28,26 +28,49 @@ const pascal_case_1 = require("pascal-case");
|
|
|
28
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
29
|
const process_1 = require("process");
|
|
30
30
|
const parse_1 = require("../parse_schema/parse");
|
|
31
|
+
const ast_1 = require("../tsc/ast");
|
|
31
32
|
function main() {
|
|
32
33
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
33
34
|
if (!options.path) {
|
|
34
35
|
throw new Error("path required");
|
|
35
36
|
}
|
|
37
|
+
const customInfo = (0, ast_1.getCustomInfo)();
|
|
38
|
+
const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
|
|
39
|
+
let globalSchema;
|
|
36
40
|
const r = /(\w+).ts/;
|
|
41
|
+
// do we still even need this...
|
|
37
42
|
const paths = glob_1.default.sync(path.join(options.path, "*.ts"), {
|
|
38
43
|
ignore: [`\d+_read_schema.ts`],
|
|
39
44
|
});
|
|
40
45
|
let potentialSchemas = {};
|
|
41
46
|
for (const p of paths) {
|
|
42
47
|
const basename = path.basename(p);
|
|
48
|
+
if (basename === globalSchemaPath) {
|
|
49
|
+
globalSchema = require(p).default;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
43
52
|
const match = r.exec(basename);
|
|
44
53
|
if (!match) {
|
|
45
54
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
46
55
|
}
|
|
47
|
-
|
|
56
|
+
let schema = match[1];
|
|
57
|
+
// convert foo_schema.ts -> foo
|
|
58
|
+
if (schema.endsWith("_schema")) {
|
|
59
|
+
schema = schema.slice(0, -7);
|
|
60
|
+
}
|
|
61
|
+
let relativePath;
|
|
62
|
+
const index = p.indexOf("src/schema");
|
|
63
|
+
if (index !== -1) {
|
|
64
|
+
relativePath = p.substring(index);
|
|
65
|
+
}
|
|
66
|
+
const s = require(p).default;
|
|
67
|
+
if (relativePath !== undefined) {
|
|
68
|
+
s.schemaPath = relativePath;
|
|
69
|
+
}
|
|
70
|
+
potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
|
|
48
71
|
}
|
|
49
72
|
// console.log(potentialSchemas);
|
|
50
|
-
const result = (0, parse_1.parseSchema)(potentialSchemas);
|
|
73
|
+
const result = (0, parse_1.parseSchema)(potentialSchemas, globalSchema);
|
|
51
74
|
console.log(JSON.stringify(result));
|
|
52
75
|
}
|
|
53
76
|
try {
|