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

chore: cleanup unused code #494

Merged
merged 15 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
naorpeled committed Apr 8, 2023
commit 2635ad5829646f19a4bf9f0ff424193d628fcc94
2 changes: 1 addition & 1 deletion src/__tests__/parse.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ describe('parse', () => {
// test_composite3: 'foo'
// })
// })
}) // end parse
})
8 changes: 4 additions & 4 deletions src/__tests__/table-creation.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Table creation', () => {
binarySetAttr: { type: 'set', setType: 'binary', mappings: {} },
_et: { type: 'string', mappings: {} }
})
}) // end table w/ attributes
})

it('creates table w/ indexes', async () => {
const TestTable = new Table({
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('Table creation', () => {
LSI1: { sortKey: 'LSI1sk', type: 'LSI' },
LSI2: { sortKey: 'LSI2sk', type: 'LSI' }
})
}) // end table w/ indexes
})

it('creates table w/ DocumentClient', async () => {
const TestTable = new Table({
Expand All @@ -137,7 +137,7 @@ describe('Table creation', () => {
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])
}) // end create table w/ DocumentClient
})

it('creates table, then add DocumentClient', async () => {
const TestTable = new Table({
Expand All @@ -159,5 +159,5 @@ describe('Table creation', () => {
expect(TestTable.autoExecute).toBe(true)
expect(TestTable.autoParse).toBe(true)
expect(TestTable.entities).toEqual([])
}) // end create table w/ DocumentClient
})
})
2 changes: 1 addition & 1 deletion src/__tests__/table.entity-actions.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ describe('table.parse', () => {
// @ts-expect-error
expect(TestTable.parse('TestEntityX')).rejects.toThrow(`'TestEntityX' is not a valid Entity`)
})
}) // end table.parse
})
20 changes: 10 additions & 10 deletions src/classes/Entity/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Entity<Name extends string = string,
: this.schema.attributes[attr]
? attr
: error(`'${attr}' does not exist or is an invalid alias`)
} // end attribute
}

// Parses the item
parse(input: { Item: unknown }, include?: string[]): Item
Expand Down Expand Up @@ -266,7 +266,7 @@ class Entity<Name extends string = string,
} else {
return formatItem()(schema.attributes, linked, data, include) as any
}
} // end parse
}

/**
* Generate GET parameters and execute operation
Expand Down Expand Up @@ -476,7 +476,7 @@ class Entity<Name extends string = string,
)

return payload
} // end getParams
}

/**
* Generate DELETE parameters and execute operation
Expand Down Expand Up @@ -703,7 +703,7 @@ class Entity<Name extends string = string,
)

return payload
} // end deleteParams
}

/**
* Generate UPDATE parameters and execute operations
Expand Down Expand Up @@ -965,7 +965,7 @@ class Entity<Name extends string = string,
this.schema.attributes[field].alias ? `/${this.schema.attributes[field].alias}` : ''
}' is a required field`,
),
) // end required field check
)

// Get partition and sort keys
const Key = getKey()(
Expand Down Expand Up @@ -1016,7 +1016,7 @@ class Entity<Name extends string = string,
const attr = schema.attributes[attrs[i]].map || attrs[i]
REMOVE.push(`#${attr}`)
names[`#${attr}`] = attr
} // end for
}
} else if (
this._table!._removeNulls === true &&
(data[field] === null || String(data[field]).trim() === '') &&
Expand Down Expand Up @@ -1187,7 +1187,7 @@ class Entity<Name extends string = string,
values[`:${field}`] = value
}
}
} // end if undefined
}
})

// Create the update expression
Expand Down Expand Up @@ -1215,12 +1215,12 @@ class Entity<Name extends string = string,
capacity ? { ReturnConsumedCapacity: capacity.toUpperCase() } : null,
metrics ? { ReturnItemCollectionMetrics: metrics.toUpperCase() } : null,
returnValues ? { ReturnValues: returnValues.toUpperCase() } : null,
) // end assign
)

return payload

// TODO: Check why primary/secondary GSIs are using if_not_exists
} // end updateParams
}

// PUT - put item
async put<MethodItemOverlay extends Overlay = undefined,
Expand Down Expand Up @@ -1520,7 +1520,7 @@ class Entity<Name extends string = string,
)

return payload
} // end putParams
}

/**
* Generate parameters for ConditionCheck transaction operation
Expand Down
10 changes: 4 additions & 6 deletions src/lib/expressionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const buildExpression = <
// Capture the first logic indicator at this level
logic = logic ? logic : clause.logic
}
}) // end for
})

return {
logic,
Expand Down Expand Up @@ -321,22 +321,20 @@ const parseClause = <EntityTable extends TableDef | undefined = undefined>(
} else {
clause = `${size ? `size(${operand})` : operand} ${operator} :attr${grp}`
}
} // end if-else
}

// Negate the clause
if (negate) {
clause = `(NOT ${clause})`
}
} else {
error('A condition is required')
} // end if operator

// console.log('CLAUSE:',clause,'\nNAMES:',names,'\nVALUES:',values)
}

return {
logic: or ? 'OR' : 'AND',
clause,
names,
values
}
} // end parseClause
}
2 changes: 1 addition & 1 deletion src/lib/normalizeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default () => (
}
return map
}
} // end dependsOn
}

// Generate normalized data object
const dataMap = Object.keys(data).reduce(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/parseMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default (
} else {
error(`Index assignments for '${field}' must be string or boolean values`)
}
} // end for
}
} else {
error(`'${prop}' must be a boolean, string, or array`)
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/parseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export const parseTable = <
autoExecute,
autoParse,
removeNullAttributes,
_entities: [] // init Entity tracker
_entities: []
},
DocumentClient ? { DocumentClient } : {}, // end DocumentClient
entities ? { entities } : {} // end entities
DocumentClient ? { DocumentClient } : {},
entities ? { entities } : {}
)
} // end parseTable
}

// Parse Indexes
const parseIndexes = (indexes: TableIndexes, pk: string): TableIndexes =>
Expand Down Expand Up @@ -152,7 +152,7 @@ const parseIndexes = (indexes: TableIndexes, pk: string): TableIndexes =>
partitionKey && type === 'GSI' ? { partitionKey } : {},
sortKey ? { sortKey } : {},
{ type }
) // end
)
})
}, {})

Expand Down
2 changes: 1 addition & 1 deletion src/lib/validateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ export default () => (mapping: any, field: any, value: any) => {
// TODO: Binary validation
return value
}
} // end validateTypes
}