@snowtop/ent 0.1.0-alpha7 → 0.1.0-alpha75
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 +29 -22
- package/action/experimental_action.js +29 -6
- package/action/orchestrator.d.ts +44 -16
- package/action/orchestrator.js +287 -73
- package/action/privacy.d.ts +2 -2
- package/core/base.d.ts +43 -23
- package/core/base.js +16 -0
- package/core/clause.d.ts +82 -3
- package/core/clause.js +463 -27
- package/core/config.d.ts +26 -0
- package/core/config.js +17 -0
- package/core/context.d.ts +5 -3
- package/core/context.js +7 -2
- package/core/convert.d.ts +1 -1
- package/core/db.d.ts +3 -4
- package/core/db.js +2 -0
- package/core/ent.d.ts +71 -27
- package/core/ent.js +458 -97
- package/core/loaders/assoc_count_loader.d.ts +2 -2
- package/core/loaders/assoc_count_loader.js +6 -1
- 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/loader.js +5 -5
- package/core/loaders/object_loader.d.ts +11 -5
- package/core/loaders/object_loader.js +70 -4
- package/core/loaders/query_loader.d.ts +2 -2
- package/core/loaders/raw_count_loader.d.ts +2 -2
- package/core/logger.d.ts +1 -1
- package/core/logger.js +1 -0
- package/core/privacy.d.ts +26 -25
- package/core/privacy.js +23 -24
- 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/query/shared_assoc_test.d.ts +1 -1
- package/core/query/shared_assoc_test.js +17 -5
- package/core/query/shared_test.d.ts +3 -0
- package/core/query/shared_test.js +95 -17
- package/core/viewer.d.ts +4 -3
- package/core/viewer.js +5 -1
- 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 +30 -23
- 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 +21 -1
- package/index.js +24 -5
- package/package.json +3 -3
- package/parse_schema/parse.d.ts +24 -5
- package/parse_schema/parse.js +90 -8
- package/schema/base_schema.d.ts +36 -1
- package/schema/base_schema.js +51 -2
- package/schema/field.d.ts +34 -6
- package/schema/field.js +67 -2
- package/schema/index.d.ts +2 -2
- package/schema/index.js +8 -1
- package/schema/json_field.d.ts +13 -1
- package/schema/json_field.js +28 -1
- package/schema/schema.d.ts +101 -2
- package/schema/schema.js +127 -5
- package/schema/struct_field.d.ts +11 -1
- package/schema/struct_field.js +43 -4
- package/scripts/custom_graphql.js +127 -16
- 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 +25 -2
- package/testutils/builder.d.ts +36 -22
- package/testutils/builder.js +110 -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 → temp_db.d.ts} +17 -4
- package/testutils/db/{test_db.js → temp_db.js} +76 -19
- 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 +5 -9
- package/testutils/fake_data/fake_contact.js +17 -21
- package/testutils/fake_data/fake_event.d.ts +5 -9
- package/testutils/fake_data/fake_event.js +24 -28
- package/testutils/fake_data/fake_user.d.ts +6 -10
- package/testutils/fake_data/fake_user.js +25 -29
- package/testutils/fake_data/test_helpers.d.ts +2 -2
- package/testutils/fake_data/test_helpers.js +6 -6
- package/testutils/fake_data/user_query.d.ts +2 -2
- package/testutils/fake_log.d.ts +3 -3
- package/testutils/parse_sql.d.ts +6 -0
- package/testutils/parse_sql.js +16 -2
- package/testutils/test_edge_global_schema.d.ts +15 -0
- package/testutils/test_edge_global_schema.js +58 -0
- package/testutils/write.d.ts +2 -2
- package/testutils/write.js +3 -3
- package/tsc/ast.d.ts +44 -0
- package/tsc/ast.js +267 -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 +22 -0
- package/tsc/transform_action.js +179 -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 +379 -0
- package/scripts/transform_schema.js +0 -288
|
@@ -4,11 +4,14 @@ import { EdgeQuery } from "./query";
|
|
|
4
4
|
interface options<TData extends Data> {
|
|
5
5
|
newQuery: (v: Viewer, user: FakeUser) => EdgeQuery<FakeUser, FakeContact, TData>;
|
|
6
6
|
tableName: string;
|
|
7
|
+
uniqKey: string;
|
|
7
8
|
entsLength?: number;
|
|
8
9
|
where: string;
|
|
9
10
|
sortCol: string;
|
|
10
11
|
livePostgresDB?: boolean;
|
|
11
12
|
sqlite?: boolean;
|
|
13
|
+
globalSchema?: boolean;
|
|
14
|
+
rawDataVerify?(user: FakeUser): Promise<void>;
|
|
12
15
|
}
|
|
13
16
|
export declare const commonTests: <TData extends Data>(opts: options<TData>) => void;
|
|
14
17
|
export {};
|
|
@@ -6,9 +6,12 @@ const ent_1 = require("../ent");
|
|
|
6
6
|
const viewer_1 = require("../viewer");
|
|
7
7
|
const index_1 = require("../../testutils/fake_data/index");
|
|
8
8
|
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
9
|
-
const
|
|
9
|
+
const temp_db_1 = require("../../testutils/db/temp_db");
|
|
10
10
|
const test_context_1 = require("../../testutils/context/test_context");
|
|
11
11
|
const logger_1 = require("../logger");
|
|
12
|
+
const test_edge_global_schema_1 = require("../../testutils/test_edge_global_schema");
|
|
13
|
+
const builder_1 = require("../../testutils/builder");
|
|
14
|
+
const action_1 = require("../../action");
|
|
12
15
|
class TestQueryFilter {
|
|
13
16
|
constructor(filter, newQuery, ents, defaultViewer) {
|
|
14
17
|
this.filter = filter;
|
|
@@ -37,19 +40,19 @@ class TestQueryFilter {
|
|
|
37
40
|
expect(ids).toEqual(this.filteredContacts.map((contact) => contact.id));
|
|
38
41
|
}
|
|
39
42
|
// rawCount isn't affected by filters...
|
|
40
|
-
async testRawCount() {
|
|
43
|
+
async testRawCount(expectedCount) {
|
|
41
44
|
const count = await this.getQuery().queryRawCount();
|
|
42
|
-
this.verifyRawCount(count);
|
|
45
|
+
this.verifyRawCount(count, expectedCount);
|
|
43
46
|
}
|
|
44
|
-
verifyRawCount(count) {
|
|
45
|
-
expect(count).toBe(test_helpers_1.inputs.length);
|
|
47
|
+
verifyRawCount(count, expectedCount) {
|
|
48
|
+
expect(count).toBe(expectedCount ?? test_helpers_1.inputs.length);
|
|
46
49
|
}
|
|
47
|
-
async testCount() {
|
|
50
|
+
async testCount(expectedCount) {
|
|
48
51
|
const count = await this.getQuery().queryCount();
|
|
49
|
-
this.verifyCount(count);
|
|
52
|
+
this.verifyCount(count, expectedCount);
|
|
50
53
|
}
|
|
51
|
-
verifyCount(count) {
|
|
52
|
-
expect(count).toBe(this.filteredContacts.length);
|
|
54
|
+
verifyCount(count, expectedCount) {
|
|
55
|
+
expect(count).toBe(expectedCount ?? this.filteredContacts.length);
|
|
53
56
|
}
|
|
54
57
|
async testEdges() {
|
|
55
58
|
const edges = await this.getQuery().queryEdges();
|
|
@@ -72,7 +75,7 @@ class TestQueryFilter {
|
|
|
72
75
|
verifyEnts(ents) {
|
|
73
76
|
(0, test_helpers_1.verifyUserToContacts)(this.user, ents, this.filteredContacts);
|
|
74
77
|
}
|
|
75
|
-
async testAll() {
|
|
78
|
+
async testAll(expectedCount) {
|
|
76
79
|
const query = this.getQuery(new viewer_1.IDViewer(this.user.id));
|
|
77
80
|
const [edges, count, ids, rawCount, ents] = await Promise.all([
|
|
78
81
|
query.queryEdges(),
|
|
@@ -81,10 +84,10 @@ class TestQueryFilter {
|
|
|
81
84
|
query.queryRawCount(),
|
|
82
85
|
query.queryEnts(),
|
|
83
86
|
]);
|
|
84
|
-
this.verifyCount(count);
|
|
87
|
+
this.verifyCount(count, expectedCount);
|
|
85
88
|
this.verifyEdges(edges);
|
|
86
89
|
this.verifyIDs(ids);
|
|
87
|
-
this.verifyRawCount(rawCount);
|
|
90
|
+
this.verifyRawCount(rawCount, expectedCount);
|
|
88
91
|
this.verifyEnts(ents);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
@@ -125,7 +128,19 @@ const commonTests = (opts) => {
|
|
|
125
128
|
expect(queries.length).toBe(length);
|
|
126
129
|
const query = queries[0];
|
|
127
130
|
const result = [...opts.where.matchAll(preparedVar)];
|
|
128
|
-
|
|
131
|
+
let parts = opts.where.split(" AND ");
|
|
132
|
+
if (parts[parts.length - 1] === "deleted_at IS NULL") {
|
|
133
|
+
parts = parts
|
|
134
|
+
.slice(0, parts.length - 1)
|
|
135
|
+
.concat([
|
|
136
|
+
`${opts.sortCol} < $${result.length + 1}`,
|
|
137
|
+
"deleted_at IS NULL",
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
parts.push(`${opts.sortCol} < $${result.length + 1}`);
|
|
142
|
+
}
|
|
143
|
+
expect(query.qs?.whereClause).toBe(`${parts.join(" AND ")} ORDER BY ${opts.sortCol} DESC LIMIT 4`);
|
|
129
144
|
}
|
|
130
145
|
function verifyLastBeforeCursorQuery(length = 1) {
|
|
131
146
|
if (opts.livePostgresDB || opts.sqlite) {
|
|
@@ -135,9 +150,21 @@ const commonTests = (opts) => {
|
|
|
135
150
|
expect(queries.length).toBe(length);
|
|
136
151
|
const query = queries[0];
|
|
137
152
|
const result = [...opts.where.matchAll(preparedVar)];
|
|
153
|
+
let parts = opts.where.split(" AND ");
|
|
154
|
+
if (parts[parts.length - 1] === "deleted_at IS NULL") {
|
|
155
|
+
parts = parts
|
|
156
|
+
.slice(0, parts.length - 1)
|
|
157
|
+
.concat([
|
|
158
|
+
`${opts.sortCol} > $${result.length + 1}`,
|
|
159
|
+
"deleted_at IS NULL",
|
|
160
|
+
]);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
parts.push(`${opts.sortCol} > $${result.length + 1}`);
|
|
164
|
+
}
|
|
138
165
|
expect(query.qs?.whereClause).toBe(
|
|
139
166
|
// extra fetched for pagination
|
|
140
|
-
`${
|
|
167
|
+
`${parts.join(" AND ")} ORDER BY ${opts.sortCol} ASC LIMIT 4`);
|
|
141
168
|
}
|
|
142
169
|
function getViewer() {
|
|
143
170
|
// live db, let's do context because we're testing complicated paths
|
|
@@ -171,10 +198,12 @@ const commonTests = (opts) => {
|
|
|
171
198
|
cursorKey: opts.sortCol,
|
|
172
199
|
});
|
|
173
200
|
}
|
|
201
|
+
if (opts.globalSchema) {
|
|
202
|
+
(0, ent_1.setGlobalSchema)(test_edge_global_schema_1.testEdgeGlobalSchema);
|
|
203
|
+
}
|
|
174
204
|
let tdb;
|
|
175
205
|
if (opts.sqlite) {
|
|
176
|
-
|
|
177
|
-
(0, test_db_1.setupSqlite)(`sqlite:///shared_test+${opts.tableName}.db`, test_helpers_1.tempDBTables);
|
|
206
|
+
(0, temp_db_1.setupSqlite)(`sqlite:///shared_test+${opts.uniqKey}.db`, () => (0, test_helpers_1.tempDBTables)(opts.globalSchema));
|
|
178
207
|
}
|
|
179
208
|
beforeAll(async () => {
|
|
180
209
|
// want error on by default in tests?
|
|
@@ -196,7 +225,7 @@ const commonTests = (opts) => {
|
|
|
196
225
|
});
|
|
197
226
|
describe("simple queries", () => {
|
|
198
227
|
const filter = new TestQueryFilter((q) => {
|
|
199
|
-
// no
|
|
228
|
+
// no filters
|
|
200
229
|
return q;
|
|
201
230
|
}, opts.newQuery, (contacts) => {
|
|
202
231
|
// nothing to do here
|
|
@@ -230,6 +259,55 @@ const commonTests = (opts) => {
|
|
|
230
259
|
await filter.testAll();
|
|
231
260
|
});
|
|
232
261
|
});
|
|
262
|
+
describe("after delete", () => {
|
|
263
|
+
const filter = new TestQueryFilter((q) => {
|
|
264
|
+
// no filters
|
|
265
|
+
return q;
|
|
266
|
+
}, opts.newQuery, (contacts) => {
|
|
267
|
+
// nothing expected since deleted
|
|
268
|
+
return [];
|
|
269
|
+
}, getViewer());
|
|
270
|
+
beforeEach(async () => {
|
|
271
|
+
await filter.beforeEach();
|
|
272
|
+
const action = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeUserSchema, new Map(), action_1.WriteOperation.Edit, filter.user);
|
|
273
|
+
await Promise.all(filter.allContacts.map(async (contact) => {
|
|
274
|
+
action.builder.orchestrator.removeOutboundEdge(contact.id, index_1.EdgeType.UserToContacts);
|
|
275
|
+
const action2 = new builder_1.SimpleAction(filter.user.viewer, index_1.FakeContactSchema, new Map(), action_1.WriteOperation.Delete, contact);
|
|
276
|
+
await action2.save();
|
|
277
|
+
}));
|
|
278
|
+
await action.save();
|
|
279
|
+
db_mock_1.QueryRecorder.clearQueries();
|
|
280
|
+
});
|
|
281
|
+
test("ids", async () => {
|
|
282
|
+
await filter.testIDs();
|
|
283
|
+
verifyQuery({});
|
|
284
|
+
});
|
|
285
|
+
test("rawCount", async () => {
|
|
286
|
+
await filter.testRawCount(0);
|
|
287
|
+
verifyCountQuery({});
|
|
288
|
+
});
|
|
289
|
+
test("count", async () => {
|
|
290
|
+
await filter.testCount(0);
|
|
291
|
+
verifyQuery({});
|
|
292
|
+
});
|
|
293
|
+
test("edges", async () => {
|
|
294
|
+
await filter.testEdges();
|
|
295
|
+
verifyQuery({});
|
|
296
|
+
});
|
|
297
|
+
test("ents", async () => {
|
|
298
|
+
await filter.testEnts();
|
|
299
|
+
// no ents so no subsequent query. just the edge query
|
|
300
|
+
verifyQuery({ length: 1 });
|
|
301
|
+
});
|
|
302
|
+
test("all", async () => {
|
|
303
|
+
await filter.testAll(0);
|
|
304
|
+
});
|
|
305
|
+
test("raw_data", async () => {
|
|
306
|
+
if (opts.rawDataVerify) {
|
|
307
|
+
await opts.rawDataVerify(filter.user);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
233
311
|
describe("first. no cursor", () => {
|
|
234
312
|
const N = 2;
|
|
235
313
|
const filter = new TestQueryFilter((q) => {
|
package/core/viewer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ID, Ent, Viewer, Context } from "./base";
|
|
2
2
|
export declare class LoggedOutViewer implements Viewer {
|
|
3
|
-
context?: Context | undefined;
|
|
4
|
-
constructor(context?: Context | undefined);
|
|
3
|
+
context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined;
|
|
4
|
+
constructor(context?: Context<Viewer<Ent<any> | null, ID | null>> | undefined);
|
|
5
5
|
viewerID: null;
|
|
6
6
|
viewer(): Promise<null>;
|
|
7
7
|
instanceKey(): string;
|
|
@@ -17,6 +17,7 @@ export declare class IDViewer implements Viewer {
|
|
|
17
17
|
context?: Context;
|
|
18
18
|
constructor(viewerID: ID, opts?: Partial<IDViewerOptions>);
|
|
19
19
|
constructor(opts: IDViewerOptions);
|
|
20
|
-
|
|
20
|
+
setContext(ctx: Context): this;
|
|
21
|
+
viewer(): Promise<Ent<Viewer<Ent<any> | null, ID | null>> | null>;
|
|
21
22
|
instanceKey(): string;
|
|
22
23
|
}
|
package/core/viewer.js
CHANGED
|
@@ -27,11 +27,15 @@ class IDViewer {
|
|
|
27
27
|
this.ent = opts?.ent || null;
|
|
28
28
|
this.context = opts?.context;
|
|
29
29
|
}
|
|
30
|
+
setContext(ctx) {
|
|
31
|
+
this.context = ctx;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
30
34
|
async viewer() {
|
|
31
35
|
return this.ent;
|
|
32
36
|
}
|
|
33
37
|
instanceKey() {
|
|
34
|
-
return `idViewer
|
|
38
|
+
return `idViewer:${this.viewerID}`;
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
exports.IDViewer = IDViewer;
|
|
@@ -11,13 +11,13 @@ exports.GraphQLConnectionInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
11
11
|
description: "connection interface",
|
|
12
12
|
fields: () => ({
|
|
13
13
|
edges: {
|
|
14
|
-
type:
|
|
14
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edge_1.GraphQLEdgeInterface))),
|
|
15
15
|
},
|
|
16
16
|
nodes: {
|
|
17
|
-
type:
|
|
17
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface))),
|
|
18
18
|
},
|
|
19
19
|
pageInfo: {
|
|
20
|
-
type:
|
|
20
|
+
type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
|
|
21
21
|
},
|
|
22
22
|
}),
|
|
23
23
|
});
|
package/graphql/builtins/edge.js
CHANGED
|
@@ -9,10 +9,10 @@ exports.GraphQLEdgeInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
9
9
|
description: "edge interface",
|
|
10
10
|
fields: () => ({
|
|
11
11
|
node: {
|
|
12
|
-
type:
|
|
12
|
+
type: new graphql_1.GraphQLNonNull(node_1.GraphQLNodeInterface),
|
|
13
13
|
},
|
|
14
14
|
cursor: {
|
|
15
|
-
type:
|
|
15
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
16
16
|
},
|
|
17
17
|
}),
|
|
18
18
|
});
|
package/graphql/builtins/node.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.GraphQLNodeInterface = new graphql_1.GraphQLInterfaceType({
|
|
|
8
8
|
description: "node interface",
|
|
9
9
|
fields: () => ({
|
|
10
10
|
id: {
|
|
11
|
-
type:
|
|
11
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
12
12
|
},
|
|
13
13
|
}),
|
|
14
14
|
});
|
package/graphql/graphql.d.ts
CHANGED
|
@@ -82,6 +82,9 @@ declare enum NullableResult {
|
|
|
82
82
|
CONTENTS_AND_LIST = "contentsAndList",
|
|
83
83
|
ITEM = "true"
|
|
84
84
|
}
|
|
85
|
+
export declare const knownAllowedNames: Map<string, string>;
|
|
86
|
+
export declare const knownDisAllowedNames: Map<string, boolean>;
|
|
87
|
+
export declare const isCustomType: (type: Type) => type is CustomType;
|
|
85
88
|
export declare const addCustomType: (type: CustomType) => void;
|
|
86
89
|
export declare class GQLCapture {
|
|
87
90
|
private static enabled;
|
|
@@ -107,8 +110,6 @@ export declare class GQLCapture {
|
|
|
107
110
|
static getProcessedCustomMutations(): ProcessedCustomField[];
|
|
108
111
|
static getProcessedCustomQueries(): ProcessedCustomField[];
|
|
109
112
|
private static getProcessedCustomFieldsImpl;
|
|
110
|
-
private static knownAllowedNames;
|
|
111
|
-
private static knownDisAllowedNames;
|
|
112
113
|
private static getResultFromMetadata;
|
|
113
114
|
static gqlField(options?: gqlFieldOptions): any;
|
|
114
115
|
private static getCustomField;
|
package/graphql/graphql.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.CustomFieldType = void 0;
|
|
3
|
+
exports.gqlFileUpload = exports.gqlConnection = exports.gqlContextType = exports.gqlMutation = exports.gqlQuery = exports.gqlObjectType = exports.gqlInputObjectType = exports.gqlArgType = exports.gqlArg = exports.gqlField = exports.GQLCapture = exports.addCustomType = exports.isCustomType = exports.knownDisAllowedNames = exports.knownAllowedNames = exports.CustomFieldType = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
// export interface gqlTopLevelOptions
|
|
6
6
|
// name?: string;
|
|
@@ -20,6 +20,22 @@ var NullableResult;
|
|
|
20
20
|
NullableResult["CONTENTS_AND_LIST"] = "contentsAndList";
|
|
21
21
|
NullableResult["ITEM"] = "true";
|
|
22
22
|
})(NullableResult || (NullableResult = {}));
|
|
23
|
+
exports.knownAllowedNames = new Map([
|
|
24
|
+
["Date", "Date"],
|
|
25
|
+
["Boolean", "boolean"],
|
|
26
|
+
["Number", "number"],
|
|
27
|
+
["String", "string"],
|
|
28
|
+
// TODO not right to have this and Number
|
|
29
|
+
["Int", "number"],
|
|
30
|
+
["Float", "number"],
|
|
31
|
+
["ID", "ID"],
|
|
32
|
+
]);
|
|
33
|
+
exports.knownDisAllowedNames = new Map([
|
|
34
|
+
["Function", true],
|
|
35
|
+
["Object", true],
|
|
36
|
+
["Array", true],
|
|
37
|
+
["Promise", true],
|
|
38
|
+
]);
|
|
23
39
|
const isArray = (type) => {
|
|
24
40
|
if (typeof type === "function") {
|
|
25
41
|
return false;
|
|
@@ -41,6 +57,7 @@ const isString = (type) => {
|
|
|
41
57
|
const isCustomType = (type) => {
|
|
42
58
|
return type.importPath !== undefined;
|
|
43
59
|
};
|
|
60
|
+
exports.isCustomType = isCustomType;
|
|
44
61
|
const isGraphQLScalarType = (type) => {
|
|
45
62
|
return type.serialize !== undefined;
|
|
46
63
|
};
|
|
@@ -62,12 +79,18 @@ const addCustomType = (type) => {
|
|
|
62
79
|
description: ct.description,
|
|
63
80
|
name: ct.name,
|
|
64
81
|
};
|
|
65
|
-
if (ct.
|
|
66
|
-
type.scalarInfo.specifiedByUrl = ct.
|
|
82
|
+
if (ct.specifiedByURL) {
|
|
83
|
+
type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
|
|
67
84
|
}
|
|
68
85
|
}
|
|
69
86
|
}
|
|
70
87
|
catch (e) {
|
|
88
|
+
if (type.secondaryImportPath) {
|
|
89
|
+
(0, exports.addCustomType)({
|
|
90
|
+
...type,
|
|
91
|
+
importPath: type.secondaryImportPath,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
71
94
|
return;
|
|
72
95
|
}
|
|
73
96
|
GQLCapture.getCustomTypes().set(type.type, type);
|
|
@@ -92,7 +115,7 @@ const getType = (typ, result) => {
|
|
|
92
115
|
}
|
|
93
116
|
return;
|
|
94
117
|
}
|
|
95
|
-
if (isCustomType(typ)) {
|
|
118
|
+
if ((0, exports.isCustomType)(typ)) {
|
|
96
119
|
result.type = typ.type;
|
|
97
120
|
(0, exports.addCustomType)(typ);
|
|
98
121
|
return;
|
|
@@ -197,20 +220,20 @@ class GQLCapture {
|
|
|
197
220
|
connection = r.connection;
|
|
198
221
|
type = r.type;
|
|
199
222
|
}
|
|
200
|
-
if (
|
|
223
|
+
if (exports.knownDisAllowedNames.has(type)) {
|
|
201
224
|
throw new Error(`${type} isn't a valid type for accessor/function/property`);
|
|
202
225
|
}
|
|
203
226
|
let result = {
|
|
204
227
|
name: metadata.paramName || "",
|
|
205
228
|
type,
|
|
206
|
-
tsType:
|
|
229
|
+
tsType: exports.knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
|
|
207
230
|
nullable: options?.nullable,
|
|
208
231
|
list: list,
|
|
209
232
|
connection: connection,
|
|
210
233
|
isContextArg: metadata.isContextArg,
|
|
211
234
|
};
|
|
212
235
|
// unknown type. we need to flag that this field needs to eventually be resolved
|
|
213
|
-
if (!
|
|
236
|
+
if (!exports.knownAllowedNames.has(type)) {
|
|
214
237
|
if (scalarType) {
|
|
215
238
|
throw new Error(`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`);
|
|
216
239
|
}
|
|
@@ -461,22 +484,6 @@ GQLCapture.customArgs = new Map();
|
|
|
461
484
|
GQLCapture.customInputObjects = new Map();
|
|
462
485
|
GQLCapture.customObjects = new Map();
|
|
463
486
|
GQLCapture.customTypes = new Map();
|
|
464
|
-
GQLCapture.knownAllowedNames = new Map([
|
|
465
|
-
["Date", "Date"],
|
|
466
|
-
["Boolean", "boolean"],
|
|
467
|
-
["Number", "number"],
|
|
468
|
-
["String", "string"],
|
|
469
|
-
// TODO not right to have this and Number
|
|
470
|
-
["Int", "number"],
|
|
471
|
-
["Float", "number"],
|
|
472
|
-
["ID", "ID"],
|
|
473
|
-
]);
|
|
474
|
-
GQLCapture.knownDisAllowedNames = new Map([
|
|
475
|
-
["Function", true],
|
|
476
|
-
["Object", true],
|
|
477
|
-
["Array", true],
|
|
478
|
-
["Promise", true],
|
|
479
|
-
]);
|
|
480
487
|
// User -> add -> [{name, options}, {}, {}]
|
|
481
488
|
GQLCapture.argMap = new Map();
|
|
482
489
|
// why is this a static class lol?
|
|
@@ -15,10 +15,10 @@ class GraphQLEdgeType extends graphql_1.GraphQLObjectType {
|
|
|
15
15
|
name: `${name}Edge`,
|
|
16
16
|
fields: () => ({
|
|
17
17
|
node: {
|
|
18
|
-
type:
|
|
18
|
+
type: new graphql_1.GraphQLNonNull(nodeType),
|
|
19
19
|
},
|
|
20
20
|
cursor: {
|
|
21
|
-
type:
|
|
21
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
22
22
|
},
|
|
23
23
|
...optional,
|
|
24
24
|
}),
|
|
@@ -34,25 +34,25 @@ class GraphQLConnectionType extends graphql_1.GraphQLObjectType {
|
|
|
34
34
|
name: `${name}Connection`,
|
|
35
35
|
fields: () => ({
|
|
36
36
|
edges: {
|
|
37
|
-
type:
|
|
37
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(edgeType))),
|
|
38
38
|
resolve: (source) => {
|
|
39
39
|
return source.queryEdges();
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
nodes: {
|
|
43
|
-
type:
|
|
43
|
+
type: new graphql_1.GraphQLNonNull(new graphql_1.GraphQLList(new graphql_1.GraphQLNonNull(nodeType))),
|
|
44
44
|
resolve: (source) => {
|
|
45
45
|
return source.queryNodes();
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
pageInfo: {
|
|
49
|
-
type:
|
|
49
|
+
type: new graphql_1.GraphQLNonNull(page_info_1.GraphQLPageInfo),
|
|
50
50
|
resolve: (source) => {
|
|
51
51
|
return source.queryPageInfo();
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
rawCount: {
|
|
55
|
-
type:
|
|
55
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLInt),
|
|
56
56
|
resolve: (source) => {
|
|
57
57
|
return source.queryTotalCount();
|
|
58
58
|
},
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { EdgeQuery, PaginationInfo } from "../../core/query/query";
|
|
2
|
-
import { Data, Ent, Viewer } from "../../core/base";
|
|
2
|
+
import { Data, Ent, ID, Viewer } from "../../core/base";
|
|
3
3
|
export interface GraphQLEdge<T extends Data> {
|
|
4
4
|
edge: T;
|
|
5
5
|
node: Ent;
|
|
6
6
|
cursor: string;
|
|
7
7
|
}
|
|
8
|
-
interface edgeQueryCtr<T extends Ent, TEdge extends Data> {
|
|
9
|
-
(v:
|
|
8
|
+
interface edgeQueryCtr<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
|
|
9
|
+
(v: TViewer, src: T): EdgeQuery<T, Ent, TEdge>;
|
|
10
10
|
}
|
|
11
|
-
interface edgeQueryCtr2<T extends Ent, TEdge extends Data> {
|
|
12
|
-
(v:
|
|
11
|
+
interface edgeQueryCtr2<T extends Ent, TEdge extends Data, TViewer extends Viewer> {
|
|
12
|
+
(v: TViewer): EdgeQuery<T, Ent, TEdge>;
|
|
13
13
|
}
|
|
14
|
-
export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data> {
|
|
14
|
+
export declare class GraphQLEdgeConnection<TSource extends Ent, TEdge extends Data, TViewer extends Viewer = Viewer> {
|
|
15
15
|
query: EdgeQuery<TSource, Ent, TEdge>;
|
|
16
16
|
private results;
|
|
17
17
|
private viewer;
|
|
18
18
|
private source?;
|
|
19
19
|
private args?;
|
|
20
|
-
constructor(viewer:
|
|
21
|
-
constructor(viewer:
|
|
20
|
+
constructor(viewer: TViewer, source: TSource, getQuery: edgeQueryCtr<TSource, TEdge, TViewer>, args?: Data);
|
|
21
|
+
constructor(viewer: TViewer, getQuery: edgeQueryCtr2<TSource, TEdge, TViewer>, args?: Data);
|
|
22
22
|
first(limit: number, cursor?: string): void;
|
|
23
23
|
last(limit: number, cursor?: string): void;
|
|
24
24
|
modifyQuery(fn: (query: EdgeQuery<TSource, Ent, TEdge>) => EdgeQuery<TSource, Ent, TEdge>): void;
|
|
25
25
|
queryTotalCount(): Promise<number>;
|
|
26
26
|
queryEdges(): Promise<GraphQLEdge<TEdge>[]>;
|
|
27
|
-
queryNodes(): Promise<Ent[]>;
|
|
27
|
+
queryNodes(): Promise<Ent<Viewer<Ent<any> | null, ID | null>>[]>;
|
|
28
28
|
private defaultPageInfo;
|
|
29
29
|
queryPageInfo(): Promise<PaginationInfo>;
|
|
30
30
|
private queryData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GraphQLObjectType } from "graphql";
|
|
2
2
|
import { RequestContext } from "../../core/context";
|
|
3
3
|
import { PaginationInfo } from "../../core/query/query";
|
|
4
|
-
export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext
|
|
4
|
+
export declare const GraphQLPageInfo: GraphQLObjectType<PaginationInfo, RequestContext<import("../..").Viewer<import("../..").Ent<any> | null, import("../..").ID | null>>>;
|
|
@@ -7,22 +7,22 @@ exports.GraphQLPageInfo = new graphql_1.GraphQLObjectType({
|
|
|
7
7
|
name: "PageInfo",
|
|
8
8
|
fields: () => ({
|
|
9
9
|
hasNextPage: {
|
|
10
|
-
type:
|
|
10
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
|
|
11
11
|
resolve: (source) => {
|
|
12
12
|
return source.hasNextPage || false;
|
|
13
13
|
},
|
|
14
14
|
},
|
|
15
15
|
hasPreviousPage: {
|
|
16
|
-
type:
|
|
16
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLBoolean),
|
|
17
17
|
resolve: (source) => {
|
|
18
18
|
return source.hasPreviousPage || false;
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
21
|
startCursor: {
|
|
22
|
-
type:
|
|
22
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
23
23
|
},
|
|
24
24
|
endCursor: {
|
|
25
|
-
type:
|
|
25
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString),
|
|
26
26
|
},
|
|
27
27
|
}),
|
|
28
28
|
});
|
|
@@ -110,7 +110,7 @@ function sharedAssocTests() {
|
|
|
110
110
|
name: "User",
|
|
111
111
|
fields: {
|
|
112
112
|
id: {
|
|
113
|
-
type:
|
|
113
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
114
114
|
},
|
|
115
115
|
firstName: {
|
|
116
116
|
type: graphql_1.GraphQLString,
|
|
@@ -128,7 +128,7 @@ function sharedAssocTests() {
|
|
|
128
128
|
name: "Event",
|
|
129
129
|
fields: {
|
|
130
130
|
id: {
|
|
131
|
-
type:
|
|
131
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
132
132
|
},
|
|
133
133
|
},
|
|
134
134
|
interfaces: [node_1.GraphQLNodeInterface],
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
export declare const GraphQLTime: GraphQLScalarType
|
|
2
|
+
export declare const GraphQLTime: GraphQLScalarType<Date, string>;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "./core/base";
|
|
2
|
-
export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey,
|
|
2
|
+
export { loadEnt, loadCustomData, loadCustomEnts, loadEntX, loadEnts, CustomQuery, loadDerivedEnt, loadDerivedEntX, loadEntViaKey, loadEntXViaKey, performRawQuery, loadRowX, loadRow, loadRows, DataOperation, EditNodeOptions, EditNodeOperation, EdgeOperation, DeleteNodeOperation, AssocEdge, AssocEdgeInputOptions, AssocEdgeInput, AssocEdgeData, loadEdgeData, loadEdgeDatas, loadEdges, loadUniqueEdge, loadUniqueNode, loadRawEdgeCountX, loadEdgeForID2, loadNodesByEdge, getEdgeTypeInGroup, setGlobalSchema, } from "./core/ent";
|
|
3
3
|
import DB from "./core/db";
|
|
4
4
|
export * from "./core/loaders";
|
|
5
5
|
export { DB };
|
|
@@ -11,12 +11,32 @@ declare const query: {
|
|
|
11
11
|
Eq: typeof q.Eq;
|
|
12
12
|
NotEq: typeof q.NotEq;
|
|
13
13
|
And: typeof q.And;
|
|
14
|
+
AndOptional: typeof q.AndOptional;
|
|
14
15
|
Or: typeof q.Or;
|
|
15
16
|
In: typeof q.In;
|
|
16
17
|
Greater: typeof q.Greater;
|
|
17
18
|
Less: typeof q.Less;
|
|
18
19
|
GreaterEq: typeof q.GreaterEq;
|
|
19
20
|
LessEq: typeof q.LessEq;
|
|
21
|
+
ArrayEq: typeof q.ArrayEq;
|
|
22
|
+
ArrayNotEq: typeof q.ArrayNotEq;
|
|
23
|
+
PostgresArrayContainsValue: typeof q.PostgresArrayContainsValue;
|
|
24
|
+
PostgresArrayContains: typeof q.PostgresArrayContains;
|
|
25
|
+
PostgresArrayNotContainsValue: typeof q.PostgresArrayNotContainsValue;
|
|
26
|
+
PostgresArrayNotContains: typeof q.PostgresArrayNotContains;
|
|
27
|
+
PostgresArrayOverlaps: typeof q.PostgresArrayOverlaps;
|
|
28
|
+
PostgresArrayNotOverlaps: typeof q.PostgresArrayNotOverlaps;
|
|
29
|
+
JSONPathValuePredicate: typeof q.JSONPathValuePredicate;
|
|
30
|
+
JSONObjectFieldKeyASJSON: typeof q.JSONObjectFieldKeyASJSON;
|
|
31
|
+
JSONObjectFieldKeyAsText: typeof q.JSONObjectFieldKeyAsText;
|
|
32
|
+
TsQuery: typeof q.TsQuery;
|
|
33
|
+
PlainToTsQuery: typeof q.PlainToTsQuery;
|
|
34
|
+
PhraseToTsQuery: typeof q.PhraseToTsQuery;
|
|
35
|
+
WebsearchToTsQuery: typeof q.WebsearchToTsQuery;
|
|
36
|
+
TsVectorColTsQuery: typeof q.TsVectorColTsQuery;
|
|
37
|
+
TsVectorPlainToTsQuery: typeof q.TsVectorPlainToTsQuery;
|
|
38
|
+
TsVectorPhraseToTsQuery: typeof q.TsVectorPhraseToTsQuery;
|
|
39
|
+
TsVectorWebsearchToTsQuery: typeof q.TsVectorWebsearchToTsQuery;
|
|
20
40
|
};
|
|
21
41
|
export { query };
|
|
22
42
|
export { RequestContext, ContextCache } from "./core/context";
|