Skip to content

Commit

Permalink
update: bump deno to v0.36.0 (#24)
Browse files Browse the repository at this point in the history
- Bump deno to v0.36.0
- Bump deno_std to v0.36.0
- Bump deno-sqlite from d451a28e55180730a296a9383cd5dd26155a2c11 to 73935087a1ebe9108d784503bc5474662ba54b73
  • Loading branch information
uki00a authored Mar 20, 2020
1 parent e6f9636 commit a238578
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@master
- uses: denolib/setup-deno@master
with:
deno-version: 0.33.0
deno-version: 0.36.0
- name: Run tests
run: |
cp ./ormconfig.gh-actions.json ./ormconfig.json
Expand Down
5 changes: 2 additions & 3 deletions dem.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
{
"protocol": "https",
"path": "deno.land/std",
"version": "v0.33.0",
"version": "v0.36.0",
"files": [
"/fmt/colors.ts",
"/fs/mod.ts",
"/node/module.ts",
"/path/mod.ts",
"/util/async.ts"
]
Expand All @@ -31,7 +30,7 @@
{
"protocol": "https",
"path": "deno.land/x/sqlite",
"version": "d451a28e55180730a296a9383cd5dd26155a2c11",
"version": "73935087a1ebe9108d784503bc5474662ba54b73",
"files": [
"/mod.ts"
]
Expand Down
14 changes: 7 additions & 7 deletions src/decorator/columns/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function Column(type: (type?: any) => Function, options?: ColumnEmbeddedO
* Column decorator is used to mark a specific class property as a table column.
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
*/
export function Column(typeOrOptions: ((type?: any) => Function)|ColumnType|(ColumnOptions&ColumnEmbeddedOptions), options?: (ColumnOptions&ColumnEmbeddedOptions)): Function {
export function Column(typeOrOptions: ((type?: any) => Function)|ColumnType|(ColumnOptions&ColumnEmbeddedOptions), options?: (ColumnOptions&ColumnEmbeddedOptions) | (ColumnCommonOptions&ColumnHstoreOptions)): Function {
return function (object: Object, propertyName: string) {

// normalize parameters
Expand All @@ -105,26 +105,26 @@ export function Column(typeOrOptions: ((type?: any) => Function)|ColumnType|(Col
if (!options) options = {} as ColumnOptions;

// check if there is no type in column options then set type from first function argument, or guessed one
if (!options.type && type)
options.type = type;
if (!(options as ColumnOptions).type && type)
(options as ColumnOptions).type = type;

// specify HSTORE type if column is HSTORE
if (options.type === "hstore" && !options.hstoreType)
options.hstoreType = "string";
if ((options as ColumnOptions).type === "hstore" && !(options as ColumnOptions).hstoreType)
(options as ColumnOptions).hstoreType = "string";

if (typeOrOptions instanceof Function) { // register an embedded
getMetadataArgsStorage().embeddeds.push({
target: object.constructor,
propertyName: propertyName,
isArray: options.array === true,
prefix: options.prefix !== undefined ? options.prefix : undefined,
prefix: (options as ColumnEmbeddedOptions).prefix !== undefined ? (options as ColumnEmbeddedOptions).prefix : undefined,
type: typeOrOptions as (type?: any) => Function
} as EmbeddedMetadataArgs);

} else { // register a regular column

// if we still don't have a type then we need to give error to user that type is required
if (!options.type)
if (!(options as ColumnOptions).type)
throw new ColumnTypeUndefinedError(object, propertyName);

// create unique
Expand Down
6 changes: 3 additions & 3 deletions src/decorator/transaction/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {IsolationLevel} from "../../driver/types/IsolationLevel.ts";
export function Transaction(connectionName?: string): MethodDecorator;
export function Transaction(options?: TransactionOptions): MethodDecorator;
export function Transaction(connectionOrOptions?: string | TransactionOptions): MethodDecorator {
return function (target: Object, methodName: string, descriptor: PropertyDescriptor) {
return function (target: Object, methodName: string | symbol, descriptor: PropertyDescriptor) {

// save original method - we gonna need it
const originalMethod = descriptor.value;
Expand All @@ -45,10 +45,10 @@ export function Transaction(connectionOrOptions?: string | TransactionOptions):

// filter all @TransactionEntityManager() and @TransactionRepository() decorator usages for this method
const transactionEntityManagerMetadatas = getMetadataArgsStorage()
.filterTransactionEntityManagers(target.constructor, methodName)
.filterTransactionEntityManagers(target.constructor, methodName as string)
.reverse();
const transactionRepositoryMetadatas = getMetadataArgsStorage()
.filterTransactionRepository(target.constructor, methodName)
.filterTransactionRepository(target.constructor, methodName as string)
.reverse();

// if there are @TransactionEntityManager() decorator usages the inject them
Expand Down
4 changes: 2 additions & 2 deletions src/decorator/transaction/TransactionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {CannotReflectMethodParameterTypeError} from "../../error/CannotReflectMe
* Injects transaction's repository into the method wrapped with @Transaction decorator.
*/
export function TransactionRepository(entityType?: Function): ParameterDecorator {
return (object: Object, methodName: string, index: number) => {
return (object: Object, methodName: string | symbol, index: number) => {

throw new CannotReflectMethodParameterTypeError(object.constructor, methodName);
throw new CannotReflectMethodParameterTypeError(object.constructor, methodName as string);
};
}
13 changes: 12 additions & 1 deletion src/driver/sqlite/SqliteDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ export class SqliteDriver extends AbstractSqliteDriver {
*/
async disconnect(): Promise<void> {
this.queryRunner = undefined;
this.databaseConnection.close();
try {
this.databaseConnection.close();
} catch (error) {
if (error.code === 5) { // SqliteBusy
// FIXME
// This problem occurs since deno-sqlite@73935087a1ebe9108d784503bc5474662ba54b73.
// We need more research...
console.warn(error); // this.connection.logger.log("warn", error.message);
} else {
throw error;
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/driver/sqlite/SqliteQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SqliteQueryRunner extends AbstractSqliteQueryRunner {
throw new QueryRunnerAlreadyReleasedError();

const connection = this.driver.connection;
const reportSlowQuery = function (): void {
const reportSlowQuery = (): void => {

// log slow queries if maxQueryExecution time is set
const maxQueryExecutionTime = connection.options.maxQueryExecutionTime;
Expand Down
4 changes: 2 additions & 2 deletions src/entity-manager/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ export class EntityManager {
// convert possible embeded path "social.likes" into object { social: { like: () => value } }
const values: QueryDeepPartialEntity<Entity> = propertyPath
.split(".")
.reduceRight(
.reduceRight<any>(
(value, key) => ({ [key]: value }) as any,
() => this.connection.driver.escape(column.databaseName) + " + " + value
);
Expand Down Expand Up @@ -982,7 +982,7 @@ export class EntityManager {
// convert possible embeded path "social.likes" into object { social: { like: () => value } }
const values: QueryDeepPartialEntity<Entity> = propertyPath
.split(".")
.reduceRight(
.reduceRight<any>(
(value, key) => ({ [key]: value }) as any,
() => this.connection.driver.escape(column.databaseName) + " - " + value
);
Expand Down
4 changes: 2 additions & 2 deletions src/util/DepGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DepGraph {
if (idx >= 0) {
edgeList[key].splice(idx, 1);
}
}, this);
}/*, this*/);
});
}
}
Expand Down Expand Up @@ -229,4 +229,4 @@ export class DepGraph {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {Question} from "../model/Question.ts";

export default {
name: "Question",
table: {
Expand All @@ -14,7 +16,7 @@ export default {
nullable: false
}
},
target: function Question() {
target: function Question(this: Question) {
this.type = "question";
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {CategoryRepository} from "../repository/CategoryRepository.ts";
export class PostController {

@Transaction("mysql") // "mysql" is a connection name. you can not pass it if you are using default connection.
async save(post: Post, category: Category, @TransactionManager() entityManager: EntityManager) {
await entityManager.save(post);
await entityManager.save(category);
async save(post: Post, category: Category, @TransactionManager() entityManager?: EntityManager) {
await entityManager!.save(post);
await entityManager!.save(category);
}

// this save is not wrapped into the transaction
Expand All @@ -27,19 +27,19 @@ export class PostController {
async saveWithRepository(
post: Post,
category: Category,
/*@TransactionRepository(Post)*/postRepository: Repository<Post>,
/*@TransactionRepository()*/categoryRepository: CategoryRepository,
/*@TransactionRepository(Post)*/postRepository?: Repository<Post>,
/*@TransactionRepository()*/categoryRepository?: CategoryRepository,
) {
await postRepository.save(post);
await categoryRepository.save(category);
await postRepository!.save(post);
await categoryRepository!.save(category);

return categoryRepository.findByName(category.name);
return categoryRepository!.findByName(category.name);
}

@Transaction({ connectionName: "mysql", isolation: "SERIALIZABLE" }) // "mysql" is a connection name. you can not pass it if you are using default connection.
async saveWithNonDefaultIsolation(post: Post, category: Category, @TransactionManager() entityManager: EntityManager) {
await entityManager.save(post);
await entityManager.save(category);
async saveWithNonDefaultIsolation(post: Post, category: Category, @TransactionManager() entityManager?: EntityManager) {
await entityManager!.save(post);
await entityManager!.save(category);
}

}
18 changes: 13 additions & 5 deletions test/utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import {EntitySchema} from "../../src/entity-schema/EntitySchema.ts";
import {createConnections} from "../../src/index.ts";
import {NamingStrategyInterface} from "../../src/naming-strategy/NamingStrategyInterface.ts";
import {PromiseUtils} from "../../src/util/PromiseUtils.ts";
import {createRequire} from "../../vendor/https/deno.land/std/node/module.ts";
import {join} from "../../vendor/https/deno.land/std/path/mod.ts";

const require = createRequire(import.meta.url);
const __dirname = getDirnameOfCurrentModule(import.meta);

export function getDirnameOfCurrentModule(meta: ImportMeta): string {
Expand Down Expand Up @@ -169,10 +167,10 @@ export function getTypeOrmConfig(): TestingConnectionOptions[] {
try {

try {
return require(__dirname + "/../../../../ormconfig.json");
return readJSONFile(__dirname + "/../../../../ormconfig.json");

} catch (err) {
return require(join(__dirname + "../../ormconfig.json"));
return readJSONFile(join(__dirname + "../../ormconfig.json"));
}

} catch (err) {
Expand Down Expand Up @@ -302,10 +300,20 @@ export function generateRandomText(length: number): string {

export function sleep(ms: number): Promise<void> {
return new Promise<void>(ok => {
setTimeout(ok, ms);
setTimeout(() => ok(), ms);
});
}

export function allSettled(values: any[]): Promise<Array<{ status: 'fulfilled' | 'rejected', value?: any, reason?: any }>> {
return (Promise as any).allSettled(values);
}

let jsonFileCache = {} as { [path: string]: any };
function readJSONFile(path: string): any {
if (jsonFileCache[path]) {
return jsonFileCache[path];
}
const decoder = new TextDecoder();
jsonFileCache[path] = JSON.parse(decoder.decode(Deno.readFileSync(path)));
return jsonFileCache[path];
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "2.1.1",
"compilerOptions": {
"strict": true,
"target": "esnext",
"experimentalDecorators": true,
"sourceMap": true,
Expand Down
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/fmt/colors.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/std@v0.33.0/fmt/colors.ts';
export * from 'https://deno.land/std@v0.36.0/fmt/colors.ts';
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/fs/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/std@v0.33.0/fs/mod.ts';
export * from 'https://deno.land/std@v0.36.0/fs/mod.ts';
1 change: 0 additions & 1 deletion vendor/https/deno.land/std/node/module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/path/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/std@v0.33.0/path/mod.ts';
export * from 'https://deno.land/std@v0.36.0/path/mod.ts';
2 changes: 1 addition & 1 deletion vendor/https/deno.land/std/util/async.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/std@v0.33.0/util/async.ts';
export * from 'https://deno.land/std@v0.36.0/util/async.ts';
2 changes: 1 addition & 1 deletion vendor/https/deno.land/x/sqlite/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://deno.land/x/sqlite@d451a28e55180730a296a9383cd5dd26155a2c11/mod.ts';
export * from 'https://deno.land/x/sqlite@73935087a1ebe9108d784503bc5474662ba54b73/mod.ts';

0 comments on commit a238578

Please sign in to comment.