Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: setup utils module with type exports and usage example #2944

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/helloworld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"checkFormat": "prettier src --check --config ../.prettierrc.js"
},
"dependencies": {
"molgenis-components": "*",
"graphql-request": "5.2.0",
"meta-data-utils": "*",
"molgenis-components": "*",
"vue": "3.3.4",
"vue-router": "4.2.5"
},
Expand Down
15 changes: 14 additions & 1 deletion apps/helloworld/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<template>
<Molgenis id="__top" v-model="session">
<router-view :session="session" :page="page" />

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline could be removed

<h3>{{ msg }}</h3>
</Molgenis>
</template>

<script setup>
<script setup lang="ts">
import { Molgenis } from "molgenis-components";
import { sayHello, isEmpty } from "meta-data-utils";
import type { ISetting } from "meta-data-utils";
import { ref } from "vue";

const msg = sayHello("World");

const setting: ISetting = {
key: "test",
value: "test",
};

console.log("is setting empty : ", isEmpty(setting));

const session = ref(null);
const page = ref(null);
</script>
27 changes: 27 additions & 0 deletions apps/meta-data-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "meta-data-utils",
"private": true,
"version": "0.0.0",
"type": "module",
"files": [
"dist"
],
"main": "dist/meta-data-utils.umd.cjs",
"module": "dist/meta-data-utils.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/meta-data-utils.js",
"require": "./dist/meta-data-utils.umd.cjs"
}
},
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "4.4.5",
"vite-plugin-dts": "3.6.3"
}
}
77 changes: 77 additions & 0 deletions apps/meta-data-utils/src/fieldHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { IColumn } from "./types";

export const fieldTypes = () => {
return [
"BOOL",
"BOOL_ARRAY",
"DATE",
"DATE_ARRAY",
"DATETIME",
"AUTO_ID",
"DATETIME_ARRAY",
"DECIMAL",
"DECIMAL_ARRAY",
"EMAIL",
"EMAIL_ARRAY",
"FILE",
"HEADING",
"HYPERLINK",
"HYPERLINK_ARRAY",
"INT",
"INT_ARRAY",
"LONG",
"LONG_ARRAY",
"ONTOLOGY",
"ONTOLOGY_ARRAY",
"REF",
"REF_ARRAY",
"REFBACK",
"STRING",
"STRING_ARRAY",
"TEXT",
"TEXT_ARRAY",
"UUID",
"UUID_ARRAY",
];
};

export const isEmpty = (obj: object) => {
for (const prop in obj) {
if (Object.hasOwnProperty.call(obj, prop)) {
return false;
}
}

return true;
};

export const isValueType = (column: IColumn) => {
return (
column.columnType === "STRING" ||
column.columnType === "TEXT" ||
column.columnType === "EMAIL" ||
column.columnType === "HYPERLINK" ||
column.columnType === "UUID" ||
column.columnType === "DATE" ||
column.columnType === "DATETIME" ||
column.columnType === "INT" ||
column.columnType === "LONG" ||
column.columnType === "DECIMAL"
);
};

export const isRefType = (column: IColumn) => {
return (
column.columnType === "REF" ||
column.columnType === "REFBACK" ||
column.columnType === "ONTOLOGY"
);
};

export const isArrayType = (column: IColumn) => {
return column.columnType.endsWith("_ARRAY");
};

export const isFileType = (column: IColumn) => {
return column.columnType === "FILE";
};
23 changes: 23 additions & 0 deletions apps/meta-data-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const sayHello = (name: string): string => {
return `Hello ${name}`;
};

export {
buildRecordDetailsQueryFields,
buildRecordListQueryFields,
extractExternalSchemas,
extractKeyFromRecord,
buildFilterFromKeysObject,
getTableMetaData,
} from "./tableQuery";

export type {
IColumn,
ILocale,
ISetting,
ISchemaMetaData,
ITableMetaData,
KeyObject,
} from "./types";

export { fieldTypes, isEmpty, isValueType } from "./fieldHelpers";
Loading