Skip to content

Commit

Permalink
declaration mergable types
Browse files Browse the repository at this point in the history
  • Loading branch information
zoe-codez committed Apr 8, 2024
1 parent ee28222 commit 15065e1
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
5 changes: 4 additions & 1 deletion cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ ignorePaths: []
dictionaryDefinitions: []
dictionaries: []
words:
- hass
- gotify
- grocy
- hass
- printlabel
- USERFIELDS
ignoreWords: []
import: []
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@digital-alchemy/grocy",
"repository": "https://github.com/Digital-Alchemy-TS/grocy",
"homepage": "https://docs.digital-alchemy.app/Grocy",
"version": "0.3.2",
"version": "0.3.3",
"scripts": {
"build": "tsc",
"lint": "eslint src",
Expand Down
29 changes: 16 additions & 13 deletions src/extensions/aggregator.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
CHORE_CACHE_UPDATED,
GROCY_REBUILD_CACHE,
GrocyBattery,
GrocyBatteryUserfields,
GrocyChore,
GrocyObjectChoreDetail,
GrocyTask,
GrocyTaskUserfields,
TASK_CACHE_UPDATED,
} from "../helpers";

export function Aggregator<USERFIELDS extends object>({
export function Aggregator({
scheduler,
logger,
grocy,
Expand All @@ -36,20 +38,20 @@ export function Aggregator<USERFIELDS extends object>({
});

const aggregator = {
BATTERY_CACHE: new Set<GrocyBattery & { userfields: USERFIELDS }>(),
CHORES_CACHE: new Set<GrocyObjectChoreDetail<USERFIELDS> & GrocyChore>(),
TASKS_CACHE: new Set<GrocyTask & { userfields: USERFIELDS }>(),
BATTERY_CACHE: new Set<GrocyBattery>(),
CHORES_CACHE: new Set<GrocyObjectChoreDetail & GrocyChore>(),
TASKS_CACHE: new Set<GrocyTask>(),

async buildBatteryCache(): Promise<void> {
const battery = await grocy.battery.listBatteries();
const cache = new Set<GrocyBattery & { userfields: USERFIELDS }>();
const cache = new Set<GrocyBattery>();

await eachLimit(
battery,
config.grocy.USERFIELDS_FETCH_RATE,
async battery => {
const userfields =
await grocy.object.listObjectUserFields<USERFIELDS>({
await grocy.object.listObjectUserFields<GrocyBatteryUserfields>({
id: battery.id.toString(),
type: "batteries",
});
Expand All @@ -66,15 +68,15 @@ export function Aggregator<USERFIELDS extends object>({

async buildChoresCache(): Promise<void> {
const chores = await grocy.chores.listChores();
const cache = new Set<GrocyObjectChoreDetail<USERFIELDS> & GrocyChore>();
const cache = new Set<GrocyObjectChoreDetail & GrocyChore>();

await eachLimit(
chores,
config.grocy.USERFIELDS_FETCH_RATE,
async chore => {
const data = (await grocy.chores.getChoreObject(
chore.id,
)) as GrocyObjectChoreDetail<USERFIELDS>;
)) as GrocyObjectChoreDetail;
cache.add({ ...chore, ...data });
},
);
Expand All @@ -85,13 +87,14 @@ export function Aggregator<USERFIELDS extends object>({

async buildTaskCache(): Promise<void> {
const tasks = await grocy.tasks.listTasks();
const cache = new Set<GrocyTask & { userfields: USERFIELDS }>();
const cache = new Set<GrocyTask>();

await eachLimit(tasks, config.grocy.USERFIELDS_FETCH_RATE, async task => {
const userfields = await grocy.object.listObjectUserFields<USERFIELDS>({
id: task.id.toString(),
type: "tasks",
});
const userfields =
await grocy.object.listObjectUserFields<GrocyTaskUserfields>({
id: task.id.toString(),
type: "tasks",
});
cache.add({
...task,
userfields,
Expand Down
7 changes: 2 additions & 5 deletions src/extensions/chores.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type ExecuteChoreRequest = {
tracked_time: Date;
};

export function Chores<USERFIELDS extends object = object>({
grocy,
logger,
}: TServiceParams) {
export function Chores({ grocy, logger }: TServiceParams) {
return {
async executeChore(id: string) {
logger.trace("executeChore");
Expand Down Expand Up @@ -47,7 +44,7 @@ export function Chores<USERFIELDS extends object = object>({

async getChoreObject(id: number) {
logger.trace("getChoreObject");
return await grocy.fetch<GrocyObjectChoreDetail<USERFIELDS>>({
return await grocy.fetch<GrocyObjectChoreDetail>({
url: `/objects/chores/${id}`,
});
},
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export interface GrocyBattery {
id: number;
last_tracked_time: Date;
next_estimated_charge_time: Date;
userfields?: GrocyBatteryUserfields;
}

export interface GrocyBatteryUserfields {
//
}

export interface Battery {
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/chores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export interface GrocyChore {
export type GrocyChorePeriodType = "daily";
export type GrocyChoreAssignmentType = "in-alphabetical-order";

export interface GrocyObjectChoreDetail<USERFIELDS extends object = object> {
export interface GrocyChoreUserfields {
//
}

export interface GrocyObjectChoreDetail {
assignment_config: string;
assignment_type: GrocyChoreAssignmentType;
consume_product_on_execution: boolean;
Expand All @@ -62,7 +66,7 @@ export interface GrocyObjectChoreDetail<USERFIELDS extends object = object> {
rollover: boolean;
row_created_timestamp: Date;
start_date: Date;
userfields: USERFIELDS;
userfields?: GrocyChoreUserfields;
}

export interface NextExecutionAssignedUser {
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface GrocyTask {
id: number;
name: string;
row_created_timestamp: Date;
userfields?: GrocyTaskUserfields;
}

export interface AssignedToUser {
Expand All @@ -29,3 +30,7 @@ export interface Category {
name: string;
row_created_timestamp: Date;
}

export interface GrocyTaskUserfields {
//
}

0 comments on commit 15065e1

Please sign in to comment.