-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: associated, connected and unconnected queries and functions
- Loading branch information
Showing
32 changed files
with
959 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from "./addAssociation"; | ||
export * from "./getAssociatedQuery"; | ||
export * from "./listAssociations"; | ||
export * from "./removeAssociation"; | ||
export * from "./types"; |
30 changes: 30 additions & 0 deletions
30
packages/common/src/associations/internal/getTypeByIdsQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getEntityTypeFromType } from "../../search/_internal/getEntityTypeFromType"; | ||
import { IQuery } from "../../search/types/IHubCatalog"; | ||
|
||
/** | ||
* Get a query that can be used in a Gallery, and will return the associated | ||
* entities, based on the AssociationType | ||
* | ||
* @param entity | ||
* @param type | ||
* @returns | ||
*/ | ||
export function getTypeByIdsQuery(itemType: string, ids: string[]): IQuery { | ||
const targetEntity = getEntityTypeFromType(itemType); | ||
|
||
const qry: IQuery = { | ||
targetEntity, | ||
filters: [ | ||
{ | ||
operation: "AND", | ||
predicates: [ | ||
{ | ||
type: itemType, | ||
id: [...ids], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
return qry; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/common/src/associations/internal/getTypeWithKeywordQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getEntityTypeFromType } from "../../search/_internal/getEntityTypeFromType"; | ||
import { IQuery } from "../../search/types/IHubCatalog"; | ||
|
||
/** | ||
* @private | ||
* Return an `IQuery` for a specific item type, with a specific typekeyword | ||
* This is used internally to build queries for "Connected" entities | ||
* @param itemType | ||
* @param keyword | ||
* @returns | ||
*/ | ||
export function getTypeWithKeywordQuery( | ||
itemType: string, | ||
keyword: string | ||
): IQuery { | ||
const targetEntity = getEntityTypeFromType(itemType); | ||
|
||
return { | ||
targetEntity, | ||
filters: [ | ||
{ | ||
operation: "AND", | ||
predicates: [ | ||
{ | ||
type: itemType, | ||
typekeywords: keyword, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/common/src/associations/internal/getTypeWithoutKeywordQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getEntityTypeFromType } from "../../search/_internal/getEntityTypeFromType"; | ||
import { IQuery } from "../../search/types/IHubCatalog"; | ||
|
||
/** | ||
* @private | ||
* Return an `IQuery` for a specific item type, without a specific typekeyword | ||
* This is used internally to build queries for "Not Connected" entities | ||
* @param itemType | ||
* @param keyword | ||
* @returns | ||
*/ | ||
export function getTypeWithoutKeywordQuery( | ||
itemType: string, | ||
keyword: string | ||
): IQuery { | ||
const targetEntity = getEntityTypeFromType(itemType); | ||
|
||
return { | ||
targetEntity, | ||
filters: [ | ||
{ | ||
operation: "AND", | ||
predicates: [ | ||
{ | ||
type: itemType, | ||
typekeywords: { not: [keyword] }, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/common/src/core/behaviors/IWIthAssociationBehavior.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AssociationType, IAssociationInfo } from "../../associations/types"; | ||
|
||
/** | ||
* Composable behavior that adds permissions to an entity | ||
*/ | ||
export interface IWithAssociationBehavior { | ||
/** | ||
* Get a list of the associations for an AssociationType | ||
* @param type | ||
*/ | ||
listAssociations(type: AssociationType): IAssociationInfo[]; | ||
|
||
/** | ||
* Add an association to the entity. | ||
* Entity needs to be saved after calling this method | ||
* @param info | ||
*/ | ||
addAssociation(info: IAssociationInfo): void; | ||
/** | ||
* Remove an association to the entity. | ||
* Entity needs to be saved after calling this method | ||
* @param info | ||
*/ | ||
removeAssociation(info: IAssociationInfo): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export interface IWithAssociations { | ||
typeKeywords?: string[]; | ||
[key: string]: any; | ||
} |
Oops, something went wrong.