Skip to content

Commit

Permalink
Merge pull request #2432 from ideafast/feat/trpc-drive
Browse files Browse the repository at this point in the history
Feat/trpc drive
  • Loading branch information
fguitton authored Jul 10, 2024
2 parents 9bf7b93 + b4fbe08 commit 34ec740
Show file tree
Hide file tree
Showing 22 changed files with 2,209 additions and 194 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"@ideafast/idgen": "0.1.1",
"@swc/helpers": "0.5.10",
"@trpc/server": "10.45.2",
"JSONStream": "1.3.5",
"antd": "5.16.4",
"apollo-upload-client": "18.0.1",
"axios": "1.6.8",
Expand Down Expand Up @@ -133,12 +134,12 @@
"hi-base32": "0.5.1",
"http-proxy-middleware": "3.0.0",
"https-browserify": "1.0.0",
"JSONStream": "1.3.5",
"jsonwebtoken": "9.0.2",
"jstat": "1.9.6",
"lint-staged": "15.2.2",
"minio": "7.1.3",
"mongodb": "6.5.0",
"multer": "1.4.3",
"nodemailer": "6.9.13",
"passport": "0.7.0",
"path-browserify": "1.0.1",
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
26 changes: 13 additions & 13 deletions packages/itmat-cores/src/GraphQLCore/studyCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ export class StudyCore {
}
}

fieldRecords = await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dateDeleted: null, dataVersion: { $in: availableDataVersions } }
fieldRecords = (await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dataVersion: { $in: availableDataVersions } }
}, {
$sort: { dateAdded: -1 }
$sort: { 'life.createdTime': -1 }
}, {
$group: {
_id: '$fieldId',
Expand All @@ -394,7 +394,7 @@ export class StudyCore {
}
}, {
$sort: { fieldId: 1 }
}]).toArray();
}]).toArray()).filter(el => el.life.deletedTime === null);
if (queryString.data_requested && queryString.data_requested.length > 0) {
fieldRecords = fieldRecords.filter(el => (queryString.data_requested || []).includes(el.fieldId));
}
Expand All @@ -409,10 +409,10 @@ export class StudyCore {
// unversioned data: metadatafilter for versioned data and all unversioned tags
if (versionId === null && aggregatedPermissions.hasVersioned) {
availableDataVersions.push(null);
fieldRecords = await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dateDeleted: null, dataVersion: { $in: availableDataVersions } }
fieldRecords = (await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dataVersion: { $in: availableDataVersions } }
}, {
$sort: { dateAdded: -1 }
$sort: { 'life.createdTime': -1 }
}, {
$match: {
$or: [
Expand All @@ -431,18 +431,18 @@ export class StudyCore {
}
}, {
$sort: { fieldId: 1 }
}]).toArray();
}]).toArray()).filter(el => el.life.deletedTime === null);
if (queryString.data_requested && queryString.data_requested?.length > 0) {
fieldRecords = fieldRecords.filter(el => (queryString.data_requested || []).includes(el.fieldId));
}
} else if (versionId === undefined || versionId === '-1') {
if (versionId === '-1') {
availableDataVersions = availableDataVersions.length !== 0 ? [availableDataVersions[availableDataVersions.length - 1]] : [];
}
fieldRecords = await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dateDeleted: null, dataVersion: { $in: availableDataVersions } }
fieldRecords = (await this.db.collections.field_dictionary_collection.aggregate<IField>([{
$match: { studyId: studyId, dataVersion: { $in: availableDataVersions } }
}, {
$sort: { dateAdded: -1 }
$sort: { 'life.createdTime': -1 }
}, {
$match: {
$or: [
Expand All @@ -460,7 +460,7 @@ export class StudyCore {
}
}, {
$sort: { fieldId: 1 }
}]).toArray();
}]).toArray()).filter(el => el.life.deletedTime === null);
if (queryString.data_requested && queryString.data_requested?.length > 0) {
fieldRecords = fieldRecords.filter(el => (queryString.data_requested || []).includes(el.fieldId));
}
Expand Down Expand Up @@ -492,7 +492,7 @@ export class StudyCore {
fieldRecords = fieldRecords.filter(el => (queryString.data_requested || []).includes(el.fieldId));
}
}

console.log(fieldRecords);
// TODO: placeholder for metadata filter
// if (queryString.metadata) {
// metadataFilter = { $and: queryString.metadata.map((el) => translateMetadata(el)) };
Expand Down
8 changes: 5 additions & 3 deletions packages/itmat-cores/src/database/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IField, IFile, IJobEntry, ILogEntry, IOrganisation, IProject, IPubkey, IQueryEntry, IRole, IStudy, IUser, IStandardization, IConfig, IData } from '@itmat-broker/itmat-types';
import type { IField, IFile, IJobEntry, ILogEntry, IOrganisation, IProject, IPubkey, IQueryEntry, IRole, IStudy, IUser, IStandardization, IConfig, IData, IDrive } from '@itmat-broker/itmat-types';
import { Database as DatabaseBase, IDatabaseBaseConfig } from '@itmat-broker/itmat-commons';
import type { Collection } from 'mongodb';

Expand All @@ -17,7 +17,8 @@ export interface IDatabaseConfig extends IDatabaseBaseConfig {
pubkeys_collection: string,
data_collection: string,
standardizations_collection: string,
configs_collection: string
configs_collection: string,
drives_collection: string
};
}

Expand All @@ -35,6 +36,7 @@ export interface IDatabaseCollectionConfig {
pubkeys_collection: Collection<IPubkey>,
data_collection: Collection<IData>,
standardizations_collection: Collection<IStandardization>,
configs_collection: Collection<IConfig>
configs_collection: Collection<IConfig>,
drives_collection: Collection<IDrive>
}
export type DBType = DatabaseBase<IDatabaseBaseConfig, IDatabaseCollectionConfig>;
4 changes: 4 additions & 0 deletions packages/itmat-cores/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export * from './GraphQLCore/standardizationCore';
export * from './GraphQLCore/studyCore';
export * from './GraphQLCore/userCore';
// TRPCCore
export * from './trpcCore/configCore';
export * from './trpcCore/driveCore';
export * from './trpcCore/fileCore';
export * from './trpcCore/studyCore';
export * from './trpcCore/userCore';
export * from './rest/fileDownload';
export * from './authentication/pubkeyAuthentication';
Expand Down
Loading

0 comments on commit 34ec740

Please sign in to comment.