@expo/entity 0.39.0 → 0.41.0
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/build/AuthorizationResultBasedEntityAssociationLoader.d.ts +99 -0
- package/build/AuthorizationResultBasedEntityAssociationLoader.js +122 -0
- package/build/AuthorizationResultBasedEntityAssociationLoader.js.map +1 -0
- package/build/AuthorizationResultBasedEntityLoader.d.ts +1 -1
- package/build/AuthorizationResultBasedEntityLoader.js.map +1 -1
- package/build/{EntityMutator.d.ts → AuthorizationResultBasedEntityMutator.d.ts} +5 -17
- package/build/{EntityMutator.js → AuthorizationResultBasedEntityMutator.js} +22 -48
- package/build/AuthorizationResultBasedEntityMutator.js.map +1 -0
- package/build/EnforcingEntityAssociationLoader.d.ts +79 -0
- package/build/EnforcingEntityAssociationLoader.js +62 -0
- package/build/EnforcingEntityAssociationLoader.js.map +1 -0
- package/build/EnforcingEntityCreator.d.ts +24 -0
- package/build/EnforcingEntityCreator.js +32 -0
- package/build/EnforcingEntityCreator.js.map +1 -0
- package/build/EnforcingEntityDeleter.d.ts +17 -0
- package/build/EnforcingEntityDeleter.js +22 -0
- package/build/EnforcingEntityDeleter.js.map +1 -0
- package/build/EnforcingEntityUpdater.d.ts +24 -0
- package/build/EnforcingEntityUpdater.js +32 -0
- package/build/EnforcingEntityUpdater.js.map +1 -0
- package/build/Entity.d.ts +26 -8
- package/build/Entity.js +38 -25
- package/build/Entity.js.map +1 -1
- package/build/EntityAssociationLoader.d.ts +12 -91
- package/build/EntityAssociationLoader.js +20 -126
- package/build/EntityAssociationLoader.js.map +1 -1
- package/build/EntityCreator.d.ts +27 -0
- package/build/EntityCreator.js +39 -0
- package/build/EntityCreator.js.map +1 -0
- package/build/EntityDeleter.d.ts +27 -0
- package/build/EntityDeleter.js +40 -0
- package/build/EntityDeleter.js.map +1 -0
- package/build/EntityLoader.d.ts +4 -14
- package/build/EntityLoader.js +7 -20
- package/build/EntityLoader.js.map +1 -1
- package/build/EntityLoaderFactory.d.ts +2 -2
- package/build/EntityLoaderFactory.js +4 -2
- package/build/EntityLoaderFactory.js.map +1 -1
- package/build/EntityMutatorFactory.d.ts +4 -4
- package/build/EntityMutatorFactory.js +4 -4
- package/build/EntityMutatorFactory.js.map +1 -1
- package/build/EntitySecondaryCacheLoader.d.ts +3 -3
- package/build/EntitySecondaryCacheLoader.js +1 -3
- package/build/EntitySecondaryCacheLoader.js.map +1 -1
- package/build/EntityUpdater.d.ts +27 -0
- package/build/EntityUpdater.js +40 -0
- package/build/EntityUpdater.js.map +1 -0
- package/build/ReadonlyEntity.d.ts +24 -5
- package/build/ReadonlyEntity.js +33 -7
- package/build/ReadonlyEntity.js.map +1 -1
- package/build/ViewerScopedEntityLoaderFactory.d.ts +2 -2
- package/build/ViewerScopedEntityLoaderFactory.js.map +1 -1
- package/build/ViewerScopedEntityMutatorFactory.d.ts +4 -4
- package/build/ViewerScopedEntityMutatorFactory.js.map +1 -1
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.d.ts +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js +242 -0
- package/build/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.js.map +1 -0
- package/build/__tests__/{EntityLoader-constructor-test.js → AuthorizationResultBasedEntityLoader-constructor-test.js} +10 -10
- package/build/__tests__/AuthorizationResultBasedEntityLoader-constructor-test.js.map +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.d.ts +1 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js +401 -0
- package/build/__tests__/AuthorizationResultBasedEntityLoader-test.js.map +1 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.d.ts +1 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js +115 -0
- package/build/__tests__/EnforcingEntityAssociationLoader-test.js.map +1 -0
- package/build/__tests__/Entity-test.js +63 -5
- package/build/__tests__/Entity-test.js.map +1 -1
- package/build/__tests__/EntityAssociationLoader-test.js +14 -184
- package/build/__tests__/EntityAssociationLoader-test.js.map +1 -1
- package/build/__tests__/EntityCommonUseCases-test.js +34 -20
- package/build/__tests__/EntityCommonUseCases-test.js.map +1 -1
- package/build/__tests__/EntityCompanion-test.js +17 -7
- package/build/__tests__/EntityCompanion-test.js.map +1 -1
- package/build/__tests__/EntityEdges-test.js +57 -71
- package/build/__tests__/EntityEdges-test.js.map +1 -1
- package/build/__tests__/EntityLoader-test.js +22 -386
- package/build/__tests__/EntityLoader-test.js.map +1 -1
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js +6 -9
- package/build/__tests__/EntityMutator-MutationCacheConsistency-test.js.map +1 -1
- package/build/__tests__/EntityMutator-test.js +67 -70
- package/build/__tests__/EntityMutator-test.js.map +1 -1
- package/build/__tests__/EntityPrivacyPolicy-test.js +17 -7
- package/build/__tests__/EntityPrivacyPolicy-test.js.map +1 -1
- package/build/__tests__/EntitySecondaryCacheLoader-test.js +7 -7
- package/build/__tests__/EntitySecondaryCacheLoader-test.js.map +1 -1
- package/build/__tests__/EntitySelfReferentialEdges-test.js +47 -81
- package/build/__tests__/EntitySelfReferentialEdges-test.js.map +1 -1
- package/build/__tests__/ReadonlyEntity-test.js +40 -7
- package/build/__tests__/ReadonlyEntity-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js +6 -10
- package/build/__tests__/cases/TwoEntitySameTableDisjointRows-test.js.map +1 -1
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js +10 -22
- package/build/__tests__/cases/TwoEntitySameTableOverlappingRows-test.js.map +1 -1
- package/build/errors/EntityCacheAdapterError.js +17 -7
- package/build/errors/EntityCacheAdapterError.js.map +1 -1
- package/build/errors/EntityDatabaseAdapterError.js +17 -7
- package/build/errors/EntityDatabaseAdapterError.js.map +1 -1
- package/build/errors/EntityInvalidFieldValueError.js +17 -7
- package/build/errors/EntityInvalidFieldValueError.js.map +1 -1
- package/build/errors/EntityNotAuthorizedError.js +17 -7
- package/build/errors/EntityNotAuthorizedError.js.map +1 -1
- package/build/errors/EntityNotFoundError.js +17 -7
- package/build/errors/EntityNotFoundError.js.map +1 -1
- package/build/index.d.ts +19 -11
- package/build/index.js +24 -7
- package/build/index.js.map +1 -1
- package/build/internal/__tests__/EntityDataManager-test.js +42 -32
- package/build/internal/__tests__/EntityDataManager-test.js.map +1 -1
- package/build/internal/__tests__/ReadThroughEntityCache-test.js +17 -7
- package/build/internal/__tests__/ReadThroughEntityCache-test.js.map +1 -1
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysAllowPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysDenyPrivacyPolicyRule.js.map +1 -1
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js +17 -7
- package/build/rules/AlwaysSkipPrivacyPolicyRule.js.map +1 -1
- package/build/utils/EntityPrivacyUtils.js +4 -8
- package/build/utils/EntityPrivacyUtils.js.map +1 -1
- package/build/utils/__tests__/EntityPrivacyUtils-test.js +38 -28
- package/build/utils/__tests__/EntityPrivacyUtils-test.js.map +1 -1
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js +5 -5
- package/build/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.js.map +1 -1
- package/build/utils/testing/StubDatabaseAdapter.js +17 -7
- package/build/utils/testing/StubDatabaseAdapter.js.map +1 -1
- package/build/utils/testing/StubQueryContextProvider.d.ts +1 -3
- package/build/utils/testing/StubQueryContextProvider.js +1 -3
- package/build/utils/testing/StubQueryContextProvider.js.map +1 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js +2 -1
- package/build/utils/testing/createUnitTestEntityCompanionProvider.js.map +1 -1
- package/package.json +19 -3
- package/src/AuthorizationResultBasedEntityAssociationLoader.ts +490 -0
- package/src/AuthorizationResultBasedEntityLoader.ts +1 -1
- package/src/{EntityMutator.ts → AuthorizationResultBasedEntityMutator.ts} +62 -58
- package/src/EnforcingEntityAssociationLoader.ts +390 -0
- package/src/EnforcingEntityCreator.ts +55 -0
- package/src/EnforcingEntityDeleter.ts +44 -0
- package/src/EnforcingEntityUpdater.ts +55 -0
- package/src/Entity.ts +140 -29
- package/src/EntityAssociationLoader.ts +38 -495
- package/src/EntityCreator.ts +73 -0
- package/src/EntityDeleter.ts +73 -0
- package/src/EntityLoader.ts +10 -49
- package/src/EntityLoaderFactory.ts +20 -3
- package/src/EntityMutatorFactory.ts +32 -7
- package/src/EntitySecondaryCacheLoader.ts +5 -7
- package/src/EntityUpdater.ts +73 -0
- package/src/ReadonlyEntity.ts +121 -7
- package/src/ViewerScopedEntityLoaderFactory.ts +9 -2
- package/src/ViewerScopedEntityMutatorFactory.ts +29 -4
- package/src/__tests__/AuthorizationResultBasedEntityAssociationLoader-test.ts +323 -0
- package/src/__tests__/{EntityLoader-constructor-test.ts → AuthorizationResultBasedEntityLoader-constructor-test.ts} +16 -9
- package/src/__tests__/AuthorizationResultBasedEntityLoader-test.ts +730 -0
- package/src/__tests__/EnforcingEntityAssociationLoader-test.ts +253 -0
- package/src/__tests__/Entity-test.ts +77 -5
- package/src/__tests__/EntityAssociationLoader-test.ts +15 -260
- package/src/__tests__/EntityCommonUseCases-test.ts +24 -15
- package/src/__tests__/EntityEdges-test.ts +44 -64
- package/src/__tests__/EntityLoader-test.ts +29 -681
- package/src/__tests__/EntityMutator-MutationCacheConsistency-test.ts +8 -9
- package/src/__tests__/EntityMutator-test.ts +116 -103
- package/src/__tests__/EntitySecondaryCacheLoader-test.ts +7 -7
- package/src/__tests__/EntitySelfReferentialEdges-test.ts +65 -81
- package/src/__tests__/ReadonlyEntity-test.ts +47 -7
- package/src/__tests__/cases/TwoEntitySameTableDisjointRows-test.ts +15 -15
- package/src/__tests__/cases/TwoEntitySameTableOverlappingRows-test.ts +19 -22
- package/src/index.ts +19 -11
- package/src/internal/__tests__/EntityDataManager-test.ts +25 -25
- package/src/utils/EntityPrivacyUtils.ts +10 -13
- package/src/utils/__tests__/EntityPrivacyUtils-test.ts +21 -23
- package/src/utils/__tests__/canViewerDeleteAsync-edgeDeletionPermissionInferenceBehavior-test.ts +5 -5
- package/src/utils/testing/StubQueryContextProvider.ts +1 -3
- package/src/utils/testing/createUnitTestEntityCompanionProvider.ts +3 -1
- package/build/EntityMutator.js.map +0 -1
- package/build/__tests__/EntityLoader-constructor-test.js.map +0 -1
- /package/build/__tests__/{EntityLoader-constructor-test.d.ts → AuthorizationResultBasedEntityLoader-constructor-test.d.ts} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import AuthorizationResultBasedEntityAssociationLoader, { EntityLoadThroughDirective } from './AuthorizationResultBasedEntityAssociationLoader';
|
|
2
|
+
import { IEntityClass } from './Entity';
|
|
3
|
+
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
4
|
+
import ReadonlyEntity from './ReadonlyEntity';
|
|
5
|
+
import ViewerContext from './ViewerContext';
|
|
6
|
+
/**
|
|
7
|
+
* An association loader is a set of convenience methods for loading entities
|
|
8
|
+
* associated with an entity. In relational databases, these entities are often referenced
|
|
9
|
+
* by foreign keys.
|
|
10
|
+
*/
|
|
11
|
+
export default class EnforcingEntityAssociationLoader<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
12
|
+
private readonly authorizationResultBasedEntityAssociationLoader;
|
|
13
|
+
constructor(authorizationResultBasedEntityAssociationLoader: AuthorizationResultBasedEntityAssociationLoader<TFields, TID, TViewerContext, TEntity, TSelectedFields>);
|
|
14
|
+
/**
|
|
15
|
+
* Load an associated entity identified by a field value of this entity. In a relational database,
|
|
16
|
+
* the field in this entity is a foreign key to the ID of the associated entity.
|
|
17
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the ID of the associated entity
|
|
18
|
+
* @param associatedEntityClass - class of the associated entity
|
|
19
|
+
*/
|
|
20
|
+
loadAssociatedEntityAsync<TIdentifyingField extends keyof Pick<TFields, TSelectedFields>, TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: TIdentifyingField, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>): Promise<null extends TFields[TIdentifyingField] ? TAssociatedEntity | null : TAssociatedEntity>;
|
|
21
|
+
/**
|
|
22
|
+
* Load many entities associated with this entity, often referred to as entites belonging
|
|
23
|
+
* to this entity. In a relational database, the field in the foreign entity is a
|
|
24
|
+
* foreign key to the ID of this entity. Also commonly referred to as a has many relationship,
|
|
25
|
+
* where this entity has many associated entities.
|
|
26
|
+
* @param associatedEntityClass - class of the associated entities
|
|
27
|
+
* @param associatedEntityFieldContainingThisID - field of associated entity which contains the ID of this entity
|
|
28
|
+
*/
|
|
29
|
+
loadManyAssociatedEntitiesAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityFieldContainingThisID: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>): Promise<readonly TAssociatedEntity[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Load an associated entity identified by a field value of this entity. In a relational database,
|
|
32
|
+
* the field in this entity is a foreign key to a unique field of the associated entity.
|
|
33
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entity
|
|
34
|
+
* @param associatedEntityClass - class of the associated entity
|
|
35
|
+
* @param associatedEntityLookupByField - field of associated entity with which to look up the associated entity
|
|
36
|
+
*/
|
|
37
|
+
loadAssociatedEntityByFieldEqualingAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>): Promise<TAssociatedEntity | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Load many associated entities identified by a field value of this entity. In a relational database,
|
|
40
|
+
* the field in this entity refers to a field of the associated entity.
|
|
41
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entities
|
|
42
|
+
* @param associatedEntityClass - class of the associated entities
|
|
43
|
+
* @param associatedEntityLookupByField - field of associated entities with which to look up the associated entities
|
|
44
|
+
*/
|
|
45
|
+
loadManyAssociatedEntitiesByFieldEqualingAsync<TAssociatedFields extends object, TAssociatedID extends NonNullable<TAssociatedFields[TAssociatedSelectedFields]>, TAssociatedEntity extends ReadonlyEntity<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedSelectedFields>, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedSelectedFields>, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick<TFields, TSelectedFields>, associatedEntityClass: IEntityClass<TAssociatedFields, TAssociatedID, TViewerContext, TAssociatedEntity, TAssociatedPrivacyPolicy, TAssociatedSelectedFields>, associatedEntityLookupByField: keyof Pick<TAssociatedFields, TAssociatedSelectedFields>): Promise<readonly TAssociatedEntity[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each
|
|
48
|
+
* fold step, load an associated entity identified by a field value of the current fold value.
|
|
49
|
+
* @param loadDirectives - associated entity load directives instructing each step of the folds
|
|
50
|
+
*/
|
|
51
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TSelectedFields2 extends keyof TFields2 = keyof TFields2>(loadDirectives: [
|
|
52
|
+
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>
|
|
53
|
+
]): Promise<TEntity2 | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each
|
|
56
|
+
* fold step, load an associated entity identified by a field value of the current fold value.
|
|
57
|
+
* @param loadDirectives - associated entity load directives instructing each step of the folds
|
|
58
|
+
*/
|
|
59
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3 extends object, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3>(loadDirectives: [
|
|
60
|
+
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>,
|
|
61
|
+
EntityLoadThroughDirective<TViewerContext, TFields2, TFields3, TID3, TEntity3, TPrivacyPolicy3, TSelectedFields2, TSelectedFields3>
|
|
62
|
+
]): Promise<TEntity3 | null>;
|
|
63
|
+
/**
|
|
64
|
+
* Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each
|
|
65
|
+
* fold step, load an associated entity identified by a field value of the current fold value.
|
|
66
|
+
* @param loadDirectives - associated entity load directives instructing each step of the folds
|
|
67
|
+
*/
|
|
68
|
+
loadAssociatedEntityThroughAsync<TFields2 extends object, TID2 extends NonNullable<TFields2[TSelectedFields2]>, TEntity2 extends ReadonlyEntity<TFields2, TID2, TViewerContext, TSelectedFields2>, TPrivacyPolicy2 extends EntityPrivacyPolicy<TFields2, TID2, TViewerContext, TEntity2, TSelectedFields2>, TFields3 extends object, TID3 extends NonNullable<TFields3[TSelectedFields3]>, TEntity3 extends ReadonlyEntity<TFields3, TID3, TViewerContext, TSelectedFields3>, TPrivacyPolicy3 extends EntityPrivacyPolicy<TFields3, TID3, TViewerContext, TEntity3, TSelectedFields3>, TFields4 extends object, TID4 extends NonNullable<TFields4[TSelectedFields4]>, TEntity4 extends ReadonlyEntity<TFields4, TID4, TViewerContext, TSelectedFields4>, TPrivacyPolicy4 extends EntityPrivacyPolicy<TFields4, TID4, TViewerContext, TEntity4, TSelectedFields4>, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3, TSelectedFields4 extends keyof TFields4 = keyof TFields4>(loadDirectives: [
|
|
69
|
+
EntityLoadThroughDirective<TViewerContext, TFields, TFields2, TID2, TEntity2, TPrivacyPolicy2, TSelectedFields, TSelectedFields2>,
|
|
70
|
+
EntityLoadThroughDirective<TViewerContext, TFields2, TFields3, TID3, TEntity3, TPrivacyPolicy3, TSelectedFields2, TSelectedFields3>,
|
|
71
|
+
EntityLoadThroughDirective<TViewerContext, TFields3, TFields4, TID4, TEntity4, TPrivacyPolicy4, TSelectedFields3, TSelectedFields4>
|
|
72
|
+
]): Promise<TEntity4 | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each
|
|
75
|
+
* fold step, load an associated entity identified by a field value of the current fold value.
|
|
76
|
+
* @param loadDirectives - associated entity load directives instructing each step of the folds
|
|
77
|
+
*/
|
|
78
|
+
loadAssociatedEntityThroughAsync(loadDirectives: EntityLoadThroughDirective<TViewerContext, any, any, any, any, any, any, any>[]): Promise<ReadonlyEntity<any, any, any, any> | null>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const results_1 = require("@expo/results");
|
|
4
|
+
const entityUtils_1 = require("./entityUtils");
|
|
5
|
+
/**
|
|
6
|
+
* An association loader is a set of convenience methods for loading entities
|
|
7
|
+
* associated with an entity. In relational databases, these entities are often referenced
|
|
8
|
+
* by foreign keys.
|
|
9
|
+
*/
|
|
10
|
+
class EnforcingEntityAssociationLoader {
|
|
11
|
+
authorizationResultBasedEntityAssociationLoader;
|
|
12
|
+
constructor(authorizationResultBasedEntityAssociationLoader) {
|
|
13
|
+
this.authorizationResultBasedEntityAssociationLoader = authorizationResultBasedEntityAssociationLoader;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Load an associated entity identified by a field value of this entity. In a relational database,
|
|
17
|
+
* the field in this entity is a foreign key to the ID of the associated entity.
|
|
18
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the ID of the associated entity
|
|
19
|
+
* @param associatedEntityClass - class of the associated entity
|
|
20
|
+
*/
|
|
21
|
+
async loadAssociatedEntityAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass) {
|
|
22
|
+
return await (0, results_1.enforceAsyncResult)(this.authorizationResultBasedEntityAssociationLoader.loadAssociatedEntityAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load many entities associated with this entity, often referred to as entites belonging
|
|
26
|
+
* to this entity. In a relational database, the field in the foreign entity is a
|
|
27
|
+
* foreign key to the ID of this entity. Also commonly referred to as a has many relationship,
|
|
28
|
+
* where this entity has many associated entities.
|
|
29
|
+
* @param associatedEntityClass - class of the associated entities
|
|
30
|
+
* @param associatedEntityFieldContainingThisID - field of associated entity which contains the ID of this entity
|
|
31
|
+
*/
|
|
32
|
+
async loadManyAssociatedEntitiesAsync(associatedEntityClass, associatedEntityFieldContainingThisID) {
|
|
33
|
+
return await (0, entityUtils_1.enforceResultsAsync)(this.authorizationResultBasedEntityAssociationLoader.loadManyAssociatedEntitiesAsync(associatedEntityClass, associatedEntityFieldContainingThisID));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load an associated entity identified by a field value of this entity. In a relational database,
|
|
37
|
+
* the field in this entity is a foreign key to a unique field of the associated entity.
|
|
38
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entity
|
|
39
|
+
* @param associatedEntityClass - class of the associated entity
|
|
40
|
+
* @param associatedEntityLookupByField - field of associated entity with which to look up the associated entity
|
|
41
|
+
*/
|
|
42
|
+
async loadAssociatedEntityByFieldEqualingAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass, associatedEntityLookupByField) {
|
|
43
|
+
const result = await this.authorizationResultBasedEntityAssociationLoader.loadAssociatedEntityByFieldEqualingAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass, associatedEntityLookupByField);
|
|
44
|
+
return result?.enforceValue() ?? null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Load many associated entities identified by a field value of this entity. In a relational database,
|
|
48
|
+
* the field in this entity refers to a field of the associated entity.
|
|
49
|
+
* @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entities
|
|
50
|
+
* @param associatedEntityClass - class of the associated entities
|
|
51
|
+
* @param associatedEntityLookupByField - field of associated entities with which to look up the associated entities
|
|
52
|
+
*/
|
|
53
|
+
async loadManyAssociatedEntitiesByFieldEqualingAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass, associatedEntityLookupByField) {
|
|
54
|
+
return await (0, entityUtils_1.enforceResultsAsync)(this.authorizationResultBasedEntityAssociationLoader.loadManyAssociatedEntitiesByFieldEqualingAsync(fieldIdentifyingAssociatedEntity, associatedEntityClass, associatedEntityLookupByField));
|
|
55
|
+
}
|
|
56
|
+
async loadAssociatedEntityThroughAsync(loadDirectives) {
|
|
57
|
+
const result = await this.authorizationResultBasedEntityAssociationLoader.loadAssociatedEntityThroughAsync(loadDirectives);
|
|
58
|
+
return result?.enforceValue() ?? null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.default = EnforcingEntityAssociationLoader;
|
|
62
|
+
//# sourceMappingURL=EnforcingEntityAssociationLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnforcingEntityAssociationLoader.js","sourceRoot":"","sources":["../src/EnforcingEntityAssociationLoader.ts"],"names":[],"mappings":";;AAAA,2CAAmD;AASnD,+CAAoD;AAEpD;;;;GAIG;AACH,MAAqB,gCAAgC;IAQhC;IADnB,YACmB,+CAMhB;QANgB,oDAA+C,GAA/C,+CAA+C,CAM/D;IACA,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,yBAAyB,CAmB7B,gCAAmD,EACnD,qBAOC;QAID,OAAO,MAAM,IAAA,4BAAkB,EAC7B,IAAI,CAAC,+CAA+C,CAAC,yBAAyB,CAC5E,gCAAgC,EAChC,qBAAqB,CACtB,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,+BAA+B,CAkBnC,qBAOC,EACD,qCAA+F;QAE/F,OAAO,MAAM,IAAA,iCAAmB,EAC9B,IAAI,CAAC,+CAA+C,CAAC,+BAA+B,CAClF,qBAAqB,EACrB,qCAAqC,CACtC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,wCAAwC,CAkB5C,gCAAsE,EACtE,qBAOC,EACD,6BAAuF;QAEvF,MAAM,MAAM,GACV,MAAM,IAAI,CAAC,+CAA+C,CAAC,wCAAwC,CACjG,gCAAgC,EAChC,qBAAqB,EACrB,6BAA6B,CAC9B,CAAC;QACJ,OAAO,MAAM,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,8CAA8C,CAkBlD,gCAAsE,EACtE,qBAOC,EACD,6BAAuF;QAEvF,OAAO,MAAM,IAAA,iCAAmB,EAC9B,IAAI,CAAC,+CAA+C,CAAC,8CAA8C,CACjG,gCAAgC,EAChC,qBAAqB,EACrB,6BAA6B,CAC9B,CACF,CAAC;IACJ,CAAC;IA0KD,KAAK,CAAC,gCAAgC,CACpC,cAA+F;QAE/F,MAAM,MAAM,GACV,MAAM,IAAI,CAAC,+CAA+C,CAAC,gCAAgC,CACzF,cAAc,CACf,CAAC;QACJ,OAAO,MAAM,EAAE,YAAY,EAAE,IAAI,IAAI,CAAC;IACxC,CAAC;CACF;AArXD,mDAqXC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthorizationResultBasedCreateMutator } from './AuthorizationResultBasedEntityMutator';
|
|
2
|
+
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
3
|
+
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
|
+
import ViewerContext from './ViewerContext';
|
|
5
|
+
/**
|
|
6
|
+
* Enforcing entity creator. All updates
|
|
7
|
+
* through this creator will throw if authorization is not successful.
|
|
8
|
+
*/
|
|
9
|
+
export default class EnforcingEntityCreator<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
10
|
+
private readonly entityCreator;
|
|
11
|
+
constructor(entityCreator: AuthorizationResultBasedCreateMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>);
|
|
12
|
+
/**
|
|
13
|
+
* Set the value for entity field.
|
|
14
|
+
* @param fieldName - entity field being updated
|
|
15
|
+
* @param value - value for entity field
|
|
16
|
+
*/
|
|
17
|
+
setField<K extends keyof Pick<TFields, TSelectedFields>>(fieldName: K, value: TFields[K]): this;
|
|
18
|
+
/**
|
|
19
|
+
* Commit the new entity after authorizing against creation privacy rules. Invalidates all caches for
|
|
20
|
+
* queries that would return new entity.
|
|
21
|
+
* @returns authorized, cached, newly-created entity, throwing if unsuccessful
|
|
22
|
+
*/
|
|
23
|
+
createAsync(): Promise<TEntity>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const results_1 = require("@expo/results");
|
|
4
|
+
/**
|
|
5
|
+
* Enforcing entity creator. All updates
|
|
6
|
+
* through this creator will throw if authorization is not successful.
|
|
7
|
+
*/
|
|
8
|
+
class EnforcingEntityCreator {
|
|
9
|
+
entityCreator;
|
|
10
|
+
constructor(entityCreator) {
|
|
11
|
+
this.entityCreator = entityCreator;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set the value for entity field.
|
|
15
|
+
* @param fieldName - entity field being updated
|
|
16
|
+
* @param value - value for entity field
|
|
17
|
+
*/
|
|
18
|
+
setField(fieldName, value) {
|
|
19
|
+
this.entityCreator.setField(fieldName, value);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Commit the new entity after authorizing against creation privacy rules. Invalidates all caches for
|
|
24
|
+
* queries that would return new entity.
|
|
25
|
+
* @returns authorized, cached, newly-created entity, throwing if unsuccessful
|
|
26
|
+
*/
|
|
27
|
+
async createAsync() {
|
|
28
|
+
return await (0, results_1.enforceAsyncResult)(this.entityCreator.createAsync());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = EnforcingEntityCreator;
|
|
32
|
+
//# sourceMappingURL=EnforcingEntityCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnforcingEntityCreator.js","sourceRoot":"","sources":["../src/EnforcingEntityCreator.ts"],"names":[],"mappings":";;AAAA,2CAAmD;AAOnD;;;GAGG;AACH,MAAqB,sBAAsB;IAetB;IADnB,YACmB,aAOhB;QAPgB,kBAAa,GAAb,aAAa,CAO7B;IACA,CAAC;IAEJ;;;;OAIG;IACH,QAAQ,CAAiD,SAAY,EAAE,KAAiB;QACtF,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,MAAM,IAAA,4BAAkB,EAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IACpE,CAAC;CACF;AA3CD,yCA2CC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthorizationResultBasedDeleteMutator } from './AuthorizationResultBasedEntityMutator';
|
|
2
|
+
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
3
|
+
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
|
+
import ViewerContext from './ViewerContext';
|
|
5
|
+
/**
|
|
6
|
+
* Enforcing entity deleter. All deletes
|
|
7
|
+
* through this deleter will throw if authorization is not successful.
|
|
8
|
+
*/
|
|
9
|
+
export default class EnforcingEntityDeleter<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
10
|
+
private readonly entityDeleter;
|
|
11
|
+
constructor(entityDeleter: AuthorizationResultBasedDeleteMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>);
|
|
12
|
+
/**
|
|
13
|
+
* Delete the entity after authorizing against delete privacy rules. The entity is invalidated in all caches.
|
|
14
|
+
* Throws when delete is not successful.
|
|
15
|
+
*/
|
|
16
|
+
deleteAsync(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const results_1 = require("@expo/results");
|
|
4
|
+
/**
|
|
5
|
+
* Enforcing entity deleter. All deletes
|
|
6
|
+
* through this deleter will throw if authorization is not successful.
|
|
7
|
+
*/
|
|
8
|
+
class EnforcingEntityDeleter {
|
|
9
|
+
entityDeleter;
|
|
10
|
+
constructor(entityDeleter) {
|
|
11
|
+
this.entityDeleter = entityDeleter;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Delete the entity after authorizing against delete privacy rules. The entity is invalidated in all caches.
|
|
15
|
+
* Throws when delete is not successful.
|
|
16
|
+
*/
|
|
17
|
+
async deleteAsync() {
|
|
18
|
+
await (0, results_1.enforceAsyncResult)(this.entityDeleter.deleteAsync());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = EnforcingEntityDeleter;
|
|
22
|
+
//# sourceMappingURL=EnforcingEntityDeleter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnforcingEntityDeleter.js","sourceRoot":"","sources":["../src/EnforcingEntityDeleter.ts"],"names":[],"mappings":";;AAAA,2CAAmD;AAOnD;;;GAGG;AACH,MAAqB,sBAAsB;IAetB;IADnB,YACmB,aAOhB;QAPgB,kBAAa,GAAb,aAAa,CAO7B;IACA,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,IAAA,4BAAkB,EAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF;AAhCD,yCAgCC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AuthorizationResultBasedUpdateMutator } from './AuthorizationResultBasedEntityMutator';
|
|
2
|
+
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
3
|
+
import ReadonlyEntity from './ReadonlyEntity';
|
|
4
|
+
import ViewerContext from './ViewerContext';
|
|
5
|
+
/**
|
|
6
|
+
* Enforcing entity updater. All updates
|
|
7
|
+
* through this updater will throw if authorization is not successful.
|
|
8
|
+
*/
|
|
9
|
+
export default class EnforcingEntityUpdater<TFields extends object, TID extends NonNullable<TFields[TSelectedFields]>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>, TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>, TSelectedFields extends keyof TFields> {
|
|
10
|
+
private readonly entityUpdater;
|
|
11
|
+
constructor(entityUpdater: AuthorizationResultBasedUpdateMutator<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>);
|
|
12
|
+
/**
|
|
13
|
+
* Set the value for entity field.
|
|
14
|
+
* @param fieldName - entity field being updated
|
|
15
|
+
* @param value - value for entity field
|
|
16
|
+
*/
|
|
17
|
+
setField<K extends keyof Pick<TFields, TSelectedFields>>(fieldName: K, value: TFields[K]): this;
|
|
18
|
+
/**
|
|
19
|
+
* Commit the changes to the entity after authorizing against update privacy rules.
|
|
20
|
+
* Invalidates all caches for pre-update entity.
|
|
21
|
+
* @returns authorized updated entity, throws upon update failure
|
|
22
|
+
*/
|
|
23
|
+
updateAsync(): Promise<TEntity>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const results_1 = require("@expo/results");
|
|
4
|
+
/**
|
|
5
|
+
* Enforcing entity updater. All updates
|
|
6
|
+
* through this updater will throw if authorization is not successful.
|
|
7
|
+
*/
|
|
8
|
+
class EnforcingEntityUpdater {
|
|
9
|
+
entityUpdater;
|
|
10
|
+
constructor(entityUpdater) {
|
|
11
|
+
this.entityUpdater = entityUpdater;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set the value for entity field.
|
|
15
|
+
* @param fieldName - entity field being updated
|
|
16
|
+
* @param value - value for entity field
|
|
17
|
+
*/
|
|
18
|
+
setField(fieldName, value) {
|
|
19
|
+
this.entityUpdater.setField(fieldName, value);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Commit the changes to the entity after authorizing against update privacy rules.
|
|
24
|
+
* Invalidates all caches for pre-update entity.
|
|
25
|
+
* @returns authorized updated entity, throws upon update failure
|
|
26
|
+
*/
|
|
27
|
+
async updateAsync() {
|
|
28
|
+
return await (0, results_1.enforceAsyncResult)(this.entityUpdater.updateAsync());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = EnforcingEntityUpdater;
|
|
32
|
+
//# sourceMappingURL=EnforcingEntityUpdater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnforcingEntityUpdater.js","sourceRoot":"","sources":["../src/EnforcingEntityUpdater.ts"],"names":[],"mappings":";;AAAA,2CAAmD;AAOnD;;;GAGG;AACH,MAAqB,sBAAsB;IAetB;IADnB,YACmB,aAOhB;QAPgB,kBAAa,GAAb,aAAa,CAO7B;IACA,CAAC;IAEJ;;;;OAIG;IACH,QAAQ,CAAiD,SAAY,EAAE,KAAiB;QACtF,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,MAAM,IAAA,4BAAkB,EAAC,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IACpE,CAAC;CACF;AA3CD,yCA2CC"}
|
package/build/Entity.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthorizationResultBasedCreateMutator, AuthorizationResultBasedDeleteMutator, AuthorizationResultBasedUpdateMutator } from './AuthorizationResultBasedEntityMutator';
|
|
2
|
+
import EnforcingEntityCreator from './EnforcingEntityCreator';
|
|
3
|
+
import EnforcingEntityDeleter from './EnforcingEntityDeleter';
|
|
4
|
+
import EnforcingEntityUpdater from './EnforcingEntityUpdater';
|
|
2
5
|
import { EntityCompanionDefinition } from './EntityCompanionProvider';
|
|
3
|
-
import { CreateMutator, UpdateMutator } from './EntityMutator';
|
|
4
6
|
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
|
5
7
|
import { EntityQueryContext } from './EntityQueryContext';
|
|
6
8
|
import ReadonlyEntity from './ReadonlyEntity';
|
|
@@ -30,26 +32,42 @@ export default abstract class Entity<TFields extends object, TID extends NonNull
|
|
|
30
32
|
* @param queryContext - query context in which to perform the create
|
|
31
33
|
* @returns mutator for creating an entity
|
|
32
34
|
*/
|
|
33
|
-
static creator<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMViewerContext2 extends TMViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, viewerContext: TMViewerContext2, queryContext?: EntityQueryContext):
|
|
35
|
+
static creator<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMViewerContext2 extends TMViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, viewerContext: TMViewerContext2, queryContext?: EntityQueryContext): EnforcingEntityCreator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
36
|
+
/**
|
|
37
|
+
* Vend mutator for creating a new entity in given query context.
|
|
38
|
+
* @param viewerContext - viewer context of creating user
|
|
39
|
+
* @param queryContext - query context in which to perform the create
|
|
40
|
+
* @returns mutator for creating an entity
|
|
41
|
+
*/
|
|
42
|
+
static creatorWithAuthorizationResults<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMViewerContext2 extends TMViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, viewerContext: TMViewerContext2, queryContext?: EntityQueryContext): AuthorizationResultBasedCreateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
43
|
+
/**
|
|
44
|
+
* Vend mutator for updating an existing entity in given query context.
|
|
45
|
+
* @param existingEntity - entity to update
|
|
46
|
+
* @param queryContext - query context in which to perform the update
|
|
47
|
+
* @returns mutator for updating existingEntity
|
|
48
|
+
*/
|
|
49
|
+
static updater<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): EnforcingEntityUpdater<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
34
50
|
/**
|
|
35
51
|
* Vend mutator for updating an existing entity in given query context.
|
|
36
52
|
* @param existingEntity - entity to update
|
|
37
53
|
* @param queryContext - query context in which to perform the update
|
|
38
54
|
* @returns mutator for updating existingEntity
|
|
39
55
|
*/
|
|
40
|
-
static
|
|
56
|
+
static updaterWithAuthorizationResults<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): AuthorizationResultBasedUpdateMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
41
57
|
/**
|
|
42
|
-
*
|
|
58
|
+
* Vend mutator for deleting an existing entity in given query context.
|
|
43
59
|
* @param existingEntity - entity to delete
|
|
44
60
|
* @param queryContext - query context in which to perform the delete
|
|
61
|
+
* @returns mutator for deleting existingEntity
|
|
45
62
|
*/
|
|
46
|
-
static
|
|
63
|
+
static deleter<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): EnforcingEntityDeleter<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
47
64
|
/**
|
|
48
|
-
*
|
|
65
|
+
* Vend mutator for deleting an existing entity in given query context.
|
|
49
66
|
* @param existingEntity - entity to delete
|
|
50
67
|
* @param queryContext - query context in which to perform the delete
|
|
68
|
+
* @returns mutator for deleting existingEntity
|
|
51
69
|
*/
|
|
52
|
-
static
|
|
70
|
+
static deleterWithAuthorizationResults<TMFields extends object, TMID extends NonNullable<TMFields[TMSelectedFields]>, TMViewerContext extends ViewerContext, TMEntity extends Entity<TMFields, TMID, TMViewerContext, TMSelectedFields>, TMPrivacyPolicy extends EntityPrivacyPolicy<TMFields, TMID, TMViewerContext, TMEntity, TMSelectedFields>, TMSelectedFields extends keyof TMFields = keyof TMFields>(this: IEntityClass<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>, existingEntity: TMEntity, queryContext?: EntityQueryContext): AuthorizationResultBasedDeleteMutator<TMFields, TMID, TMViewerContext, TMEntity, TMPrivacyPolicy, TMSelectedFields>;
|
|
53
71
|
}
|
|
54
72
|
/**
|
|
55
73
|
* An interface to pass in constructor (class) of an Entity as a function argument.
|
package/build/Entity.js
CHANGED
|
@@ -3,6 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const EntityCreator_1 = __importDefault(require("./EntityCreator"));
|
|
7
|
+
const EntityDeleter_1 = __importDefault(require("./EntityDeleter"));
|
|
8
|
+
const EntityUpdater_1 = __importDefault(require("./EntityUpdater"));
|
|
6
9
|
const ReadonlyEntity_1 = __importDefault(require("./ReadonlyEntity"));
|
|
7
10
|
/**
|
|
8
11
|
* Entity is a privacy-first data model.
|
|
@@ -33,10 +36,19 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
33
36
|
.getViewerScopedEntityCompanionForClass(this)
|
|
34
37
|
.getQueryContextProvider()
|
|
35
38
|
.getQueryContext()) {
|
|
36
|
-
return viewerContext
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
return new EntityCreator_1.default(viewerContext, queryContext, this).enforcing();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Vend mutator for creating a new entity in given query context.
|
|
43
|
+
* @param viewerContext - viewer context of creating user
|
|
44
|
+
* @param queryContext - query context in which to perform the create
|
|
45
|
+
* @returns mutator for creating an entity
|
|
46
|
+
*/
|
|
47
|
+
static creatorWithAuthorizationResults(viewerContext, queryContext = viewerContext
|
|
48
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
49
|
+
.getQueryContextProvider()
|
|
50
|
+
.getQueryContext()) {
|
|
51
|
+
return new EntityCreator_1.default(viewerContext, queryContext, this).withAuthorizationResults();
|
|
40
52
|
}
|
|
41
53
|
/**
|
|
42
54
|
* Vend mutator for updating an existing entity in given query context.
|
|
@@ -49,45 +61,46 @@ class Entity extends ReadonlyEntity_1.default {
|
|
|
49
61
|
.getViewerScopedEntityCompanionForClass(this)
|
|
50
62
|
.getQueryContextProvider()
|
|
51
63
|
.getQueryContext()) {
|
|
52
|
-
return existingEntity
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
return new EntityUpdater_1.default(existingEntity, queryContext, this).enforcing();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Vend mutator for updating an existing entity in given query context.
|
|
68
|
+
* @param existingEntity - entity to update
|
|
69
|
+
* @param queryContext - query context in which to perform the update
|
|
70
|
+
* @returns mutator for updating existingEntity
|
|
71
|
+
*/
|
|
72
|
+
static updaterWithAuthorizationResults(existingEntity, queryContext = existingEntity
|
|
73
|
+
.getViewerContext()
|
|
74
|
+
.getViewerScopedEntityCompanionForClass(this)
|
|
75
|
+
.getQueryContextProvider()
|
|
76
|
+
.getQueryContext()) {
|
|
77
|
+
return new EntityUpdater_1.default(existingEntity, queryContext, this).withAuthorizationResults();
|
|
57
78
|
}
|
|
58
79
|
/**
|
|
59
|
-
*
|
|
80
|
+
* Vend mutator for deleting an existing entity in given query context.
|
|
60
81
|
* @param existingEntity - entity to delete
|
|
61
82
|
* @param queryContext - query context in which to perform the delete
|
|
83
|
+
* @returns mutator for deleting existingEntity
|
|
62
84
|
*/
|
|
63
|
-
static
|
|
85
|
+
static deleter(existingEntity, queryContext = existingEntity
|
|
64
86
|
.getViewerContext()
|
|
65
87
|
.getViewerScopedEntityCompanionForClass(this)
|
|
66
88
|
.getQueryContextProvider()
|
|
67
89
|
.getQueryContext()) {
|
|
68
|
-
return existingEntity
|
|
69
|
-
.getViewerContext()
|
|
70
|
-
.getViewerScopedEntityCompanionForClass(this)
|
|
71
|
-
.getMutatorFactory()
|
|
72
|
-
.forDelete(existingEntity, queryContext)
|
|
73
|
-
.deleteAsync();
|
|
90
|
+
return new EntityDeleter_1.default(existingEntity, queryContext, this).enforcing();
|
|
74
91
|
}
|
|
75
92
|
/**
|
|
76
|
-
*
|
|
93
|
+
* Vend mutator for deleting an existing entity in given query context.
|
|
77
94
|
* @param existingEntity - entity to delete
|
|
78
95
|
* @param queryContext - query context in which to perform the delete
|
|
96
|
+
* @returns mutator for deleting existingEntity
|
|
79
97
|
*/
|
|
80
|
-
static
|
|
98
|
+
static deleterWithAuthorizationResults(existingEntity, queryContext = existingEntity
|
|
81
99
|
.getViewerContext()
|
|
82
100
|
.getViewerScopedEntityCompanionForClass(this)
|
|
83
101
|
.getQueryContextProvider()
|
|
84
102
|
.getQueryContext()) {
|
|
85
|
-
return existingEntity
|
|
86
|
-
.getViewerContext()
|
|
87
|
-
.getViewerScopedEntityCompanionForClass(this)
|
|
88
|
-
.getMutatorFactory()
|
|
89
|
-
.forDelete(existingEntity, queryContext)
|
|
90
|
-
.enforceDeleteAsync();
|
|
103
|
+
return new EntityDeleter_1.default(existingEntity, queryContext, this).withAuthorizationResults();
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
exports.default = Entity;
|
package/build/Entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"Entity.js","sourceRoot":"","sources":["../src/Entity.ts"],"names":[],"mappings":";;;;;AASA,oEAA4C;AAC5C,oEAA4C;AAG5C,oEAA4C;AAC5C,sEAA8C;AAG9C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAA8B,MAK5B,SAAQ,wBAA6D;IACrE;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAuBZ,aAA+B,EAC/B,eAAmC,aAAa;SAC7C,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC1E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,+BAA+B,CAuBpC,aAA+B,EAC/B,eAAmC,aAAa;SAC7C,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,aAAa,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IACzF,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAsBZ,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,+BAA+B,CAsBpC,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC1F,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAsBZ,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3E,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,+BAA+B,CAsBpC,cAAwB,EACxB,eAAmC,cAAc;SAC9C,gBAAgB,EAAE;SAClB,sCAAsC,CAAC,IAAI,CAAC;SAC5C,uBAAuB,EAAE;SACzB,eAAe,EAAE;QASpB,OAAO,IAAI,uBAAa,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,wBAAwB,EAAE,CAAC;IAC1F,CAAC;CACF;AAnRD,yBAmRC"}
|