Skip to content

Commit

Permalink
fix: sdk new package name and some small improvements (#1701)
Browse files Browse the repository at this point in the history
* fix local sdk generation after introducing some new parameters on the backend and do some cleanup of appendToArrayField endpoint usage

* bump sdk version and improve the local generation

* rename the scicat-sdk-ts to scicat-sdk-ts-angular

* fix linting issues

* add some improvements in the dataset sharing process suggested by sourcery-ai

* fix unit test types

* fix failing tests and add some small improvements

* try to revert the appendToDatasetArray changes

* fix failing tests
  • Loading branch information
martin-trajanovski authored Jan 23, 2025
1 parent 70d71d3 commit da67ff4
Show file tree
Hide file tree
Showing 127 changed files with 209 additions and 162 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@ngrx/router-store": "^16",
"@ngrx/store": "^16",
"@ngx-translate/core": "^16.0.4",
"@scicatproject/scicat-sdk-ts": "^4.8.3",
"@scicatproject/scicat-sdk-ts-angular": "^4.11.0",
"autolinker": "^4.0.0",
"deep-equal": "^2.0.5",
"exceljs": "^4.3.0",
Expand Down
14 changes: 7 additions & 7 deletions scripts/generate-nestjs-sdk.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ USER=`who am i | cut -d\ -f1`
echo -e "\nUser running the script: ${USER}"

echo -e "\nCleanup old files..."
rm -rf node_modules/@scicatproject/scicat-sdk-ts
rm -rf @scicatproject/scicat-sdk-ts
rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular
rm -rf @scicatproject/scicat-sdk-ts-angular

echo -e "\nGenerating the new sdk..."
docker run \
Expand All @@ -17,8 +17,8 @@ docker run \
openapitools/openapi-generator-cli:v7.9.0 generate \
-i http://host.docker.internal:3000/explorer-json \
-g typescript-angular \
-o local/@scicatproject/scicat-sdk-ts \
--additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true
-o local/@scicatproject/scicat-sdk-ts-angular \
--additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,npmVersion=10.8.2,withInterfaces=true

REMOVE_NPM_LINK=0
if ! command -v npm 2>&1 1>/dev/null
Expand All @@ -38,16 +38,16 @@ then
fi

echo -e "\nInstalling dependencies and building the sdk..."
cd @scicatproject/scicat-sdk-ts
cd @scicatproject/scicat-sdk-ts-angular
npm install
npm run build

echo -e "\nCopying the build files in node_modules..."
cd ../..
cp -rv @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts
cp -rv @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular

echo -e "\nAdjusting ownership to user ${USER}"
chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts
chown -Rv ${USER} node_modules/@scicatproject/scicat-sdk-ts-angular

echo -e "\nFinal cleanup..."
echo -e "Removing sdk folder"
Expand Down
26 changes: 14 additions & 12 deletions scripts/generate-nestjs-sdk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* NOTE: This file contains commands that generate new typescript-angular sdk against the running scicat backend
* which overwrites the node_modules/@scicatproject/scicat-sdk-ts for development purpose
* It should NOT be used in production because the real (@scicatproject/scicat-sdk-ts) npm package will be installed and used.
* which overwrites the node_modules/@scicatproject/scicat-sdk-ts-angular for development purpose
* It should NOT be used in production because the real (@scicatproject/scicat-sdk-ts-angular) npm package will be installed and used.
*/

const execSync = require("child_process").execSync;
Expand All @@ -20,31 +20,34 @@ function getCurrentDirectory() {
}

if (isWindows()) {

// NOTE: First do some cleanup before starting the generation
console.log("Cleanup old files...");
execSync(
"rm -rf node_modules/@scicatproject/scicat-sdk-ts && rm -rf @scicatproject/scicat-sdk-ts",
"rm -rf node_modules/@scicatproject/scicat-sdk-ts-angular && rm -rf @scicatproject/scicat-sdk-ts-angular",
{ encoding: "utf-8" },
);

console.log("Generating the new sdk...");
/**
* NOTE: parameter --skip-validate-spec is passed to avoid some errors like not supporting the "content" in the @ApiQuery() parameter that we use in the dataset v4 controller.
* This should not be a risk as after the generation we can get a feedback immediately if something is broken here when we run and test the frontend.
*/
const generationOutput = execSync(
`docker run --rm --add-host host.docker.internal:host-gateway -v "${getCurrentDirectory()}:/local" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/@scicatproject/scicat-sdk-ts --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts,supportsES6=true,npmVersion=10.8.2,withInterfaces=true`,
`docker run --rm --add-host host.docker.internal:host-gateway -v "${getCurrentDirectory()}:/local" openapitools/openapi-generator-cli:v7.9.0 generate -i http://host.docker.internal:3000/explorer-json -g typescript-angular -o local/@scicatproject/scicat-sdk-ts-angular --additional-properties=ngVersion=16.2.12,npmName=@scicatproject/scicat-sdk-ts-angular,supportsES6=true,npmVersion=10.8.2,withInterfaces=true,paramNaming=original,modelPropertyNaming=original,enumPropertyNaming=original --skip-validate-spec`,
{ encoding: "utf-8" },
);
console.log(generationOutput);

console.log("Installing dependencies and building the sdk...");
const installBuildOutput = execSync(
"cd @scicatproject/scicat-sdk-ts && npm install && npm run build",
"cd @scicatproject/scicat-sdk-ts-angular && npm install && npm run build",
{ encoding: "utf-8" },
);
);
console.log(installBuildOutput);

console.log("Copying the build files in node_modules...");
const copyToNodeModulesOutput = execSync(
"cp -r @scicatproject/scicat-sdk-ts/dist node_modules/@scicatproject/scicat-sdk-ts",
"cp -r @scicatproject/scicat-sdk-ts-angular/dist node_modules/@scicatproject/scicat-sdk-ts-angular",
{ encoding: "utf-8" },
);
console.log(copyToNodeModulesOutput);
Expand All @@ -55,14 +58,13 @@ if (isWindows()) {
});

