From bb30a6e8a8379af7777ff687330a51911d982599 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 6 Oct 2024 06:57:15 +0200 Subject: [PATCH] feat(core): Add selection dimensions and route removal functionality --- changelog.md | 42 ++++++++++++++++ pnpm-lock.yaml | 32 +++---------- ts/00_commitinfo_data.ts | 6 +-- ts/smartrouter.classes.selectiondimension.ts | 50 ++++++++++++++++++++ ts/smartrouter.classes.smartrouter.ts | 27 +++++++++-- ts/smartrouter.plugins.ts | 10 ++++ 6 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 changelog.md create mode 100644 ts/smartrouter.classes.selectiondimension.ts diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..c26dac0 --- /dev/null +++ b/changelog.md @@ -0,0 +1,42 @@ +# Changelog + +## 2024-10-06 - 1.1.0 - feat(core) +Add selection dimensions and route removal functionality + +- Introduced the SelectionDimension class for managing stateful selections across routes. +- Enhanced SmartRouter with the ability to create and manage selection dimensions. +- Added route removal functionality in SmartRouter using the 'on' method. + +## 2024-05-29 - 1.0.17 - Maintenance +Minor updates and maintenance changes to the project's configuration and metadata. + +- Updated project description. +- Modified tsconfig settings. +- Updated npmextra.json for the githost setting. + +## 2023-09-11 to 2023-04-11 - 1.0.16 - Fixes and Organizational Improvements +A series of minor bug fixes and organizational updates. + +- Fixed core component issues. +- Switched to a new organizational scheme. + +## 2023-03-18 to 2022-12-31 - 1.0.13 to 1.0.15 - Bug Fixes +Regular fixes to address bugs in the core. + +- Recurring fixes in core components across versions. + +## 2022-01-22 to 2021-09-08 - 1.0.11 to 1.0.12 - Stability Enhancements +Enhancements aimed at improving stability with core updates. + +- Core stability improvements and updates. + +## 2021-09-08 to 2020-11-30 - 1.0.5 to 1.0.10 - Regular Updates +Ongoing updates focused on the core's functionality. + +- Multiple core updates to ensure optimal performance. + +## 2020-11-30 to 2020-06-01 - 1.0.1 to 1.0.4 - Initial Fixes +Initial series of fixes and updates following project kickoff. + +- Addressed initial core component issues. + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4375d21..8530b07 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,12 @@ settings: excludeLinksFromLockfile: false dependencies: + '@push.rocks/lik': + specifier: ^6.0.5 + version: 6.0.5 + '@push.rocks/smartrx': + specifier: ^3.0.6 + version: 3.0.6 path-to-regexp: specifier: ^6.2.0 version: 6.2.1 @@ -578,7 +584,6 @@ packages: '@types/minimatch': 5.1.2 '@types/symbol-tree': 3.2.2 symbol-tree: 3.2.4 - dev: true /@push.rocks/smartbrowser@2.0.6: resolution: {integrity: sha512-Ne+KCVhV/DROc1rHRRw59K6h0+LpQAK9fdOUtgDZ7laLPmB/tmnbUh3IuRDNcIY1iVA9pydoobwjnTjVgio9eQ==} @@ -629,7 +634,6 @@ packages: resolution: {integrity: sha512-mUuI7kj2f7ztjpic96FvRIlf2RsKBa5arw81AHNsndbxO6asRcxuWL8dTVxouEIK8YsBUlj0AsrCkHhMbLQdHw==} dependencies: '@push.rocks/smartpromise': 4.0.3 - dev: true /@push.rocks/smartenv@5.0.5: resolution: {integrity: sha512-GmFGcUvi6iXU3uS4dNyxFGLktnroHE5Kjn+5sqojiJh/U+F134Ep5DwI3aeBtsD+BNHrDNa8t74v7uoWd1zR4g==} @@ -734,7 +738,6 @@ packages: resolution: {integrity: sha512-MBzP++1yNIBeox71X6VxpIgZ8m4bXnJpZJ4nWVH6IWpmO38MXTu4X0QF8tQnyT4LFcwvc9iiWaD15cstHa7Mmw==} dependencies: matcher: 5.0.0 - dev: true /@push.rocks/smartmime@1.0.6: resolution: {integrity: sha512-PHd+I4UcsnOATNg8wjDsSAmmJ4CwQFrQCNzd0HSJMs4ZpiK3Ya91almd6GLpDPU370U4HFh4FaPF4eEAI6vkJQ==} @@ -797,7 +800,6 @@ packages: /@push.rocks/smartpromise@4.0.3: resolution: {integrity: sha512-z3lIso4/6KK3c6NFTVGZ7AOBsGURf8ha3qQtX/OxjZFk5dqS//8PLd0XqghVdIaUlRGmJ7Sfds/efZERWn1tAg==} - dev: true /@push.rocks/smartpuppeteer@2.0.2: resolution: {integrity: sha512-EcYCT0PX++WjfHp7W5UYX3t8x5gSNpJMMUvhA7SHz8b2t76ItslNWxprRcF0CUQyN1fozbf5StZf7dwdGc/dIA==} @@ -829,7 +831,6 @@ packages: dependencies: '@push.rocks/smartpromise': 4.0.3 rxjs: 7.8.1 - dev: true /@push.rocks/smartshell@3.0.3: resolution: {integrity: sha512-S4RXI76ltPetdJ8Gv4HlnlhR/hXDV8QmSU7TdhLEe171ZzfouAyt9XZ4MFDCtjk3VQ4Mw+zz4mSDaACXP/QdlQ==} @@ -924,7 +925,6 @@ packages: dayjs: 1.11.9 is-nan: 1.3.2 pretty-ms: 8.0.0 - dev: true /@push.rocks/smartunique@3.0.6: resolution: {integrity: sha512-/fvh5BBHiTvZcCH4km2Oh3f0spfcWKr7e0Dp6lAb3rJq+5KiO7fQmI1UcQ9clADUaaJOn8sPzseiLt+kJ2tajw==} @@ -1585,7 +1585,6 @@ packages: /@types/minimatch@5.1.2: resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==} - dev: true /@types/mocha@5.2.7: resolution: {integrity: sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==} @@ -1657,7 +1656,6 @@ packages: /@types/symbol-tree@3.2.2: resolution: {integrity: sha512-+NcSHyA9K2EDHv3ny4wpbRSA+f+Tj0O7hIj7+w4tVw9yxqMavXwtFwuZEo3vyigTgOhGkrAUl3gj4oxAcyLfRQ==} - dev: true /@types/through2@2.0.38: resolution: {integrity: sha512-YFu+nHmjxMurkH1BSzA0Z1WrKDAY8jUKPZctNQn7mc+/KKtp2XxnclHFXxdB1m7Iqnzb5aywgP8TMK283LezGQ==} @@ -2142,7 +2140,6 @@ packages: dependencies: function-bind: 1.1.1 get-intrinsic: 1.2.0 - dev: true /callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} @@ -2373,7 +2370,6 @@ packages: /croner@5.7.0: resolution: {integrity: sha512-9pSLe+tDJnmNak2JeMkz6ZmTCXP5p6vCxSd4kvDqrTJkqAP62j2uAEIZjf8cPDZIakStujqVzh5Y5MIWH3yYAw==} engines: {node: '>=6.0'} - dev: true /cross-fetch@3.1.5: resolution: {integrity: sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==} @@ -2408,7 +2404,6 @@ packages: /dayjs@1.11.9: resolution: {integrity: sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==} - dev: true /debounce@1.2.1: resolution: {integrity: sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==} @@ -2500,7 +2495,6 @@ packages: dependencies: has-property-descriptors: 1.0.0 object-keys: 1.1.1 - dev: true /delayed-stream@1.0.0: resolution: {integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk=} @@ -2773,7 +2767,6 @@ packages: /escape-string-regexp@5.0.0: resolution: {integrity: sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==} engines: {node: '>=12'} - dev: true /esm@3.2.25: resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} @@ -3034,7 +3027,6 @@ packages: /function-bind@1.1.1: resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} - dev: true /function.prototype.name@1.1.6: resolution: {integrity: sha512-Z5kx79swU5P27WEayXM1tBi5Ze/lbIyiNgU3qyXUOf9b2rgXYyF9Dy9Cx+IQv/Lc8WCG6L82zwUPpSS9hGehIg==} @@ -3065,7 +3057,6 @@ packages: function-bind: 1.1.1 has: 1.0.3 has-symbols: 1.0.3 - dev: true /get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} @@ -3206,7 +3197,6 @@ packages: resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==} dependencies: get-intrinsic: 1.2.0 - dev: true /has-proto@1.0.1: resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==} @@ -3216,7 +3206,6 @@ packages: /has-symbols@1.0.3: resolution: {integrity: sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==} engines: {node: '>= 0.4'} - dev: true /has-tostringtag@1.0.0: resolution: {integrity: sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==} @@ -3230,7 +3219,6 @@ packages: engines: {node: '>= 0.4.0'} dependencies: function-bind: 1.1.1 - dev: true /he@1.2.0: resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} @@ -3485,7 +3473,6 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.2.0 - dev: true /is-negative-zero@2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} @@ -3966,7 +3953,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: escape-string-regexp: 5.0.0 - dev: true /math-random@1.0.4: resolution: {integrity: sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==} @@ -4218,7 +4204,6 @@ packages: /object-keys@1.1.1: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} - dev: true /object.assign@4.1.0: resolution: {integrity: sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==} @@ -4350,7 +4335,6 @@ packages: /parse-ms@3.0.0: resolution: {integrity: sha512-Tpb8Z7r7XbbtBTrM9UhpkzzaMrqA2VXMT3YChzYltwV3P3pM6t8wl7TvpMnSTosz1aQAdVib7kdoys7vYOPerw==} engines: {node: '>=12'} - dev: true /parse5@6.0.1: resolution: {integrity: sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==} @@ -4473,7 +4457,6 @@ packages: engines: {node: '>=14.16'} dependencies: parse-ms: 3.0.0 - dev: true /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} @@ -4733,7 +4716,6 @@ packages: resolution: {integrity: sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==} dependencies: tslib: 2.5.0 - dev: true /safe-array-concat@1.0.1: resolution: {integrity: sha512-6XbUAseYE2KtOuGueyeobCySj9L4+66Tn6KQMOPQJrAJEowYKW/YR/MGJZl7FdydUdaFu4LYyDZjxf4/Nmo23Q==} @@ -5131,7 +5113,6 @@ packages: /symbol-tree@3.2.4: resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==} - dev: true /systeminformation@5.21.4: resolution: {integrity: sha512-fLW6j47UoAJDlZPEqykkWTKxubxb8IFuow6pMQlqf4irZ2lBgCrCReavMkH2t8VxxjOcg6wBlZ2EPQcluAT6xg==} @@ -5254,7 +5235,6 @@ packages: /tslib@2.5.0: resolution: {integrity: sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==} - dev: true /tsscmp@1.0.6: resolution: {integrity: sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==} diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index a483513..91e820a 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -1,8 +1,8 @@ /** - * autocreated commitinfo by @pushrocks/commitinfo + * autocreated commitinfo by @push.rocks/commitinfo */ export const commitinfo = { name: '@push.rocks/smartrouter', - version: '1.0.17', - description: 'a router for routing on websites' + version: '1.1.0', + description: 'A JavaScript library providing routing capabilities for web applications.' } diff --git a/ts/smartrouter.classes.selectiondimension.ts b/ts/smartrouter.classes.selectiondimension.ts new file mode 100644 index 0000000..5a17f00 --- /dev/null +++ b/ts/smartrouter.classes.selectiondimension.ts @@ -0,0 +1,50 @@ +import * as plugins from './smartrouter.plugins.js'; + +export interface ISelectionOption { + key: string; + detail: T; + selected?: boolean; + action: () => Promise; +} + +export class SelectionDimension { + /** + * the key of the selection dimension + */ + public dimensionKey: string; + /** + * the level of the selection dimension + * a higher level is execution later than a lower level + * during catchup phase + */ + public dimensionLevel: number; + public dimensionPeers: SelectionDimension[] = []; + public selectionOptions: ISelectionOption[] = []; + + public selectionOptionSubject = new plugins.smartrx.rxjs.Subject[]>(); + + public async emitSelectionOptions () { + const selectionOptions = this.selectionOptions.map((selectionOptionArg): ISelectionOption => { + return { + key: selectionOptionArg.key, + detail: selectionOptionArg.detail, + action: async () => { + this.updateSelection(selectionOptionArg); + return await selectionOptionArg.action(); + }, + } + }); + this.selectionOptionSubject.next(selectionOptions); + } + + public async updateSelection (selectionOptionArg: ISelectionOption) { + for (const selectionOption of this.selectionOptions) { + if (selectionOption.key === selectionOptionArg.key) { + selectionOption.selected = true; + } else { + selectionOption.selected = false; + } + } + this.emitSelectionOptions(); + } +} \ No newline at end of file diff --git a/ts/smartrouter.classes.smartrouter.ts b/ts/smartrouter.classes.smartrouter.ts index 9f1fc82..e3b8e97 100644 --- a/ts/smartrouter.classes.smartrouter.ts +++ b/ts/smartrouter.classes.smartrouter.ts @@ -1,6 +1,7 @@ import * as plugins from './smartrouter.plugins.js'; import { QueryParams } from './smartrouter.classes.queryparams.js'; +import { type ISelectionOption, SelectionDimension } from './smartrouter.classes.selectiondimension.js'; const routeLog = (message: string) => { console.log(`%c[Router]%c ${message}`, 'color: rgb(255, 105, 100);', 'color: inherit'); @@ -71,10 +72,15 @@ export class SmartRouter { * @param {function} handlerArg */ public on(routeArg: string, handlerArg: THandlerFunction) { - this.routes.push({ + const routeObject = { matchFunction: plugins.pathToRegExp.match(routeArg), handler: handlerArg, - }); + }; + this.routes.push(routeObject); + const removeFunction = () => { + this.routes.splice(this.routes.indexOf(routeObject), 1); + }; + return removeFunction; } /** @@ -96,4 +102,19 @@ export class SmartRouter { } as IRouteInfo); // not waiting here } } -} + + public selectionDimensionsMap = new plugins.lik.ObjectMap(); + public async createSelectionDimension(optionsArg: { + routeArg: string, + keyArg: string, + options: ISelectionOption[], + peers?: SelectionDimension[], + }) { + const selectionDimension = new SelectionDimension(); + selectionDimension.dimensionKey = optionsArg.keyArg; + selectionDimension.dimensionPeers = optionsArg.peers; + selectionDimension.selectionOptions = optionsArg.options; + await this.selectionDimensionsMap.findOneAndRemove(async dimensionArg => dimensionArg.dimensionKey === optionsArg.keyArg); + this.selectionDimensionsMap.addMappedUnique(optionsArg.keyArg, selectionDimension); + } +} \ No newline at end of file diff --git a/ts/smartrouter.plugins.ts b/ts/smartrouter.plugins.ts index 7ae6f56..6558b23 100644 --- a/ts/smartrouter.plugins.ts +++ b/ts/smartrouter.plugins.ts @@ -1,3 +1,13 @@ +// @push.rocks scope +import * as lik from '@push.rocks/lik'; +import * as smartrx from '@push.rocks/smartrx'; + +export { + lik, + smartrx, +} + +// third party scope import * as pathToRegExp from 'path-to-regexp'; export { pathToRegExp };