Skip to content

Commit

Permalink
feat(core): Update to TypeScript 3.8
Browse files Browse the repository at this point in the history
Relates to #286
  • Loading branch information
michaelbromley committed Apr 6, 2020
1 parent 38b375f commit e255674
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ts-jest": "^25.2.1",
"ts-node": "^8.4.1",
"tslint": "^5.11.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-ui-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@vendure/core": "^0.10.1",
"express": "^4.16.4",
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"dependencies": {
"fs-extra": "^9.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@
"puppeteer": "^2.1.1",
"rimraf": "^3.0.0",
"tslint": "^6.1.0",
"typescript": "~3.7.5"
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/asset-server-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"express": "^4.16.4",
"node-fetch": "^2.6.0",
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"dependencies": {
"fs-extra": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
],
"devDependencies": {
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
"rimraf": "^3.0.0",
"sql.js": "1.1.0",
"sqlite3": "^4.0.6",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
3 changes: 2 additions & 1 deletion packages/core/src/common/types/locale-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LanguageCode } from '@vendure/common/lib/generated-types';
import { CustomFieldsObject, ID } from '@vendure/common/lib/shared-types';

import { VendureEntity } from '../../entity/base/base.entity';
import { TranslatableRelationsKeys } from '../../service/helpers/utils/translate-entity';

import { UnwrappedArray } from './common-types';
Expand All @@ -19,7 +20,7 @@ export type NonTranslateableKeys<T> = { [K in keyof T]: T[K] extends LocaleStrin
/**
* Entities which have localizable string properties should implement this type.
*/
export interface Translatable { translations: Array<Translation<any>>; }
export interface Translatable { translations: Array<Translation<VendureEntity>>; }

export type TranslationCustomFields<T> = { [K in keyof T]: K extends 'customFields' ? K : never }[keyof T];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ID, Type } from '@vendure/common/lib/shared-types';
import { Connection } from 'typeorm';

import { Translatable, TranslatedInput, Translation } from '../../../common/types/locale-types';
import { VendureEntity } from '../../../entity/base/base.entity';
import { patchEntity } from '../utils/patch-entity';

import { TranslationDiffer } from './translation-differ';
Expand Down Expand Up @@ -32,7 +33,7 @@ export class TranslatableSaver {
* Create a translatable entity, including creating any translation entities according
* to the `translations` array.
*/
async create<T extends Translatable>(options: CreateTranslatableOptions<T>): Promise<T> {
async create<T extends Translatable & VendureEntity>(options: CreateTranslatableOptions<T>): Promise<T> {
const { entityType, translationType, input, beforeSave, typeOrmSubscriberData } = options;

const entity = new entityType(input);
Expand All @@ -57,7 +58,7 @@ export class TranslatableSaver {
* Update a translatable entity. Performs a diff of the `translations` array in order to
* perform the correct operation on the translations.
*/
async update<T extends Translatable>(options: UpdateTranslatableOptions<T>): Promise<T> {
async update<T extends Translatable & VendureEntity>(options: UpdateTranslatableOptions<T>): Promise<T> {
const { entityType, translationType, input, beforeSave, typeOrmSubscriberData } = options;
const existingTranslations = await this.connection.getRepository(translationType).find({
where: { base: input.id },
Expand Down
15 changes: 11 additions & 4 deletions packages/core/src/service/helpers/utils/translate-entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LanguageCode } from '@vendure/common/lib/generated-types';

import { DEFAULT_LANGUAGE_CODE } from '../../../common/constants';
import { Translatable, Translation } from '../../../common/types/locale-types';
import { VendureEntity } from '../../../entity/base/base.entity';
import { CollectionTranslation } from '../../../entity/collection/collection-translation.entity';
import { Collection } from '../../../entity/collection/collection.entity';
import { ProductOptionTranslation } from '../../../entity/product-option/product-option-translation.entity';
Expand Down Expand Up @@ -130,23 +131,29 @@ describe('translateEntity()', () => {
});

describe('translateDeep()', () => {
interface TestProduct {
interface TestProduct extends VendureEntity {
singleTestVariant: TestVariant;
singleRealVariant: ProductVariant;
}

class TestProductEntity implements Translatable {
class TestProductEntity extends VendureEntity implements Translatable {
constructor() {
super();
}
id: string;
singleTestVariant: TestVariantEntity;
singleRealVariant: ProductVariant;
translations: Array<Translation<TestProduct>>;
}

interface TestVariant {
interface TestVariant extends VendureEntity {
singleOption: ProductOption;
}

class TestVariantEntity implements Translatable {
class TestVariantEntity extends VendureEntity implements Translatable {
constructor() {
super();
}
id: string;
singleOption: ProductOption;
translations: Array<Translation<TestVariant>>;
Expand Down
15 changes: 8 additions & 7 deletions packages/core/src/service/helpers/utils/translate-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEFAULT_LANGUAGE_CODE } from '../../../common/constants';
import { InternalServerError } from '../../../common/error/errors';
import { UnwrappedArray } from '../../../common/types/common-types';
import { Translatable, Translated, Translation } from '../../../common/types/locale-types';
import { VendureEntity } from '../../../entity/base/base.entity';

// prettier-ignore
export type TranslatableRelationsKeys<T> = {
Expand Down Expand Up @@ -34,15 +35,15 @@ export type DeepTranslatableRelations<T> = Array<TranslatableRelationsKeys<T> |
* Converts a Translatable entity into the public-facing entity by unwrapping
* the translated strings from the matching Translation entity.
*/
export function translateEntity<T extends Translatable>(
export function translateEntity<T extends Translatable & VendureEntity>(
translatable: T,
languageCode: LanguageCode,
): Translated<T> {
let translation: Translation<any> | undefined;
let translation: Translation<VendureEntity> | undefined;
if (translatable.translations) {
translation = translatable.translations.find(t => t.languageCode === languageCode);
translation = translatable.translations.find((t) => t.languageCode === languageCode);
if (!translation && languageCode !== DEFAULT_LANGUAGE_CODE) {
translation = translatable.translations.find(t => t.languageCode === DEFAULT_LANGUAGE_CODE);
translation = translatable.translations.find((t) => t.languageCode === DEFAULT_LANGUAGE_CODE);
}
}

Expand Down Expand Up @@ -72,7 +73,7 @@ export function translateEntity<T extends Translatable>(
/**
* Translates an entity and its deeply-nested translatable properties. Supports up to 2 levels of nesting.
*/
export function translateDeep<T extends Translatable>(
export function translateDeep<T extends Translatable & VendureEntity>(
translatable: T,
languageCode: LanguageCode,
translatableRelations: DeepTranslatableRelations<T> = [],
Expand Down Expand Up @@ -134,7 +135,7 @@ function translateLeaf(
}
}

export type TreeNode = { children: TreeNode[] } & Translatable;
export type TreeNode = { children: TreeNode[] } & Translatable & VendureEntity;

/**
* Translates a tree structure of Translatable entities
Expand All @@ -146,7 +147,7 @@ export function translateTree<T extends TreeNode>(
): Translated<T> {
const output = translateDeep(node, languageCode, translatableRelations);
if (Array.isArray(output.children)) {
output.children = output.children.map(child =>
output.children = output.children.map((child) =>
translateTree(child, languageCode, translatableRelations as any),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@vendure/core": "^0.10.1",
"rimraf": "^3.0.0",
"ts-node": "^8.4.1",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"dependencies": {
"chalk": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/create/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const REQUIRED_NODE_VERSION = '>=8.9.0';
export const REQUIRED_NODE_VERSION = '>=10.13.0';
export const SERVER_PORT = 3000;
/**
* The TypeScript version needs to pinned because minor versions often
* introduce breaking changes.
*/
export const TYPESCRIPT_VERSION = '3.7.5';
export const TYPESCRIPT_VERSION = '3.8.3';
2 changes: 1 addition & 1 deletion packages/dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@vendure/core": "^0.10.1",
"@vendure/elasticsearch-plugin": "^0.10.1",
"@vendure/email-plugin": "^0.10.1",
"typescript": "3.7.5"
"typescript": "3.8.3"
},
"devDependencies": {
"@types/csv-stringify": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/elasticsearch-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"@vendure/common": "^0.10.1",
"@vendure/core": "^0.10.1",
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/email-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"@vendure/common": "^0.10.1",
"@vendure/core": "^0.10.1",
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
"mysql": "^2.17.1",
"pg": "^7.17.1",
"rimraf": "^3.0.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
2 changes: 1 addition & 1 deletion packages/ui-devkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.26.0",
"tslib": "^1.10.0",
"typescript": "3.7.5"
"typescript": "3.8.3"
}
}
38 changes: 2 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7105,13 +7105,6 @@ debug@4, [email protected], debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "^2.1.1"

[email protected]:
version "4.1.0"
resolved "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz#373687bffa678b38b1cd91f861b63850035ddc87"
integrity sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==
dependencies:
ms "^2.1.1"

debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
Expand Down Expand Up @@ -7171,7 +7164,7 @@ deep-extend@^0.6.0:
resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac"
integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==

deep-is@^0.1.3, deep-is@~0.1.3:
deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
Expand Down Expand Up @@ -10411,11 +10404,6 @@ is-unc-path@^1.0.0:
dependencies:
unc-path-regex "^0.1.2"

is-url@^1.2.2:
version "1.2.4"
resolved "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-utf8@^0.2.0, is-utf8@^0.2.1:
version "0.2.1"
resolved "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
Expand Down Expand Up @@ -10446,15 +10434,6 @@ is-yarn-global@^0.3.0:
resolved "https://registry.npmjs.org/is-yarn-global/-/is-yarn-global-0.3.0.tgz#d502d3382590ea3004893746754c89139973e232"
integrity sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==

[email protected]:
version "2.0.1"
resolved "https://registry.npmjs.org/is2/-/is2-2.0.1.tgz#8ac355644840921ce435d94f05d3a94634d3481a"
integrity sha512-+WaJvnaA7aJySz2q/8sLjMb2Mw14KTplHmSwcSpZ/fWJPkUmqw3YTzSWbPJ7OAwRvdYTWF2Wg+yYJ1AdP5Z8CA==
dependencies:
deep-is "^0.1.3"
ip-regex "^2.1.0"
is-url "^1.2.2"

[email protected]:
version "0.0.1"
resolved "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
Expand Down Expand Up @@ -17377,14 +17356,6 @@ tar@^6.0.0, tar@^6.0.1:
mkdirp "^1.0.3"
yallist "^4.0.0"

tcp-port-used@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/tcp-port-used/-/tcp-port-used-1.0.1.tgz#46061078e2d38c73979a2c2c12b5a674e6689d70"
integrity sha512-rwi5xJeU6utXoEIiMvVBMc9eJ2/ofzB+7nLOdnZuFTmNCLqRiQh2sMG9MqCxHU/69VC/Fwp5dV9306Qd54ll1Q==
dependencies:
debug "4.1.0"
is2 "2.0.1"

temp-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz#0a7c0ea26d3a39afa7e0ebea9c1fc0bc4daa011d"
Expand Down Expand Up @@ -17907,12 +17878,7 @@ [email protected]:
resolved "https://registry.npmjs.org/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==

[email protected], typescript@~3.7.5:
version "3.7.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae"
integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==

typescript@^3.8.3, typescript@~3.8.2:
[email protected], typescript@^3.8.3, typescript@~3.8.2:
version "3.8.3"
resolved "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
Expand Down

0 comments on commit e255674

Please sign in to comment.