From 909e72b8fab027a1fc251270162d5aa46cadcc51 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Sun, 3 Sep 2023 17:40:41 +0600 Subject: [PATCH 1/2] Pass default types parameters to MinilinkCollection --- imports/minilinks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imports/minilinks.ts b/imports/minilinks.ts index 522f91ab..db02020a 100644 --- a/imports/minilinks.ts +++ b/imports/minilinks.ts @@ -189,7 +189,7 @@ export function Minilinks> { +export class MinilinkCollection = Link> { useMinilinksQuery = useMinilinksQuery; useMinilinksFilter = useMinilinksFilter; useMinilinksApply = useMinilinksApply; From 0cd489fec74412524e0bf4fedb35a81aea82f750 Mon Sep 17 00:00:00 2001 From: FreePhoenix888 Date: Sun, 3 Sep 2023 18:02:05 +0600 Subject: [PATCH 2/2] Add createMinilinksDecorator --- .../create-minilinks-decorator.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 imports/experimental/create-minilinks-decorator.ts diff --git a/imports/experimental/create-minilinks-decorator.ts b/imports/experimental/create-minilinks-decorator.ts new file mode 100644 index 00000000..83b210ee --- /dev/null +++ b/imports/experimental/create-minilinks-decorator.ts @@ -0,0 +1,26 @@ +import { MinilinkCollection } from "../minilinks" + +export function createMinilinksDecorator(minilinks: TMinilinks): MinilinksDecorator { + const result: MinilinksDecorator = Object.assign({ + id: function (this: MinilinksDecorator, pathItems: [string, ...Array]) { + const result = this.idOrNull(pathItems) + if(result === null) throw new Error(`Minilink Error: id not found by path ${pathItems.join('/')}`) + return result + }, + idOrNull: function (this: TMinilinks, pathItems: [string, ...Array]) { + const result = this.query({ + id: { + _id: pathItems + } + }) + if (result.length === 0) return null; + return result[0].id + } + } , minilinks) + return result; +} + +export type MinilinksDecorator = TMinilinks & { + id(this: MinilinksDecorator, pathItems: [string, ...Array]): number; + idOrNull(this: MinilinksDecorator, pathItems: [string, ...Array]): number | null; +}