Skip to content

Commit

Permalink
feat: dual module export (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
antstanley committed Oct 18, 2023
1 parent d0bb431 commit 67914eb
Show file tree
Hide file tree
Showing 68 changed files with 228 additions and 178 deletions.
13 changes: 11 additions & 2 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ module.exports = {
testMatch: ['**/?(*.)+(unit.test).+(ts|tsx|js)'],
testPathIgnorePatterns: ['/__tests__/entities/*', '/__tests__/tables/*'],
coveragePathIgnorePatterns: ['/__tests__/*'],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest'
}
'^.+\\.[tj]sx?$': [
'ts-jest',
{
useESM: true,
},
],
},
}
34 changes: 27 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@
"name": "dynamodb-toolbox",
"description": "A simple set of tools for working with Amazon DynamoDB and the DocumentClient.",
"author": "Jeremy Daly <jeremy@jeremydaly.com>",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"import": {
"default": "./dist/esm/index.js",
"types": "./dist/esm/index.d.ts"
},
"require": {
"default": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts"
}
}
},
"type": "module",
"scripts": {
"test": "jest unit",
"test-cov": "jest unit --coverage",
"test-ci": "eslint . && jest unit --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test-types": "tsd",
"check-types": "tsc --noEmit",
"lint": "eslint .",
"build": "rm -rf dist && tsc -p tsconfig.build.json",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{ \"type\": \"commonjs\" }' > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.esm.json && echo '{ \"type\": \"module\" }' > dist/esm/package.json",
"build": "npm run build:cjs & npm run build:esm",
"prebuild": "rm -rf dist",
"prepublishOnly": "npm test && npm run lint && npm run test-types",
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline"
},
Expand Down Expand Up @@ -62,9 +78,13 @@
"typescript": "^4.1.3"
},
"files": [
"dist/index.*",
"dist/constants.*",
"dist/classes/",
"dist/lib/"
"dist/cjs/index.*",
"dist/cjs/constants.*",
"dist/cjs/classes/",
"dist/cjs/lib/",
"dist/esm/index.*",
"dist/esm/constants.*",
"dist/esm/classes/",
"dist/esm/lib/"
]
}
6 changes: 3 additions & 3 deletions src/__tests__/checkAttribute.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import checkAttribute from '../lib/checkAttribute'
import checkAttribute from '../lib/checkAttribute.js'

// Require Table and Entity classes
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

// Create basic table
const DefaultTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity-creation.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test.js'

const tableAddEntity = jest.spyOn(Table.prototype, 'addEntity').mockReturnValue()

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity-properties.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

describe('Entity properties', () => {
describe('table', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.delete.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '..'
import { DocumentClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.get.int.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.get.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '..'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity.parse.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DocumentClientWithWrappedNumbers } from './bootstrap.test'
import { DocumentClientWithWrappedNumbers } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { unmarshall } from '@aws-sdk/util-dynamodb'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.put.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.putBatch.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/entity.transaction.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/entity.update.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
ATTRIBUTE_VALUES_LIST_DEFAULT_KEY,
ATTRIBUTE_VALUES_LIST_DEFAULT_VALUE
} from '../constants'
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
} from '../constants.js'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/entity.utils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { shouldExecute, shouldParse } from '../classes/Entity'
import { shouldExecute, shouldParse } from '../classes/Entity/Entity.js'

describe('Entity - utils', () => {
it('should execute', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/expressionBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import {
default as expressionBuilder,
SUPPORTED_FILTER_EXP_ATTR_REF_OPERATORS
} from '../lib/expressionBuilder'
} from '../lib/expressionBuilder.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/format.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/formatItem.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import formatItem from '../lib/formatItem'
import formatItem from '../lib/formatItem.js'

import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

// Create basic table
const DefaultTable = new Table({
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/misc-tests.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

describe('Misc Tests (development only)', () => {
it('uses a numeric pk value', async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/normalizeData.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import normalizeData from '../lib/normalizeData'
import normalizeData from '../lib/normalizeData.js'

import { DocumentClient } from './bootstrap.test'
import { DocumentClient } from './bootstrap.test.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

const DefaultTable = new Table({
name: 'test-table',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/parse-alias.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-alias',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/parse.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Table from '../classes/Table'
import Entity from '../classes/Entity'
import { DocumentClient } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseCompositeKey.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TrackingInfo } from '../lib/parseEntity'
import parseCompositeKey from '../lib/parseCompositeKey'
import { TrackingInfo } from '../lib/parseEntity.js'
import parseCompositeKey from '../lib/parseCompositeKey.js'

// Simulate attributes
const attributes = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/parseEntity.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parseEntity from '../lib/parseEntity'
import parseEntity from '../lib/parseEntity.js'

// Simulate Entity config
const entity = {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseMapping.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parseMapping from '../lib/parseMapping'
import { TrackingInfo } from '../lib/parseEntity'
import parseMapping from '../lib/parseMapping.js'
import { TrackingInfo } from '../lib/parseEntity.js'

let track: TrackingInfo = {
fields: [],
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseTable.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import parseTable from '../lib/parseTable'
import parseTable from '../lib/parseTable.js'

// Require Table and Entity classes
import { TableConstructor } from '../classes/Table'
import { TableConstructor } from '../classes/Table/types.js'

const table: TableConstructor<'test-table', 'pk', 'sk'> = {
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/parseTableAttributes.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TableAttributes } from '../classes/Table'
import parseTableAttributes from '../lib/parseTableAttributes'
import { TableAttributes } from '../classes/Table/types.js'
import parseTableAttributes from '../lib/parseTableAttributes.js'

const attrs: TableAttributes = {
pk: 'string',
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/projectionBuilder.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import projectionBuilder from '../lib/projectionBuilder'
import projectionBuilder from '../lib/projectionBuilder.js'

import Table from '../classes/Table'
import Entity from '../classes/Entity'
import Table from '../classes/Table/Table.js'
import Entity from '../classes/Entity/Entity.js'

const DefaultTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table-creation.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Table from '../classes/Table'
import { DocumentClient, DocumentClientWithoutConfig } from './bootstrap.test'
import Table from '../classes/Table/Table.js'
import { DocumentClient, DocumentClientWithoutConfig } from './bootstrap.test.js'

describe('Table creation', () => {
it('creates table w/ minimum options', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.batchGet.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.batchWrite.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BatchWriteCommandInput } from '@aws-sdk/lib-dynamodb'
import { Entity, Table } from '../index'
import { DocumentClient as docClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient as docClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.entities.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

let TestTable: any
let TestEntity: any
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.entity-actions.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.query.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.scan.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, Table } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Entity, Table } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.transactGet.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient } from './bootstrap.test.js'

const TestTable = new Table({
name: 'test-table',
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/table.transactWrite.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Table, Entity } from '../index'
import { DocumentClient as docClient } from './bootstrap.test'
import { Table, Entity } from '../index.js'
import { DocumentClient as docClient } from './bootstrap.test.js'
import assert from 'assert'

const TestTable = new Table({
Expand Down
Loading

0 comments on commit 67914eb

Please sign in to comment.