Skip to content

Commit

Permalink
Switch to new style imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Mar 10, 2023
1 parent 9fb56c7 commit b7f863d
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 35 deletions.
3 changes: 3 additions & 0 deletions fix-commonjs-dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as fs from 'fs'

fs.writeFileSync('./dist/main/package.json', '{"type": "commonjs"}')
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
export default {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
}
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
"dist",
"src"
],
"type": "module",
"main": "dist/main/index.js",
"module": "dist/module/index.js",
"types": "dist/module/index.d.ts",
"exports": {
"require": "./dist/main/index.js",
"import": "./dist/module/index.js",
"types": "./dist/module/index.d.ts"
},
"repository": "supabase/postgrest-js",
"scripts": {
"clean": "rimraf dist docs/v2",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"build": "run-s clean format build:*",
"build:main": "tsc -p tsconfig.json",
"build:main": "tsc -p tsconfig.json && node ./fix-commonjs-dist.js",
"build:module": "tsc -p tsconfig.module.json",
"docs": "typedoc src/index.ts --out docs/v2",
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/PostgrestBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crossFetch from 'cross-fetch'

import type { Fetch, PostgrestSingleResponse } from './types'
import type { Fetch, PostgrestSingleResponse } from './types.js'

export default abstract class PostgrestBuilder<Result>
implements PromiseLike<PostgrestSingleResponse<Result>>
Expand Down
10 changes: 5 additions & 5 deletions src/PostgrestClient.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PostgrestQueryBuilder from './PostgrestQueryBuilder'
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
import PostgrestBuilder from './PostgrestBuilder'
import { DEFAULT_HEADERS } from './constants'
import { Fetch, GenericSchema } from './types'
import PostgrestQueryBuilder from './PostgrestQueryBuilder.js'
import PostgrestFilterBuilder from './PostgrestFilterBuilder.js'
import PostgrestBuilder from './PostgrestBuilder.js'
import { DEFAULT_HEADERS } from './constants.js'
import { Fetch, GenericSchema } from './types.js'

/**
* PostgREST client.
Expand Down
4 changes: 2 additions & 2 deletions src/PostgrestFilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PostgrestTransformBuilder from './PostgrestTransformBuilder'
import { GenericSchema } from './types'
import PostgrestTransformBuilder from './PostgrestTransformBuilder.js'
import { GenericSchema } from './types.js'

type FilterOperator =
| 'eq'
Expand Down
8 changes: 4 additions & 4 deletions src/PostgrestQueryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PostgrestBuilder from './PostgrestBuilder'
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
import { GetResult } from './select-query-parser'
import { Fetch, GenericSchema, GenericTable, GenericView } from './types'
import PostgrestBuilder from './PostgrestBuilder.js'
import PostgrestFilterBuilder from './PostgrestFilterBuilder.js'
import { GetResult } from './select-query-parser.js'
import { Fetch, GenericSchema, GenericTable, GenericView } from './types.js'

export default class PostgrestQueryBuilder<
Schema extends GenericSchema,
Expand Down
6 changes: 3 additions & 3 deletions src/PostgrestTransformBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PostgrestBuilder from './PostgrestBuilder'
import { GetResult } from './select-query-parser'
import { GenericSchema } from './types'
import PostgrestBuilder from './PostgrestBuilder.js'
import { GetResult } from './select-query-parser.js'
import { GenericSchema } from './types.js'

export default class PostgrestTransformBuilder<
Schema extends GenericSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { version } from './version'
import { version } from './version.js'
export const DEFAULT_HEADERS = { 'X-Client-Info': `postgrest-js/${version}` }
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export { default as PostgrestClient } from './PostgrestClient'
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder'
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder'
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder'
export { default as PostgrestBuilder } from './PostgrestBuilder'
export { default as PostgrestClient } from './PostgrestClient.js'
export { default as PostgrestQueryBuilder } from './PostgrestQueryBuilder.js'
export { default as PostgrestFilterBuilder } from './PostgrestFilterBuilder.js'
export { default as PostgrestTransformBuilder } from './PostgrestTransformBuilder.js'
export { default as PostgrestBuilder } from './PostgrestBuilder.js'
export {
PostgrestResponse,
PostgrestResponseFailure,
PostgrestResponseSuccess,
PostgrestSingleResponse,
PostgrestMaybeSingleResponse,
PostgrestError,
} from './types'
} from './types.js'
2 changes: 1 addition & 1 deletion src/select-query-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query)

import { GenericSchema, Prettify } from './types'
import { GenericSchema, Prettify } from './types.js'

type Whitespace = ' ' | '\n' | '\t'

Expand Down
4 changes: 2 additions & 2 deletions test/basic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostgrestClient } from '../src/index'
import { Database } from './types'
import { PostgrestClient } from '../src/index.js'
import { Database } from './types.js'

const REST_URL = 'http://localhost:3000'
const postgrest = new PostgrestClient<Database>(REST_URL)
Expand Down
4 changes: 2 additions & 2 deletions test/filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostgrestClient } from '../src/index'
import { Database } from './types'
import { PostgrestClient } from '../src/index.js'
import { Database } from './types.js'

const postgrest = new PostgrestClient<Database>('http://localhost:3000')

Expand Down
4 changes: 2 additions & 2 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectError, expectType } from 'tsd'
import { PostgrestClient } from '../src/index'
import { Database, Json } from './types'
import { PostgrestClient } from '../src/index.js'
import { Database, Json } from './types.js'

const REST_URL = 'http://localhost:3000'
const postgrest = new PostgrestClient<Database>(REST_URL)
Expand Down
4 changes: 2 additions & 2 deletions test/resource-embedding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostgrestClient } from '../src/index'
import { Database } from './types'
import { PostgrestClient } from '../src/index.js'
import { Database } from './types.js'

const postgrest = new PostgrestClient<Database>('http://localhost:3000')

Expand Down
4 changes: 2 additions & 2 deletions test/transforms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostgrestClient } from '../src/index'
import { Database } from './types'
import { PostgrestClient } from '../src/index.js'
import { Database } from './types.js'

import { AbortController } from 'node-abort-controller'

Expand Down

0 comments on commit b7f863d

Please sign in to comment.