@snowtop/ent 0.1.0-alpha3 → 0.1.0-alpha30
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 +21 -20
- package/action/experimental_action.js +11 -5
- package/action/orchestrator.d.ts +31 -16
- package/action/orchestrator.js +156 -43
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +25 -21
- package/core/base.js +16 -0
- package/core/clause.d.ts +24 -3
- package/core/clause.js +246 -5
- package/core/config.d.ts +23 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +2 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -3
- package/core/db.js +2 -0
- package/core/ent.d.ts +19 -21
- package/core/ent.js +76 -25
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- 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/object_loader.d.ts +10 -5
- package/core/loaders/object_loader.js +59 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/privacy.d.ts +25 -25
- package/core/privacy.js +3 -0
- 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/viewer.d.ts +4 -3
- package/core/viewer.js +4 -0
- 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 +24 -23
- package/graphql/index.d.ts +1 -0
- package/graphql/index.js +3 -1
- package/graphql/mutations/union.d.ts +2 -0
- package/graphql/mutations/union.js +35 -0
- 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 +16 -1
- package/index.js +18 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +18 -5
- package/parse_schema/parse.js +55 -6
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +1 -1
- package/schema/field.js +1 -1
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/schema.d.ts +61 -1
- package/schema/schema.js +126 -5
- package/schema/union_field.d.ts +2 -1
- package/schema/union_field.js +32 -14
- package/scripts/custom_graphql.js +122 -15
- 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 +15 -1
- package/testutils/builder.d.ts +31 -21
- package/testutils/builder.js +98 -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 +2 -1
- package/testutils/db/test_db.js +13 -4
- 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 +4 -8
- package/testutils/fake_data/fake_contact.js +15 -19
- package/testutils/fake_data/fake_event.d.ts +4 -8
- package/testutils/fake_data/fake_event.js +21 -25
- package/testutils/fake_data/fake_user.d.ts +5 -9
- package/testutils/fake_data/fake_user.js +23 -27
- package/testutils/fake_data/test_helpers.js +1 -1
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/tsc/ast.d.ts +43 -0
- package/tsc/ast.js +264 -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 +20 -0
- package/tsc/transform_action.js +169 -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 +354 -0
- package/scripts/transform_schema.js +0 -288
package/parse_schema/parse.js
CHANGED
|
@@ -22,6 +22,7 @@ function processFields(src, patternName) {
|
|
|
22
22
|
let f = { name, ...field };
|
|
23
23
|
f.hasDefaultValueOnCreate = field.defaultValueOnCreate != undefined;
|
|
24
24
|
f.hasDefaultValueOnEdit = field.defaultValueOnEdit != undefined;
|
|
25
|
+
f.hasFieldPrivacy = field.privacyPolicy !== undefined;
|
|
25
26
|
if (field.polymorphic) {
|
|
26
27
|
// convert boolean into object
|
|
27
28
|
// we keep boolean as an option to keep API simple
|
|
@@ -46,6 +47,7 @@ function processFields(src, patternName) {
|
|
|
46
47
|
if (patternName) {
|
|
47
48
|
f.patternName = patternName;
|
|
48
49
|
}
|
|
50
|
+
transformType(field.type);
|
|
49
51
|
if (field.getDerivedFields) {
|
|
50
52
|
f.derivedFields = processFields(field.getDerivedFields(name));
|
|
51
53
|
}
|
|
@@ -65,6 +67,24 @@ function processFields(src, patternName) {
|
|
|
65
67
|
}
|
|
66
68
|
return ret;
|
|
67
69
|
}
|
|
70
|
+
function transformImportType(typ) {
|
|
71
|
+
if (!typ.importType) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
typ.importType = {
|
|
75
|
+
...typ.importType,
|
|
76
|
+
// these 2 needed for forwards compatibility with new go schema
|
|
77
|
+
importPath: typ.importType.path,
|
|
78
|
+
import: typ.importType.type,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function transformType(typ) {
|
|
82
|
+
if (!typ) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
transformImportType(typ);
|
|
86
|
+
transformType(typ.listElemType);
|
|
87
|
+
}
|
|
68
88
|
function processEdges(src, patternName) {
|
|
69
89
|
const ret = [];
|
|
70
90
|
for (const edge of src) {
|
|
@@ -89,6 +109,9 @@ function processEdgeGroups(processedSchema, edgeGroups) {
|
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
111
|
function processPattern(patterns, pattern, processedSchema) {
|
|
112
|
+
let ret = {
|
|
113
|
+
...pattern,
|
|
114
|
+
};
|
|
92
115
|
const name = pattern.name;
|
|
93
116
|
const fields = processFields(pattern.fields, pattern.name);
|
|
94
117
|
processedSchema.fields.push(...fields);
|
|
@@ -96,6 +119,10 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
96
119
|
const edges = processEdges(pattern.edges, pattern.name);
|
|
97
120
|
processedSchema.assocEdges.push(...edges);
|
|
98
121
|
}
|
|
122
|
+
// flag transformsSelect
|
|
123
|
+
if (pattern.transformRead) {
|
|
124
|
+
ret.transformsSelect = true;
|
|
125
|
+
}
|
|
99
126
|
if (patterns[name] === undefined) {
|
|
100
127
|
// intentionally processing separately and not passing pattern.name
|
|
101
128
|
const edges = processEdges(pattern.edges || []);
|
|
@@ -103,12 +130,14 @@ function processPattern(patterns, pattern, processedSchema) {
|
|
|
103
130
|
name: pattern.name,
|
|
104
131
|
assocEdges: edges,
|
|
105
132
|
fields: fields,
|
|
133
|
+
disableMixin: pattern.disableMixin,
|
|
106
134
|
};
|
|
107
135
|
}
|
|
108
136
|
else {
|
|
109
137
|
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
110
138
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
111
139
|
}
|
|
140
|
+
return ret;
|
|
112
141
|
}
|
|
113
142
|
var NullableResult;
|
|
114
143
|
(function (NullableResult) {
|
|
@@ -149,14 +178,19 @@ function parseSchema(potentialSchemas) {
|
|
|
149
178
|
for (const key in potentialSchemas) {
|
|
150
179
|
const value = potentialSchemas[key];
|
|
151
180
|
let schema;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
181
|
+
const name = value.constructor.name;
|
|
182
|
+
// named class e.g. new BaseEntSchema
|
|
183
|
+
switch (name) {
|
|
184
|
+
case "Function":
|
|
185
|
+
schema = new value();
|
|
186
|
+
break;
|
|
187
|
+
default:
|
|
188
|
+
// implicit schema or named class
|
|
189
|
+
schema = value;
|
|
157
190
|
}
|
|
158
191
|
let processedSchema = {
|
|
159
192
|
fields: [],
|
|
193
|
+
schemaPath: schema.schemaPath,
|
|
160
194
|
tableName: schema.tableName,
|
|
161
195
|
enumTable: schema.enumTable,
|
|
162
196
|
dbRows: schema.dbRows,
|
|
@@ -169,13 +203,28 @@ function parseSchema(potentialSchemas) {
|
|
|
169
203
|
};
|
|
170
204
|
// let's put patterns first just so we have id, created_at, updated_at first
|
|
171
205
|
// ¯\_(ツ)_/¯
|
|
206
|
+
let patternNames = [];
|
|
172
207
|
if (schema.patterns) {
|
|
173
208
|
for (const pattern of schema.patterns) {
|
|
174
|
-
processPattern(patterns, pattern, processedSchema);
|
|
209
|
+
const ret = processPattern(patterns, pattern, processedSchema);
|
|
210
|
+
patternNames.push(pattern.name);
|
|
211
|
+
if (ret.transformsSelect) {
|
|
212
|
+
if (processedSchema.transformsSelect) {
|
|
213
|
+
throw new Error(`can only have one pattern which transforms default querying behavior`);
|
|
214
|
+
}
|
|
215
|
+
processedSchema.transformsSelect = true;
|
|
216
|
+
}
|
|
217
|
+
if (ret.transformsDelete) {
|
|
218
|
+
if (processedSchema.transformsDelete) {
|
|
219
|
+
throw new Error(`can only have one pattern which transforms default deletion behavior`);
|
|
220
|
+
}
|
|
221
|
+
processedSchema.transformsDelete = true;
|
|
222
|
+
}
|
|
175
223
|
}
|
|
176
224
|
}
|
|
177
225
|
const fields = processFields(schema.fields);
|
|
178
226
|
processedSchema.fields.push(...fields);
|
|
227
|
+
processedSchema.patternNames = patternNames;
|
|
179
228
|
if (schema.edges) {
|
|
180
229
|
const edges = processEdges(schema.edges);
|
|
181
230
|
processedSchema.assocEdges.push(...edges);
|
package/schema/base_schema.d.ts
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
|
-
import { Pattern } from "./schema";
|
|
1
|
+
import { Field, FieldMap, Pattern } from "./schema";
|
|
2
|
+
import { Action, AssocEdgeGroup, Constraint, Edge, Index, Schema } from ".";
|
|
2
3
|
export declare const Timestamps: Pattern;
|
|
3
4
|
export declare const Node: Pattern;
|
|
5
|
+
export interface SchemaConfig extends Schema {
|
|
6
|
+
}
|
|
7
|
+
export declare class EntSchema implements Schema {
|
|
8
|
+
fields: FieldMap | Field[];
|
|
9
|
+
tableName: string | undefined;
|
|
10
|
+
patterns: Pattern[];
|
|
11
|
+
edges: Edge[] | undefined;
|
|
12
|
+
edgeGroups: AssocEdgeGroup[] | undefined;
|
|
13
|
+
actions: Action[] | undefined;
|
|
14
|
+
enumTable: boolean | undefined;
|
|
15
|
+
dbRows: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
}[] | undefined;
|
|
18
|
+
constraints: Constraint[] | undefined;
|
|
19
|
+
indices: Index[] | undefined;
|
|
20
|
+
hideFromGraphQL?: boolean;
|
|
21
|
+
constructor(cfg: SchemaConfig);
|
|
22
|
+
}
|
|
23
|
+
export declare class EntSchemaWithTZ implements Schema {
|
|
24
|
+
fields: FieldMap | Field[];
|
|
25
|
+
tableName: string | undefined;
|
|
26
|
+
patterns: Pattern[];
|
|
27
|
+
edges: Edge[] | undefined;
|
|
28
|
+
edgeGroups: AssocEdgeGroup[] | undefined;
|
|
29
|
+
actions: Action[] | undefined;
|
|
30
|
+
enumTable: boolean | undefined;
|
|
31
|
+
dbRows: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}[] | undefined;
|
|
34
|
+
constraints: Constraint[] | undefined;
|
|
35
|
+
indices: Index[] | undefined;
|
|
36
|
+
hideFromGraphQL?: boolean;
|
|
37
|
+
constructor(cfg: SchemaConfig);
|
|
38
|
+
}
|
|
4
39
|
export declare abstract class BaseEntSchema {
|
|
5
40
|
addPatterns(...patterns: Pattern[]): void;
|
|
6
41
|
patterns: Pattern[];
|
package/schema/base_schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.Node = exports.Timestamps = void 0;
|
|
3
|
+
exports.BaseEntSchemaWithTZ = exports.BaseEntSchema = exports.EntSchemaWithTZ = exports.EntSchema = exports.Node = exports.Timestamps = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
let tsFields = {
|
|
@@ -66,9 +66,56 @@ let nodeFieldsWithTZ = {
|
|
|
66
66
|
exports.Node = {
|
|
67
67
|
name: "node",
|
|
68
68
|
fields: nodeFields,
|
|
69
|
+
disableMixin: true,
|
|
69
70
|
};
|
|
70
|
-
//
|
|
71
|
+
// Ent schema. has Node Pattern by default.
|
|
71
72
|
// exists just to have less typing and easier for clients to implement
|
|
73
|
+
class EntSchema {
|
|
74
|
+
constructor(cfg) {
|
|
75
|
+
this.patterns = [exports.Node];
|
|
76
|
+
this.fields = cfg.fields;
|
|
77
|
+
this.tableName = cfg.tableName;
|
|
78
|
+
if (cfg.patterns) {
|
|
79
|
+
this.patterns.push(...cfg.patterns);
|
|
80
|
+
}
|
|
81
|
+
this.edges = cfg.edges;
|
|
82
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
83
|
+
this.actions = cfg.actions;
|
|
84
|
+
this.enumTable = cfg.enumTable;
|
|
85
|
+
this.dbRows = cfg.dbRows;
|
|
86
|
+
this.constraints = cfg.constraints;
|
|
87
|
+
this.indices = cfg.indices;
|
|
88
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.EntSchema = EntSchema;
|
|
92
|
+
class EntSchemaWithTZ {
|
|
93
|
+
constructor(cfg) {
|
|
94
|
+
this.patterns = [
|
|
95
|
+
{
|
|
96
|
+
// default schema added
|
|
97
|
+
name: "nodeWithTZ",
|
|
98
|
+
fields: nodeFieldsWithTZ,
|
|
99
|
+
disableMixin: true,
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
this.fields = cfg.fields;
|
|
103
|
+
this.tableName = cfg.tableName;
|
|
104
|
+
if (cfg.patterns) {
|
|
105
|
+
this.patterns.push(...cfg.patterns);
|
|
106
|
+
}
|
|
107
|
+
this.edges = cfg.edges;
|
|
108
|
+
this.edgeGroups = cfg.edgeGroups;
|
|
109
|
+
this.actions = cfg.actions;
|
|
110
|
+
this.enumTable = cfg.enumTable;
|
|
111
|
+
this.dbRows = cfg.dbRows;
|
|
112
|
+
this.constraints = cfg.constraints;
|
|
113
|
+
this.indices = cfg.indices;
|
|
114
|
+
this.hideFromGraphQL = cfg.hideFromGraphQL;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.EntSchemaWithTZ = EntSchemaWithTZ;
|
|
118
|
+
// @deprecated use EntSchema
|
|
72
119
|
class BaseEntSchema {
|
|
73
120
|
constructor() {
|
|
74
121
|
this.patterns = [exports.Node];
|
|
@@ -78,6 +125,7 @@ class BaseEntSchema {
|
|
|
78
125
|
}
|
|
79
126
|
}
|
|
80
127
|
exports.BaseEntSchema = BaseEntSchema;
|
|
128
|
+
// @deprecated use EntSchemaWithTZ
|
|
81
129
|
class BaseEntSchemaWithTZ {
|
|
82
130
|
constructor() {
|
|
83
131
|
this.patterns = [
|
|
@@ -85,6 +133,7 @@ class BaseEntSchemaWithTZ {
|
|
|
85
133
|
// default schema added
|
|
86
134
|
name: "nodeWithTZ",
|
|
87
135
|
fields: nodeFieldsWithTZ,
|
|
136
|
+
disableMixin: true,
|
|
88
137
|
},
|
|
89
138
|
];
|
|
90
139
|
}
|
package/schema/field.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export declare function IntegerType(options?: IntegerOptions): IntegerField;
|
|
|
44
44
|
export declare class BigIntegerField extends BaseField implements Field {
|
|
45
45
|
type: Type;
|
|
46
46
|
}
|
|
47
|
-
export declare function BigIntegerType(options
|
|
47
|
+
export declare function BigIntegerType(options?: FieldOptions): BigIntegerField;
|
|
48
48
|
export declare class FloatField extends BaseField implements Field {
|
|
49
49
|
type: Type;
|
|
50
50
|
}
|
package/schema/field.js
CHANGED
|
@@ -616,7 +616,7 @@ class ListField extends BaseField {
|
|
|
616
616
|
for (let i = 0; i < val.length; i++) {
|
|
617
617
|
let formatted = val[i];
|
|
618
618
|
if (this.field.format) {
|
|
619
|
-
formatted = this.field.format(val[i]);
|
|
619
|
+
formatted = this.field.format(val[i], nested);
|
|
620
620
|
}
|
|
621
621
|
// postgres supports arrays natively so we
|
|
622
622
|
// structure it in the expected format
|
package/schema/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Schema from "./schema";
|
|
2
2
|
export { Schema };
|
|
3
|
-
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, } from "./schema";
|
|
4
|
-
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, } from "./base_schema";
|
|
3
|
+
export { Field, AssocEdge, AssocEdgeGroup, InverseAssocEdge, Edge, Pattern, DBType, Type, FieldOptions, SchemaConstructor, SchemaInputType, getFields, getFieldsWithPrivacy, getStorageKey, ActionOperation, Action, EdgeAction, NoFields, FieldMap, Constraint, Index, ConstraintType, ForeignKeyInfo, requiredField, optionalField, UpdateOperation, TransformedUpdateOperation, SQLStatementOperation, getTransformedReadClause, getObjectLoaderProperties, } from "./schema";
|
|
4
|
+
export { Timestamps, Node, BaseEntSchema, BaseEntSchemaWithTZ, EntSchema, EntSchemaWithTZ, SchemaConfig, } from "./base_schema";
|
|
5
5
|
export * from "./field";
|
|
6
6
|
export * from "./json_field";
|
|
7
7
|
export * from "./struct_field";
|
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/schema.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
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";
|
|
3
4
|
export declare type FieldMap = {
|
|
4
5
|
[key: string]: Field;
|
|
5
6
|
};
|
|
7
|
+
interface FieldInfo {
|
|
8
|
+
dbCol: string;
|
|
9
|
+
inputKey: string;
|
|
10
|
+
}
|
|
11
|
+
export declare type FieldInfoMap = {
|
|
12
|
+
[key: string]: FieldInfo;
|
|
13
|
+
};
|
|
6
14
|
export default interface Schema {
|
|
7
15
|
fields: FieldMap | Field[];
|
|
8
16
|
tableName?: string;
|
|
@@ -61,7 +69,29 @@ export declare type Edge = AssocEdge;
|
|
|
61
69
|
export interface Pattern {
|
|
62
70
|
name: string;
|
|
63
71
|
fields: FieldMap | Field[];
|
|
72
|
+
disableMixin?: boolean;
|
|
64
73
|
edges?: Edge[];
|
|
74
|
+
transformRead?: () => Clause;
|
|
75
|
+
transformWrite?: <T extends Ent>(stmt: UpdateOperation<T>) => TransformedUpdateOperation<T> | null;
|
|
76
|
+
transformsDelete?: boolean;
|
|
77
|
+
transformsInsert?: boolean;
|
|
78
|
+
transformsUpdate?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare enum SQLStatementOperation {
|
|
81
|
+
Insert = "insert",
|
|
82
|
+
Update = "update",
|
|
83
|
+
Delete = "delete"
|
|
84
|
+
}
|
|
85
|
+
export interface UpdateOperation<T extends Ent> {
|
|
86
|
+
op: SQLStatementOperation;
|
|
87
|
+
existingEnt: T | null;
|
|
88
|
+
viewer: Viewer;
|
|
89
|
+
data?: Map<string, any>;
|
|
90
|
+
}
|
|
91
|
+
export interface TransformedUpdateOperation<T extends Ent> {
|
|
92
|
+
op: SQLStatementOperation;
|
|
93
|
+
data?: Data;
|
|
94
|
+
existingEnt?: T | null;
|
|
65
95
|
}
|
|
66
96
|
export declare enum DBType {
|
|
67
97
|
UUID = "UUID",
|
|
@@ -85,6 +115,7 @@ export declare enum DBType {
|
|
|
85
115
|
export interface ImportType {
|
|
86
116
|
path: string;
|
|
87
117
|
type: string;
|
|
118
|
+
[x: string]: any;
|
|
88
119
|
}
|
|
89
120
|
declare type EnumMap = {
|
|
90
121
|
[key: string]: string;
|
|
@@ -135,11 +166,13 @@ export interface FieldOptions {
|
|
|
135
166
|
fieldEdge?: FieldEdge;
|
|
136
167
|
primaryKey?: boolean;
|
|
137
168
|
disableUserEditable?: boolean;
|
|
169
|
+
disableUserGraphQLEditable?: boolean;
|
|
138
170
|
defaultValueOnCreate?(builder: Builder<Ent>, input: Data): any;
|
|
139
171
|
defaultToViewerOnCreate?: boolean;
|
|
140
172
|
defaultValueOnEdit?(builder: Builder<Ent>, input: Data): any;
|
|
141
173
|
derivedWhenEmbedded?: boolean;
|
|
142
174
|
polymorphic?: boolean | PolymorphicOptions;
|
|
175
|
+
privacyPolicy?: PrivacyPolicy | (() => PrivacyPolicy);
|
|
143
176
|
getDerivedFields?(name: string): FieldMap;
|
|
144
177
|
[x: string]: any;
|
|
145
178
|
}
|
|
@@ -158,7 +191,20 @@ export interface SchemaConstructor {
|
|
|
158
191
|
new (): Schema;
|
|
159
192
|
}
|
|
160
193
|
export declare type SchemaInputType = Schema | SchemaConstructor;
|
|
194
|
+
export declare function getSchema(value: SchemaInputType): Schema;
|
|
161
195
|
export declare function getFields(value: SchemaInputType): Map<string, Field>;
|
|
196
|
+
/**
|
|
197
|
+
* @deprecated should only be used by tests
|
|
198
|
+
*/
|
|
199
|
+
export declare function getStorageKey(field: Field, fieldName: string): string;
|
|
200
|
+
export declare function getFieldsWithPrivacy(value: SchemaInputType, fieldMap: FieldInfoMap): Map<string, PrivacyPolicy>;
|
|
201
|
+
export declare function getTransformedReadClause(value: SchemaInputType): Clause | undefined;
|
|
202
|
+
interface objectLoaderOptions {
|
|
203
|
+
clause?: () => Clause | undefined;
|
|
204
|
+
instanceKey?: string;
|
|
205
|
+
}
|
|
206
|
+
export declare function getObjectLoaderProperties(value: SchemaInputType, tableName: string): objectLoaderOptions | undefined;
|
|
207
|
+
export declare function getTransformedUpdateOp<T extends Ent>(value: SchemaInputType, stmt: UpdateOperation<T>): TransformedUpdateOperation<T> | null;
|
|
162
208
|
export declare enum ActionOperation {
|
|
163
209
|
Create = 1,
|
|
164
210
|
Edit = 2,
|
|
@@ -201,10 +247,24 @@ export interface Constraint {
|
|
|
201
247
|
fkey?: ForeignKeyInfo;
|
|
202
248
|
condition?: string;
|
|
203
249
|
}
|
|
250
|
+
export interface FullTextWeight {
|
|
251
|
+
A?: string[];
|
|
252
|
+
B?: string[];
|
|
253
|
+
C?: string[];
|
|
254
|
+
D?: string[];
|
|
255
|
+
}
|
|
256
|
+
export interface FullText {
|
|
257
|
+
generatedColumnName?: string;
|
|
258
|
+
language?: "english" | "french" | "german" | "simple";
|
|
259
|
+
languageColumn?: string;
|
|
260
|
+
indexType?: "gin" | "gist";
|
|
261
|
+
weights?: FullTextWeight;
|
|
262
|
+
}
|
|
204
263
|
export interface Index {
|
|
205
264
|
name: string;
|
|
206
265
|
columns: string[];
|
|
207
266
|
unique?: boolean;
|
|
267
|
+
fulltext?: FullText;
|
|
208
268
|
}
|
|
209
269
|
export interface ForeignKeyInfo {
|
|
210
270
|
tableName: string;
|
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
|
|
@@ -28,14 +43,17 @@ var DBType;
|
|
|
28
43
|
function isSchema(value) {
|
|
29
44
|
return value.fields !== undefined;
|
|
30
45
|
}
|
|
31
|
-
function
|
|
32
|
-
let schema;
|
|
46
|
+
function getSchema(value) {
|
|
33
47
|
if (isSchema(value)) {
|
|
34
|
-
|
|
48
|
+
return value;
|
|
35
49
|
}
|
|
36
50
|
else {
|
|
37
|
-
|
|
51
|
+
return new value();
|
|
38
52
|
}
|
|
53
|
+
}
|
|
54
|
+
exports.getSchema = getSchema;
|
|
55
|
+
function getFields(value) {
|
|
56
|
+
const schema = getSchema(value);
|
|
39
57
|
function addFields(fields) {
|
|
40
58
|
if (Array.isArray(fields)) {
|
|
41
59
|
for (const field of fields) {
|
|
@@ -68,6 +86,109 @@ function getFields(value) {
|
|
|
68
86
|
return m;
|
|
69
87
|
}
|
|
70
88
|
exports.getFields = getFields;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated should only be used by tests
|
|
91
|
+
*/
|
|
92
|
+
function getStorageKey(field, fieldName) {
|
|
93
|
+
return field.storageKey || (0, snake_case_1.snakeCase)(fieldName);
|
|
94
|
+
}
|
|
95
|
+
exports.getStorageKey = getStorageKey;
|
|
96
|
+
// returns a mapping of storage key to field privacy
|
|
97
|
+
function getFieldsWithPrivacy(value, fieldMap) {
|
|
98
|
+
const schema = getSchema(value);
|
|
99
|
+
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
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
for (const name in fields) {
|
|
127
|
+
const field = fields[name];
|
|
128
|
+
if (field.getDerivedFields !== undefined) {
|
|
129
|
+
addFields(field.getDerivedFields(name));
|
|
130
|
+
}
|
|
131
|
+
if (field.privacyPolicy) {
|
|
132
|
+
let privacyPolicy;
|
|
133
|
+
if (typeof field.privacyPolicy === "function") {
|
|
134
|
+
privacyPolicy = field.privacyPolicy();
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
privacyPolicy = field.privacyPolicy;
|
|
138
|
+
}
|
|
139
|
+
const info = fieldMap[name];
|
|
140
|
+
if (!info) {
|
|
141
|
+
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
142
|
+
}
|
|
143
|
+
m.set(info.dbCol, privacyPolicy);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
let m = new Map();
|
|
148
|
+
if (schema.patterns) {
|
|
149
|
+
for (const pattern of schema.patterns) {
|
|
150
|
+
addFields(pattern.fields);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
addFields(schema.fields);
|
|
154
|
+
return m;
|
|
155
|
+
}
|
|
156
|
+
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
157
|
+
function getTransformedReadClause(value) {
|
|
158
|
+
const schema = getSchema(value);
|
|
159
|
+
if (!schema.patterns) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
for (const p of schema.patterns) {
|
|
163
|
+
// e.g. discarded_at, deleted_at, etc
|
|
164
|
+
if (p.transformRead) {
|
|
165
|
+
// return clause.Eq('deleted_at', null);
|
|
166
|
+
return p.transformRead();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
exports.getTransformedReadClause = getTransformedReadClause;
|
|
172
|
+
function getObjectLoaderProperties(value, tableName) {
|
|
173
|
+
return {
|
|
174
|
+
clause: () => getTransformedReadClause(value),
|
|
175
|
+
instanceKey: `${tableName}:transformedReadClause`,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
exports.getObjectLoaderProperties = getObjectLoaderProperties;
|
|
179
|
+
function getTransformedUpdateOp(value, stmt) {
|
|
180
|
+
const schema = getSchema(value);
|
|
181
|
+
if (!schema.patterns) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
for (const p of schema.patterns) {
|
|
185
|
+
if (p.transformWrite) {
|
|
186
|
+
return p.transformWrite(stmt);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
exports.getTransformedUpdateOp = getTransformedUpdateOp;
|
|
71
192
|
// this maps to ActionOperation in ent/action.go
|
|
72
193
|
var ActionOperation;
|
|
73
194
|
(function (ActionOperation) {
|
package/schema/union_field.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export declare class UnionField extends BaseField implements FieldOptions {
|
|
|
15
15
|
type: Type;
|
|
16
16
|
m: Map<Object, string>;
|
|
17
17
|
constructor(options: UnionOptions);
|
|
18
|
-
format(obj: any
|
|
18
|
+
format(obj: any): string | Object;
|
|
19
|
+
private validField;
|
|
19
20
|
valid(obj: any): Promise<boolean>;
|
|
20
21
|
}
|
|
21
22
|
export declare function UnionType(options: UnionOptions): UnionField & UnionOptions;
|
package/schema/union_field.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.UnionListType = exports.UnionType = exports.UnionField = void 0;
|
|
4
4
|
const schema_1 = require("./schema");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
|
+
// used to know which key in the union is valid.
|
|
7
|
+
// maybe there's a better way of doing this eventually
|
|
8
|
+
const KEY = "___valid___key___";
|
|
6
9
|
class UnionField extends field_1.BaseField {
|
|
7
10
|
constructor(options) {
|
|
8
11
|
super();
|
|
@@ -19,21 +22,26 @@ class UnionField extends field_1.BaseField {
|
|
|
19
22
|
this.type.dbType = schema_1.DBType.JSON;
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
|
-
format(obj
|
|
25
|
+
format(obj) {
|
|
23
26
|
if (!(obj instanceof Object)) {
|
|
24
27
|
throw new Error("valid was not called");
|
|
25
28
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (fmt !== "{}") {
|
|
30
|
-
return fmt;
|
|
31
|
-
}
|
|
29
|
+
const k = obj[KEY];
|
|
30
|
+
if (k === undefined) {
|
|
31
|
+
throw new Error(`need to call valid first`);
|
|
32
32
|
}
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
// now delete it since we don't need it anymore
|
|
34
|
+
delete obj[KEY];
|
|
35
|
+
const field = this.options.fields[k];
|
|
36
|
+
// always nested for now so pass through
|
|
37
|
+
return field.format(obj, true);
|
|
38
|
+
}
|
|
39
|
+
async validField(k, f, obj) {
|
|
40
|
+
const valid = await f.valid(obj);
|
|
41
|
+
return {
|
|
42
|
+
valid,
|
|
43
|
+
key: k,
|
|
44
|
+
};
|
|
37
45
|
}
|
|
38
46
|
async valid(obj) {
|
|
39
47
|
if (!(obj instanceof Object)) {
|
|
@@ -42,11 +50,21 @@ class UnionField extends field_1.BaseField {
|
|
|
42
50
|
let promises = [];
|
|
43
51
|
for (const k in this.options.fields) {
|
|
44
52
|
const field = this.options.fields[k];
|
|
45
|
-
promises.push(
|
|
53
|
+
promises.push(this.validField(k, field, obj));
|
|
46
54
|
}
|
|
55
|
+
let lastKey;
|
|
56
|
+
let validCt = 0;
|
|
47
57
|
const ret = await Promise.all(promises);
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
for (const v of ret) {
|
|
59
|
+
if (v.valid) {
|
|
60
|
+
validCt++;
|
|
61
|
+
lastKey = v.key;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (lastKey !== undefined) {
|
|
65
|
+
obj[KEY] = lastKey;
|
|
66
|
+
}
|
|
67
|
+
return validCt == 1;
|
|
50
68
|
}
|
|
51
69
|
}
|
|
52
70
|
exports.UnionField = UnionField;
|