@snowtop/ent 0.1.0-alpha12 → 0.1.0-alpha120
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 +33 -14
- package/action/orchestrator.js +251 -54
- 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 +60 -37
- package/core/base.js +7 -1
- package/core/clause.d.ts +84 -40
- package/core/clause.js +358 -64
- package/core/config.d.ts +12 -1
- package/core/config.js +7 -1
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +6 -4
- 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 +86 -30
- package/core/ent.js +641 -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 +3 -3
- package/core/loaders/loader.d.ts +2 -2
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -10
- package/core/loaders/object_loader.js +70 -60
- package/core/loaders/query_loader.d.ts +7 -13
- 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 +27 -0
- package/core/query/custom_clause_query.js +84 -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 +15 -7
- package/graphql/graphql.js +23 -7
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +3 -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/graphql/scalars/orderby_direction.d.ts +2 -0
- package/graphql/scalars/orderby_direction.js +15 -0
- 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 +30 -9
- package/parse_schema/parse.js +145 -12
- package/schema/base_schema.d.ts +5 -3
- package/schema/base_schema.js +6 -0
- package/schema/field.d.ts +75 -20
- package/schema/field.js +175 -69
- package/schema/index.d.ts +2 -2
- package/schema/index.js +5 -1
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +87 -20
- package/schema/schema.js +13 -14
- 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 +124 -31
- package/scripts/migrate_v0.1.js +36 -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 +43 -47
- package/testutils/builder.js +76 -49
- 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} +182 -45
- 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 +52 -23
- 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 +8 -4
- 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 +10 -7
- 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 +25 -2
- package/tsc/ast.js +141 -17
- package/tsc/compilerOptions.js +5 -1
- 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 +60 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/{scripts → tsc}/transform_schema.js +146 -117
- package/graphql/enums.d.ts +0 -3
- package/graphql/enums.js +0 -25
- package/scripts/move_generated.js +0 -142
- package/scripts/transform_code.js +0 -113
- package/scripts/transform_schema.d.ts +0 -1
- /package/scripts/{move_generated.d.ts → migrate_v0.1.d.ts} +0 -0
- /package/scripts/{transform_code.d.ts → move_types.d.ts} +0 -0
package/schema/schema.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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,11 +9,22 @@ interface FieldInfo {
|
|
|
8
9
|
dbCol: string;
|
|
9
10
|
inputKey: string;
|
|
10
11
|
}
|
|
11
|
-
export
|
|
12
|
+
export type FieldInfoMap = {
|
|
12
13
|
[key: string]: FieldInfo;
|
|
13
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
|
+
};
|
|
14
25
|
export default interface Schema {
|
|
15
|
-
fields: FieldMap
|
|
26
|
+
fields: FieldMap;
|
|
27
|
+
fieldOverrides?: FieldOverrideMap;
|
|
16
28
|
tableName?: string;
|
|
17
29
|
patterns?: Pattern[];
|
|
18
30
|
edges?: Edge[];
|
|
@@ -61,17 +73,30 @@ export interface AssocEdgeGroup {
|
|
|
61
73
|
tableName?: string;
|
|
62
74
|
assocEdges: AssocEdge[];
|
|
63
75
|
statusEnums?: string[];
|
|
64
|
-
|
|
76
|
+
viewerBased?: boolean;
|
|
77
|
+
nullStates?: string | string[];
|
|
65
78
|
nullStateFn?: string;
|
|
66
79
|
edgeAction?: EdgeGroupAction;
|
|
67
80
|
}
|
|
68
|
-
export
|
|
81
|
+
export type Edge = AssocEdge;
|
|
82
|
+
interface ImportPath {
|
|
83
|
+
importPath: string;
|
|
84
|
+
import: string;
|
|
85
|
+
defaultImport?: boolean;
|
|
86
|
+
originalImport?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface TransformReadBetaResult {
|
|
89
|
+
code: string;
|
|
90
|
+
imports: ImportPath[];
|
|
91
|
+
}
|
|
69
92
|
export interface Pattern {
|
|
70
93
|
name: string;
|
|
71
|
-
fields: FieldMap
|
|
94
|
+
fields: FieldMap;
|
|
95
|
+
disableMixin?: boolean;
|
|
72
96
|
edges?: Edge[];
|
|
73
97
|
transformRead?: () => Clause;
|
|
74
|
-
|
|
98
|
+
transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
|
|
99
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
75
100
|
transformsDelete?: boolean;
|
|
76
101
|
transformsInsert?: boolean;
|
|
77
102
|
transformsUpdate?: boolean;
|
|
@@ -81,16 +106,25 @@ export declare enum SQLStatementOperation {
|
|
|
81
106
|
Update = "update",
|
|
82
107
|
Delete = "delete"
|
|
83
108
|
}
|
|
84
|
-
export interface
|
|
109
|
+
export interface EdgeUpdateOperation {
|
|
110
|
+
op: SQLStatementOperation;
|
|
111
|
+
edge: AssocEdgeInput;
|
|
112
|
+
}
|
|
113
|
+
export interface TransformedEdgeUpdateOperation {
|
|
85
114
|
op: SQLStatementOperation;
|
|
86
|
-
|
|
87
|
-
|
|
115
|
+
data?: Data;
|
|
116
|
+
}
|
|
117
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
118
|
+
op: SQLStatementOperation;
|
|
119
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
120
|
+
input: Data;
|
|
88
121
|
data?: Map<string, any>;
|
|
89
122
|
}
|
|
90
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
123
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
91
124
|
op: SQLStatementOperation;
|
|
92
125
|
data?: Data;
|
|
93
|
-
existingEnt?: T;
|
|
126
|
+
existingEnt?: T | null;
|
|
127
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
94
128
|
}
|
|
95
129
|
export declare enum DBType {
|
|
96
130
|
UUID = "UUID",
|
|
@@ -106,19 +140,27 @@ export declare enum DBType {
|
|
|
106
140
|
JSONB = "JSONB",
|
|
107
141
|
Enum = "Enum",
|
|
108
142
|
StringEnum = "StringEnum",
|
|
143
|
+
IntEnum = "IntEnum",
|
|
109
144
|
Date = "Date",
|
|
110
145
|
Time = "Time",
|
|
111
146
|
Timetz = "Timetz",
|
|
112
147
|
List = "List"
|
|
113
148
|
}
|
|
114
|
-
export interface
|
|
149
|
+
export interface DeprecatedImportType {
|
|
115
150
|
path: string;
|
|
116
151
|
type: string;
|
|
117
152
|
[x: string]: any;
|
|
118
153
|
}
|
|
154
|
+
export interface ConvertType {
|
|
155
|
+
path: string;
|
|
156
|
+
function: string;
|
|
157
|
+
}
|
|
119
158
|
declare type EnumMap = {
|
|
120
159
|
[key: string]: string;
|
|
121
160
|
};
|
|
161
|
+
declare type IntEnumMap = {
|
|
162
|
+
[key: string]: number;
|
|
163
|
+
};
|
|
122
164
|
export interface Type {
|
|
123
165
|
dbType: DBType;
|
|
124
166
|
listElemType?: Type;
|
|
@@ -126,9 +168,13 @@ export interface Type {
|
|
|
126
168
|
graphQLType?: string;
|
|
127
169
|
values?: string[];
|
|
128
170
|
enumMap?: EnumMap;
|
|
129
|
-
|
|
171
|
+
intEnumMap?: IntEnumMap;
|
|
172
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
173
|
+
disableUnknownType?: boolean;
|
|
174
|
+
importType?: DeprecatedImportType;
|
|
130
175
|
subFields?: FieldMap;
|
|
131
176
|
unionFields?: FieldMap;
|
|
177
|
+
[x: string]: any;
|
|
132
178
|
}
|
|
133
179
|
export interface ForeignKey {
|
|
134
180
|
schema: string;
|
|
@@ -136,8 +182,9 @@ export interface ForeignKey {
|
|
|
136
182
|
name?: string;
|
|
137
183
|
disableIndex?: boolean;
|
|
138
184
|
disableBuilderType?: boolean;
|
|
185
|
+
[x: string]: any;
|
|
139
186
|
}
|
|
140
|
-
|
|
187
|
+
type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
141
188
|
export interface InverseFieldEdge {
|
|
142
189
|
name: string;
|
|
143
190
|
edgeConstName?: string;
|
|
@@ -151,45 +198,56 @@ export interface FieldEdge {
|
|
|
151
198
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
152
199
|
disableBuilderType?: boolean;
|
|
153
200
|
}
|
|
201
|
+
interface PrivateOptions {
|
|
202
|
+
exposeToActions?: boolean;
|
|
203
|
+
}
|
|
154
204
|
export interface FieldOptions {
|
|
155
205
|
nullable?: boolean;
|
|
156
206
|
storageKey?: string;
|
|
157
207
|
serverDefault?: any;
|
|
158
208
|
unique?: boolean;
|
|
159
209
|
hideFromGraphQL?: boolean;
|
|
160
|
-
private?: boolean;
|
|
210
|
+
private?: boolean | PrivateOptions;
|
|
161
211
|
sensitive?: boolean;
|
|
162
212
|
graphqlName?: string;
|
|
163
213
|
index?: boolean;
|
|
164
214
|
foreignKey?: ForeignKey;
|
|
165
215
|
fieldEdge?: FieldEdge;
|
|
166
216
|
primaryKey?: boolean;
|
|
217
|
+
immutable?: boolean;
|
|
167
218
|
disableUserEditable?: boolean;
|
|
168
219
|
disableUserGraphQLEditable?: boolean;
|
|
169
220
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
170
221
|
defaultToViewerOnCreate?: boolean;
|
|
222
|
+
onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
|
|
171
223
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
172
224
|
derivedWhenEmbedded?: boolean;
|
|
173
225
|
polymorphic?: boolean | PolymorphicOptions;
|
|
174
226
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
175
227
|
getDerivedFields?(name: string): FieldMap;
|
|
228
|
+
convert?: ConvertType;
|
|
229
|
+
fetchOnDemand?: boolean;
|
|
230
|
+
dbOnly?: boolean;
|
|
176
231
|
[x: string]: any;
|
|
177
232
|
}
|
|
178
233
|
export interface PolymorphicOptions {
|
|
234
|
+
name?: string;
|
|
179
235
|
types?: string[];
|
|
180
236
|
hideFromInverseGraphQL?: boolean;
|
|
181
237
|
disableBuilderType?: boolean;
|
|
238
|
+
serverDefault?: any;
|
|
182
239
|
}
|
|
183
240
|
export interface Field extends FieldOptions {
|
|
184
241
|
type: Type;
|
|
185
242
|
valid?(val: any): Promise<boolean> | boolean;
|
|
243
|
+
validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
|
|
186
244
|
format?(val: any, nested?: boolean): any;
|
|
187
245
|
logValue(val: any): any;
|
|
188
246
|
}
|
|
189
247
|
export interface SchemaConstructor {
|
|
190
248
|
new (): Schema;
|
|
191
249
|
}
|
|
192
|
-
export
|
|
250
|
+
export type SchemaInputType = Schema | SchemaConstructor;
|
|
193
251
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
194
252
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
195
253
|
/**
|
|
@@ -203,7 +261,7 @@ interface objectLoaderOptions {
|
|
|
203
261
|
instanceKey?: string;
|
|
204
262
|
}
|
|
205
263
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
206
|
-
export declare function getTransformedUpdateOp<
|
|
264
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
207
265
|
export declare enum ActionOperation {
|
|
208
266
|
Create = 1,
|
|
209
267
|
Edit = 2,
|
|
@@ -213,15 +271,18 @@ export declare enum ActionOperation {
|
|
|
213
271
|
RemoveEdge = 32,
|
|
214
272
|
EdgeGroup = 64
|
|
215
273
|
}
|
|
216
|
-
|
|
217
|
-
|
|
274
|
+
type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
|
|
275
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
218
276
|
export interface ActionField {
|
|
219
277
|
name: string;
|
|
220
278
|
type: actionFieldType;
|
|
221
279
|
nullable?: boolean | NullableListOptions;
|
|
280
|
+
optional?: boolean;
|
|
222
281
|
list?: boolean;
|
|
223
282
|
actionName?: string;
|
|
224
283
|
excludedFields?: string[];
|
|
284
|
+
hideFromGraphQL?: boolean;
|
|
285
|
+
[x: string]: any;
|
|
225
286
|
}
|
|
226
287
|
export interface Action {
|
|
227
288
|
operation: ActionOperation;
|
|
@@ -235,6 +296,7 @@ export interface Action {
|
|
|
235
296
|
optionalFields?: string[];
|
|
236
297
|
requiredFields?: string[];
|
|
237
298
|
noFields?: boolean;
|
|
299
|
+
[x: string]: any;
|
|
238
300
|
}
|
|
239
301
|
export declare const NoFields = "__NO_FIELDS__";
|
|
240
302
|
export declare function requiredField(field: string): string;
|
|
@@ -245,6 +307,7 @@ export interface Constraint {
|
|
|
245
307
|
columns: string[];
|
|
246
308
|
fkey?: ForeignKeyInfo;
|
|
247
309
|
condition?: string;
|
|
310
|
+
[x: string]: any;
|
|
248
311
|
}
|
|
249
312
|
export interface FullTextWeight {
|
|
250
313
|
A?: string[];
|
|
@@ -258,17 +321,21 @@ export interface FullText {
|
|
|
258
321
|
languageColumn?: string;
|
|
259
322
|
indexType?: "gin" | "gist";
|
|
260
323
|
weights?: FullTextWeight;
|
|
324
|
+
[x: string]: any;
|
|
261
325
|
}
|
|
262
326
|
export interface Index {
|
|
263
327
|
name: string;
|
|
264
328
|
columns: string[];
|
|
265
329
|
unique?: boolean;
|
|
266
330
|
fulltext?: FullText;
|
|
331
|
+
indexType?: "gin" | "btree";
|
|
332
|
+
[x: string]: any;
|
|
267
333
|
}
|
|
268
334
|
export interface ForeignKeyInfo {
|
|
269
335
|
tableName: string;
|
|
270
336
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
271
337
|
columns: string[];
|
|
338
|
+
[x: string]: any;
|
|
272
339
|
}
|
|
273
340
|
export declare enum ConstraintType {
|
|
274
341
|
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
|
}
|
|
@@ -121,6 +112,7 @@ function getFieldsWithPrivacy(value, fieldMap) {
|
|
|
121
112
|
m.set(info.dbCol, privacyPolicy);
|
|
122
113
|
}
|
|
123
114
|
}
|
|
115
|
+
return;
|
|
124
116
|
}
|
|
125
117
|
for (const name in fields) {
|
|
126
118
|
const field = fields[name];
|
|
@@ -168,6 +160,9 @@ function getTransformedReadClause(value) {
|
|
|
168
160
|
return;
|
|
169
161
|
}
|
|
170
162
|
exports.getTransformedReadClause = getTransformedReadClause;
|
|
163
|
+
// would like to avoid calling this so that itwe don't run into circular dependencies
|
|
164
|
+
// but the fact that it returns a clause makes it hard since we don't control the patterns...
|
|
165
|
+
// we can make each clause return a format that can be extrapolated and used in codegen...
|
|
171
166
|
function getObjectLoaderProperties(value, tableName) {
|
|
172
167
|
return {
|
|
173
168
|
clause: () => getTransformedReadClause(value),
|
|
@@ -178,13 +173,14 @@ exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
|
178
173
|
function getTransformedUpdateOp(value, stmt) {
|
|
179
174
|
const schema = getSchema(value);
|
|
180
175
|
if (!schema.patterns) {
|
|
181
|
-
return;
|
|
176
|
+
return null;
|
|
182
177
|
}
|
|
183
178
|
for (const p of schema.patterns) {
|
|
184
179
|
if (p.transformWrite) {
|
|
185
180
|
return p.transformWrite(stmt);
|
|
186
181
|
}
|
|
187
182
|
}
|
|
183
|
+
return null;
|
|
188
184
|
}
|
|
189
185
|
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
190
186
|
// this maps to ActionOperation in ent/action.go
|
|
@@ -208,6 +204,9 @@ var ActionOperation;
|
|
|
208
204
|
// RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
|
|
209
205
|
ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
|
|
210
206
|
// EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
|
|
207
|
+
// if you want to clear this edge group e.g. any set edge with id1 and id2,
|
|
208
|
+
// you should create a custom action that takes the id as an action only field,
|
|
209
|
+
// and then calls `clearEdgeTypeInGroup` in a trigger to clear
|
|
211
210
|
ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
|
|
212
211
|
})(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
|
|
213
212
|
// 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
|
}
|