@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action/action.d.ts +28 -24
- package/action/executor.d.ts +4 -4
- package/action/executor.js +2 -2
- package/action/experimental_action.d.ts +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- package/core/loaders/assoc_edge_loader.d.ts +3 -3
- package/core/loaders/assoc_edge_loader.js +5 -4
- package/core/loaders/index_loader.js +1 -0
- package/core/loaders/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- package/core/query/assoc_query.d.ts +6 -6
- package/core/query/custom_query.d.ts +5 -5
- package/core/query/query.d.ts +1 -1
- package/core/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- package/graphql/builtins/connection.js +3 -3
- package/graphql/builtins/edge.js +2 -2
- package/graphql/builtins/node.js +1 -1
- package/graphql/graphql.d.ts +3 -2
- package/graphql/graphql.js +30 -23
- package/graphql/node_resolver.d.ts +0 -1
- package/graphql/query/connection_type.js +6 -6
- package/graphql/query/edge_connection.d.ts +9 -9
- package/graphql/query/page_info.d.ts +1 -1
- package/graphql/query/page_info.js +4 -4
- package/graphql/query/shared_assoc_test.js +2 -2
- package/graphql/scalars/time.d.ts +1 -1
- package/index.d.ts +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- package/scripts/{transform_schema.d.ts → migrate_v0.1.d.ts} +0 -0
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/read_schema.js +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -13
- package/testutils/context/test_context.d.ts +2 -2
- package/testutils/context/test_context.js +7 -1
- package/testutils/db/{test_db.d.ts → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- package/testutils/ent-graphql-tests/index.d.ts +2 -0
- package/testutils/ent-graphql-tests/index.js +26 -17
- package/testutils/fake_data/fake_contact.d.ts +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -0
- package/tsc/compilerOptions.d.ts +6 -0
- package/tsc/compilerOptions.js +40 -1
- package/tsc/move_generated.d.ts +1 -0
- package/tsc/move_generated.js +160 -0
- package/tsc/transform.d.ts +21 -0
- package/tsc/transform.js +167 -0
- package/tsc/transform_action.d.ts +22 -0
- package/tsc/transform_action.js +179 -0
- package/tsc/transform_ent.d.ts +17 -0
- package/tsc/transform_ent.js +59 -0
- package/tsc/transform_schema.d.ts +27 -0
- package/tsc/transform_schema.js +379 -0
- package/scripts/transform_schema.js +0 -288
package/schema/index.js
CHANGED
|
@@ -10,20 +10,27 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
13
|
+
exports.EntSchemaWithTZ = exports.EntSchema = exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.SQLStatementOperation = exports.optionalField = exports.requiredField = exports.ConstraintType = exports.NoFields = exports.ActionOperation = exports.getStorageKey = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
|
|
14
14
|
var schema_1 = require("./schema");
|
|
15
15
|
Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
|
|
16
16
|
Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
|
|
17
|
+
Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
|
|
18
|
+
Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
|
|
17
19
|
Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
|
|
18
20
|
Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
|
|
19
21
|
Object.defineProperty(exports, "ConstraintType", { enumerable: true, get: function () { return schema_1.ConstraintType; } });
|
|
20
22
|
Object.defineProperty(exports, "requiredField", { enumerable: true, get: function () { return schema_1.requiredField; } });
|
|
21
23
|
Object.defineProperty(exports, "optionalField", { enumerable: true, get: function () { return schema_1.optionalField; } });
|
|
24
|
+
Object.defineProperty(exports, "SQLStatementOperation", { enumerable: true, get: function () { return schema_1.SQLStatementOperation; } });
|
|
25
|
+
Object.defineProperty(exports, "getTransformedReadClause", { enumerable: true, get: function () { return schema_1.getTransformedReadClause; } });
|
|
26
|
+
Object.defineProperty(exports, "getObjectLoaderProperties", { enumerable: true, get: function () { return schema_1.getObjectLoaderProperties; } });
|
|
22
27
|
var base_schema_1 = require("./base_schema");
|
|
23
28
|
Object.defineProperty(exports, "Timestamps", { enumerable: true, get: function () { return base_schema_1.Timestamps; } });
|
|
24
29
|
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return base_schema_1.Node; } });
|
|
25
30
|
Object.defineProperty(exports, "BaseEntSchema", { enumerable: true, get: function () { return base_schema_1.BaseEntSchema; } });
|
|
26
31
|
Object.defineProperty(exports, "BaseEntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.BaseEntSchemaWithTZ; } });
|
|
32
|
+
Object.defineProperty(exports, "EntSchema", { enumerable: true, get: function () { return base_schema_1.EntSchema; } });
|
|
33
|
+
Object.defineProperty(exports, "EntSchemaWithTZ", { enumerable: true, get: function () { return base_schema_1.EntSchemaWithTZ; } });
|
|
27
34
|
__exportStar(require("./field"), exports);
|
|
28
35
|
__exportStar(require("./json_field"), exports);
|
|
29
36
|
__exportStar(require("./struct_field"), exports);
|
package/schema/json_field.d.ts
CHANGED
|
@@ -4,14 +4,26 @@ export interface JSONOptions extends FieldOptions {
|
|
|
4
4
|
validator?: (val: any) => boolean;
|
|
5
5
|
importType?: ImportType;
|
|
6
6
|
}
|
|
7
|
+
interface allJSONOptions extends JSONOptions {
|
|
8
|
+
jsonAsList?: boolean;
|
|
9
|
+
}
|
|
7
10
|
export declare class JSONField extends BaseField implements Field {
|
|
8
11
|
private options?;
|
|
9
12
|
type: Type;
|
|
10
|
-
constructor(jsonb: boolean, options?:
|
|
13
|
+
constructor(jsonb: boolean, options?: allJSONOptions | undefined);
|
|
11
14
|
format(val: any): string;
|
|
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,6 +16,11 @@ 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
25
|
format(val) {
|
|
21
26
|
return JSON.stringify(val);
|
|
@@ -38,11 +43,33 @@ function JSONBType(options) {
|
|
|
38
43
|
return Object.assign(result, options);
|
|
39
44
|
}
|
|
40
45
|
exports.JSONBType = JSONBType;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated use JSONBTypeAsList
|
|
48
|
+
*/
|
|
41
49
|
function JSONBListType(options) {
|
|
42
50
|
return new field_1.ListField(JSONBType(options), options);
|
|
43
51
|
}
|
|
44
52
|
exports.JSONBListType = JSONBListType;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use JSONTypeAsList
|
|
55
|
+
*/
|
|
45
56
|
function JSONListType(options) {
|
|
46
57
|
return new field_1.ListField(JSONType(options), options);
|
|
47
58
|
}
|
|
48
59
|
exports.JSONListType = JSONListType;
|
|
60
|
+
function JSONBTypeAsList(options) {
|
|
61
|
+
let result = new JSONField(true, {
|
|
62
|
+
...options,
|
|
63
|
+
jsonAsList: true,
|
|
64
|
+
});
|
|
65
|
+
return Object.assign(result, options);
|
|
66
|
+
}
|
|
67
|
+
exports.JSONBTypeAsList = JSONBTypeAsList;
|
|
68
|
+
function JSONTypeAsList(options) {
|
|
69
|
+
let result = new JSONField(false, {
|
|
70
|
+
...options,
|
|
71
|
+
jsonAsList: true,
|
|
72
|
+
});
|
|
73
|
+
return Object.assign(result, options);
|
|
74
|
+
}
|
|
75
|
+
exports.JSONTypeAsList = JSONTypeAsList;
|
package/schema/schema.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { Data, Ent, LoaderInfo } from "../core/base";
|
|
1
|
+
import { Data, Ent, LoaderInfo, PrivacyPolicy, Viewer } from "../core/base";
|
|
2
2
|
import { Builder } from "../action/action";
|
|
3
|
+
import { Clause } from "../core/clause";
|
|
4
|
+
import { AssocEdgeInput } from "../core/ent";
|
|
3
5
|
export declare type FieldMap = {
|
|
4
6
|
[key: string]: Field;
|
|
5
7
|
};
|
|
8
|
+
interface FieldInfo {
|
|
9
|
+
dbCol: string;
|
|
10
|
+
inputKey: string;
|
|
11
|
+
}
|
|
12
|
+
export declare type FieldInfoMap = {
|
|
13
|
+
[key: string]: FieldInfo;
|
|
14
|
+
};
|
|
15
|
+
export interface GlobalSchema {
|
|
16
|
+
edges?: Edge[];
|
|
17
|
+
extraEdgeFields?: FieldMap;
|
|
18
|
+
transformEdgeRead?: () => Clause;
|
|
19
|
+
transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
|
|
20
|
+
}
|
|
6
21
|
export default interface Schema {
|
|
7
22
|
fields: FieldMap | Field[];
|
|
8
23
|
tableName?: string;
|
|
@@ -61,7 +76,37 @@ export declare type Edge = AssocEdge;
|
|
|
61
76
|
export interface Pattern {
|
|
62
77
|
name: string;
|
|
63
78
|
fields: FieldMap | Field[];
|
|
79
|
+
disableMixin?: boolean;
|
|
64
80
|
edges?: Edge[];
|
|
81
|
+
transformRead?: () => Clause;
|
|
82
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
|
|
83
|
+
transformsDelete?: boolean;
|
|
84
|
+
transformsInsert?: boolean;
|
|
85
|
+
transformsUpdate?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export declare enum SQLStatementOperation {
|
|
88
|
+
Insert = "insert",
|
|
89
|
+
Update = "update",
|
|
90
|
+
Delete = "delete"
|
|
91
|
+
}
|
|
92
|
+
export interface EdgeUpdateOperation {
|
|
93
|
+
op: SQLStatementOperation;
|
|
94
|
+
edge: AssocEdgeInput;
|
|
95
|
+
}
|
|
96
|
+
export interface TransformedEdgeUpdateOperation {
|
|
97
|
+
op: SQLStatementOperation;
|
|
98
|
+
data?: Data;
|
|
99
|
+
}
|
|
100
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
101
|
+
op: SQLStatementOperation;
|
|
102
|
+
builder: Builder<TEnt, TViewer>;
|
|
103
|
+
input: Data;
|
|
104
|
+
data?: Map<string, any>;
|
|
105
|
+
}
|
|
106
|
+
export interface TransformedUpdateOperation<T extends Ent> {
|
|
107
|
+
op: SQLStatementOperation;
|
|
108
|
+
data?: Data;
|
|
109
|
+
existingEnt?: T | null;
|
|
65
110
|
}
|
|
66
111
|
export declare enum DBType {
|
|
67
112
|
UUID = "UUID",
|
|
@@ -77,6 +122,7 @@ export declare enum DBType {
|
|
|
77
122
|
JSONB = "JSONB",
|
|
78
123
|
Enum = "Enum",
|
|
79
124
|
StringEnum = "StringEnum",
|
|
125
|
+
IntEnum = "IntEnum",
|
|
80
126
|
Date = "Date",
|
|
81
127
|
Time = "Time",
|
|
82
128
|
Timetz = "Timetz",
|
|
@@ -85,10 +131,18 @@ export declare enum DBType {
|
|
|
85
131
|
export interface ImportType {
|
|
86
132
|
path: string;
|
|
87
133
|
type: string;
|
|
134
|
+
[x: string]: any;
|
|
135
|
+
}
|
|
136
|
+
export interface ConvertType {
|
|
137
|
+
path: string;
|
|
138
|
+
function: string;
|
|
88
139
|
}
|
|
89
140
|
declare type EnumMap = {
|
|
90
141
|
[key: string]: string;
|
|
91
142
|
};
|
|
143
|
+
declare type IntEnumMap = {
|
|
144
|
+
[key: string]: number;
|
|
145
|
+
};
|
|
92
146
|
export interface Type {
|
|
93
147
|
dbType: DBType;
|
|
94
148
|
listElemType?: Type;
|
|
@@ -96,9 +150,12 @@ export interface Type {
|
|
|
96
150
|
graphQLType?: string;
|
|
97
151
|
values?: string[];
|
|
98
152
|
enumMap?: EnumMap;
|
|
153
|
+
intEnumMap?: IntEnumMap;
|
|
154
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
99
155
|
importType?: ImportType;
|
|
100
156
|
subFields?: FieldMap;
|
|
101
157
|
unionFields?: FieldMap;
|
|
158
|
+
[x: string]: any;
|
|
102
159
|
}
|
|
103
160
|
export interface ForeignKey {
|
|
104
161
|
schema: string;
|
|
@@ -106,6 +163,7 @@ export interface ForeignKey {
|
|
|
106
163
|
name?: string;
|
|
107
164
|
disableIndex?: boolean;
|
|
108
165
|
disableBuilderType?: boolean;
|
|
166
|
+
[x: string]: any;
|
|
109
167
|
}
|
|
110
168
|
declare type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
111
169
|
export interface InverseFieldEdge {
|
|
@@ -121,13 +179,16 @@ export interface FieldEdge {
|
|
|
121
179
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
122
180
|
disableBuilderType?: boolean;
|
|
123
181
|
}
|
|
182
|
+
interface PrivateOptions {
|
|
183
|
+
exposeToActions?: boolean;
|
|
184
|
+
}
|
|
124
185
|
export interface FieldOptions {
|
|
125
186
|
nullable?: boolean;
|
|
126
187
|
storageKey?: string;
|
|
127
188
|
serverDefault?: any;
|
|
128
189
|
unique?: boolean;
|
|
129
190
|
hideFromGraphQL?: boolean;
|
|
130
|
-
private?: boolean;
|
|
191
|
+
private?: boolean | PrivateOptions;
|
|
131
192
|
sensitive?: boolean;
|
|
132
193
|
graphqlName?: string;
|
|
133
194
|
index?: boolean;
|
|
@@ -135,12 +196,16 @@ export interface FieldOptions {
|
|
|
135
196
|
fieldEdge?: FieldEdge;
|
|
136
197
|
primaryKey?: boolean;
|
|
137
198
|
disableUserEditable?: boolean;
|
|
199
|
+
disableUserGraphQLEditable?: boolean;
|
|
138
200
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
139
201
|
defaultToViewerOnCreate?: boolean;
|
|
140
202
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
141
203
|
derivedWhenEmbedded?: boolean;
|
|
142
204
|
polymorphic?: boolean | PolymorphicOptions;
|
|
205
|
+
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
143
206
|
getDerivedFields?(name: string): FieldMap;
|
|
207
|
+
convert?: ConvertType;
|
|
208
|
+
fetchOnDemand?: boolean;
|
|
144
209
|
[x: string]: any;
|
|
145
210
|
}
|
|
146
211
|
export interface PolymorphicOptions {
|
|
@@ -158,7 +223,20 @@ export interface SchemaConstructor {
|
|
|
158
223
|
new (): Schema;
|
|
159
224
|
}
|
|
160
225
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
226
|
+
export declare function getSchema(value: SchemaInputType): Schema;
|
|
161
227
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
228
|
+
/**
|
|
229
|
+
* @deprecated should only be used by tests
|
|
230
|
+
*/
|
|
231
|
+
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
232
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
233
|
+
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
234
|
+
interface objectLoaderOptions {
|
|
235
|
+
clause?: () => Clause | undefined;
|
|
236
|
+
instanceKey?: string;
|
|
237
|
+
}
|
|
238
|
+
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
239
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
162
240
|
export declare enum ActionOperation {
|
|
163
241
|
Create = 1,
|
|
164
242
|
Edit = 2,
|
|
@@ -177,6 +255,7 @@ export interface ActionField {
|
|
|
177
255
|
list?: boolean;
|
|
178
256
|
actionName?: string;
|
|
179
257
|
excludedFields?: string[];
|
|
258
|
+
[x: string]: any;
|
|
180
259
|
}
|
|
181
260
|
export interface Action {
|
|
182
261
|
operation: ActionOperation;
|
|
@@ -190,6 +269,7 @@ export interface Action {
|
|
|
190
269
|
optionalFields?: string[];
|
|
191
270
|
requiredFields?: string[];
|
|
192
271
|
noFields?: boolean;
|
|
272
|
+
[x: string]: any;
|
|
193
273
|
}
|
|
194
274
|
export declare const NoFields = "__NO_FIELDS__";
|
|
195
275
|
export declare function requiredField(field: string): string;
|
|
@@ -200,16 +280,35 @@ export interface Constraint {
|
|
|
200
280
|
columns: string[];
|
|
201
281
|
fkey?: ForeignKeyInfo;
|
|
202
282
|
condition?: string;
|
|
283
|
+
[x: string]: any;
|
|
284
|
+
}
|
|
285
|
+
export interface FullTextWeight {
|
|
286
|
+
A?: string[];
|
|
287
|
+
B?: string[];
|
|
288
|
+
C?: string[];
|
|
289
|
+
D?: string[];
|
|
290
|
+
}
|
|
291
|
+
export interface FullText {
|
|
292
|
+
generatedColumnName?: string;
|
|
293
|
+
language?: "english" | "french" | "german" | "simple";
|
|
294
|
+
languageColumn?: string;
|
|
295
|
+
indexType?: "gin" | "gist";
|
|
296
|
+
weights?: FullTextWeight;
|
|
297
|
+
[x: string]: any;
|
|
203
298
|
}
|
|
204
299
|
export interface Index {
|
|
205
300
|
name: string;
|
|
206
301
|
columns: string[];
|
|
207
302
|
unique?: boolean;
|
|
303
|
+
fulltext?: FullText;
|
|
304
|
+
indexType?: "gin" | "btree";
|
|
305
|
+
[x: string]: any;
|
|
208
306
|
}
|
|
209
307
|
export interface ForeignKeyInfo {
|
|
210
308
|
tableName: string;
|
|
211
309
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
212
310
|
columns: string[];
|
|
311
|
+
[x: string]: any;
|
|
213
312
|
}
|
|
214
313
|
export declare enum ConstraintType {
|
|
215
314
|
PrimaryKey = "primary",
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getFields = exports.DBType = void 0;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
|
+
const snake_case_1 = require("snake-case");
|
|
5
|
+
// we also want this transformation to exist on a per-action basis
|
|
6
|
+
// if it exists on an action, we don't do the global schema transformation
|
|
7
|
+
var SQLStatementOperation;
|
|
8
|
+
(function (SQLStatementOperation) {
|
|
9
|
+
// transform insert e.g. to an update based on whatever logic
|
|
10
|
+
SQLStatementOperation["Insert"] = "insert";
|
|
11
|
+
// // transform select e.g. deleted_at. can't change from select to different query type
|
|
12
|
+
// // but can change the query
|
|
13
|
+
// Select = "select",
|
|
14
|
+
// e.g. change updated value
|
|
15
|
+
SQLStatementOperation["Update"] = "update";
|
|
16
|
+
// delete -> update theoretically e.g. deleted_at
|
|
17
|
+
SQLStatementOperation["Delete"] = "delete";
|
|
18
|
+
})(SQLStatementOperation = exports.SQLStatementOperation || (exports.SQLStatementOperation = {}));
|
|
4
19
|
// we want --strictNullChecks flag so nullable is used to type graphql, ts, db
|
|
5
20
|
// should eventually generate (boolean | null) etc
|
|
6
21
|
// supported db types
|
|
@@ -20,6 +35,7 @@ var DBType;
|
|
|
20
35
|
DBType["JSONB"] = "JSONB";
|
|
21
36
|
DBType["Enum"] = "Enum";
|
|
22
37
|
DBType["StringEnum"] = "StringEnum";
|
|
38
|
+
DBType["IntEnum"] = "IntEnum";
|
|
23
39
|
DBType["Date"] = "Date";
|
|
24
40
|
DBType["Time"] = "Time";
|
|
25
41
|
DBType["Timetz"] = "Timetz";
|
|
@@ -28,14 +44,17 @@ var DBType;
|
|
|
28
44
|
function isSchema(value) {
|
|
29
45
|
return value.fields !== undefined;
|
|
30
46
|
}
|
|
31
|
-
function
|
|
32
|
-
let schema;
|
|
47
|
+
function getSchema(value) {
|
|
33
48
|
if (isSchema(value)) {
|
|
34
|
-
|
|
49
|
+
return value;
|
|
35
50
|
}
|
|
36
51
|
else {
|
|
37
|
-
|
|
52
|
+
return new value();
|
|
38
53
|
}
|
|
54
|
+
}
|
|
55
|
+
exports.getSchema = getSchema;
|
|
56
|
+
function getFields(value) {
|
|
57
|
+
const schema = getSchema(value);
|
|
39
58
|
function addFields(fields) {
|
|
40
59
|
if (Array.isArray(fields)) {
|
|
41
60
|
for (const field of fields) {
|
|
@@ -68,6 +87,109 @@ function getFields(value) {
|
|
|
68
87
|
return m;
|
|
69
88
|
}
|
|
70
89
|
exports.getFields = getFields;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated should only be used by tests
|
|
92
|
+
*/
|
|
93
|
+
function getStorageKey(field, fieldName) {
|
|
94
|
+
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
95
|
+
}
|
|
96
|
+
exports.getStorageKey = getStorageKey;
|
|
97
|
+
// returns a mapping of storage key to field privacy
|
|
98
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
99
|
+
const schema = getSchema(value);
|
|
100
|
+
function addFields(fields) {
|
|
101
|
+
if (Array.isArray(fields)) {
|
|
102
|
+
for (const field of fields) {
|
|
103
|
+
const name = field.name;
|
|
104
|
+
if (!field.name) {
|
|
105
|
+
throw new Error(`name required`);
|
|
106
|
+
}
|
|
107
|
+
if (field.getDerivedFields !== undefined) {
|
|
108
|
+
addFields(field.getDerivedFields(name));
|
|
109
|
+
}
|
|
110
|
+
if (field.privacyPolicy) {
|
|
111
|
+
let privacyPolicy;
|
|
112
|
+
if (typeof field.privacyPolicy === "function") {
|
|
113
|
+
privacyPolicy = field.privacyPolicy();
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
privacyPolicy = field.privacyPolicy;
|
|
117
|
+
}
|
|
118
|
+
const info = fieldMap[name];
|
|
119
|
+
if (!info) {
|
|
120
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
121
|
+
}
|
|
122
|
+
m.set(info.dbCol, privacyPolicy);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (const name in fields) {
|
|
128
|
+
const field = fields[name];
|
|
129
|
+
if (field.getDerivedFields !== undefined) {
|
|
130
|
+
addFields(field.getDerivedFields(name));
|
|
131
|
+
}
|
|
132
|
+
if (field.privacyPolicy) {
|
|
133
|
+
let privacyPolicy;
|
|
134
|
+
if (typeof field.privacyPolicy === "function") {
|
|
135
|
+
privacyPolicy = field.privacyPolicy();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
privacyPolicy = field.privacyPolicy;
|
|
139
|
+
}
|
|
140
|
+
const info = fieldMap[name];
|
|
141
|
+
if (!info) {
|
|
142
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
143
|
+
}
|
|
144
|
+
m.set(info.dbCol, privacyPolicy);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
let m = new Map();
|
|
149
|
+
if (schema.patterns) {
|
|
150
|
+
for (const pattern of schema.patterns) {
|
|
151
|
+
addFields(pattern.fields);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
addFields(schema.fields);
|
|
155
|
+
return m;
|
|
156
|
+
}
|
|
157
|
+
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
158
|
+
function getTransformedReadClause(value) {
|
|
159
|
+
const schema = getSchema(value);
|
|
160
|
+
if (!schema.patterns) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
for (const p of schema.patterns) {
|
|
164
|
+
// e.g. discarded_at, deleted_at, etc
|
|
165
|
+
if (p.transformRead) {
|
|
166
|
+
// return clause.Eq('deleted_at', null);
|
|
167
|
+
return p.transformRead();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
exports.getTransformedReadClause = getTransformedReadClause;
|
|
173
|
+
function getObjectLoaderProperties(value, tableName) {
|
|
174
|
+
return {
|
|
175
|
+
clause: () => getTransformedReadClause(value),
|
|
176
|
+
instanceKey: `${tableName}:transformedReadClause`,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
180
|
+
function getTransformedUpdateOp(value, stmt) {
|
|
181
|
+
const schema = getSchema(value);
|
|
182
|
+
if (!schema.patterns) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
for (const p of schema.patterns) {
|
|
186
|
+
if (p.transformWrite) {
|
|
187
|
+
return p.transformWrite(stmt);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
71
193
|
// this maps to ActionOperation in ent/action.go
|
|
72
194
|
var ActionOperation;
|
|
73
195
|
(function (ActionOperation) {
|
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,6 +1,6 @@
|
|
|
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
4
|
const field_1 = require("./field");
|
|
5
5
|
const schema_1 = require("./schema");
|
|
6
6
|
const camel_case_1 = require("camel-case");
|
|
@@ -17,11 +17,16 @@ class StructField extends field_1.BaseField {
|
|
|
17
17
|
if (options.jsonNotJSONB) {
|
|
18
18
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
19
|
}
|
|
20
|
+
if (options?.jsonAsList) {
|
|
21
|
+
this.type.listElemType = {
|
|
22
|
+
dbType: schema_1.DBType.JSONB,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
// right now, we store things in the db in lowerCase format
|
|
22
27
|
// this will lead to issues if field changes.
|
|
23
28
|
// TODO: use storageKey and convert back...
|
|
24
|
-
|
|
29
|
+
formatImpl(obj, nested) {
|
|
25
30
|
if (!(obj instanceof Object)) {
|
|
26
31
|
throw new Error("valid was not called");
|
|
27
32
|
}
|
|
@@ -47,13 +52,23 @@ class StructField extends field_1.BaseField {
|
|
|
47
52
|
ret[dbKey] = val;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
// don't json.stringify if nested
|
|
55
|
+
// don't json.stringify if nested or list
|
|
51
56
|
if (nested) {
|
|
52
57
|
return ret;
|
|
53
58
|
}
|
|
54
59
|
return JSON.stringify(ret);
|
|
55
60
|
}
|
|
56
|
-
|
|
61
|
+
format(obj, nested) {
|
|
62
|
+
if (Array.isArray(obj) && this.options.jsonAsList) {
|
|
63
|
+
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
64
|
+
if (nested) {
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
return JSON.stringify(ret);
|
|
68
|
+
}
|
|
69
|
+
return this.formatImpl(obj, nested);
|
|
70
|
+
}
|
|
71
|
+
async validImpl(obj) {
|
|
57
72
|
if (!(obj instanceof Object)) {
|
|
58
73
|
return false;
|
|
59
74
|
}
|
|
@@ -89,6 +104,19 @@ class StructField extends field_1.BaseField {
|
|
|
89
104
|
const ret = await Promise.all(promises);
|
|
90
105
|
return ret.every((v) => v);
|
|
91
106
|
}
|
|
107
|
+
async valid(obj) {
|
|
108
|
+
if (this.options.jsonAsList) {
|
|
109
|
+
if (!Array.isArray(obj)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const valid = await Promise.all(obj.map((v) => this.validImpl(v)));
|
|
113
|
+
return valid.every((b) => b);
|
|
114
|
+
}
|
|
115
|
+
if (!(obj instanceof Object)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return this.validImpl(obj);
|
|
119
|
+
}
|
|
92
120
|
}
|
|
93
121
|
exports.StructField = StructField;
|
|
94
122
|
function StructType(options) {
|
|
@@ -96,7 +124,18 @@ function StructType(options) {
|
|
|
96
124
|
return Object.assign(result, options);
|
|
97
125
|
}
|
|
98
126
|
exports.StructType = StructType;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated use StructTypeAsList
|
|
129
|
+
*/
|
|
99
130
|
function StructListType(options) {
|
|
100
131
|
return new field_1.ListField(StructType(options), options);
|
|
101
132
|
}
|
|
102
133
|
exports.StructListType = StructListType;
|
|
134
|
+
function StructTypeAsList(options) {
|
|
135
|
+
let result = new StructField({
|
|
136
|
+
...options,
|
|
137
|
+
jsonAsList: true,
|
|
138
|
+
});
|
|
139
|
+
return Object.assign(result, options);
|
|
140
|
+
}
|
|
141
|
+
exports.StructTypeAsList = StructTypeAsList;
|