Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Rename Export DTOs (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Apr 19, 2022
1 parent fee2f78 commit ad37de9
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion common/spec/services/export.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Utils } from "jslib-common/misc/utils";
import { Cipher } from "jslib-common/models/domain/cipher";
import { EncString } from "jslib-common/models/domain/encString";
import { Login } from "jslib-common/models/domain/login";
import { CipherWithIds as CipherExport } from "jslib-common/models/export/cipherWithIds";
import { CipherWithIdExport as CipherExport } from "jslib-common/models/export/cipherWithIdsExport";
import { CipherView } from "jslib-common/models/view/cipherView";
import { LoginView } from "jslib-common/models/view/loginView";
import { ExportService } from "jslib-common/services/export.service";
Expand Down
30 changes: 15 additions & 15 deletions common/src/importers/bitwardenJsonImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { CryptoService } from "../abstractions/crypto.service";
import { I18nService } from "../abstractions/i18n.service";
import { EncString } from "../models/domain/encString";
import { ImportResult } from "../models/domain/importResult";
import { CipherWithIds } from "../models/export/cipherWithIds";
import { CollectionWithId } from "../models/export/collectionWithId";
import { FolderWithId } from "../models/export/folderWithId";
import { CipherWithIdExport } from "../models/export/cipherWithIdsExport";
import { CollectionWithIdExport } from "../models/export/collectionWithIdExport";
import { FolderWithIdExport } from "../models/export/folderWithIdExport";

import { BaseImporter } from "./baseImporter";
import { Importer } from "./importer";
Expand Down Expand Up @@ -59,8 +59,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
const groupingsMap = new Map<string, number>();

