Skip to content

Commit

Permalink
Merge pull request #520 from drizzle-team/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
dankochetov authored Apr 25, 2023
2 parents d43e04b + a6ec9f3 commit aadde62
Show file tree
Hide file tree
Showing 16 changed files with 956 additions and 28 deletions.
2 changes: 2 additions & 0 deletions changelogs/drizzle-orm/0.25.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- 🐛 Fix `pg` imports in ESM mode (#505)
- 🐛 Add "types" and "default" fields to "exports" entries in package.json (#511)
1 change: 1 addition & 0 deletions changelogs/drizzle-zod/0.4.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 🐛 Add "exports" field to package.json
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.25.2",
"version": "0.25.3",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down
18 changes: 11 additions & 7 deletions drizzle-orm/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { entries } from '../rollup.common';
function updateAndCopyPackageJson() {
const pkg = fs.readJSONSync('package.json');

pkg.exports = entries.reduce<Record<string, { import: string; require: string }>>((acc, entry) => {
const exportsEntry = entry === 'index' ? '.' : './' + entry.replace(/\/index$/, '');
const importEntry = `./${entry}.mjs`;
const requireEntry = `./${entry}.cjs`;
acc[exportsEntry] = { import: importEntry, require: requireEntry };
return acc;
}, {});
pkg.exports = entries.reduce<Record<string, { import: string; require: 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] = { import: importEntry, require: requireEntry, default: importEntry, types: typesEntry };
return acc;
},
{},
);

fs.writeJSONSync('dist/package.json', pkg, { spaces: 2 });
}
Expand Down
13 changes: 6 additions & 7 deletions drizzle-orm/src/mysql-core/columns/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export * from './bigint';
export * from './binary';
export * from './char';
export * from './boolean';
export { MySqlColumn } from './common';
export type { AnyMySqlColumn } from './common';
export * from './char';
export * from './common';
export * from './custom';
export * from './date';
export * from './datetime';
export * from './decimal';
export * from './double';
export * from './enum';
Expand All @@ -15,12 +17,9 @@ export * from './real';
export * from './serial';
export * from './smallint';
export * from './text';
export * from './time';
export * from './timestamp';
export * from './tinyint';
export * from './varbinary';
export * from './varchar';
export * from './date';
export * from './datetime';
export * from './time';
export * from './year';
export * from './custom'
2 changes: 1 addition & 1 deletion drizzle-orm/src/node-postgres/driver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as pg from 'pg';
import pg from 'pg';
import type { Logger } from '~/logger';
import { DefaultLogger } from '~/logger';
import { PgDatabase } from '~/pg-core/db';
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/node-postgres/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client, PoolClient, QueryArrayConfig, QueryConfig, QueryResult, QueryResultRow } from 'pg';
import * as pg from 'pg';
import pg from 'pg';
import { type Logger, NoopLogger } from '~/logger';
import { PgTransaction } from '~/pg-core';
import type { PgDialect } from '~/pg-core/dialect';
Expand Down
3 changes: 1 addition & 2 deletions drizzle-orm/src/pg-core/columns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export * from './bigserial';
export * from './boolean';
export * from './char';
export * from './cidr';
export { PgColumn } from './common';
export type { AnyPgColumn } from './common';
export * from './common';
export * from './custom';
export * from './date';
export * from './double-precision';
Expand Down
3 changes: 1 addition & 2 deletions drizzle-orm/src/sqlite-core/columns/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './blob';
export { SQLiteColumn } from './common';
export type { AnySQLiteColumn } from './common';
export * from './common';
export * from './custom';
export * from './integer';
export * from './numeric';
Expand Down
904 changes: 904 additions & 0 deletions drizzle-orm/type-tests/mysql/1000columns.ts

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion drizzle-zod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-zod",
"version": "0.4.0",
"version": "0.4.1",
"description": "Generate Zod schemas from Drizzle ORM schemas",
"type": "module",
"scripts": {
Expand All @@ -11,6 +11,14 @@
"publish": "npm publish package.tgz",
"test": "ava tests"
},
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.cjs",
"default": "./index.mjs",
"types": "./index.d.ts"
}
},
"main": "./index.cjs",
"module": "./index.mjs",
"types": "./index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion drizzle-zod/tests/imports.test.cjs

This file was deleted.

Empty file removed drizzle-zod/tests/imports.test.mjs
Empty file.
10 changes: 8 additions & 2 deletions integration-tests/tests/imports.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require('drizzle-orm/neon-serverless');
require('drizzle-orm/neon-serverless/migrator');
require('drizzle-orm/node-postgres');
require('drizzle-orm/node-postgres/migrator');
require('drizzle-orm/pg-core');
const { pgTable, serial } = require('drizzle-orm/pg-core');
require('drizzle-orm/planetscale-serverless');
require('drizzle-orm/planetscale-serverless/migrator');
require('drizzle-orm/postgres-js');
Expand All @@ -29,9 +29,15 @@ require('drizzle-orm/sqlite-core');
require('drizzle-orm/sqlite-proxy');
require('drizzle-orm/sqlite-proxy/migrator');
require('drizzle-orm/migrator');
require('drizzle-zod');
const { createInsertSchema } = require('drizzle-zod');
const { compatibilityVersion, npmVersion } = require('drizzle-orm/version');
const { strict: assert } = require('node:assert');

assert.equal(typeof compatibilityVersion, 'number');
assert.equal(typeof npmVersion, 'string');

const test = pgTable('test', {
id: serial('id').primaryKey(),
});

const insertSchema = createInsertSchema(test);
10 changes: 8 additions & 2 deletions integration-tests/tests/imports.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'drizzle-orm/neon-serverless';
import 'drizzle-orm/neon-serverless/migrator';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/node-postgres/migrator';
import 'drizzle-orm/pg-core';
import { pgTable, serial } from 'drizzle-orm/pg-core';
import 'drizzle-orm/planetscale-serverless';
import 'drizzle-orm/planetscale-serverless/migrator';
import 'drizzle-orm/postgres-js';
Expand All @@ -29,9 +29,15 @@ import 'drizzle-orm/sqlite-core';
import 'drizzle-orm/sqlite-proxy';
import 'drizzle-orm/sqlite-proxy/migrator';
import 'drizzle-orm/migrator';
import 'drizzle-zod';
import { createInsertSchema } from 'drizzle-zod';
import { compatibilityVersion, npmVersion } from 'drizzle-orm/version';
import { strict as assert } from 'node:assert';

assert.equal(typeof compatibilityVersion, 'number');
assert.equal(typeof npmVersion, 'string');

const test = pgTable('test', {
id: serial('id').primaryKey(),
});

const insertSchema = createInsertSchema(test);
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"allowUnusedLabels": false /* Disable error reporting for unused labels. */,
"allowUnreachableCode": false /* Disable error reporting for unreachable code. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"noErrorTruncation": true /* Disable truncating types in error messages. */
"noErrorTruncation": true /* Disable truncating types in error messages. */,
"checkJs": true
},
"exclude": ["**/dist"],
"ts-node": {
Expand Down

0 comments on commit aadde62

Please sign in to comment.