@snowtop/ent 0.1.0-alpha99 → 0.1.0
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 +8 -1
- package/action/executor.d.ts +16 -3
- package/action/executor.js +83 -27
- package/action/index.d.ts +2 -1
- package/action/operations.d.ts +126 -0
- package/action/operations.js +686 -0
- package/action/orchestrator.d.ts +22 -8
- package/action/orchestrator.js +278 -67
- package/core/base.d.ts +34 -24
- package/core/clause.d.ts +62 -79
- package/core/clause.js +77 -5
- package/core/config.d.ts +5 -1
- package/core/config.js +3 -0
- package/core/const.d.ts +3 -0
- package/core/const.js +6 -0
- package/core/context.d.ts +4 -3
- package/core/context.js +2 -1
- package/core/db.d.ts +1 -0
- package/core/db.js +7 -7
- package/core/ent.d.ts +53 -105
- package/core/ent.js +104 -599
- package/core/global_schema.d.ts +7 -0
- package/core/global_schema.js +51 -0
- package/core/loaders/assoc_count_loader.d.ts +4 -2
- package/core/loaders/assoc_count_loader.js +10 -2
- package/core/loaders/assoc_edge_loader.d.ts +2 -3
- package/core/loaders/assoc_edge_loader.js +16 -7
- package/core/loaders/index.d.ts +0 -1
- package/core/loaders/index.js +1 -3
- package/core/loaders/loader.d.ts +3 -3
- package/core/loaders/loader.js +3 -20
- package/core/loaders/object_loader.d.ts +30 -10
- package/core/loaders/object_loader.js +179 -40
- package/core/loaders/query_loader.d.ts +4 -4
- package/core/loaders/query_loader.js +14 -19
- package/core/loaders/raw_count_loader.d.ts +1 -0
- package/core/loaders/raw_count_loader.js +3 -2
- package/core/privacy.d.ts +19 -10
- package/core/privacy.js +47 -26
- package/core/query/assoc_query.js +1 -1
- package/core/query/custom_clause_query.d.ts +6 -3
- package/core/query/custom_clause_query.js +36 -9
- package/core/query/custom_query.d.ts +3 -1
- package/core/query/custom_query.js +29 -6
- package/core/query/query.d.ts +12 -2
- package/core/query/query.js +67 -38
- package/core/query/shared_assoc_test.js +151 -10
- package/core/query/shared_test.d.ts +2 -2
- package/core/query/shared_test.js +90 -30
- package/core/query_impl.d.ts +8 -0
- package/core/query_impl.js +28 -0
- package/core/viewer.d.ts +2 -0
- package/core/viewer.js +2 -0
- package/graphql/graphql.d.ts +103 -19
- package/graphql/graphql.js +169 -134
- package/graphql/graphql_field_helpers.d.ts +9 -3
- package/graphql/graphql_field_helpers.js +22 -2
- package/graphql/index.d.ts +2 -1
- package/graphql/index.js +5 -2
- 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 +1 -1
- package/imports/index.js +2 -2
- package/index.d.ts +12 -1
- package/index.js +18 -6
- package/package.json +20 -17
- package/parse_schema/parse.d.ts +10 -4
- package/parse_schema/parse.js +70 -24
- package/schema/base_schema.d.ts +8 -0
- package/schema/base_schema.js +11 -0
- package/schema/field.d.ts +6 -3
- package/schema/field.js +72 -17
- package/schema/index.d.ts +1 -1
- package/schema/index.js +2 -1
- package/schema/json_field.d.ts +3 -3
- package/schema/json_field.js +4 -1
- package/schema/schema.d.ts +42 -5
- package/schema/schema.js +35 -41
- package/schema/struct_field.d.ts +8 -6
- package/schema/struct_field.js +67 -8
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +4 -4
- package/scripts/custom_graphql.js +105 -75
- package/scripts/move_types.js +4 -1
- package/scripts/read_schema.js +2 -2
- package/testutils/action/complex_schemas.d.ts +1 -1
- package/testutils/action/complex_schemas.js +10 -3
- package/testutils/builder.d.ts +3 -0
- package/testutils/builder.js +6 -0
- package/testutils/db/temp_db.d.ts +9 -1
- package/testutils/db/temp_db.js +82 -14
- package/testutils/db_mock.js +1 -3
- package/testutils/ent-graphql-tests/index.d.ts +1 -1
- package/testutils/ent-graphql-tests/index.js +30 -19
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_data/fake_contact.d.ts +1 -1
- package/testutils/fake_data/fake_tag.d.ts +1 -1
- package/testutils/fake_data/fake_user.d.ts +3 -3
- package/testutils/fake_data/fake_user.js +15 -4
- package/testutils/fake_data/tag_query.js +8 -3
- package/testutils/fake_data/test_helpers.d.ts +3 -2
- package/testutils/fake_data/test_helpers.js +4 -4
- package/testutils/fake_data/user_query.d.ts +5 -2
- package/testutils/fake_data/user_query.js +19 -2
- package/testutils/fake_log.js +1 -1
- package/tsc/ast.js +2 -1
- package/tsc/move_generated.js +2 -2
- package/tsc/transform.d.ts +2 -2
- package/tsc/transform.js +4 -3
- package/tsc/transform_ent.js +2 -1
- package/tsc/transform_schema.js +4 -3
- package/core/loaders/index_loader.d.ts +0 -14
- package/core/loaders/index_loader.js +0 -27
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
|
|
@@ -85,53 +85,45 @@ function getStorageKey(field, fieldName) {
|
|
|
85
85
|
}
|
|
86
86
|
exports.getStorageKey = getStorageKey;
|
|
87
87
|
// returns a mapping of storage key to field privacy
|
|
88
|
-
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) {
|
|
89
104
|
const schema = getSchema(value);
|
|
90
105
|
function addFields(fields) {
|
|
91
|
-
if (Array.isArray(fields)) {
|
|
92
|
-
for (const field of fields) {
|
|
93
|
-
const name = field.name;
|
|
94
|
-
if (!field.name) {
|
|
95
|
-
throw new Error(`name required`);
|
|
96
|
-
}
|
|
97
|
-
if (field.getDerivedFields !== undefined) {
|
|
98
|
-
addFields(field.getDerivedFields(name));
|
|
99
|
-
}
|
|
100
|
-
if (field.privacyPolicy) {
|
|
101
|
-
let privacyPolicy;
|
|
102
|
-
if (typeof field.privacyPolicy === "function") {
|
|
103
|
-
privacyPolicy = field.privacyPolicy();
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
privacyPolicy = field.privacyPolicy;
|
|
107
|
-
}
|
|
108
|
-
const info = fieldMap[name];
|
|
109
|
-
if (!info) {
|
|
110
|
-
throw new Error(`field with name ${name} not passed in fieldMap`);
|
|
111
|
-
}
|
|
112
|
-
m.set(info.dbCol, privacyPolicy);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
106
|
for (const name in fields) {
|
|
118
107
|
const field = fields[name];
|
|
108
|
+
if (field.dbOnly) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
119
111
|
if (field.getDerivedFields !== undefined) {
|
|
120
112
|
addFields(field.getDerivedFields(name));
|
|
121
113
|
}
|
|
122
|
-
|
|
123
|
-
let privacyPolicy;
|
|
124
|
-
if (
|
|
125
|
-
privacyPolicy
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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;
|
|
133
126
|
}
|
|
134
|
-
m.set(info.dbCol, privacyPolicy);
|
|
135
127
|
}
|
|
136
128
|
}
|
|
137
129
|
}
|
|
@@ -144,7 +136,6 @@ function getFieldsWithPrivacy(value, fieldMap) {
|
|
|
144
136
|
addFields(schema.fields);
|
|
145
137
|
return m;
|
|
146
138
|
}
|
|
147
|
-
exports.getFieldsWithPrivacy = getFieldsWithPrivacy;
|
|
148
139
|
function getTransformedReadClause(value) {
|
|
149
140
|
const schema = getSchema(value);
|
|
150
141
|
if (!schema.patterns) {
|
|
@@ -160,6 +151,9 @@ function getTransformedReadClause(value) {
|
|
|
160
151
|
return;
|
|
161
152
|
}
|
|
162
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...
|
|
163
157
|
function getObjectLoaderProperties(value, tableName) {
|
|
164
158
|
return {
|
|
165
159
|
clause: () => getTransformedReadClause(value),
|
package/schema/struct_field.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
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
|
|
10
|
-
|
|
9
|
+
interface GlobalStructOptions extends FieldOptions {
|
|
10
|
+
globalType: string;
|
|
11
11
|
}
|
|
12
|
+
export type StructOptions = structFieldOptions | GlobalStructOptions;
|
|
12
13
|
export declare class StructField extends BaseField implements Field {
|
|
13
14
|
private options;
|
|
15
|
+
private jsonAsList?;
|
|
14
16
|
type: Type;
|
|
15
|
-
constructor(options:
|
|
17
|
+
constructor(options: StructOptions, jsonAsList?: boolean | undefined);
|
|
16
18
|
formatImpl(obj: any, nested?: boolean): string | Object;
|
|
17
|
-
format(obj: any, nested?: boolean):
|
|
19
|
+
format(obj: any, nested?: boolean): any;
|
|
18
20
|
private validImpl;
|
|
19
21
|
valid(obj: any): Promise<boolean>;
|
|
20
22
|
}
|
|
@@ -23,5 +25,5 @@ export declare function StructType(options: StructOptions): StructField & Struct
|
|
|
23
25
|
* @deprecated use StructTypeAsList
|
|
24
26
|
*/
|
|
25
27
|
export declare function StructListType(options: StructOptions): ListField;
|
|
26
|
-
export declare function StructTypeAsList(options:
|
|
28
|
+
export declare function StructTypeAsList(options: StructOptions): StructField & StructOptions;
|
|
27
29
|
export {};
|
package/schema/struct_field.js
CHANGED
|
@@ -4,20 +4,24 @@ exports.StructTypeAsList = exports.StructListType = exports.StructType = exports
|
|
|
4
4
|
const camel_case_1 = require("camel-case");
|
|
5
5
|
const field_1 = require("./field");
|
|
6
6
|
const schema_1 = require("./schema");
|
|
7
|
+
const global_schema_1 = require("../core/global_schema");
|
|
8
|
+
const logger_1 = require("../core/logger");
|
|
7
9
|
class StructField extends field_1.BaseField {
|
|
8
|
-
constructor(options) {
|
|
10
|
+
constructor(options, jsonAsList) {
|
|
9
11
|
super();
|
|
10
12
|
this.options = options;
|
|
13
|
+
this.jsonAsList = jsonAsList;
|
|
11
14
|
this.type = {
|
|
12
15
|
dbType: schema_1.DBType.JSONB,
|
|
13
16
|
};
|
|
14
17
|
this.type.subFields = options.fields;
|
|
15
18
|
this.type.type = options.tsType;
|
|
16
19
|
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
20
|
+
this.type.globalType = this.options.globalType;
|
|
17
21
|
if (options.jsonNotJSONB) {
|
|
18
22
|
this.type.dbType = schema_1.DBType.JSON;
|
|
19
23
|
}
|
|
20
|
-
if (
|
|
24
|
+
if (jsonAsList) {
|
|
21
25
|
this.type.listElemType = {
|
|
22
26
|
dbType: schema_1.DBType.JSONB,
|
|
23
27
|
};
|
|
@@ -57,7 +61,37 @@ class StructField extends field_1.BaseField {
|
|
|
57
61
|
return JSON.stringify(ret);
|
|
58
62
|
}
|
|
59
63
|
format(obj, nested) {
|
|
60
|
-
if (
|
|
64
|
+
if (this.type.globalType) {
|
|
65
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
66
|
+
if (f && f.format) {
|
|
67
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
68
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
69
|
+
if (this.jsonAsList) {
|
|
70
|
+
// handle as nested
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
const formatted = obj.map((v) => f.format(v, true));
|
|
73
|
+
if (nested) {
|
|
74
|
+
return formatted;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return JSON.stringify(formatted);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const formatted = f.format([obj], true);
|
|
82
|
+
if (nested) {
|
|
83
|
+
return formatted[0];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return JSON.stringify(formatted[0]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// TODO handle format code
|
|
91
|
+
return f.format(obj);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (Array.isArray(obj) && this.jsonAsList) {
|
|
61
95
|
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
62
96
|
if (nested) {
|
|
63
97
|
return ret;
|
|
@@ -102,7 +136,35 @@ class StructField extends field_1.BaseField {
|
|
|
102
136
|
return ret.every((v) => v);
|
|
103
137
|
}
|
|
104
138
|
async valid(obj) {
|
|
105
|
-
if (this.
|
|
139
|
+
if (this.type.globalType) {
|
|
140
|
+
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
141
|
+
// list and global type is not valid.
|
|
142
|
+
if (f) {
|
|
143
|
+
if (f.valid) {
|
|
144
|
+
if (JSON.stringify(this.type.listElemType) !==
|
|
145
|
+
JSON.stringify(f?.type.listElemType)) {
|
|
146
|
+
if (this.jsonAsList) {
|
|
147
|
+
if (!Array.isArray(obj)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
const valid = await Promise.all(obj.map((v) => f.valid(v)));
|
|
152
|
+
return valid.every((b) => b);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return f.valid([obj]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return f.valid(obj);
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (this.jsonAsList) {
|
|
106
168
|
if (!Array.isArray(obj)) {
|
|
107
169
|
return false;
|
|
108
170
|
}
|
|
@@ -129,10 +191,7 @@ function StructListType(options) {
|
|
|
129
191
|
}
|
|
130
192
|
exports.StructListType = StructListType;
|
|
131
193
|
function StructTypeAsList(options) {
|
|
132
|
-
let result = new StructField(
|
|
133
|
-
...options,
|
|
134
|
-
jsonAsList: true,
|
|
135
|
-
});
|
|
194
|
+
let result = new StructField(options, true);
|
|
136
195
|
return Object.assign(result, options);
|
|
137
196
|
}
|
|
138
197
|
exports.StructTypeAsList = StructTypeAsList;
|
package/schema/union_field.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ 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): any;
|
|
19
19
|
private validField;
|
|
20
20
|
valid(obj: any): Promise<boolean>;
|
|
21
21
|
}
|
|
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
30
|
const typescript_1 = __importDefault(require("typescript"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
|
-
const
|
|
32
|
+
const glob = __importStar(require("glob"));
|
|
33
33
|
const compilerOptions_1 = require("../tsc/compilerOptions");
|
|
34
34
|
// TODO this should probably be its own package but for now it's here
|
|
35
35
|
class Compiler {
|
|
@@ -229,7 +229,7 @@ class Compiler {
|
|
|
229
229
|
let relPath = checkPath(paths, text);
|
|
230
230
|
if (relPath) {
|
|
231
231
|
// update the node...
|
|
232
|
-
return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.
|
|
232
|
+
return typescript_1.default.factory.updateImportDeclaration(importNode, importNode.modifiers, importNode.importClause, typescript_1.default.factory.createStringLiteral(relPath), importNode.assertClause);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
if (node.kind === typescript_1.default.SyntaxKind.ExportDeclaration) {
|
|
@@ -239,7 +239,7 @@ class Compiler {
|
|
|
239
239
|
let relPath = checkPath(paths, text);
|
|
240
240
|
if (relPath) {
|
|
241
241
|
// update the node...
|
|
242
|
-
return typescript_1.default.updateExportDeclaration(exportNode, exportNode.
|
|
242
|
+
return typescript_1.default.factory.updateExportDeclaration(exportNode, exportNode.modifiers, exportNode.isTypeOnly, exportNode.exportClause, typescript_1.default.factory.createStringLiteral(relPath), exportNode.assertClause);
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -265,6 +265,6 @@ class Compiler {
|
|
|
265
265
|
// todo this should be configurable
|
|
266
266
|
// TODO this should be broken into its own repo and npm module
|
|
267
267
|
// TODO use includes and exclude in tsconfig.json if it exists
|
|
268
|
-
new Compiler(
|
|
268
|
+
new Compiler(glob.sync("**/*.ts", {
|
|
269
269
|
ignore: ["node_modules/**", "tests/**", "**/*.test.ts"],
|
|
270
270
|
}), ["node_modules/@types/node"]).compile();
|
|
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
const
|
|
30
|
+
const glob = __importStar(require("glob"));
|
|
31
31
|
const json5_1 = __importDefault(require("json5"));
|
|
32
32
|
const minimist_1 = __importDefault(require("minimist"));
|
|
33
33
|
const path = __importStar(require("path"));
|
|
@@ -37,10 +37,11 @@ const readline = __importStar(require("readline"));
|
|
|
37
37
|
const imports_1 = require("../imports");
|
|
38
38
|
const process_1 = require("process");
|
|
39
39
|
const child_process_1 = require("child_process");
|
|
40
|
+
const const_1 = require("../core/const");
|
|
40
41
|
// need to use the GQLCapture from the package so that when we call GQLCapture.enable()
|
|
41
42
|
// we're affecting the local paths as opposed to a different instance
|
|
42
43
|
// life is hard
|
|
43
|
-
const MODULE_PATH =
|
|
44
|
+
const MODULE_PATH = const_1.GRAPHQL_PATH;
|
|
44
45
|
async function readInputs() {
|
|
45
46
|
return await new Promise((resolve) => {
|
|
46
47
|
const rl = readline.createInterface({
|
|
@@ -59,14 +60,7 @@ async function readInputs() {
|
|
|
59
60
|
});
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
|
-
function processCustomObjects(l, gqlCapture,
|
|
63
|
-
let m;
|
|
64
|
-
if (input) {
|
|
65
|
-
m = gqlCapture.getCustomInputObjects();
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
m = gqlCapture.getCustomObjects();
|
|
69
|
-
}
|
|
63
|
+
function processCustomObjects(l, gqlCapture, m) {
|
|
70
64
|
for (const input of l) {
|
|
71
65
|
m.set(input.name, {
|
|
72
66
|
nodeName: input.graphQLName || input.name,
|
|
@@ -77,7 +71,7 @@ function processCustomObjects(l, gqlCapture, input) {
|
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
|
-
function transformArgs(f) {
|
|
74
|
+
function transformArgs(f, gqlCapture) {
|
|
81
75
|
return (f.args || []).map((v) => {
|
|
82
76
|
const ret = {
|
|
83
77
|
...v,
|
|
@@ -85,13 +79,25 @@ function transformArgs(f) {
|
|
|
85
79
|
// duplicated from getType in graphql.ts
|
|
86
80
|
if ((0, graphql_1.isCustomType)(ret.type)) {
|
|
87
81
|
ret.type = v.type.type;
|
|
88
|
-
(0, graphql_1.addCustomType)(v.type);
|
|
82
|
+
(0, graphql_1.addCustomType)(v.type, gqlCapture);
|
|
89
83
|
}
|
|
90
84
|
// scalar types not supported for now
|
|
91
85
|
ret.tsType = graphql_1.knownAllowedNames.get(v.type);
|
|
92
86
|
return ret;
|
|
93
87
|
});
|
|
94
88
|
}
|
|
89
|
+
function transformFieldTypeInput(input) {
|
|
90
|
+
switch (input) {
|
|
91
|
+
case "ACCESSOR":
|
|
92
|
+
return graphql_1.CustomFieldType.Accessor;
|
|
93
|
+
case "ASYNC_FUNCTION":
|
|
94
|
+
return graphql_1.CustomFieldType.AsyncFunction;
|
|
95
|
+
case "FUNCTION":
|
|
96
|
+
return graphql_1.CustomFieldType.Function;
|
|
97
|
+
case "FIELD":
|
|
98
|
+
return graphql_1.CustomFieldType.Field;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
95
101
|
function transformResultType(f) {
|
|
96
102
|
return f.resultType
|
|
97
103
|
? [
|
|
@@ -106,14 +112,15 @@ function transformResultType(f) {
|
|
|
106
112
|
]
|
|
107
113
|
: [];
|
|
108
114
|
}
|
|
109
|
-
function processTopLevel(l, l2) {
|
|
115
|
+
function processTopLevel(l, l2, gqlCapture) {
|
|
110
116
|
for (const custom of l) {
|
|
111
117
|
l2.push({
|
|
112
|
-
nodeName: custom.class,
|
|
113
|
-
functionName: custom.functionName || custom.name,
|
|
114
|
-
gqlName: custom.graphQLName || custom.name,
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
nodeName: custom.class ?? "",
|
|
119
|
+
functionName: custom.functionName || custom.name || "",
|
|
120
|
+
gqlName: custom.graphQLName || custom.name || "",
|
|
121
|
+
edgeName: custom.edgeName,
|
|
122
|
+
fieldType: transformFieldTypeInput(custom.fieldType),
|
|
123
|
+
args: transformArgs(custom, gqlCapture),
|
|
117
124
|
results: transformResultType(custom),
|
|
118
125
|
description: custom.description,
|
|
119
126
|
extraImports: custom.extraImports,
|
|
@@ -121,16 +128,21 @@ function processTopLevel(l, l2) {
|
|
|
121
128
|
});
|
|
122
129
|
}
|
|
123
130
|
}
|
|
131
|
+
function processCustomTypes(m, gqlCapture) {
|
|
132
|
+
for (const k in m) {
|
|
133
|
+
(0, graphql_1.addCustomType)(m[k], gqlCapture);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
124
136
|
function processCustomFields(fields, gqlCapture, nodeName) {
|
|
125
137
|
const m = gqlCapture.getCustomFields();
|
|
126
138
|
let results = [];
|
|
127
139
|
for (const f of fields) {
|
|
128
140
|
results.push({
|
|
129
141
|
nodeName: nodeName,
|
|
130
|
-
gqlName: f.graphQLName || f.name,
|
|
131
|
-
functionName: f.functionName || f.name,
|
|
132
|
-
fieldType: f.fieldType,
|
|
133
|
-
args: transformArgs(f),
|
|
142
|
+
gqlName: f.graphQLName || f.name || "",
|
|
143
|
+
functionName: f.functionName || f.name || "",
|
|
144
|
+
fieldType: transformFieldTypeInput(f.fieldType),
|
|
145
|
+
args: transformArgs(f, gqlCapture),
|
|
134
146
|
results: transformResultType(f),
|
|
135
147
|
description: f.description,
|
|
136
148
|
});
|
|
@@ -141,9 +153,26 @@ async function captureDynamic(filePath, gqlCapture) {
|
|
|
141
153
|
if (!filePath) {
|
|
142
154
|
return;
|
|
143
155
|
}
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
const
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
let cmd = "";
|
|
158
|
+
const args = [];
|
|
159
|
+
const env = {
|
|
160
|
+
...process.env,
|
|
161
|
+
};
|
|
162
|
+
if (process.env.ENABLE_SWC) {
|
|
163
|
+
cmd = "node";
|
|
164
|
+
// we seem to get tsconfig-paths by default because child process but not 100% sure...
|
|
165
|
+
args.push("-r", "@swc-node/register");
|
|
166
|
+
env.SWCRC = "true";
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
cmd = "ts-node";
|
|
170
|
+
args.push("--transpileOnly");
|
|
171
|
+
}
|
|
172
|
+
args.push(filePath);
|
|
173
|
+
const r = (0, child_process_1.spawn)(cmd, args, {
|
|
174
|
+
env,
|
|
175
|
+
});
|
|
147
176
|
const datas = [];
|
|
148
177
|
r.stdout.on("data", (data) => {
|
|
149
178
|
datas.push(data.toString());
|
|
@@ -157,45 +186,42 @@ async function captureDynamic(filePath, gqlCapture) {
|
|
|
157
186
|
return;
|
|
158
187
|
}
|
|
159
188
|
let json = json5_1.default.parse(datas.join(""));
|
|
160
|
-
|
|
161
|
-
const v = json[k];
|
|
162
|
-
switch (k) {
|
|
163
|
-
case "queries":
|
|
164
|
-
processTopLevel(v, gqlCapture.getCustomQueries());
|
|
165
|
-
break;
|
|
166
|
-
case "mutations":
|
|
167
|
-
processTopLevel(v, gqlCapture.getCustomMutations());
|
|
168
|
-
break;
|
|
169
|
-
default:
|
|
170
|
-
reject(new Error(`key ${k} is unsupported in dynamic custom graphql. only queries and mutations are supported`));
|
|
171
|
-
}
|
|
172
|
-
}
|
|
189
|
+
processJSON(gqlCapture, json);
|
|
173
190
|
resolve(undefined);
|
|
174
191
|
});
|
|
175
192
|
});
|
|
176
193
|
}
|
|
194
|
+
async function processJSON(gqlCapture, json) {
|
|
195
|
+
if (json.fields) {
|
|
196
|
+
for (const k in json.fields) {
|
|
197
|
+
processCustomFields(json.fields[k], gqlCapture, k);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (json.inputs) {
|
|
201
|
+
processCustomObjects(json.inputs, gqlCapture, gqlCapture.getCustomInputObjects());
|
|
202
|
+
}
|
|
203
|
+
if (json.objects) {
|
|
204
|
+
processCustomObjects(json.objects, gqlCapture, gqlCapture.getCustomObjects());
|
|
205
|
+
}
|
|
206
|
+
if (json.args) {
|
|
207
|
+
processCustomObjects(json.args, gqlCapture, gqlCapture.getCustomArgs());
|
|
208
|
+
}
|
|
209
|
+
if (json.queries) {
|
|
210
|
+
processTopLevel(json.queries, gqlCapture.getCustomQueries(), gqlCapture);
|
|
211
|
+
}
|
|
212
|
+
if (json.mutations) {
|
|
213
|
+
processTopLevel(json.mutations, gqlCapture.getCustomMutations(), gqlCapture);
|
|
214
|
+
}
|
|
215
|
+
if (json.customTypes) {
|
|
216
|
+
processCustomTypes(json.customTypes, gqlCapture);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
177
219
|
async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
178
220
|
if (jsonPath !== undefined) {
|
|
179
221
|
let json = json5_1.default.parse(fs.readFileSync(jsonPath, {
|
|
180
222
|
encoding: "utf8",
|
|
181
223
|
}));
|
|
182
|
-
|
|
183
|
-
for (const k in json.fields) {
|
|
184
|
-
processCustomFields(json.fields[k], gqlCapture, k);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (json.inputs) {
|
|
188
|
-
processCustomObjects(json.inputs, gqlCapture, true);
|
|
189
|
-
}
|
|
190
|
-
if (json.objects) {
|
|
191
|
-
processCustomObjects(json.objects, gqlCapture);
|
|
192
|
-
}
|
|
193
|
-
if (json.queries) {
|
|
194
|
-
processTopLevel(json.queries, gqlCapture.getCustomQueries());
|
|
195
|
-
}
|
|
196
|
-
if (json.mutations) {
|
|
197
|
-
processTopLevel(json.mutations, gqlCapture.getCustomMutations());
|
|
198
|
-
}
|
|
224
|
+
processJSON(gqlCapture, json);
|
|
199
225
|
return;
|
|
200
226
|
}
|
|
201
227
|
if (filesCsv !== undefined) {
|
|
@@ -225,12 +251,12 @@ async function captureCustom(filePath, filesCsv, jsonPath, gqlCapture) {
|
|
|
225
251
|
// ignore test files.
|
|
226
252
|
"**/*.test.ts",
|
|
227
253
|
];
|
|
228
|
-
const customGQLResolvers =
|
|
254
|
+
const customGQLResolvers = glob.sync(path.join(filePath, "/graphql/resolvers/**/*.ts"), {
|
|
229
255
|
// no actions for now to speed things up
|
|
230
256
|
// no index.ts or internal file.
|
|
231
257
|
ignore: ignore,
|
|
232
258
|
});
|
|
233
|
-
const customGQLMutations =
|
|
259
|
+
const customGQLMutations = glob.sync(path.join(filePath, "/graphql/mutations/**/*.ts"), {
|
|
234
260
|
// no actions for now to speed things up
|
|
235
261
|
// no index.ts or internal file.
|
|
236
262
|
ignore: ignore,
|
|
@@ -295,24 +321,6 @@ function findGraphQLPath(filePath) {
|
|
|
295
321
|
// also, there should be a way to get the list of objects here that's not manual
|
|
296
322
|
//echo "User\nContact\nContactEmail\nComment" | ts-node-script --log-error --project ./tsconfig.json -r tsconfig-paths/register ../../ts/src/scripts/custom_graphql.ts --path ~/code/ent/examples/simple/src/
|
|
297
323
|
async function main() {
|
|
298
|
-
// known custom types that are not required
|
|
299
|
-
// if not in the schema, will be ignored
|
|
300
|
-
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
301
|
-
// these 2 need this because they're added by the schema
|
|
302
|
-
// if this list grows too long, need to build this into golang types and passed here
|
|
303
|
-
// TODO foreign non-scalars eventually
|
|
304
|
-
(0, graphql_1.addCustomType)({
|
|
305
|
-
importPath: MODULE_PATH,
|
|
306
|
-
// for go tests...
|
|
307
|
-
// TODO need a flag that only does this for go tests
|
|
308
|
-
// breaks when running locally sometimes...
|
|
309
|
-
secondaryImportPath: "../graphql/scalars/time",
|
|
310
|
-
type: "GraphQLTime",
|
|
311
|
-
});
|
|
312
|
-
(0, graphql_1.addCustomType)({
|
|
313
|
-
importPath: "graphql-type-json",
|
|
314
|
-
type: "GraphQLJSON",
|
|
315
|
-
});
|
|
316
324
|
const options = (0, minimist_1.default)(process.argv.slice(2));
|
|
317
325
|
if (!options.path) {
|
|
318
326
|
throw new Error("path required");
|
|
@@ -337,6 +345,24 @@ async function main() {
|
|
|
337
345
|
gqlCapture = r.GQLCapture;
|
|
338
346
|
gqlCapture.enable(true);
|
|
339
347
|
}
|
|
348
|
+
// known custom types that are not required
|
|
349
|
+
// if not in the schema, will be ignored
|
|
350
|
+
// something like GraphQLUpload gotten via gqlArg({type: gqlFileUpload})
|
|
351
|
+
// these 2 need this because they're added by the schema
|
|
352
|
+
// if this list grows too long, need to build this into golang types and passed here
|
|
353
|
+
// TODO foreign non-scalars eventually
|
|
354
|
+
(0, graphql_1.addCustomType)({
|
|
355
|
+
importPath: MODULE_PATH,
|
|
356
|
+
// for go tests...
|
|
357
|
+
// TODO need a flag that only does this for go tests
|
|
358
|
+
// breaks when running locally sometimes...
|
|
359
|
+
secondaryImportPath: "../graphql/scalars/time",
|
|
360
|
+
type: "GraphQLTime",
|
|
361
|
+
}, gqlCapture);
|
|
362
|
+
(0, graphql_1.addCustomType)({
|
|
363
|
+
importPath: "graphql-type-json",
|
|
364
|
+
type: "GraphQLJSON",
|
|
365
|
+
}, gqlCapture);
|
|
340
366
|
const [inputsRead, _, __, imports] = await Promise.all([
|
|
341
367
|
readInputs(),
|
|
342
368
|
captureCustom(options.path, options.files, options.json_path, gqlCapture),
|
|
@@ -358,6 +384,8 @@ async function main() {
|
|
|
358
384
|
let queries = gqlCapture.getProcessedCustomQueries();
|
|
359
385
|
let mutations = gqlCapture.getProcessedCustomMutations();
|
|
360
386
|
let objects = fromMap(gqlCapture.getCustomObjects());
|
|
387
|
+
let interfaces = fromMap(gqlCapture.getCustomInterfaces());
|
|
388
|
+
let unions = fromMap(gqlCapture.getCustomUnions());
|
|
361
389
|
let customTypes = fromMap(gqlCapture.getCustomTypes());
|
|
362
390
|
let classes = {};
|
|
363
391
|
let allFiles = {};
|
|
@@ -420,6 +448,8 @@ async function main() {
|
|
|
420
448
|
mutations,
|
|
421
449
|
classes,
|
|
422
450
|
objects,
|
|
451
|
+
interfaces,
|
|
452
|
+
unions,
|
|
423
453
|
files: allFiles,
|
|
424
454
|
customTypes,
|
|
425
455
|
}));
|
package/scripts/move_types.js
CHANGED
|
@@ -36,7 +36,10 @@ class GatherExportsInGeneratedTypes {
|
|
|
36
36
|
this.names = [];
|
|
37
37
|
}
|
|
38
38
|
traverseChild(sourceFile, contents, file, node) {
|
|
39
|
-
const
|
|
39
|
+
const modifiers = typescript_1.default.canHaveModifiers(node)
|
|
40
|
+
? typescript_1.default.getModifiers(node)
|
|
41
|
+
: undefined;
|
|
42
|
+
const exported = modifiers?.filter((mod) => mod.getText(sourceFile) === "export");
|
|
40
43
|
if (exported?.length) {
|
|
41
44
|
if (typescript_1.default.isEnumDeclaration(node) ||
|
|
42
45
|
typescript_1.default.isInterfaceDeclaration(node) ||
|
package/scripts/read_schema.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const
|
|
29
|
+
const glob = __importStar(require("glob"));
|
|
30
30
|
const path = __importStar(require("path"));
|
|
31
31
|
const pascal_case_1 = require("pascal-case");
|
|
32
32
|
const minimist_1 = __importDefault(require("minimist"));
|
|
@@ -42,7 +42,7 @@ function main() {
|
|
|
42
42
|
let globalSchema;
|
|
43
43
|
const r = /(\w+).ts/;
|
|
44
44
|
// do we still even need this...
|
|
45
|
-
const paths =
|
|
45
|
+
const paths = glob.sync(path.join(options.path, "*.ts"), {
|
|
46
46
|
ignore: [`\d+_read_schema.ts`],
|
|
47
47
|
});
|
|
48
48
|
let potentialSchemas = {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ent, ID, Viewer, Data } from "../../core/base";
|
|
2
|
-
import { DataOperation } from "../../
|
|
2
|
+
import { DataOperation } from "../../action/operations";
|
|
3
3
|
import { Action, Builder, Executor, WriteOperation, Trigger, Observer, TriggerReturn } from "../../action/action";
|
|
4
4
|
import { EdgeInputData } from "../../action/orchestrator";
|
|
5
5
|
import { User, Group, Message, Contact, SimpleBuilder, BuilderSchema, SimpleAction, BaseEnt } from "../../testutils/builder";
|