@snowtop/ent 0.1.0-alpha124 → 0.1.0-alpha126
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/base.d.ts +7 -8
- package/core/clause.d.ts +1 -2
- package/core/clause.js +1 -18
- package/core/ent.d.ts +10 -10
- package/core/ent.js +54 -35
- package/core/loaders/assoc_edge_loader.d.ts +1 -1
- package/core/loaders/object_loader.d.ts +8 -28
- package/core/loaders/object_loader.js +39 -176
- package/core/loaders/query_loader.d.ts +1 -1
- package/core/query/shared_test.js +1 -2
- package/graphql/graphql.d.ts +19 -12
- package/graphql/graphql.js +66 -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
|
@@ -1,46 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
7
8
|
};
|
|
8
|
-
var
|
|
9
|
-
if (
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.push(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.push(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
10
35
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
13
39
|
};
|
|
14
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
41
|
const graphql_1 = require("../../../graphql/graphql");
|
|
16
42
|
const graphql_2 = require("graphql");
|
|
17
|
-
let ViewerType =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
exports.default =
|
|
43
|
+
let ViewerType = (() => {
|
|
44
|
+
let _classDecorators = [(0, graphql_1.gqlObjectType)({ name: "Viewer" })];
|
|
45
|
+
let _classDescriptor;
|
|
46
|
+
let _classExtraInitializers = [];
|
|
47
|
+
let _classThis;
|
|
48
|
+
let _instanceExtraInitializers = [];
|
|
49
|
+
let _get_viewerID_decorators;
|
|
50
|
+
var ViewerType = _classThis = class {
|
|
51
|
+
constructor(viewer) {
|
|
52
|
+
this.viewer = (__runInitializers(this, _instanceExtraInitializers), viewer);
|
|
53
|
+
}
|
|
54
|
+
get viewerID() {
|
|
55
|
+
return this.viewer.viewerID;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
__setFunctionName(_classThis, "ViewerType");
|
|
59
|
+
(() => {
|
|
60
|
+
_get_viewerID_decorators = [(0, graphql_1.gqlField)({
|
|
61
|
+
nodeName: "ViewerType",
|
|
62
|
+
type: graphql_2.GraphQLID,
|
|
63
|
+
nullable: true,
|
|
64
|
+
})];
|
|
65
|
+
__esDecorate(_classThis, null, _get_viewerID_decorators, { kind: "getter", name: "viewerID", static: false, private: false, access: { has: obj => "viewerID" in obj, get: obj => obj.viewerID } }, null, _instanceExtraInitializers);
|
|
66
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name }, null, _classExtraInitializers);
|
|
67
|
+
ViewerType = _classThis = _classDescriptor.value;
|
|
68
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
69
|
+
})();
|
|
70
|
+
return ViewerType = _classThis;
|
|
71
|
+
})();
|
|
72
|
+
exports.default = (() => {
|
|
73
|
+
var _a;
|
|
74
|
+
let _instanceExtraInitializers_1 = [];
|
|
75
|
+
let _viewer_decorators;
|
|
76
|
+
return _a = class ViewerResolver {
|
|
77
|
+
viewer(context) {
|
|
78
|
+
return new ViewerType(context.getViewer());
|
|
79
|
+
}
|
|
80
|
+
constructor() {
|
|
81
|
+
__runInitializers(this, _instanceExtraInitializers_1);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
(() => {
|
|
85
|
+
_viewer_decorators = [(0, graphql_1.gqlQuery)({
|
|
86
|
+
nodeName: "ViewerResolver",
|
|
87
|
+
name: "viewer",
|
|
88
|
+
type: ViewerType,
|
|
89
|
+
args: [(0, graphql_1.gqlContextType)()],
|
|
90
|
+
})];
|
|
91
|
+
__esDecorate(_a, null, _viewer_decorators, { kind: "method", name: "viewer", static: false, private: false, access: { has: obj => "viewer" in obj, get: obj => obj.viewer } }, null, _instanceExtraInitializers_1);
|
|
92
|
+
})(),
|
|
93
|
+
_a;
|
|
94
|
+
})();
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from "./core/base";
|
|
2
|
-
export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, } from "./core/ent";
|
|
3
|
-
export { setGlobalSchema } from "./core/global_schema";
|
|
2
|
+
export { loadEnt, loadCustomData, loadCustomEnts, loadCustomCount, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, RawQueryOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
|
|
4
3
|
import DB from "./core/db";
|
|
5
4
|
export * from "./core/loaders";
|
|
6
5
|
export { DB };
|
package/index.js
CHANGED
|
@@ -63,8 +63,7 @@ Object.defineProperty(exports, "loadRawEdgeCountX", { enumerable: true, get: fun
|
|
|
63
63
|
Object.defineProperty(exports, "loadEdgeForID2", { enumerable: true, get: function () { return ent_1.loadEdgeForID2; } });
|
|
64
64
|
Object.defineProperty(exports, "loadNodesByEdge", { enumerable: true, get: function () { return ent_1.loadNodesByEdge; } });
|
|
65
65
|
Object.defineProperty(exports, "getEdgeTypeInGroup", { enumerable: true, get: function () { return ent_1.getEdgeTypeInGroup; } });
|
|
66
|
-
|
|
67
|
-
Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return global_schema_1.setGlobalSchema; } });
|
|
66
|
+
Object.defineProperty(exports, "setGlobalSchema", { enumerable: true, get: function () { return ent_1.setGlobalSchema; } });
|
|
68
67
|
const db_1 = __importDefault(require("./core/db"));
|
|
69
68
|
exports.DB = db_1.default;
|
|
70
69
|
__exportStar(require("./core/loaders"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha126",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -22,12 +22,11 @@
|
|
|
22
22
|
"pascal-case": "^3.1.2",
|
|
23
23
|
"pg": "^8.8.0",
|
|
24
24
|
"prettier": "^2.8.1",
|
|
25
|
-
"reflect-metadata": "^0.1.13",
|
|
26
25
|
"snake-case": "^3.0.4",
|
|
27
26
|
"ts-node": "^10.9.1",
|
|
28
|
-
"tsconfig-paths": "^4.
|
|
29
|
-
"tslib": "^2.
|
|
30
|
-
"typescript": "^
|
|
27
|
+
"tsconfig-paths": "^4.2.0",
|
|
28
|
+
"tslib": "^2.5.0",
|
|
29
|
+
"typescript": "^5.0.4",
|
|
31
30
|
"uuid": "^9.0.0"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
package/parse_schema/parse.d.ts
CHANGED
package/parse_schema/parse.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseSchema = void 0;
|
|
4
4
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
5
5
|
const const_1 = require("../core/const");
|
|
6
|
-
const global_schema_1 = require("../core/global_schema");
|
|
7
6
|
async function processFields(src, patternName) {
|
|
8
7
|
const ret = [];
|
|
9
8
|
let m = {};
|
|
@@ -237,9 +236,6 @@ async function parseSchema(potentialSchemas, globalSchema) {
|
|
|
237
236
|
let parsedGlobalSchema;
|
|
238
237
|
if (globalSchema) {
|
|
239
238
|
parsedGlobalSchema = await parseGlobalSchema(globalSchema);
|
|
240
|
-
// set this so that we can use it, if we're trying to process server default or anything
|
|
241
|
-
// that ends up parsing,validating and formatting fields
|
|
242
|
-
(0, global_schema_1.setGlobalSchema)(globalSchema);
|
|
243
239
|
}
|
|
244
240
|
for (const key in potentialSchemas) {
|
|
245
241
|
const value = potentialSchemas[key];
|
|
@@ -358,10 +354,9 @@ async function parseGlobalSchema(s) {
|
|
|
358
354
|
const ret = {
|
|
359
355
|
globalEdges: [],
|
|
360
356
|
extraEdgeFields: [],
|
|
361
|
-
|
|
357
|
+
initForEdges: !!s.extraEdgeFields ||
|
|
362
358
|
s.transformEdgeRead !== undefined ||
|
|
363
|
-
s.transformEdgeWrite !== undefined
|
|
364
|
-
s.fields !== undefined,
|
|
359
|
+
s.transformEdgeWrite !== undefined,
|
|
365
360
|
};
|
|
366
361
|
if (s.extraEdgeFields) {
|
|
367
362
|
ret.extraEdgeFields = await processFields(s.extraEdgeFields);
|
|
@@ -369,8 +364,5 @@ async function parseGlobalSchema(s) {
|
|
|
369
364
|
if (s.edges) {
|
|
370
365
|
ret.globalEdges = processEdges(s.edges);
|
|
371
366
|
}
|
|
372
|
-
if (s.fields) {
|
|
373
|
-
ret.globalFields = await processFields(s.fields);
|
|
374
|
-
}
|
|
375
367
|
return ret;
|
|
376
368
|
}
|
package/schema/field.d.ts
CHANGED
|
@@ -149,7 +149,6 @@ export interface EnumOptions extends FieldOptions {
|
|
|
149
149
|
graphQLType?: string;
|
|
150
150
|
createEnumType?: boolean;
|
|
151
151
|
disableUnknownType?: boolean;
|
|
152
|
-
globalType?: string;
|
|
153
152
|
}
|
|
154
153
|
/**
|
|
155
154
|
* @deprecated Use StringEnumField
|
|
@@ -159,7 +158,7 @@ export declare class EnumField extends BaseField implements Field {
|
|
|
159
158
|
private values?;
|
|
160
159
|
private map?;
|
|
161
160
|
constructor(options: StringEnumOptions);
|
|
162
|
-
valid(val: any):
|
|
161
|
+
valid(val: any): boolean;
|
|
163
162
|
format(val: any): any;
|
|
164
163
|
}
|
|
165
164
|
export declare class StringEnumField extends EnumField {
|
|
@@ -174,18 +173,17 @@ declare type IntEnumMap = {
|
|
|
174
173
|
[key: string]: number;
|
|
175
174
|
};
|
|
176
175
|
export interface IntegerEnumOptions extends FieldOptions {
|
|
177
|
-
map
|
|
176
|
+
map: IntEnumMap;
|
|
178
177
|
deprecated?: IntEnumMap;
|
|
179
178
|
tsType?: string;
|
|
180
179
|
graphQLType?: string;
|
|
181
180
|
disableUnknownType?: boolean;
|
|
182
|
-
globalType?: string;
|
|
183
181
|
}
|
|
184
182
|
export declare class IntegerEnumField extends BaseField implements Field {
|
|
185
183
|
type: Type;
|
|
186
184
|
private map;
|
|
187
185
|
constructor(options: IntegerEnumOptions);
|
|
188
|
-
valid(val: any):
|
|
186
|
+
valid(val: any): boolean;
|
|
189
187
|
format(val: any): any;
|
|
190
188
|
}
|
|
191
189
|
export declare function IntegerEnumType(options: IntegerEnumOptions): IntegerEnumField;
|
package/schema/field.js
CHANGED
|
@@ -31,8 +31,6 @@ const uuid_1 = require("uuid");
|
|
|
31
31
|
const base_1 = require("../core/base");
|
|
32
32
|
const db_1 = __importStar(require("../core/db"));
|
|
33
33
|
const schema_1 = require("./schema");
|
|
34
|
-
const global_schema_1 = require("../core/global_schema");
|
|
35
|
-
const logger_1 = require("../core/logger");
|
|
36
34
|
class BaseField {
|
|
37
35
|
logValue(val) {
|
|
38
36
|
if (this.sensitive) {
|
|
@@ -527,11 +525,10 @@ class EnumField extends BaseField {
|
|
|
527
525
|
type: options.tsType,
|
|
528
526
|
graphQLType: options.graphQLType,
|
|
529
527
|
disableUnknownType: options.disableUnknownType,
|
|
530
|
-
globalType: options.globalType,
|
|
531
528
|
};
|
|
532
529
|
if (!options.foreignKey) {
|
|
533
|
-
if (!options.values && !options.map
|
|
534
|
-
throw new Error("values
|
|
530
|
+
if (!options.values && !options.map) {
|
|
531
|
+
throw new Error("values or map required if not look up table enum. Look-up table enum indicated by foreignKey field");
|
|
535
532
|
}
|
|
536
533
|
if (options.values) {
|
|
537
534
|
if (!options.values.length) {
|
|
@@ -550,8 +547,8 @@ class EnumField extends BaseField {
|
|
|
550
547
|
}
|
|
551
548
|
}
|
|
552
549
|
else {
|
|
553
|
-
if (options.values || options.map
|
|
554
|
-
throw new Error("cannot specify values
|
|
550
|
+
if (options.values || options.map) {
|
|
551
|
+
throw new Error("cannot specify values or map and foreign key for lookup table enum type");
|
|
555
552
|
}
|
|
556
553
|
if (options.createEnumType) {
|
|
557
554
|
throw new Error("cannot specify createEnumType without specifying values");
|
|
@@ -566,20 +563,7 @@ class EnumField extends BaseField {
|
|
|
566
563
|
this.values = options.values;
|
|
567
564
|
this.map = options.map;
|
|
568
565
|
}
|
|
569
|
-
|
|
570
|
-
if (this.type.globalType) {
|
|
571
|
-
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
572
|
-
if (f) {
|
|
573
|
-
if (f.valid) {
|
|
574
|
-
return f.valid(val);
|
|
575
|
-
}
|
|
576
|
-
return true;
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
566
|
+
valid(val) {
|
|
583
567
|
// lookup table enum and indicated via presence of foreignKey
|
|
584
568
|
if (!this.values && !this.map) {
|
|
585
569
|
return true;
|
|
@@ -597,13 +581,6 @@ class EnumField extends BaseField {
|
|
|
597
581
|
return false;
|
|
598
582
|
}
|
|
599
583
|
format(val) {
|
|
600
|
-
if (this.type.globalType) {
|
|
601
|
-
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
602
|
-
if (f && f.format) {
|
|
603
|
-
return f.format(val);
|
|
604
|
-
}
|
|
605
|
-
return val;
|
|
606
|
-
}
|
|
607
584
|
return val;
|
|
608
585
|
}
|
|
609
586
|
}
|
|
@@ -626,46 +603,21 @@ class IntegerEnumField extends BaseField {
|
|
|
626
603
|
graphQLType: options.graphQLType,
|
|
627
604
|
deprecatedIntEnumMap: options.deprecated,
|
|
628
605
|
disableUnknownType: options.disableUnknownType,
|
|
629
|
-
globalType: options.globalType,
|
|
630
606
|
};
|
|
631
|
-
|
|
632
|
-
|
|
607
|
+
let count = 0;
|
|
608
|
+
for (const _ in options.map) {
|
|
609
|
+
count++;
|
|
610
|
+
break;
|
|
633
611
|
}
|
|
634
|
-
if (
|
|
635
|
-
|
|
636
|
-
throw new Error(`cannot specify map and globalType`);
|
|
637
|
-
}
|
|
638
|
-
this.map = {};
|
|
612
|
+
if (!count) {
|
|
613
|
+
throw new Error("need at least one entry in enum map");
|
|
639
614
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
for (const _ in options.map) {
|
|
643
|
-
count++;
|
|
644
|
-
break;
|
|
645
|
-
}
|
|
646
|
-
if (!count) {
|
|
647
|
-
throw new Error("need at least one entry in enum map");
|
|
648
|
-
}
|
|
649
|
-
if (!options.map) {
|
|
650
|
-
throw new Error("map required if not globalType");
|
|
651
|
-
}
|
|
652
|
-
this.map = options.map;
|
|
615
|
+
if (options.foreignKey) {
|
|
616
|
+
throw new Error(`foreignKey on intEnum not supported`);
|
|
653
617
|
}
|
|
618
|
+
this.map = options.map;
|
|
654
619
|
}
|
|
655
|
-
|
|
656
|
-
if (this.type?.globalType) {
|
|
657
|
-
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
658
|
-
if (f) {
|
|
659
|
-
if (f.valid) {
|
|
660
|
-
return f.valid(val);
|
|
661
|
-
}
|
|
662
|
-
return true;
|
|
663
|
-
}
|
|
664
|
-
else {
|
|
665
|
-
(0, logger_1.log)("error", `globalType ${this.type.globalType} not found in global schema`);
|
|
666
|
-
return false;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
620
|
+
valid(val) {
|
|
669
621
|
// lookup table enum and indicated via presence of foreignKey
|
|
670
622
|
for (const k in this.map) {
|
|
671
623
|
const v = this.map[k];
|
|
@@ -676,12 +628,6 @@ class IntegerEnumField extends BaseField {
|
|
|
676
628
|
return false;
|
|
677
629
|
}
|
|
678
630
|
format(val) {
|
|
679
|
-
if (this.type.globalType) {
|
|
680
|
-
const f = (0, global_schema_1.__getGlobalSchemaField)(this.type.globalType);
|
|
681
|
-
if (f && f.format) {
|
|
682
|
-
return f.format(val);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
631
|
return parseInt(val);
|
|
686
632
|
}
|
|
687
633
|
}
|
package/schema/schema.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export interface GlobalSchema {
|
|
|
17
17
|
extraEdgeFields?: FieldMap;
|
|
18
18
|
transformEdgeRead?: () => Clause;
|
|
19
19
|
transformEdgeWrite?: (stmt: EdgeUpdateOperation) => TransformedEdgeUpdateOperation | null;
|
|
20
|
-
fields?: FieldMap;
|
|
21
20
|
}
|
|
22
21
|
type FieldOverride = Pick<FieldOptions, "nullable" | "storageKey" | "serverDefault" | "unique" | "hideFromGraphQL" | "graphqlName" | "index">;
|
|
23
22
|
export type FieldOverrideMap = {
|
|
@@ -172,7 +171,6 @@ export interface Type {
|
|
|
172
171
|
intEnumMap?: IntEnumMap;
|
|
173
172
|
deprecatedIntEnumMap?: IntEnumMap;
|
|
174
173
|
disableUnknownType?: boolean;
|
|
175
|
-
globalType?: string;
|
|
176
174
|
importType?: DeprecatedImportType;
|
|
177
175
|
subFields?: FieldMap;
|
|
178
176
|
unionFields?: FieldMap;
|
package/schema/struct_field.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { BaseField, ListField } from "./field";
|
|
2
2
|
import { FieldOptions, Field, Type, FieldMap } from "./schema";
|
|
3
|
-
interface
|
|
3
|
+
export interface StructOptions 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 allStructOptions extends StructOptions {
|
|
10
|
+
jsonAsList?: boolean;
|
|
11
11
|
}
|
|
12
|
-
export type StructOptions = structFieldOptions | GlobalStructOptions;
|
|
13
12
|
export declare class StructField extends BaseField implements Field {
|
|
14
13
|
private options;
|
|
15
|
-
private jsonAsList?;
|
|
16
14
|
type: Type;
|
|
17
|
-
constructor(options:
|
|
15
|
+
constructor(options: allStructOptions);
|
|
18
16
|
formatImpl(obj: any, nested?: boolean): string | Object;
|
|
19
|
-
format(obj: any, nested?: boolean):
|
|
17
|
+
format(obj: any, nested?: boolean): string | Object;
|
|
20
18
|
private validImpl;
|
|
21
19
|
valid(obj: any): Promise<boolean>;
|
|
22
20
|
}
|
|
@@ -25,5 +23,5 @@ export declare function StructType(options: StructOptions): StructField & Struct
|
|
|
25
23
|
* @deprecated use StructTypeAsList
|
|
26
24
|
*/
|
|
27
25
|
export declare function StructListType(options: StructOptions): ListField;
|
|
28
|
-
export declare function StructTypeAsList(options:
|
|
26
|
+
export declare function StructTypeAsList(options: allStructOptions): StructField & allStructOptions;
|
|
29
27
|
export {};
|
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
|