Skip to content

Commit

Permalink
Signature fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Aug 2, 2024
1 parent 90ebea2 commit e2454e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/services/BaseEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export interface IModelSchema {
methods?: { [key: string]: any };
}

export interface IModel<T> {
export interface IModel<T, TM = any> {
name: string;
create?(properties?: IClrEntityLike<T>): T;
patch?(original: IClrEntityLike<T>, updates: IClrEntityLike<T>): T;
Expand Down Expand Up @@ -344,8 +344,8 @@ export default abstract class BaseEntityService extends HttpSession {
]);
}

public query<T extends IClrEntity>(m: IModel<T>,
queryFunction?: InferSchemaMethod<IModel<T>>,
public query<T extends IClrEntity, TR>(m: IModel<T, TR>,
queryFunction?: keyof TR,
... args: any[]): Query<T> {
return new Query({
service: this,
Expand All @@ -366,9 +366,9 @@ export default abstract class BaseEntityService extends HttpSession {
return this.putJson({url, body});
}

public invoke<T extends IClrEntity>(m: IModel<T>, method: InferSchemaMethod<IModel<T>>,entity: IClrEntity, ... args: any[]) {
public invoke<T extends IClrEntity, TR>(m: IModel<T, TR>, method: keyof TR,entity: IClrEntity, ... args: any[]) {
return this.postJson({
url: `${this.url}invoke/${entity.$type}/${method}`,
url: `${this.url}invoke/${entity.$type}/${method as any}`,
method: "POST",
body: {
entity,
Expand Down
32 changes: 32 additions & 0 deletions src/tests/schema-test/SchemaTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import BaseEntityService, { IModel, Model } from "../../services/BaseEntityService";
import HttpSession from "../../services/HttpSession";
import { QueryProcessor } from "../../services/QueryProcessor";

interface IItem {
$type: string, name: string, desc: string
}

const m1: IModel<IItem> = new Model<IItem>(
"n1",
["name"],
void 0,
{
keys: [ { name:"name" }],
name: "n1",
properties: [ { name: "desc"}],
relations: [],
methods: {
run: "run"
}
}
);

class EnttiyService extends BaseEntityService {

public queryProcessor: QueryProcessor;

}

const es = new EnttiyService();

es.query(m1, "run");

0 comments on commit e2454e1

Please sign in to comment.