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

feat: dual module export #607

Merged
merged 10 commits into from
Oct 18, 2023
Prev Previous commit
Next Next commit
feat: update import extensions to use .js
  • Loading branch information
antstanley committed Oct 18, 2023
commit 9e8abf18715cd3615b1b91fe6afbd76947162c04
22 changes: 11 additions & 11 deletions src/classes/Entity/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ import type {
import cloneDeep from 'deep-copy'
import type { A, B, O } from 'ts-toolbelt'

import parseEntity from '../../lib/parseEntity'
import validateTypes from '../../lib/validateTypes'
import normalizeData from '../../lib/normalizeData'
import formatItem from '../../lib/formatItem'
import getKey from '../../lib/getKey'
import parseConditions from '../../lib/expressionBuilder'
import parseProjections from '../../lib/projectionBuilder'
import { error, transformAttr, isEmpty, If, FirstDefined, Compute } from '../../lib/utils'
import parseEntity from '../../lib/parseEntity.js'
import validateTypes from '../../lib/validateTypes.js'
import normalizeData from '../../lib/normalizeData.js'
import formatItem from '../../lib/formatItem.js'
import getKey from '../../lib/getKey.js'
import parseConditions from '../../lib/expressionBuilder.js'
import parseProjections from '../../lib/projectionBuilder.js'
import { error, transformAttr, isEmpty, If, FirstDefined, Compute } from '../../lib/utils.js'
import {
ATTRIBUTE_VALUES_LIST_DEFAULT_KEY,
ATTRIBUTE_VALUES_LIST_DEFAULT_VALUE,
} from '../../constants'
import type { ScanOptions, TableDef } from '../Table'
} from '../../constants.js'
import type { ScanOptions, TableDef } from '../Table/types.js'
import type {
$GetOptions,
$PutOptions,
Expand All @@ -61,7 +61,7 @@ import type {
Writable,
Readonly,
$PutBatchOptions, AttributeMap,
} from './types'
} from './types.js'

class Entity<Name extends string = string,
// Name is used to detect Entity instances (new Entity(...)) vs Entity type (const e: Entity = ...)
Expand Down
6 changes: 3 additions & 3 deletions src/classes/Entity/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as default } from './Entity'
export * from './Entity'
export * from './types'
export { default as default } from './Entity.js'
export * from './Entity.js'
export * from './types.js'
6 changes: 3 additions & 3 deletions src/classes/Entity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { A, B, O, F } from 'ts-toolbelt'
import { NativeAttributeValue } from '@aws-sdk/util-dynamodb'
import { ReturnConsumedCapacity, ReturnItemCollectionMetrics } from '@aws-sdk/client-dynamodb'

import type { Compute, FirstDefined, If } from '../../lib/utils'
import type { DynamoDBKeyTypes, DynamoDBTypes, $QueryOptions, TableDef } from '../Table'
import Entity from './Entity'
import type { Compute, FirstDefined, If } from '../../lib/utils.js'
import type { DynamoDBKeyTypes, DynamoDBTypes, $QueryOptions, TableDef } from '../Table/types.js'
import Entity from './Entity.js'
import { UpdateCommandInput } from '@aws-sdk/lib-dynamodb'

export interface EntityConstructor<
Expand Down
17 changes: 9 additions & 8 deletions src/classes/Table/Table.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { A, O } from 'ts-toolbelt'

import { parseTable, ParsedTable } from '../../lib/parseTable'
import parseFilters from '../../lib/expressionBuilder'
import validateTypes from '../../lib/validateTypes'
import Entity, { AttributeMap } from '../Entity'
import { parseTable, ParsedTable } from '../../lib/parseTable.js'
import parseFilters from '../../lib/expressionBuilder.js'
import validateTypes from '../../lib/validateTypes.js'
import Entity from '../Entity/Entity.js'
import { AttributeMap } from '../Entity/types.js'
import {
default as parseProjections,
ProjectionAttributes,
ProjectionAttributesTable,
} from '../../lib/projectionBuilder'
import type { ParsedEntity } from '../../lib/parseEntity'
} from '../../lib/projectionBuilder.js'
import type { ParsedEntity } from '../../lib/parseEntity.js'
import type {
BatchGetOptions,
BatchGetParamsMeta,
Expand All @@ -23,9 +24,9 @@ import type {
transactGetParamsOptions,
TransactWriteOptions,
transactWriteParamsOptions,
} from './types'
} from './types.js'

