@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,37 @@
|
|
|
1
|
+
import { Builder } from "./action";
|
|
2
|
+
import {
|
|
3
|
+
Viewer,
|
|
4
|
+
ID,
|
|
5
|
+
Ent,
|
|
6
|
+
PrivacyResult,
|
|
7
|
+
PrivacyPolicyRule,
|
|
8
|
+
Deny,
|
|
9
|
+
Allow,
|
|
10
|
+
Skip,
|
|
11
|
+
} from "../core/base";
|
|
12
|
+
|
|
13
|
+
function isBuilder(node: ID | Builder<Ent, any>): node is Builder<Ent, any> {
|
|
14
|
+
return (node as Builder<Ent>).placeholderID !== undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class DenyIfBuilder implements PrivacyPolicyRule {
|
|
18
|
+
constructor(private id?: ID | Builder<Ent, any>) {}
|
|
19
|
+
|
|
20
|
+
async apply(_v: Viewer, _ent: Ent): Promise<PrivacyResult> {
|
|
21
|
+
if (this.id && isBuilder(this.id)) {
|
|
22
|
+
return Deny();
|
|
23
|
+
}
|
|
24
|
+
return Skip();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class AllowIfBuilder implements PrivacyPolicyRule {
|
|
29
|
+
constructor(private id?: ID | Builder<Ent, any>) {}
|
|
30
|
+
|
|
31
|
+
async apply(_v: Viewer, _ent: Ent): Promise<PrivacyResult> {
|
|
32
|
+
if (this.id && isBuilder(this.id)) {
|
|
33
|
+
return Allow();
|
|
34
|
+
}
|
|
35
|
+
return Skip();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Add,
|
|
3
|
+
Clause,
|
|
4
|
+
Divide,
|
|
5
|
+
Modulo,
|
|
6
|
+
Multiply,
|
|
7
|
+
Subtract,
|
|
8
|
+
} from "../core/clause";
|
|
9
|
+
|
|
10
|
+
export interface RelativeFieldValue<T = BigInt | number> {
|
|
11
|
+
delta: T;
|
|
12
|
+
sqlExpression: (col: string) => Clause;
|
|
13
|
+
eval: (curr: T) => T;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RelativeNumberValue<T> {
|
|
17
|
+
add?: T;
|
|
18
|
+
subtract?: T;
|
|
19
|
+
divide?: T;
|
|
20
|
+
multiply?: T;
|
|
21
|
+
// note modulo only seems to work with integer types in postgres
|
|
22
|
+
modulo?: T;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// and then that translates to calling these which returns a RelativeFieldValue which is much cleaner?
|
|
26
|
+
// can also do it one by one instead of what we had in
|
|
27
|
+
|
|
28
|
+
// https://github.com/microsoft/TypeScript/issues/27808 is why we have the ts-expect-error below
|
|
29
|
+
function addNumber(delta: number): RelativeFieldValue<number>;
|
|
30
|
+
function addNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
31
|
+
function addNumber<T = number | BigInt>(delta: T): RelativeFieldValue<T> {
|
|
32
|
+
return {
|
|
33
|
+
delta,
|
|
34
|
+
sqlExpression(col: string): Clause {
|
|
35
|
+
return Add(col, delta);
|
|
36
|
+
},
|
|
37
|
+
eval(curr): T {
|
|
38
|
+
// @ts-expect-error
|
|
39
|
+
return curr + delta;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function subtractNumber(delta: number): RelativeFieldValue<number>;
|
|
45
|
+
function subtractNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
46
|
+
function subtractNumber<T = number | BigInt>(delta: T): RelativeFieldValue<T> {
|
|
47
|
+
return {
|
|
48
|
+
delta,
|
|
49
|
+
sqlExpression(col: string): Clause {
|
|
50
|
+
return Subtract(col, delta);
|
|
51
|
+
},
|
|
52
|
+
eval(curr): T {
|
|
53
|
+
// @ts-expect-error
|
|
54
|
+
return curr - delta;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function multiplyNumber(delta: number): RelativeFieldValue<number>;
|
|
60
|
+
function multiplyNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
61
|
+
function multiplyNumber<T = number | BigInt>(delta: T): RelativeFieldValue<T> {
|
|
62
|
+
return {
|
|
63
|
+
delta,
|
|
64
|
+
sqlExpression(col: string): Clause {
|
|
65
|
+
return Multiply(col, delta);
|
|
66
|
+
},
|
|
67
|
+
eval(curr): T {
|
|
68
|
+
// @ts-expect-error
|
|
69
|
+
return curr * delta;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function divideNumber(delta: number): RelativeFieldValue<number>;
|
|
75
|
+
function divideNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
76
|
+
function divideNumber<T = BigInt | number>(delta: T): RelativeFieldValue<T> {
|
|
77
|
+
return {
|
|
78
|
+
delta,
|
|
79
|
+
sqlExpression(col: string): Clause {
|
|
80
|
+
return Divide(col, delta);
|
|
81
|
+
},
|
|
82
|
+
eval(curr): T {
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
return curr / delta;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// note modulo only seems to work with integer types in postgres
|
|
90
|
+
function moduloNumber(delta: number): RelativeFieldValue<number>;
|
|
91
|
+
function moduloNumber(delta: BigInt): RelativeFieldValue<BigInt>;
|
|
92
|
+
function moduloNumber<T = BigInt | number>(delta: T): RelativeFieldValue<T> {
|
|
93
|
+
return {
|
|
94
|
+
delta,
|
|
95
|
+
sqlExpression(col: string): Clause {
|
|
96
|
+
return Modulo(col, delta);
|
|
97
|
+
},
|
|
98
|
+
eval(curr): T {
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
return curr % delta;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const NumberOps = {
|
|
106
|
+
addNumber,
|
|
107
|
+
moduloNumber,
|
|
108
|
+
divideNumber,
|
|
109
|
+
subtractNumber,
|
|
110
|
+
multiplyNumber,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export function convertRelativeInput(
|
|
114
|
+
rel: RelativeNumberValue<BigInt>,
|
|
115
|
+
col: string,
|
|
116
|
+
existing: BigInt,
|
|
117
|
+
): { value: BigInt; clause: Clause };
|
|
118
|
+
export function convertRelativeInput(
|
|
119
|
+
rel: RelativeNumberValue<number>,
|
|
120
|
+
col: string,
|
|
121
|
+
existing: number,
|
|
122
|
+
): { value: number; clause: Clause };
|
|
123
|
+
export function convertRelativeInput<T = BigInt | number>(
|
|
124
|
+
rel: RelativeNumberValue<T>,
|
|
125
|
+
col: string,
|
|
126
|
+
existing: T,
|
|
127
|
+
): { value: T; clause: Clause } {
|
|
128
|
+
if (Object.keys(rel).length !== 1) {
|
|
129
|
+
throw new Error(`only 1 key is expected. ${Object.keys(rel).length} given`);
|
|
130
|
+
}
|
|
131
|
+
const ret = (relField: RelativeFieldValue<T>) => {
|
|
132
|
+
return {
|
|
133
|
+
value: relField.eval(existing),
|
|
134
|
+
clause: relField.sqlExpression(col),
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
if (rel.add !== undefined) {
|
|
138
|
+
// @ts-expect-error
|
|
139
|
+
return ret(addNumber(rel.add));
|
|
140
|
+
}
|
|
141
|
+
if (rel.subtract !== undefined) {
|
|
142
|
+
// @ts-expect-error
|
|
143
|
+
return ret(subtractNumber(rel.subtract));
|
|
144
|
+
}
|
|
145
|
+
if (rel.multiply !== undefined) {
|
|
146
|
+
// @ts-expect-error
|
|
147
|
+
return ret(multiplyNumber(rel.multiply));
|
|
148
|
+
}
|
|
149
|
+
if (rel.divide !== undefined) {
|
|
150
|
+
// @ts-expect-error
|
|
151
|
+
return ret(divideNumber(rel.divide));
|
|
152
|
+
}
|
|
153
|
+
if (rel.modulo !== undefined) {
|
|
154
|
+
// @ts-expect-error
|
|
155
|
+
return ret(moduloNumber(rel.modulo));
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`error in convertRelativeInput. shouldn't have gotten here`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
161
|
+
rel: number | RelativeNumberValue<number>,
|
|
162
|
+
col: string,
|
|
163
|
+
existing: number,
|
|
164
|
+
expressions: Map<string, Clause>,
|
|
165
|
+
): number;
|
|
166
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
167
|
+
rel: number | RelativeNumberValue<number> | undefined,
|
|
168
|
+
col: string,
|
|
169
|
+
existing: number,
|
|
170
|
+
expressions: Map<string, Clause>,
|
|
171
|
+
): number | undefined;
|
|
172
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
173
|
+
rel: number | RelativeNumberValue<number> | null,
|
|
174
|
+
col: string,
|
|
175
|
+
existing: number | null,
|
|
176
|
+
expressions: Map<string, Clause>,
|
|
177
|
+
): number | null;
|
|
178
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
179
|
+
rel: number | RelativeNumberValue<number> | null | undefined,
|
|
180
|
+
col: string,
|
|
181
|
+
existing: number | null,
|
|
182
|
+
expressions: Map<string, Clause>,
|
|
183
|
+
): number | undefined | null;
|
|
184
|
+
|
|
185
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
186
|
+
rel: BigInt | RelativeNumberValue<BigInt>,
|
|
187
|
+
col: string,
|
|
188
|
+
existing: BigInt,
|
|
189
|
+
expressions: Map<string, Clause>,
|
|
190
|
+
): BigInt;
|
|
191
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
192
|
+
rel: BigInt | RelativeNumberValue<BigInt> | undefined,
|
|
193
|
+
col: string,
|
|
194
|
+
existing: BigInt,
|
|
195
|
+
expressions: Map<string, Clause>,
|
|
196
|
+
): BigInt | undefined;
|
|
197
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
198
|
+
rel: BigInt | RelativeNumberValue<BigInt> | null,
|
|
199
|
+
col: string,
|
|
200
|
+
existing: BigInt | null,
|
|
201
|
+
expressions: Map<string, Clause>,
|
|
202
|
+
): BigInt | null;
|
|
203
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
204
|
+
rel: BigInt | RelativeNumberValue<BigInt> | null | undefined,
|
|
205
|
+
col: string,
|
|
206
|
+
existing: BigInt | null,
|
|
207
|
+
expressions: Map<string, Clause>,
|
|
208
|
+
): BigInt | null | undefined;
|
|
209
|
+
|
|
210
|
+
export function maybeConvertRelativeInputPlusExpressions(
|
|
211
|
+
rel:
|
|
212
|
+
| number
|
|
213
|
+
| RelativeNumberValue<number>
|
|
214
|
+
| BigInt
|
|
215
|
+
| RelativeNumberValue<BigInt>
|
|
216
|
+
| null
|
|
217
|
+
| undefined,
|
|
218
|
+
col: string,
|
|
219
|
+
existing: number | BigInt | null,
|
|
220
|
+
expressions: Map<string, Clause>,
|
|
221
|
+
): number | null | undefined | BigInt {
|
|
222
|
+
if (rel === null) {
|
|
223
|
+
return rel;
|
|
224
|
+
}
|
|
225
|
+
if (rel === undefined) {
|
|
226
|
+
return rel;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (typeof rel === "bigint" || typeof rel === "number") {
|
|
230
|
+
return rel;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// // TODO is this the behavior we want? should we coalesce as 0?
|
|
234
|
+
// if (existing === null) {
|
|
235
|
+
// throw new Error(`cannot perform a relative operation on null`);
|
|
236
|
+
// }
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
// shouldn't be failing like it currently is. it thinks rel can be bigint and it shouldn't be???
|
|
239
|
+
const { clause, value } = convertRelativeInput(rel, col, existing);
|
|
240
|
+
expressions.set(col, clause);
|
|
241
|
+
return value;
|
|
242
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Ent, Viewer } from "../core/base";
|
|
2
|
+
import { Action, Builder, Changeset } from "./action";
|
|
3
|
+
import { ComplexExecutor } from "./executor";
|
|
4
|
+
|
|
5
|
+
type ActionAny = Action<
|
|
6
|
+
Ent<Viewer<any, any>>,
|
|
7
|
+
Builder<Ent<Viewer<any, any>>, Viewer<any, any>, any>,
|
|
8
|
+
Viewer<any, any>,
|
|
9
|
+
any,
|
|
10
|
+
any
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export class Transaction {
|
|
14
|
+
constructor(
|
|
15
|
+
private viewer: Viewer,
|
|
16
|
+
// independent operations
|
|
17
|
+
private actions: ActionAny[], // TODO ops for different types of transaction
|
|
18
|
+
) {}
|
|
19
|
+
|
|
20
|
+
async run() {
|
|
21
|
+
const changesets: Changeset[] = [];
|
|
22
|
+
await Promise.all(
|
|
23
|
+
this.actions.map(async (action) => {
|
|
24
|
+
const c = await action.changeset();
|
|
25
|
+
changesets.push(c);
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const executor = new ComplexExecutor(
|
|
30
|
+
this.viewer,
|
|
31
|
+
"", // no placeholder, no opers
|
|
32
|
+
[],
|
|
33
|
+
new Map(),
|
|
34
|
+
changesets,
|
|
35
|
+
);
|
|
36
|
+
await executor.execute();
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/auth/auth.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Viewer } from "../core/base";
|
|
2
|
+
import { LoggedOutViewer } from "../core/viewer";
|
|
3
|
+
import { RequestContext, ContextCache } from "../core/context";
|
|
4
|
+
import { IncomingMessage, ServerResponse } from "http";
|
|
5
|
+
import { log } from "../core/logger";
|
|
6
|
+
|
|
7
|
+
export type AuthViewer = Viewer | null;
|
|
8
|
+
export interface AuthHandler {
|
|
9
|
+
authViewer(ctx: RequestContext): AuthViewer | Promise<AuthViewer>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let handlers: Map<string, AuthHandler> = new Map();
|
|
13
|
+
export async function registerAuthHandler(name: string, auth: AuthHandler) {
|
|
14
|
+
handlers.set(name, auth);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function clearAuthHandlers() {
|
|
18
|
+
handlers.clear();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function getLoggedInViewer(
|
|
22
|
+
context: RequestContext,
|
|
23
|
+
): Promise<Viewer | null> {
|
|
24
|
+
for (const [name, authHandler] of handlers) {
|
|
25
|
+
let v = await authHandler.authViewer(context);
|
|
26
|
+
if (v !== null) {
|
|
27
|
+
log(
|
|
28
|
+
"info",
|
|
29
|
+
`auth handler \`${name}\` authenticated user \`${v.viewerID}\``,
|
|
30
|
+
);
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
log("info", "no auth handler returned viewer. default to logged out viewer");
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function buildContext(
|
|
39
|
+
request: IncomingMessage,
|
|
40
|
+
response: ServerResponse,
|
|
41
|
+
): Promise<RequestContext> {
|
|
42
|
+
const ctx = new contextImpl(request, response);
|
|
43
|
+
let viewer = await getLoggedInViewer(ctx);
|
|
44
|
+
if (viewer) {
|
|
45
|
+
// TODO since this is done, whatever other call to authViewer that was needed no longer needed
|
|
46
|
+
ctx.authViewer(viewer);
|
|
47
|
+
}
|
|
48
|
+
return ctx;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class contextImpl implements RequestContext {
|
|
52
|
+
cache?: ContextCache;
|
|
53
|
+
private loggedOutViewer: LoggedOutViewer;
|
|
54
|
+
private viewer: Viewer;
|
|
55
|
+
|
|
56
|
+
constructor(
|
|
57
|
+
public request: IncomingMessage,
|
|
58
|
+
public response: ServerResponse,
|
|
59
|
+
) {
|
|
60
|
+
this.cache = new ContextCache();
|
|
61
|
+
// needs to be after this.cache above
|
|
62
|
+
this.loggedOutViewer = new LoggedOutViewer(this);
|
|
63
|
+
this.viewer = this.loggedOutViewer;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getViewer(): Viewer {
|
|
67
|
+
return this.viewer;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async authViewer(viewer: Viewer): Promise<void> {
|
|
71
|
+
this.viewer = viewer;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async logout(): Promise<void> {
|
|
75
|
+
this.viewer = this.loggedOutViewer;
|
|
76
|
+
}
|
|
77
|
+
}
|