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

Fix Pg array type error, fix ESM imports #1102

Merged
merged 6 commits into from
Aug 23, 2023
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rules:
'@typescript-eslint/consistent-type-imports':
- error
- disallowTypeAnnotations: false
fixStyle: inline-type-imports
fixStyle: separate-type-imports
import/no-cycle: error
import/no-self-import: error
import/no-empty-named-blocks: error
Expand Down Expand Up @@ -64,3 +64,5 @@ rules:
'unicorn/prefer-string-replace-all': 'off'
'unicorn/no-process-exit': 'off'
'@typescript-eslint/ban-ts-comment': 'off'
'@typescript-eslint/no-empty-interface': 'off'
'@typescript-eslint/no-unsafe-declaration-merging': 'off'
2 changes: 2 additions & 0 deletions changelogs/drizzle-orm/0.28.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- 🐛 Fixed imports in ESM-based projects (#1088)
- 🐛 Fixed type error on Postgres table definitions (#1089)
1 change: 1 addition & 0 deletions changelogs/drizzle-typebox/0.1.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 🐛 Fixed imports in ESM projects
1 change: 1 addition & 0 deletions changelogs/drizzle-valibot/0.1.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 🐛 Fixed imports in ESM projects
1 change: 1 addition & 0 deletions changelogs/drizzle-zod/0.5.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 🐛 Fixed imports in ESM projects
5 changes: 3 additions & 2 deletions drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.28.3",
"version": "0.28.4",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -140,7 +140,7 @@
"@vercel/postgres": "^0.3.0",
"better-sqlite3": "^8.4.0",
"bun-types": "^0.6.6",
"concurrently": "^8.1.0",
"cpy": "^10.1.0",
"cpy-cli": "^5.0.0",
"knex": "^2.4.2",
"kysely": "^0.25.0",
Expand All @@ -150,6 +150,7 @@
"rimraf": "^5.0.0",
"rollup": "^3.27.2",
"rollup-plugin-dts": "^5.3.1",
"rollup-plugin-typescript2": "^0.35.0",
"sql.js": "^1.8.0",
"sqlite3": "^5.1.2",
"tslib": "^2.5.2",
Expand Down
1 change: 1 addition & 0 deletions drizzle-orm/rollup.cjs.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';

import { entries, external } from './rollup.common';

export default defineConfig([
Expand Down
1 change: 1 addition & 0 deletions drizzle-orm/rollup.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const external = [
'knex',
'kysely',
'mysql2',
'mysql2/promise',
'postgres',
'sqlite3',
'bun:sqlite',
Expand Down
1 change: 1 addition & 0 deletions drizzle-orm/rollup.esm.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';

import { entries, external } from './rollup.common';

export default defineConfig([
Expand Down
58 changes: 35 additions & 23 deletions drizzle-orm/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
#!/usr/bin/env -S pnpm tsx
import 'zx/globals';
import concurrently from 'concurrently';
import cpy from 'cpy';

import { entries } from '../rollup.common';

function updateAndCopyPackageJson() {
const pkg = fs.readJSONSync('package.json');

pkg.exports = entries.reduce<Record<string, { import: string; require: string; default: string; types: string }>>(
pkg.exports = entries.reduce<
Record<string, {
import: {
types?: string;
default: string;
};
require: {
types: string;
default: string;
};
default: string;
types: string;
}>
>(
(acc, entry) => {
const exportsEntry = entry === 'index' ? '.' : './' + entry.replace(/\/index$/, '');
const importEntry = `./${entry}.mjs`;
const requireEntry = `./${entry}.cjs`;
const typesEntry = `./${entry}.d.ts`;
acc[exportsEntry] = {
types: typesEntry,
import: importEntry,
require: requireEntry,
import: {
types: `./${entry}.d.mts`,
default: importEntry,
},
require: {
types: `./${entry}.d.cts`,
default: requireEntry,
},
types: `./${entry}.d.ts`,
default: importEntry,
};
return acc;
Expand All @@ -27,23 +45,17 @@ function updateAndCopyPackageJson() {
fs.writeJSONSync('dist.new/package.json', pkg, { spaces: 2 });
}

await concurrently([
{
command: 'rollup --config rollup.cjs.config.ts --configPlugin typescript',
name: 'cjs',
},
{
command: 'rollup --config rollup.esm.config.ts --configPlugin typescript',
name: 'esm',
},
{
command:
`rimraf dist-dts && tsc -p tsconfig.dts.json --declaration --outDir dist-dts --emitDeclarationOnly && resolve-tspaths --out dist-dts && cpy 'dist-dts/**/*' dist.new && rimraf dist-dts`,
name: 'dts',
},
], {
killOthers: 'failure',
}).result.catch(() => process.exit(1));
await $`rollup --config rollup.cjs.config.ts --configPlugin typescript`;
await $`rollup --config rollup.esm.config.ts --configPlugin typescript`;
await $`rimraf dist-dts && tsc -p tsconfig.dts.json && resolve-tspaths -p tsconfig.dts.json --out dist-dts`;
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.mts'),
});
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.cts'),
});
await cpy('dist-dts/**/*.d.ts', 'dist.new');
fs.removeSync('dist-dts');
fs.copySync('../README.md', 'dist.new/README.md');
updateAndCopyPackageJson();
fs.removeSync('dist');
Expand Down
14 changes: 7 additions & 7 deletions drizzle-orm/src/alias.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AnyColumn } from './column';
import { Column } from './column';
import { entityKind, is } from './entity';
import type { Relation } from './relations';
import { SQL, sql } from './sql';
import { Table } from './table';
import { type View, ViewBaseConfig } from './view';
import type { AnyColumn } from './column.ts';
import { Column } from './column.ts';
import { entityKind, is } from './entity.ts';
import type { Relation } from './relations.ts';
import { SQL, sql } from './sql/index.ts';
import { Table } from './table.ts';
import { type View, ViewBaseConfig } from './view.ts';

export class ColumnAliasProxyHandler<TColumn extends Column> implements ProxyHandler<TColumn> {
static readonly [entityKind]: string = 'ColumnAliasProxyHandler';
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/aws-data-api/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Field } from '@aws-sdk/client-rds-data';
import { TypeHint } from '@aws-sdk/client-rds-data';
import type { QueryTypingsValue } from '~/sql';
import type { QueryTypingsValue } from '~/sql/index.ts';

export function getValueFromDataApi(field: Field) {
if (field.stringValue !== undefined) {
Expand Down
18 changes: 9 additions & 9 deletions drizzle-orm/src/aws-data-api/pg/driver.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { entityKind } from '~/entity';
import type { Logger } from '~/logger';
import { DefaultLogger } from '~/logger';
import { PgDatabase } from '~/pg-core/db';
import { PgDialect } from '~/pg-core/dialect';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import { DefaultLogger } from '~/logger.ts';
import { PgDatabase } from '~/pg-core/db.ts';
import { PgDialect } from '~/pg-core/dialect.ts';
import {
createTableRelationsHelpers,
extractTablesRelationalConfig,
type RelationalSchemaConfig,
type TablesRelationalConfig,
} from '~/relations';
import { type DrizzleConfig } from '~/utils';
import type { AwsDataApiClient, AwsDataApiPgQueryResultHKT } from './session';
import { AwsDataApiSession } from './session';
} from '~/relations.ts';
import { type DrizzleConfig } from '~/utils.ts';
import type { AwsDataApiClient, AwsDataApiPgQueryResultHKT } from './session.ts';
import { AwsDataApiSession } from './session.ts';

export interface PgDriverOptions {
logger?: Logger;
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/aws-data-api/pg/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './driver';
export * from './session';
export * from './driver.ts';
export * from './session.ts';
6 changes: 3 additions & 3 deletions drizzle-orm/src/aws-data-api/pg/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MigrationConfig } from '~/migrator';
import { readMigrationFiles } from '~/migrator';
import type { AwsDataApiPgDatabase } from './driver';
import type { MigrationConfig } from '~/migrator.ts';
import { readMigrationFiles } from '~/migrator.ts';
import type { AwsDataApiPgDatabase } from './driver.ts';

export async function migrate<TSchema extends Record<string, unknown>>(
db: AwsDataApiPgDatabase<TSchema>,
Expand Down
16 changes: 8 additions & 8 deletions drizzle-orm/src/aws-data-api/pg/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
ExecuteStatementCommand,
RollbackTransactionCommand,
} from '@aws-sdk/client-rds-data';
import { entityKind } from '~/entity';
import type { Logger } from '~/logger';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import {
type PgDialect,
PgSession,
Expand All @@ -15,12 +15,12 @@ import {
PreparedQuery,
type PreparedQueryConfig,
type QueryResultHKT,
} from '~/pg-core';
import type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations';
import { fillPlaceholders, type Query, type QueryTypingsValue, type SQL, sql } from '~/sql';
import { mapResultRow } from '~/utils';
import { getValueFromDataApi, toValueParam } from '../common';
} from '~/pg-core/index.ts';
import type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations.ts';
import { fillPlaceholders, type Query, type QueryTypingsValue, type SQL, sql } from '~/sql/index.ts';
import { mapResultRow } from '~/utils.ts';
import { getValueFromDataApi, toValueParam } from '../common/index.ts';

export type AwsDataApiClient = RDSDataClient;

Expand Down
12 changes: 6 additions & 6 deletions drizzle-orm/src/better-sqlite3/driver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Database, RunResult } from 'better-sqlite3';
import { DefaultLogger } from '~/logger';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
extractTablesRelationalConfig,
type RelationalSchemaConfig,
type TablesRelationalConfig,
} from '~/relations';
import { BaseSQLiteDatabase } from '~/sqlite-core/db';
import { SQLiteSyncDialect } from '~/sqlite-core/dialect';
import { type DrizzleConfig } from '~/utils';
import { BetterSQLiteSession } from './session';
} from '~/relations.ts';
import { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';
import { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import { type DrizzleConfig } from '~/utils.ts';
import { BetterSQLiteSession } from './session.ts';

export type BetterSQLite3Database<
TSchema extends Record<string, unknown> = Record<string, never>,
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/better-sqlite3/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './driver';
export * from './session';
export * from './driver.ts';
export * from './session.ts';
6 changes: 3 additions & 3 deletions drizzle-orm/src/better-sqlite3/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MigrationConfig } from '~/migrator';
import { readMigrationFiles } from '~/migrator';
import type { BetterSQLite3Database } from './driver';
import type { MigrationConfig } from '~/migrator.ts';
import { readMigrationFiles } from '~/migrator.ts';
import type { BetterSQLite3Database } from './driver.ts';

export function migrate<TSchema extends Record<string, unknown>>(
db: BetterSQLite3Database<TSchema>,
Expand Down
20 changes: 10 additions & 10 deletions drizzle-orm/src/better-sqlite3/session.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { Database, RunResult, Statement } from 'better-sqlite3';
import { entityKind } from '~/entity';
import type { Logger } from '~/logger';
import { NoopLogger } from '~/logger';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations';
import { fillPlaceholders, type Query, sql } from '~/sql';
import { SQLiteTransaction } from '~/sqlite-core';
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect';
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations.ts';
import { fillPlaceholders, type Query, sql } from '~/sql/index.ts';
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import { SQLiteTransaction } from '~/sqlite-core/index.ts';
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types.ts';
import {
PreparedQuery as PreparedQueryBase,
type PreparedQueryConfig as PreparedQueryConfigBase,
type SQLiteExecuteMethod,
SQLiteSession,
type SQLiteTransactionConfig,
} from '~/sqlite-core/session';
import { mapResultRow } from '~/utils';
} from '~/sqlite-core/session.ts';
import { mapResultRow } from '~/utils.ts';

export interface BetterSQLiteSessionOptions {
logger?: Logger;
Expand Down
12 changes: 6 additions & 6 deletions drizzle-orm/src/bun-sqlite/driver.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// <reference types="bun-types" />

import type { Database } from 'bun:sqlite';
import { DefaultLogger } from '~/logger';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
extractTablesRelationalConfig,
type RelationalSchemaConfig,
type TablesRelationalConfig,
} from '~/relations';
import { BaseSQLiteDatabase } from '~/sqlite-core/db';
import { SQLiteSyncDialect } from '~/sqlite-core/dialect';
import { type DrizzleConfig } from '~/utils';
import { SQLiteBunSession } from './session';
} from '~/relations.ts';
import { BaseSQLiteDatabase } from '~/sqlite-core/db.ts';
import { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import { type DrizzleConfig } from '~/utils.ts';
import { SQLiteBunSession } from './session.ts';

export type BunSQLiteDatabase<
TSchema extends Record<string, unknown> = Record<string, never>,
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/bun-sqlite/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './driver';
export * from './session';
export * from './driver.ts';
export * from './session.ts';
6 changes: 3 additions & 3 deletions drizzle-orm/src/bun-sqlite/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MigrationConfig } from '~/migrator';
import { readMigrationFiles } from '~/migrator';
import type { BunSQLiteDatabase } from './driver';
import type { MigrationConfig } from '~/migrator.ts';
import { readMigrationFiles } from '~/migrator.ts';
import type { BunSQLiteDatabase } from './driver.ts';

export function migrate<TSchema extends Record<string, unknown>>(
db: BunSQLiteDatabase<TSchema>,
Expand Down
22 changes: 11 additions & 11 deletions drizzle-orm/src/bun-sqlite/session.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/// <reference types="bun-types" />

import type { Database, Statement as BunStatement } from 'bun:sqlite';
import { entityKind } from '~/entity';
import type { Logger } from '~/logger';
import { NoopLogger } from '~/logger';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations';
import { fillPlaceholders, type Query, sql } from '~/sql';
import { SQLiteTransaction } from '~/sqlite-core';
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect';
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import { NoopLogger } from '~/logger.ts';
import { type RelationalSchemaConfig, type TablesRelationalConfig } from '~/relations.ts';
import { fillPlaceholders, type Query, sql } from '~/sql/index.ts';
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import { SQLiteTransaction } from '~/sqlite-core/index.ts';
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types.ts';
import type {
PreparedQueryConfig as PreparedQueryConfigBase,
SQLiteExecuteMethod,
SQLiteTransactionConfig,
} from '~/sqlite-core/session';
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session';
import { mapResultRow } from '~/utils';
} from '~/sqlite-core/session.ts';
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session.ts';
import { mapResultRow } from '~/utils.ts';

export interface SQLiteBunSessionOptions {
logger?: Logger;
Expand Down
Loading