@snowtop/ent 0.1.0-alpha160-test4 → 0.1.0-alpha160-test6
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/dist/package.json +64 -0
- package/{scripts → dist/scripts}/custom_compiler.js +0 -0
- package/{scripts → dist/scripts}/custom_graphql.js +0 -0
- package/package.json +48 -6
- package/src/action/action.ts +330 -0
- package/src/action/executor.ts +453 -0
- package/src/action/experimental_action.ts +277 -0
- package/src/action/index.ts +31 -0
- package/src/action/operations.ts +967 -0
- package/src/action/orchestrator.ts +1527 -0
- package/src/action/privacy.ts +37 -0
- package/src/action/relative_value.ts +242 -0
- package/src/action/transaction.ts +38 -0
- package/src/auth/auth.ts +77 -0
- package/src/auth/index.ts +8 -0
- package/src/core/base.ts +367 -0
- package/src/core/clause.ts +1065 -0
- package/src/core/config.ts +219 -0
- package/src/core/const.ts +5 -0
- package/src/core/context.ts +135 -0
- package/src/core/convert.ts +106 -0
- package/src/core/date.ts +23 -0
- package/src/core/db.ts +498 -0
- package/src/core/ent.ts +1740 -0
- package/src/core/global_schema.ts +49 -0
- package/src/core/loaders/assoc_count_loader.ts +99 -0
- package/src/core/loaders/assoc_edge_loader.ts +250 -0
- package/src/core/loaders/index.ts +12 -0
- package/src/core/loaders/loader.ts +66 -0
- package/src/core/loaders/object_loader.ts +489 -0
- package/src/core/loaders/query_loader.ts +314 -0
- package/src/core/loaders/raw_count_loader.ts +175 -0
- package/src/core/logger.ts +49 -0
- package/src/core/privacy.ts +660 -0
- package/src/core/query/assoc_query.ts +240 -0
- package/src/core/query/custom_clause_query.ts +174 -0
- package/src/core/query/custom_query.ts +302 -0
- package/src/core/query/index.ts +9 -0
- package/src/core/query/query.ts +674 -0
- package/src/core/query_impl.ts +32 -0
- package/src/core/viewer.ts +52 -0
- package/src/ent.code-workspace +73 -0
- package/src/graphql/builtins/connection.ts +25 -0
- package/src/graphql/builtins/edge.ts +16 -0
- package/src/graphql/builtins/node.ts +12 -0
- package/src/graphql/graphql.ts +891 -0
- package/src/graphql/graphql_field_helpers.ts +221 -0
- package/src/graphql/index.ts +42 -0
- package/src/graphql/mutations/union.ts +39 -0
- package/src/graphql/node_resolver.ts +122 -0
- package/src/graphql/query/connection_type.ts +113 -0
- package/src/graphql/query/edge_connection.ts +171 -0
- package/src/graphql/query/page_info.ts +34 -0
- package/src/graphql/query/shared_edge_connection.ts +287 -0
- package/src/graphql/scalars/orderby_direction.ts +13 -0
- package/src/graphql/scalars/time.ts +38 -0
- package/src/imports/dataz/example1/_auth.ts +51 -0
- package/src/imports/dataz/example1/_viewer.ts +35 -0
- package/src/imports/index.ts +213 -0
- package/src/index.ts +145 -0
- package/src/parse_schema/parse.ts +585 -0
- package/src/schema/base_schema.ts +224 -0
- package/src/schema/field.ts +1087 -0
- package/src/schema/index.ts +53 -0
- package/src/schema/json_field.ts +94 -0
- package/src/schema/schema.ts +1028 -0
- package/src/schema/struct_field.ts +234 -0
- package/src/schema/union_field.ts +105 -0
- package/src/scripts/custom_compiler.ts +331 -0
- package/src/scripts/custom_graphql.ts +550 -0
- package/src/scripts/migrate_v0.1.ts +41 -0
- package/src/scripts/move_types.ts +131 -0
- package/src/scripts/read_schema.ts +67 -0
- package/src/setupPackage.js +42 -0
- package/src/testutils/action/complex_schemas.ts +517 -0
- package/src/testutils/builder.ts +422 -0
- package/src/testutils/context/test_context.ts +25 -0
- package/src/testutils/db/fixture.ts +32 -0
- package/src/testutils/db/temp_db.ts +941 -0
- package/src/testutils/db/value.ts +294 -0
- package/src/testutils/db_mock.ts +351 -0
- package/src/testutils/db_time_zone.ts +40 -0
- package/src/testutils/ent-graphql-tests/index.ts +653 -0
- package/src/testutils/fake_comms.ts +50 -0
- package/src/testutils/fake_data/const.ts +64 -0
- package/src/testutils/fake_data/events_query.ts +145 -0
- package/src/testutils/fake_data/fake_contact.ts +150 -0
- package/src/testutils/fake_data/fake_event.ts +150 -0
- package/src/testutils/fake_data/fake_tag.ts +139 -0
- package/src/testutils/fake_data/fake_user.ts +232 -0
- package/src/testutils/fake_data/index.ts +1 -0
- package/src/testutils/fake_data/internal.ts +8 -0
- package/src/testutils/fake_data/tag_query.ts +56 -0
- package/src/testutils/fake_data/test_helpers.ts +388 -0
- package/src/testutils/fake_data/user_query.ts +524 -0
- package/src/testutils/fake_log.ts +52 -0
- package/src/testutils/mock_date.ts +10 -0
- package/src/testutils/mock_log.ts +39 -0
- package/src/testutils/parse_sql.ts +685 -0
- package/src/testutils/test_edge_global_schema.ts +49 -0
- package/src/testutils/write.ts +70 -0
- package/src/tsc/ast.ts +351 -0
- package/src/tsc/compilerOptions.ts +85 -0
- package/src/tsc/move_generated.ts +191 -0
- package/src/tsc/transform.ts +226 -0
- package/src/tsc/transform_action.ts +224 -0
- package/src/tsc/transform_ent.ts +66 -0
- package/src/tsc/transform_schema.ts +546 -0
- package/tsconfig.json +20 -0
- package/core/query/shared_assoc_test.d.ts +0 -2
- package/core/query/shared_assoc_test.js +0 -804
- package/core/query/shared_test.d.ts +0 -21
- package/core/query/shared_test.js +0 -736
- package/graphql/query/shared_assoc_test.d.ts +0 -1
- package/graphql/query/shared_assoc_test.js +0 -203
- /package/{action → dist/action}/action.d.ts +0 -0
- /package/{action → dist/action}/action.js +0 -0
- /package/{action → dist/action}/executor.d.ts +0 -0
- /package/{action → dist/action}/executor.js +0 -0
- /package/{action → dist/action}/experimental_action.d.ts +0 -0
- /package/{action → dist/action}/experimental_action.js +0 -0
- /package/{action → dist/action}/index.d.ts +0 -0
- /package/{action → dist/action}/index.js +0 -0
- /package/{action → dist/action}/operations.d.ts +0 -0
- /package/{action → dist/action}/operations.js +0 -0
- /package/{action → dist/action}/orchestrator.d.ts +0 -0
- /package/{action → dist/action}/orchestrator.js +0 -0
- /package/{action → dist/action}/privacy.d.ts +0 -0
- /package/{action → dist/action}/privacy.js +0 -0
- /package/{action → dist/action}/relative_value.d.ts +0 -0
- /package/{action → dist/action}/relative_value.js +0 -0
- /package/{action → dist/action}/transaction.d.ts +0 -0
- /package/{action → dist/action}/transaction.js +0 -0
- /package/{auth → dist/auth}/auth.d.ts +0 -0
- /package/{auth → dist/auth}/auth.js +0 -0
- /package/{auth → dist/auth}/index.d.ts +0 -0
- /package/{auth → dist/auth}/index.js +0 -0
- /package/{core → dist/core}/base.d.ts +0 -0
- /package/{core → dist/core}/base.js +0 -0
- /package/{core → dist/core}/clause.d.ts +0 -0
- /package/{core → dist/core}/clause.js +0 -0
- /package/{core → dist/core}/config.d.ts +0 -0
- /package/{core → dist/core}/config.js +0 -0
- /package/{core → dist/core}/const.d.ts +0 -0
- /package/{core → dist/core}/const.js +0 -0
- /package/{core → dist/core}/context.d.ts +0 -0
- /package/{core → dist/core}/context.js +0 -0
- /package/{core → dist/core}/convert.d.ts +0 -0
- /package/{core → dist/core}/convert.js +0 -0
- /package/{core → dist/core}/date.d.ts +0 -0
- /package/{core → dist/core}/date.js +0 -0
- /package/{core → dist/core}/db.d.ts +0 -0
- /package/{core → dist/core}/db.js +0 -0
- /package/{core → dist/core}/ent.d.ts +0 -0
- /package/{core → dist/core}/ent.js +0 -0
- /package/{core → dist/core}/global_schema.d.ts +0 -0
- /package/{core → dist/core}/global_schema.js +0 -0
- /package/{core → dist/core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/assoc_count_loader.js +0 -0
- /package/{core → dist/core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/assoc_edge_loader.js +0 -0
- /package/{core → dist/core}/loaders/index.d.ts +0 -0
- /package/{core → dist/core}/loaders/index.js +0 -0
- /package/{core → dist/core}/loaders/loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/loader.js +0 -0
- /package/{core → dist/core}/loaders/object_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/object_loader.js +0 -0
- /package/{core → dist/core}/loaders/query_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/query_loader.js +0 -0
- /package/{core → dist/core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{core → dist/core}/loaders/raw_count_loader.js +0 -0
- /package/{core → dist/core}/logger.d.ts +0 -0
- /package/{core → dist/core}/logger.js +0 -0
- /package/{core → dist/core}/privacy.d.ts +0 -0
- /package/{core → dist/core}/privacy.js +0 -0
- /package/{core → dist/core}/query/assoc_query.d.ts +0 -0
- /package/{core → dist/core}/query/assoc_query.js +0 -0
- /package/{core → dist/core}/query/custom_clause_query.d.ts +0 -0
- /package/{core → dist/core}/query/custom_clause_query.js +0 -0
- /package/{core → dist/core}/query/custom_query.d.ts +0 -0
- /package/{core → dist/core}/query/custom_query.js +0 -0
- /package/{core → dist/core}/query/index.d.ts +0 -0
- /package/{core → dist/core}/query/index.js +0 -0
- /package/{core → dist/core}/query/query.d.ts +0 -0
- /package/{core → dist/core}/query/query.js +0 -0
- /package/{core → dist/core}/query_impl.d.ts +0 -0
- /package/{core → dist/core}/query_impl.js +0 -0
- /package/{core → dist/core}/viewer.d.ts +0 -0
- /package/{core → dist/core}/viewer.js +0 -0
- /package/{graphql → dist/graphql}/builtins/connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/connection.js +0 -0
- /package/{graphql → dist/graphql}/builtins/edge.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/edge.js +0 -0
- /package/{graphql → dist/graphql}/builtins/node.d.ts +0 -0
- /package/{graphql → dist/graphql}/builtins/node.js +0 -0
- /package/{graphql → dist/graphql}/graphql.d.ts +0 -0
- /package/{graphql → dist/graphql}/graphql.js +0 -0
- /package/{graphql → dist/graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{graphql → dist/graphql}/graphql_field_helpers.js +0 -0
- /package/{graphql → dist/graphql}/index.d.ts +0 -0
- /package/{graphql → dist/graphql}/index.js +0 -0
- /package/{graphql → dist/graphql}/mutations/union.d.ts +0 -0
- /package/{graphql → dist/graphql}/mutations/union.js +0 -0
- /package/{graphql → dist/graphql}/node_resolver.d.ts +0 -0
- /package/{graphql → dist/graphql}/node_resolver.js +0 -0
- /package/{graphql → dist/graphql}/query/connection_type.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/connection_type.js +0 -0
- /package/{graphql → dist/graphql}/query/edge_connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/edge_connection.js +0 -0
- /package/{graphql → dist/graphql}/query/page_info.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/page_info.js +0 -0
- /package/{graphql → dist/graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{graphql → dist/graphql}/query/shared_edge_connection.js +0 -0
- /package/{graphql → dist/graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{graphql → dist/graphql}/scalars/orderby_direction.js +0 -0
- /package/{graphql → dist/graphql}/scalars/time.d.ts +0 -0
- /package/{graphql → dist/graphql}/scalars/time.js +0 -0
- /package/{imports → dist/imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{imports → dist/imports}/dataz/example1/_auth.js +0 -0
- /package/{imports → dist/imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{imports → dist/imports}/dataz/example1/_viewer.js +0 -0
- /package/{imports → dist/imports}/index.d.ts +0 -0
- /package/{imports → dist/imports}/index.js +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{parse_schema → dist/parse_schema}/parse.d.ts +0 -0
- /package/{parse_schema → dist/parse_schema}/parse.js +0 -0
- /package/{schema → dist/schema}/base_schema.d.ts +0 -0
- /package/{schema → dist/schema}/base_schema.js +0 -0
- /package/{schema → dist/schema}/field.d.ts +0 -0
- /package/{schema → dist/schema}/field.js +0 -0
- /package/{schema → dist/schema}/index.d.ts +0 -0
- /package/{schema → dist/schema}/index.js +0 -0
- /package/{schema → dist/schema}/json_field.d.ts +0 -0
- /package/{schema → dist/schema}/json_field.js +0 -0
- /package/{schema → dist/schema}/schema.d.ts +0 -0
- /package/{schema → dist/schema}/schema.js +0 -0
- /package/{schema → dist/schema}/struct_field.d.ts +0 -0
- /package/{schema → dist/schema}/struct_field.js +0 -0
- /package/{schema → dist/schema}/union_field.d.ts +0 -0
- /package/{schema → dist/schema}/union_field.js +0 -0
- /package/{scripts → dist/scripts}/custom_compiler.d.ts +0 -0
- /package/{scripts → dist/scripts}/custom_graphql.d.ts +0 -0
- /package/{scripts → dist/scripts}/migrate_v0.1.d.ts +0 -0
- /package/{scripts → dist/scripts}/migrate_v0.1.js +0 -0
- /package/{scripts → dist/scripts}/move_types.d.ts +0 -0
- /package/{scripts → dist/scripts}/move_types.js +0 -0
- /package/{scripts → dist/scripts}/read_schema.d.ts +0 -0
- /package/{scripts → dist/scripts}/read_schema.js +0 -0
- /package/{testutils → dist/testutils}/action/complex_schemas.d.ts +0 -0
- /package/{testutils → dist/testutils}/action/complex_schemas.js +0 -0
- /package/{testutils → dist/testutils}/builder.d.ts +0 -0
- /package/{testutils → dist/testutils}/builder.js +0 -0
- /package/{testutils → dist/testutils}/context/test_context.d.ts +0 -0
- /package/{testutils → dist/testutils}/context/test_context.js +0 -0
- /package/{testutils → dist/testutils}/db/fixture.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/fixture.js +0 -0
- /package/{testutils → dist/testutils}/db/temp_db.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/temp_db.js +0 -0
- /package/{testutils → dist/testutils}/db/value.d.ts +0 -0
- /package/{testutils → dist/testutils}/db/value.js +0 -0
- /package/{testutils → dist/testutils}/db_mock.d.ts +0 -0
- /package/{testutils → dist/testutils}/db_mock.js +0 -0
- /package/{testutils → dist/testutils}/db_time_zone.d.ts +0 -0
- /package/{testutils → dist/testutils}/db_time_zone.js +0 -0
- /package/{testutils → dist/testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{testutils → dist/testutils}/ent-graphql-tests/index.js +0 -0
- /package/{testutils → dist/testutils}/fake_comms.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_comms.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/const.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/const.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/events_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/events_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_contact.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_event.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_tag.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/fake_user.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/index.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/index.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/internal.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/internal.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/tag_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/test_helpers.js +0 -0
- /package/{testutils → dist/testutils}/fake_data/user_query.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_data/user_query.js +0 -0
- /package/{testutils → dist/testutils}/fake_log.d.ts +0 -0
- /package/{testutils → dist/testutils}/fake_log.js +0 -0
- /package/{testutils → dist/testutils}/mock_date.d.ts +0 -0
- /package/{testutils → dist/testutils}/mock_date.js +0 -0
- /package/{testutils → dist/testutils}/mock_log.d.ts +0 -0
- /package/{testutils → dist/testutils}/mock_log.js +0 -0
- /package/{testutils → dist/testutils}/parse_sql.d.ts +0 -0
- /package/{testutils → dist/testutils}/parse_sql.js +0 -0
- /package/{testutils → dist/testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{testutils → dist/testutils}/test_edge_global_schema.js +0 -0
- /package/{testutils → dist/testutils}/write.d.ts +0 -0
- /package/{testutils → dist/testutils}/write.js +0 -0
- /package/{tsc → dist/tsc}/ast.d.ts +0 -0
- /package/{tsc → dist/tsc}/ast.js +0 -0
- /package/{tsc → dist/tsc}/compilerOptions.d.ts +0 -0
- /package/{tsc → dist/tsc}/compilerOptions.js +0 -0
- /package/{tsc → dist/tsc}/move_generated.d.ts +0 -0
- /package/{tsc → dist/tsc}/move_generated.js +0 -0
- /package/{tsc → dist/tsc}/transform.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform.js +0 -0
- /package/{tsc → dist/tsc}/transform_action.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_action.js +0 -0
- /package/{tsc → dist/tsc}/transform_ent.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_ent.js +0 -0
- /package/{tsc → dist/tsc}/transform_schema.d.ts +0 -0
- /package/{tsc → dist/tsc}/transform_schema.js +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Ent, LoadEntOptions } from "../../core/base";
|
|
2
|
+
import { FakeContact, FakeEvent, FakeUser, FakeTag } from "./internal";
|
|
3
|
+
|
|
4
|
+
export enum EdgeType {
|
|
5
|
+
UserToContacts = "userToContacts",
|
|
6
|
+
UserToFriends = "userToFriends",
|
|
7
|
+
UserToCustomEdge = "userToCustomEdge",
|
|
8
|
+
|
|
9
|
+
UserToEventsAttending = "userToEventsAttending",
|
|
10
|
+
EventToAttendees = "eventToAttendees",
|
|
11
|
+
|
|
12
|
+
// we may need the inverse edge of these 3 later
|
|
13
|
+
EventToInvited = "eventToInvited",
|
|
14
|
+
EventToDeclined = "eventToDeclined",
|
|
15
|
+
EventToMaybe = "eventToMaybe",
|
|
16
|
+
|
|
17
|
+
EventToHosts = "eventToHosts",
|
|
18
|
+
UserToHostedEvents = "userToHostedEvents",
|
|
19
|
+
|
|
20
|
+
UserToFriendRequests = "userToFriendRequests",
|
|
21
|
+
UserToIncomingFriendRequests = "userToIncomingFriendRequests",
|
|
22
|
+
|
|
23
|
+
// can follow users or events...
|
|
24
|
+
// so a polymorphic edge
|
|
25
|
+
UserToFollowing = "userToFollowing",
|
|
26
|
+
ObjectToFollowedUsers = "objectToFollowedUsers",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum NodeType {
|
|
30
|
+
FakeUser = "user",
|
|
31
|
+
FakeContact = "contact",
|
|
32
|
+
FakeEvent = "event",
|
|
33
|
+
FakeTag = "tag",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SymmetricEdges = new Set<string>();
|
|
37
|
+
SymmetricEdges.add(EdgeType.UserToFriends);
|
|
38
|
+
|
|
39
|
+
export const InverseEdges = new Map<EdgeType, EdgeType>([
|
|
40
|
+
[EdgeType.UserToEventsAttending, EdgeType.EventToAttendees],
|
|
41
|
+
[EdgeType.EventToAttendees, EdgeType.UserToEventsAttending],
|
|
42
|
+
|
|
43
|
+
[EdgeType.UserToHostedEvents, EdgeType.EventToHosts],
|
|
44
|
+
[EdgeType.EventToHosts, EdgeType.UserToHostedEvents],
|
|
45
|
+
|
|
46
|
+
[EdgeType.UserToFriendRequests, EdgeType.UserToIncomingFriendRequests],
|
|
47
|
+
[EdgeType.UserToIncomingFriendRequests, EdgeType.UserToFriendRequests],
|
|
48
|
+
|
|
49
|
+
[EdgeType.UserToFollowing, EdgeType.ObjectToFollowedUsers],
|
|
50
|
+
[EdgeType.ObjectToFollowedUsers, EdgeType.UserToFollowing],
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
export function getLoaderOptions(type: NodeType): LoadEntOptions<Ent> {
|
|
54
|
+
switch (type) {
|
|
55
|
+
case NodeType.FakeContact:
|
|
56
|
+
return FakeContact.loaderOptions();
|
|
57
|
+
case NodeType.FakeUser:
|
|
58
|
+
return FakeUser.loaderOptions();
|
|
59
|
+
case NodeType.FakeEvent:
|
|
60
|
+
return FakeEvent.loaderOptions();
|
|
61
|
+
case NodeType.FakeTag:
|
|
62
|
+
return FakeTag.loaderOptions();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ID, Viewer } from "../../core/base";
|
|
2
|
+
import { AssocEdge } from "../../core/ent";
|
|
3
|
+
import {
|
|
4
|
+
AssocEdgeQueryBase,
|
|
5
|
+
EdgeQuerySource,
|
|
6
|
+
} from "../../core/query/assoc_query";
|
|
7
|
+
import { FakeUser } from "./fake_user";
|
|
8
|
+
import { EdgeType, FakeEvent } from "./internal";
|
|
9
|
+
import { AssocEdgeCountLoaderFactory } from "../../core/loaders/assoc_count_loader";
|
|
10
|
+
import { AssocEdgeLoaderFactory } from "../../core/loaders/assoc_edge_loader";
|
|
11
|
+
|
|
12
|
+
export class EventToAttendeesQuery extends AssocEdgeQueryBase<
|
|
13
|
+
FakeEvent,
|
|
14
|
+
FakeUser,
|
|
15
|
+
AssocEdge
|
|
16
|
+
> {
|
|
17
|
+
constructor(viewer: Viewer, src: EdgeQuerySource<FakeEvent, FakeUser>) {
|
|
18
|
+
super(
|
|
19
|
+
viewer,
|
|
20
|
+
src,
|
|
21
|
+
new AssocEdgeCountLoaderFactory(EdgeType.EventToAttendees),
|
|
22
|
+
new AssocEdgeLoaderFactory(EdgeType.EventToAttendees, AssocEdge),
|
|
23
|
+
FakeUser.loaderOptions(),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static query(
|
|
28
|
+
viewer: Viewer,
|
|
29
|
+
src: EdgeQuerySource<FakeEvent, FakeUser>,
|
|
30
|
+
): EventToAttendeesQuery {
|
|
31
|
+
return new EventToAttendeesQuery(viewer, src);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
sourceEnt(id: ID) {
|
|
35
|
+
return FakeEvent.load(this.viewer, id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class EventToInvitedQuery extends AssocEdgeQueryBase<
|
|
40
|
+
FakeEvent,
|
|
41
|
+
FakeUser,
|
|
42
|
+
AssocEdge
|
|
43
|
+
> {
|
|
44
|
+
constructor(viewer: Viewer, src: EdgeQuerySource<FakeEvent, FakeUser>) {
|
|
45
|
+
super(
|
|
46
|
+
viewer,
|
|
47
|
+
src,
|
|
48
|
+
new AssocEdgeCountLoaderFactory(EdgeType.EventToInvited),
|
|
49
|
+
new AssocEdgeLoaderFactory(EdgeType.EventToInvited, AssocEdge),
|
|
50
|
+
FakeUser.loaderOptions(),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static query(
|
|
55
|
+
viewer: Viewer,
|
|
56
|
+
src: EdgeQuerySource<FakeEvent, FakeUser>,
|
|
57
|
+
): EventToInvitedQuery {
|
|
58
|
+
return new EventToInvitedQuery(viewer, src);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
sourceEnt(id: ID) {
|
|
62
|
+
return FakeEvent.load(this.viewer, id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class EventToDeclinedQuery extends AssocEdgeQueryBase<
|
|
67
|
+
FakeEvent,
|
|
68
|
+
FakeUser,
|
|
69
|
+
AssocEdge
|
|
70
|
+
> {
|
|
71
|
+
constructor(viewer: Viewer, src: EdgeQuerySource<FakeEvent, FakeUser>) {
|
|
72
|
+
super(
|
|
73
|
+
viewer,
|
|
74
|
+
src,
|
|
75
|
+
new AssocEdgeCountLoaderFactory(EdgeType.EventToDeclined),
|
|
76
|
+
new AssocEdgeLoaderFactory(EdgeType.EventToDeclined, AssocEdge),
|
|
77
|
+
FakeUser.loaderOptions(),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static query(
|
|
82
|
+
viewer: Viewer,
|
|
83
|
+
src: EdgeQuerySource<FakeEvent, FakeUser>,
|
|
84
|
+
): EventToDeclinedQuery {
|
|
85
|
+
return new EventToDeclinedQuery(viewer, src);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sourceEnt(id: ID) {
|
|
89
|
+
return FakeEvent.load(this.viewer, id);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class EventToMaybeQuery extends AssocEdgeQueryBase<
|
|
94
|
+
FakeEvent,
|
|
95
|
+
FakeUser,
|
|
96
|
+
AssocEdge
|
|
97
|
+
> {
|
|
98
|
+
constructor(viewer: Viewer, src: EdgeQuerySource<FakeEvent, FakeUser>) {
|
|
99
|
+
super(
|
|
100
|
+
viewer,
|
|
101
|
+
src,
|
|
102
|
+
new AssocEdgeCountLoaderFactory(EdgeType.EventToMaybe),
|
|
103
|
+
new AssocEdgeLoaderFactory(EdgeType.EventToMaybe, AssocEdge),
|
|
104
|
+
FakeUser.loaderOptions(),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static query(
|
|
109
|
+
viewer: Viewer,
|
|
110
|
+
src: EdgeQuerySource<FakeEvent, FakeUser>,
|
|
111
|
+
): EventToMaybeQuery {
|
|
112
|
+
return new EventToMaybeQuery(viewer, src);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
sourceEnt(id: ID) {
|
|
116
|
+
return FakeEvent.load(this.viewer, id);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class EventToHostsQuery extends AssocEdgeQueryBase<
|
|
121
|
+
FakeEvent,
|
|
122
|
+
FakeUser,
|
|
123
|
+
AssocEdge
|
|
124
|
+
> {
|
|
125
|
+
constructor(viewer: Viewer, src: EdgeQuerySource<FakeEvent, FakeUser>) {
|
|
126
|
+
super(
|
|
127
|
+
viewer,
|
|
128
|
+
src,
|
|
129
|
+
new AssocEdgeCountLoaderFactory(EdgeType.EventToHosts),
|
|
130
|
+
new AssocEdgeLoaderFactory(EdgeType.EventToHosts, AssocEdge),
|
|
131
|
+
FakeUser.loaderOptions(),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static query(
|
|
136
|
+
viewer: Viewer,
|
|
137
|
+
src: EdgeQuerySource<FakeEvent, FakeUser>,
|
|
138
|
+
): EventToHostsQuery {
|
|
139
|
+
return new EventToHostsQuery(viewer, src);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
sourceEnt(id: ID) {
|
|
143
|
+
return FakeEvent.load(this.viewer, id);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ID,
|
|
3
|
+
Ent,
|
|
4
|
+
Viewer,
|
|
5
|
+
Data,
|
|
6
|
+
LoadEntOptions,
|
|
7
|
+
PrivacyPolicy,
|
|
8
|
+
Context,
|
|
9
|
+
} from "../../core/base";
|
|
10
|
+
import { loadEnt, loadEntX } from "../../core/ent";
|
|
11
|
+
import { AllowIfViewerIsRule, AlwaysDenyRule } from "../../core/privacy";
|
|
12
|
+
import { getBuilderSchemaFromFields, SimpleBuilder } from "../builder";
|
|
13
|
+
import { StringType, UUIDType } from "../../schema";
|
|
14
|
+
import { NodeType } from "./const";
|
|
15
|
+
import { table, uuid, text, timestamptz } from "../db/temp_db";
|
|
16
|
+
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
17
|
+
import { convertDate } from "../../core/convert";
|
|
18
|
+
import { WriteOperation } from "../../action";
|
|
19
|
+
|
|
20
|
+
export class FakeContact implements Ent {
|
|
21
|
+
readonly id: ID;
|
|
22
|
+
readonly data: Data;
|
|
23
|
+
readonly nodeType = NodeType.FakeContact;
|
|
24
|
+
readonly createdAt: Date;
|
|
25
|
+
readonly updatedAt: Date;
|
|
26
|
+
readonly firstName: string;
|
|
27
|
+
readonly lastName: string;
|
|
28
|
+
readonly emailAddress: string;
|
|
29
|
+
readonly userID: ID;
|
|
30
|
+
|
|
31
|
+
getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
32
|
+
return {
|
|
33
|
+
rules: [new AllowIfViewerIsRule("userID"), AlwaysDenyRule],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
constructor(public viewer: Viewer, data: Data) {
|
|
38
|
+
this.data = data;
|
|
39
|
+
this.id = data.id;
|
|
40
|
+
this.createdAt = convertDate(data.created_at);
|
|
41
|
+
this.updatedAt = convertDate(data.updated_at);
|
|
42
|
+
this.firstName = data.first_name;
|
|
43
|
+
this.lastName = data.last_name;
|
|
44
|
+
this.emailAddress = data.email_address;
|
|
45
|
+
this.userID = data.user_id;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
__setRawDBData(data: Data) {}
|
|
49
|
+
|
|
50
|
+
static getFields(): string[] {
|
|
51
|
+
return [
|
|
52
|
+
"id",
|
|
53
|
+
"created_at",
|
|
54
|
+
"updated_at",
|
|
55
|
+
"first_name",
|
|
56
|
+
"last_name",
|
|
57
|
+
"email_address",
|
|
58
|
+
"user_id",
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static getTestTable() {
|
|
63
|
+
return table(
|
|
64
|
+
"fake_contacts",
|
|
65
|
+
uuid("id", { primaryKey: true }),
|
|
66
|
+
timestamptz("created_at"),
|
|
67
|
+
timestamptz("updated_at"),
|
|
68
|
+
text("first_name"),
|
|
69
|
+
text("last_name"),
|
|
70
|
+
text("email_address"),
|
|
71
|
+
uuid("user_id"),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static loaderOptions(): LoadEntOptions<FakeContact> {
|
|
76
|
+
return {
|
|
77
|
+
tableName: "fake_contacts",
|
|
78
|
+
fields: FakeContact.getFields(),
|
|
79
|
+
ent: this,
|
|
80
|
+
loaderFactory: new ObjectLoaderFactory({
|
|
81
|
+
tableName: "fake_contacts",
|
|
82
|
+
key: "id",
|
|
83
|
+
fields: FakeContact.getFields(),
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
static async load(v: Viewer, id: ID): Promise<FakeContact | null> {
|
|
88
|
+
return loadEnt(v, id, FakeContact.loaderOptions());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static async loadX(v: Viewer, id: ID): Promise<FakeContact> {
|
|
92
|
+
return loadEntX(v, id, FakeContact.loaderOptions());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static async loadRawData(id: ID, context?: Context): Promise<Data | null> {
|
|
96
|
+
return FakeContact.loaderOptions()
|
|
97
|
+
.loaderFactory.createLoader(context)
|
|
98
|
+
.load(id);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const FakeContactSchema = getBuilderSchemaFromFields(
|
|
103
|
+
{
|
|
104
|
+
firstName: StringType(),
|
|
105
|
+
lastName: StringType(),
|
|
106
|
+
emailAddress: StringType(),
|
|
107
|
+
userID: UUIDType({
|
|
108
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
FakeContact,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export interface ContactCreateInput {
|
|
115
|
+
firstName: string;
|
|
116
|
+
lastName: string;
|
|
117
|
+
emailAddress: string;
|
|
118
|
+
userID: ID;
|
|
119
|
+
createdAt?: Date;
|
|
120
|
+
updatedAt?: Date;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getContactBuilder(viewer: Viewer, input: ContactCreateInput) {
|
|
124
|
+
const m = new Map();
|
|
125
|
+
for (const key in input) {
|
|
126
|
+
m.set(key, input[key]);
|
|
127
|
+
}
|
|
128
|
+
//To lock in the value of Date now incase of advanceTo/advanceBy
|
|
129
|
+
m.set("createdAt", new Date());
|
|
130
|
+
m.set("updatedAt", new Date());
|
|
131
|
+
|
|
132
|
+
return new SimpleBuilder(
|
|
133
|
+
viewer,
|
|
134
|
+
FakeContactSchema,
|
|
135
|
+
m,
|
|
136
|
+
WriteOperation.Insert,
|
|
137
|
+
null,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function createContact(viewer: Viewer, input: ContactCreateInput) {
|
|
142
|
+
const builder = getContactBuilder(viewer, input);
|
|
143
|
+
return await builder.saveX();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export const contactLoader = new ObjectLoaderFactory({
|
|
147
|
+
tableName: "fake_contacts",
|
|
148
|
+
fields: FakeContact.getFields(),
|
|
149
|
+
key: "id",
|
|
150
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ID,
|
|
3
|
+
Ent,
|
|
4
|
+
Viewer,
|
|
5
|
+
Data,
|
|
6
|
+
LoadEntOptions,
|
|
7
|
+
PrivacyPolicy,
|
|
8
|
+
} from "../../core/base";
|
|
9
|
+
import { loadEnt, loadEntX } from "../../core/ent";
|
|
10
|
+
import { AlwaysAllowPrivacyPolicy } from "../../core/privacy";
|
|
11
|
+
import { getBuilderSchemaFromFields, SimpleBuilder } from "../builder";
|
|
12
|
+
import { StringType, UUIDType, TimestampType } from "../../schema";
|
|
13
|
+
import { NodeType } from "./const";
|
|
14
|
+
import { table, uuid, text, timestamptz } from "../db/temp_db";
|
|
15
|
+
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
16
|
+
import { convertDate, convertNullableDate } from "../../core/convert";
|
|
17
|
+
import { WriteOperation } from "../../action";
|
|
18
|
+
|
|
19
|
+
export class FakeEvent implements Ent {
|
|
20
|
+
readonly id: ID;
|
|
21
|
+
readonly data: Data;
|
|
22
|
+
readonly nodeType = NodeType.FakeEvent;
|
|
23
|
+
readonly createdAt: Date;
|
|
24
|
+
readonly updatedAt: Date;
|
|
25
|
+
readonly startTime: Date;
|
|
26
|
+
readonly endTime: Date | null;
|
|
27
|
+
readonly location: string;
|
|
28
|
+
readonly title: string;
|
|
29
|
+
readonly description: string | null;
|
|
30
|
+
readonly userID: ID;
|
|
31
|
+
|
|
32
|
+
getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
33
|
+
return AlwaysAllowPrivacyPolicy;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
constructor(public viewer: Viewer, data: Data) {
|
|
37
|
+
this.data = data;
|
|
38
|
+
this.id = data.id;
|
|
39
|
+
this.createdAt = convertDate(data.created_at);
|
|
40
|
+
this.updatedAt = convertDate(data.updated_at);
|
|
41
|
+
this.startTime = convertDate(data.start_time);
|
|
42
|
+
this.endTime = convertNullableDate(data.end_time);
|
|
43
|
+
this.location = data.location;
|
|
44
|
+
this.title = data.title;
|
|
45
|
+
this.description = data.description;
|
|
46
|
+
this.userID = data.user_id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
__setRawDBData(data: Data) {}
|
|
50
|
+
|
|
51
|
+
private static getFields(): string[] {
|
|
52
|
+
return [
|
|
53
|
+
"id",
|
|
54
|
+
"created_at",
|
|
55
|
+
"updated_at",
|
|
56
|
+
"start_time",
|
|
57
|
+
"end_time",
|
|
58
|
+
"location",
|
|
59
|
+
"title",
|
|
60
|
+
"description",
|
|
61
|
+
"user_id",
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static getTestTable() {
|
|
66
|
+
return table(
|
|
67
|
+
"fake_events",
|
|
68
|
+
uuid("id", { primaryKey: true }),
|
|
69
|
+
timestamptz("created_at"),
|
|
70
|
+
timestamptz("updated_at"),
|
|
71
|
+
// TODO index:true
|
|
72
|
+
timestamptz("start_time"),
|
|
73
|
+
timestamptz("end_time", { nullable: true }),
|
|
74
|
+
text("location"),
|
|
75
|
+
text("title"),
|
|
76
|
+
text("description", { nullable: true }),
|
|
77
|
+
uuid("user_id"),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static loaderOptions(): LoadEntOptions<FakeEvent> {
|
|
82
|
+
return {
|
|
83
|
+
tableName: "fake_events",
|
|
84
|
+
fields: FakeEvent.getFields(),
|
|
85
|
+
ent: this,
|
|
86
|
+
loaderFactory: new ObjectLoaderFactory({
|
|
87
|
+
tableName: "fake_events",
|
|
88
|
+
key: "id",
|
|
89
|
+
fields: FakeEvent.getFields(),
|
|
90
|
+
}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
static async load(v: Viewer, id: ID): Promise<FakeEvent | null> {
|
|
94
|
+
return loadEnt(v, id, FakeEvent.loaderOptions());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static async loadX(v: Viewer, id: ID): Promise<FakeEvent> {
|
|
98
|
+
return loadEntX(v, id, FakeEvent.loaderOptions());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const FakeEventSchema = getBuilderSchemaFromFields(
|
|
103
|
+
{
|
|
104
|
+
startTime: TimestampType({
|
|
105
|
+
index: true,
|
|
106
|
+
}),
|
|
107
|
+
endTime: TimestampType({
|
|
108
|
+
nullable: true,
|
|
109
|
+
}),
|
|
110
|
+
title: StringType(),
|
|
111
|
+
location: StringType(),
|
|
112
|
+
description: StringType({
|
|
113
|
+
nullable: true,
|
|
114
|
+
}),
|
|
115
|
+
userID: UUIDType({
|
|
116
|
+
foreignKey: { schema: "User", column: "ID" },
|
|
117
|
+
}),
|
|
118
|
+
},
|
|
119
|
+
FakeEvent,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
export interface EventCreateInput {
|
|
123
|
+
createdAt?: Date;
|
|
124
|
+
updatedAt?: Date;
|
|
125
|
+
startTime: Date;
|
|
126
|
+
endTime?: Date | null;
|
|
127
|
+
location: string;
|
|
128
|
+
title: string;
|
|
129
|
+
description?: string | null;
|
|
130
|
+
userID: ID;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function getEventBuilder(viewer: Viewer, input: EventCreateInput) {
|
|
134
|
+
const m = new Map();
|
|
135
|
+
for (const key in input) {
|
|
136
|
+
m.set(key, input[key]);
|
|
137
|
+
}
|
|
138
|
+
return new SimpleBuilder(
|
|
139
|
+
viewer,
|
|
140
|
+
FakeEventSchema,
|
|
141
|
+
m,
|
|
142
|
+
WriteOperation.Insert,
|
|
143
|
+
null,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function createEvent(viewer: Viewer, input: EventCreateInput) {
|
|
148
|
+
const builder = getEventBuilder(viewer, input);
|
|
149
|
+
return await builder.saveX();
|
|
150
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ID,
|
|
3
|
+
Ent,
|
|
4
|
+
Viewer,
|
|
5
|
+
Data,
|
|
6
|
+
LoadEntOptions,
|
|
7
|
+
PrivacyPolicy,
|
|
8
|
+
} from "../../core/base";
|
|
9
|
+
import { loadEnt, loadEntX } from "../../core/ent";
|
|
10
|
+
import {
|
|
11
|
+
AlwaysDenyRule,
|
|
12
|
+
AllowIfViewerIsEntPropertyRule,
|
|
13
|
+
} from "../../core/privacy";
|
|
14
|
+
import { getBuilderSchemaFromFields, SimpleAction } from "../builder";
|
|
15
|
+
import { StringType, UUIDType } from "../../schema";
|
|
16
|
+
import { NodeType } from "./const";
|
|
17
|
+
import { table, uuid, text, timestamptz, index } from "../db/temp_db";
|
|
18
|
+
import { ObjectLoaderFactory } from "../../core/loaders";
|
|
19
|
+
import { convertDate } from "../../core/convert";
|
|
20
|
+
import { WriteOperation } from "../../action";
|
|
21
|
+
|
|
22
|
+
export class FakeTag implements Ent {
|
|
23
|
+
readonly id: ID;
|
|
24
|
+
readonly data: Data;
|
|
25
|
+
readonly nodeType = NodeType.FakeUser;
|
|
26
|
+
readonly createdAt: Date;
|
|
27
|
+
readonly updatedAt: Date;
|
|
28
|
+
readonly displayName: string;
|
|
29
|
+
readonly canonicalName: string;
|
|
30
|
+
readonly ownerID: string;
|
|
31
|
+
|
|
32
|
+
getPrivacyPolicy(): PrivacyPolicy<this> {
|
|
33
|
+
return {
|
|
34
|
+
rules: [new AllowIfViewerIsEntPropertyRule("ownerID"), AlwaysDenyRule],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
constructor(public viewer: Viewer, data: Data) {
|
|
39
|
+
this.data = data;
|
|
40
|
+
this.id = data.id;
|
|
41
|
+
this.createdAt = convertDate(data.created_at);
|
|
42
|
+
this.updatedAt = convertDate(data.updated_at);
|
|
43
|
+
this.displayName = data.display_name;
|
|
44
|
+
this.canonicalName = data.canonical_name;
|
|
45
|
+
this.ownerID = data.owner_id;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
__setRawDBData(data: Data) {}
|
|
49
|
+
|
|
50
|
+
static getFields(): string[] {
|
|
51
|
+
return [
|
|
52
|
+
"id",
|
|
53
|
+
"created_at",
|
|
54
|
+
"updated_at",
|
|
55
|
+
"display_name",
|
|
56
|
+
"canonical_name",
|
|
57
|
+
"owner_id",
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static getTestTable() {
|
|
62
|
+
return table(
|
|
63
|
+
"fake_tags",
|
|
64
|
+
uuid("id", { primaryKey: true }),
|
|
65
|
+
timestamptz("created_at"),
|
|
66
|
+
timestamptz("updated_at"),
|
|
67
|
+
text("display_name"),
|
|
68
|
+
text("canonical_name"),
|
|
69
|
+
uuid("owner_id"), // TODO index: true sqlite broken?
|
|
70
|
+
index("fake_tags", ["canonical_name", "owner_id"], { unique: true }),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static loaderOptions(): LoadEntOptions<FakeTag> {
|
|
75
|
+
return {
|
|
76
|
+
tableName: "fake_tags",
|
|
77
|
+
fields: FakeTag.getFields(),
|
|
78
|
+
ent: this,
|
|
79
|
+
loaderFactory: tagLoader,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
static async load(v: Viewer, id: ID): Promise<FakeTag | null> {
|
|
83
|
+
return loadEnt(v, id, FakeTag.loaderOptions());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static async loadX(v: Viewer, id: ID): Promise<FakeTag> {
|
|
87
|
+
return loadEntX(v, id, FakeTag.loaderOptions());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const FakeTagSchema = getBuilderSchemaFromFields(
|
|
92
|
+
{
|
|
93
|
+
displayName: StringType(),
|
|
94
|
+
canonicalName: StringType().trim().toLowerCase(),
|
|
95
|
+
ownerID: UUIDType({}),
|
|
96
|
+
},
|
|
97
|
+
FakeTag,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
export interface TagCreateInput {
|
|
101
|
+
displayName: string;
|
|
102
|
+
canonicalName: string;
|
|
103
|
+
ownerID: ID;
|
|
104
|
+
createdAt?: Date;
|
|
105
|
+
updatedAt?: Date;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type TagEditInput = Partial<TagCreateInput>;
|
|
109
|
+
|
|
110
|
+
export function getTagBuilder(viewer: Viewer, input: TagCreateInput) {
|
|
111
|
+
const action = getTagAction(viewer, input);
|
|
112
|
+
return action.builder;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function getTagAction(viewer: Viewer, input: TagCreateInput) {
|
|
116
|
+
const m = new Map();
|
|
117
|
+
for (const key in input) {
|
|
118
|
+
m.set(key, input[key]);
|
|
119
|
+
}
|
|
120
|
+
const action = new SimpleAction(
|
|
121
|
+
viewer,
|
|
122
|
+
FakeTagSchema,
|
|
123
|
+
m,
|
|
124
|
+
WriteOperation.Insert,
|
|
125
|
+
null,
|
|
126
|
+
);
|
|
127
|
+
return action;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function createTag(viewer: Viewer, input: TagCreateInput) {
|
|
131
|
+
const action = getTagAction(viewer, input);
|
|
132
|
+
return action.saveX();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const tagLoader = new ObjectLoaderFactory({
|
|
136
|
+
tableName: "fake_tags",
|
|
137
|
+
fields: FakeTag.getFields(),
|
|
138
|
+
key: "id",
|
|
139
|
+
});
|