@snowtop/ent 0.1.0-alpha10 → 0.1.0-alpha101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/action.d.ts +37 -31
- package/action/action.js +22 -7
- package/action/executor.d.ts +3 -3
- package/action/executor.js +8 -3
- package/action/experimental_action.d.ts +32 -22
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +2 -0
- package/action/index.js +7 -1
- package/action/orchestrator.d.ts +40 -16
- package/action/orchestrator.js +230 -62
- package/action/privacy.d.ts +2 -2
- package/action/relative_value.d.ts +47 -0
- package/action/relative_value.js +125 -0
- package/action/transaction.d.ts +10 -0
- package/action/transaction.js +23 -0
- package/auth/auth.d.ts +1 -1
- package/core/base.d.ts +49 -26
- package/core/base.js +7 -1
- package/core/clause.d.ts +88 -7
- package/core/clause.js +355 -63
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/context.d.ts +5 -3
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +11 -8
- package/core/db.js +20 -8
- package/core/ent.d.ts +81 -25
- package/core/ent.js +636 -193
- package/core/loaders/assoc_count_loader.d.ts +3 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -2
- package/core/loaders/assoc_edge_loader.js +8 -11
- package/core/loaders/index.d.ts +1 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/index_loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +6 -5
- package/core/loaders/object_loader.js +67 -59
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.js +5 -1
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +25 -24
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +7 -6
- package/core/query/assoc_query.js +9 -1
- package/core/query/custom_clause_query.d.ts +26 -0
- package/core/query/custom_clause_query.js +78 -0
- package/core/query/custom_query.d.ts +20 -5
- package/core/query/custom_query.js +87 -12
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +8 -4
- package/core/query/query.js +101 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +35 -45
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +469 -236
- package/core/viewer.d.ts +3 -3
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +14 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +0 -1
- package/graphql/index.js +1 -4
- package/graphql/query/connection_type.d.ts +9 -9
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/shared_assoc_test.js +1 -1
- package/graphql/query/shared_edge_connection.js +1 -19
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +12 -5
- package/index.js +20 -7
- package/package.json +17 -16
- package/parse_schema/parse.d.ts +29 -9
- package/parse_schema/parse.js +118 -11
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +5 -0
- package/schema/field.d.ts +74 -20
- package/schema/field.js +174 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +81 -18
- package/schema/schema.js +24 -17
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +57 -21
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +117 -30
- package/scripts/{transform_code.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/{transform_schema.d.ts → move_types.d.ts} +0 -0
- package/scripts/move_types.js +117 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +398 -0
- package/testutils/builder.d.ts +46 -47
- package/testutils/builder.js +108 -65
- package/testutils/db/fixture.d.ts +10 -0
- package/testutils/db/fixture.js +26 -0
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +24 -8
- package/testutils/db/{test_db.js → temp_db.js} +179 -44
- package/testutils/db/value.d.ts +7 -0
- package/testutils/db/value.js +251 -0
- package/testutils/db_mock.d.ts +16 -4
- package/testutils/db_mock.js +51 -6
- package/testutils/db_time_zone.d.ts +4 -0
- package/testutils/db_time_zone.js +41 -0
- package/testutils/ent-graphql-tests/index.d.ts +7 -1
- package/testutils/ent-graphql-tests/index.js +27 -8
- package/testutils/fake_data/const.d.ts +2 -1
- package/testutils/fake_data/const.js +3 -0
- package/testutils/fake_data/fake_contact.d.ts +7 -3
- package/testutils/fake_data/fake_contact.js +15 -8
- package/testutils/fake_data/fake_event.d.ts +5 -2
- package/testutils/fake_data/fake_event.js +9 -7
- package/testutils/fake_data/fake_tag.d.ts +36 -0
- package/testutils/fake_data/fake_tag.js +89 -0
- package/testutils/fake_data/fake_user.d.ts +7 -4
- package/testutils/fake_data/fake_user.js +18 -16
- package/testutils/fake_data/index.js +5 -1
- package/testutils/fake_data/internal.d.ts +2 -0
- package/testutils/fake_data/internal.js +7 -1
- package/testutils/fake_data/tag_query.d.ts +13 -0
- package/testutils/fake_data/tag_query.js +43 -0
- package/testutils/fake_data/test_helpers.d.ts +11 -4
- package/testutils/fake_data/test_helpers.js +28 -12
- package/testutils/fake_data/user_query.d.ts +13 -6
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +62 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +33 -7
- package/tsc/ast.d.ts +26 -2
- package/tsc/ast.js +163 -17
- package/tsc/compilerOptions.d.ts +2 -1
- package/tsc/compilerOptions.js +11 -2
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +164 -0
- package/tsc/transform.d.ts +22 -0
- package/tsc/transform.js +181 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +183 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +145 -119
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/transform_code.js +0 -114
package/schema/schema.d.ts
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
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 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
|
+
}
|
|
21
|
+
type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
|
|
22
|
+
export type FieldOverrideMap = {
|
|
23
|
+
[key: string]: FieldOverride;
|
|
24
|
+
};
|
|
7
25
|
export default interface Schema {
|
|
8
|
-
fields: FieldMap
|
|
26
|
+
fields: FieldMap;
|
|
27
|
+
fieldOverrides?: FieldOverrideMap;
|
|
9
28
|
tableName?: string;
|
|
10
29
|
patterns?: Pattern[];
|
|
11
30
|
edges?: Edge[];
|
|
@@ -54,17 +73,19 @@ export interface AssocEdgeGroup {
|
|
|
54
73
|
tableName?: string;
|
|
55
74
|
assocEdges: AssocEdge[];
|
|
56
75
|
statusEnums?: string[];
|
|
57
|
-
|
|
76
|
+
viewerBased?: boolean;
|
|
77
|
+
nullStates?: string | string[];
|
|
58
78
|
nullStateFn?: string;
|
|
59
79
|
edgeAction?: EdgeGroupAction;
|
|
60
80
|
}
|
|
61
|
-
export
|
|
81
|
+
export type Edge = AssocEdge;
|
|
62
82
|
export interface Pattern {
|
|
63
83
|
name: string;
|
|
64
|
-
fields: FieldMap
|
|
84
|
+
fields: FieldMap;
|
|
85
|
+
disableMixin?: boolean;
|
|
65
86
|
edges?: Edge[];
|
|
66
87
|
transformRead?: () => Clause;
|
|
67
|
-
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> |
|
|
88
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
68
89
|
transformsDelete?: boolean;
|
|
69
90
|
transformsInsert?: boolean;
|
|
70
91
|
transformsUpdate?: boolean;
|
|
@@ -74,16 +95,25 @@ export declare enum SQLStatementOperation {
|
|
|
74
95
|
Update = "update",
|
|
75
96
|
Delete = "delete"
|
|
76
97
|
}
|
|
77
|
-
export interface
|
|
98
|
+
export interface EdgeUpdateOperation {
|
|
99
|
+
op: SQLStatementOperation;
|
|
100
|
+
edge: AssocEdgeInput;
|
|
101
|
+
}
|
|
102
|
+
export interface TransformedEdgeUpdateOperation {
|
|
78
103
|
op: SQLStatementOperation;
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
data?: Data;
|
|
105
|
+
}
|
|
106
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
107
|
+
op: SQLStatementOperation;
|
|
108
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
109
|
+
input: Data;
|
|
81
110
|
data?: Map<string, any>;
|
|
82
111
|
}
|
|
83
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
112
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
84
113
|
op: SQLStatementOperation;
|
|
85
114
|
data?: Data;
|
|
86
|
-
existingEnt?: T;
|
|
115
|
+
existingEnt?: T | null;
|
|
116
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
87
117
|
}
|
|
88
118
|
export declare enum DBType {
|
|
89
119
|
UUID = "UUID",
|
|
@@ -99,6 +129,7 @@ export declare enum DBType {
|
|
|
99
129
|
JSONB = "JSONB",
|
|
100
130
|
Enum = "Enum",
|
|
101
131
|
StringEnum = "StringEnum",
|
|
132
|
+
IntEnum = "IntEnum",
|
|
102
133
|
Date = "Date",
|
|
103
134
|
Time = "Time",
|
|
104
135
|
Timetz = "Timetz",
|
|
@@ -109,9 +140,16 @@ export interface ImportType {
|
|
|
109
140
|
type: string;
|
|
110
141
|
[x: string]: any;
|
|
111
142
|
}
|
|
143
|
+
export interface ConvertType {
|
|
144
|
+
path: string;
|
|
145
|
+
function: string;
|
|
146
|
+
}
|
|
112
147
|
declare type EnumMap = {
|
|
113
148
|
[key: string]: string;
|
|
114
149
|
};
|
|
150
|
+
declare type IntEnumMap = {
|
|
151
|
+
[key: string]: number;
|
|
152
|
+
};
|
|
115
153
|
export interface Type {
|
|
116
154
|
dbType: DBType;
|
|
117
155
|
listElemType?: Type;
|
|
@@ -119,9 +157,13 @@ export interface Type {
|
|
|
119
157
|
graphQLType?: string;
|
|
120
158
|
values?: string[];
|
|
121
159
|
enumMap?: EnumMap;
|
|
160
|
+
intEnumMap?: IntEnumMap;
|
|
161
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
162
|
+
disableUnknownType?: boolean;
|
|
122
163
|
importType?: ImportType;
|
|
123
164
|
subFields?: FieldMap;
|
|
124
165
|
unionFields?: FieldMap;
|
|
166
|
+
[x: string]: any;
|
|
125
167
|
}
|
|
126
168
|
export interface ForeignKey {
|
|
127
169
|
schema: string;
|
|
@@ -129,8 +171,9 @@ export interface ForeignKey {
|
|
|
129
171
|
name?: string;
|
|
130
172
|
disableIndex?: boolean;
|
|
131
173
|
disableBuilderType?: boolean;
|
|
174
|
+
[x: string]: any;
|
|
132
175
|
}
|
|
133
|
-
|
|
176
|
+
type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
134
177
|
export interface InverseFieldEdge {
|
|
135
178
|
name: string;
|
|
136
179
|
edgeConstName?: string;
|
|
@@ -144,13 +187,16 @@ export interface FieldEdge {
|
|
|
144
187
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
145
188
|
disableBuilderType?: boolean;
|
|
146
189
|
}
|
|
190
|
+
interface PrivateOptions {
|
|
191
|
+
exposeToActions?: boolean;
|
|
192
|
+
}
|
|
147
193
|
export interface FieldOptions {
|
|
148
194
|
nullable?: boolean;
|
|
149
195
|
storageKey?: string;
|
|
150
196
|
serverDefault?: any;
|
|
151
197
|
unique?: boolean;
|
|
152
198
|
hideFromGraphQL?: boolean;
|
|
153
|
-
private?: boolean;
|
|
199
|
+
private?: boolean | PrivateOptions;
|
|
154
200
|
sensitive?: boolean;
|
|
155
201
|
graphqlName?: string;
|
|
156
202
|
index?: boolean;
|
|
@@ -166,34 +212,43 @@ export interface FieldOptions {
|
|
|
166
212
|
polymorphic?: boolean | PolymorphicOptions;
|
|
167
213
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
168
214
|
getDerivedFields?(name: string): FieldMap;
|
|
215
|
+
convert?: ConvertType;
|
|
216
|
+
fetchOnDemand?: boolean;
|
|
217
|
+
dbOnly?: boolean;
|
|
169
218
|
[x: string]: any;
|
|
170
219
|
}
|
|
171
220
|
export interface PolymorphicOptions {
|
|
221
|
+
name?: string;
|
|
172
222
|
types?: string[];
|
|
173
223
|
hideFromInverseGraphQL?: boolean;
|
|
174
224
|
disableBuilderType?: boolean;
|
|
225
|
+
serverDefault?: any;
|
|
175
226
|
}
|
|
176
227
|
export interface Field extends FieldOptions {
|
|
177
228
|
type: Type;
|
|
178
229
|
valid?(val: any): Promise<boolean> | boolean;
|
|
230
|
+
validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
|
|
179
231
|
format?(val: any, nested?: boolean): any;
|
|
180
232
|
logValue(val: any): any;
|
|
181
233
|
}
|
|
182
234
|
export interface SchemaConstructor {
|
|
183
235
|
new (): Schema;
|
|
184
236
|
}
|
|
185
|
-
export
|
|
237
|
+
export type SchemaInputType = Schema | SchemaConstructor;
|
|
186
238
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
187
239
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
240
|
+
/**
|
|
241
|
+
* @deprecated should only be used by tests
|
|
242
|
+
*/
|
|
188
243
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
189
|
-
export declare function getFieldsWithPrivacy(value: SchemaInputType): Map<string, PrivacyPolicy>;
|
|
244
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
190
245
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
191
246
|
interface objectLoaderOptions {
|
|
192
247
|
clause?: () => Clause | undefined;
|
|
193
248
|
instanceKey?: string;
|
|
194
249
|
}
|
|
195
250
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
196
|
-
export declare function getTransformedUpdateOp<
|
|
251
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
197
252
|
export declare enum ActionOperation {
|
|
198
253
|
Create = 1,
|
|
199
254
|
Edit = 2,
|
|
@@ -203,8 +258,8 @@ export declare enum ActionOperation {
|
|
|
203
258
|
RemoveEdge = 32,
|
|
204
259
|
EdgeGroup = 64
|
|
205
260
|
}
|
|
206
|
-
|
|
207
|
-
|
|
261
|
+
type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "Object";
|
|
262
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
208
263
|
export interface ActionField {
|
|
209
264
|
name: string;
|
|
210
265
|
type: actionFieldType;
|
|
@@ -212,6 +267,8 @@ export interface ActionField {
|
|
|
212
267
|
list?: boolean;
|
|
213
268
|
actionName?: string;
|
|
214
269
|
excludedFields?: string[];
|
|
270
|
+
hideFromGraphQL?: boolean;
|
|
271
|
+
[x: string]: any;
|
|
215
272
|
}
|
|
216
273
|
export interface Action {
|
|
217
274
|
operation: ActionOperation;
|
|
@@ -225,6 +282,7 @@ export interface Action {
|
|
|
225
282
|
optionalFields?: string[];
|
|
226
283
|
requiredFields?: string[];
|
|
227
284
|
noFields?: boolean;
|
|
285
|
+
[x: string]: any;
|
|
228
286
|
}
|
|
229
287
|
export declare const NoFields = "__NO_FIELDS__";
|
|
230
288
|
export declare function requiredField(field: string): string;
|
|
@@ -235,6 +293,7 @@ export interface Constraint {
|
|
|
235
293
|
columns: string[];
|
|
236
294
|
fkey?: ForeignKeyInfo;
|
|
237
295
|
condition?: string;
|
|
296
|
+
[x: string]: any;
|
|
238
297
|
}
|
|
239
298
|
export interface FullTextWeight {
|
|
240
299
|
A?: string[];
|
|
@@ -248,17 +307,21 @@ export interface FullText {
|
|
|
248
307
|
languageColumn?: string;
|
|
249
308
|
indexType?: "gin" | "gist";
|
|
250
309
|
weights?: FullTextWeight;
|
|
310
|
+
[x: string]: any;
|
|
251
311
|
}
|
|
252
312
|
export interface Index {
|
|
253
313
|
name: string;
|
|
254
314
|
columns: string[];
|
|
255
315
|
unique?: boolean;
|
|
256
316
|
fulltext?: FullText;
|
|
317
|
+
indexType?: "gin" | "btree";
|
|
318
|
+
[x: string]: any;
|
|
257
319
|
}
|
|
258
320
|
export interface ForeignKeyInfo {
|
|
259
321
|
tableName: string;
|
|
260
322
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
261
323
|
columns: string[];
|
|
324
|
+
[x: string]: any;
|
|
262
325
|
}
|
|
263
326
|
export declare enum ConstraintType {
|
|
264
327
|
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";
|
|
@@ -55,21 +56,11 @@ exports.getSchema = getSchema;
|
|
|
55
56
|
function getFields(value) {
|
|
56
57
|
const schema = getSchema(value);
|
|
57
58
|
function addFields(fields) {
|
|
58
|
-
if (Array.isArray(fields)) {
|
|
59
|
-
for (const field of fields) {
|
|
60
|
-
const name = field.name;
|
|
61
|
-
if (!name) {
|
|
62
|
-
throw new Error(`name required`);
|
|
63
|
-
}
|
|
64
|
-
if (field.getDerivedFields !== undefined) {
|
|
65
|
-
addFields(field.getDerivedFields(name));
|
|
66
|
-
}
|
|
67
|
-
m.set(name, field);
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
59
|
for (const name in fields) {
|
|
72
60
|
const field = fields[name];
|
|
61
|
+
if (field.dbOnly) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
73
64
|
if (field.getDerivedFields !== undefined) {
|
|
74
65
|
addFields(field.getDerivedFields(name));
|
|
75
66
|
}
|
|
@@ -86,12 +77,15 @@ function getFields(value) {
|
|
|
86
77
|
return m;
|
|
87
78
|
}
|
|
88
79
|
exports.getFields = getFields;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated should only be used by tests
|
|
82
|
+
*/
|
|
89
83
|
function getStorageKey(field, fieldName) {
|
|
90
84
|
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
91
85
|
}
|
|
92
86
|
exports.getStorageKey = getStorageKey;
|
|
93
87
|
// returns a mapping of storage key to field privacy
|
|
94
|
-
function getFieldsWithPrivacy(value) {
|
|
88
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
95
89
|
const schema = getSchema(value);
|
|
96
90
|
function addFields(fields) {
|
|
97
91
|
if (Array.isArray(fields)) {
|
|
@@ -111,9 +105,14 @@ function getFieldsWithPrivacy(value) {
|
|
|
111
105
|
else {
|
|
112
106
|
privacyPolicy = field.privacyPolicy;
|
|
113
107
|
}
|
|
114
|
-
|
|
108
|
+
const info = fieldMap[name];
|
|
109
|
+
if (!info) {
|
|
110
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
111
|
+
}
|
|
112
|
+
m.set(info.dbCol, privacyPolicy);
|
|
115
113
|
}
|
|
116
114
|
}
|
|
115
|
+
return;
|
|
117
116
|
}
|
|
118
117
|
for (const name in fields) {
|
|
119
118
|
const field = fields[name];
|
|
@@ -128,7 +127,11 @@ function getFieldsWithPrivacy(value) {
|
|
|
128
127
|
else {
|
|
129
128
|
privacyPolicy = field.privacyPolicy;
|
|
130
129
|
}
|
|
131
|
-
|
|
130
|
+
const info = fieldMap[name];
|
|
131
|
+
if (!info) {
|
|
132
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
133
|
+
}
|
|
134
|
+
m.set(info.dbCol, privacyPolicy);
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
}
|
|
@@ -167,13 +170,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
|
167
170
|
function getTransformedUpdateOp(value, stmt) {
|
|
168
171
|
const schema = getSchema(value);
|
|
169
172
|
if (!schema.patterns) {
|
|
170
|
-
return;
|
|
173
|
+
return null;
|
|
171
174
|
}
|
|
172
175
|
for (const p of schema.patterns) {
|
|
173
176
|
if (p.transformWrite) {
|
|
174
177
|
return p.transformWrite(stmt);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
180
|
+
return null;
|
|
177
181
|
}
|
|
178
182
|
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
179
183
|
// this maps to ActionOperation in ent/action.go
|
|
@@ -197,6 +201,9 @@ var ActionOperation;
|
|
|
197
201
|
// RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
|
|
198
202
|
ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
|
|
199
203
|
// EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
|
|
204
|
+
// if you want to clear this edge group e.g. any set edge with id1 and id2,
|
|
205
|
+
// you should create a custom action that takes the id as an action only field,
|
|
206
|
+
// and then calls `clearEdgeTypeInGroup` in a trigger to clear
|
|
200
207
|
ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
|
|
201
208
|
})(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
|
|
202
209
|
// sentinel that indicates an action has no fields
|
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,28 +17,31 @@ 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
|
-
|
|
22
|
-
// this will lead to issues if field changes.
|
|
23
|
-
// TODO: use storageKey and convert back...
|
|
24
|
-
format(obj, nested) {
|
|
26
|
+
formatImpl(obj, nested) {
|
|
25
27
|
if (!(obj instanceof Object)) {
|
|
26
28
|
throw new Error("valid was not called");
|
|
27
29
|
}
|
|
28
30
|
let ret = {};
|
|
29
31
|
for (const k in this.options.fields) {
|
|
32
|
+
const field = this.options.fields[k];
|
|
33
|
+
// check two values
|
|
34
|
+
// store in dbKey format
|
|
30
35
|
// TODO more #510
|
|
31
|
-
let dbKey = (0,
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
if (val === undefined && obj[
|
|
35
|
-
val = obj[
|
|
36
|
-
dbKey = k;
|
|
36
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
37
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
38
|
+
let val = obj[camelKey];
|
|
39
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
40
|
+
val = obj[dbKey];
|
|
37
41
|
}
|
|
38
42
|
if (val === undefined) {
|
|
39
43
|
continue;
|
|
40
44
|
}
|
|
41
|
-
const field = this.options.fields[k];
|
|
42
45
|
if (field.format) {
|
|
43
46
|
// indicate nested so this isn't JSON stringified
|
|
44
47
|
ret[dbKey] = field.format(val, true);
|
|
@@ -47,13 +50,23 @@ class StructField extends field_1.BaseField {
|
|
|
47
50
|
ret[dbKey] = val;
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
53
|
+
// don't json.stringify if nested or list
|
|
51
54
|
if (nested) {
|
|
52
55
|
return ret;
|
|
53
56
|
}
|
|
54
57
|
return JSON.stringify(ret);
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
format(obj, nested) {
|
|
60
|
+
if (Array.isArray(obj) && this.options.jsonAsList) {
|
|
61
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
62
|
+
if (nested) {
|
|
63
|
+
return ret;
|
|
64
|
+
}
|
|
65
|
+
return JSON.stringify(ret);
|
|
66
|
+
}
|
|
67
|
+
return this.formatImpl(obj, nested);
|
|
68
|
+
}
|
|
69
|
+
async validImpl(obj) {
|
|
57
70
|
if (!(obj instanceof Object)) {
|
|
58
71
|
return false;
|
|
59
72
|
}
|
|
@@ -63,12 +76,11 @@ class StructField extends field_1.BaseField {
|
|
|
63
76
|
for (const k in this.options.fields) {
|
|
64
77
|
const field = this.options.fields[k];
|
|
65
78
|
// TODO more #510
|
|
66
|
-
let dbKey = (0,
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
if (val === undefined && obj[
|
|
70
|
-
val = obj[
|
|
71
|
-
dbKey = k;
|
|
79
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
80
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
81
|
+
let val = obj[camelKey];
|
|
82
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
83
|
+
val = obj[dbKey];
|
|
72
84
|
}
|
|
73
85
|
if (val === undefined || val === null) {
|
|
74
86
|
// nullable, nothing to do here
|
|
@@ -89,6 +101,19 @@ class StructField extends field_1.BaseField {
|
|
|
89
101
|
const ret = await Promise.all(promises);
|
|
90
102
|
return ret.every((v) => v);
|
|
91
103
|
}
|
|
104
|
+
async valid(obj) {
|
|
105
|
+
if (this.options.jsonAsList) {
|
|
106
|
+
if (!Array.isArray(obj)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
110
|
+
return valid.every((b) => b);
|
|
111
|
+
}
|
|
112
|
+
if (!(obj instanceof Object)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return this.validImpl(obj);
|
|
116
|
+
}
|
|
92
117
|
}
|
|
93
118
|
exports.StructField = StructField;
|
|
94
119
|
function StructType(options) {
|
|
@@ -96,7 +121,18 @@ function StructType(options) {
|
|
|
96
121
|
return Object.assign(result, options);
|
|
97
122
|
}
|
|
98
123
|
exports.StructType = StructType;
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated use StructTypeAsList
|
|
126
|
+
*/
|
|
99
127
|
function StructListType(options) {
|
|
100
128
|
return new field_1.ListField(StructType(options), options);
|
|
101
129
|
}
|
|
102
130
|
exports.StructListType = StructListType;
|
|
131
|
+
function StructTypeAsList(options) {
|
|
132
|
+
let result = new StructField({
|
|
133
|
+
...options,
|
|
134
|
+
jsonAsList: true,
|
|
135
|
+
});
|
|
136
|
+
return Object.assign(result, options);
|
|
137
|
+
}
|
|
138
|
+
exports.StructTypeAsList = StructTypeAsList;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -193,7 +197,7 @@ class Compiler {
|
|
|
193
197
|
}
|
|
194
198
|
relPath = path.relative(
|
|
195
199
|
// just because of how imports work. it's relative from directory not current path
|
|
196
|
-
path.dirname(fullPath), path.join(text.
|
|
200
|
+
path.dirname(fullPath), path.join(text.substring(0, idx).replace(r, str.substring(0, strIdx)), text.substring(idx)));
|
|
197
201
|
// if file ends with "..", we've reached a case where we're trying to
|
|
198
202
|
// import something like foo/contact(.ts) from within foo/contact/bar/baz/page.ts
|
|
199
203
|
// and we're confused about it so we need to detect that case and handle it
|
|
@@ -204,7 +208,7 @@ class Compiler {
|
|
|
204
208
|
let text2 = text + ".ts";
|
|
205
209
|
relPath = path.relative(
|
|
206
210
|
// just because of how imports work. it's relative from directory not current path
|
|
207
|
-
path.dirname(fullPath), path.join(text2.
|
|
211
|
+
path.dirname(fullPath), path.join(text2.substring(0, idx).replace(r, str.substring(0, strIdx)), text2.substring(idx)));
|
|
208
212
|
}
|
|
209
213
|
}
|
|
210
214
|
if (!relPath.startsWith("..")) {
|
|
@@ -213,7 +217,7 @@ class Compiler {
|
|
|
213
217
|
// tsc removes this by default so we need to also do it
|
|
214
218
|
let tsIdx = relPath.indexOf(".ts");
|
|
215
219
|
if (tsIdx !== -1) {
|
|
216
|
-
relPath = relPath.
|
|
220
|
+
relPath = relPath.substring(0, tsIdx);
|
|
217
221
|
}
|
|
218
222
|
return relPath;
|
|
219
223
|
}
|
|
@@ -225,7 +229,7 @@ class Compiler {
|
|
|
225
229
|
let relPath = checkPath(paths, text);
|
|
226
230
|
if (relPath) {
|
|
227
231
|
// update the node...
|
|
228
|
-
return typescript_1.default.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.
|
|
232
|
+
return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
|
|
@@ -235,7 +239,7 @@ class Compiler {
|
|
|
235
239
|
let relPath = checkPath(paths, text);
|
|
236
240
|
if (relPath) {
|
|
237
241
|
// update the node...
|
|
238
|
-
return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.
|
|
242
|
+
return typescript_1.default.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.isTypeOnly);
|
|
239
243
|
}
|
|
240
244
|
}
|
|
241
245
|
}
|