@snowtop/ent 0.1.0-alpha14 → 0.1.0-alpha140
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 +27 -16
- package/action/action.js +22 -7
- package/action/executor.d.ts +16 -3
- package/action/executor.js +88 -21
- package/action/experimental_action.d.ts +25 -16
- package/action/experimental_action.js +35 -9
- package/action/index.d.ts +3 -1
- package/action/index.js +7 -1
- package/action/operations.d.ts +125 -0
- package/action/operations.js +684 -0
- package/action/orchestrator.d.ts +34 -11
- package/action/orchestrator.js +355 -92
- 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 +51 -21
- package/core/base.js +7 -1
- package/core/clause.d.ts +85 -40
- package/core/clause.js +375 -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 +4 -2
- package/core/context.js +20 -2
- package/core/convert.d.ts +1 -1
- package/core/date.js +1 -5
- package/core/db.d.ts +12 -8
- package/core/db.js +18 -8
- package/core/ent.d.ts +66 -93
- package/core/ent.js +517 -577
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +1 -0
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- 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 +30 -9
- package/core/loaders/object_loader.js +225 -78
- package/core/loaders/query_loader.d.ts +6 -12
- package/core/loaders/query_loader.js +52 -11
- 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 +7 -6
- package/core/privacy.js +21 -25
- package/core/query/assoc_query.d.ts +3 -2
- 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 +17 -2
- 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 +7 -3
- 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 +470 -236
- package/core/viewer.js +1 -1
- package/graphql/graphql.d.ts +52 -19
- package/graphql/graphql.js +174 -136
- package/graphql/graphql_field_helpers.d.ts +7 -1
- package/graphql/graphql_field_helpers.js +21 -1
- package/graphql/index.d.ts +2 -2
- package/graphql/index.js +3 -5
- package/graphql/query/connection_type.d.ts +9 -9
- 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/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/imports/index.d.ts +6 -1
- package/imports/index.js +19 -4
- package/index.d.ts +14 -5
- package/index.js +26 -10
- package/package.json +18 -17
- package/parse_schema/parse.d.ts +31 -9
- package/parse_schema/parse.js +156 -13
- package/schema/base_schema.d.ts +9 -3
- package/schema/base_schema.js +12 -0
- package/schema/field.d.ts +78 -21
- package/schema/field.js +231 -71
- 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 +94 -19
- package/schema/schema.js +11 -13
- package/schema/struct_field.d.ts +15 -3
- package/schema/struct_field.js +117 -22
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +10 -6
- package/scripts/custom_graphql.js +142 -31
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +20 -5
- package/testutils/action/complex_schemas.d.ts +69 -0
- package/testutils/action/complex_schemas.js +405 -0
- package/testutils/builder.d.ts +39 -43
- package/testutils/builder.js +75 -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} +25 -8
- package/testutils/db/{test_db.js → temp_db.js} +224 -47
- 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 +52 -7
- 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_comms.js +1 -1
- 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 +13 -7
- package/testutils/fake_data/fake_event.d.ts +4 -1
- package/testutils/fake_data/fake_event.js +7 -6
- 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 +8 -5
- package/testutils/fake_data/fake_user.js +16 -15
- 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 +11 -4
- package/testutils/fake_data/user_query.js +54 -22
- package/testutils/fake_log.js +1 -1
- 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/json_field.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import { FieldOptions, Type, Field,
|
|
1
|
+
import { FieldOptions, Type, Field, DeprecatedImportType } from "./schema";
|
|
2
2
|
import { BaseField, ListField } from "./field";
|
|
3
3
|
export interface JSONOptions extends FieldOptions {
|
|
4
4
|
validator?: (val: any) => boolean;
|
|
5
|
-
importType?:
|
|
5
|
+
importType?: DeprecatedImportType;
|
|
6
|
+
}
|
|
7
|
+
interface allJSONOptions extends JSONOptions {
|
|
8
|
+
jsonAsList?: boolean;
|
|
6
9
|
}
|
|
7
10
|
export declare class JSONField extends BaseField implements Field {
|
|
8
11
|
private options?;
|
|
9
12
|
type: Type;
|
|
10
|
-
constructor(jsonb: boolean, options?:
|
|
11
|
-
format(val: any):
|
|
13
|
+
constructor(jsonb: boolean, options?: allJSONOptions | undefined);
|
|
14
|
+
format(val: any, nested?: boolean): any;
|
|
12
15
|
valid(val: any): boolean;
|
|
13
16
|
}
|
|
14
17
|
export declare function JSONType(options?: JSONOptions): JSONField;
|
|
15
18
|
export declare function JSONBType(options?: JSONOptions): JSONField;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use JSONBTypeAsList
|
|
21
|
+
*/
|
|
16
22
|
export declare function JSONBListType(options?: JSONOptions): ListField;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use JSONTypeAsList
|
|
25
|
+
*/
|
|
17
26
|
export declare function JSONListType(options?: JSONOptions): ListField;
|
|
27
|
+
export declare function JSONBTypeAsList(options?: JSONOptions): JSONField & JSONOptions;
|
|
28
|
+
export declare function JSONTypeAsList(options?: JSONOptions): JSONField & JSONOptions;
|
|
29
|
+
export {};
|
package/schema/json_field.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONListType = exports.JSONBListType = exports.JSONBType = exports.JSONType = exports.JSONField = void 0;
|
|
3
|
+
exports.JSONTypeAsList = exports.JSONBTypeAsList = exports.JSONListType = exports.JSONBListType = exports.JSONBType = exports.JSONType = exports.JSONField = void 0;
|
|
4
4
|
const schema_1 = require("./schema");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
class JSONField extends field_1.BaseField {
|
|
@@ -16,8 +16,16 @@ class JSONField extends field_1.BaseField {
|
|
|
16
16
|
if (options?.importType) {
|
|
17
17
|
this.type.importType = options.importType;
|
|
18
18
|
}
|
|
19
|
+
if (options?.jsonAsList) {
|
|
20
|
+
this.type.listElemType = {
|
|
21
|
+
dbType: schema_1.DBType.JSONB,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
|
-
format(val) {
|
|
25
|
+
format(val, nested) {
|
|
26
|
+
if (nested) {
|
|
27
|
+
return val;
|
|
28
|
+
}
|
|
21
29
|
return JSON.stringify(val);
|
|
22
30
|
}
|
|
23
31
|
valid(val) {
|
|
@@ -38,11 +46,33 @@ function JSONBType(options) {
|
|
|
38
46
|
return Object.assign(result, options);
|
|
39
47
|
}
|
|
40
48
|
exports.JSONBType = JSONBType;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use JSONBTypeAsList
|
|
51
|
+
*/
|
|
41
52
|
function JSONBListType(options) {
|
|
42
53
|
return new field_1.ListField(JSONBType(options), options);
|
|
43
54
|
}
|
|
44
55
|
exports.JSONBListType = JSONBListType;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated use JSONTypeAsList
|
|
58
|
+
*/
|
|
45
59
|
function JSONListType(options) {
|
|
46
60
|
return new field_1.ListField(JSONType(options), options);
|
|
47
61
|
}
|
|
48
62
|
exports.JSONListType = JSONListType;
|
|
63
|
+
function JSONBTypeAsList(options) {
|
|
64
|
+
let result = new JSONField(true, {
|
|
65
|
+
...options,
|
|
66
|
+
jsonAsList: true,
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(result, options);
|
|
69
|
+
}
|
|
70
|
+
exports.JSONBTypeAsList = JSONBTypeAsList;
|
|
71
|
+
function JSONTypeAsList(options) {
|
|
72
|
+
let result = new JSONField(false, {
|
|
73
|
+
...options,
|
|
74
|
+
jsonAsList: true,
|
|
75
|
+
});
|
|
76
|
+
return Object.assign(result, options);
|
|
77
|
+
}
|
|
78
|
+
exports.JSONTypeAsList = JSONTypeAsList;
|
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 "../action/operations";
|
|
4
5
|
export declare type FieldMap = {
|
|
5
6
|
[key: string]: Field;
|
|
6
7
|
};
|
|
@@ -8,11 +9,23 @@ 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
|
+
fields?: FieldMap;
|
|
21
|
+
}
|
|
22
|
+
type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
|
|
23
|
+
export type FieldOverrideMap = {
|
|
24
|
+
[key: string]: FieldOverride;
|
|
25
|
+
};
|
|
14
26
|
export default interface Schema {
|
|
15
|
-
fields: FieldMap
|
|
27
|
+
fields: FieldMap;
|
|
28
|
+
fieldOverrides?: FieldOverrideMap;
|
|
16
29
|
tableName?: string;
|
|
17
30
|
patterns?: Pattern[];
|
|
18
31
|
edges?: Edge[];
|
|
@@ -25,6 +38,8 @@ export default interface Schema {
|
|
|
25
38
|
constraints?: Constraint[];
|
|
26
39
|
indices?: Index[];
|
|
27
40
|
hideFromGraphQL?: boolean;
|
|
41
|
+
customGraphQLInterfaces?: string[];
|
|
42
|
+
supportUpsert?: boolean;
|
|
28
43
|
}
|
|
29
44
|
export interface AssocEdge {
|
|
30
45
|
name: string;
|
|
@@ -61,17 +76,30 @@ export interface AssocEdgeGroup {
|
|
|
61
76
|
tableName?: string;
|
|
62
77
|
assocEdges: AssocEdge[];
|
|
63
78
|
statusEnums?: string[];
|
|
64
|
-
|
|
79
|
+
viewerBased?: boolean;
|
|
80
|
+
nullStates?: string | string[];
|
|
65
81
|
nullStateFn?: string;
|
|
66
82
|
edgeAction?: EdgeGroupAction;
|
|
67
83
|
}
|
|
68
|
-
export
|
|
84
|
+
export type Edge = AssocEdge;
|
|
85
|
+
interface ImportPath {
|
|
86
|
+
importPath: string;
|
|
87
|
+
import: string;
|
|
88
|
+
defaultImport?: boolean;
|
|
89
|
+
originalImport?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface TransformReadBetaResult {
|
|
92
|
+
code: string;
|
|
93
|
+
imports: ImportPath[];
|
|
94
|
+
}
|
|
69
95
|
export interface Pattern {
|
|
70
96
|
name: string;
|
|
71
|
-
fields: FieldMap
|
|
97
|
+
fields: FieldMap;
|
|
98
|
+
disableMixin?: boolean;
|
|
72
99
|
edges?: Edge[];
|
|
73
100
|
transformRead?: () => Clause;
|
|
74
|
-
|
|
101
|
+
transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
|
|
102
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
75
103
|
transformsDelete?: boolean;
|
|
76
104
|
transformsInsert?: boolean;
|
|
77
105
|
transformsUpdate?: boolean;
|
|
@@ -81,16 +109,25 @@ export declare enum SQLStatementOperation {
|
|
|
81
109
|
Update = "update",
|
|
82
110
|
Delete = "delete"
|
|
83
111
|
}
|
|
84
|
-
export interface
|
|
112
|
+
export interface EdgeUpdateOperation {
|
|
113
|
+
op: SQLStatementOperation;
|
|
114
|
+
edge: AssocEdgeInput;
|
|
115
|
+
}
|
|
116
|
+
export interface TransformedEdgeUpdateOperation {
|
|
85
117
|
op: SQLStatementOperation;
|
|
86
|
-
|
|
87
|
-
|
|
118
|
+
data?: Data;
|
|
119
|
+
}
|
|
120
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
121
|
+
op: SQLStatementOperation;
|
|
122
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
123
|
+
input: Data;
|
|
88
124
|
data?: Map<string, any>;
|
|
89
125
|
}
|
|
90
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
126
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
91
127
|
op: SQLStatementOperation;
|
|
92
128
|
data?: Data;
|
|
93
129
|
existingEnt?: T | null;
|
|
130
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
94
131
|
}
|
|
95
132
|
export declare enum DBType {
|
|
96
133
|
UUID = "UUID",
|
|
@@ -106,19 +143,27 @@ export declare enum DBType {
|
|
|
106
143
|
JSONB = "JSONB",
|
|
107
144
|
Enum = "Enum",
|
|
108
145
|
StringEnum = "StringEnum",
|
|
146
|
+
IntEnum = "IntEnum",
|
|
109
147
|
Date = "Date",
|
|
110
148
|
Time = "Time",
|
|
111
149
|
Timetz = "Timetz",
|
|
112
150
|
List = "List"
|
|
113
151
|
}
|
|
114
|
-
export interface
|
|
152
|
+
export interface DeprecatedImportType {
|
|
115
153
|
path: string;
|
|
116
154
|
type: string;
|
|
117
155
|
[x: string]: any;
|
|
118
156
|
}
|
|
157
|
+
export interface ConvertType {
|
|
158
|
+
path: string;
|
|
159
|
+
function: string;
|
|
160
|
+
}
|
|
119
161
|
declare type EnumMap = {
|
|
120
162
|
[key: string]: string;
|
|
121
163
|
};
|
|
164
|
+
declare type IntEnumMap = {
|
|
165
|
+
[key: string]: number;
|
|
166
|
+
};
|
|
122
167
|
export interface Type {
|
|
123
168
|
dbType: DBType;
|
|
124
169
|
listElemType?: Type;
|
|
@@ -126,9 +171,14 @@ export interface Type {
|
|
|
126
171
|
graphQLType?: string;
|
|
127
172
|
values?: string[];
|
|
128
173
|
enumMap?: EnumMap;
|
|
129
|
-
|
|
174
|
+
intEnumMap?: IntEnumMap;
|
|
175
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
176
|
+
disableUnknownType?: boolean;
|
|
177
|
+
globalType?: string;
|
|
178
|
+
importType?: DeprecatedImportType;
|
|
130
179
|
subFields?: FieldMap;
|
|
131
180
|
unionFields?: FieldMap;
|
|
181
|
+
[x: string]: any;
|
|
132
182
|
}
|
|
133
183
|
export interface ForeignKey {
|
|
134
184
|
schema: string;
|
|
@@ -136,60 +186,76 @@ export interface ForeignKey {
|
|
|
136
186
|
name?: string;
|
|
137
187
|
disableIndex?: boolean;
|
|
138
188
|
disableBuilderType?: boolean;
|
|
189
|
+
[x: string]: any;
|
|
139
190
|
}
|
|
140
|
-
|
|
191
|
+
type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
141
192
|
export interface InverseFieldEdge {
|
|
142
193
|
name: string;
|
|
143
194
|
edgeConstName?: string;
|
|
144
195
|
tableName?: string;
|
|
145
196
|
hideFromGraphQL?: boolean;
|
|
146
197
|
}
|
|
198
|
+
export interface IndexEdgeOptions {
|
|
199
|
+
name: string;
|
|
200
|
+
}
|
|
147
201
|
export interface FieldEdge {
|
|
148
202
|
schema: string;
|
|
149
203
|
inverseEdge?: string | InverseFieldEdge;
|
|
204
|
+
indexEdge?: IndexEdgeOptions;
|
|
150
205
|
enforceSchema?: boolean;
|
|
151
206
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
152
207
|
disableBuilderType?: boolean;
|
|
153
208
|
}
|
|
209
|
+
interface PrivateOptions {
|
|
210
|
+
exposeToActions?: boolean;
|
|
211
|
+
}
|
|
154
212
|
export interface FieldOptions {
|
|
155
213
|
nullable?: boolean;
|
|
156
214
|
storageKey?: string;
|
|
157
215
|
serverDefault?: any;
|
|
158
216
|
unique?: boolean;
|
|
159
217
|
hideFromGraphQL?: boolean;
|
|
160
|
-
private?: boolean;
|
|
218
|
+
private?: boolean | PrivateOptions;
|
|
161
219
|
sensitive?: boolean;
|
|
162
220
|
graphqlName?: string;
|
|
163
221
|
index?: boolean;
|
|
164
222
|
foreignKey?: ForeignKey;
|
|
165
223
|
fieldEdge?: FieldEdge;
|
|
166
224
|
primaryKey?: boolean;
|
|
225
|
+
immutable?: boolean;
|
|
167
226
|
disableUserEditable?: boolean;
|
|
168
227
|
disableUserGraphQLEditable?: boolean;
|
|
169
228
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
170
229
|
defaultToViewerOnCreate?: boolean;
|
|
230
|
+
onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
|
|
171
231
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
172
232
|
derivedWhenEmbedded?: boolean;
|
|
173
233
|
polymorphic?: boolean | PolymorphicOptions;
|
|
174
234
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
175
235
|
getDerivedFields?(name: string): FieldMap;
|
|
236
|
+
convert?: ConvertType;
|
|
237
|
+
fetchOnDemand?: boolean;
|
|
238
|
+
dbOnly?: boolean;
|
|
176
239
|
[x: string]: any;
|
|
177
240
|
}
|
|
178
241
|
export interface PolymorphicOptions {
|
|
242
|
+
name?: string;
|
|
179
243
|
types?: string[];
|
|
180
244
|
hideFromInverseGraphQL?: boolean;
|
|
181
245
|
disableBuilderType?: boolean;
|
|
246
|
+
serverDefault?: any;
|
|
182
247
|
}
|
|
183
248
|
export interface Field extends FieldOptions {
|
|
184
249
|
type: Type;
|
|
185
250
|
valid?(val: any): Promise<boolean> | boolean;
|
|
251
|
+
validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
|
|
186
252
|
format?(val: any, nested?: boolean): any;
|
|
187
253
|
logValue(val: any): any;
|
|
188
254
|
}
|
|
189
255
|
export interface SchemaConstructor {
|
|
190
256
|
new (): Schema;
|
|
191
257
|
}
|
|
192
|
-
export
|
|
258
|
+
export type SchemaInputType = Schema | SchemaConstructor;
|
|
193
259
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
194
260
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
195
261
|
/**
|
|
@@ -203,7 +269,7 @@ interface objectLoaderOptions {
|
|
|
203
269
|
instanceKey?: string;
|
|
204
270
|
}
|
|
205
271
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
206
|
-
export declare function getTransformedUpdateOp<
|
|
272
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
207
273
|
export declare enum ActionOperation {
|
|
208
274
|
Create = 1,
|
|
209
275
|
Edit = 2,
|
|
@@ -213,15 +279,18 @@ export declare enum ActionOperation {
|
|
|
213
279
|
RemoveEdge = 32,
|
|
214
280
|
EdgeGroup = 64
|
|
215
281
|
}
|
|
216
|
-
|
|
217
|
-
|
|
282
|
+
type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
|
|
283
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
218
284
|
export interface ActionField {
|
|
219
285
|
name: string;
|
|
220
286
|
type: actionFieldType;
|
|
221
287
|
nullable?: boolean | NullableListOptions;
|
|
288
|
+
optional?: boolean;
|
|
222
289
|
list?: boolean;
|
|
223
290
|
actionName?: string;
|
|
224
291
|
excludedFields?: string[];
|
|
292
|
+
hideFromGraphQL?: boolean;
|
|
293
|
+
[x: string]: any;
|
|
225
294
|
}
|
|
226
295
|
export interface Action {
|
|
227
296
|
operation: ActionOperation;
|
|
@@ -235,6 +304,7 @@ export interface Action {
|
|
|
235
304
|
optionalFields?: string[];
|
|
236
305
|
requiredFields?: string[];
|
|
237
306
|
noFields?: boolean;
|
|
307
|
+
[x: string]: any;
|
|
238
308
|
}
|
|
239
309
|
export declare const NoFields = "__NO_FIELDS__";
|
|
240
310
|
export declare function requiredField(field: string): string;
|
|
@@ -245,6 +315,7 @@ export interface Constraint {
|
|
|
245
315
|
columns: string[];
|
|
246
316
|
fkey?: ForeignKeyInfo;
|
|
247
317
|
condition?: string;
|
|
318
|
+
[x: string]: any;
|
|
248
319
|
}
|
|
249
320
|
export interface FullTextWeight {
|
|
250
321
|
A?: string[];
|
|
@@ -258,17 +329,21 @@ export interface FullText {
|
|
|
258
329
|
languageColumn?: string;
|
|
259
330
|
indexType?: "gin" | "gist";
|
|
260
331
|
weights?: FullTextWeight;
|
|
332
|
+
[x: string]: any;
|
|
261
333
|
}
|
|
262
334
|
export interface Index {
|
|
263
335
|
name: string;
|
|
264
336
|
columns: string[];
|
|
265
337
|
unique?: boolean;
|
|
266
338
|
fulltext?: FullText;
|
|
339
|
+
indexType?: "gin" | "btree";
|
|
340
|
+
[x: string]: any;
|
|
267
341
|
}
|
|
268
342
|
export interface ForeignKeyInfo {
|
|
269
343
|
tableName: string;
|
|
270
344
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
271
345
|
columns: string[];
|
|
346
|
+
[x: string]: any;
|
|
272
347
|
}
|
|
273
348
|
export declare enum ConstraintType {
|
|
274
349
|
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),
|
|
@@ -209,6 +204,9 @@ var ActionOperation;
|
|
|
209
204
|
// RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
|
|
210
205
|
ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
|
|
211
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
|
|
212
210
|
ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
|
|
213
211
|
})(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
|
|
214
212
|
// sentinel that indicates an action has no fields
|
package/schema/struct_field.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { BaseField, ListField } from "./field";
|
|
2
2
|
import { FieldOptions, Field, Type, FieldMap } from "./schema";
|
|
3
|
-
|
|
3
|
+
interface structFieldOptions extends FieldOptions {
|
|
4
4
|
tsType: string;
|
|
5
5
|
fields: FieldMap;
|
|
6
6
|
graphQLType?: string;
|
|
7
7
|
jsonNotJSONB?: boolean;
|
|
8
8
|
}
|
|
9
|
+
interface GlobalStructOptions extends FieldOptions {
|
|
10
|
+
globalType: string;
|
|
11
|
+
}
|
|
12
|
+
export type StructOptions = structFieldOptions | GlobalStructOptions;
|
|
9
13
|
export declare class StructField extends BaseField implements Field {
|
|
10
14
|
private options;
|
|
15
|
+
private jsonAsList?;
|
|
11
16
|
type: Type;
|
|
12
|
-
constructor(options: StructOptions);
|
|
13
|
-
|
|
17
|
+
constructor(options: StructOptions, jsonAsList?: boolean | undefined);
|
|
18
|
+
formatImpl(obj: any, nested?: boolean): string | Object;
|
|
19
|
+
format(obj: any, nested?: boolean): any;
|
|
20
|
+
private validImpl;
|
|
14
21
|
valid(obj: any): Promise<boolean>;
|
|
15
22
|
}
|
|
16
23
|
export declare function StructType(options: StructOptions): StructField & StructOptions;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use StructTypeAsList
|
|
26
|
+
*/
|
|
17
27
|
export declare function StructListType(options: StructOptions): ListField;
|
|
28
|
+
export declare function StructTypeAsList(options: StructOptions): StructField & StructOptions;
|
|
29
|
+
export {};
|
package/schema/struct_field.js
CHANGED
|
@@ -1,44 +1,51 @@
|
|
|
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
|
|
7
|
+
const global_schema_1 = require("../core/global_schema");
|
|
8
|
+
const logger_1 = require("../core/logger");
|
|
7
9
|
class StructField extends field_1.BaseField {
|
|
8
|
-
constructor(options) {
|
|
10
|
+
constructor(options, jsonAsList) {
|
|
9
11
|
super();
|
|
10
12
|
this.options = options;
|
|
13
|
+
this.jsonAsList = jsonAsList;
|
|
11
14
|
this.type = {
|
|
12
15
|
dbType: schema_1.DBType.JSONB,
|
|
13
16
|
};
|
|
14
17
|
this.type.subFields = options.fields;
|
|
15
18
|
this.type.type = options.tsType;
|
|
16
19
|
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
20
|
+
this.type.globalType = this.options.globalType;
|
|
17
21
|
if (options.jsonNotJSONB) {
|
|
18
22
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
23
|
}
|
|
24
|
+
if (jsonAsList) {
|
|
25
|
+
this.type.listElemType = {
|
|
26
|
+
dbType: schema_1.DBType.JSONB,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
// this will lead to issues if field changes.
|
|
23
|
-
// TODO: use storageKey and convert back...
|
|
24
|
-
format(obj, nested) {
|
|
30
|
+
formatImpl(obj, nested) {
|
|
25
31
|
if (!(obj instanceof Object)) {
|
|
26
32
|
throw new Error("valid was not called");
|
|
27
33
|
}
|
|
28
34
|
let ret = {};
|
|
29
35
|
for (const k in this.options.fields) {
|
|
36
|
+
const field = this.options.fields[k];
|
|
37
|
+
// check two values
|
|
38
|
+
// store in dbKey format
|
|
30
39
|
// TODO more #510
|
|
31
|
-
let dbKey = (0,
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
if (val === undefined && obj[
|
|
35
|
-
val = obj[
|
|
36
|
-
dbKey = k;
|
|
40
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
41
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
42
|
+
let val = obj[camelKey];
|
|
43
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
44
|
+
val = obj[dbKey];
|
|
37
45
|
}
|
|
38
46
|
if (val === undefined) {
|
|
39
47
|
continue;
|
|
40
48
|
}
|
|
41
|
-
const field = this.options.fields[k];
|
|
42
49
|
if (field.format) {
|
|
43
50
|
// indicate nested so this isn't JSON stringified
|
|
44
51
|
ret[dbKey] = field.format(val, true);
|
|
@@ -47,13 +54,53 @@ class StructField extends field_1.BaseField {
|
|
|
47
54
|
ret[dbKey] = val;
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
57
|
+
// don't json.stringify if nested or list
|
|
51
58
|
if (nested) {
|
|
52
59
|
return ret;
|
|
53
60
|
}
|
|
54
61
|
return JSON.stringify(ret);
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
format(obj, nested) {
|
|
64
|
+
if (this.type.globalType) {
|
|
65
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
66
|
+
if (f && f.format) {
|
|
67
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
68
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
69
|
+
if (this.jsonAsList) {
|
|
70
|
+
// handle as nested
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
const formatted = obj.map((v) => f.format(v, true));
|
|
73
|
+
if (nested) {
|
|
74
|
+
return formatted;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return JSON.stringify(formatted);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const formatted = f.format([obj], true);
|
|
82
|
+
if (nested) {
|
|
83
|
+
return formatted[0];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return JSON.stringify(formatted[0]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// TODO handle format code
|
|
91
|
+
return f.format(obj);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(obj) && this.jsonAsList) {
|
|
95
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
96
|
+
if (nested) {
|
|
97
|
+
return ret;
|
|
98
|
+
}
|
|
99
|
+
return JSON.stringify(ret);
|
|
100
|
+
}
|
|
101
|
+
return this.formatImpl(obj, nested);
|
|
102
|
+
}
|
|
103
|
+
async validImpl(obj) {
|
|
57
104
|
if (!(obj instanceof Object)) {
|
|
58
105
|
return false;
|
|
59
106
|
}
|
|
@@ -63,12 +110,11 @@ class StructField extends field_1.BaseField {
|
|
|
63
110
|
for (const k in this.options.fields) {
|
|
64
111
|
const field = this.options.fields[k];
|
|
65
112
|
// TODO more #510
|
|
66
|
-
let dbKey = (0,
|
|
67
|
-
let
|
|
68
|
-
|
|
69
|
-
if (val === undefined && obj[
|
|
70
|
-
val = obj[
|
|
71
|
-
dbKey = k;
|
|
113
|
+
let dbKey = (0, schema_1.getStorageKey)(field, k);
|
|
114
|
+
let camelKey = (0, camel_case_1.camelCase)(k);
|
|
115
|
+
let val = obj[camelKey];
|
|
116
|
+
if (val === undefined && obj[dbKey] !== undefined) {
|
|
117
|
+
val = obj[dbKey];
|
|
72
118
|
}
|
|
73
119
|
if (val === undefined || val === null) {
|
|
74
120
|
// nullable, nothing to do here
|
|
@@ -89,6 +135,47 @@ class StructField extends field_1.BaseField {
|
|
|
89
135
|
const ret = await Promise.all(promises);
|
|
90
136
|
return ret.every((v) => v);
|
|
91
137
|
}
|
|
138
|
+
async valid(obj) {
|
|
139
|
+
if (this.type.globalType) {
|
|
140
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
141
|
+
// list and global type is not valid.
|
|
142
|
+
if (f) {
|
|
143
|
+
if (f.valid) {
|
|
144
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
145
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
146
|
+
if (this.jsonAsList) {
|
|
147
|
+
if (!Array.isArray(obj)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
152
|
+
return valid.every((b) => b);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return f.valid([obj]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return f.valid(obj);
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (this.jsonAsList) {
|
|
168
|
+
if (!Array.isArray(obj)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
172
|
+
return valid.every((b) => b);
|
|
173
|
+
}
|
|
174
|
+
if (!(obj instanceof Object)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
return this.validImpl(obj);
|
|
178
|
+
}
|
|
92
179
|
}
|
|
93
180
|
exports.StructField = StructField;
|
|
94
181
|
function StructType(options) {
|
|
@@ -96,7 +183,15 @@ function StructType(options) {
|
|
|
96
183
|
return Object.assign(result, options);
|
|
97
184
|
}
|
|
98
185
|
exports.StructType = StructType;
|
|
186
|
+
/**
|
|
187
|
+
* @deprecated use StructTypeAsList
|
|
188
|
+
*/
|
|
99
189
|
function StructListType(options) {
|
|
100
190
|
return new field_1.ListField(StructType(options), options);
|
|
101
191
|
}
|
|
102
192
|
exports.StructListType = StructListType;
|
|
193
|
+
function StructTypeAsList(options) {
|
|
194
|
+
let result = new StructField(options, true);
|
|
195
|
+
return Object.assign(result, options);
|
|
196
|
+
}
|
|
197
|
+
exports.StructTypeAsList = StructTypeAsList;
|