Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist';
export * from './dist/index.js';
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__export(require("./dist"));
export * from './dist/index.js';
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist';
export * from './dist/index.js';
4 changes: 2 additions & 2 deletions lib/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './typeorm.decorators';
export * from './typeorm.utils';
export * from './typeorm.decorators.js';
export * from './typeorm.utils.js';
6 changes: 5 additions & 1 deletion lib/common/typeorm-compat.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createRequire } from 'node:module';

/**
* Runtime compatibility helpers for accessing TypeORM APIs that were
* removed in TypeORM v1.0.0 (notably `Connection` and `AbstractRepository`).
Expand All @@ -17,9 +19,11 @@
* package. Returns `undefined` when the export is not present (e.g.
* TypeORM v1.0.0 has removed it) or when the module fails to load.
*/
const require = createRequire(import.meta.url);

function resolveTypeormExport<T = unknown>(exportName: string): T | undefined {
try {
// Using `require` here (rather than a static import) ensures the
// Using `createRequire(import.meta.url)` here (rather than a static import) ensures the
// reference is resolved at runtime and is not included in the
// emitted type definitions — which is required for forward
// compatibility with TypeORM v1 where these symbols no longer exist.
Expand Down
6 changes: 3 additions & 3 deletions lib/common/typeorm.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Inject } from '@nestjs/common';
import { DataSource, DataSourceOptions } from 'typeorm';
import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type';
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants';
import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type.js';
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js';
import {
getDataSourceToken,
getEntityManagerToken,
getRepositoryToken,
} from './typeorm.utils';
} from './typeorm.utils.js';

/**
* @publicApi
Expand Down
8 changes: 4 additions & 4 deletions lib/common/typeorm.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
EntitySchema,
Repository,
} from 'typeorm';
import { CircularDependencyException } from '../exceptions/circular-dependency.exception';
import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type';
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants';
import { AbstractRepository } from './typeorm-compat';
import { CircularDependencyException } from '../exceptions/circular-dependency.exception.js';
import { EntityClassOrSchema } from '../interfaces/entity-class-or-schema.type.js';
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js';
import { AbstractRepository } from './typeorm-compat.js';

const logger = new Logger('TypeOrmModule');

Expand Down
2 changes: 1 addition & 1 deletion lib/data-source-name.registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DuplicateDataSourceException } from './exceptions/duplicate-data-source.exception';
import { DuplicateDataSourceException } from './exceptions/duplicate-data-source.exception.js';

/**
* Tracks active data source names at runtime in order to prevent multiple
Expand Down
2 changes: 1 addition & 1 deletion lib/entities-metadata.storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataSource, DataSourceOptions } from 'typeorm';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js';

type DataSourceToken = DataSource | DataSourceOptions | string;

Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions/duplicate-data-source.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants';
import { DEFAULT_DATA_SOURCE_NAME } from '../typeorm.constants.js';

export class DuplicateDataSourceException extends Error {
constructor(dataSourceName: string) {
Expand Down
8 changes: 4 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './common';
export * from './exceptions/duplicate-data-source.exception';
export * from './interfaces';
export * from './typeorm.module';
export * from './common/index.js';
export * from './exceptions/duplicate-data-source.exception.js';
export * from './interfaces/index.js';
export * from './typeorm.module.js';
2 changes: 1 addition & 1 deletion lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './typeorm-options.interface';
export * from './typeorm-options.interface.js';
6 changes: 4 additions & 2 deletions lib/interfaces/typeorm-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export type TypeOrmDataSourceFactory = (
/**
* @publicApi
*/
export interface TypeOrmModuleAsyncOptions
extends Pick<ModuleMetadata, 'imports'> {
export interface TypeOrmModuleAsyncOptions extends Pick<
ModuleMetadata,
'imports'
> {
name?: string;
useExisting?: Type<TypeOrmOptionsFactory>;
useClass?: Type<TypeOrmOptionsFactory>;
Expand Down
12 changes: 6 additions & 6 deletions lib/typeorm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import {
import { ModuleRef } from '@nestjs/core';
import { defer, lastValueFrom } from 'rxjs';
import { DataSource, DataSourceOptions } from 'typeorm';
import { Connection } from './common/typeorm-compat';
import { Connection } from './common/typeorm-compat.js';
import {
generateString,
getDataSourceName,
getDataSourceToken,
getEntityManagerToken,
handleRetry,
} from './common/typeorm.utils';
import { DataSourceNameRegistry } from './data-source-name.registry';
import { EntitiesMetadataStorage } from './entities-metadata.storage';
} from './common/typeorm.utils.js';
import { DataSourceNameRegistry } from './data-source-name.registry.js';
import { EntitiesMetadataStorage } from './entities-metadata.storage.js';
import {
TypeOrmDataSourceFactory,
TypeOrmModuleAsyncOptions,
TypeOrmModuleOptions,
TypeOrmOptionsFactory,
} from './interfaces/typeorm-options.interface';
import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants';
} from './interfaces/typeorm-options.interface.js';
import { TYPEORM_MODULE_ID, TYPEORM_MODULE_OPTIONS } from './typeorm.constants.js';

@Global()
@Module({})
Expand Down
12 changes: 6 additions & 6 deletions lib/typeorm.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DynamicModule, Module } from '@nestjs/common';
import { DataSource, DataSourceOptions } from 'typeorm';
import { EntitiesMetadataStorage } from './entities-metadata.storage';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type';
import { EntitiesMetadataStorage } from './entities-metadata.storage.js';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js';
import {
TypeOrmModuleAsyncOptions,
TypeOrmModuleOptions,
} from './interfaces/typeorm-options.interface';
import { TypeOrmCoreModule } from './typeorm-core.module';
import { DEFAULT_DATA_SOURCE_NAME } from './typeorm.constants';
import { createTypeOrmProviders } from './typeorm.providers';
} from './interfaces/typeorm-options.interface.js';
import { TypeOrmCoreModule } from './typeorm-core.module.js';
import { DEFAULT_DATA_SOURCE_NAME } from './typeorm.constants.js';
import { createTypeOrmProviders } from './typeorm.providers.js';

/**
* @publicApi
Expand Down
4 changes: 2 additions & 2 deletions lib/typeorm.providers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Provider } from '@nestjs/common';
import { DataSource, DataSourceOptions, getMetadataArgsStorage } from 'typeorm';
import { getDataSourceToken, getRepositoryToken } from './common/typeorm.utils';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type';
import { getDataSourceToken, getRepositoryToken } from './common/typeorm.utils.js';
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type.js';

export function createTypeOrmProviders(
entities?: EntityClassOrSchema[],
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"author": "Kamil Mysliwiec",
"license": "MIT",
"url": "https://github.com/nestjs/typeorm#readme",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.json",
"format": "prettier --write \"**/*.ts\"",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "bundler",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"declaration": true,
"strict": true,
"removeComments": false,
Expand Down