@snowtop/ent 0.1.0-alpha123 → 0.1.0-alpha125
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/core/ent.d.ts +4 -0
- package/core/ent.js +27 -18
- package/core/query/shared_test.js +1 -2
- package/graphql/graphql.d.ts +19 -12
- package/graphql/graphql.js +65 -126
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +1 -2
- package/imports/dataz/example1/_auth.js +128 -47
- package/imports/dataz/example1/_viewer.js +87 -39
- package/index.d.ts +1 -2
- package/index.js +1 -2
- package/package.json +4 -5
- package/parse_schema/parse.d.ts +1 -2
- package/parse_schema/parse.js +2 -10
- package/schema/field.d.ts +3 -5
- package/schema/field.js +15 -69
- package/schema/schema.d.ts +0 -2
- package/schema/struct_field.d.ts +6 -8
- package/schema/struct_field.js +8 -67
- package/schema/union_field.d.ts +1 -1
- package/scripts/custom_compiler.js +2 -2
- package/scripts/move_types.js +4 -1
- package/testutils/db_mock.js +1 -1
- package/testutils/fake_comms.js +1 -1
- package/testutils/fake_log.js +1 -1
- package/core/global_schema.d.ts +0 -7
- package/core/global_schema.js +0 -51
package/schema/struct_field.js
CHANGED
|
@@ -4,24 +4,20 @@ 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");
|
|
9
7
|
class StructField extends field_1.BaseField {
|
|
10
|
-
constructor(options
|
|
8
|
+
constructor(options) {
|
|
11
9
|
super();
|
|
12
10
|
this.options = options;
|
|
13
|
-
this.jsonAsList = jsonAsList;
|
|
14
11
|
this.type = {
|
|
15
12
|
dbType: schema_1.DBType.JSONB,
|
|
16
13
|
};
|
|
17
14
|
this.type.subFields = options.fields;
|
|
18
15
|
this.type.type = options.tsType;
|
|
19
16
|
this.type.graphQLType = options.graphQLType || options.tsType;
|
|
20
|
-
this.type.globalType = this.options.globalType;
|
|
21
17
|
if (options.jsonNotJSONB) {
|
|
22
18
|
this.type.dbType = schema_1.DBType.JSON;
|
|
23
19
|
}
|
|
24
|
-
if (jsonAsList) {
|
|
20
|
+
if (options?.jsonAsList) {
|
|
25
21
|
this.type.listElemType = {
|
|
26
22
|
dbType: schema_1.DBType.JSONB,
|
|
27
23
|
};
|
|
@@ -61,37 +57,7 @@ class StructField extends field_1.BaseField {
|
|
|
61
57
|
return JSON.stringify(ret);
|
|
62
58
|
}
|
|
63
59
|
format(obj, nested) {
|
|
64
|
-
if (this.
|
|
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) {
|
|
60
|
+
if (Array.isArray(obj) && this.options.jsonAsList) {
|
|
95
61
|
const ret = obj.map((v) => this.formatImpl(v, true));
|
|
96
62
|
if (nested) {
|
|
97
63
|
return ret;
|
|
@@ -136,35 +102,7 @@ class StructField extends field_1.BaseField {
|
|
|
136
102
|
return ret.every((v) => v);
|
|
137
103
|
}
|
|
138
104
|
async valid(obj) {
|
|
139
|
-
if (this.
|
|
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) {
|
|
105
|
+
if (this.options.jsonAsList) {
|
|
168
106
|
if (!Array.isArray(obj)) {
|
|
169
107
|
return false;
|
|
170
108
|
}
|
|
@@ -191,7 +129,10 @@ function StructListType(options) {
|
|
|
191
129
|
}
|
|
192
130
|
exports.StructListType = StructListType;
|
|
193
131
|
function StructTypeAsList(options) {
|
|
194
|
-
let result = new StructField(
|
|
132
|
+
let result = new StructField({
|
|
133
|
+
...options,
|
|
134
|
+
jsonAsList: true,
|
|
135
|
+
});
|
|
195
136
|
return Object.assign(result, options);
|
|
196
137
|
}
|
|
197
138
|
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): string | Object;
|
|
19
19
|
private validField;
|
|
20
20
|
valid(obj: any): Promise<boolean>;
|
|
21
21
|
}
|
|
@@ -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
|
}
|
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/testutils/db_mock.js
CHANGED
|
@@ -263,10 +263,10 @@ class QueryRecorder {
|
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
|
-
exports.QueryRecorder = QueryRecorder;
|
|
267
266
|
QueryRecorder.queries = [];
|
|
268
267
|
QueryRecorder.ids = [];
|
|
269
268
|
// we need pkeys when storing...
|
|
270
269
|
QueryRecorder.data = new Map();
|
|
270
|
+
exports.QueryRecorder = QueryRecorder;
|
|
271
271
|
// TODO
|
|
272
272
|
process.env.DB_CONNECTION_STRING = "INVALID DATABASE";
|
package/testutils/fake_comms.js
CHANGED
package/testutils/fake_log.js
CHANGED
|
@@ -21,12 +21,12 @@ class FakeLogger {
|
|
|
21
21
|
this.logs = [];
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
exports.FakeLogger = FakeLogger;
|
|
25
24
|
// todo this is quick and ideal.
|
|
26
25
|
// more ideal is capturing all console.logs
|
|
27
26
|
// we do it in golang for example
|
|
28
27
|
// and will need this for production launch anyways
|
|
29
28
|
FakeLogger.logs = [];
|
|
29
|
+
exports.FakeLogger = FakeLogger;
|
|
30
30
|
// TODO instead of needing to add this manually
|
|
31
31
|
// we need to build a way to add global observers (and maybe triggers)
|
|
32
32
|
// to be run on every action/mutation
|
package/core/global_schema.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Field, GlobalSchema } from "../schema/schema";
|
|
2
|
-
export declare function setGlobalSchema(val: GlobalSchema): void;
|
|
3
|
-
export declare function clearGlobalSchema(): void;
|
|
4
|
-
export declare function __hasGlobalSchema(): boolean;
|
|
5
|
-
export declare function __getGlobalSchema(): GlobalSchema | undefined;
|
|
6
|
-
export declare function __getGlobalSchemaFields(): Map<string, Field>;
|
|
7
|
-
export declare function __getGlobalSchemaField(type: string): Field | undefined;
|
package/core/global_schema.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.__getGlobalSchemaField = exports.__getGlobalSchemaFields = exports.__getGlobalSchema = exports.__hasGlobalSchema = exports.clearGlobalSchema = exports.setGlobalSchema = void 0;
|
|
4
|
-
const schema_1 = require("../schema/schema");
|
|
5
|
-
let globalSchema;
|
|
6
|
-
let globalSchemaFields = new Map();
|
|
7
|
-
function isGlobalSchemaField(f) {
|
|
8
|
-
switch (f.type.dbType) {
|
|
9
|
-
case schema_1.DBType.Enum:
|
|
10
|
-
case schema_1.DBType.StringEnum:
|
|
11
|
-
case schema_1.DBType.IntEnum:
|
|
12
|
-
case schema_1.DBType.JSON:
|
|
13
|
-
case schema_1.DBType.JSONB:
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
function setGlobalSchema(val) {
|
|
19
|
-
globalSchema = val;
|
|
20
|
-
if (val.fields) {
|
|
21
|
-
for (const [k, v] of Object.entries(val.fields)) {
|
|
22
|
-
if (isGlobalSchemaField(v) && v.type.type) {
|
|
23
|
-
globalSchemaFields.set(v.type.type, v);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.setGlobalSchema = setGlobalSchema;
|
|
29
|
-
function clearGlobalSchema() {
|
|
30
|
-
globalSchema = undefined;
|
|
31
|
-
globalSchemaFields.clear();
|
|
32
|
-
}
|
|
33
|
-
exports.clearGlobalSchema = clearGlobalSchema;
|
|
34
|
-
// used by tests. no guarantee will always exist
|
|
35
|
-
function __hasGlobalSchema() {
|
|
36
|
-
return globalSchema !== undefined;
|
|
37
|
-
}
|
|
38
|
-
exports.__hasGlobalSchema = __hasGlobalSchema;
|
|
39
|
-
// used by tests. no guarantee will always exist
|
|
40
|
-
function __getGlobalSchema() {
|
|
41
|
-
return globalSchema;
|
|
42
|
-
}
|
|
43
|
-
exports.__getGlobalSchema = __getGlobalSchema;
|
|
44
|
-
function __getGlobalSchemaFields() {
|
|
45
|
-
return globalSchemaFields;
|
|
46
|
-
}
|
|
47
|
-
exports.__getGlobalSchemaFields = __getGlobalSchemaFields;
|
|
48
|
-
function __getGlobalSchemaField(type) {
|
|
49
|
-
return globalSchemaFields.get(type);
|
|
50
|
-
}
|
|
51
|
-
exports.__getGlobalSchemaField = __getGlobalSchemaField;
|