@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha160
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/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +804 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +8 -53
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/assoc_query.d.ts +0 -0
- /package/{dist/core → core}/query/assoc_query.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query/query.d.ts +0 -0
- /package/{dist/core → core}/query/query.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sharedAssocTests(): void;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sharedAssocTests = void 0;
|
|
4
|
+
const viewer_1 = require("../../core/viewer");
|
|
5
|
+
const jest_date_mock_1 = require("jest-date-mock");
|
|
6
|
+
const edge_connection_1 = require("./edge_connection");
|
|
7
|
+
const connection_type_1 = require("./connection_type");
|
|
8
|
+
const graphql_1 = require("graphql");
|
|
9
|
+
const node_1 = require("../builtins/node");
|
|
10
|
+
const ent_graphql_tests_1 = require("../../testutils/ent-graphql-tests");
|
|
11
|
+
const index_1 = require("../../testutils/fake_data/index");
|
|
12
|
+
const test_helpers_1 = require("../../testutils/fake_data/test_helpers");
|
|
13
|
+
function sharedAssocTests() {
|
|
14
|
+
// pretty sure this works for custom ents but need tests for this eventually
|
|
15
|
+
describe("not all ents visible", () => {
|
|
16
|
+
let user;
|
|
17
|
+
let event;
|
|
18
|
+
let users;
|
|
19
|
+
let conn;
|
|
20
|
+
let friendCount;
|
|
21
|
+
// let's make it big. 20 people
|
|
22
|
+
let friendsInput = [...test_helpers_1.inputs, ...test_helpers_1.inputs, ...test_helpers_1.inputs, ...test_helpers_1.inputs];
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
friendCount = 0;
|
|
25
|
+
user = await (0, test_helpers_1.createTestUser)();
|
|
26
|
+
event = await (0, test_helpers_1.createTestEvent)(user);
|
|
27
|
+
let promises = [];
|
|
28
|
+
for (let i = 0; i < friendsInput.length; i++) {
|
|
29
|
+
(0, jest_date_mock_1.advanceBy)(100);
|
|
30
|
+
let input = friendsInput[i];
|
|
31
|
+
const builder = (0, index_1.getUserBuilder)(user.viewer, (0, test_helpers_1.getUserInput)(input));
|
|
32
|
+
if (i % 2 == 1) {
|
|
33
|
+
builder.orchestrator.addOutboundEdge(user.id, index_1.EdgeType.UserToFriends, "User");
|
|
34
|
+
friendCount++;
|
|
35
|
+
}
|
|
36
|
+
// invite user to events
|
|
37
|
+
builder.orchestrator.addInboundEdge(event.id, index_1.EdgeType.EventToInvited, "User", {
|
|
38
|
+
// just to make times deterministic so that tests can consistently work
|
|
39
|
+
time: new Date(),
|
|
40
|
+
});
|
|
41
|
+
promises.push((async function () {
|
|
42
|
+
await builder.saveX();
|
|
43
|
+
return builder.editedEntX();
|
|
44
|
+
})());
|
|
45
|
+
}
|
|
46
|
+
users = await Promise.all(promises);
|
|
47
|
+
// only few of the users invited as friends
|
|
48
|
+
const vc = new viewer_1.IDViewer(user.id);
|
|
49
|
+
const friendsEdge = await index_1.UserToFriendsQuery.query(vc, user.id).queryEdges();
|
|
50
|
+
expect(friendsEdge.length).toBe(friendCount);
|
|
51
|
+
// everyone invited to event
|
|
52
|
+
const invitedEventsEdges = await index_1.EventToInvitedQuery.query(vc, event.id).queryEdges();
|
|
53
|
+
expect(invitedEventsEdges.length).toBe(friendsInput.length);
|
|
54
|
+
resetConn();
|
|
55
|
+
});
|
|
56
|
+
function resetConn() {
|
|
57
|
+
conn = new edge_connection_1.GraphQLEdgeConnection(new viewer_1.IDViewer(user.id), event, (v, event) => new index_1.EventToInvitedQuery(v, event));
|
|
58
|
+
}
|
|
59
|
+
test("totalCount", async () => {
|
|
60
|
+
const count = await conn.queryTotalCount();
|
|
61
|
+
expect(count).toBe(users.length);
|
|
62
|
+
});
|
|
63
|
+
test("nodes", async () => {
|
|
64
|
+
const nodes = await conn.queryNodes();
|
|
65
|
+
expect(nodes.length).toBe(friendCount);
|
|
66
|
+
});
|
|
67
|
+
test("edges", async () => {
|
|
68
|
+
const edges = await conn.queryEdges();
|
|
69
|
+
expect(edges.length).toBe(friendCount);
|
|
70
|
+
});
|
|
71
|
+
test("pagination", async () => {
|
|
72
|
+
const edges = await index_1.EventToInvitedQuery.query(new viewer_1.LoggedOutViewer(), event).queryEdges();
|
|
73
|
+
async function verify(first, length, hasNextpage, index) {
|
|
74
|
+
let cursor;
|
|
75
|
+
if (index) {
|
|
76
|
+
cursor = edges[index].getCursor();
|
|
77
|
+
}
|
|
78
|
+
resetConn();
|
|
79
|
+
conn.first(first, cursor);
|
|
80
|
+
const [pagination, gqlEdges, nodes] = await Promise.all([
|
|
81
|
+
conn.queryPageInfo(),
|
|
82
|
+
conn.queryEdges(),
|
|
83
|
+
conn.queryNodes(),
|
|
84
|
+
]);
|
|
85
|
+
expect(pagination.hasNextPage, `${index}`).toBe(hasNextpage);
|
|
86
|
+
expect(pagination.hasPreviousPage, `${index}`).toBe(false);
|
|
87
|
+
expect(gqlEdges.length, `${index}`).toBe(length);
|
|
88
|
+
expect(nodes.length, `${index}`).toBe(length);
|
|
89
|
+
// TODO: not equal even though we're querying only one because the cursors are not privacy-aware
|
|
90
|
+
// TODO: fix
|
|
91
|
+
}
|
|
92
|
+
// TODO build exponential backoff into EntQuery so this isn't needed
|
|
93
|
+
// but this is how it is for now
|
|
94
|
+
await verify(1, 1, true);
|
|
95
|
+
await verify(2, 1, true);
|
|
96
|
+
await verify(2, 1, true, 0);
|
|
97
|
+
await verify(2, 1, true, 2);
|
|
98
|
+
await verify(2, 1, true, 4);
|
|
99
|
+
await verify(2, 1, true, 6);
|
|
100
|
+
await verify(2, 1, true, 8);
|
|
101
|
+
await verify(2, 1, true, 10);
|
|
102
|
+
await verify(2, 1, true, 12);
|
|
103
|
+
await verify(2, 1, true, 14);
|
|
104
|
+
await verify(2, 1, true, 16);
|
|
105
|
+
await verify(2, 1, false, 17);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
test("custom edge fields", async () => {
|
|
109
|
+
let userType = new graphql_1.GraphQLObjectType({
|
|
110
|
+
name: "User",
|
|
111
|
+
fields: {
|
|
112
|
+
id: {
|
|
113
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
114
|
+
},
|
|
115
|
+
firstName: {
|
|
116
|
+
type: graphql_1.GraphQLString,
|
|
117
|
+
},
|
|
118
|
+
lastName: {
|
|
119
|
+
type: graphql_1.GraphQLString,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
interfaces: [node_1.GraphQLNodeInterface],
|
|
123
|
+
isTypeOf(obj, _context) {
|
|
124
|
+
return obj instanceof index_1.FakeUser;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
let eventType = new graphql_1.GraphQLObjectType({
|
|
128
|
+
name: "Event",
|
|
129
|
+
fields: {
|
|
130
|
+
id: {
|
|
131
|
+
type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLID),
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
interfaces: [node_1.GraphQLNodeInterface],
|
|
135
|
+
isTypeOf(obj, _context) {
|
|
136
|
+
return obj instanceof index_1.FakeEvent;
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
const conn = new connection_type_1.GraphQLConnectionType("CustomEdge", eventType);
|
|
140
|
+
const length = (m) => {
|
|
141
|
+
let count = 0;
|
|
142
|
+
for (let _ in m) {
|
|
143
|
+
count++;
|
|
144
|
+
}
|
|
145
|
+
return count;
|
|
146
|
+
};
|
|
147
|
+
const fields = conn.edgeType.getFields();
|
|
148
|
+
// default.
|
|
149
|
+
expect(length(fields)).toBe(2);
|
|
150
|
+
expect(fields["node"]).toBeDefined();
|
|
151
|
+
expect(fields["cursor"]).toBeDefined();
|
|
152
|
+
const conn2 = new connection_type_1.GraphQLConnectionType("CustomEdge", eventType, {
|
|
153
|
+
fields: () => ({
|
|
154
|
+
bar: {
|
|
155
|
+
type: graphql_1.GraphQLString,
|
|
156
|
+
resolve() {
|
|
157
|
+
return "customEdgeData";
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
const fields2 = conn2.edgeType.getFields();
|
|
163
|
+
expect(length(fields2)).toBe(3);
|
|
164
|
+
expect(fields2["bar"]).toBeDefined();
|
|
165
|
+
expect(fields2["node"]).toBeDefined();
|
|
166
|
+
expect(fields2["cursor"]).toBeDefined();
|
|
167
|
+
const user = await (0, test_helpers_1.createTestUser)();
|
|
168
|
+
const event = await (0, test_helpers_1.createTestEvent)(user);
|
|
169
|
+
let rootQuery = new graphql_1.GraphQLObjectType({
|
|
170
|
+
name: "RootQueryType",
|
|
171
|
+
fields: {
|
|
172
|
+
conn: {
|
|
173
|
+
type: conn2,
|
|
174
|
+
async resolve(_source, { id }, context) {
|
|
175
|
+
return new edge_connection_1.GraphQLEdgeConnection(new viewer_1.IDViewer(user.id), user, (v, event) => new index_1.UserToHostedEventsQuery(v, event));
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
let schema = new graphql_1.GraphQLSchema({
|
|
181
|
+
query: rootQuery,
|
|
182
|
+
types: [userType, eventType],
|
|
183
|
+
});
|
|
184
|
+
let cfg = {
|
|
185
|
+
schema: schema,
|
|
186
|
+
root: "conn",
|
|
187
|
+
viewer: new viewer_1.IDViewer(user.id),
|
|
188
|
+
args: {},
|
|
189
|
+
};
|
|
190
|
+
await (0, ent_graphql_tests_1.expectQueryFromRoot)(cfg, [
|
|
191
|
+
"edges",
|
|
192
|
+
[
|
|
193
|
+
{
|
|
194
|
+
node: {
|
|
195
|
+
id: event.id,
|
|
196
|
+
},
|
|
197
|
+
bar: "customEdgeData",
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
exports.sharedAssocTests = sharedAssocTests;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.1.0-alpha160
|
|
3
|
+
"version": "0.1.0-alpha160",
|
|
4
4
|
"description": "snowtop ent framework",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
7
|
"directories": {
|
|
8
8
|
"example": "examples"
|
|
9
9
|
},
|
|
@@ -45,56 +45,11 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=16.0"
|
|
47
47
|
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
|
|
50
|
-
"@swc/jest": "^0.2.26",
|
|
51
|
-
"@types/bcryptjs": "^2.4.2",
|
|
52
|
-
"@types/better-sqlite3": "^7.6.4",
|
|
53
|
-
"@types/express": "^4.17.15",
|
|
54
|
-
"@types/glob": "^8.0.0",
|
|
55
|
-
"@types/graphql-upload": "^8.0.12",
|
|
56
|
-
"@types/jest": "^29.2.4",
|
|
57
|
-
"@types/js-yaml": "^4.0.5",
|
|
58
|
-
"@types/luxon": "^3.1.0",
|
|
59
|
-
"@types/memoizee": "^0.4.8",
|
|
60
|
-
"@types/minimist": "^1.2.2",
|
|
61
|
-
"@types/passport": "^1.0.11",
|
|
62
|
-
"@types/passport-jwt": "^3.0.8",
|
|
63
|
-
"@types/pg": "^8.6.6",
|
|
64
|
-
"@types/pluralize": "0.0.29",
|
|
65
|
-
"@types/supertest": "^2.0.12",
|
|
66
|
-
"@types/uuid": "^9.0.0",
|
|
67
|
-
"better-sqlite3": "^8.4.0",
|
|
68
|
-
"email-addresses": "^5.0.0",
|
|
69
|
-
"express": "^4.18.2",
|
|
70
|
-
"graphql": "^16.6.0",
|
|
71
|
-
"graphql-helix": "^1.13.0",
|
|
72
|
-
"graphql-type-json": "^0.3.2",
|
|
73
|
-
"graphql-upload": "^13.0.0",
|
|
74
|
-
"jest": "^29.3.1",
|
|
75
|
-
"jest-date-mock": "^1.0.8",
|
|
76
|
-
"jest-each": "^29.5.0",
|
|
77
|
-
"jest-expect-message": "^1.1.3",
|
|
78
|
-
"jest-mock": "^29.3.1",
|
|
79
|
-
"node-sql-parser": "^3.9.4",
|
|
80
|
-
"object-path": "^0.11.8",
|
|
81
|
-
"pg-copy-streams": "^6.0.5",
|
|
82
|
-
"pluralize": "^8.0.0",
|
|
83
|
-
"supertest": "^6.3.3",
|
|
84
|
-
"ts-jest": "^29.1.0"
|
|
85
|
-
},
|
|
86
|
-
"scripts": {
|
|
87
|
-
"compile": "tsc",
|
|
88
|
-
"test": "jest",
|
|
89
|
-
"clean": "rm -rf dist",
|
|
90
|
-
"prepublish": "npm run clean && npm run compile && node src/setupPackage.js"
|
|
91
|
-
},
|
|
48
|
+
"devDependencies": {},
|
|
49
|
+
"scripts": {},
|
|
92
50
|
"bin": {
|
|
93
|
-
"ent-custom-graphql": "
|
|
94
|
-
"ent-custom-compiler": "
|
|
95
|
-
"ent-read-schema": "dist/scripts/read_schema.js",
|
|
96
|
-
"ent-move-types": "dist/scripts/move-types.js",
|
|
97
|
-
"ent-migrate-v0.1": "dist/scripts/migrate-v0.1"
|
|
51
|
+
"ent-custom-graphql": "scripts/custom_graphql.js",
|
|
52
|
+
"ent-custom-compiler": "scripts/custom_compiler.js"
|
|
98
53
|
},
|
|
99
54
|
"author": "lolopinto",
|
|
100
55
|
"license": "MIT",
|
|
@@ -106,4 +61,4 @@
|
|
|
106
61
|
"url": "https://github.com/lolopinto/ent/issues"
|
|
107
62
|
},
|
|
108
63
|
"homepage": "https://github.com/lolopinto/ent#readme"
|
|
109
|
-
}
|
|
64
|
+
}
|
package/dist/package.json
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@snowtop/ent",
|
|
3
|
-
"version": "0.1.0-alpha160-test6",
|
|
4
|
-
"description": "snowtop ent framework",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"directories": {
|
|
8
|
-
"example": "examples"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"@types/node": "^20.2.5",
|
|
12
|
-
"camel-case": "^4.1.2",
|
|
13
|
-
"cosmiconfig": "^8.1.3",
|
|
14
|
-
"dataloader": "^2.2.2",
|
|
15
|
-
"glob": "^10.2.6",
|
|
16
|
-
"graph-data-structure": "^3.3.0",
|
|
17
|
-
"js-yaml": "^4.1.0",
|
|
18
|
-
"json5": "^2.2.3",
|
|
19
|
-
"luxon": "^3.3.0",
|
|
20
|
-
"memoizee": "^0.4.15",
|
|
21
|
-
"minimist": "^1.2.8",
|
|
22
|
-
"pascal-case": "^3.1.2",
|
|
23
|
-
"pg": "^8.11.0",
|
|
24
|
-
"prettier": "^2.8.8",
|
|
25
|
-
"snake-case": "^3.0.4",
|
|
26
|
-
"ts-node": "^10.9.1",
|
|
27
|
-
"tsconfig-paths": "^4.2.0",
|
|
28
|
-
"tslib": "^2.5.2",
|
|
29
|
-
"typescript": "^5.0.4",
|
|
30
|
-
"uuid": "^9.0.0"
|
|
31
|
-
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"@swc-node/register": "^1.6.5",
|
|
34
|
-
"better-sqlite3": "^8.4.0",
|
|
35
|
-
"graphql": "^16.5.0"
|
|
36
|
-
},
|
|
37
|
-
"peerDependenciesMeta": {
|
|
38
|
-
"better-sqlite3": {
|
|
39
|
-
"optional": true
|
|
40
|
-
},
|
|
41
|
-
"@swc-node/register": {
|
|
42
|
-
"optional": true
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"engines": {
|
|
46
|
-
"node": ">=16.0"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {},
|
|
49
|
-
"scripts": {},
|
|
50
|
-
"bin": {
|
|
51
|
-
"ent-custom-graphql": "scripts/custom_graphql.js",
|
|
52
|
-
"ent-custom-compiler": "scripts/custom_compiler.js"
|
|
53
|
-
},
|
|
54
|
-
"author": "lolopinto",
|
|
55
|
-
"license": "MIT",
|
|
56
|
-
"repository": {
|
|
57
|
-
"type": "git",
|
|
58
|
-
"url": "git+ssh://git@github.com/lolopinto/ent.git"
|
|
59
|
-
},
|
|
60
|
-
"bugs": {
|
|
61
|
-
"url": "https://github.com/lolopinto/ent/issues"
|
|
62
|
-
},
|
|
63
|
-
"homepage": "https://github.com/lolopinto/ent#readme"
|
|
64
|
-
}
|
package/src/action/action.ts
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Ent,
|
|
3
|
-
EntConstructor,
|
|
4
|
-
Viewer,
|
|
5
|
-
ID,
|
|
6
|
-
Data,
|
|
7
|
-
PrivacyPolicy,
|
|
8
|
-
Context,
|
|
9
|
-
WriteOperation,
|
|
10
|
-
} from "../core/base";
|
|
11
|
-
import { loadEdgeForID2, AssocEdge } from "../core/ent";
|
|
12
|
-
import { DataOperation, AssocEdgeInputOptions } from "./operations";
|
|
13
|
-
import { Queryer } from "../core/db";
|
|
14
|
-
import { log } from "../core/logger";
|
|
15
|
-
import { TransformedUpdateOperation, UpdateOperation } from "../schema";
|
|
16
|
-
import { FieldInfoMap } from "../schema/schema";
|
|
17
|
-
|
|
18
|
-
export { WriteOperation };
|
|
19
|
-
|
|
20
|
-
type MaybeNull<T extends Ent> = T | null;
|
|
21
|
-
type TMaybleNullableEnt<T extends Ent> = T | MaybeNull<T>;
|
|
22
|
-
|
|
23
|
-
interface BuilderOrchestrator {
|
|
24
|
-
__getOptions(): {
|
|
25
|
-
fieldInfo: FieldInfoMap;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface Builder<
|
|
30
|
-
TEnt extends Ent<TViewer>,
|
|
31
|
-
TViewer extends Viewer = Viewer,
|
|
32
|
-
TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
|
|
33
|
-
> {
|
|
34
|
-
existingEnt: TExistingEnt;
|
|
35
|
-
ent: EntConstructor<TEnt, TViewer>;
|
|
36
|
-
placeholderID: ID;
|
|
37
|
-
readonly viewer: TViewer;
|
|
38
|
-
build(): Promise<Changeset>;
|
|
39
|
-
buildWithOptions_BETA?(options: ChangesetOptions): Promise<Changeset>;
|
|
40
|
-
operation: WriteOperation;
|
|
41
|
-
editedEnt?(): Promise<TEnt | null>;
|
|
42
|
-
nodeType: string;
|
|
43
|
-
// TODO TInput in Builder
|
|
44
|
-
getInput(): Data;
|
|
45
|
-
// TODO full orchestrator...
|
|
46
|
-
orchestrator: BuilderOrchestrator;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// PS: this is a private API subject to change
|
|
50
|
-
export interface Executor
|
|
51
|
-
extends Iterable<DataOperation>,
|
|
52
|
-
Iterator<DataOperation> {
|
|
53
|
-
placeholderID: ID;
|
|
54
|
-
// this returns a non-privacy checked "ent"
|
|
55
|
-
resolveValue(val: any): Ent | null;
|
|
56
|
-
builderOpChanged(builder: Builder<any>): boolean;
|
|
57
|
-
builder?: Builder<Ent>;
|
|
58
|
-
|
|
59
|
-
execute(): Promise<void>;
|
|
60
|
-
|
|
61
|
-
// TODO add this so we can differentiate btw when ops are being executed?
|
|
62
|
-
// vs gathered for other use
|
|
63
|
-
// or change how execute() works?
|
|
64
|
-
// right now have to reset at the end of next() if we call for (const op of executor) {}
|
|
65
|
-
// also want to throw if DataOperation.returnedRow or DataOperation.createdEnt
|
|
66
|
-
// called too early
|
|
67
|
-
// getSortedOps(): DataOperation[];
|
|
68
|
-
|
|
69
|
-
// these 3 are to help chained/contained executors
|
|
70
|
-
preFetch?(queryer: Queryer, context?: Context): Promise<void>;
|
|
71
|
-
postFetch?(queryer: Queryer, context?: Context): Promise<void>;
|
|
72
|
-
executeObservers?(): Promise<void>;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface Changeset {
|
|
76
|
-
executor(): Executor;
|
|
77
|
-
viewer: Viewer;
|
|
78
|
-
placeholderID: ID;
|
|
79
|
-
// ent: EntConstructor<T>;
|
|
80
|
-
changesets?: Changeset[];
|
|
81
|
-
dependencies?: Map<ID, Builder<Ent>>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export type TriggerReturn =
|
|
85
|
-
| void
|
|
86
|
-
| Promise<Changeset | void | (Changeset | void)[]>
|
|
87
|
-
| Promise<Changeset>[];
|
|
88
|
-
|
|
89
|
-
export interface Trigger<
|
|
90
|
-
TEnt extends Ent<TViewer>,
|
|
91
|
-
TBuilder extends Builder<TEnt, TViewer, TExistingEnt>,
|
|
92
|
-
TViewer extends Viewer = Viewer,
|
|
93
|
-
TInput extends Data = Data,
|
|
94
|
-
TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
|
|
95
|
-
> {
|
|
96
|
-
// TODO: way in the future. detect any writes happening in changesets and optionally throw if configured to do so
|
|
97
|
-
// can throw if it wants. not expected to throw tho.
|
|
98
|
-
// input passed in here !== builder.getInput()
|
|
99
|
-
// builder.getInput() can have other default fields
|
|
100
|
-
changeset(builder: TBuilder, input: TInput): TriggerReturn;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface Observer<
|
|
104
|
-
TEnt extends Ent<TViewer>,
|
|
105
|
-
TBuilder extends Builder<TEnt, TViewer, TExistingEnt>,
|
|
106
|
-
TViewer extends Viewer = Viewer,
|
|
107
|
-
TInput extends Data = Data,
|
|
108
|
-
TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
|
|
109
|
-
> {
|
|
110
|
-
// input passed in here !== builder.getInput()
|
|
111
|
-
// builder.getInput() can have other default fields
|
|
112
|
-
observe(builder: TBuilder, input: TInput): void | Promise<void>;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface Validator<
|
|
116
|
-
TEnt extends Ent<TViewer>,
|
|
117
|
-
TBuilder extends Builder<TEnt, TViewer, TExistingEnt>,
|
|
118
|
-
TViewer extends Viewer = Viewer,
|
|
119
|
-
TInput extends Data = Data,
|
|
120
|
-
TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
|
|
121
|
-
> {
|
|
122
|
-
// can throw if it wants
|
|
123
|
-
// input passed in here !== builder.getInput()
|
|
124
|
-
// builder.getInput() can have other default fields
|
|
125
|
-
validate(
|
|
126
|
-
builder: TBuilder,
|
|
127
|
-
input: TInput,
|
|
128
|
-
): Promise<void | undefined | Error> | void | Error | undefined;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface ChangesetOptions {
|
|
132
|
-
// conditional on builder operation remaining the same
|
|
133
|
-
// TODO I don't really like this
|
|
134
|
-
// https://github.com/lolopinto/ent/issues/1437
|
|
135
|
-
conditionalBuilder: Builder<any, any>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export interface Action<
|
|
139
|
-
TEnt extends Ent<TViewer>,
|
|
140
|
-
TBuilder extends Builder<TEnt, TViewer, TExistingEnt>,
|
|
141
|
-
TViewer extends Viewer = Viewer,
|
|
142
|
-
TInput extends Data = Data,
|
|
143
|
-
TExistingEnt extends TMaybleNullableEnt<TEnt> = MaybeNull<TEnt>,
|
|
144
|
-
> {
|
|
145
|
-
readonly viewer: Viewer;
|
|
146
|
-
changeset(): Promise<Changeset>;
|
|
147
|
-
changesetWithOptions_BETA?(options: ChangesetOptions): Promise<Changeset>;
|
|
148
|
-
builder: TBuilder;
|
|
149
|
-
getPrivacyPolicy(): PrivacyPolicy<TEnt>;
|
|
150
|
-
|
|
151
|
-
// we allow grouping triggers to indicate dependency trees
|
|
152
|
-
// so that you can say one or more triggers is higher priority
|
|
153
|
-
// than the others and should be run first
|
|
154
|
-
// any encountered list is a different priority from prior and subsequent triggers
|
|
155
|
-
getTriggers?(): (
|
|
156
|
-
| Trigger<TEnt, TBuilder, TViewer, TInput, TExistingEnt>
|
|
157
|
-
| Trigger<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[]
|
|
158
|
-
)[];
|
|
159
|
-
getObservers?(): Observer<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
|
|
160
|
-
getValidators?(): Validator<TEnt, TBuilder, TViewer, TInput, TExistingEnt>[];
|
|
161
|
-
getInput(): TInput; // this input is passed to Triggers, Observers, Validators
|
|
162
|
-
transformWrite?: (
|
|
163
|
-
stmt: UpdateOperation<TEnt, TViewer>,
|
|
164
|
-
) =>
|
|
165
|
-
| Promise<TransformedUpdateOperation<TEnt, TViewer>>
|
|
166
|
-
| TransformedUpdateOperation<TEnt, TViewer>
|
|
167
|
-
| null;
|
|
168
|
-
|
|
169
|
-
valid(): Promise<boolean>;
|
|
170
|
-
// throws if invalid
|
|
171
|
-
validX(): Promise<void>;
|
|
172
|
-
|
|
173
|
-
// this is used to load the ent after the action
|
|
174
|
-
// you can imagine this being overwritten for a create user or create account
|
|
175
|
-
// action to load the just-created user after the fact
|
|
176
|
-
viewerForEntLoad?(
|
|
177
|
-
data: Data,
|
|
178
|
-
context?: Context<TViewer>,
|
|
179
|
-
): TViewer | Promise<TViewer>;
|
|
180
|
-
|
|
181
|
-
// if we have overloads we need to provide all which sucks
|
|
182
|
-
// so maybe don't make the ones below required
|
|
183
|
-
// save(): Promise<T | null>;
|
|
184
|
-
// save(): Promise<void>;
|
|
185
|
-
// saveX(): Promise<T>;
|
|
186
|
-
// saveX(): Promise<T>;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export async function saveBuilder<
|
|
190
|
-
TEnt extends Ent<TViewer>,
|
|
191
|
-
TViewer extends Viewer,
|
|
192
|
-
>(builder: Builder<TEnt, TViewer>): Promise<void> {
|
|
193
|
-
await saveBuilderImpl(builder, false);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export async function saveBuilderX<
|
|
197
|
-
TEnt extends Ent<TViewer>,
|
|
198
|
-
TViewer extends Viewer,
|
|
199
|
-
>(builder: Builder<TEnt, TViewer>): Promise<void> {
|
|
200
|
-
await saveBuilderImpl(builder, true);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async function saveBuilderImpl<
|
|
204
|
-
TEnt extends Ent<TViewer>,
|
|
205
|
-
TViewer extends Viewer,
|
|
206
|
-
>(builder: Builder<TEnt, TViewer>, throwErr: boolean): Promise<void> {
|
|
207
|
-
let changeset: Changeset;
|
|
208
|
-
try {
|
|
209
|
-
changeset = await builder.build();
|
|
210
|
-
} catch (e) {
|
|
211
|
-
log("error", e);
|
|
212
|
-
if (throwErr) {
|
|
213
|
-
throw e;
|
|
214
|
-
} else {
|
|
215
|
-
// expected...
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const executor = changeset.executor();
|
|
220
|
-
if (throwErr) {
|
|
221
|
-
return executor.execute();
|
|
222
|
-
} else {
|
|
223
|
-
try {
|
|
224
|
-
return executor.execute();
|
|
225
|
-
} catch (e) {
|
|
226
|
-
// it's already caught and logged upstream
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Orchestrator in orchestrator.ts in generated Builders
|
|
232
|
-
// we indicate the API we expect here. Not typing it to Orchestrator class in Orchestrator.ts
|
|
233
|
-
// for flexibility
|
|
234
|
-
interface Orchestrator {
|
|
235
|
-
addOutboundEdge<T2 extends Ent>(
|
|
236
|
-
id2: ID | Builder<T2>,
|
|
237
|
-
edgeType: string,
|
|
238
|
-
nodeType: string,
|
|
239
|
-
options?: AssocEdgeInputOptions,
|
|
240
|
-
): void;
|
|
241
|
-
removeOutboundEdge(id2: ID, edgeType: string): void;
|
|
242
|
-
viewer: Viewer;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function modifyEdgeSet<T extends string>(
|
|
246
|
-
orchestrator: Orchestrator,
|
|
247
|
-
id1: ID,
|
|
248
|
-
id2: ID,
|
|
249
|
-
inputEnumValue: string,
|
|
250
|
-
enumValue: string,
|
|
251
|
-
edgeType: T,
|
|
252
|
-
nodeType: string,
|
|
253
|
-
) {
|
|
254
|
-
let edge = await loadEdgeForID2({
|
|
255
|
-
id1: id1,
|
|
256
|
-
id2: id2,
|
|
257
|
-
edgeType: edgeType,
|
|
258
|
-
ctr: AssocEdge,
|
|
259
|
-
context: orchestrator.viewer.context,
|
|
260
|
-
});
|
|
261
|
-
// always add the edge because the data field may be getting overwritten later on
|
|
262
|
-
// and we need to give that operation a chance to succeed
|
|
263
|
-
// TODO: can save a write here by checking in EdgeOperation and not doing this write if nothing
|
|
264
|
-
// has changed.
|
|
265
|
-
if (inputEnumValue === enumValue) {
|
|
266
|
-
orchestrator.addOutboundEdge(id2, edgeType, nodeType);
|
|
267
|
-
}
|
|
268
|
-
if (edge) {
|
|
269
|
-
if (enumValue !== inputEnumValue) {
|
|
270
|
-
orchestrator.removeOutboundEdge(id2, edgeType);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// This sets one edge in a group
|
|
276
|
-
// used for assoc groups where setting the value of one edge in the group
|
|
277
|
-
// unsets the other
|
|
278
|
-
// e.g. 3 states for event rsvp: attending, maybe, declined. user can't be rsvped as more than one at a time so this helps you
|
|
279
|
-
// so that setting an rsvp status for one clears the others (if set)
|
|
280
|
-
// or for friendship status: incoming_friend_request, outgoing_friend_request, are_friends
|
|
281
|
-
// accepting a friend request should clear an incoming or outgoing friend request
|
|
282
|
-
// @args
|
|
283
|
-
// orchestrator: see interface
|
|
284
|
-
// inputEnumValue: the value of the enum. should be one of the keys of m
|
|
285
|
-
// id1: source ID in Orchestrator. We take this as extra param because we need it to check if edge exists
|
|
286
|
-
// id2: target id
|
|
287
|
-
// nodeType: nodeType of ent in question
|
|
288
|
-
// m: Map<enumType, to EdgeType to check>
|
|
289
|
-
export async function setEdgeTypeInGroup<T extends string>(
|
|
290
|
-
orchestrator: Orchestrator,
|
|
291
|
-
inputEnumValue: string,
|
|
292
|
-
id1: ID,
|
|
293
|
-
id2: ID,
|
|
294
|
-
nodeType: string,
|
|
295
|
-
m: Map<T, string>,
|
|
296
|
-
) {
|
|
297
|
-
let promises: Promise<void>[] = [];
|
|
298
|
-
for (const [k, v] of m) {
|
|
299
|
-
promises.push(
|
|
300
|
-
modifyEdgeSet(orchestrator, id1, id2, inputEnumValue, k, v, nodeType),
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
await Promise.all(promises);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export async function clearEdgeTypeInGroup<T extends string>(
|
|
307
|
-
orchestrator: Orchestrator,
|
|
308
|
-
id1: ID,
|
|
309
|
-
id2: ID,
|
|
310
|
-
m: Map<T, string>,
|
|
311
|
-
) {
|
|
312
|
-
let promises: Promise<void>[] = [];
|
|
313
|
-
for (const [_, edgeType] of m) {
|
|
314
|
-
promises.push(
|
|
315
|
-
(async () => {
|
|
316
|
-
let edge = await loadEdgeForID2({
|
|
317
|
-
id1,
|
|
318
|
-
id2,
|
|
319
|
-
edgeType,
|
|
320
|
-
ctr: AssocEdge,
|
|
321
|
-
context: orchestrator.viewer.context,
|
|
322
|
-
});
|
|
323
|
-
if (edge) {
|
|
324
|
-
orchestrator.removeOutboundEdge(id2, edgeType);
|
|
325
|
-
}
|
|
326
|
-
})(),
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
await Promise.all(promises);
|
|
330
|
-
}
|