Skip to content

Commit

Permalink
Exporting all types
Browse files Browse the repository at this point in the history
  • Loading branch information
tywalch committed Jun 30, 2022
1 parent 05aeb41 commit b742c70
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 57 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,8 @@ All notable changes to this project will be documented in this file. Breaking ch
### Fixed
- TypeScript 4.7 introduced changes that caused type inference issues with the Entity, Service, and exposed types. A re-vamp of some typing was done to rectify these issues, new tests and existing tests were made work with the latest versions of TypeScript and tsd.
### Changed
- Project now is more deliberate about the types exposed via the package. This is because I have moved away from a single type definition file (which by default exports all types). If you had a dependency on a type that used to be exposed, open a ticket and I can expose it. In the future exposed types will be the only types officially supported by semver.
- Project now is more deliberate about the types exposed via the package. This is because I have moved away from a single type definition file (which by default exports all types). If you had a dependency on a type that used to be exposed, open a ticket and I can expose it. In the future exposed types will be the only types officially supported by semver.

## [1.10.1] - 2022-06-30
### Fixed
- Exported additional types
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Entity } from './src/entity';
export { Service } from './src/service';
export * from './src/entity';
export * from './src/service';
export * from './src/types';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrodb",
"version": "1.10.0",
"version": "1.10.1",
"description": "A library to more easily create and interact with multiple entities and heretical relationships in dynamodb",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import { ElectroEventListener } from './types/events';
import { DocumentClient } from './types/client';

export type Resolve<T> = T extends Function | string | number | boolean
type Resolve<T> = T extends Function | string | number | boolean
? T : {[Key in keyof T]: Resolve<T[Key]>}