import { error, conditionError, If, Compute } from '../../lib/utils'
import { error, conditionError, If, Compute } from '../../lib/utils.js'
import {
BatchGetCommand,
BatchGetCommandInput, BatchWriteCommand,
Expand Down
6 changes: 3 additions & 3 deletions src/classes/Table/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as default } from './Table'
export * from './Table'
export * from './types'
export { default as default } from './Table.js'
export * from './Table.js'
export * from './types.js'
8 changes: 4 additions & 4 deletions src/classes/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { ReturnConsumedCapacity, ReturnItemCollectionMetrics, Select } from '@aw
import { DynamoDBDocumentClient, ScanCommandInput, TransactGetCommandInput } from '@aws-sdk/lib-dynamodb'
import type { A, O } from 'ts-toolbelt'

import type { ProjectionAttributes } from '../../lib/projectionBuilder'
import type { FilterExpressions } from '../../lib/expressionBuilder'
import type { $ReadOptions, ConditionsOrFilters } from '../Entity'
import type Table from './Table'
import type { ProjectionAttributes } from '../../lib/projectionBuilder.js'
import type { FilterExpressions } from '../../lib/expressionBuilder.js'
import type { $ReadOptions, ConditionsOrFilters } from '../Entity/types.js'
import type Table from './Table.js'

export interface TableConstructor<
Name extends string,
Expand Down
6 changes: 3 additions & 3 deletions src/index.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'
import type {
GetOptions,
QueryOptions,
Expand All @@ -8,7 +8,7 @@ import type {
UpdateOptions,
EntityItem,
InferEntityItem
} from './classes/Entity'
} from './classes/Entity/types.js'

export {
Table,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/checkAttribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { error } from './utils'
import { error } from './utils.js'

// Check attribute against attribute set
export default (attr: string, attrs: any): string => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/expressionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import { A } from 'ts-toolbelt'

import checkAttribute from './checkAttribute'
import { error, toDynamoBigInt } from './utils'
import { TableDef } from '../classes/Table'
import checkAttribute from './checkAttribute.js'
import { error, toDynamoBigInt } from './utils.js'
import { TableDef } from '../classes/Table/types.js'

interface AttrRef {
attr: string
Expand Down
6 changes: 3 additions & 3 deletions src/lib/formatItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

import type { NativeAttributeValue, NativeScalarAttributeValue, NumberValue } from '@aws-sdk/util-dynamodb'
import type { PureAttributeDefinition } from '../classes/Entity'
import validateTypes from './validateTypes'
import type { Linked } from './parseEntity'
import type { PureAttributeDefinition } from '../classes/Entity/types.js'
import validateTypes from './validateTypes.js'
import type { Linked } from './parseEntity.js'

// Convert from DocumentClient values, which may be wrapped sets or numbers,
// into normal TS values.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/getKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @license MIT
*/

import validateTypes from './validateTypes'
import { error, transformAttr } from './utils'
import validateTypes from './validateTypes.js'
import { error, transformAttr } from './utils.js'

// Get partitionKey/sortKey
export default () => (
Expand Down
4 changes: 2 additions & 2 deletions src/lib/normalizeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

import validateTypes from './validateTypes'
import { error, transformAttr } from './utils'
import validateTypes from './validateTypes.js'
import { error, transformAttr } from './utils.js'

// Normalize Data
export default () => (
Expand Down
8 changes: 4 additions & 4 deletions src/lib/parseCompositeKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
import { A, O } from 'ts-toolbelt'

import { error } from './utils'
import parseMapping from './parseMapping'
import { error } from './utils.js'
import parseMapping from './parseMapping.js'
import {
CompositeAttributeDefinition,
PureAttributeDefinition,
AttributeDefinitions
} from '../classes/Entity'
import { TrackingInfo } from './parseEntity'
} from '../classes/Entity/types.js'
import { TrackingInfo } from './parseEntity.js'

const parseCompositeKey = <
ReadonlyAttributeDefinitions extends
Expand Down
8 changes: 4 additions & 4 deletions src/lib/parseEntity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import parseEntityAttributes from './parseEntityAttributes'
import type { TableDef } from '../classes/Table'
import parseEntityAttributes from './parseEntityAttributes.js'
import type { TableDef } from '../classes/Table/types.js'
import type {
AttributeDefinitions,
EntityConstructor,
PureAttributeDefinition,
Readonly
} from '../classes/Entity'
import { error } from './utils'
} from '../classes/Entity/types.js'
import { error } from './utils.js'

export interface TrackingInfo {
fields: string[]
Expand Down
10 changes: 5 additions & 5 deletions src/lib/parseEntityAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
AttributeDefinitions,
PureAttributeDefinition,
CompositeAttributeDefinition
} from '../classes/Entity'
import { TrackingInfo } from './parseEntity'
import parseMapping from './parseMapping'
import parseCompositeKey from './parseCompositeKey'
import { error, typeError, validTypes, isDynamoDbType } from './utils'
} from '../classes/Entity/types.js'
import { TrackingInfo } from './parseEntity.js'
import parseMapping from './parseMapping.js'
import parseCompositeKey from './parseCompositeKey.js'
import { error, typeError, validTypes, isDynamoDbType } from './utils.js'

const parseEntityAttributes = <
ReadonlyAttributeDefinitions extends
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parseMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
SortKeyDefinition,
GSISortKeyDefinition,
PureAttributeDefinition
} from '../classes/Entity'
import { TrackingInfo } from './parseEntity'
import { error } from './utils'
} from '../classes/Entity/types.js'
import { TrackingInfo } from './parseEntity.js'
import { error } from './utils.js'

