@snowtop/ent 0.1.0-alpha160-test5 → 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 +47 -5
- 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
package/src/core/base.ts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import * as clause from "./clause";
|
|
2
|
+
import { ObjectLoaderFactory } from "./loaders";
|
|
3
|
+
import { OrderBy } from "./query_impl";
|
|
4
|
+
|
|
5
|
+
// Loader is the primitive data fetching abstraction in the framework
|
|
6
|
+
// implementation details up to each instance
|
|
7
|
+
// A DataLoader could be used internally or not.
|
|
8
|
+
// For Loaders that use DataLoader, there's batching done to fetch multiple pieces
|
|
9
|
+
// of information.
|
|
10
|
+
// Using Loader and LoaderFactory allows us to use the same instance of Loader across a
|
|
11
|
+
// request and potentially batch data as needed when possible
|
|
12
|
+
export interface Loader<K, V> {
|
|
13
|
+
context?: Context;
|
|
14
|
+
load(key: K): Promise<V>;
|
|
15
|
+
// TODO we need a loadMany() API similar to DataLoaer
|
|
16
|
+
// what's the plural api to be?
|
|
17
|
+
loadMany?(keys: K[]): Promise<(V | null)[]>;
|
|
18
|
+
clearAll(): any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LoaderWithLoadMany<T, V> extends Loader<T, V> {
|
|
22
|
+
loadMany(keys: T[]): Promise<V[]>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// A LoaderFactory is used to create a Loader
|
|
26
|
+
// We cache data on a per-request basis therefore for each new request, createLoader
|
|
27
|
+
// is called to get a new instance of Loader which will then be used to load data as needed
|
|
28
|
+
export interface LoaderFactory<K, V> {
|
|
29
|
+
name: string; // used to have a per-request cache of each loader type
|
|
30
|
+
|
|
31
|
+
// factory method.
|
|
32
|
+
// when context is passed, there's potentially opportunities to batch data in the same
|
|
33
|
+
// request
|
|
34
|
+
// when no context is passed, no batching possible (except with explicit call to loadMany API)
|
|
35
|
+
createLoader(context?: Context): Loader<K, V>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface LoaderFactoryWithLoaderMany<T, V> extends LoaderFactory<T, V> {
|
|
39
|
+
createLoader(context?: Context): LoaderWithLoadMany<T, V>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// better name for this?
|
|
43
|
+
// this is used by EntQuery and then smart decision is made of what to do
|
|
44
|
+
export interface ConfigurableLoaderFactory<T, V> extends LoaderFactory<T, V> {
|
|
45
|
+
createConfigurableLoader(
|
|
46
|
+
options: EdgeQueryableDataOptions,
|
|
47
|
+
context?: Context,
|
|
48
|
+
): Loader<T, V>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type EdgeQueryableDataOptions = Partial<
|
|
52
|
+
Pick<
|
|
53
|
+
QueryableDataOptions,
|
|
54
|
+
"limit" | "orderby" | "clause" | "disableTransformations"
|
|
55
|
+
>
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
export type EdgeQueryableDataOptionsConfigureLoader = Pick<
|
|
59
|
+
EdgeQueryableDataOptions,
|
|
60
|
+
"disableTransformations"
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
// PrimableLoader allows us to prime data in the cache that's retrieved from
|
|
64
|
+
// other sources
|
|
65
|
+
export interface PrimableLoader<K, V> extends Loader<K, V> {
|
|
66
|
+
prime(d: V): void;
|
|
67
|
+
// prime this loader and any other loader it's aware of
|
|
68
|
+
primeAll?(d: V): void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface cache {
|
|
72
|
+
getLoader<K, V>(name: string, create: () => Loader<K, V>): Loader<K, V>;
|
|
73
|
+
getLoaderWithLoadMany<K, V>(
|
|
74
|
+
name: string,
|
|
75
|
+
create: () => LoaderWithLoadMany<K, V>,
|
|
76
|
+
): LoaderWithLoadMany<K, V>;
|
|
77
|
+
getCachedRows(options: queryOptions): Data[] | null;
|
|
78
|
+
getCachedRow(options: queryOptions): Data | null;
|
|
79
|
+
primeCache(options: queryOptions, rows: Data[]): void;
|
|
80
|
+
primeCache(options: queryOptions, rows: Data): void;
|
|
81
|
+
clearCache(): void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface queryOptions {
|
|
85
|
+
fields: string[];
|
|
86
|
+
tableName: string;
|
|
87
|
+
clause: clause.Clause;
|
|
88
|
+
orderby?: OrderBy;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface Context<TViewer extends Viewer = Viewer> {
|
|
92
|
+
getViewer(): TViewer;
|
|
93
|
+
// optional per (request)contet
|
|
94
|
+
// absence means we are not doing any caching
|
|
95
|
+
// presence means we have loader, ent cache etc
|
|
96
|
+
|
|
97
|
+
// TODO expose this? use
|
|
98
|
+
cache?: cache;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface Viewer<
|
|
102
|
+
TEnt extends any = Ent<any> | null,
|
|
103
|
+
TID extends any = ID | null,
|
|
104
|
+
> {
|
|
105
|
+
viewerID: TID;
|
|
106
|
+
viewer: () => Promise<TEnt>;
|
|
107
|
+
instanceKey: () => string;
|
|
108
|
+
// isOmniscient?(): boolean; // optional function to indicate a viewer that can see anything e.g. admin
|
|
109
|
+
// TODO determine if we want this here.
|
|
110
|
+
// just helpful to have it here
|
|
111
|
+
// not providing a default AllowIfOmniRule
|
|
112
|
+
|
|
113
|
+
// where should dataloaders be put?
|
|
114
|
+
// I want dataloaders to be created on demand as needed
|
|
115
|
+
// so it seems having it in Context (per-request info makes sense)
|
|
116
|
+
// so does that mean we should pass Context all the way down and not Viewer?
|
|
117
|
+
context?: Context<any>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface Ent<TViewer extends Viewer = Viewer> {
|
|
121
|
+
id: ID;
|
|
122
|
+
viewer: TViewer;
|
|
123
|
+
getPrivacyPolicy(): PrivacyPolicy<this, TViewer>;
|
|
124
|
+
nodeType: string;
|
|
125
|
+
// used to set raw data that's then used by ent internals
|
|
126
|
+
// shouldn't be used...
|
|
127
|
+
__setRawDBData<T extends Data = Data>(data: T);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export declare type Data = {
|
|
131
|
+
[key: string]: any;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export interface EntConstructor<
|
|
135
|
+
TEnt extends Ent,
|
|
136
|
+
TViewer extends Viewer = Viewer,
|
|
137
|
+
> {
|
|
138
|
+
new (viewer: TViewer, data: Data): TEnt;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type ID = string | number;
|
|
142
|
+
|
|
143
|
+
export interface DataOptions {
|
|
144
|
+
// TODO pool or client later since we should get it from there
|
|
145
|
+
// TODO this can be passed in for scenarios where we are not using default configuration
|
|
146
|
+
// clientConfig?: ClientConfig;
|
|
147
|
+
tableName: string;
|
|
148
|
+
|
|
149
|
+
// TODO remove this from here since we're changing how this works....
|
|
150
|
+
context?: Context;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface SelectBaseDataOptions extends DataOptions {
|
|
154
|
+
// list of fields to read
|
|
155
|
+
fields: string[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
159
|
+
// primary key we're selecting from most often 'id'
|
|
160
|
+
key: string;
|
|
161
|
+
// if postgres and using an integer primary key, we need to pass this so that when we do an In query,
|
|
162
|
+
// we can cast accurately
|
|
163
|
+
// TODO https://github.com/lolopinto/ent/issues/1431
|
|
164
|
+
keyType?: string; // 'uuid' | 'integer' etc...
|
|
165
|
+
// if exists, we and with the primary key query
|
|
166
|
+
clause?: clause.Clause | (() => clause.Clause | undefined);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface QueryableDataOptions
|
|
170
|
+
extends SelectBaseDataOptions,
|
|
171
|
+
QueryDataOptions {}
|
|
172
|
+
|
|
173
|
+
export interface QueryDataOptions<T extends Data = Data, K = keyof T> {
|
|
174
|
+
distinct?: boolean;
|
|
175
|
+
clause: clause.Clause<T, K>;
|
|
176
|
+
orderby?: OrderBy; // this technically doesn't make sense when querying just one row but whatevs
|
|
177
|
+
groupby?: K;
|
|
178
|
+
limit?: number;
|
|
179
|
+
disableTransformations?: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// For loading data from database
|
|
183
|
+
export interface LoadRowOptions extends QueryableDataOptions {}
|
|
184
|
+
|
|
185
|
+
export interface LoadRowsOptions extends QueryableDataOptions {}
|
|
186
|
+
|
|
187
|
+
interface OnConflictOptions {
|
|
188
|
+
// TODO these should change to fields instead of columns
|
|
189
|
+
onConflictCols: string[];
|
|
190
|
+
|
|
191
|
+
// onConflictConstraint doesn't work with do nothing since ent always reloads the
|
|
192
|
+
// row after insert and if there's no conflict columns provided, we have no way of querying
|
|
193
|
+
// the db for the original/conflicting row
|
|
194
|
+
onConflictConstraint?: string;
|
|
195
|
+
// update values based on fields
|
|
196
|
+
// if not provided, we do nothing
|
|
197
|
+
updateCols?: string[];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface CreateRowOptions extends DataOptions {
|
|
201
|
+
// fields to be edited
|
|
202
|
+
fields: Data;
|
|
203
|
+
fieldsToLog?: Data;
|
|
204
|
+
onConflict?: OnConflictOptions;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface EditRowOptions extends Omit<CreateRowOptions, "onConflict"> {
|
|
208
|
+
whereClause: clause.Clause;
|
|
209
|
+
// if a column exists in here as opposed to in fields, we use the expression given
|
|
210
|
+
// instead of the value
|
|
211
|
+
expressions?: Map<string, clause.Clause>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interface LoadableEntOptions<
|
|
215
|
+
TEnt extends Ent,
|
|
216
|
+
TViewer extends Viewer = Viewer,
|
|
217
|
+
TData extends Data = Data,
|
|
218
|
+
> {
|
|
219
|
+
loaderFactory: ObjectLoaderFactory<TData>;
|
|
220
|
+
ent: EntConstructor<TEnt, TViewer>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface LoaderFactoryWithOptions<T extends Data = Data>
|
|
224
|
+
extends LoaderFactoryWithLoaderMany<any, T | null> {
|
|
225
|
+
options?: SelectDataOptions;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// information needed to load an ent from the databse
|
|
229
|
+
export interface LoadEntOptions<
|
|
230
|
+
TEnt extends Ent,
|
|
231
|
+
TViewer extends Viewer = Viewer,
|
|
232
|
+
TData extends Data = Data,
|
|
233
|
+
> extends LoadableEntOptions<TEnt, TViewer, TData>,
|
|
234
|
+
// extending DataOptions and fields is to make APIs like loadEntsFromClause work until we come up with a cleaner API
|
|
235
|
+
SelectBaseDataOptions {
|
|
236
|
+
// if passed in, it means there's field privacy on the ents *and* we want to apply it at ent load
|
|
237
|
+
// if there's field privacy on the ent and not passed in, it'll be applied on demand when we try and load the ent
|
|
238
|
+
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface SelectCustomDataOptions<T extends Data = Data>
|
|
242
|
+
extends SelectBaseDataOptions {
|
|
243
|
+
// main loader factory for the ent, passed in for priming the data so subsequent fetches of this id don't reload
|
|
244
|
+
loaderFactory: ObjectLoaderFactory<T>;
|
|
245
|
+
|
|
246
|
+
// should we prime the ent after loading. uses loaderFactory above
|
|
247
|
+
// only pass prime if the fields is equivalent to the ids of the other loader factory
|
|
248
|
+
// it doesn't check...
|
|
249
|
+
prime?: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface LoadCustomEntOptions<
|
|
253
|
+
TEnt extends Ent,
|
|
254
|
+
TViewer extends Viewer = Viewer,
|
|
255
|
+
TData extends Data = Data,
|
|
256
|
+
>
|
|
257
|
+
// extending DataOptions and fields is to make APIs like loadEntsFromClause work until we come up with a cleaner API
|
|
258
|
+
extends SelectCustomDataOptions<TData> {
|
|
259
|
+
ent: EntConstructor<TEnt, TViewer>;
|
|
260
|
+
fieldPrivacy?: Map<string, PrivacyPolicy>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export interface LoaderInfo<T = Data> {
|
|
264
|
+
tableName: string;
|
|
265
|
+
fields: string[];
|
|
266
|
+
nodeType: string;
|
|
267
|
+
loaderFactory: LoaderFactory<ID, T | null>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// information needed to edit an ent
|
|
271
|
+
export interface EditEntOptions<T extends Ent>
|
|
272
|
+
extends LoadableEntOptions<T>,
|
|
273
|
+
EditRowOptions {}
|
|
274
|
+
|
|
275
|
+
// Privacy
|
|
276
|
+
enum privacyResult {
|
|
277
|
+
// using http status codes similar to golang for the lols
|
|
278
|
+
Allow = 200,
|
|
279
|
+
Deny = 401,
|
|
280
|
+
Skip = 307,
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface PrivacyResult {
|
|
284
|
+
result: privacyResult;
|
|
285
|
+
error?: PrivacyError;
|
|
286
|
+
getError?(
|
|
287
|
+
policy: PrivacyPolicy,
|
|
288
|
+
rule: PrivacyPolicyRule,
|
|
289
|
+
ent?: Ent,
|
|
290
|
+
): PrivacyError;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface PrivacyError extends Error {
|
|
294
|
+
privacyPolicy: PrivacyPolicy<Ent>;
|
|
295
|
+
ent?: Ent;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const allow: PrivacyResult = {
|
|
299
|
+
result: privacyResult.Allow,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export function Allow(): PrivacyResult {
|
|
303
|
+
return allow;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const skip: PrivacyResult = {
|
|
307
|
+
result: privacyResult.Skip,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export function Skip(): PrivacyResult {
|
|
311
|
+
return skip;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const deny: PrivacyResult = {
|
|
315
|
+
result: privacyResult.Deny,
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export function Deny(): PrivacyResult {
|
|
319
|
+
return deny;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
class DenyWithReasonError extends Error implements PrivacyError {
|
|
323
|
+
privacyPolicy: PrivacyPolicy;
|
|
324
|
+
privacyRule: PrivacyPolicyRule;
|
|
325
|
+
ent?: Ent;
|
|
326
|
+
|
|
327
|
+
constructor(
|
|
328
|
+
privacyPolicy: PrivacyPolicy,
|
|
329
|
+
rule: PrivacyPolicyRule,
|
|
330
|
+
msg: string,
|
|
331
|
+
ent?: Ent,
|
|
332
|
+
) {
|
|
333
|
+
super(msg);
|
|
334
|
+
this.privacyPolicy = privacyPolicy;
|
|
335
|
+
this.privacyRule = rule;
|
|
336
|
+
this.ent = ent;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function DenyWithReason(e: PrivacyError | string): PrivacyResult {
|
|
341
|
+
if (typeof e === "string") {
|
|
342
|
+
return {
|
|
343
|
+
result: privacyResult.Deny,
|
|
344
|
+
getError(policy: PrivacyPolicy, rule: PrivacyPolicyRule, ent?: Ent) {
|
|
345
|
+
return new DenyWithReasonError(policy, rule, e, ent);
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
result: privacyResult.Deny,
|
|
351
|
+
error: e,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface PrivacyPolicyRule<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
356
|
+
apply(v: TViewer, ent?: TEnt): Promise<PrivacyResult>;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface PrivacyPolicy<TEnt extends Ent = Ent, TViewer = Viewer> {
|
|
360
|
+
rules: PrivacyPolicyRule<TEnt, TViewer>[];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export enum WriteOperation {
|
|
364
|
+
Insert = "insert",
|
|
365
|
+
Edit = "edit",
|
|
366
|
+
Delete = "delete",
|
|
367
|
+
}
|