Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "functional-models-orm-memory",
"version": "3.0.2",
"version": "3.0.3",
"description": "An in-memory datastore adapter for functional-models",
"main": "index.js",
"types": "index.d.ts",
Expand Down
13 changes: 9 additions & 4 deletions src/datastoreAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ type Props = {
) => string
}

type Database = Record<string, Record<PrimaryKeyType, ToObjectResult<any>>>

const create = ({
seedData,
getCollectionNameForModel = defaultCollectionName,
}: Props = {}): WithRequired<DatastoreAdapter, 'count'> => {
const database: Record<string, Record<string | number, any>> = clone(
seedData
) || {}
}: Props = {}): WithRequired<DatastoreAdapter, 'count'> & {
getRecords: () => Database
} => {
const database: Database = clone(seedData) || {}

const _getRecords = <TData extends DataDescription>(
model: ModelType<TData>
Expand All @@ -43,6 +45,9 @@ const create = ({
}

return {
getRecords: () => {
return database
},
delete: <TData extends DataDescription>(
model: OrmModel<TData>,
id: PrimaryKeyType
Expand Down
7 changes: 7 additions & 0 deletions test/src/datastoreAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe('/src/datastoreAdapter.ts', () => {
const expected = ['save', 'delete', 'retrieve', 'search', 'count']
assert.includeMembers(actual, expected)
})
describe('#getRecords()', () => {
it('should return the database', () => {
const instance = create()
const actual = instance.getRecords()
assert.isOk(actual)
})
})
describe('#retrieve()', () => {
it('should return an object from the seedData when the primary key is provided', async () => {
const { datastoreAdapter, models } = setup(getSeedData1())
Expand Down