Skip to content

Commit

Permalink
feat: prefix all types with I
Browse files Browse the repository at this point in the history
BREAKING CHANGE: all types exported have been renamed
  • Loading branch information
ruicsh committed Mar 4, 2023
1 parent 5370547 commit c6360c3
Show file tree
Hide file tree
Showing 25 changed files with 440 additions and 382 deletions.
5 changes: 3 additions & 2 deletions src/bug-reports.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IFilterInput } from "src/dynoexpr.d";

import dynoexpr from "./index";
import type { FilterInput } from "./dynoexpr.d";

describe("bug reports", () => {
it("logical operator", () => {
Expand Down Expand Up @@ -59,7 +60,7 @@ describe("bug reports", () => {
a: "<> true",
b: "<> false",
};
const params: FilterInput = { Filter };
const params: IFilterInput = { Filter };
const actual = dynoexpr(params);

const expected = {
Expand Down
160 changes: 87 additions & 73 deletions src/dynoexpr.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/indent */
type LogicalOperatorType = string | "AND" | "OR";
type ILogicalOperatorType = string | "AND" | "OR";

type DynoexprInputValue =
type IDynoexprInputValue =
| string
| string[]
| number
Expand All @@ -15,7 +15,7 @@ type DynoexprInputValue =
| null
| undefined;

type DynamoDbValue =
type IDynamoDbValue =
| string
| string[]
| number
Expand All @@ -28,115 +28,129 @@ type DynamoDbValue =
| unknown;

// batch operations
type BatchGetInput = ProjectionInput & Record<string, unknown>;
type BatchWriteInput = {
type IBatchGetInput = IProjectionInput & Record<string, unknown>;
interface IBatchWriteInput {
DeleteRequest?: unknown;
PutRequest?: unknown;
};
type BatchRequestItemsInput = Record<string, BatchGetInput | BatchWriteInput[]>;
export type BatchRequestInput = {
RequestItems: BatchRequestItemsInput;
}
interface IBatchRequestItemsInput {
[key: string]: IBatchGetInput | IBatchWriteInput[];
}
export interface IBatchRequestInput {
RequestItems: IBatchRequestItemsInput;
[key: string]: unknown;
};
type BatchRequestOutput = {
RequestItems: ProjectionOutput & Record<string, unknown>;
}
interface IBatchRequestOutput {
RequestItems: IProjectionOutput & Record<string, unknown>;
[key: string]: unknown;
};
}

// transact operations
type TransactOperation = "Get" | "ConditionCheck" | "Put" | "Delete" | "Update";
type TransactRequestItems = Partial<Record<TransactOperation, DynoexprInput>>;
export type TransactRequestInput = {
TransactItems: TransactRequestItems[];
type ITransactOperation =
| "Get"
| "ConditionCheck"
| "Put"
| "Delete"
| "Update";

type ITransactRequestItems = Partial<
Record<ITransactOperation, IDynoexprInput>
>;
export interface ITransactRequestInput {
TransactItems: ITransactRequestItems[];
[key: string]: unknown;
};
type TransactRequestOutput = {
TransactItems: TransactRequestItems[];
}
interface ITransactRequestOutput {
TransactItems: ITransactRequestItems[];
[key: string]: unknown;
};
}

// Condition
type Condition = Record<string, DynoexprInputValue>;
type ConditionInput = Partial<{
Condition: Condition;
ConditionLogicalOperator: LogicalOperatorType;
type ICondition = Record<string, IDynoexprInputValue>;
type IConditionInput = Partial<{
Condition: ICondition;
ConditionLogicalOperator: ILogicalOperatorType;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;
type ConditionOutput = Partial<{
type IConditionOutput = Partial<{
ConditionExpression: string;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;

// KeyCondition
type KeyCondition = Record<string, DynoexprInputValue>;
type KeyConditionInput = Partial<{
KeyCondition: KeyCondition;
KeyConditionLogicalOperator: LogicalOperatorType;
type IKeyCondition = Record<string, IDynoexprInputValue>;
type IKeyConditionInput = Partial<{
KeyCondition: IKeyCondition;
KeyConditionLogicalOperator: ILogicalOperatorType;
ExpressionAttributeNames: Record<string, string>;
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;
type KeyConditionOutput = Partial<{
type IKeyConditionOutput = Partial<{
KeyConditionExpression: string;
ExpressionAttributeNames: Record<string, string>;
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;

// Filter
type Filter = Record<string, DynoexprInputValue>;
type FilterInput = Partial<{
Filter: Filter;
FilterLogicalOperator: LogicalOperatorType;
type IFilter = Record<string, IDynoexprInputValue>;
type IFilterInput = Partial<{
Filter: IFilter;
FilterLogicalOperator: ILogicalOperatorType;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;
type FilterOutput = Partial<{
type IFilterOutput = Partial<{
FilterExpression: string;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;

// Projection
type Projection = string[];
type ProjectionInput = Partial<{
Projection: Projection;
ExpressionAttributeNames: Record<string, string>;
}>;
type ProjectionOutput = Partial<{
ProjectionExpression: string;
type IProjection = string[];
type IProjectionInput = Partial<{
Projection: IProjection;
ExpressionAttributeNames: Record<string, string>;
}>;
interface IProjectionOutput {
ProjectionExpression?: string;
ExpressionAttributeNames?: Record<string, string>;
}

// Update
type Update = Record<string, DynoexprInputValue>;
type UpdateAction = "SET" | "ADD" | "DELETE" | "REMOVE";
type UpdateInput = Partial<{
Update?: Update;
UpdateAction?: UpdateAction;
UpdateRemove?: Update;
UpdateAdd?: Update;
UpdateSet?: Update;
UpdateDelete?: Update;
interface IUpdate {
[key: string]: IDynoexprInputValue;
}
type IUpdateAction = "SET" | "ADD" | "DELETE" | "REMOVE";
type IUpdateInput = Partial<{
Update: IUpdate;
UpdateAction: IUpdateAction;
UpdateRemove: IUpdate;
UpdateAdd: IUpdate;
UpdateSet: IUpdate;
UpdateDelete: IUpdate;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;
type UpdateOutput = Partial<{
type IUpdateOutput = Partial<{
UpdateExpression: string;
ExpressionAttributeNames: { [key: string]: string };
ExpressionAttributeValues: { [key: string]: DynamoDbValue };
ExpressionAttributeValues: { [key: string]: IDynamoDbValue };
}>;

export type DynoexprInput = ConditionInput &
FilterInput &
KeyConditionInput &
ProjectionInput &
UpdateInput &
Record<string, unknown>;
export type IDynoexprInput = IConditionInput &
IFilterInput &
IKeyConditionInput &
IProjectionInput &
IUpdateInput & {
[key: string]: unknown;
};

export type DynoexprOutput = ConditionOutput &
FilterOutput &
KeyConditionOutput &
ProjectionOutput &
UpdateOutput &
Record<string, unknown>;
export type IDynoexprOutput = IConditionOutput &
IFilterOutput &
IKeyConditionOutput &
IProjectionOutput &
IUpdateOutput & {
[key: string]: unknown;
};
13 changes: 7 additions & 6 deletions src/expressions/condition.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ConditionInput } from "../dynoexpr";
import type { IConditionInput } from "src/dynoexpr.d";

import { getConditionExpression } from "./condition";

describe("condition expression", () => {
Expand All @@ -14,7 +15,7 @@ describe("condition expression", () => {
g: "BETWEEN 6 AND 7",
h: "IN (foo, bar)",
};
const params: ConditionInput = { Condition };
const params: IConditionInput = { Condition };
const result = getConditionExpression(params);

const expected = {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe("condition expression", () => {
e: "contains(foo)",
f: "size > 10",
};
const params: ConditionInput = { Condition };
const params: IConditionInput = { Condition };
const result = getConditionExpression(params);

const expected = {
Expand Down Expand Up @@ -104,7 +105,7 @@ describe("condition expression", () => {
b: "between 2 and 3",
c: "size > 4",
};
const params: ConditionInput = {
const params: IConditionInput = {
Condition,
ConditionLogicalOperator: "OR",
};
Expand Down Expand Up @@ -138,7 +139,7 @@ describe("condition expression", () => {
a: "attribute_exists",
b: "attribute_not_exists",
};
const params: ConditionInput = { Condition };
const params: IConditionInput = { Condition };
const result = getConditionExpression(params);

const expected = {
Expand All @@ -160,7 +161,7 @@ describe("condition expression", () => {
const Condition = {
key: ["attribute_not_exists", "foobar"],
};
const params: ConditionInput = {
const params: IConditionInput = {
Condition,
ConditionLogicalOperator: "OR",
};
Expand Down
28 changes: 16 additions & 12 deletions src/expressions/condition.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import type { ConditionInput, ConditionOutput } from "../dynoexpr";
import type { IConditionInput, IConditionOutput } from "src/dynoexpr.d";

import {
buildConditionAttributeNames,
buildConditionAttributeValues,
buildConditionExpression,
} from "./helpers";

type GetConditionExpressionFn = (params?: ConditionInput) => ConditionOutput;
export const getConditionExpression: GetConditionExpressionFn = (
params = {}
) => {
if (!params.Condition) return params;
export function getConditionExpression(params: IConditionInput = {}) {
if (!params.Condition) {
return params;
}

const { Condition, ConditionLogicalOperator, ...restOfParams } = params;
const paramsWithConditions: ConditionOutput = {

const ConditionExpression = buildConditionExpression({
Condition,
LogicalOperator: ConditionLogicalOperator,
});

const paramsWithConditions: IConditionOutput = {
...restOfParams,
ConditionExpression: buildConditionExpression({
Condition,
LogicalOperator: ConditionLogicalOperator,
}),
ConditionExpression,
ExpressionAttributeNames: buildConditionAttributeNames(Condition, params),
ExpressionAttributeValues: buildConditionAttributeValues(Condition, params),
};
Expand All @@ -33,4 +37,4 @@ export const getConditionExpression: GetConditionExpressionFn = (
}

return paramsWithConditions;
};
}
9 changes: 5 additions & 4 deletions src/expressions/filter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FilterInput } from "../dynoexpr";
import type { IFilterInput } from "src/dynoexpr.d";

import { getFilterExpression } from "./filter";

describe("filter expression", () => {
Expand All @@ -20,7 +21,7 @@ describe("filter expression", () => {
m: "BETWEEN you AND me",
n: "IN (foo, bar)",
};
const params: FilterInput = { Filter };
const params: IFilterInput = { Filter };
const result = getFilterExpression(params);

const expected = {
Expand Down Expand Up @@ -92,7 +93,7 @@ describe("filter expression", () => {
e: "contains(foo)",
f: "size > 10",
};
const params: FilterInput = { Filter };
const params: IFilterInput = { Filter };
const result = getFilterExpression(params);

const expected = {
Expand Down Expand Up @@ -129,7 +130,7 @@ describe("filter expression", () => {
b: "between 2 and 3",
c: "size > 4",
};
const params: FilterInput = { Filter };
const params: IFilterInput = { Filter };
const result = getFilterExpression(params);

const expected = {
Expand Down

0 comments on commit c6360c3

Please sign in to comment.