Skip to content

Commit

Permalink
Added run
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Dec 5, 2024
1 parent e01f312 commit d0901bb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 66 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@web-atoms/core": "^v2.4.29",
"@web-atoms/core": "^v2.4.30",
"@web-atoms/date-time": "^1.1.0",
"@web-atoms/module-loader": "^2.1.2",
"@web-atoms/web-controls": "^2.2.1",
Expand Down
48 changes: 2 additions & 46 deletions src/services/BaseEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export default abstract class BaseEntityService extends TaskManager {
// }) as Promise<T>;
}

buildRunUrl<T extends IClrEntity, TA, TQ>(m: IModel<T, TQ, TA>, method: keyof TA, argEntity: IClrEntity, {
run<T extends IClrEntity, TA, TQ>(m: IModel<T, TQ, TA>, method: keyof TA, argEntity: IClrEntity, {
args = void 0 as any[],
cacheSeconds = 0,
cacheVersion = void 0 as any
Expand All @@ -482,51 +482,7 @@ export default abstract class BaseEntityService extends TaskManager {
if (cacheVersion) {
usp.append("cv", cacheVersion);
}
return `${this.url}run/${$type}/${method as any}?${usp.toString()}`;
}

async runAsText<T extends IClrEntity, TA, TQ>(m: IModel<T, TQ, TA>, method: keyof TA, argEntity: IClrEntity, {
args = void 0 as any[],
cacheSeconds = 0,
cacheVersion = void 0 as any,
cancelToken = void 0 as CancelToken
} = {
}) {
using busy = this.createBusyIndicator(false);
const url = this.buildRunUrl(m, method, argEntity, { args, cacheSeconds, cacheVersion});
return await FetchBuilder.get(url)
.cancelToken(cancelToken)
.asText();
}

async runAsBlob<T extends IClrEntity, TA, TQ>(m: IModel<T, TQ, TA>, method: keyof TA, argEntity: IClrEntity, {
args = void 0 as any[],
cacheSeconds = 0,
cacheVersion = void 0 as any,
cancelToken = void 0 as CancelToken
} = {
}) {
using busy = this.createBusyIndicator(false);
const url = this.buildRunUrl(m, method, argEntity, { args, cacheSeconds, cacheVersion});
return await FetchBuilder.get(url)
.cancelToken(cancelToken)
.asBlob();
}

async run<T extends IClrEntity, TA, TQ>(m: IModel<T, TQ, TA>, method: keyof TA, argEntity: IClrEntity, {
args = void 0 as any[],
cacheSeconds = 0,
cacheVersion = void 0 as any,
cancelToken = void 0 as CancelToken
} = {
}) {
using busy = this.createBusyIndicator(false);
const url = this.buildRunUrl(m, method, argEntity, { args, cacheSeconds, cacheVersion});
let result = await FetchBuilder.get(url)
.cancelToken(cancelToken)
.asJson();
result = this.resultConverter(result);
return result as any;
return FetchBuilder.get(`${this.url}run/${$type}/${method as any}?${usp.toString()}`).jsonPostProcessor(this.resultConverter);
}


Expand Down
38 changes: 26 additions & 12 deletions src/services/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import IPagedList from "../models/IPagedList";
import type BaseEntityService from "./BaseEntityService";
import type { ICollection, IListParams, IModel, IPagedListParams, IQueryMethod } from "./BaseEntityService";
import StringHelper from "./StringHelper";
import FetchBuilder from "@web-atoms/core/dist/services/FetchBuilder";

export type stepTypes = "Day" | "Month" | "Year" | "Week" | "Hour";

Expand Down Expand Up @@ -303,7 +304,7 @@ export default class Query<T> {
return r.items;
}

public toPagedList(
async toPagedList(
{
start = 0,
size = 100,
Expand All @@ -326,6 +327,9 @@ export default class Query<T> {
args
} = this.context;

// @ts-expect-error
using busy = service.createBusyIndicator(hideActivityIndicator);

const trace = traceQuery;
const methods = JSON.stringify(this.methods);
const fm = new URLSearchParams();
Expand All @@ -348,15 +352,15 @@ export default class Query<T> {
fm.append("expandable", "1");
}
const encodedMethods = fm.toString();
let result;
if (encodedMethods.length > 1824) {
if (cacheSeconds > 0) {
throw new Error("Generated query too big for caching");
}
url = `${service.url}methods/${name}`;
return (service as any).postJson({
url,
cancelToken,
body: {
result = await FetchBuilder.post(url)
.cancelToken(cancelToken)
.jsonBody({
methods: this.methods,
start,
size,
Expand All @@ -366,8 +370,11 @@ export default class Query<T> {
expandable: expandable ? 1 : void 0,
function: queryFunction || void 0,
args: queryFunction ? args : void 0
}
});
})
.asJson();
// @ts-expect-error
result = service.resultConverter(result);
return result;
}
if (cacheSeconds > 0) {
fm.append("cache", cacheSeconds.toString());
Expand All @@ -378,12 +385,19 @@ export default class Query<T> {
} else {
}
url = `${service.url}query/${name}?${fm.toString()}`;
result = await FetchBuilder.get(url)
.cancelToken(cancelToken)
.asJson();
// @ts-expect-error
return service.resultConverter(result);
// @ts-ignore
return service.getJson({
url,
cancelToken,
hideActivityIndicator
});
// return service.getJson({
// url,
// cancelToken,
// hideActivityIndicator
// });


}

protected thenInclude(a): any {
Expand Down

0 comments on commit d0901bb

Please sign in to comment.