From 40ad7ffc0bf5cd3dc795fb5bf36495c2c1de1283 Mon Sep 17 00:00:00 2001 From: Polle Pas Date: Wed, 6 Nov 2024 16:30:26 +0100 Subject: [PATCH] Fix resource.props doesn't resolve default props like parent --- browser/lib/package.json | 3 ++- browser/lib/src/resource.ts | 11 +++++++++++ browser/pnpm-lock.yaml | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/browser/lib/package.json b/browser/lib/package.json index 26017143..27fbc569 100644 --- a/browser/lib/package.json +++ b/browser/lib/package.json @@ -15,7 +15,8 @@ "tslib": "^2.8.0", "typescript": "^5.6.3", "vite": "^5.4.10", - "vite-plugin-dts": "^3.9.1" + "vite-plugin-dts": "^3.9.1", + "vitest": "^2.1.3" }, "files": [ "dist" diff --git a/browser/lib/src/resource.ts b/browser/lib/src/resource.ts index 1188d5f8..88cdd430 100644 --- a/browser/lib/src/resource.ts +++ b/browser/lib/src/resource.ts @@ -113,6 +113,13 @@ export class Resource { * @example const description = resource.props.description */ public get props(): QuickAccesPropType { + const defaultProps = { + parent: core.properties.parent, + isA: core.properties.isA, + write: core.properties.write, + read: core.properties.read, + }; + // eslint-disable-next-line @typescript-eslint/no-this-alias const innerThis = this; @@ -121,6 +128,10 @@ export class Resource { .filter(def => def !== undefined); const getPropSubject = (name: string) => { + if (name in defaultProps) { + return defaultProps[name]; + } + for (const def of defs) { const value = def[name]; diff --git a/browser/pnpm-lock.yaml b/browser/pnpm-lock.yaml index 476cb3c9..47cb4e8f 100644 --- a/browser/pnpm-lock.yaml +++ b/browser/pnpm-lock.yaml @@ -342,6 +342,9 @@ importers: vite-plugin-dts: specifier: ^3.9.1 version: 3.9.1(@types/node@20.17.0)(rollup@4.24.0)(typescript@5.6.3)(vite@5.4.10(@types/node@20.17.0)(terser@5.36.0)) + vitest: + specifier: ^2.1.3 + version: 2.1.3(@types/node@20.17.0)(terser@5.36.0) react: dependencies: