@snowtop/ent 0.1.0-alpha9 → 0.1.0-alpha90
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 +36 -31
- package/action/action.js +2 -6
- package/action/executor.d.ts +3 -3
- 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 +38 -16
- package/action/orchestrator.js +219 -61
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +45 -24
- package/core/base.js +7 -1
- package/core/clause.d.ts +68 -7
- package/core/clause.js +291 -62
- package/core/config.d.ts +8 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +2 -2
- package/core/db.js +1 -1
- package/core/ent.d.ts +79 -24
- package/core/ent.js +520 -168
- 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 +2 -2
- 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 +62 -58
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +47 -10
- 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 +21 -25
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_clause_query.d.ts +24 -0
- package/core/query/custom_clause_query.js +72 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +77 -10
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +1 -1
- package/core/query/query.js +8 -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 +211 -30
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.js +6 -0
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/index.d.ts +11 -5
- package/index.js +15 -6
- package/package.json +1 -1
- package/parse_schema/parse.d.ts +12 -3
- package/parse_schema/parse.js +70 -11
- package/schema/base_schema.js +3 -0
- package/schema/field.d.ts +44 -8
- package/schema/field.js +125 -9
- package/schema/index.d.ts +2 -2
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +65 -11
- package/schema/schema.js +18 -4
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +44 -5
- package/scripts/custom_graphql.js +8 -3
- 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 +15 -4
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +83 -29
- 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} +15 -3
- package/testutils/db/{test_db.js → temp_db.js} +70 -16
- package/testutils/db/value.d.ts +6 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/fake_data/fake_contact.d.ts +5 -4
- package/testutils/fake_data/fake_contact.js +14 -6
- package/testutils/fake_data/fake_event.d.ts +5 -3
- package/testutils/fake_data/fake_event.js +8 -5
- package/testutils/fake_data/fake_user.d.ts +4 -4
- package/testutils/fake_data/fake_user.js +16 -13
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +8 -6
- package/testutils/fake_data/user_query.d.ts +8 -6
- package/testutils/fake_data/user_query.js +28 -21
- 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 +29 -7
- 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 -445
package/schema/schema.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
|
|
2
|
-
import { Builder } from "../action/action";
|
|
2
|
+
import { Builder, Changeset } from "../action/action";
|
|
3
3
|
import { Clause } from "../core/clause";
|
|
4
|
+
import { AssocEdgeInput } from "../core/ent";
|
|
4
5
|
export declare type FieldMap = {
|
|
5
6
|
[key: string]: Field;
|
|
6
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
|
+
}
|
|
7
21
|
export default interface Schema {
|
|
8
22
|
fields: FieldMap | Field[];
|
|
9
23
|
tableName?: string;
|
|
@@ -54,7 +68,8 @@ export interface AssocEdgeGroup {
|
|
|
54
68
|
tableName?: string;
|
|
55
69
|
assocEdges: AssocEdge[];
|
|
56
70
|
statusEnums?: string[];
|
|
57
|
-
|
|
71
|
+
viewerBased?: boolean;
|
|
72
|
+
nullStates?: string | string[];
|
|
58
73
|
nullStateFn?: string;
|
|
59
74
|
edgeAction?: EdgeGroupAction;
|
|
60
75
|
}
|
|
@@ -62,9 +77,10 @@ export declare type Edge = AssocEdge;
|
|
|
62
77
|
export interface Pattern {
|
|
63
78
|
name: string;
|
|
64
79
|
fields: FieldMap | Field[];
|
|
80
|
+
disableMixin?: boolean;
|
|
65
81
|
edges?: Edge[];
|
|
66
82
|
transformRead?: () => Clause;
|
|
67
|
-
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> |
|
|
83
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
68
84
|
transformsDelete?: boolean;
|
|
69
85
|
transformsInsert?: boolean;
|
|
70
86
|
transformsUpdate?: boolean;
|
|
@@ -74,16 +90,25 @@ export declare enum SQLStatementOperation {
|
|
|
74
90
|
Update = "update",
|
|
75
91
|
Delete = "delete"
|
|
76
92
|
}
|
|
77
|
-
export interface
|
|
93
|
+
export interface EdgeUpdateOperation {
|
|
94
|
+
op: SQLStatementOperation;
|
|
95
|
+
edge: AssocEdgeInput;
|
|
96
|
+
}
|
|
97
|
+
export interface TransformedEdgeUpdateOperation {
|
|
78
98
|
op: SQLStatementOperation;
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
data?: Data;
|
|
100
|
+
}
|
|
101
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
102
|
+
op: SQLStatementOperation;
|
|
103
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
104
|
+
input: Data;
|
|
81
105
|
data?: Map<string, any>;
|
|
82
106
|
}
|
|
83
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
107
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
84
108
|
op: SQLStatementOperation;
|
|
85
109
|
data?: Data;
|
|
86
|
-
existingEnt?: T;
|
|
110
|
+
existingEnt?: T | null;
|
|
111
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
87
112
|
}
|
|
88
113
|
export declare enum DBType {
|
|
89
114
|
UUID = "UUID",
|
|
@@ -99,6 +124,7 @@ export declare enum DBType {
|
|
|
99
124
|
JSONB = "JSONB",
|
|
100
125
|
Enum = "Enum",
|
|
101
126
|
StringEnum = "StringEnum",
|
|
127
|
+
IntEnum = "IntEnum",
|
|
102
128
|
Date = "Date",
|
|
103
129
|
Time = "Time",
|
|
104
130
|
Timetz = "Timetz",
|
|
@@ -109,9 +135,16 @@ export interface ImportType {
|
|
|
109
135
|
type: string;
|
|
110
136
|
[x: string]: any;
|
|
111
137
|
}
|
|
138
|
+
export interface ConvertType {
|
|
139
|
+
path: string;
|
|
140
|
+
function: string;
|
|
141
|
+
}
|
|
112
142
|
declare type EnumMap = {
|
|
113
143
|
[key: string]: string;
|
|
114
144
|
};
|
|
145
|
+
declare type IntEnumMap = {
|
|
146
|
+
[key: string]: number;
|
|
147
|
+
};
|
|
115
148
|
export interface Type {
|
|
116
149
|
dbType: DBType;
|
|
117
150
|
listElemType?: Type;
|
|
@@ -119,9 +152,12 @@ export interface Type {
|
|
|
119
152
|
graphQLType?: string;
|
|
120
153
|
values?: string[];
|
|
121
154
|
enumMap?: EnumMap;
|
|
155
|
+
intEnumMap?: IntEnumMap;
|
|
156
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
122
157
|
importType?: ImportType;
|
|
123
158
|
subFields?: FieldMap;
|
|
124
159
|
unionFields?: FieldMap;
|
|
160
|
+
[x: string]: any;
|
|
125
161
|
}
|
|
126
162
|
export interface ForeignKey {
|
|
127
163
|
schema: string;
|
|
@@ -129,6 +165,7 @@ export interface ForeignKey {
|
|
|
129
165
|
name?: string;
|
|
130
166
|
disableIndex?: boolean;
|
|
131
167
|
disableBuilderType?: boolean;
|
|
168
|
+
[x: string]: any;
|
|
132
169
|
}
|
|
133
170
|
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
134
171
|
export interface InverseFieldEdge {
|
|
@@ -144,13 +181,16 @@ export interface FieldEdge {
|
|
|
144
181
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
145
182
|
disableBuilderType?: boolean;
|
|
146
183
|
}
|
|
184
|
+
interface PrivateOptions {
|
|
185
|
+
exposeToActions?: boolean;
|
|
186
|
+
}
|
|
147
187
|
export interface FieldOptions {
|
|
148
188
|
nullable?: boolean;
|
|
149
189
|
storageKey?: string;
|
|
150
190
|
serverDefault?: any;
|
|
151
191
|
unique?: boolean;
|
|
152
192
|
hideFromGraphQL?: boolean;
|
|
153
|
-
private?: boolean;
|
|
193
|
+
private?: boolean | PrivateOptions;
|
|
154
194
|
sensitive?: boolean;
|
|
155
195
|
graphqlName?: string;
|
|
156
196
|
index?: boolean;
|
|
@@ -166,9 +206,12 @@ export interface FieldOptions {
|
|
|
166
206
|
polymorphic?: boolean | PolymorphicOptions;
|
|
167
207
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
168
208
|
getDerivedFields?(name: string): FieldMap;
|
|
209
|
+
convert?: ConvertType;
|
|
210
|
+
fetchOnDemand?: boolean;
|
|
169
211
|
[x: string]: any;
|
|
170
212
|
}
|
|
171
213
|
export interface PolymorphicOptions {
|
|
214
|
+
name?: string;
|
|
172
215
|
types?: string[];
|
|
173
216
|
hideFromInverseGraphQL?: boolean;
|
|
174
217
|
disableBuilderType?: boolean;
|
|
@@ -176,6 +219,7 @@ export interface PolymorphicOptions {
|
|
|
176
219
|
export interface Field extends FieldOptions {
|
|
177
220
|
type: Type;
|
|
178
221
|
valid?(val: any): Promise<boolean> | boolean;
|
|
222
|
+
validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
|
|
179
223
|
format?(val: any, nested?: boolean): any;
|
|
180
224
|
logValue(val: any): any;
|
|
181
225
|
}
|
|
@@ -185,15 +229,18 @@ export interface SchemaConstructor {
|
|
|
185
229
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
186
230
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
187
231
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
232
|
+
/**
|
|
233
|
+
* @deprecated should only be used by tests
|
|
234
|
+
*/
|
|
188
235
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
189
|
-
export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
|
|
236
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
190
237
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
191
238
|
interface objectLoaderOptions {
|
|
192
239
|
clause?: () => Clause | undefined;
|
|
193
240
|
instanceKey?: string;
|
|
194
241
|
}
|
|
195
242
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
196
|
-
export declare function getTransformedUpdateOp<
|
|
243
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
197
244
|
export declare enum ActionOperation {
|
|
198
245
|
Create = 1,
|
|
199
246
|
Edit = 2,
|
|
@@ -212,6 +259,7 @@ export interface ActionField {
|
|
|
212
259
|
list?: boolean;
|
|
213
260
|
actionName?: string;
|
|
214
261
|
excludedFields?: string[];
|
|
262
|
+
[x: string]: any;
|
|
215
263
|
}
|
|
216
264
|
export interface Action {
|
|
217
265
|
operation: ActionOperation;
|
|
@@ -225,6 +273,7 @@ export interface Action {
|
|
|
225
273
|
optionalFields?: string[];
|
|
226
274
|
requiredFields?: string[];
|
|
227
275
|
noFields?: boolean;
|
|
276
|
+
[x: string]: any;
|
|
228
277
|
}
|
|
229
278
|
export declare const NoFields = "__NO_FIELDS__";
|
|
230
279
|
export declare function requiredField(field: string): string;
|
|
@@ -235,6 +284,7 @@ export interface Constraint {
|
|
|
235
284
|
columns: string[];
|
|
236
285
|
fkey?: ForeignKeyInfo;
|
|
237
286
|
condition?: string;
|
|
287
|
+
[x: string]: any;
|
|
238
288
|
}
|
|
239
289
|
export interface FullTextWeight {
|
|
240
290
|
A?: string[];
|
|
@@ -248,17 +298,21 @@ export interface FullText {
|
|
|
248
298
|
languageColumn?: string;
|
|
249
299
|
indexType?: "gin" | "gist";
|
|
250
300
|
weights?: FullTextWeight;
|
|
301
|
+
[x: string]: any;
|
|
251
302
|
}
|
|
252
303
|
export interface Index {
|
|
253
304
|
name: string;
|
|
254
305
|
columns: string[];
|
|
255
306
|
unique?: boolean;
|
|
256
307
|
fulltext?: FullText;
|
|
308
|
+
indexType?: "gin" | "btree";
|
|
309
|
+
[x: string]: any;
|
|
257
310
|
}
|
|
258
311
|
export interface ForeignKeyInfo {
|
|
259
312
|
tableName: string;
|
|
260
313
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
261
314
|
columns: string[];
|
|
315
|
+
[x: string]: any;
|
|
262
316
|
}
|
|
263
317
|
export declare enum ConstraintType {
|
|
264
318
|
PrimaryKey = "primary",
|
package/schema/schema.js
CHANGED
|
@@ -35,6 +35,7 @@ var DBType;
|
|
|
35
35
|
DBType["JSONB"] = "JSONB";
|
|
36
36
|
DBType["Enum"] = "Enum";
|
|
37
37
|
DBType["StringEnum"] = "StringEnum";
|
|
38
|
+
DBType["IntEnum"] = "IntEnum";
|
|
38
39
|
DBType["Date"] = "Date";
|
|
39
40
|
DBType["Time"] = "Time";
|
|
40
41
|
DBType["Timetz"] = "Timetz";
|
|
@@ -86,12 +87,15 @@ function getFields(value) {
|
|
|
86
87
|
return m;
|
|
87
88
|
}
|
|
88
89
|
exports.getFields = getFields;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated should only be used by tests
|
|
92
|
+
*/
|
|
89
93
|
function getStorageKey(field, fieldName) {
|
|
90
94
|
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
91
95
|
}
|
|
92
96
|
exports.getStorageKey = getStorageKey;
|
|
93
97
|
// returns a mapping of storage key to field privacy
|
|
94
|
-
function getFieldsWithPrivacy(value) {
|
|
98
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
95
99
|
const schema = getSchema(value);
|
|
96
100
|
function addFields(fields) {
|
|
97
101
|
if (Array.isArray(fields)) {
|
|
@@ -111,9 +115,14 @@ function getFieldsWithPrivacy(value) {
|
|
|
111
115
|
else {
|
|
112
116
|
privacyPolicy = field.privacyPolicy;
|
|
113
117
|
}
|
|
114
|
-
|
|
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);
|
|
115
123
|
}
|
|
116
124
|
}
|
|
125
|
+
return;
|
|
117
126
|
}
|
|
118
127
|
for (const name in fields) {
|
|
119
128
|
const field = fields[name];
|
|
@@ -128,7 +137,11 @@ function getFieldsWithPrivacy(value) {
|
|
|
128
137
|
else {
|
|
129
138
|
privacyPolicy = field.privacyPolicy;
|
|
130
139
|
}
|
|
131
|
-
|
|
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);
|
|
132
145
|
}
|
|
133
146
|
}
|
|
134
147
|
}
|
|
@@ -167,13 +180,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
|
167
180
|
function getTransformedUpdateOp(value, stmt) {
|
|
168
181
|
const schema = getSchema(value);
|
|
169
182
|
if (!schema.patterns) {
|
|
170
|
-
return;
|
|
183
|
+
return null;
|
|
171
184
|
}
|
|
172
185
|
for (const p of schema.patterns) {
|
|
173
186
|
if (p.transformWrite) {
|
|
174
187
|
return p.transformWrite(stmt);
|
|
175
188
|
}
|
|
176
189
|
}
|
|
190
|
+
return null;
|
|
177
191
|
}
|
|
178
192
|
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
179
193
|
// this maps to ActionOperation in ent/action.go
|
package/schema/struct_field.d.ts
CHANGED
|
@@ -6,12 +6,22 @@ export interface StructOptions extends FieldOptions {
|
|
|
6
6
|
graphQLType?: string;
|
|
7
7
|
jsonNotJSONB?: boolean;
|
|
8
8
|
}
|
|
9
|
+
interface allStructOptions extends StructOptions {
|
|
10
|
+
jsonAsList?: boolean;
|
|
11
|
+
}
|
|
9
12
|
export declare class StructField extends BaseField implements Field {
|
|
10
13
|
private options;
|
|
11
14
|
type: Type;
|
|
12
|
-
constructor(options:
|
|
15
|
+
constructor(options: allStructOptions);
|
|
16
|
+
formatImpl(obj: any, nested?: boolean): string | Object;
|
|
13
17
|
format(obj: any, nested?: boolean): string | Object;
|
|
18
|
+
private validImpl;
|
|
14
19
|
valid(obj: any): Promise<boolean>;
|
|
15
20
|
}
|
|
16
21
|
export declare function StructType(options: StructOptions): StructField & StructOptions;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated use StructTypeAsList
|
|
24
|
+
*/
|
|
17
25
|
export declare function StructListType(options: StructOptions): ListField;
|
|
26
|
+
export declare function StructTypeAsList(options: allStructOptions): StructField & allStructOptions;
|
|
27
|
+
export {};
|
package/schema/struct_field.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StructListType = exports.StructType = exports.StructField = void 0;
|
|
3
|
+
exports.StructTypeAsList = exports.StructListType = exports.StructType = exports.StructField = void 0;
|
|
4
|
+
const camel_case_1 = require("camel-case");
|
|
4
5
|
const field_1 = require("./field");
|
|
5
6
|
const schema_1 = require("./schema");
|
|
6
|
-
const camel_case_1 = require("camel-case");
|
|
7
7
|
class StructField extends field_1.BaseField {
|
|
8
8
|
constructor(options) {
|
|
9
9
|
super();
|
|
@@ -17,11 +17,16 @@ class StructField extends field_1.BaseField {
|
|
|
17
17
|
if (options.jsonNotJSONB) {
|
|
18
18
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
19
|
}
|
|
20
|
+
if (options?.jsonAsList) {
|
|
21
|
+
this.type.listElemType = {
|
|
22
|
+
dbType: schema_1.DBType.JSONB,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
// right now, we store things in the db in lowerCase format
|
|
22
27
|
// this will lead to issues if field changes.
|
|
23
28
|
// TODO: use storageKey and convert back...
|
|
24
|
-
|
|
29
|
+
formatImpl(obj, nested) {
|
|
25
30
|
if (!(obj instanceof Object)) {
|
|
26
31
|
throw new Error("valid was not called");
|
|
27
32
|
}
|
|
@@ -47,13 +52,23 @@ class StructField extends field_1.BaseField {
|
|
|
47
52
|
ret[dbKey] = val;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
55
|
+
// don't json.stringify if nested or list
|
|
51
56
|
if (nested) {
|
|
52
57
|
return ret;
|
|
53
58
|
}
|
|
54
59
|
return JSON.stringify(ret);
|
|
55
60
|
}
|
|
56
|
-
|
|
61
|
+
format(obj, nested) {
|
|
62
|
+
if (Array.isArray(obj) && this.options.jsonAsList) {
|
|
63
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
64
|
+
if (nested) {
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
return JSON.stringify(ret);
|
|
68
|
+
}
|
|
69
|
+
return this.formatImpl(obj, nested);
|
|
70
|
+
}
|
|
71
|
+
async validImpl(obj) {
|
|
57
72
|
if (!(obj instanceof Object)) {
|
|
58
73
|
return false;
|
|
59
74
|
}
|
|
@@ -89,6 +104,19 @@ class StructField extends field_1.BaseField {
|
|
|
89
104
|
const ret = await Promise.all(promises);
|
|
90
105
|
return ret.every((v) => v);
|
|
91
106
|
}
|
|
107
|
+
async valid(obj) {
|
|
108
|
+
if (this.options.jsonAsList) {
|
|
109
|
+
if (!Array.isArray(obj)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
113
|
+
return valid.every((b) => b);
|
|
114
|
+
}
|
|
115
|
+
if (!(obj instanceof Object)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return this.validImpl(obj);
|
|
119
|
+
}
|
|
92
120
|
}
|
|
93
121
|
exports.StructField = StructField;
|
|
94
122
|
function StructType(options) {
|
|
@@ -96,7 +124,18 @@ function StructType(options) {
|
|
|
96
124
|
return Object.assign(result, options);
|
|
97
125
|
}
|
|
98
126
|
exports.StructType = StructType;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated use StructTypeAsList
|
|
129
|
+
*/
|
|
99
130
|
function StructListType(options) {
|
|
100
131
|
return new field_1.ListField(StructType(options), options);
|
|
101
132
|
}
|
|
102
133
|
exports.StructListType = StructListType;
|
|
134
|
+
function StructTypeAsList(options) {
|
|
135
|
+
let result = new StructField({
|
|
136
|
+
...options,
|
|
137
|
+
jsonAsList: true,
|
|
138
|
+
});
|
|
139
|
+
return Object.assign(result, options);
|
|
140
|
+
}
|
|
141
|
+
exports.StructTypeAsList = StructTypeAsList;
|
|
@@ -26,10 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const glob_1 = __importDefault(require("glob"));
|
|
27
27
|
const json5_1 = __importDefault(require("json5"));
|
|
28
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
|
-
const graphql_1 = require("../graphql/graphql");
|
|
30
|
-
const readline = __importStar(require("readline"));
|
|
31
29
|
const path = __importStar(require("path"));
|
|
32
30
|
const fs = __importStar(require("fs"));
|
|
31
|
+
const graphql_1 = require("../graphql/graphql");
|
|
32
|
+
const readline = __importStar(require("readline"));
|
|
33
33
|
const imports_1 = require("../imports");
|
|
34
34
|
const process_1 = require("process");
|
|
35
35
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
@@ -95,6 +95,7 @@ function transformResultType(f) {
|
|
|
95
95
|
type: f.resultType,
|
|
96
96
|
tsType: graphql_1.knownAllowedNames.get(f.resultType),
|
|
97
97
|
list: f.list,
|
|
98
|
+
connection: f.connection,
|
|
98
99
|
nullable: f.nullable,
|
|
99
100
|
},
|
|
100
101
|
]
|
|
@@ -235,7 +236,11 @@ async function main() {
|
|
|
235
236
|
// if this list grows too long, need to build this into golang types and passed here
|
|
236
237
|
// TODO foreign non-scalars eventually
|
|
237
238
|
(0, graphql_1.addCustomType)({
|
|
238
|
-
importPath:
|
|
239
|
+
importPath: MODULE_PATH,
|
|
240
|
+
// for go tests...
|
|
241
|
+
// TODO need a flag that only does this for go tests
|
|
242
|
+
// breaks when running locally sometimes...
|
|
243
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
239
244
|
type: "GraphQLTime",
|
|
240
245
|
});
|
|
241
246
|
(0, graphql_1.addCustomType)({
|
|
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 minimist_1 = __importDefault(require("minimist"));
|
|
7
|
+
const transform_1 = require("../tsc/transform");
|
|
8
|
+
const transform_schema_1 = require("../tsc/transform_schema");
|
|
9
|
+
const transform_ent_1 = require("../tsc/transform_ent");
|
|
10
|
+
const move_generated_1 = require("../tsc/move_generated");
|
|
11
|
+
const transform_action_1 = require("../tsc/transform_action");
|
|
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
|
@@ -26,20 +26,28 @@ const glob_1 = __importDefault(require("glob"));
|
|
|
26
26
|
const path = __importStar(require("path"));
|
|
27
27
|
const pascal_case_1 = require("pascal-case");
|
|
28
28
|
const minimist_1 = __importDefault(require("minimist"));
|
|
29
|
-
const process_1 = require("process");
|
|
30
29
|
const parse_1 = require("../parse_schema/parse");
|
|
30
|
+
const ast_1 = require("../tsc/ast");
|
|
31
31
|
function main() {
|
|
32
32
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
33
33
|
if (!options.path) {
|
|
34
34
|
throw new Error("path required");
|
|
35
35
|
}
|
|
36
|
+
const customInfo = (0, ast_1.getCustomInfo)();
|
|
37
|
+
const globalSchemaPath = customInfo.globalSchemaPath || "__global__schema.ts";
|
|
38
|
+
let globalSchema;
|
|
36
39
|
const r = /(\w+).ts/;
|
|
40
|
+
// do we still even need this...
|
|
37
41
|
const paths = glob_1.default.sync(path.join(options.path, "*.ts"), {
|
|
38
42
|
ignore: [`\d+_read_schema.ts`],
|
|
39
43
|
});
|
|
40
44
|
let potentialSchemas = {};
|
|
41
45
|
for (const p of paths) {
|
|
42
46
|
const basename = path.basename(p);
|
|
47
|
+
if (basename === globalSchemaPath) {
|
|
48
|
+
globalSchema = require(p).default;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
43
51
|
const match = r.exec(basename);
|
|
44
52
|
if (!match) {
|
|
45
53
|
throw new Error(`non-typescript file ${p} returned by glob`);
|
|
@@ -61,13 +69,16 @@ function main() {
|
|
|
61
69
|
potentialSchemas[(0, pascal_case_1.pascalCase)(schema)] = s;
|
|
62
70
|
}
|
|
63
71
|
// console.log(potentialSchemas);
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
// NB: do not change this to async/await
|
|
73
|
+
// doing so runs it buffer limit on linux (65536 bytes) and we lose data reading in go
|
|
74
|
+
(0, parse_1.parseSchema)(potentialSchemas, globalSchema).then((result) => {
|
|
75
|
+
console.log(JSON.stringify(result));
|
|
76
|
+
});
|
|
66
77
|
}
|
|
67
78
|
try {
|
|
68
79
|
main();
|
|
69
80
|
}
|
|
70
81
|
catch (err) {
|
|
71
82
|
console.error(err);
|
|
72
|
-
|
|
83
|
+
process.exit(1);
|
|
73
84
|
}
|
package/testutils/builder.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { Ent, ID, Viewer, Data, EntConstructor } from "../core/base";
|
|
1
|
+
import { Ent, ID, Viewer, Data, EntConstructor, PrivacyPolicy } from "../core/base";
|
|
2
2
|
import { Orchestrator } from "../action/orchestrator";
|
|
3
3
|
import { Action, Builder, Changeset, WriteOperation, Validator, Trigger, Observer } from "../action";
|
|
4
4
|
import { FieldMap, Schema } from "../schema";
|
|
5
5
|
import { SchemaConfig } from "../schema/base_schema";
|
|
6
|
+
import { FieldInfoMap } from "../schema/schema";
|
|
6
7
|
export declare class User implements Ent {
|
|
7
8
|
viewer: Viewer;
|
|
8
9
|
data: Data;
|
|
9
10
|
id: ID;
|
|
10
11
|
accountID: string;
|
|
11
12
|
nodeType: string;
|
|
12
|
-
|
|
13
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
13
14
|
firstName: string;
|
|
14
15
|
constructor(viewer: Viewer, data: Data);
|
|
15
16
|
}
|
|
@@ -19,7 +20,7 @@ export declare class Event implements Ent {
|
|
|
19
20
|
id: ID;
|
|
20
21
|
accountID: string;
|
|
21
22
|
nodeType: string;
|
|
22
|
-
|
|
23
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
23
24
|
constructor(viewer: Viewer, data: Data);
|
|
24
25
|
}
|
|
25
26
|
export declare class Contact implements Ent {
|
|
@@ -28,7 +29,7 @@ export declare class Contact implements Ent {
|
|
|
28
29
|
id: ID;
|
|
29
30
|
accountID: string;
|
|
30
31
|
nodeType: string;
|
|
31
|
-
|
|
32
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
32
33
|
constructor(viewer: Viewer, data: Data);
|
|
33
34
|
}
|
|
34
35
|
export declare class Group implements Ent {
|
|
@@ -37,7 +38,7 @@ export declare class Group implements Ent {
|
|
|
37
38
|
id: ID;
|
|
38
39
|
accountID: string;
|
|
39
40
|
nodeType: string;
|
|
40
|
-
|
|
41
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
41
42
|
constructor(viewer: Viewer, data: Data);
|
|
42
43
|
}
|
|
43
44
|
export declare class Message implements Ent {
|
|
@@ -46,7 +47,7 @@ export declare class Message implements Ent {
|
|
|
46
47
|
id: ID;
|
|
47
48
|
accountID: string;
|
|
48
49
|
nodeType: string;
|
|
49
|
-
|
|
50
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
50
51
|
constructor(viewer: Viewer, data: Data);
|
|
51
52
|
}
|
|
52
53
|
export declare class Address implements Ent {
|
|
@@ -55,7 +56,7 @@ export declare class Address implements Ent {
|
|
|
55
56
|
id: ID;
|
|
56
57
|
accountID: string;
|
|
57
58
|
nodeType: string;
|
|
58
|
-
|
|
59
|
+
getPrivacyPolicy(): PrivacyPolicy<this>;
|
|
59
60
|
constructor(viewer: Viewer, data: Data);
|
|
60
61
|
}
|
|
61
62
|
export interface BuilderSchema<T extends Ent> extends Schema {
|
|
@@ -66,18 +67,26 @@ export declare function getBuilderSchemaFromFields<T extends Ent>(fields: FieldM
|
|
|
66
67
|
export declare function getBuilderSchemaTZFromFields<T extends Ent>(fields: FieldMap, ent: EntConstructor<T>): BuilderSchema<T>;
|
|
67
68
|
export declare function getSchemaName(value: BuilderSchema<Ent>): string;
|
|
68
69
|
export declare function getTableName(value: BuilderSchema<Ent>): string;
|
|
69
|
-
export declare
|
|
70
|
+
export declare function getFieldInfo(value: BuilderSchema<Ent>): FieldInfoMap;
|
|
71
|
+
declare type MaybeNull<T extends Ent> = T | null;
|
|
72
|
+
declare type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
|
|
73
|
+
export declare class SimpleBuilder<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Builder<T, Viewer, TExistingEnt> {
|
|
70
74
|
viewer: Viewer;
|
|
71
75
|
private schema;
|
|
72
76
|
operation: WriteOperation;
|
|
73
|
-
existingEnt:
|
|
74
|
-
ent: EntConstructor<T>;
|
|
77
|
+
existingEnt: TExistingEnt;
|
|
78
|
+
ent: EntConstructor<T, Viewer>;
|
|
75
79
|
placeholderID: ID;
|
|
76
|
-
orchestrator: Orchestrator<T, Data>;
|
|
80
|
+
orchestrator: Orchestrator<T, Data, Viewer, TExistingEnt>;
|
|
77
81
|
fields: Map<string, any>;
|
|
78
82
|
nodeType: string;
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
m: Map<string, any>;
|
|
84
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation, existingEnt: TExistingEnt, action?: Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> | undefined);
|
|
85
|
+
getInput(): Data;
|
|
86
|
+
updateInput(input: Data): void;
|
|
87
|
+
storeData(k: string, v: any): void;
|
|
88
|
+
getStoredData(k: string): any;
|
|
89
|
+
build(): Promise<Changeset>;
|
|
81
90
|
editedEnt(): Promise<T | null>;
|
|
82
91
|
editedEntX(): Promise<T>;
|
|
83
92
|
save(): Promise<void>;
|
|
@@ -88,20 +97,21 @@ export declare class SimpleBuilder<T extends Ent> implements Builder<T> {
|
|
|
88
97
|
interface viewerEntLoadFunc {
|
|
89
98
|
(data: Data): Viewer | Promise<Viewer>;
|
|
90
99
|
}
|
|
91
|
-
export declare class SimpleAction<T extends Ent> implements Action<T, SimpleBuilder<T>, Data> {
|
|
100
|
+
export declare class SimpleAction<T extends Ent, TExistingEnt extends TMaybleNullableEnt<T> = MaybeNull<T>> implements Action<T, SimpleBuilder<T, TExistingEnt>, Viewer, Data, TExistingEnt> {
|
|
92
101
|
viewer: Viewer;
|
|
93
102
|
private fields;
|
|
94
|
-
builder: SimpleBuilder<T>;
|
|
95
|
-
validators: Validator<SimpleBuilder<T>, Data>[];
|
|
96
|
-
triggers: Trigger<SimpleBuilder<T>, Data>[];
|
|
97
|
-
observers: Observer<SimpleBuilder<T>, Data>[];
|
|
103
|
+
builder: SimpleBuilder<T, TExistingEnt>;
|
|
98
104
|
viewerForEntLoad: viewerEntLoadFunc | undefined;
|
|
99
|
-
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation
|
|
100
|
-
|
|
105
|
+
constructor(viewer: Viewer, schema: BuilderSchema<T>, fields: Map<string, any>, operation: WriteOperation | undefined, existingEnt: TExistingEnt);
|
|
106
|
+
getTriggers(): (Trigger<T, SimpleBuilder<T>> | Array<Trigger<T, SimpleBuilder<T>>>)[];
|
|
107
|
+
getValidators(): Validator<T, SimpleBuilder<T>>[];
|
|
108
|
+
getObservers(): Observer<T, SimpleBuilder<T>>[];
|
|
109
|
+
getPrivacyPolicy(): PrivacyPolicy<Ent<Viewer<Ent<any> | null, ID | null>>, Viewer<Ent<any> | null, ID | null>>;
|
|
101
110
|
getInput(): Data;
|
|
102
|
-
changeset(): Promise<Changeset
|
|
111
|
+
changeset(): Promise<Changeset>;
|
|
103
112
|
valid(): Promise<boolean>;
|
|
104
113
|
validX(): Promise<void>;
|
|
114
|
+
validWithErrors(): Promise<Error[]>;
|
|
105
115
|
save(): Promise<T | null>;
|
|
106
116
|
saveX(): Promise<T>;
|
|
107
117
|
editedEnt(): Promise<T | null>;
|