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

WIP (DO NOT MERGE) attempt to identify and solve of strictNullChecks errors (many) #475

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
fa995ce
stricter code checks (TypeScript and Lint)
danielweck Jul 10, 2019
8e78c19
Merge branch 'develop' into feature/stricterCode
danielweck Jul 11, 2019
d5b4b99
lint fixes: prefer-for-of and forin rules
danielweck Jul 24, 2019
289fcb2
disable lint code ordering
danielweck Jul 24, 2019
c692d57
added tslint language service (TS compiler hook)
danielweck Jul 24, 2019
9c593ed
noImplicitThis TypeScript rule
danielweck Jul 24, 2019
fb0046e
Merge branch 'develop' into feature/stricterCode
danielweck Jul 24, 2019
1638657
strictFunctionTypes fixes
danielweck Jul 24, 2019
e242a3f
noImplicitReturns fixes, as well as floating promises, missing async,…
danielweck Jul 24, 2019
6b7d152
noUnusedLocals fixes (many!)
danielweck Jul 24, 2019
cd3968d
noUnusedParameters fixes
danielweck Jul 24, 2019
17c4f14
TSLint and TypeScript strict compiler passes, except for
danielweck Jul 24, 2019
a23a31c
strictNullChecks fixes in unit tests, and various other linting (code…
danielweck Jul 24, 2019
6eb74a2
further strictNullChecks fixes in unit tests
danielweck Jul 24, 2019
4f50b20
last safe / consensual commit before strictNullChecks (which requires…
danielweck Jul 24, 2019
d1f652e
WIP strictNullChecks (many errors)
danielweck Jul 24, 2019
1e8a5ea
replaced any with proper OPDS type in API code
danielweck Jul 24, 2019
a5cff1e
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Jul 24, 2019
d617773
Merge branch 'develop' into feature/stricterCode
danielweck Jul 29, 2019
d13f15b
compile error fixed
danielweck Jul 29, 2019
bc572e4
Merge branch 'develop' into feature/stricterCode
danielweck Jul 29, 2019
d7ba053
fixed TS lint errors
danielweck Jul 29, 2019
216999e
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Jul 29, 2019
b1206f3
strongly-typed IPC messages (win and sync)
danielweck Jul 30, 2019
88cae1f
strongly-typed i18n / l10n / translator action (locale payload)
danielweck Jul 30, 2019
afdf5d8
Merge branch 'develop' into feature/stricterCode
danielweck Jul 31, 2019
ae53acd
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Jul 31, 2019
6130771
Merge branch 'develop' into feature/stricterCode
danielweck Aug 1, 2019
8283017
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 1, 2019
4a06ef0
merge conflict solved
danielweck Aug 1, 2019
45df05c
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 1, 2019
2ee24c6
removed unused import
danielweck Aug 1, 2019
8d2797f
Merge branch 'develop' into feature/stricterCode
danielweck Aug 1, 2019
a51ad8f
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 1, 2019
45d0760
Merge branch 'develop' into feature/stricterCode
danielweck Aug 1, 2019
4594290
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 1, 2019
305addf
Merge branch 'develop' into feature/stricterCode
danielweck Aug 2, 2019
beb728d
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 2, 2019
3f5a263
Merge branch 'develop' into feature/stricterCode
danielweck Aug 2, 2019
79dbc9e
fixed the TypeScript types for httpGet() (promisify)
danielweck Aug 2, 2019
b234b6b
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 2, 2019
b454ee6
Merge branch 'develop' into feature/stricterCode
danielweck Aug 6, 2019
55b4677
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 6, 2019
51a6da5
Merge branch 'develop' into feature/stricterCode
danielweck Aug 6, 2019
f6519b7
Merge branch 'feature/stricterCode' into feature/stricterCodeMore
danielweck Aug 6, 2019
31f18f8
Merge branch 'develop' into feature/stricterCodeMore
danielweck Sep 5, 2019
7a7cdf2
removed unused file
danielweck Sep 5, 2019
a35cec1
fixed typoo
danielweck Sep 5, 2019
fac1f19
correct fix for strictNullChecks
danielweck Sep 5, 2019
ab7242e
removed unnecessary changes
danielweck Sep 5, 2019
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
9 changes: 9 additions & 0 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions src/common/models/timestampable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
// ==LICENSE-END==

export interface Timestampable {
createdAt: string; // ISO 8601 string
updatedAt: string; // ISO 8601 string
createdAt?: string; // ISO 8601 string
updatedAt?: string; // ISO 8601 string
}
2 changes: 1 addition & 1 deletion src/common/redux/states/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
// ==LICENSE-END==

export interface LoggerState {
lastMessage: string;
lastMessage: string | null;
}
7 changes: 5 additions & 2 deletions src/common/services/opds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export class OPDSParser {
identifier: uuid.v4(),
title: entry.title,
description: entry.summary.content,
authors: [],
files: [],
// authors: [],
// files: [],
};
// To satisfy the static TypeScript compiler checks (strictNullChecks)
publication.authors = [];
publication.files = [];

// Fill authors
for (const author of entry.authors) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/api/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export class PublicationApi {

for (const path of paths) {
const newDoc = await this.catalogService.importFile(path);
newDocs.push(newDoc);
if (newDoc) {
newDocs.push(newDoc);
}
}

return newDocs.map((doc) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/api/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ReaderApi {
return this.locatorViewConverter.convertDocumentToView(savedDoc);
}

public async getLastReadingLocation(data: any): Promise<LocatorView> {
public async getLastReadingLocation(data: any): Promise<LocatorView | null> {
const { publication } = data;
const docs = await this.locatorRepository.findByPublicationIdentifierAndLocatorType(
publication.identifier,
Expand Down
16 changes: 9 additions & 7 deletions src/main/converter/opds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { OPDSPublication } from "@r2-opds-js/opds/opds2/opds2-publication";
// Logger
const debug = debug_("readium-desktop:main#services/lcp");

import { CoverView } from "readium-desktop/common/views/publication";

@injectable()
export class OpdsFeedViewConverter {
public convertDocumentToView(document: OpdsFeedDocument): OpdsFeedView {
Expand All @@ -46,7 +48,7 @@ export class OpdsFeedViewConverter {
return {
title,
url: link.Href,
publicationCount: (link.Children) ? link.Children.length : null,
publicationCount: (link.Children) ? link.Children.length : undefined,
};
}

Expand All @@ -61,13 +63,13 @@ export class OpdsFeedViewConverter {
tags = metadata.Subject.map((subject) => convertMultiLangStringToString(subject.Name));
}

let publishedAt = null;
let publishedAt: string | undefined;

if (metadata.PublicationDate) {
publishedAt = moment(metadata.PublicationDate).toISOString();
}

let cover = null;
let cover: CoverView | undefined;

if (publication.Images && publication.Images.length > 0) {
cover = {
Expand All @@ -76,8 +78,8 @@ export class OpdsFeedViewConverter {
}

// Get odps entry
let url = null;
let sampleUrl = null;
let url: string | undefined;
let sampleUrl: string | undefined;
const links = publication.Links.filter(
(link: any) => {
return (link.TypeLink.indexOf(";type=entry;profile=opds-catalog") > 0);
Expand All @@ -94,7 +96,7 @@ export class OpdsFeedViewConverter {
sampleUrl = sampleLinks[0].Href;
}

let base64OpdsPublication = null;
let base64OpdsPublication: string | undefined;
if (links.length > 0) {
url = links[0].Href;
} else {
Expand Down Expand Up @@ -142,7 +144,7 @@ export class OpdsFeedViewConverter {
buyUrl: buyLink && buyLink.Href,
borrowUrl: borrowLink && borrowLink.Href,
subscribeUrl: subscribeLink && subscribeLink.Href,
hasSample: sampleUrl && true,
hasSample: (typeof sampleUrl !== "undefined") && true,
base64OpdsPublication,
isFree,
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/db/document/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { IHttpGetResult } from "readium-desktop/common/utils/http";

interface Resources {
filePublication: string;
opdsPublication: string;
opdsPublication?: string;
}

export interface PublicationDocument extends Identifiable, Timestampable {
resources: Resources;
opdsPublication: any;
opdsPublication?: any;
title: string;
tags?: string[];
files?: File[];
Expand Down
2 changes: 2 additions & 0 deletions src/main/redux/sagas/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { all, call, take } from "redux-saga/effects";

import { I18NState } from "readium-desktop/common/redux/states/i18n";

import { I18NState } from "readium-desktop/common/redux/states/i18n";

export function* localeWatcher() {
while (true) {
const action: i18nActions.ActionLocale = yield take(i18nActions.ActionType.Set);
Expand Down
24 changes: 15 additions & 9 deletions src/main/services/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class CatalogService {
@inject("publication-repository")
private readonly publicationRepository!: PublicationRepository;

public async importFile(filePath: string, isLcpFile?: boolean): Promise<PublicationDocument> {
public async importFile(filePath: string, isLcpFile?: boolean): Promise<PublicationDocument | null> {
const ext = path.extname(filePath);

if (ext === ".lcpl" || (ext === ".part" && isLcpFile)) {
Expand All @@ -65,7 +65,7 @@ export class CatalogService {
return this.importEpubFile(filePath);
}

return null;
return Promise.resolve(null);
}

public async importOpdsEntry(url: string, downloadSample: boolean): Promise<THttpGetPublicationDocument> {
Expand Down Expand Up @@ -156,6 +156,9 @@ export class CatalogService {
debug("[END] Download publication", downloadUrl, newDownload);
// Import downloaded publication in catalog
let publicationDocument = await this.importFile(download.dstPath, isLcpFile);
if (!publicationDocument) {
return Promise.reject("!publicationDocument");
}

// Add opds publication serialization to resources
const jsonOpdsPublication = TAJSON.serialize(opdsPublication);
Expand Down Expand Up @@ -200,6 +203,9 @@ export class CatalogService {
* @return: Refreshed publication
*/
public async refreshPublicationMetadata(publication: Publication) {
if (!publication.files) {
return;
}
const pubPath = path.join(
this.publicationStorage.getRootPath(),
publication.files[0].url.substr(6),
Expand Down Expand Up @@ -238,7 +244,7 @@ export class CatalogService {
const lcpl = JSON.parse(buffer.toString());

// search the path of the epub file
let download: Download = null;
let download: Download | undefined;

if (lcpl.links) {
for (const link of lcpl.links) {
Expand Down Expand Up @@ -280,18 +286,18 @@ export class CatalogService {
.from(JSON.stringify(jsonParsedPublication))
.toString("base64");

const pubDocument = {
const pubDocument: PublicationDocument = {
identifier: uuid.v4(),
resources: {
filePublication: b64ParsedPublication,
opdsPublication: null,
opdsPublication: undefined,
},
title: convertMultiLangStringToString(parsedPublication.Metadata.Title),
tags: [],
files: [],
coverFile: null,
customCover: null,
} as PublicationDocument;
coverFile: undefined,
customCover: undefined,
};
pubDocument.files = [];

// Store publication on filesystem
debug("[START] Store publication on filesystem", filePath);
Expand Down
4 changes: 2 additions & 2 deletions src/main/services/lcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class LcpManager {

debug("Parse publication - START", epubPath);
const parsedPublication: Epub = await EpubParsePromise(epubPath);
let lcpInfo: LcpInfo = null;
let lcpInfo: LcpInfo | undefined;

if (parsedPublication.LCP) {
// Add Lcp info
Expand Down Expand Up @@ -286,7 +286,7 @@ export class LcpManager {
lsdStatus: any,
): Promise<THttpGetPublicationDocument> {
// Search LCPL license url
let lcplUrl: string = null;
let lcplUrl: string | undefined;

for (const link of lsdStatus.links) {
if (link.rel === "license") {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/components/dialog/SameFileImportConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class SameFileImportConfirm extends React.Component<Props> {
}

private addToCatalog() {
if (!this.props.importOpdsEntry) {
return;
}
this.props.importOpdsEntry(
{
url: this.props.publication.url,
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
Expand Down