Skip to content

Commit

Permalink
Added support for entity key
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Dec 11, 2024
1 parent 74b3b33 commit c732fbf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/services/BaseEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ export default abstract class BaseEntityService extends TaskManager {
query<T extends IClrEntity, TR>(m: IModel<T, TR>,
queryFunction?: keyof TR,
... args: any[]): Query<T> {
let entityKey;
if (args.length) {
const first = args[0];
if (first) {
const { $key, $type } = first;
if ($key && $type) {
// this is an entity, and must be sent as an entity key
entityKey = $key;
args.splice(0, 1);
}
}
}
return new Query({
service: this,
name: m.name,
Expand Down
8 changes: 7 additions & 1 deletion src/services/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ interface IQueryContext {
traceQuery?: boolean;
queryFunction?: string;
args?: any[];
entityKey?: string;
queryProcessor?: "DotNet" | "JavaScript"
}

Expand Down Expand Up @@ -324,6 +325,7 @@ export default class Query<T> {
name,
service,
queryFunction,
entityKey,
args
} = this.context;

Expand All @@ -347,6 +349,9 @@ export default class Query<T> {
if (queryFunction) {
fm.append("function", queryFunction);
fm.append("args", JSON.stringify(args ?? "[]"));
if (entityKey) {
fm.append("entityKey", entityKey);
}
}
if (expandable) {
fm.append("expandable", "1");
Expand All @@ -369,7 +374,8 @@ export default class Query<T> {
trace,
expandable: expandable ? 1 : void 0,
function: queryFunction || void 0,
args: queryFunction ? args : void 0
args: queryFunction ? args : void 0,
entityKey: entityKey ?? void 0
})
.asJson();
// @ts-expect-error
Expand Down

0 comments on commit c732fbf

Please sign in to comment.