@snowtop/ent 0.1.0-alpha15 → 0.1.0-alpha150
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 +90 -23
- 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 +38 -12
- package/action/orchestrator.js +427 -102
- 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 +15 -1
- package/core/config.js +10 -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 +68 -94
- package/core/ent.js +535 -586
- 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 +10 -13
- 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 +54 -13
- 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 +88 -0
- package/core/query/custom_query.d.ts +17 -2
- package/core/query/custom_query.js +88 -13
- package/core/query/index.d.ts +1 -0
- package/core/query/index.js +3 -1
- package/core/query/query.d.ts +15 -3
- package/core/query/query.js +128 -53
- package/core/query/shared_assoc_test.d.ts +2 -1
- package/core/query/shared_assoc_test.js +44 -54
- package/core/query/shared_test.d.ts +8 -1
- package/core/query/shared_test.js +532 -236
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +3 -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 +7 -2
- package/imports/index.js +20 -5
- 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 +179 -32
- package/schema/base_schema.d.ts +13 -3
- package/schema/base_schema.js +13 -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 +7 -2
- package/schema/json_field.d.ts +16 -4
- package/schema/json_field.js +32 -2
- package/schema/schema.d.ts +109 -20
- package/schema/schema.js +42 -53
- 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 +12 -8
- package/scripts/custom_graphql.js +145 -34
- package/scripts/migrate_v0.1.js +36 -0
- package/scripts/move_types.js +120 -0
- package/scripts/read_schema.js +22 -7
- 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} +32 -8
- package/testutils/db/{test_db.js → temp_db.js} +244 -48
- 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 -9
- 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 +56 -26
- 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 +29 -13
- 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 +182 -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/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -10,11 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
17
|
+
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.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getFields = exports.DBType = void 0;
|
|
14
18
|
var schema_1 = require("./schema");
|
|
15
19
|
Object.defineProperty(exports, "DBType", { enumerable: true, get: function () { return schema_1.DBType; } });
|
|
16
20
|
Object.defineProperty(exports, "getFields", { enumerable: true, get: function () { return schema_1.getFields; } });
|
|
17
21
|
Object.defineProperty(exports, "getFieldsWithPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithPrivacy; } });
|
|
22
|
+
Object.defineProperty(exports, "getFieldsWithEditPrivacy", { enumerable: true, get: function () { return schema_1.getFieldsWithEditPrivacy; } });
|
|
18
23
|
Object.defineProperty(exports, "getStorageKey", { enumerable: true, get: function () { return schema_1.getStorageKey; } });
|
|
19
24
|
Object.defineProperty(exports, "ActionOperation", { enumerable: true, get: function () { return schema_1.ActionOperation; } });
|
|
20
25
|
Object.defineProperty(exports, "NoFields", { enumerable: true, get: function () { return schema_1.NoFields; } });
|
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,10 @@ export default interface Schema {
|
|
|
25
38
|
constraints?: Constraint[];
|
|
26
39
|
indices?: Index[];
|
|
27
40
|
hideFromGraphQL?: boolean;
|
|
41
|
+
customGraphQLInterfaces?: string[];
|
|
42
|
+
supportUpsert?: boolean;
|
|
43
|
+
showCanViewerSee?: boolean;
|
|
44
|
+
showCanViewerEdit?: boolean;
|
|
28
45
|
}
|
|
29
46
|
export interface AssocEdge {
|
|
30
47
|
name: string;
|
|
@@ -43,6 +60,7 @@ export interface EdgeAction {
|
|
|
43
60
|
hideFromGraphQL?: boolean;
|
|
44
61
|
graphQLName?: string;
|
|
45
62
|
actionOnlyFields?: ActionField[];
|
|
63
|
+
canViewerDo?: boolean | CanViewerDo;
|
|
46
64
|
}
|
|
47
65
|
export interface InverseAssocEdge {
|
|
48
66
|
name: string;
|
|
@@ -54,6 +72,7 @@ export interface EdgeGroupAction {
|
|
|
54
72
|
hideFromGraphQL?: boolean;
|
|
55
73
|
graphQLName?: string;
|
|
56
74
|
actionOnlyFields?: ActionField[];
|
|
75
|
+
canViewerDo?: boolean | CanViewerDo;
|
|
57
76
|
}
|
|
58
77
|
export interface AssocEdgeGroup {
|
|
59
78
|
name: string;
|
|
@@ -61,18 +80,30 @@ export interface AssocEdgeGroup {
|
|
|
61
80
|
tableName?: string;
|
|
62
81
|
assocEdges: AssocEdge[];
|
|
63
82
|
statusEnums?: string[];
|
|
64
|
-
|
|
83
|
+
viewerBased?: boolean;
|
|
84
|
+
nullStates?: string | string[];
|
|
65
85
|
nullStateFn?: string;
|
|
66
86
|
edgeAction?: EdgeGroupAction;
|
|
67
87
|
}
|
|
68
|
-
export
|
|
88
|
+
export type Edge = AssocEdge;
|
|
89
|
+
interface ImportPath {
|
|
90
|
+
importPath: string;
|
|
91
|
+
import: string;
|
|
92
|
+
defaultImport?: boolean;
|
|
93
|
+
originalImport?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface TransformReadBetaResult {
|
|
96
|
+
code: string;
|
|
97
|
+
imports: ImportPath[];
|
|
98
|
+
}
|
|
69
99
|
export interface Pattern {
|
|
70
100
|
name: string;
|
|
71
|
-
fields: FieldMap
|
|
101
|
+
fields: FieldMap;
|
|
72
102
|
disableMixin?: boolean;
|
|
73
103
|
edges?: Edge[];
|
|
74
104
|
transformRead?: () => Clause;
|
|
75
|
-
|
|
105
|
+
transformReadCodegen_BETA?: () => string | TransformReadBetaResult;
|
|
106
|
+
transformWrite?: <T extends Ent<TViewer>, TViewer extends Viewer = Viewer>(stmt: UpdateOperation<T, TViewer>) => TransformedUpdateOperation<T, TViewer> | null;
|
|
76
107
|
transformsDelete?: boolean;
|
|
77
108
|
transformsInsert?: boolean;
|
|
78
109
|
transformsUpdate?: boolean;
|
|
@@ -82,16 +113,25 @@ export declare enum SQLStatementOperation {
|
|
|
82
113
|
Update = "update",
|
|
83
114
|
Delete = "delete"
|
|
84
115
|
}
|
|
85
|
-
export interface
|
|
116
|
+
export interface EdgeUpdateOperation {
|
|
117
|
+
op: SQLStatementOperation;
|
|
118
|
+
edge: AssocEdgeInput;
|
|
119
|
+
}
|
|
120
|
+
export interface TransformedEdgeUpdateOperation {
|
|
86
121
|
op: SQLStatementOperation;
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
data?: Data;
|
|
123
|
+
}
|
|
124
|
+
export interface UpdateOperation<TEnt extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
125
|
+
op: SQLStatementOperation;
|
|
126
|
+
builder: Builder<TEnt, TViewer, any>;
|
|
127
|
+
input: Data;
|
|
89
128
|
data?: Map<string, any>;
|
|
90
129
|
}
|
|
91
|
-
export interface TransformedUpdateOperation<T extends Ent> {
|
|
130
|
+
export interface TransformedUpdateOperation<T extends Ent<TViewer>, TViewer extends Viewer = Viewer> {
|
|
92
131
|
op: SQLStatementOperation;
|
|
93
132
|
data?: Data;
|
|
94
133
|
existingEnt?: T | null;
|
|
134
|
+
changeset?(): Promise<Changeset> | Changeset;
|
|
95
135
|
}
|
|
96
136
|
export declare enum DBType {
|
|
97
137
|
UUID = "UUID",
|
|
@@ -107,19 +147,27 @@ export declare enum DBType {
|
|
|
107
147
|
JSONB = "JSONB",
|
|
108
148
|
Enum = "Enum",
|
|
109
149
|
StringEnum = "StringEnum",
|
|
150
|
+
IntEnum = "IntEnum",
|
|
110
151
|
Date = "Date",
|
|
111
152
|
Time = "Time",
|
|
112
153
|
Timetz = "Timetz",
|
|
113
154
|
List = "List"
|
|
114
155
|
}
|
|
115
|
-
export interface
|
|
156
|
+
export interface DeprecatedImportType {
|
|
116
157
|
path: string;
|
|
117
158
|
type: string;
|
|
118
159
|
[x: string]: any;
|
|
119
160
|
}
|
|
161
|
+
export interface ConvertType {
|
|
162
|
+
path: string;
|
|
163
|
+
function: string;
|
|
164
|
+
}
|
|
120
165
|
declare type EnumMap = {
|
|
121
166
|
[key: string]: string;
|
|
122
167
|
};
|
|
168
|
+
declare type IntEnumMap = {
|
|
169
|
+
[key: string]: number;
|
|
170
|
+
};
|
|
123
171
|
export interface Type {
|
|
124
172
|
dbType: DBType;
|
|
125
173
|
listElemType?: Type;
|
|
@@ -127,9 +175,14 @@ export interface Type {
|
|
|
127
175
|
graphQLType?: string;
|
|
128
176
|
values?: string[];
|
|
129
177
|
enumMap?: EnumMap;
|
|
130
|
-
|
|
178
|
+
intEnumMap?: IntEnumMap;
|
|
179
|
+
deprecatedIntEnumMap?: IntEnumMap;
|
|
180
|
+
disableUnknownType?: boolean;
|
|
181
|
+
globalType?: string;
|
|
182
|
+
importType?: DeprecatedImportType;
|
|
131
183
|
subFields?: FieldMap;
|
|
132
184
|
unionFields?: FieldMap;
|
|
185
|
+
[x: string]: any;
|
|
133
186
|
}
|
|
134
187
|
export interface ForeignKey {
|
|
135
188
|
schema: string;
|
|
@@ -137,20 +190,29 @@ export interface ForeignKey {
|
|
|
137
190
|
name?: string;
|
|
138
191
|
disableIndex?: boolean;
|
|
139
192
|
disableBuilderType?: boolean;
|
|
193
|
+
[x: string]: any;
|
|
140
194
|
}
|
|
141
|
-
|
|
195
|
+
type getLoaderInfoFn = (type: string) => LoaderInfo;
|
|
142
196
|
export interface InverseFieldEdge {
|
|
143
197
|
name: string;
|
|
144
198
|
edgeConstName?: string;
|
|
145
199
|
tableName?: string;
|
|
146
200
|
hideFromGraphQL?: boolean;
|
|
147
201
|
}
|
|
202
|
+
export interface IndexEdgeOptions {
|
|
203
|
+
name: string;
|
|
204
|
+
}
|
|
148
205
|
export interface FieldEdge {
|
|
149
206
|
schema: string;
|
|
150
207
|
inverseEdge?: string | InverseFieldEdge;
|
|
208
|
+
indexEdge?: IndexEdgeOptions;
|
|
151
209
|
enforceSchema?: boolean;
|
|
152
210
|
getLoaderInfoFromSchema?: getLoaderInfoFn;
|
|
153
211
|
disableBuilderType?: boolean;
|
|
212
|
+
edgeConstName?: string;
|
|
213
|
+
}
|
|
214
|
+
interface PrivateOptions {
|
|
215
|
+
exposeToActions?: boolean;
|
|
154
216
|
}
|
|
155
217
|
export interface FieldOptions {
|
|
156
218
|
nullable?: boolean;
|
|
@@ -158,53 +220,66 @@ export interface FieldOptions {
|
|
|
158
220
|
serverDefault?: any;
|
|
159
221
|
unique?: boolean;
|
|
160
222
|
hideFromGraphQL?: boolean;
|
|
161
|
-
private?: boolean;
|
|
223
|
+
private?: boolean | PrivateOptions;
|
|
162
224
|
sensitive?: boolean;
|
|
163
225
|
graphqlName?: string;
|
|
164
226
|
index?: boolean;
|
|
165
227
|
foreignKey?: ForeignKey;
|
|
166
228
|
fieldEdge?: FieldEdge;
|
|
167
229
|
primaryKey?: boolean;
|
|
230
|
+
immutable?: boolean;
|
|
168
231
|
disableUserEditable?: boolean;
|
|
169
232
|
disableUserGraphQLEditable?: boolean;
|
|
170
233
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
171
234
|
defaultToViewerOnCreate?: boolean;
|
|
235
|
+
onlyUpdateIfOtherFieldsBeingSet_BETA?: boolean;
|
|
172
236
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
173
237
|
derivedWhenEmbedded?: boolean;
|
|
174
238
|
polymorphic?: boolean | PolymorphicOptions;
|
|
175
239
|
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
240
|
+
editPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
241
|
+
createOnlyOverrideEditPrivacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
176
242
|
getDerivedFields?(name: string): FieldMap;
|
|
243
|
+
convert?: ConvertType;
|
|
244
|
+
fetchOnDemand?: boolean;
|
|
245
|
+
dbOnly?: boolean;
|
|
177
246
|
[x: string]: any;
|
|
178
247
|
}
|
|
179
248
|
export interface PolymorphicOptions {
|
|
249
|
+
name?: string;
|
|
180
250
|
types?: string[];
|
|
181
251
|
hideFromInverseGraphQL?: boolean;
|
|
182
252
|
disableBuilderType?: boolean;
|
|
253
|
+
serverDefault?: any;
|
|
254
|
+
edgeConstName?: string;
|
|
183
255
|
}
|
|
184
256
|
export interface Field extends FieldOptions {
|
|
185
257
|
type: Type;
|
|
186
258
|
valid?(val: any): Promise<boolean> | boolean;
|
|
259
|
+
validateWithFullData?(val: any, builder: Builder<any>): boolean | Promise<boolean>;
|
|
187
260
|
format?(val: any, nested?: boolean): any;
|
|
188
261
|
logValue(val: any): any;
|
|
189
262
|
}
|
|
190
263
|
export interface SchemaConstructor {
|
|
191
264
|
new (): Schema;
|
|
192
265
|
}
|
|
193
|
-
export
|
|
266
|
+
export type SchemaInputType = Schema | SchemaConstructor;
|
|
194
267
|
export declare function getSchema(value: SchemaInputType): Schema;
|
|
195
268
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
196
269
|
/**
|
|
197
270
|
* @deprecated should only be used by tests
|
|
198
271
|
*/
|
|
199
272
|
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
200
|
-
export declare function getFieldsWithPrivacy(value: SchemaInputType,
|
|
273
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
274
|
+
export declare function getFieldsWithEditPrivacy(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
275
|
+
export declare function getFieldsForCreateAction(value: SchemaInputType, fieldInfoMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
201
276
|
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
202
277
|
interface objectLoaderOptions {
|
|
203
278
|
clause?: () => Clause | undefined;
|
|
204
279
|
instanceKey?: string;
|
|
205
280
|
}
|
|
206
281
|
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
207
|
-
export declare function getTransformedUpdateOp<
|
|
282
|
+
export declare function getTransformedUpdateOp<TEnt extends Ent<TViewer>, TViewer extends Viewer>(value: SchemaInputType, stmt: UpdateOperation<TEnt, TViewer>): TransformedUpdateOperation<TEnt> | null;
|
|
208
283
|
export declare enum ActionOperation {
|
|
209
284
|
Create = 1,
|
|
210
285
|
Edit = 2,
|
|
@@ -214,15 +289,18 @@ export declare enum ActionOperation {
|
|
|
214
289
|
RemoveEdge = 32,
|
|
215
290
|
EdgeGroup = 64
|
|
216
291
|
}
|
|
217
|
-
|
|
218
|
-
|
|
292
|
+
type actionFieldType = "ID" | "Boolean" | "Int" | "Float" | "String" | "Time" | "JSON" | "Object";
|
|
293
|
+
type NullableListOptions = "contents" | "contentsAndList";
|
|
219
294
|
export interface ActionField {
|
|
220
295
|
name: string;
|
|
221
296
|
type: actionFieldType;
|
|
222
297
|
nullable?: boolean | NullableListOptions;
|
|
298
|
+
optional?: boolean;
|
|
223
299
|
list?: boolean;
|
|
224
300
|
actionName?: string;
|
|
225
301
|
excludedFields?: string[];
|
|
302
|
+
hideFromGraphQL?: boolean;
|
|
303
|
+
[x: string]: any;
|
|
226
304
|
}
|
|
227
305
|
export interface Action {
|
|
228
306
|
operation: ActionOperation;
|
|
@@ -236,6 +314,12 @@ export interface Action {
|
|
|
236
314
|
optionalFields?: string[];
|
|
237
315
|
requiredFields?: string[];
|
|
238
316
|
noFields?: boolean;
|
|
317
|
+
canViewerDo?: boolean | CanViewerDo;
|
|
318
|
+
[x: string]: any;
|
|
319
|
+
}
|
|
320
|
+
export interface CanViewerDo {
|
|
321
|
+
addAllFields?: boolean;
|
|
322
|
+
inputFields?: string[];
|
|
239
323
|
}
|
|
240
324
|
export declare const NoFields = "__NO_FIELDS__";
|
|
241
325
|
export declare function requiredField(field: string): string;
|
|
@@ -246,6 +330,7 @@ export interface Constraint {
|
|
|
246
330
|
columns: string[];
|
|
247
331
|
fkey?: ForeignKeyInfo;
|
|
248
332
|
condition?: string;
|
|
333
|
+
[x: string]: any;
|
|
249
334
|
}
|
|
250
335
|
export interface FullTextWeight {
|
|
251
336
|
A?: string[];
|
|
@@ -259,17 +344,21 @@ export interface FullText {
|
|
|
259
344
|
languageColumn?: string;
|
|
260
345
|
indexType?: "gin" | "gist";
|
|
261
346
|
weights?: FullTextWeight;
|
|
347
|
+
[x: string]: any;
|
|
262
348
|
}
|
|
263
349
|
export interface Index {
|
|
264
350
|
name: string;
|
|
265
351
|
columns: string[];
|
|
266
352
|
unique?: boolean;
|
|
267
353
|
fulltext?: FullText;
|
|
354
|
+
indexType?: "gin" | "btree";
|
|
355
|
+
[x: string]: any;
|
|
268
356
|
}
|
|
269
357
|
export interface ForeignKeyInfo {
|
|
270
358
|
tableName: string;
|
|
271
359
|
ondelete?: "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT" | "NO ACTION";
|
|
272
360
|
columns: string[];
|
|
361
|
+
[x: string]: any;
|
|
273
362
|
}
|
|
274
363
|
export declare enum ConstraintType {
|
|
275
364
|
PrimaryKey = "primary",
|
package/schema/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.ConstraintType = exports.optionalField = exports.requiredField = exports.NoFields = exports.ActionOperation = exports.getTransformedUpdateOp = exports.getObjectLoaderProperties = exports.getTransformedReadClause = exports.getFieldsForCreateAction = exports.getFieldsWithEditPrivacy = exports.getFieldsWithPrivacy = exports.getStorageKey = exports.getFields = exports.getSchema = exports.DBType = exports.SQLStatementOperation = void 0;
|
|
4
4
|
const snake_case_1 = require("snake-case");
|
|
5
5
|
// we also want this transformation to exist on a per-action basis
|
|
6
6
|
// if it exists on an action, we don't do the global schema transformation
|
|
@@ -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
|
}
|
|
@@ -94,52 +85,45 @@ function getStorageKey(field, fieldName) {
|
|
|
94
85
|
}
|
|
95
86
|
exports.getStorageKey = getStorageKey;
|
|
96
87
|
// returns a mapping of storage key to field privacy
|
|
97
|
-
function getFieldsWithPrivacy(value,
|
|
88
|
+
function getFieldsWithPrivacy(value, fieldInfoMap) {
|
|
89
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["privacyPolicy"]);
|
|
90
|
+
}
|
|
91
|
+
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
92
|
+
function getFieldsWithEditPrivacy(value, fieldInfoMap) {
|
|
93
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, ["editPrivacyPolicy"]);
|
|
94
|
+
}
|
|
95
|
+
exports.getFieldsWithEditPrivacy = getFieldsWithEditPrivacy;
|
|
96
|
+
function getFieldsForCreateAction(value, fieldInfoMap) {
|
|
97
|
+
return getFieldsWithPrivacyImpl(value, fieldInfoMap, [
|
|
98
|
+
"createOnlyOverrideEditPrivacyPolicy",
|
|
99
|
+
"editPrivacyPolicy",
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
exports.getFieldsForCreateAction = getFieldsForCreateAction;
|
|
103
|
+
function getFieldsWithPrivacyImpl(value, fieldInfoMap, keys) {
|
|
98
104
|
const schema = getSchema(value);
|
|
99
105
|
function addFields(fields) {
|
|
100
|
-
if (Array.isArray(fields)) {
|
|
101
|
-
for (const field of fields) {
|
|
102
|
-
const name = field.name;
|
|
103
|
-
if (!field.name) {
|
|
104
|
-
throw new Error(`name required`);
|
|
105
|
-
}
|
|
106
|
-
if (field.getDerivedFields !== undefined) {
|
|
107
|
-
addFields(field.getDerivedFields(name));
|
|
108
|
-
}
|
|
109
|
-
if (field.privacyPolicy) {
|
|
110
|
-
let privacyPolicy;
|
|
111
|
-
if (typeof field.privacyPolicy === "function") {
|
|
112
|
-
privacyPolicy = field.privacyPolicy();
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
privacyPolicy = field.privacyPolicy;
|
|
116
|
-
}
|
|
117
|
-
const info = fieldMap[name];
|
|
118
|
-
if (!info) {
|
|
119
|
-
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
120
|
-
}
|
|
121
|
-
m.set(info.dbCol, privacyPolicy);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
106
|
for (const name in fields) {
|
|
126
107
|
const field = fields[name];
|
|
108
|
+
if (field.dbOnly) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
127
111
|
if (field.getDerivedFields !== undefined) {
|
|
128
112
|
addFields(field.getDerivedFields(name));
|
|
129
113
|
}
|
|
130
|
-
|
|
131
|
-
let privacyPolicy;
|
|
132
|
-
if (
|
|
133
|
-
privacyPolicy
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
114
|
+
for (const key of keys) {
|
|
115
|
+
let privacyPolicy = field[key];
|
|
116
|
+
if (privacyPolicy) {
|
|
117
|
+
if (typeof privacyPolicy === "function") {
|
|
118
|
+
privacyPolicy = privacyPolicy();
|
|
119
|
+
}
|
|
120
|
+
const info = fieldInfoMap[name];
|
|
121
|
+
if (!info) {
|
|
122
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
123
|
+
}
|
|
124
|
+
m.set(info.dbCol, privacyPolicy);
|
|
125
|
+
break;
|
|
141
126
|
}
|
|
142
|
-
m.set(info.dbCol, privacyPolicy);
|
|
143
127
|
}
|
|
144
128
|
}
|
|
145
129
|
}
|
|
@@ -152,7 +136,6 @@ function getFieldsWithPrivacy(value, fieldMap) {
|
|
|
152
136
|
addFields(schema.fields);
|
|
153
137
|
return m;
|
|
154
138
|
}
|
|
155
|
-
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
156
139
|
function getTransformedReadClause(value) {
|
|
157
140
|
const schema = getSchema(value);
|
|
158
141
|
if (!schema.patterns) {
|
|
@@ -168,6 +151,9 @@ function getTransformedReadClause(value) {
|
|
|
168
151
|
return;
|
|
169
152
|
}
|
|
170
153
|
exports.getTransformedReadClause = getTransformedReadClause;
|
|
154
|
+
// would like to avoid calling this so that itwe don't run into circular dependencies
|
|
155
|
+
// but the fact that it returns a clause makes it hard since we don't control the patterns...
|
|
156
|
+
// we can make each clause return a format that can be extrapolated and used in codegen...
|
|
171
157
|
function getObjectLoaderProperties(value, tableName) {
|
|
172
158
|
return {
|
|
173
159
|
clause: () => getTransformedReadClause(value),
|
|
@@ -209,6 +195,9 @@ var ActionOperation;
|
|
|
209
195
|
// RemoveEdge is used to provide the ability to remove an edge in an AssociationEdge.
|
|
210
196
|
ActionOperation[ActionOperation["RemoveEdge"] = 32] = "RemoveEdge";
|
|
211
197
|
// EdgeGroup is used to provide the ability to edit an edge group in an AssociationEdgeGroup.
|
|
198
|
+
// if you want to clear this edge group e.g. any set edge with id1 and id2,
|
|
199
|
+
// you should create a custom action that takes the id as an action only field,
|
|
200
|
+
// and then calls `clearEdgeTypeInGroup` in a trigger to clear
|
|
212
201
|
ActionOperation[ActionOperation["EdgeGroup"] = 64] = "EdgeGroup";
|
|
213
202
|
})(ActionOperation = exports.ActionOperation || (exports.ActionOperation = {}));
|
|
214
203
|
// 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 {};
|