if (this.organization && this.results.collections != null) {
for (const c of this.results.collections as CollectionWithId[]) {
const collection = CollectionWithId.toDomain(c);
for (const c of this.results.collections as CollectionWithIdExport[]) {
const collection = CollectionWithIdExport.toDomain(c);
if (collection != null) {
collection.id = null;
collection.organizationId = this.organizationId;
Expand All @@ -70,8 +70,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
}
}
} else if (!this.organization && this.results.folders != null) {
for (const f of this.results.folders as FolderWithId[]) {
const folder = FolderWithId.toDomain(f);
for (const f of this.results.folders as FolderWithIdExport[]) {
const folder = FolderWithIdExport.toDomain(f);
if (folder != null) {
folder.id = null;
const view = await folder.decrypt();
Expand All @@ -81,8 +81,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
}
}

for (const c of this.results.items as CipherWithIds[]) {
const cipher = CipherWithIds.toDomain(c);
for (const c of this.results.items as CipherWithIdExport[]) {
const cipher = CipherWithIdExport.toDomain(c);
// reset ids incase they were set for some reason
cipher.id = null;
cipher.folderId = null;
Expand Down Expand Up @@ -121,8 +121,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
private parseDecrypted() {
const groupingsMap = new Map<string, number>();
if (this.organization && this.results.collections != null) {
this.results.collections.forEach((c: CollectionWithId) => {
const collection = CollectionWithId.toView(c);
this.results.collections.forEach((c: CollectionWithIdExport) => {
const collection = CollectionWithIdExport.toView(c);
if (collection != null) {
collection.id = null;
collection.organizationId = null;
Expand All @@ -131,8 +131,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
}
});
} else if (!this.organization && this.results.folders != null) {
this.results.folders.forEach((f: FolderWithId) => {
const folder = FolderWithId.toView(f);
this.results.folders.forEach((f: FolderWithIdExport) => {
const folder = FolderWithIdExport.toView(f);
if (folder != null) {
folder.id = null;
groupingsMap.set(f.id, this.result.folders.length);
Expand All @@ -141,8 +141,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
});
}

this.results.items.forEach((c: CipherWithIds) => {
const cipher = CipherWithIds.toView(c);
this.results.items.forEach((c: CipherWithIdExport) => {
const cipher = CipherWithIdExport.toView(c);
// reset ids incase they were set for some reason
cipher.id = null;
cipher.folderId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Card as CardDomain } from "../domain/card";
import { EncString } from "../domain/encString";
import { CardView } from "../view/cardView";

export class Card {
static template(): Card {
const req = new Card();
export class CardExport {
static template(): CardExport {
const req = new CardExport();
req.cardholderName = "John Doe";
req.brand = "visa";
req.number = "4242424242424242";
Expand All @@ -14,7 +14,7 @@ export class Card {
return req;
}

static toView(req: Card, view = new CardView()) {
static toView(req: CardExport, view = new CardView()) {
view.cardholderName = req.cardholderName;
view.brand = req.brand;
view.number = req.number;
Expand All @@ -24,7 +24,7 @@ export class Card {
return view;
}

static toDomain(req: Card, domain = new CardDomain()) {
static toDomain(req: CardExport, domain = new CardDomain()) {
domain.cardholderName = req.cardholderName != null ? new EncString(req.cardholderName) : null;
domain.brand = req.brand != null ? new EncString(req.brand) : null;
domain.number = req.number != null ? new EncString(req.number) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { Cipher as CipherDomain } from "../domain/cipher";
import { EncString } from "../domain/encString";
import { CipherView } from "../view/cipherView";

import { Card } from "./card";
import { Field } from "./field";
import { Identity } from "./identity";
import { Login } from "./login";
import { SecureNote } from "./secureNote";

export class Cipher {
static template(): Cipher {
const req = new Cipher();
import { CardExport } from "./cardExport";
import { FieldExport } from "./fieldExport";
import { IdentityExport } from "./identityExport";
import { LoginExport } from "./loginExport";
import { SecureNoteExport } from "./secureNoteExport";

export class CipherExport {
static template(): CipherExport {
const req = new CipherExport();
req.organizationId = null;
req.collectionIds = null;
req.folderId = null;
Expand All @@ -29,7 +29,7 @@ export class Cipher {
return req;
}

static toView(req: Cipher, view = new CipherView()) {
static toView(req: CipherExport, view = new CipherView()) {
view.type = req.type;
view.folderId = req.folderId;
if (view.organizationId == null) {
Expand All @@ -45,28 +45,28 @@ export class Cipher {
view.reprompt = req.reprompt ?? CipherRepromptType.None;

if (req.fields != null) {
view.fields = req.fields.map((f) => Field.toView(f));
view.fields = req.fields.map((f) => FieldExport.toView(f));
}

switch (req.type) {
case CipherType.Login:
view.login = Login.toView(req.login);
view.login = LoginExport.toView(req.login);
break;
case CipherType.SecureNote:
view.secureNote = SecureNote.toView(req.secureNote);
view.secureNote = SecureNoteExport.toView(req.secureNote);
break;
case CipherType.Card:
view.card = Card.toView(req.card);
view.card = CardExport.toView(req.card);
break;
case CipherType.Identity:
view.identity = Identity.toView(req.identity);
view.identity = IdentityExport.toView(req.identity);
break;
}

return view;
}

static toDomain(req: Cipher, domain = new CipherDomain()) {
static toDomain(req: CipherExport, domain = new CipherDomain()) {
domain.type = req.type;
domain.folderId = req.folderId;
if (domain.organizationId == null) {
Expand All @@ -78,21 +78,21 @@ export class Cipher {
domain.reprompt = req.reprompt ?? CipherRepromptType.None;

if (req.fields != null) {
domain.fields = req.fields.map((f) => Field.toDomain(f));
domain.fields = req.fields.map((f) => FieldExport.toDomain(f));
}

switch (req.type) {
case CipherType.Login:
domain.login = Login.toDomain(req.login);
domain.login = LoginExport.toDomain(req.login);
break;
case CipherType.SecureNote:
domain.secureNote = SecureNote.toDomain(req.secureNote);
domain.secureNote = SecureNoteExport.toDomain(req.secureNote);
break;
case CipherType.Card:
domain.card = Card.toDomain(req.card);
domain.card = CardExport.toDomain(req.card);
break;
case CipherType.Identity:
domain.identity = Identity.toDomain(req.identity);
domain.identity = IdentityExport.toDomain(req.identity);
break;
}

Expand All @@ -106,11 +106,11 @@ export class Cipher {
name: string;
notes: string;
favorite: boolean;
fields: Field[];
login: Login;
secureNote: SecureNote;
card: Card;
identity: Identity;
fields: FieldExport[];
login: LoginExport;
secureNote: SecureNoteExport;
card: CardExport;
identity: IdentityExport;
reprompt: CipherRepromptType;

// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
Expand All @@ -132,24 +132,24 @@ export class Cipher {

if (o.fields != null) {
if (o instanceof CipherView) {
this.fields = o.fields.map((f) => new Field(f));
this.fields = o.fields.map((f) => new FieldExport(f));
} else {
this.fields = o.fields.map((f) => new Field(f));
this.fields = o.fields.map((f) => new FieldExport(f));
}
}

switch (o.type) {
case CipherType.Login:
this.login = new Login(o.login);
this.login = new LoginExport(o.login);
break;
case CipherType.SecureNote:
this.secureNote = new SecureNote(o.secureNote);
this.secureNote = new SecureNoteExport(o.secureNote);
break;
case CipherType.Card:
this.card = new Card(o.card);
this.card = new CardExport(o.card);
break;
case CipherType.Identity:
this.identity = new Identity(o.identity);
this.identity = new IdentityExport(o.identity);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Cipher as CipherDomain } from "../domain/cipher";
import { CipherView } from "../view/cipherView";

import { Cipher } from "./cipher";
import { CipherExport } from "./cipherExport";

export class CipherWithIds extends Cipher {
export class CipherWithIdExport extends CipherExport {
id: string;
collectionIds: string[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { Collection as CollectionDomain } from "../domain/collection";
import { EncString } from "../domain/encString";
import { CollectionView } from "../view/collectionView";

export class Collection {
static template(): Collection {
const req = new Collection();
export class CollectionExport {
static template(): CollectionExport {
const req = new CollectionExport();
req.organizationId = "00000000-0000-0000-0000-000000000000";
req.name = "Collection name";
req.externalId = null;
return req;
}

static toView(req: Collection, view = new CollectionView()) {
static toView(req: CollectionExport, view = new CollectionView()) {
view.name = req.name;
view.externalId = req.externalId;
if (view.organizationId == null) {
Expand All @@ -20,7 +20,7 @@ export class Collection {
return view;
}

static toDomain(req: Collection, domain = new CollectionDomain()) {
static toDomain(req: CollectionExport, domain = new CollectionDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
domain.externalId = req.externalId;
if (domain.organizationId == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Collection as CollectionDomain } from "../domain/collection";
import { CollectionView } from "../view/collectionView";

import { Collection } from "./collection";
import { CollectionExport } from "./collectionExport";

export class CollectionWithId extends Collection {
export class CollectionWithIdExport extends CollectionExport {
id: string;

// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventType } from "../../enums/eventType";
import { EventView } from "../view/eventView";

export class Event {
export class EventExport {
message: string;
appIcon: string;
appName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import { EncString } from "../domain/encString";
import { Field as FieldDomain } from "../domain/field";
import { FieldView } from "../view/fieldView";

export class Field {
static template(): Field {
const req = new Field();
export class FieldExport {
static template(): FieldExport {
const req = new FieldExport();
req.name = "Field name";
req.value = "Some value";
req.type = FieldType.Text;
return req;
}

static toView(req: Field, view = new FieldView()) {
static toView(req: FieldExport, view = new FieldView()) {
view.type = req.type;
view.value = req.value;
view.name = req.name;
view.linkedId = req.linkedId;
return view;
}

static toDomain(req: Field, domain = new FieldDomain()) {
static toDomain(req: FieldExport, domain = new FieldDomain()) {
domain.type = req.type;
domain.value = req.value != null ? new EncString(req.value) : null;
domain.name = req.name != null ? new EncString(req.name) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { EncString } from "../domain/encString";
import { Folder as FolderDomain } from "../domain/folder";
import { FolderView } from "../view/folderView";

export class Folder {
static template(): Folder {
const req = new Folder();
export class FolderExport {
static template(): FolderExport {
const req = new FolderExport();
req.name = "Folder name";
return req;
}

static toView(req: Folder, view = new FolderView()) {
static toView(req: FolderExport, view = new FolderView()) {
view.name = req.name;
return view;
}

static toDomain(req: Folder, domain = new FolderDomain()) {
static toDomain(req: FolderExport, domain = new FolderDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
return domain;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Folder as FolderDomain } from "../domain/folder";
import { FolderView } from "../view/folderView";

import { Folder } from "./folder";
import { FolderExport } from "./folderExport";

export class FolderWithId extends Folder {
export class FolderWithIdExport extends FolderExport {
id: string;

// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
Expand Down
Loading

0 comments on commit ad37de9

Please sign in to comment.