From bebee6b4d0469311cd8f9078f1e91a04d220b008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Wed, 26 Jul 2023 16:03:22 +0000 Subject: [PATCH] feat: migrate app collection helpers to use the collecion-utils package --- .changeset/config.json | 2 +- .changeset/silly-news-punch.md | 5 + frontend/app/package.json | 1 + .../app/_helpers/collections/chunk.spec.ts | 22 ---- .../app/src/app/_helpers/collections/chunk.ts | 27 ---- .../_helpers/collections/difference.spec.ts | 25 ---- .../app/_helpers/collections/difference.ts | 23 ---- .../src/app/_helpers/collections/get.spec.ts | 39 ------ .../app/src/app/_helpers/collections/get.ts | 30 ----- .../app/_helpers/collections/group-by.spec.ts | 123 ------------------ .../src/app/_helpers/collections/group-by.ts | 45 ------- .../app/_helpers/collections/key-by.spec.ts | 41 ------ .../src/app/_helpers/collections/key-by.ts | 27 ---- .../_helpers/collections/map-values.spec.ts | 50 ------- .../app/_helpers/collections/map-values.ts | 32 ----- .../src/app/_helpers/collections/min.spec.ts | 44 ------- .../app/src/app/_helpers/collections/min.ts | 23 ---- .../src/app/_helpers/collections/omit.spec.ts | 23 ---- .../app/src/app/_helpers/collections/omit.ts | 23 ---- .../_helpers/collections/partition.spec.ts | 25 ---- .../src/app/_helpers/collections/partition.ts | 28 ---- .../src/app/_helpers/collections/pick.spec.ts | 23 ---- .../app/src/app/_helpers/collections/pick.ts | 41 ------ .../app/_helpers/collections/shuffle.spec.ts | 30 ----- .../src/app/_helpers/collections/shuffle.ts | 28 ---- .../_helpers/collections/string-sort.spec.ts | 33 ----- .../app/_helpers/collections/string-sort.ts | 36 ----- .../src/app/_helpers/collections/sum.spec.ts | 31 ----- .../app/src/app/_helpers/collections/sum.ts | 31 ----- .../_helpers/collections/tree-group.spec.ts | 74 ----------- .../app/_helpers/collections/tree-group.ts | 46 ------- .../src/app/_helpers/collections/uniq.spec.ts | 24 ---- .../app/src/app/_helpers/collections/uniq.ts | 26 ---- .../src/app/_helpers/collections/zip.spec.ts | 25 ---- .../app/src/app/_helpers/collections/zip.ts | 21 --- .../assessments/assessments.provider.ts | 4 +- .../page/assessments-page.component.ts | 4 +- .../app/modules/calendar/ical/ical.spec.ts | 3 +- .../app/src/app/modules/calendar/ical/ical.ts | 3 +- .../app/modules/calendar/schedule.provider.ts | 3 +- .../chips/edit-event-selection.component.ts | 13 +- .../app/src/app/modules/data/data.provider.ts | 2 +- .../data/list/tree-list-fragment.component.ts | 2 +- .../modules/data/list/tree-list.component.ts | 2 +- .../mensa/place-mensa-detail.component.ts | 4 +- .../special/mensa/place-mensa-service.ts | 3 +- .../daia-availability.component.ts | 2 +- .../page/grid/infinite-swiper.component.ts | 3 +- .../schedule/page/grid/range-overlap.spec.ts | 3 +- .../schedule/page/grid/range-overlap.ts | 2 +- .../page/schedule-single-events.component.ts | 4 +- .../app/translation/translate-simple.pipe.ts | 2 +- frontend/app/src/app/util/lazy.pipe.ts | 3 +- pnpm-lock.yaml | 5 +- 54 files changed, 35 insertions(+), 1159 deletions(-) create mode 100644 .changeset/silly-news-punch.md delete mode 100644 frontend/app/src/app/_helpers/collections/chunk.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/chunk.ts delete mode 100644 frontend/app/src/app/_helpers/collections/difference.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/difference.ts delete mode 100644 frontend/app/src/app/_helpers/collections/get.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/get.ts delete mode 100644 frontend/app/src/app/_helpers/collections/group-by.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/group-by.ts delete mode 100644 frontend/app/src/app/_helpers/collections/key-by.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/key-by.ts delete mode 100644 frontend/app/src/app/_helpers/collections/map-values.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/map-values.ts delete mode 100644 frontend/app/src/app/_helpers/collections/min.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/min.ts delete mode 100644 frontend/app/src/app/_helpers/collections/omit.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/omit.ts delete mode 100644 frontend/app/src/app/_helpers/collections/partition.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/partition.ts delete mode 100644 frontend/app/src/app/_helpers/collections/pick.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/pick.ts delete mode 100644 frontend/app/src/app/_helpers/collections/shuffle.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/shuffle.ts delete mode 100644 frontend/app/src/app/_helpers/collections/string-sort.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/string-sort.ts delete mode 100644 frontend/app/src/app/_helpers/collections/sum.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/sum.ts delete mode 100644 frontend/app/src/app/_helpers/collections/tree-group.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/tree-group.ts delete mode 100644 frontend/app/src/app/_helpers/collections/uniq.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/uniq.ts delete mode 100644 frontend/app/src/app/_helpers/collections/zip.spec.ts delete mode 100644 frontend/app/src/app/_helpers/collections/zip.ts diff --git a/.changeset/config.json b/.changeset/config.json index d5229d5c..bab7f207 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -5,7 +5,7 @@ "fixed": [], "linked": [["@openstapps/*"]], "access": "restricted", - "baseBranch": "main", + "baseBranch": "develop", "updateInternalDependencies": "patch", "ignore": [] } diff --git a/.changeset/silly-news-punch.md b/.changeset/silly-news-punch.md new file mode 100644 index 00000000..5874c5de --- /dev/null +++ b/.changeset/silly-news-punch.md @@ -0,0 +1,5 @@ +--- +'@openstapps/app': patch +--- + +Migrate collection helpers to use @openstapps/collection-utils diff --git a/frontend/app/package.json b/frontend/app/package.json index 37cfcd06..e676eec1 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -85,6 +85,7 @@ "@openid/appauth": "1.3.1", "@openstapps/api": "workspace:*", "@openstapps/core": "workspace:*", + "@openstapps/collection-utils": "workspace:*", "@transistorsoft/capacitor-background-fetch": "1.0.2", "capacitor-secure-storage-plugin": "0.8.1", "cordova-plugin-calendar": "5.1.6", diff --git a/frontend/app/src/app/_helpers/collections/chunk.spec.ts b/frontend/app/src/app/_helpers/collections/chunk.spec.ts deleted file mode 100644 index 4c53d402..00000000 --- a/frontend/app/src/app/_helpers/collections/chunk.spec.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {chunk} from './chunk'; - -describe('chunk', function () { - it('should chunk items in the correct sizes', function () { - expect(chunk([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)).toEqual([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/chunk.ts b/frontend/app/src/app/_helpers/collections/chunk.ts deleted file mode 100644 index 4d5422c5..00000000 --- a/frontend/app/src/app/_helpers/collections/chunk.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Chunk array into smaller arrays of a specified size. - * @param array The array to chunk. - * @param chunkSize The size of each chunk. - */ -export function chunk(array: T[], chunkSize = 1): T[][] { - const arrayCopy = [...array]; - const out: T[][] = []; - if (chunkSize <= 0) return out; - while (arrayCopy.length > 0) out.push(arrayCopy.splice(0, chunkSize)); - return out; -} diff --git a/frontend/app/src/app/_helpers/collections/difference.spec.ts b/frontend/app/src/app/_helpers/collections/difference.spec.ts deleted file mode 100644 index ea9fab3d..00000000 --- a/frontend/app/src/app/_helpers/collections/difference.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {differenceBy} from './difference'; - -describe('differenceBy', function () { - it('should return the difference of two arrays', function () { - const a = [1, 2, 3, 4, 5]; - const b = [1, 2, 3]; - - expect(differenceBy(a, b, it => it)).toEqual([4, 5]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/difference.ts b/frontend/app/src/app/_helpers/collections/difference.ts deleted file mode 100644 index 62839057..00000000 --- a/frontend/app/src/app/_helpers/collections/difference.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Returns the difference between two arrays. - */ -export function differenceBy(a: T[], b: T[], transform: (item: T) => unknown) { - const disallowed = new Set(b.map(transform)); - - return a.filter(item => !disallowed.has(transform(item))); -} diff --git a/frontend/app/src/app/_helpers/collections/get.spec.ts b/frontend/app/src/app/_helpers/collections/get.spec.ts deleted file mode 100644 index 5682f2c5..00000000 --- a/frontend/app/src/app/_helpers/collections/get.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {get} from './get'; - -describe('get', function () { - it('should get a simple path', function () { - const object = { - a: { - b: { - c: 'd', - }, - }, - }; - expect(get(object, 'a.b.c')).toBe('d'); - }); - - it('should return undefined for a non-existent path', function () { - const object = { - a: { - b: { - c: 'd', - }, - }, - }; - expect(get(object, 'a.b.c.d')).toBeUndefined(); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/get.ts b/frontend/app/src/app/_helpers/collections/get.ts deleted file mode 100644 index 78f20749..00000000 --- a/frontend/app/src/app/_helpers/collections/get.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Gets a value from a nested object. - * The path must be key names separated by dots. - * If the path doesn't exist, undefined is returned. - */ -export function get(object: object, path: string): U { - return path.split('.').reduce( - (accumulator, current) => - accumulator?.hasOwnProperty(current) - ? // eslint-disable-next-line @typescript-eslint/no-explicit-any - (accumulator as any)[current] - : undefined, - object, - ) as unknown as U; -} diff --git a/frontend/app/src/app/_helpers/collections/group-by.spec.ts b/frontend/app/src/app/_helpers/collections/group-by.spec.ts deleted file mode 100644 index 5d165257..00000000 --- a/frontend/app/src/app/_helpers/collections/group-by.spec.ts +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {groupBy, groupByStable, groupByProperty} from './group-by'; - -describe('groupBy', () => { - it('should group an array by a key', () => { - const array = [ - {id: 1, name: 'one'}, - {id: 2, name: 'two'}, - {id: 3, name: 'three'}, - {id: 4, name: 'four'}, - {id: 5, name: 'five'}, - ]; - - const result = groupBy(array, it => it.name); - - expect(result).toEqual({ - one: [{id: 1, name: 'one'}], - two: [{id: 2, name: 'two'}], - three: [{id: 3, name: 'three'}], - four: [{id: 4, name: 'four'}], - five: [{id: 5, name: 'five'}], - }); - }); - - it('should handle multiple elements per group', () => { - const array = [ - {id: 1, name: 'one'}, - {id: 2, name: 'two'}, - {id: 3, name: 'three'}, - {id: 4, name: 'four'}, - {id: 5, name: 'five'}, - {id: 6, name: 'one'}, - {id: 7, name: 'two'}, - {id: 8, name: 'three'}, - {id: 9, name: 'four'}, - {id: 10, name: 'five'}, - ]; - - const result = groupBy(array, it => it.name); - - expect(result).toEqual({ - one: [ - {id: 1, name: 'one'}, - {id: 6, name: 'one'}, - ], - two: [ - {id: 2, name: 'two'}, - {id: 7, name: 'two'}, - ], - three: [ - {id: 3, name: 'three'}, - {id: 8, name: 'three'}, - ], - four: [ - {id: 4, name: 'four'}, - {id: 9, name: 'four'}, - ], - five: [ - {id: 5, name: 'five'}, - {id: 10, name: 'five'}, - ], - }); - }); -}); - -describe('groupByStable', () => { - const array = [ - {id: 2, name: 'two'}, - {id: 4, name: 'three'}, - {id: 3, name: 'three'}, - {id: 1, name: 'one'}, - ]; - const result = groupByStable(array, it => it.name); - - it('should group an array by keys', () => { - expect(result.get('one')).toEqual([{id: 1, name: 'one'}]); - expect(result.get('two')).toEqual([{id: 2, name: 'two'}]); - expect(result.get('three')).toEqual([ - {id: 4, name: 'three'}, - {id: 3, name: 'three'}, - ]); - }); - - it('should provide ordered keys', () => { - expect([...result.keys()]).toEqual(['two', 'three', 'one']); - }); -}); - -describe('groupByProperty', function () { - it('should group by property', () => { - const array = [ - {id: 1, name: 'one'}, - {id: 2, name: 'two'}, - {id: 3, name: 'three'}, - {id: 4, name: 'four'}, - {id: 5, name: 'five'}, - ]; - - const result = groupByProperty(array, 'name'); - - expect(result).toEqual({ - one: [{id: 1, name: 'one'}], - two: [{id: 2, name: 'two'}], - three: [{id: 3, name: 'three'}], - four: [{id: 4, name: 'four'}], - five: [{id: 5, name: 'five'}], - }); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/group-by.ts b/frontend/app/src/app/_helpers/collections/group-by.ts deleted file mode 100644 index 6723f7db..00000000 --- a/frontend/app/src/app/_helpers/collections/group-by.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Group an array by a function - */ -export function groupBy(collection: T[], group: (item: T) => string | undefined): Record { - return collection.reduce((accumulator: Record, item) => { - const key = group(item) ?? ''; - accumulator[key] = accumulator[key] ?? []; - accumulator[key].push(item); - return accumulator; - }, {}); -} - -/** - * Group an array by a function (returns a Map, whose keys keep order info of items entry) - */ -export function groupByStable(collection: T[], group: (item: T) => string | undefined): Map { - return collection.reduce((accumulator: Map, item) => { - const key = group(item) ?? ''; - accumulator.set(key, accumulator.get(key) ?? []); - accumulator.get(key)?.push(item); - return accumulator; - }, new Map()); -} - -/** - * - */ -export function groupByProperty(collection: T[], property: keyof T): Record { - return groupBy(collection, item => item[property] as unknown as string); -} diff --git a/frontend/app/src/app/_helpers/collections/key-by.spec.ts b/frontend/app/src/app/_helpers/collections/key-by.spec.ts deleted file mode 100644 index 104ce6dc..00000000 --- a/frontend/app/src/app/_helpers/collections/key-by.spec.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {keyBy} from './key-by'; - -describe('keyBy', function () { - it('should key objects', function () { - const objects = [ - { - id: 1, - name: 'foo', - }, - { - id: 2, - name: 'bar', - }, - ]; - const result = keyBy(objects, it => it.id); - expect(result).toEqual({ - 1: { - id: 1, - name: 'foo', - }, - 2: { - id: 2, - name: 'bar', - }, - }); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/key-by.ts b/frontend/app/src/app/_helpers/collections/key-by.ts deleted file mode 100644 index e7f3a544..00000000 --- a/frontend/app/src/app/_helpers/collections/key-by.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Create an object composed of keys generated from the results of running - * each element of collection thru iteratee. The corresponding value of - * each key is the last element responsible for generating the key. The - * iteratee is invoked with one argument: (value). - */ -export function keyBy(collection: T[], key: (item: T) => string | number): Record { - return collection.reduce((accumulator, item) => { - accumulator[key(item)] = item; - return accumulator; - }, {} as Record); -} diff --git a/frontend/app/src/app/_helpers/collections/map-values.spec.ts b/frontend/app/src/app/_helpers/collections/map-values.spec.ts deleted file mode 100644 index 1a8a7fe7..00000000 --- a/frontend/app/src/app/_helpers/collections/map-values.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {mapValues} from './map-values'; - -describe('map-values', () => { - it('should map values', () => { - const object = { - a: 1, - b: 2, - c: 3, - }; - - const result = mapValues(object, value => value * 2); - - expect(result).toEqual({ - a: 2, - b: 4, - c: 6, - }); - }); - - it('should not modify the original object', () => { - const object = { - a: 1, - b: 2, - c: 3, - }; - - mapValues(object, value => value * 2); - - expect(object).toEqual({ - a: 1, - b: 2, - c: 3, - }); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/map-values.ts b/frontend/app/src/app/_helpers/collections/map-values.ts deleted file mode 100644 index 3b36d107..00000000 --- a/frontend/app/src/app/_helpers/collections/map-values.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Maps the values of an object to a new object - */ -export function mapValues( - object: T, - transform: (value: T[keyof T], key: keyof T) => U, -): {[key in keyof T]: U} { - const result = {} as {[key in keyof T]: U}; - - for (const key in object) { - if (object.hasOwnProperty(key)) { - result[key] = transform(object[key], key); - } - } - - return result; -} diff --git a/frontend/app/src/app/_helpers/collections/min.spec.ts b/frontend/app/src/app/_helpers/collections/min.spec.ts deleted file mode 100644 index c88cda33..00000000 --- a/frontend/app/src/app/_helpers/collections/min.spec.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {minBy} from './min'; - -describe('minBy', function () { - it('should pick the minimum value based on transform', function () { - expect( - minBy( - [ - {id: 1, name: 'A'}, - {id: 2, name: 'B'}, - {id: 3, name: 'C'}, - ], - it => it.id, - ), - ).toEqual({id: 1, name: 'A'}); - }); - - it('should not return undefined if there are other choices', function () { - expect( - minBy( - [ - {id: undefined, name: 'B'}, - {id: 1, name: 'A'}, - {id: undefined, name: 'C'}, - ], - it => it.id, - ), - ).toEqual({id: 1, name: 'A'}); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/min.ts b/frontend/app/src/app/_helpers/collections/min.ts deleted file mode 100644 index 2a99e971..00000000 --- a/frontend/app/src/app/_helpers/collections/min.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Returns the minimum value of a collection. - */ -export function minBy(array: T[], transform: (item: T) => number | undefined): T { - const transforms = array.map(transform); - const min = Math.min(...(transforms.filter(it => !!it) as number[])); - return array.find((_, i) => transforms[i] === min) as T; -} diff --git a/frontend/app/src/app/_helpers/collections/omit.spec.ts b/frontend/app/src/app/_helpers/collections/omit.spec.ts deleted file mode 100644 index 7c7adfd7..00000000 --- a/frontend/app/src/app/_helpers/collections/omit.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {omit} from './omit'; - -describe('omit', function () { - it('should omit keys', function () { - const object = {a: 1, b: 2, c: 3}; - const result = omit(object, 'a', 'c'); - expect(result).toEqual({b: 2}); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/omit.ts b/frontend/app/src/app/_helpers/collections/omit.ts deleted file mode 100644 index dd15b66f..00000000 --- a/frontend/app/src/app/_helpers/collections/omit.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Returns a new object without the specified keys. - */ -export function omit(object: T, ...keys: U[]): Omit { - const out = {...object}; - for (const key of keys) delete out[key]; - return out as Exclude; -} diff --git a/frontend/app/src/app/_helpers/collections/partition.spec.ts b/frontend/app/src/app/_helpers/collections/partition.spec.ts deleted file mode 100644 index c64b568a..00000000 --- a/frontend/app/src/app/_helpers/collections/partition.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {partition} from './partition'; - -describe('partition', function () { - it('should partition an array', function () { - expect(partition([1, 2, 3, 4], it => it % 2 === 0)).toEqual([ - [2, 4], - [1, 3], - ]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/partition.ts b/frontend/app/src/app/_helpers/collections/partition.ts deleted file mode 100644 index 27ccfb62..00000000 --- a/frontend/app/src/app/_helpers/collections/partition.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Partitions a list into two lists. One with the elements that satisfy a predicate, - * and one with the elements that don't satisfy the predicate. - */ -export function partition(array: T[], transform: (item: T) => boolean): [T[], T[]] { - return array.reduce<[T[], T[]]>( - (accumulator, item) => { - accumulator[transform(item) ? 0 : 1].push(item); - return accumulator; - }, - [[], []], - ); -} diff --git a/frontend/app/src/app/_helpers/collections/pick.spec.ts b/frontend/app/src/app/_helpers/collections/pick.spec.ts deleted file mode 100644 index 6db203eb..00000000 --- a/frontend/app/src/app/_helpers/collections/pick.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {pick} from './pick'; - -describe('pick', function () { - it('should pick properties', function () { - const object = {a: 1, b: 2, c: 3}; - const result = pick(object, ['a', 'c']); - expect(result).toEqual({a: 1, c: 3}); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/pick.ts b/frontend/app/src/app/_helpers/collections/pick.ts deleted file mode 100644 index 9405a37b..00000000 --- a/frontend/app/src/app/_helpers/collections/pick.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Pick a set of properties from an object - */ -export function pick(object: T, keys: U[]): Pick { - return keys.reduce((accumulator, key) => { - if (object.hasOwnProperty(key)) { - accumulator[key] = object[key]; - } - return accumulator; - }, {} as Pick); -} - -/** - * Pick a set of properties from an object using a predicate function - */ -export function pickBy( - object: T, - predicate: (value: T[U], key: U) => boolean, -): Pick { - return (Object.keys(object) as U[]).reduce((accumulator, key) => { - if (predicate(object[key], key)) { - accumulator[key] = object[key]; - } - return accumulator; - }, {} as Pick); -} diff --git a/frontend/app/src/app/_helpers/collections/shuffle.spec.ts b/frontend/app/src/app/_helpers/collections/shuffle.spec.ts deleted file mode 100644 index d2e8d0c3..00000000 --- a/frontend/app/src/app/_helpers/collections/shuffle.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {shuffle} from './shuffle'; - -describe('shuffle', function () { - it('should shuffle an array', function () { - const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - const shuffled = shuffle(array); - expect(shuffled).not.toEqual(array); - expect(shuffled).toEqual(jasmine.arrayContaining(array)); - }); - - it('should not modify the original array', function () { - const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - shuffle(array); - expect(array).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/shuffle.ts b/frontend/app/src/app/_helpers/collections/shuffle.ts deleted file mode 100644 index 1c053c85..00000000 --- a/frontend/app/src/app/_helpers/collections/shuffle.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Shuffles an array - */ -export function shuffle(array: T[]): T[] { - const copy = [...array]; - const out = []; - - while (copy.length > 0) { - out.push(copy.splice(Math.floor(Math.random() * copy.length), 1)[0]); - } - - return out; -} diff --git a/frontend/app/src/app/_helpers/collections/string-sort.spec.ts b/frontend/app/src/app/_helpers/collections/string-sort.spec.ts deleted file mode 100644 index d20744a4..00000000 --- a/frontend/app/src/app/_helpers/collections/string-sort.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {stringSort, stringSortBy} from './string-sort'; - -describe('stringSort', () => { - it('should sort an array of strings', () => { - expect(['a', 'c', 'b', 'd'].sort(stringSort)).toEqual(['a', 'b', 'c', 'd']); - }); -}); - -describe('stringSortBy', () => { - it('should sort an array of strings', () => { - expect([{item: 'a'}, {item: 'c'}, {item: 'b'}, {item: 'd'}].sort(stringSortBy(it => it.item))).toEqual([ - {item: 'a'}, - {item: 'b'}, - {item: 'c'}, - {item: 'd'}, - ]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/string-sort.ts b/frontend/app/src/app/_helpers/collections/string-sort.ts deleted file mode 100644 index b7a2b24d..00000000 --- a/frontend/app/src/app/_helpers/collections/string-sort.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * sort function for two strings - */ -export function stringSort(a = '', b = ''): number { - if (a < b) return -1; - if (a > b) return 1; - return 0; -} - -/** - * sort function for two strings that allows for a custom transform - */ -export function stringSortBy(map: (item: T) => string | undefined): (a: T, b: T) => number { - return (a: T, b: T): number => { - const aValue = map(a) || ''; - const bValue = map(b) || ''; - if (aValue < bValue) return -1; - if (aValue > bValue) return 1; - return 0; - }; -} diff --git a/frontend/app/src/app/_helpers/collections/sum.spec.ts b/frontend/app/src/app/_helpers/collections/sum.spec.ts deleted file mode 100644 index 0b1b43d7..00000000 --- a/frontend/app/src/app/_helpers/collections/sum.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {sum, sumBy} from './sum'; - -describe('sum', () => { - it('should return the sum of all elements in the collection', () => { - const collection = [1, 2, 3, 4, 5]; - const result = sum(collection); - expect(result).toBe(15); - }); -}); - -describe('sumBy', function () { - it('should return the sum of all elements in the collection', () => { - const collection = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]; - const result = sumBy(collection, it => it.a); - expect(result).toBe(15); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/sum.ts b/frontend/app/src/app/_helpers/collections/sum.ts deleted file mode 100644 index a92a796c..00000000 --- a/frontend/app/src/app/_helpers/collections/sum.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Sum an an array - */ -export function sumBy( - collection: T[], - transform: (value: T) => number | undefined, -): number { - return collection.reduce((accumulator, item) => accumulator + (transform(item) || 0), 0); -} - -/** - * Sum an array of numbers - */ -export function sum(collection: Array): number { - return collection.reduce((accumulator, item) => accumulator + (item || 0), 0); -} diff --git a/frontend/app/src/app/_helpers/collections/tree-group.spec.ts b/frontend/app/src/app/_helpers/collections/tree-group.spec.ts deleted file mode 100644 index 31f762ba..00000000 --- a/frontend/app/src/app/_helpers/collections/tree-group.spec.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {Tree, treeGroupBy} from './tree-group'; - -interface TestItem { - id: number; - path?: string[]; -} - -describe('tree-group', function () { - it('should create a tree', function () { - const items: Array = [ - { - id: 1, - path: ['a', 'b', 'c'], - }, - { - id: 2, - path: ['a', 'b', 'd'], - }, - ]; - - const tree = treeGroupBy(items, item => item.path ?? []); - - const expectedTree: Tree = { - a: { - b: { - c: {_: [items[0]]}, - d: {_: [items[1]]}, - } as Tree, - } as Tree, - } as Tree; - - expect(tree).toEqual(expectedTree); - }); - - it('should also sort empty paths', () => { - const items: Array = [ - { - id: 1, - path: ['a', 'b', 'c'], - }, - { - id: 2, - }, - ]; - - const tree = treeGroupBy(items, item => item.path ?? []); - - const expectedTree: Tree = { - a: { - b: { - c: {_: [items[0]]}, - } as Tree, - } as Tree, - _: [items[1]], - } as Tree; - - expect(tree).toEqual(expectedTree); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/tree-group.ts b/frontend/app/src/app/_helpers/collections/tree-group.ts deleted file mode 100644 index 295bf193..00000000 --- a/frontend/app/src/app/_helpers/collections/tree-group.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -export type Tree = { - [key: string]: Tree; -} & { - _?: T[] | undefined; -}; - -/** - * - */ -export function treeGroupBy(items: T[], transform: (item: T) => string[]): Tree { - const tree: Tree = {}; - - for (const item of items) { - let currentTree = tree; - const keys = transform(item); - if (keys.length === 0) { - currentTree._ = currentTree._ || []; - currentTree._.push(item); - } - for (const [i, key] of keys.entries()) { - currentTree = currentTree[key] = (currentTree[key] ?? {}) as Tree; - if (i === keys.length - 1) { - currentTree._ = currentTree._ ?? []; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - currentTree._.push(item); - } - } - } - - return tree; -} diff --git a/frontend/app/src/app/_helpers/collections/uniq.spec.ts b/frontend/app/src/app/_helpers/collections/uniq.spec.ts deleted file mode 100644 index 37cf55be..00000000 --- a/frontend/app/src/app/_helpers/collections/uniq.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -import {uniqBy} from './uniq'; - -describe('uniq', function () { - it('should return an array with unique values', function () { - const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - const result = uniqBy(array, it => it); - expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/uniq.ts b/frontend/app/src/app/_helpers/collections/uniq.ts deleted file mode 100644 index 933c07e7..00000000 --- a/frontend/app/src/app/_helpers/collections/uniq.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Filter out duplicates from an array. - */ -export function uniqBy(array: T[], transform: (item: T) => string | number): T[] { - return Object.values( - array.reduce((accumulator, current) => { - accumulator[transform(current)] = current; - return accumulator; - }, {} as Record), - ); -} diff --git a/frontend/app/src/app/_helpers/collections/zip.spec.ts b/frontend/app/src/app/_helpers/collections/zip.spec.ts deleted file mode 100644 index 35f7c6bc..00000000 --- a/frontend/app/src/app/_helpers/collections/zip.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ -import {zip} from './zip'; - -describe('zip', function () { - it('should zip arrays together', function () { - expect(zip([1, 2, 3], [4, 5, 6])).toEqual([ - [1, 4], - [2, 5], - [3, 6], - ]); - }); -}); diff --git a/frontend/app/src/app/_helpers/collections/zip.ts b/frontend/app/src/app/_helpers/collections/zip.ts deleted file mode 100644 index f17e89f1..00000000 --- a/frontend/app/src/app/_helpers/collections/zip.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2022 StApps - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -/** - * Zip two arrays together. - */ -export function zip(a: T[], b: U[]): [T, U][] { - return a.map((_, i) => [a[i], b[i]]); -} diff --git a/frontend/app/src/app/modules/assessments/assessments.provider.ts b/frontend/app/src/app/modules/assessments/assessments.provider.ts index 5fde0e6e..b0f94abf 100644 --- a/frontend/app/src/app/modules/assessments/assessments.provider.ts +++ b/frontend/app/src/app/modules/assessments/assessments.provider.ts @@ -12,14 +12,12 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import {Injectable} from '@angular/core'; import {ConfigProvider} from '../config/config.provider'; import {SCAssessment, SCUuid} from '@openstapps/core'; import {DefaultAuthService} from '../auth/default-auth.service'; import {HttpClient} from '@angular/common/http'; -import {uniqBy} from '../../_helpers/collections/uniq'; -import {keyBy} from '../../_helpers/collections/key-by'; +import {uniqBy, keyBy} from '@openstapps/collection-utils'; /** * diff --git a/frontend/app/src/app/modules/assessments/page/assessments-page.component.ts b/frontend/app/src/app/modules/assessments/page/assessments-page.component.ts index a5db3129..3e1be673 100644 --- a/frontend/app/src/app/modules/assessments/page/assessments-page.component.ts +++ b/frontend/app/src/app/modules/assessments/page/assessments-page.component.ts @@ -12,7 +12,6 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import {AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {AssessmentsProvider} from '../assessments.provider'; import {SCAssessment, SCCourseOfStudy} from '@openstapps/core'; @@ -23,8 +22,7 @@ import {materialSharedAxisX} from '../../../animation/material-motion'; import {SharedAxisChoreographer} from '../../../animation/animation-choreographer'; import {DataProvider, DataScope} from '../../data/data.provider'; import {DataRoutingService} from '../../data/data-routing.service'; -import {groupBy} from '../../../_helpers/collections/group-by'; -import {mapValues} from '../../../_helpers/collections/map-values'; +import {groupBy, mapValues} from '@openstapps/collection-utils'; @Component({ selector: 'app-assessments-page', diff --git a/frontend/app/src/app/modules/calendar/ical/ical.spec.ts b/frontend/app/src/app/modules/calendar/ical/ical.spec.ts index 752026d5..158372ad 100644 --- a/frontend/app/src/app/modules/calendar/ical/ical.spec.ts +++ b/frontend/app/src/app/modules/calendar/ical/ical.spec.ts @@ -12,11 +12,10 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import {findRRules, RRule} from './ical'; import moment, {unitOfTime} from 'moment'; import {SCISO8601Date} from '@openstapps/core'; -import {shuffle} from '../../../_helpers/collections/shuffle'; +import {shuffle} from '@openstapps/collection-utils'; /** * diff --git a/frontend/app/src/app/modules/calendar/ical/ical.ts b/frontend/app/src/app/modules/calendar/ical/ical.ts index 47ecd34d..f580cd8c 100644 --- a/frontend/app/src/app/modules/calendar/ical/ical.ts +++ b/frontend/app/src/app/modules/calendar/ical/ical.ts @@ -21,8 +21,7 @@ import { SCUuid, } from '@openstapps/core'; import moment, {unitOfTime} from 'moment'; -import {minBy} from '../../../_helpers/collections/min'; -import {mapValues} from '../../../_helpers/collections/map-values'; +import {minBy, mapValues} from '@openstapps/collection-utils'; export interface ICalEvent { name?: string; diff --git a/frontend/app/src/app/modules/calendar/schedule.provider.ts b/frontend/app/src/app/modules/calendar/schedule.provider.ts index 46e18ea7..5c6c2cba 100644 --- a/frontend/app/src/app/modules/calendar/schedule.provider.ts +++ b/frontend/app/src/app/modules/calendar/schedule.provider.ts @@ -12,7 +12,6 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - /* eslint-disable unicorn/no-null */ import {Injectable, OnDestroy} from '@angular/core'; import { @@ -28,7 +27,7 @@ import {BehaviorSubject, Observable, Subscription} from 'rxjs'; import {DataProvider} from '../data/data.provider'; import {map} from 'rxjs/operators'; import {DateFormatPipe, DurationPipe} from 'ngx-moment'; -import {pick} from '../../_helpers/collections/pick'; +import {pick} from '@openstapps/collection-utils'; /** * diff --git a/frontend/app/src/app/modules/data/chips/edit-event-selection.component.ts b/frontend/app/src/app/modules/data/chips/edit-event-selection.component.ts index 2f643a8c..1ef33120 100644 --- a/frontend/app/src/app/modules/data/chips/edit-event-selection.component.ts +++ b/frontend/app/src/app/modules/data/chips/edit-event-selection.component.ts @@ -21,11 +21,14 @@ import { toDateSeriesRelevantData, } from '../../calendar/schedule.provider'; import {CalendarService} from '../../calendar/calendar.service'; -import {groupBy, groupByProperty} from '../../../_helpers/collections/group-by'; -import {mapValues} from '../../../_helpers/collections/map-values'; -import {stringSortBy} from '../../../_helpers/collections/string-sort'; -import {uniqBy} from '../../../_helpers/collections/uniq'; -import {differenceBy} from '../../../_helpers/collections/difference'; +import { + groupBy, + groupByProperty, + mapValues, + stringSortBy, + uniqBy, + differenceBy, +} from '@openstapps/collection-utils'; import {SelectionValue, TreeNode} from './tree-node'; /** diff --git a/frontend/app/src/app/modules/data/data.provider.ts b/frontend/app/src/app/modules/data/data.provider.ts index cf9d23f8..69ce4b1a 100644 --- a/frontend/app/src/app/modules/data/data.provider.ts +++ b/frontend/app/src/app/modules/data/data.provider.ts @@ -35,7 +35,7 @@ import { import {environment} from '../../../environments/environment'; import {StorageProvider} from '../storage/storage.provider'; import {StAppsWebHttpClient} from './stapps-web-http-client.provider'; -import {chunk} from '../../_helpers/collections/chunk'; +import {chunk} from '@openstapps/collection-utils'; export enum DataScope { Local = 'local', diff --git a/frontend/app/src/app/modules/data/list/tree-list-fragment.component.ts b/frontend/app/src/app/modules/data/list/tree-list-fragment.component.ts index 9e19a89f..90352410 100644 --- a/frontend/app/src/app/modules/data/list/tree-list-fragment.component.ts +++ b/frontend/app/src/app/modules/data/list/tree-list-fragment.component.ts @@ -14,7 +14,7 @@ */ import {Component, Input, TemplateRef} from '@angular/core'; import {SCThings, SCThingWithoutReferences, SCUuid} from '@openstapps/core'; -import {Tree} from '../../../_helpers/collections/tree-group'; +import type {Tree} from '@openstapps/collection-utils'; import {DataListContext} from './data-list.component'; @Component({ diff --git a/frontend/app/src/app/modules/data/list/tree-list.component.ts b/frontend/app/src/app/modules/data/list/tree-list.component.ts index ba57e2af..fee3cdd9 100644 --- a/frontend/app/src/app/modules/data/list/tree-list.component.ts +++ b/frontend/app/src/app/modules/data/list/tree-list.component.ts @@ -15,7 +15,7 @@ import {Component, ContentChild, Input, TemplateRef} from '@angular/core'; import {DataListContext} from './data-list.component'; import {SCThings, SCThingWithoutReferences, SCUuid} from '@openstapps/core'; -import {Tree, treeGroupBy} from '../../../_helpers/collections/tree-group'; +import {Tree, treeGroupBy} from '@openstapps/collection-utils'; @Component({ selector: 'tree-list', diff --git a/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-detail.component.ts b/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-detail.component.ts index 63ddfc32..bb54238a 100644 --- a/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-detail.component.ts +++ b/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-detail.component.ts @@ -12,9 +12,7 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import moment, {Moment} from 'moment'; - import {AfterViewInit, Component, Input, OnDestroy} from '@angular/core'; import {SCDish, SCISO8601Date, SCPlace} from '@openstapps/core'; import {PlaceMensaService} from './place-mensa-service'; @@ -22,7 +20,7 @@ import {Router} from '@angular/router'; import {Subscription} from 'rxjs'; import {IonRouterOutlet} from '@ionic/angular'; import {DataRoutingService} from '../../../../data-routing.service'; -import {groupBy} from 'src/app/_helpers/collections/group-by'; +import {groupBy} from '@openstapps/collection-utils'; /** * TODO diff --git a/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-service.ts b/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-service.ts index e18b4021..e711da47 100644 --- a/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-service.ts +++ b/frontend/app/src/app/modules/data/types/place/special/mensa/place-mensa-service.ts @@ -12,12 +12,11 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import {Injectable} from '@angular/core'; import {SCDish, SCISO8601Date, SCPlace, SCSearchQuery, SCThingType} from '@openstapps/core'; import moment from 'moment'; import {DataProvider} from '../../../../data.provider'; -import {mapValues} from '../../../../../../_helpers/collections/map-values'; +import {mapValues} from '@openstapps/collection-utils'; import {SettingsProvider} from '../../../../../settings/settings.provider'; /** diff --git a/frontend/app/src/app/modules/hebis/daia-availability/daia-availability.component.ts b/frontend/app/src/app/modules/hebis/daia-availability/daia-availability.component.ts index abc053f6..fac26db8 100644 --- a/frontend/app/src/app/modules/hebis/daia-availability/daia-availability.component.ts +++ b/frontend/app/src/app/modules/hebis/daia-availability/daia-availability.component.ts @@ -22,7 +22,7 @@ import {DataDetailComponent} from '../../data/detail/data-detail.component'; import {DaiaDataProvider} from '../daia-data.provider'; import {DaiaHolding} from '../protocol/response'; import {ModalController} from '@ionic/angular'; -import {groupByStable} from '../../../_helpers/collections/group-by'; +import {groupByStable} from '@openstapps/collection-utils'; /** * A Component to display an SCThing detailed diff --git a/frontend/app/src/app/modules/schedule/page/grid/infinite-swiper.component.ts b/frontend/app/src/app/modules/schedule/page/grid/infinite-swiper.component.ts index 815f740e..c9f439cf 100644 --- a/frontend/app/src/app/modules/schedule/page/grid/infinite-swiper.component.ts +++ b/frontend/app/src/app/modules/schedule/page/grid/infinite-swiper.component.ts @@ -12,7 +12,6 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { AfterViewInit, @@ -34,7 +33,7 @@ import { } from '@angular/core'; import Swiper from 'swiper'; import {materialManualFade} from '../../../../animation/material-motion'; -import {zip} from '../../../../_helpers/collections/zip'; +import {zip} from '@openstapps/collection-utils'; export interface SlideContext { $implicit: number; diff --git a/frontend/app/src/app/modules/schedule/page/grid/range-overlap.spec.ts b/frontend/app/src/app/modules/schedule/page/grid/range-overlap.spec.ts index c4883b59..aca0012d 100644 --- a/frontend/app/src/app/modules/schedule/page/grid/range-overlap.spec.ts +++ b/frontend/app/src/app/modules/schedule/page/grid/range-overlap.spec.ts @@ -12,10 +12,9 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - /* eslint-disable @typescript-eslint/no-explicit-any */ import {groupRangeOverlaps} from './range-overlap'; -import {shuffle} from '../../../../_helpers/collections/shuffle'; +import {shuffle} from '@openstapps/collection-utils'; interface SimpleRange { starty: number; diff --git a/frontend/app/src/app/modules/schedule/page/grid/range-overlap.ts b/frontend/app/src/app/modules/schedule/page/grid/range-overlap.ts index bba6a7b4..57f89d01 100644 --- a/frontend/app/src/app/modules/schedule/page/grid/range-overlap.ts +++ b/frontend/app/src/app/modules/schedule/page/grid/range-overlap.ts @@ -12,7 +12,7 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -import {partition} from '../../../../_helpers/collections/partition'; +import {partition} from '@openstapps/collection-utils'; export interface RangeInfo { elements: T[]; diff --git a/frontend/app/src/app/modules/schedule/page/schedule-single-events.component.ts b/frontend/app/src/app/modules/schedule/page/schedule-single-events.component.ts index 01d3d42a..c26026f4 100644 --- a/frontend/app/src/app/modules/schedule/page/schedule-single-events.component.ts +++ b/frontend/app/src/app/modules/schedule/page/schedule-single-events.component.ts @@ -19,9 +19,7 @@ import {Subscription} from 'rxjs'; import {materialFade} from '../../../animation/material-motion'; import {ScheduleProvider} from '../../calendar/schedule.provider'; import {ScheduleEvent} from './schema/schema'; -import {groupBy} from '../../../_helpers/collections/group-by'; -import {omit} from '../../../_helpers/collections/omit'; -import {stringSortBy} from '../../../_helpers/collections/string-sort'; +import {groupBy, omit, stringSortBy} from '@openstapps/collection-utils'; /** * A single event diff --git a/frontend/app/src/app/translation/translate-simple.pipe.ts b/frontend/app/src/app/translation/translate-simple.pipe.ts index 0108a415..11edf52f 100644 --- a/frontend/app/src/app/translation/translate-simple.pipe.ts +++ b/frontend/app/src/app/translation/translate-simple.pipe.ts @@ -14,7 +14,7 @@ */ import {Injectable, OnDestroy, Pipe, PipeTransform} from '@angular/core'; import {TranslateService} from '@ngx-translate/core'; -import {get} from '../_helpers/collections/get'; +import {get} from '@openstapps/collection-utils'; import {Subscription} from 'rxjs'; @Injectable() diff --git a/frontend/app/src/app/util/lazy.pipe.ts b/frontend/app/src/app/util/lazy.pipe.ts index 23079153..a5ba8cd0 100644 --- a/frontend/app/src/app/util/lazy.pipe.ts +++ b/frontend/app/src/app/util/lazy.pipe.ts @@ -12,12 +12,11 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ - import {Observable} from 'rxjs'; import {Pipe, PipeTransform} from '@angular/core'; import {SCSaveableThing, SCThings, SCUuid} from '@openstapps/core'; import {DataProvider, DataScope} from '../modules/data/data.provider'; -import {get} from '../_helpers/collections/get'; +import {get} from '@openstapps/collection-utils'; @Pipe({ name: 'lazyThing', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9d5d7830..ca87e354 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -815,6 +815,9 @@ importers: '@openstapps/api': specifier: workspace:* version: link:../../packages/api + '@openstapps/collection-utils': + specifier: workspace:* + version: link:../../packages/collection-utils '@openstapps/core': specifier: workspace:* version: link:../../packages/core @@ -1084,8 +1087,6 @@ importers: specifier: 4.7.0 version: 4.7.0 - frontend/app-release-template: {} - images/app-builder: {} images/node-base: {}