Skip to content

Commit

Permalink
Merge develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy19961129 committed Jul 12, 2024
2 parents d875f57 + 1c1e4ca commit 2325f49
Show file tree
Hide file tree
Showing 20 changed files with 1,305 additions and 906 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
(await getProjects(ctx, projectFilter))
.forEach(element => {
projectNames.add(element);
projectNames.add(element.replaceAll('itmat-', ''));
});
return [
2,
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[.yml]
indent_size = 2

[*.md]
max_line_length = off
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
*.mjsx
*.cjs
*.cjsx
*.yaml
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ currently being supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 2.5.1 | :white_check_mark: |
| 2.6.0 | :white_check_mark: |
| < 2 | :x: |

## Reporting a Vulnerability
Expand Down
58 changes: 58 additions & 0 deletions dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "dependencies"
groups:
nx:
patterns:
- "nx"
- "@nx/*"
- "@jscutlery/semver"
lint:
patterns:
- "eslint*"
- "@typescript-eslint/*"
dev:
patterns:
- "commitlint"
- "@commitlint/*"
- "@swc/*"
- "@svgr/webpack"
- "esbuild*"
- "postcss"
- "prettier"
- "webpack"
- "verdaccio"
- "typscript"
test:
patterns:
- "jsdom"
- "sinon-chrome"
- "jest*"
- "babel-jest"
babel:
patterns:
- "babel*"
- "@babel/*"
types:
patterns:
- "@types/*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "actions"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
target-branch: "develop"
labels:
- "docker"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itmat-broker",
"version": "2.5.1",
"version": "2.6.0",
"private": true,
"license": "MIT",
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions packages/itmat-commons/src/utils/objStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ export class ObjectStore {
return result.etag;
}

public async copyObject(sourceBucket: string, sourceUri: string, targetBucket: string, targetUri: string) {
if (!this.client) {
throw new Error('Connection failed.');
}

const lowerSourceBucket = sourceBucket.toLowerCase();
const lowerTargetBucket = targetBucket.toLowerCase();

// Ensure target bucket exists
const bucketExists = await this.client.bucketExists(lowerTargetBucket);
if (!bucketExists) {
await this.client.makeBucket(lowerTargetBucket, this.config?.bucketRegion ?? '');
}
// Copy the object
const conds = new Minio.CopyConditions();
const result = await this.client.copyObject(lowerTargetBucket, targetUri, `/${lowerSourceBucket}/${sourceUri}`, conds);
return result.etag;
}

public async downloadFile(studyId: string, uri: string): Promise<Readable> {
if (!this.client) {
throw new Error('Connection failed.');
Expand Down
71 changes: 34 additions & 37 deletions packages/itmat-cores/src/GraphQLCore/studyCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ import { buildPipeline, dataStandardization } from '../utils/query';
import { DBType } from '../database/database';
import { ObjectStore } from '@itmat-broker/itmat-commons';

enum enumV2DataType {
'INT' = 'int',
'DEC' = 'dec',
'STR' = 'str',
'BOOL' = 'bool',
'DATE' = 'date',
'FILE' = 'file',
'JSON' = 'json',
'CAT' = 'cat'
}

export interface CreateFieldInput {
fieldId: string;
fieldName: string
tableName?: string
dataType: string;
dataType: enumV2DataType;
possibleValues?: ICategoricalOption[]
unit?: string
comments?: string
Expand All @@ -28,7 +39,7 @@ export interface EditFieldInput {
fieldId: string;
fieldName: string;
tableName?: string;
dataType: string;
dataType: enumV2DataType;
possibleValues?: ICategoricalOption[]
unit?: string
comments?: string
Expand Down Expand Up @@ -107,28 +118,35 @@ export class StudyCore {
return {
id: el.id,
code: el.code,
description: el.description
description: el.description,
life: {
createdTime: el.life.createdTime,
createdUser: el.life.createdUser,
deletedTime: el.life.deletedTime,
deletedUser: el.life.deletedUser
},
metadata: {}
};
}) : [],
dataType: (() => {
if (field.dataType === enumDataTypes.INTEGER) {
return 'int';
return enumV2DataType.INT;
} else if (field.dataType === enumDataTypes.DECIMAL) {
return 'dec';
return enumV2DataType.DEC;
} else if (field.dataType === enumDataTypes.STRING) {
return 'str';
return enumV2DataType.STR;
} else if (field.dataType === enumDataTypes.BOOLEAN) {
return 'bool';
return enumV2DataType.BOOL;
} else if (field.dataType === enumDataTypes.DATETIME) {
return 'date';
return enumV2DataType.DATE;
} else if (field.dataType === enumDataTypes.FILE) {
return 'file';
return enumV2DataType.FILE;
} else if (field.dataType === enumDataTypes.JSON) {
return 'json';
return enumV2DataType.JSON;
} else if (field.dataType === enumDataTypes.CATEGORICAL) {
return 'cat';
return enumV2DataType.CAT;
} else {
return 'str';
return enumV2DataType.STR;
}
})(),
dateAdded: field.life.createdTime.toString(),
Expand Down Expand Up @@ -654,7 +672,7 @@ export class StudyCore {
error.push(`Data type shouldn't be ${fieldEntry.dataType}: use 'int' for integer, 'dec' for decimal, 'str' for string, 'bool' for boolean, 'date' for datetime, 'file' for FILE, 'json' for json.`);
}
// check possiblevalues to be not-empty if datatype is categorical
if (fieldEntry.dataType === enumDataTypes.CATEGORICAL) {
if (fieldEntry.dataType === enumV2DataType.CAT) {
if (fieldEntry.possibleValues !== undefined && fieldEntry.possibleValues !== null) {
if (fieldEntry.possibleValues.length === 0) {
error.push(`${fieldEntry.fieldId}-${fieldEntry.fieldName}: possible values can't be empty if data type is categorical.`);
Expand All @@ -672,7 +690,7 @@ export class StudyCore {
fieldName: fieldEntry.fieldName,
tableName: null,
dataType: fieldEntry.dataType,
possibleValues: fieldEntry.dataType === enumDataTypes.CATEGORICAL ? fieldEntry.possibleValues : null,
possibleValues: fieldEntry.dataType === enumV2DataType.CAT ? fieldEntry.possibleValues : null,
unit: fieldEntry.unit,
comments: fieldEntry.comments,
metadata: {
Expand Down Expand Up @@ -808,27 +826,6 @@ export class StudyCore {
}
searchField.fieldId = fieldInput.fieldId;
searchField.fieldName = fieldInput.fieldName;
searchField.dataType = (() => {
if (fieldInput.dataType === 'int') {
return enumDataTypes.INTEGER;
} else if (fieldInput.dataType === 'dec') {
return enumDataTypes.DECIMAL;
} else if (fieldInput.dataType === 'str') {
return enumDataTypes.STRING;
} else if (fieldInput.dataType === 'bool') {
return enumDataTypes.BOOLEAN;
} else if (fieldInput.dataType === 'date') {
return enumDataTypes.DATETIME;
} else if (fieldInput.dataType === 'file') {
return enumDataTypes.FILE;
} else if (fieldInput.dataType === 'json') {
return enumDataTypes.JSON;
} else if (fieldInput.dataType === 'cat') {
return enumDataTypes.CATEGORICAL;
} else {
return enumDataTypes.STRING;
}
})();
if (fieldInput.tableName) {
searchField.metadata['tableName'] = fieldInput.tableName;
}
Expand All @@ -845,7 +842,7 @@ export class StudyCore {
searchField.comments = fieldInput.comments;
}

const { error } = await this.validateAndGenerateFieldEntry(searchField, requester);
const { error } = await this.validateAndGenerateFieldEntry({ ...this.fieldTypeConverter([searchField])[0], dataType: fieldInput.dataType }, requester);
if (error.length !== 0) {
throw new GraphQLError(JSON.stringify(error), { extensions: { code: errorCodes.CLIENT_MALFORMED_INPUT } });
}
Expand Down Expand Up @@ -1187,7 +1184,7 @@ export class StudyCore {
error = `Field ${dataClip.fieldId}: Cannot parse as decimal.`;
break;
}
if (!/^\d+(.\d+)?$/.test(dataClip.value)) {
if (!/^-?\d+(\.\d+)?$/.test(dataClip.value)) {
error = `Field ${dataClip.fieldId}: Cannot parse as decimal.`;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/itmat-cores/src/trpcCore/dataCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export class TRPCDataCore {
error = makeGenericReponse(counter.toString(), false, enumCoreErrors.CLIENT_MALFORMED_INPUT, `Field ${dataClip.fieldId}: Cannot parse as decimal.`);
break;
}
if (!/^\d+(.\d+)?$/.test(dataClip.value)) {
if (!/^-?\d+(\.\d+)?$/.test(dataClip.value)) {
error = makeGenericReponse(counter.toString(), false, enumCoreErrors.CLIENT_MALFORMED_INPUT, `Field ${dataClip.fieldId}: Cannot parse as decimal.`);
break;
}
Expand Down
Loading

0 comments on commit 2325f49

Please sign in to comment.