// Parse and validate mapping config
export default (
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parseTable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { A } from 'ts-toolbelt'

import parseAttributes from './parseTableAttributes'
import { error, hasValue } from './utils'
import { TableConstructor, TableIndexes } from '../classes/Table'
import parseAttributes from './parseTableAttributes.js'
import { error, hasValue } from './utils.js'
import { TableConstructor, TableIndexes } from '../classes/Table/types.js'

export type ParsedTable = ReturnType<typeof parseTable>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/parseTableAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @license MIT
*/

import { TableAttributes, TableAttributeConfig, ParsedTableAttribute } from '../classes/Table'
import { error, typeError, keyTypeError, isDynamoDbType, isDynamoDbKeyType } from './utils'
import { TableAttributes, TableAttributeConfig, ParsedTableAttribute } from '../classes/Table/types.js'
import { error, typeError, keyTypeError, isDynamoDbType, isDynamoDbKeyType } from './utils.js'

// Parse the attributes and verify valid types
export default (attrs: TableAttributes, partitionKey: string, sortKey: string | null) =>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/projectionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import { A } from 'ts-toolbelt'

import { TableDef } from '../classes/Table'
import { error } from './utils'
import checkAttribute from './checkAttribute'
import { TableDef } from '../classes/Table/types.js'
import { error } from './utils.js'
import checkAttribute from './checkAttribute.js'

// This should be able to parse an array with values,
// or an object that uses the name of the entity plus an array of values
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { A, L } from 'ts-toolbelt'

import { PureAttributeDefinition } from '../classes/Entity'
import { DynamoDBTypes, DynamoDBKeyTypes } from '../classes/Table'
import { PureAttributeDefinition } from '../classes/Entity/types.js'
import { DynamoDBTypes, DynamoDBKeyTypes } from '../classes/Table/types.js'
import { unmarshall } from '@aws-sdk/util-dynamodb'

export const validTypes: DynamoDBTypes[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { toBool, hasValue, error, toDynamoBigInt, typeOf, isArrayOfSameType } from './utils'
import { toBool, hasValue, error, toDynamoBigInt, typeOf, isArrayOfSameType } from './utils.js'

// Performs type validation/coercion
export default () => (mapping: any, field: any, value: any) => {
Expand Down