export type EntityConfiguration = {
Expand Down
2 changes: 1 addition & 1 deletion src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ class Entity {
let pattern = `^${this._regexpEscape(prefix)}`;
let labels = this.model.facets.labels[index][keyType] || [];
for (let {name, label} of labels) {
let { type } = this.model.schema.attributes[name];
let { type } = this.model.schema.attributes[name] || {};
if (isCustom) {
pattern += `${this._regexpEscape(label === undefined ? "" : label)}(.+)`;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/types/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type DocumentClientMethod = (parameters: any) => {promise: () => Promise<any>};
export type DocumentClientMethod = (parameters: any) => {promise: () => Promise<any>};

export type DocumentClient = {
get: DocumentClientMethod;
Expand Down
34 changes: 17 additions & 17 deletions src/types/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
WhereAttributeSymbol
} from './where';

type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
export type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
[Name in keyof E]:
E[Name] extends Entity<infer A, infer F, infer C, infer S>
? {
Expand All @@ -24,13 +24,13 @@ type AllCollectionNames<E extends {[name: string]: Entity<any, any, any, any>}>
: never
}[keyof E];

type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
export type AllEntityAttributeNames<E extends {[name: string]: Entity<any, any, any, any>}> = {
[Name in keyof E]: {
[A in keyof E[Name]["schema"]["attributes"]]: A
}[keyof E[Name]["schema"]["attributes"]]
}[keyof E];

type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
export type AllEntityAttributes<E extends {[name: string]: Entity<any, any, any, any>}> = {
[Attr in AllEntityAttributeNames<E>]: {
[Name in keyof E]: Attr extends keyof E[Name]["schema"]["attributes"]
? ItemAttribute<E[Name]["schema"]["attributes"][Attr]>
Expand All @@ -48,7 +48,7 @@ export type CollectionAssociations<E extends {[name: string]: Entity<any, any, a
}[keyof E];
}

type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
export type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
[Collection in keyof Collections]: {
[EntityName in keyof E]: E[EntityName] extends Entity<infer A, infer F, infer C, infer S>
? EntityName extends Collections[Collection]
Expand All @@ -58,7 +58,7 @@ type CollectionAttributes<E extends {[name: string]: Entity<any, any, any, any>}
}[keyof E]
}

interface CollectionWhereOperations {
export interface CollectionWhereOperations {
eq: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
ne: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
gt: <T, A extends WhereAttributeSymbol<T>>(attr: A, value: T) => string;
Expand All @@ -75,19 +75,19 @@ interface CollectionWhereOperations {
name: <T, A extends WhereAttributeSymbol<T>>(attr: A) => string;
}

type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
export type CollectionWhereCallback<E extends {[name: string]: Entity<any, any, any, any>}, I extends Partial<AllEntityAttributes<E>>> =
<W extends {[A in keyof I]: WhereAttributeSymbol<I[A]>}>(attributes: W, operations: CollectionWhereOperations) => string;

type CollectionWhereClause<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, T> = (where: CollectionWhereCallback<E, I>) => T;
export type CollectionWhereClause<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, T> = (where: CollectionWhereCallback<E, I>) => T;

interface WhereRecordsActionOptions<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, Items, IndexCompositeAttributes> {
export interface WhereRecordsActionOptions<E extends {[name: string]: Entity<any, any, any, any>}, A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends Partial<AllEntityAttributes<E>>, Items, IndexCompositeAttributes> {
go: GoRecord<Items>;
params: ParamRecord;
page: PageRecord<Items,IndexCompositeAttributes>;
where: CollectionWhereClause<E,A,F,C,S,I, WhereRecordsActionOptions<E,A,F,C,S,I,Items,IndexCompositeAttributes>>;
}

type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
export type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
[Collection in keyof Collections]: {
[EntityResultName in Collections[Collection]]:
EntityResultName extends keyof Entities
Expand All @@ -98,7 +98,7 @@ type CollectionIndexKeys<Entities extends {[name: string]: Entity<any, any, any,
}[Collections[Collection]]
}

type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
export type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
[Collection in keyof Collections]: {
[EntityResultName in Collections[Collection]]:
EntityResultName extends keyof Entities
Expand All @@ -113,7 +113,7 @@ type CollectionPageKeys<Entities extends {[name: string]: Entity<any, any, any,
}[Collections[Collection]]
}

type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
export type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
[Collection in keyof CollectionIndexKeys<Entities, Collections>]: {
[key in CollectionIndexKeys<Entities, Collections>[Collection]]:
key extends keyof AllEntityAttributes<Entities>
Expand All @@ -122,7 +122,7 @@ type CollectionIndexAttributes<Entities extends {[name: string]: Entity<any, any
}
}

type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
export type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<Entities>> = {
[Collection in keyof CollectionPageKeys<Entities, Collections>]: {
[key in CollectionPageKeys<Entities, Collections>[Collection]]:
key extends keyof AllEntityAttributes<Entities>
Expand All @@ -131,17 +131,17 @@ type CollectionPageAttributes<Entities extends {[name: string]: Entity<any, any,
}
}

type OptionalPropertyNames<T> =
export type OptionalPropertyNames<T> =
{ [K in keyof T]: undefined extends T[K] ? K : never }[keyof T];

// Common properties from L and R with undefined in R[K] replaced by type in L[K]
type SpreadProperties<L, R, K extends keyof L & keyof R> =
export type SpreadProperties<L, R, K extends keyof L & keyof R> =
{ [P in K]: L[P] | Exclude<R[P], undefined> };

type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*
export type Id<T> = {[K in keyof T]: T[K]} // see note at bottom*

// Type of { ...L, ...R }
type Spread<L, R> = Id<
export type Spread<L, R> = Id<
// Properties in L that don't exist in R
& Pick<L, Exclude<keyof L, keyof R>>
// Properties in R with types that exclude undefined
Expand All @@ -152,7 +152,7 @@ type Spread<L, R> = Id<
& SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
>;

type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>
export type RequiredProperties<T> = Pick<T, {[K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T]>

export type CollectionQueries<E extends {[name: string]: Entity<any, any, any, any>}, Collections extends CollectionAssociations<E>> = {
[Collection in keyof Collections]: {
Expand Down
10 changes: 5 additions & 5 deletions src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";
export type ElectroDBMethodTypes = "put" | "get" | "query" | "scan" | "update" | "delete" | "remove" | "patch" | "create" | "batchGet" | "batchWrite";

interface ElectroQueryEvent<P extends any = any> {
export interface ElectroQueryEvent<P extends any = any> {
type: 'query';
method: ElectroDBMethodTypes;
config: any;
params: P;
}

interface ElectroResultsEvent<R extends any = any> {
export interface ElectroResultsEvent<R extends any = any> {
type: 'results';
method: ElectroDBMethodTypes;
config: any;
results: R;
success: boolean;
}

type ElectroEvent =
export type ElectroEvent =
ElectroQueryEvent
| ElectroResultsEvent;

type ElectroEventType = Pick<ElectroEvent, 'type'>;
export type ElectroEventType = Pick<ElectroEvent, 'type'>;

export type ElectroEventListener = (event: ElectroEvent) => void;

Expand Down
9 changes: 7 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { ResponseItem, PutItem, AddItem, SubtractItem, AppendItem, RemoveItem, D
import { Service } from '../service';
import { CollectionAssociations } from './collections';

export { WhereAttributeSymbol } from './where';
export { Schema } from './schema';
export * from './where';
export * from './schema';
export * from './options';
export * from './client';
export * from './collections';
export * from './model';
export * from './events';

export type EntityItem<E extends Entity<any, any, any, any>> =
E extends Entity<infer A, infer F, infer C, infer S>
Expand Down
12 changes: 6 additions & 6 deletions src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,32 @@ export interface SingleRecordOperationOptions<A extends string, F extends string
go: GoRecord<ResponseType, QueryOptions>;
params: ParamRecord<QueryOptions>;
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,SingleRecordOperationOptions<A,F,C,S,ResponseType>>;
};
}

export interface PutRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
go: GoRecord<ResponseType, PutQueryOptions>;
params: ParamRecord<PutQueryOptions>;
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
};
}

export interface UpdateRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
go: GoRecord<ResponseType, UpdateQueryOptions>;
params: ParamRecord<UpdateQueryParams>;
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,PutRecordOperationOptions<A,F,C,S,ResponseType>>;
};
}

export interface DeleteRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType> {
go: GoRecord<ResponseType, DeleteQueryOptions>;
params: ParamRecord<DeleteQueryOptions>;
where: WhereClause<A,F,C,S,Item<A,F,C,S,S["attributes"]>,DeleteRecordOperationOptions<A,F,C,S,ResponseType>>;
};
}

export interface BulkRecordOperationOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, ResponseType, AlternateResponseType> {
go: BatchGoRecord<ResponseType, AlternateResponseType>;
params: ParamRecord<BulkOptions>;
};
}

interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
export interface SetRecordActionOptions<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, SetAttr,IndexCompositeAttributes,TableItem> {
go: GoRecord<Partial<TableItem>, UpdateQueryOptions>;
params: ParamRecord<UpdateQueryParams>;
set: SetRecord<A,F,C,S, SetItem<A,F,C,S>,IndexCompositeAttributes,TableItem>;
Expand Down
26 changes: 13 additions & 13 deletions src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export interface NumberSetAttribute {
readonly watch?: ReadonlyArray<string> | "*";
}

type Attribute =
export type Attribute =
BooleanAttribute
| NumberAttribute
| StringAttribute
Expand All @@ -386,7 +386,7 @@ type Attribute =
| NumberListAttribute
| MapListAttribute;

type NestedAttributes =
export type NestedAttributes =
NestedBooleanAttribute
| NestedNumberAttribute
| NestedStringAttribute
Expand All @@ -407,7 +407,7 @@ export interface IndexWithSortKey {
}
}

type AccessPatternCollection<C extends string> = C | ReadonlyArray<C>;
export type AccessPatternCollection<C extends string> = C | ReadonlyArray<C>;

export interface Schema<A extends string, F extends string, C extends string> {
readonly model: {
Expand Down Expand Up @@ -436,9 +436,9 @@ export interface Schema<A extends string, F extends string, C extends string> {
}
}
}
};
}

type Attributes<A extends string> = Record<A, Attribute>
export type Attributes<A extends string> = Record<A, Attribute>

export type IndexCollections<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = {
[i in keyof S["indexes"]]: S["indexes"][i]["collection"] extends
Expand All @@ -464,7 +464,7 @@ export type EntityCollections<A extends string, F extends string, C extends stri
declare const SkipSymbol: unique symbol;
type SkipValue = typeof SkipSymbol;

type DefinedKeys<T> = {
type DefinedKeys<T> = {
[P in keyof T as
[undefined] extends [T[P]]
? never
Expand Down Expand Up @@ -540,7 +540,7 @@ type FormattedPutMapAttributes<A extends MapAttribute> = {
: false
}

type ReturnedAttribute<A extends Attribute> =
export type ReturnedAttribute<A extends Attribute> =
A["type"] extends infer R
? R extends "string" ? string
: R extends "number" ? number
Expand Down Expand Up @@ -612,7 +612,7 @@ type ReturnedAttribute<A extends Attribute> =
: never
: never

type CreatedAttribute<A extends Attribute> =
export type CreatedAttribute<A extends Attribute> =
A["type"] extends infer R
? R extends "string" ? string
: R extends "number" ? number
Expand Down Expand Up @@ -692,7 +692,7 @@ export type CreatedItem<A extends string, F extends string, C extends string, S
[a in keyof Attr]: CreatedAttribute<Attr[a]>
}

type EditableItemAttribute<A extends Attribute> =
export type EditableItemAttribute<A extends Attribute> =
A extends ReadOnlyAttribute
? never
: A["type"] extends infer R
Expand Down Expand Up @@ -735,7 +735,7 @@ type EditableItemAttribute<A extends Attribute> =
: never
: never

type UpdatableItemAttribute<A extends Attribute> =
export type UpdatableItemAttribute<A extends Attribute> =
A extends ReadOnlyAttribute
? never
: A["type"] extends infer R
Expand Down Expand Up @@ -793,7 +793,7 @@ type UpdatableItemAttribute<A extends Attribute> =
: never
: never

type RemovableItemAttribute<A extends Attribute> =
export type RemovableItemAttribute<A extends Attribute> =
A extends ReadOnlyAttribute | RequiredAttribute
? never
: A["type"] extends infer R
Expand Down Expand Up @@ -894,9 +894,9 @@ export type TableIndexPKCompositeAttributes<A extends string, F extends string,

export type TableIndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> = Pick<SKCompositeAttributes<A,F,C,S>, TableIndexName<A,F,C,S>>;

type IndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<PKCompositeAttributes<A,F,C,S>,I>;
export type IndexPKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<PKCompositeAttributes<A,F,C,S>,I>;

type IndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<SKCompositeAttributes<A,F,C,S>,I>;
export type IndexSKCompositeAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>, I extends keyof S["indexes"]> = Pick<SKCompositeAttributes<A,F,C,S>,I>;

export type TableIndexPKAttributes<A extends string, F extends string, C extends string, S extends Schema<A,F,C>> =
TableIndexName<A,F,C,S> extends keyof TableIndexPKCompositeAttributes<A,F,C,S>
Expand Down
Loading

0 comments on commit b742c70

Please sign in to comment.