From 785dece8cb72adef1cbb969530ac3e1d64fd3ad9 Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Thu, 3 Aug 2023 21:45:45 +0200 Subject: [PATCH 1/5] feat: add reflection metadata --- .eslintrc.cjs | 1 + stores/firestore/input.ts | 5 +---- stores/firestore/var.ts | 11 ++++++++++- tsconfig.json | 3 ++- vite.config.cjs | 25 ++++++++++++++++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index a4983dc3..c43b9d02 100755 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -33,6 +33,7 @@ module.exports = { disallowTypeAnnotations: false, }, ], + "@typescript-eslint/consistent-type-imports": false, "prettier-vue/prettier": [ "error", { diff --git a/stores/firestore/input.ts b/stores/firestore/input.ts index cf83d59b..405c1969 100755 --- a/stores/firestore/input.ts +++ b/stores/firestore/input.ts @@ -1,3 +1,4 @@ +import "reflect-metadata"; import { reactive } from "vue"; import { onInitialize } from "./entity"; import type { EntityMetaData } from "./entityMetadata"; @@ -14,9 +15,5 @@ export function Input(type: any, options: any = {}) { errors: [], }; }); - /* setPropertyMetadata(target, name, "input", { - type, - options, - });*/ }; } diff --git a/stores/firestore/var.ts b/stores/firestore/var.ts index 914f3c03..1174932b 100644 --- a/stores/firestore/var.ts +++ b/stores/firestore/var.ts @@ -110,8 +110,17 @@ function isUnparsedEqual(a: any, b: any, type: any): boolean { return a === b; } -export function Var(type: any) { +export function Var() { return function (target: EntityBase, name: string) { + const metadata = Reflect.getMetadata("design:type", target, name); + if (metadata === undefined) + throw new Error( + "Property type is not set for " + target.constructor.name + ":" + name + ); + + let type = metadata; + if (metadata.type === Array) type = Array.of(metadata.elementType); + onInitialize(target, function (this: any, metadata: EntityMetaData) { if (metadata.properties[name] === undefined) metadata.properties[name] = {}; diff --git a/tsconfig.json b/tsconfig.json index 5d694e0c..3877b116 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -49,6 +49,7 @@ ".eslintrc.cjs", "index.ts", "vite.config.cjs", - "default-styles.ts" + "default-styles.ts", + "reflect-metadata.d.ts" ] } diff --git a/vite.config.cjs b/vite.config.cjs index 479f6139..66b0aac9 100755 --- a/vite.config.cjs +++ b/vite.config.cjs @@ -12,6 +12,8 @@ const vueI18n = require("@intlify/unplugin-vue-i18n/vite"); const { VitePWA } = require("vite-plugin-pwa"); const { createHtmlPlugin } = require("vite-plugin-html"); const purgecss = require("rollup-plugin-purgecss"); +const { esbuildDecorators } = require("@anatine/esbuild-decorators"); +const { default: babel } = require("vite-plugin-babel"); const { VueUseComponentsResolver, VueUseDirectiveResolver, @@ -69,7 +71,6 @@ module.exports.define = function (config = {}) { logLevel: SILENT ? "error" : "info", clearScreen: false, cacheDir: cacheDir, - css: { devSourcemap: config.map !== undefined ? config.map : DEV, preprocessorOptions: { @@ -87,6 +88,13 @@ module.exports.define = function (config = {}) { "bulma", "addeus-common-library", ], + esbuildOptions: { + plugins: [ + esbuildDecorators({ + tsconfig: "./tsconfig.json", + }), + ], + }, }, resolve: { //dedupe: localDependencies, @@ -104,6 +112,7 @@ module.exports.define = function (config = {}) { sourcemap: config.map !== undefined ? config.map : !DEV, outDir: outDir, emptyOutDir: true, + esbuild: false, //chunkSizeWarningLimit: 3000, rollupOptions: { maxParallelFileOps: Math.max(1, cpus().length - 1), @@ -199,6 +208,20 @@ module.exports.define = function (config = {}) { isProduction: !DEV, }), + babel({ + filter: /\.tsx?$/, + babelConfig: { + babelrc: false, + configFile: false, + presets: ["@babel/preset-typescript"], + plugins: [ + "babel-plugin-reactgenie", + ["@babel/plugin-proposal-decorators", { legacy: true }], + ["@babel/plugin-proposal-class-properties", { loose: true }], + ], + }, + }), + createHtmlPlugin({ minify: !DEV, inject: { From 080d36a53737f603de59f4e3866b77d79062cf3b Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Thu, 3 Aug 2023 21:51:04 +0200 Subject: [PATCH 2/5] fix: eslint rule import --- .eslintrc.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c43b9d02..349d2d86 100755 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -33,7 +33,7 @@ module.exports = { disallowTypeAnnotations: false, }, ], - "@typescript-eslint/consistent-type-imports": false, + "@typescript-eslint/consistent-type-imports": 0, "prettier-vue/prettier": [ "error", { From 137970e6324a3d255a360b98c64227530e7f2920 Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Sat, 5 Aug 2023 14:51:04 +0200 Subject: [PATCH 3/5] Update var.ts --- stores/firestore/var.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/stores/firestore/var.ts b/stores/firestore/var.ts index 1174932b..5f32b3fc 100644 --- a/stores/firestore/var.ts +++ b/stores/firestore/var.ts @@ -110,16 +110,19 @@ function isUnparsedEqual(a: any, b: any, type: any): boolean { return a === b; } -export function Var() { +export function Var(type?: any) { return function (target: EntityBase, name: string) { - const metadata = Reflect.getMetadata("design:type", target, name); - if (metadata === undefined) - throw new Error( - "Property type is not set for " + target.constructor.name + ":" + name - ); - - let type = metadata; - if (metadata.type === Array) type = Array.of(metadata.elementType); + if (type === undefined) { + const metadata = Reflect.getMetadata("design:type", target, name); + if (metadata === undefined) + throw new Error( + "Property type is not set for " + target.constructor.name + ":" + name + ); + + + if (metadata.type === Array) type = Array.of(metadata.elementType); + else type = metadata; + } onInitialize(target, function (this: any, metadata: EntityMetaData) { if (metadata.properties[name] === undefined) metadata.properties[name] = {}; From f4df8a91e4bdf662c90d86ed6358868afef4f6ee Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Mon, 7 Aug 2023 09:59:10 +0200 Subject: [PATCH 4/5] fix: lint error in var --- stores/firestore/var.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stores/firestore/var.ts b/stores/firestore/var.ts index 5f32b3fc..8468bb93 100644 --- a/stores/firestore/var.ts +++ b/stores/firestore/var.ts @@ -118,8 +118,7 @@ export function Var(type?: any) { throw new Error( "Property type is not set for " + target.constructor.name + ":" + name ); - - + if (metadata.type === Array) type = Array.of(metadata.elementType); else type = metadata; } From db379aadf03e808af8844cc34d8671ddd0264d3b Mon Sep 17 00:00:00 2001 From: Maxime Allanic Date: Thu, 11 Jan 2024 14:13:25 +0100 Subject: [PATCH 5/5] fix: update workflows path --- .github/workflows/enable-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/enable-auto-merge.yml b/.github/workflows/enable-auto-merge.yml index 656237ed..53c47ee8 100644 --- a/.github/workflows/enable-auto-merge.yml +++ b/.github/workflows/enable-auto-merge.yml @@ -7,4 +7,4 @@ permissions: jobs: auto-merge: - uses: ../../workflows/enable-auto-merge.yml + uses: add-eus/library/workflows/enable-auto-merge.yml#master