console.log("Local SDK generation completed");

} else {
console.log("Your environment is a linux/unix");
console.log("Please run the following command on your terminal:");
console.log("> sudo -E ./scripts/generate-nestjs-sdk.bash");
console.log("");
console.log("IMPORTANT: the script runs under sudo. You will be asked your password.");
console.log(
"IMPORTANT: the script runs under sudo. You will be asked your password.",
);
console.log("");

}

2 changes: 1 addition & 1 deletion src/app/app-routing/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ActivatedRouteSnapshot,
RouterStateSnapshot,
} from "@angular/router";
import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";

/**
* Ensure that the current user is logged in
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MockStore } from "./shared/MockStubs";
import { APP_CONFIG } from "./app-config.module";
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
import { AppConfigService } from "app-config.service";
import { Configuration } from "@scicatproject/scicat-sdk-ts";
import { Configuration } from "@scicatproject/scicat-sdk-ts-angular";

describe("AppComponent", () => {
const getConfig = () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "state-management/selectors/user.selectors";
import { MessageType } from "state-management/models";
import { AppConfigService, AppConfig as Config } from "app-config.service";
import { Configuration } from "@scicatproject/scicat-sdk-ts";
import { Configuration } from "@scicatproject/scicat-sdk-ts-angular";

@Component({
selector: "app-root",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { APP_INITIALIZER, NgModule } from "@angular/core";
import { ExtraOptions, RouterModule } from "@angular/router";
import { StoreModule } from "@ngrx/store";
import { ApiModule, Configuration } from "@scicatproject/scicat-sdk-ts";
import { ApiModule, Configuration } from "@scicatproject/scicat-sdk-ts-angular";
import { routerReducer } from "@ngrx/router-store";
import { extModules } from "./build-specifics";
import { MatNativeDateModule } from "@angular/material/core";
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/admin-tab/admin-tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { take } from "rxjs/operators";
import {
CreateJobDto,
OutputDatasetObsoleteDto,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";
import { submitJobAction } from "state-management/actions/jobs.actions";
import {
selectCurrentDatablocks,
Expand Down
5 changes: 4 additions & 1 deletion src/app/datasets/archiving.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
import { JobsState } from "state-management/state/jobs.store";
import { ArchivingService } from "./archiving.service";
import { createMock, mockDataset } from "shared/MockStubs";
import { CreateJobDto, ReturnedUserDto } from "@scicatproject/scicat-sdk-ts";
import {
CreateJobDto,
ReturnedUserDto,
} from "@scicatproject/scicat-sdk-ts-angular";

describe("ArchivingService", () => {
let service: ArchivingService;
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/archiving.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { RetrieveDestinations } from "app-config.service";
import {
OutputDatasetObsoleteDto,
ReturnedUserDto,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";

@Injectable()
export class ArchivingService {
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/batch-view/batch-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { MatFormFieldModule } from "@angular/material/form-field";
import { MatChipsModule } from "@angular/material/chips";
import { MatInputModule } from "@angular/material/input";
import { AppConfigService } from "app-config.service";
import { DatasetsService } from "@scicatproject/scicat-sdk-ts";
import { DatasetsService } from "@scicatproject/scicat-sdk-ts-angular";

describe("BatchViewComponent", () => {
let component: BatchViewComponent;
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/batch-view/batch-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
selectIsAdmin,
selectProfile,
} from "state-management/selectors/user.selectors";
import { OutputDatasetObsoleteDto } from "@scicatproject/scicat-sdk-ts";
import { OutputDatasetObsoleteDto } from "@scicatproject/scicat-sdk-ts-angular";

@Component({
selector: "batch-view",
Expand Down
16 changes: 11 additions & 5 deletions src/app/datasets/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ import { MatIconModule } from "@angular/material/icon";
import { AppConfigService } from "app-config.service";
import { PageChangeEvent } from "shared/modules/table/table.component";
import {
CreateDerivedDatasetObsoleteDto,
DatasetsControllerCreateRequest,
ReturnedUserDto,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";

class MockMatDialog {
open() {
Expand Down Expand Up @@ -241,10 +241,10 @@ describe("DashboardComponent", () => {
authStrategy: "local",
});

const dataset: CreateDerivedDatasetObsoleteDto = {
const dataset: DatasetsControllerCreateRequest = {
accessGroups: [],
contactEmail: currentUser.email,
creationTime: new Date().toString(),
creationTime: new Date().toISOString(),
datasetName: "Test Name",
description: "Test description",
isPublished: false,
Expand All @@ -261,6 +261,8 @@ describe("DashboardComponent", () => {
scientificMetadata: {},
usedSoftware: ["test software"],
numberOfFilesArchived: 0,
creationLocation: undefined,
principalInvestigator: undefined,
};

component.currentUser = currentUser;
Expand All @@ -269,7 +271,11 @@ describe("DashboardComponent", () => {
component.openDialog();

expect(dispatchSpy).toHaveBeenCalledTimes(1);
expect(dispatchSpy).toHaveBeenCalledWith(addDatasetAction({ dataset }));
expect(dispatchSpy).toHaveBeenCalledWith(
addDatasetAction({
dataset: dataset,
}),
);
});
});

Expand Down
6 changes: 4 additions & 2 deletions src/app/datasets/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import {
OutputDatasetObsoleteDto,
ReturnedUserDto,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";
import {
selectColumnAction,
deselectColumnAction,
Expand Down Expand Up @@ -142,7 +142,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
const dataset = {
accessGroups: [],
contactEmail: email, // Required
creationTime: new Date().toString(), // Required
creationTime: new Date().toISOString(), // Required
datasetName: res.datasetName,
description: res.description,
isPublished: false,
Expand All @@ -158,6 +158,8 @@ export class DashboardComponent implements OnInit, OnDestroy {
investigator: email, // Required
scientificMetadata: {},
numberOfFilesArchived: 0, // Required
principalInvestigator: undefined, // Required
creationLocation: undefined, // Required
usedSoftware: res.usedSoftware
.split(",")
.map((entry: string) => entry.trim())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Input } from "@angular/core";
import { MatTableDataSource } from "@angular/material/table";
import { Datablock } from "@scicatproject/scicat-sdk-ts";
import { Datablock } from "@scicatproject/scicat-sdk-ts-angular";

@Component({
selector: "datablocks-table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MockUserApi,
} from "shared/MockStubs";
import { ActionDataset } from "./datafiles-action.interfaces";
import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";
import { AuthService } from "shared/services/auth/auth.service";

describe("1000: DatafilesActionComponent", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SimpleChanges,
} from "@angular/core";

import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";
import { ActionConfig, ActionDataset } from "./datafiles-action.interfaces";
import { DataFiles_File } from "datasets/datafiles/datafiles.interfaces";
import { AuthService } from "shared/services/auth/auth.service";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { RouterModule } from "@angular/router";
import { StoreModule } from "@ngrx/store";
import { MockMatDialogRef, MockUserApi } from "shared/MockStubs";
import { AppConfigService } from "app-config.service";
import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";

describe("DatafilesActionsComponent", () => {
let component: DatafilesActionsComponent;
Expand Down
2 changes: 1 addition & 1 deletion src/app/datasets/datafiles/datafiles.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { MatButtonModule } from "@angular/material/button";
import { AppConfigService } from "app-config.service";
import { MatDialogModule, MatDialogRef } from "@angular/material/dialog";
import { DatafilesActionsComponent } from "datasets/datafiles-actions/datafiles-actions.component";
import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";
import { AuthService } from "shared/services/auth/auth.service";
import { FileSizePipe } from "shared/pipes/filesize.pipe";

Expand Down
5 changes: 4 additions & 1 deletion src/app/datasets/datafiles/datafiles.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
selectIsLoading,
selectIsLoggedIn,
} from "state-management/selectors/user.selectors";
import { CreateUserJWT, UsersService } from "@scicatproject/scicat-sdk-ts";
import {
CreateUserJWT,
UsersService,
} from "@scicatproject/scicat-sdk-ts-angular";
import { FileSizePipe } from "shared/pipes/filesize.pipe";
import { MatCheckboxChange } from "@angular/material/checkbox";
import { MatDialog } from "@angular/material/dialog";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { MockActivatedRoute, mockDataset } from "shared/MockStubs";
import { DialogComponent } from "shared/modules/dialog/dialog.component";
import { AppConfigService } from "app-config.service";
import { AttachmentService } from "shared/services/attachment.service";
import { OutputDatasetObsoleteDto } from "@scicatproject/scicat-sdk-ts";
import { OutputDatasetObsoleteDto } from "@scicatproject/scicat-sdk-ts-angular";
import {
TranslateLoader,
TranslateModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
ProposalClass,
ReturnedUserDto,
SampleClass,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";
import { AttachmentService } from "shared/services/attachment.service";
import { TranslateService } from "@ngx-translate/core";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { MatButtonModule } from "@angular/material/button";
import { MockStore } from "@ngrx/store/testing";
import { AppConfigService } from "app-config.service";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { UsersService } from "@scicatproject/scicat-sdk-ts";
import { UsersService } from "@scicatproject/scicat-sdk-ts-angular";

describe("DetailsDashboardComponent", () => {
let component: DatasetDetailsDashboardComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Store } from "@ngrx/store";
import {
OutputDatasetObsoleteDto,
UsersService,
} from "@scicatproject/scicat-sdk-ts";
} from "@scicatproject/scicat-sdk-ts-angular";
import { selectCurrentDataset } from "state-management/selectors/datasets.selectors";
import {
selectIsAdmin,
Expand Down
Loading

0 comments on commit da67ff4

Please sign in to comment.