@things-factory/scheduler 10.1.38 → 10.1.40
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/dist-client/pages/scheduler/schedule-list-page.d.ts +1 -1
- package/dist-client/pages/scheduler/schedule-list-page.js +5 -4
- package/dist-client/pages/scheduler/schedule-list-page.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/service/schedule/schedule-query.js +3 -33
- package/dist-server/service/schedule/schedule-query.js.map +1 -1
- package/dist-server/service/schedule/select-schedules.d.ts +10 -0
- package/dist-server/service/schedule/select-schedules.js +34 -0
- package/dist-server/service/schedule/select-schedules.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/tests/select-schedules.test.ts +64 -0
|
@@ -6,43 +6,13 @@ const type_graphql_1 = require("type-graphql");
|
|
|
6
6
|
const shell_1 = require("@things-factory/shell");
|
|
7
7
|
const scheduler_client_1 = require("@things-factory/scheduler-client");
|
|
8
8
|
const schedule_type_1 = require("./schedule-type");
|
|
9
|
+
const select_schedules_1 = require("./select-schedules");
|
|
9
10
|
let ScheduleQuery = class ScheduleQuery {
|
|
10
11
|
async schedule(id) {
|
|
11
12
|
return await (0, scheduler_client_1.getSchedule)(id);
|
|
12
13
|
}
|
|
13
14
|
async schedules(params) {
|
|
14
|
-
|
|
15
|
-
const name = filters.find(filter => filter.name === 'name')?.value;
|
|
16
|
-
const application = filters.find(filter => filter.name === 'application')?.value;
|
|
17
|
-
const group = filters.find(filter => filter.name === 'group')?.value;
|
|
18
|
-
const type = filters.find(filter => filter.name === 'type')?.value;
|
|
19
|
-
const key = filters.find(filter => filter.name === 'key')?.value;
|
|
20
|
-
const operation = filters.find(filter => filter.name === 'operation')?.value;
|
|
21
|
-
let schedules = await (0, scheduler_client_1.getSchedules)({});
|
|
22
|
-
if (name) {
|
|
23
|
-
schedules = schedules.filter(schedule => (schedule.name || '').toLowerCase().includes(name.toLowerCase()));
|
|
24
|
-
}
|
|
25
|
-
if (application) {
|
|
26
|
-
schedules = schedules.filter(schedule => (schedule.client?.application || '').toLowerCase().includes(application.toLowerCase()));
|
|
27
|
-
}
|
|
28
|
-
if (group) {
|
|
29
|
-
schedules = schedules.filter(schedule => (schedule.client?.group || '').toLowerCase().includes(group.toLowerCase()));
|
|
30
|
-
}
|
|
31
|
-
if (type) {
|
|
32
|
-
schedules = schedules.filter(schedule => (schedule.client?.type || '').toLowerCase().includes(type.toLowerCase()));
|
|
33
|
-
}
|
|
34
|
-
if (key) {
|
|
35
|
-
schedules = schedules.filter(schedule => (schedule.client?.key || '').toLowerCase().includes(key.toLowerCase()));
|
|
36
|
-
}
|
|
37
|
-
if (operation) {
|
|
38
|
-
schedules = schedules.filter(schedule => (schedule.client?.operation || '').toLowerCase().includes(operation.toLowerCase()));
|
|
39
|
-
}
|
|
40
|
-
const { page = 1, limit = 20 } = params.pagination || {};
|
|
41
|
-
const start = (page - 1) * limit;
|
|
42
|
-
const end = start + limit;
|
|
43
|
-
const items = schedules.slice(start, end);
|
|
44
|
-
const total = schedules.length;
|
|
45
|
-
return { items, total };
|
|
15
|
+
return (0, select_schedules_1.selectSchedules)(await (0, scheduler_client_1.getSchedules)({}), params);
|
|
46
16
|
}
|
|
47
17
|
};
|
|
48
18
|
exports.ScheduleQuery = ScheduleQuery;
|
|
@@ -57,7 +27,7 @@ tslib_1.__decorate([
|
|
|
57
27
|
tslib_1.__decorate([
|
|
58
28
|
(0, type_graphql_1.Directive)('@privilege(superUserGranted: true)'),
|
|
59
29
|
(0, type_graphql_1.Query)(returns => schedule_type_1.ScheduleList, {
|
|
60
|
-
description: 'Retrieve a paginated list of schedules
|
|
30
|
+
description: 'Retrieve a paginated list of schedules, filtered by name, application, group, type, key and operation, or by a search term matching any of them.'
|
|
61
31
|
}),
|
|
62
32
|
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
63
33
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule-query.js","sourceRoot":"","sources":["../../../server/service/schedule/schedule-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAwE;AACxE,iDAAiD;AACjD,uEAA4E;AAC5E,mDAAwD;
|
|
1
|
+
{"version":3,"file":"schedule-query.js","sourceRoot":"","sources":["../../../server/service/schedule/schedule-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAwE;AACxE,iDAAiD;AACjD,uEAA4E;AAC5E,mDAAwD;AACxD,yDAAoD;AAG7C,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGlB,AAAN,KAAK,CAAC,QAAQ,CAAsB,EAAU;QAC5C,OAAO,MAAM,IAAA,8BAAW,EAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAOK,AAAN,KAAK,CAAC,SAAS,CAA0B,MAAiB;QACxD,OAAO,IAAA,kCAAe,EAAC,MAAM,IAAA,+BAAY,EAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC;CACF,CAAA;AAfY,sCAAa;AAGlB;IAFL,IAAA,wBAAS,EAAC,oCAAoC,CAAC;IAC/C,IAAA,oBAAK,EAAC,GAAG,EAAE,CAAC,wBAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,sDAAsD,EAAE,CAAC;IAC/F,mBAAA,IAAA,kBAAG,EAAC,IAAI,EAAE,GAAG,EAAE,CAAC,iBAAE,CAAC,CAAA;;;;6CAElC;AAOK;IALL,IAAA,wBAAS,EAAC,oCAAoC,CAAC;IAC/C,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,4BAAY,EAAE;QAC9B,WAAW,EACT,kJAAkJ;KACrJ,CAAC;IACe,mBAAA,IAAA,mBAAI,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC,CAAA;;6CAAS,iBAAS;;8CAEzD;wBAdU,aAAa;IADzB,IAAA,uBAAQ,EAAC,wBAAQ,CAAC;GACN,aAAa,CAezB","sourcesContent":["import { Resolver, Query, Args, Arg, Directive, ID } from 'type-graphql'\nimport { ListParam } from '@things-factory/shell'\nimport { getSchedules, getSchedule } from '@things-factory/scheduler-client'\nimport { Schedule, ScheduleList } from './schedule-type'\nimport { selectSchedules } from './select-schedules'\n\n@Resolver(Schedule)\nexport class ScheduleQuery {\n @Directive('@privilege(superUserGranted: true)')\n @Query(() => Schedule, { nullable: true, description: 'Retrieve a single schedule by its unique identifier.' })\n async schedule(@Arg('id', () => ID) id: string): Promise<Schedule | null> {\n return await getSchedule(id)\n }\n\n @Directive('@privilege(superUserGranted: true)')\n @Query(returns => ScheduleList, {\n description:\n 'Retrieve a paginated list of schedules, filtered by name, application, group, type, key and operation, or by a search term matching any of them.'\n })\n async schedules(@Args(type => ListParam) params: ListParam): Promise<ScheduleList> {\n return selectSchedules(await getSchedules({}), params)\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ListParam } from '@things-factory/shell';
|
|
2
|
+
/**
|
|
3
|
+
* The page of schedules a list asks for. The scheduler hands back every schedule, so the door
|
|
4
|
+
* selects in memory: each named filter narrows on its own field, and the title bar's term
|
|
5
|
+
* (`params.search`, ADR-0060 decision 10) keeps a schedule when any of the fields contains it.
|
|
6
|
+
*/
|
|
7
|
+
export declare function selectSchedules<T>(schedules: T[], params: ListParam): {
|
|
8
|
+
items: T[];
|
|
9
|
+
total: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectSchedules = selectSchedules;
|
|
4
|
+
/* The fields a schedule can be found by - the name and the five that say who registered it. */
|
|
5
|
+
const FIELDS = {
|
|
6
|
+
name: schedule => schedule.name,
|
|
7
|
+
application: schedule => schedule.client?.application,
|
|
8
|
+
group: schedule => schedule.client?.group,
|
|
9
|
+
type: schedule => schedule.client?.type,
|
|
10
|
+
key: schedule => schedule.client?.key,
|
|
11
|
+
operation: schedule => schedule.client?.operation
|
|
12
|
+
};
|
|
13
|
+
const contains = (value, part) => (value || '').toLowerCase().includes(String(part).toLowerCase());
|
|
14
|
+
/**
|
|
15
|
+
* The page of schedules a list asks for. The scheduler hands back every schedule, so the door
|
|
16
|
+
* selects in memory: each named filter narrows on its own field, and the title bar's term
|
|
17
|
+
* (`params.search`, ADR-0060 decision 10) keeps a schedule when any of the fields contains it.
|
|
18
|
+
*/
|
|
19
|
+
function selectSchedules(schedules, params) {
|
|
20
|
+
let selected = schedules;
|
|
21
|
+
for (const filter of params.filters || []) {
|
|
22
|
+
const field = FIELDS[filter.name];
|
|
23
|
+
if (field && filter.value)
|
|
24
|
+
selected = selected.filter(schedule => contains(field(schedule), filter.value));
|
|
25
|
+
}
|
|
26
|
+
const term = params.search?.trim();
|
|
27
|
+
if (term) {
|
|
28
|
+
selected = selected.filter(schedule => Object.values(FIELDS).some(field => contains(field(schedule), term)));
|
|
29
|
+
}
|
|
30
|
+
const { page = 1, limit = 20 } = params.pagination || {};
|
|
31
|
+
const start = (page - 1) * limit;
|
|
32
|
+
return { items: selected.slice(start, start + limit), total: selected.length };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=select-schedules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-schedules.js","sourceRoot":"","sources":["../../../server/service/schedule/select-schedules.ts"],"names":[],"mappings":";;AAoBA,0CAiBC;AAnCD,+FAA+F;AAC/F,MAAM,MAAM,GAA8D;IACxE,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI;IAC/B,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW;IACrD,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK;IACzC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM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AAE,CAAA;IACxD,MAAM,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;IAEhC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAA;AAChF,CAAC","sourcesContent":["import type { ListParam } from '@things-factory/shell'\n\n/* The fields a schedule can be found by - the name and the five that say who registered it. */\nconst FIELDS: { [name: string]: (schedule: any) => string | undefined } = {\n name: schedule => schedule.name,\n application: schedule => schedule.client?.application,\n group: schedule => schedule.client?.group,\n type: schedule => schedule.client?.type,\n key: schedule => schedule.client?.key,\n operation: schedule => schedule.client?.operation\n}\n\nconst contains = (value: string | undefined, part: string) =>\n (value || '').toLowerCase().includes(String(part).toLowerCase())\n\n/**\n * The page of schedules a list asks for. The scheduler hands back every schedule, so the door\n * selects in memory: each named filter narrows on its own field, and the title bar's term\n * (`params.search`, ADR-0060 decision 10) keeps a schedule when any of the fields contains it.\n */\nexport function selectSchedules<T>(schedules: T[], params: ListParam): { items: T[]; total: number } {\n let selected = schedules\n\n for (const filter of params.filters || []) {\n const field = FIELDS[filter.name]\n if (field && filter.value) selected = selected.filter(schedule => contains(field(schedule), filter.value))\n }\n\n const term = params.search?.trim()\n if (term) {\n selected = selected.filter(schedule => Object.values(FIELDS).some(field => contains(field(schedule), term)))\n }\n\n const { page = 1, limit = 20 } = params.pagination || {}\n const start = (page - 1) * limit\n\n return { items: selected.slice(start, start + limit), total: selected.length }\n}\n"]}
|