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

Adding sql requests #91

Merged
merged 19 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7146902
feat : added sql requests
h1ppox99 Jul 4, 2024
a120313
fix : fixed minor test issues
h1ppox99 Jul 4, 2024
7397e0d
fix : corrected sql requests when the filterfields contain keys with …
h1ppox99 Jul 5, 2024
2827702
feat : added getJoin request and more tests
h1ppox99 Jul 5, 2024
f86a7fe
fix : istanbul ignored updateKey.ts since not used for the moment
h1ppox99 Jul 5, 2024
b87e73f
fix : fixed wrong management of empty queries (NB: default req.query …
h1ppox99 Jul 5, 2024
795f82a
fix : changed the order of parameters for _get and _getMax methods fo…
h1ppox99 Jul 5, 2024
289654c
fix : fixed initialisation of token following changes to the req.quer…
h1ppox99 Jul 5, 2024
6ba4eba
feat: test files v1
Mathixx Jul 4, 2024
1eb2e30
fix: tests covering matrixDb
Mathixx Jul 4, 2024
0e5a16b
fix: no personal settings in gitignore + changed test anme
Mathixx Jul 4, 2024
f6b59cc
fix: test config in __testData__ folder
Mathixx Jul 4, 2024
61df3cc
feat : added /register endpoint to test User Interactive Authenticati…
BichraiX Jul 5, 2024
433f700
chore: workaround TS type because it's Friday. TODO exists, to be fix…
guimard Jul 5, 2024
98647bd
fix : cancel previous commit
h1ppox99 Jul 5, 2024
c4fbe2e
fix: added istanbul ignore to ensure good test coverage
Mathixx Jul 5, 2024
1e5caa4
feat : added sql request getWhereEqualAndHigher
h1ppox99 Jul 5, 2024
602361e
Merge branch 'full-id-service' into adding-sql-requests
h1ppox99 Jul 8, 2024
e7746cc
fix : corrected wrong syntax
h1ppox99 Jul 8, 2024
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
189 changes: 189 additions & 0 deletions packages/matrix-identity-server/src/db/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,195 @@ describe('Id Server DB', () => {
})
})

it('should create aliases if the fields contain periods', (done) => {
idDb = new IdDb(baseConf, logger)
idDb.ready
.then(() => {
idDb
.insert('accessTokens', { id: '1', data: '{}' })
.then(() => {
idDb
.get('accessTokens', ['accessTokens.id'], { id: '1' })
.then((rows) => {
expect(rows.length).toBe(1)
expect(rows[0].accessTokens_id).toEqual('1')
clearTimeout(idDb.cleanJob)
idDb.close()
done()
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})

it('should get entry with corresponding equal or different conditions', (done) => {
idDb = new IdDb(baseConf, logger)
idDb.ready
.then(() => {
const id = randomString(64)
idDb
.insert('accessTokens', { id, data: '{}' })
.then(() => {
idDb
.insert('accessTokens', {
id: 'wrong_id_1',
data: '{wrong_data}'
})
.then(() => {
idDb
.insert('accessTokens', {
id: 'wrong_id_2',
data: '{}'
})
.then(() => {
idDb
.getWhereEqualOrDifferent(
'accessTokens',
['id', 'data'],
{ id: id },
{ data: '{}' }
)
.then((rows) => {
expect(rows.length).toBe(2)
expect(rows[0].id).toEqual(id)
expect(rows[1].data).toEqual('{wrong_data}')
clearTimeout(idDb.cleanJob)
idDb.close()
done()
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})

it('should get max entry with corresponding equal condition', (done) => {
idDb = new IdDb(baseConf, logger)
idDb.ready
.then(() => {
idDb.insert('accessTokens', { id: '1', data: '{}' }).then(() => {
idDb
.insert('accessTokens', { id: '2', data: '{}' })
.then(() => {
idDb
.insert('accessTokens', { id: '3', data: '{wrong_data}' })
.then(() => {
idDb
.getMaxWhereEqual('accessTokens', 'id', ['id', 'data'], {
data: '{}'
})
.then((rows) => {
expect(rows.length).toBe(1)
expect(rows[0].id).toEqual('2')
clearTimeout(idDb.cleanJob)
idDb.close()
done()
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
})
.catch((e) => done(e))
})

it('should get max entry with corresponding equal and lower conditions on multiple joined tables', (done) => {
idDb = new IdDb(baseConf, logger)
idDb.ready
.then(() => {
idDb.insert('accessTokens', { id: '1', data: '{}' }).then(() => {
idDb
.insert('oneTimeTokens', { id: '1', expires: 999 })
.then(() => {
idDb
.insert('accessTokens', { id: '2', data: '{}' })
.then(() => {
idDb
.insert('oneTimeTokens', { id: '2', expires: 999 })
.then(() => {
idDb
.insert('accessTokens', {
id: '3',
data: '{wrong_data}'
})
.then(() => {
idDb
.insert('oneTimeTokens', { id: '3', expires: 999 })
.then(() => {
idDb
.insert('accessTokens', {
id: '4',
data: '{wrong_data}'
})
.then(() => {
idDb
.insert('oneTimeTokens', {
id: '4',
expires: 1001
})
.then(() => {
idDb
.getMaxWhereEqualAndLowerJoin(
['accessTokens', 'oneTimeTokens'],
'accessTokens.id',
[
'accessTokens.id',
'accessTokens.data',
'oneTimeTokens.expires'
],
{
'accessTokens.data': '{}'
},
{ 'oneTimeTokens.expires': 1000 },
{
'accessTokens.id':
'oneTimeTokens.id'
}
)
.then((rows) => {
expect(rows.length).toBe(1)
expect(
rows[0].accessTokens_id
).toEqual('2')
expect(
rows[0].accessTokens_data
).toEqual('{}')
expect(
rows[0].oneTimeTokens_expires
).toBeLessThan(1000)
clearTimeout(idDb.cleanJob)
idDb.close()
done()
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
.catch((e) => done(e))
})
})
.catch((e) => done(e))
})

it('should provide ephemeral Keypair', (done) => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
idDb = new IdDb(baseConf, logger)
Expand Down
86 changes: 84 additions & 2 deletions packages/matrix-identity-server/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ type Get<T> = (
filterFields: Record<string, string | number | Array<string | number>>,
order?: string
) => Promise<DbGetResult>
type Get2<T> = (
table: T,
fields: string[],
filterFields1: Record<string, string | number | Array<string | number>>,
filterFields2: Record<string, string | number | Array<string | number>>,
order?: string
) => Promise<DbGetResult>
type GetMax<T> = (
table: T,
targetField: string,
fields: string[],
filterFields: Record<string, string | number | Array<string | number>>,
order?: string
) => Promise<DbGetResult>
type GetMaxJoin2<T> = (
tables: Array<T>,
targetField: string,
fields: string[],
filterFields1: Record<string, string | number | Array<string | number>>,
filterFields2: Record<string, string | number | Array<string | number>>,
joinFields: Record<string, string>,
order?: string
) => Promise<DbGetResult>
type GetCount<T> = (
table: T,
field: string,
Expand Down Expand Up @@ -135,6 +158,9 @@ export interface IdDbBackend<T> {
createDatabases: (conf: Config, ...args: any) => Promise<void>
insert: Insert<T>
get: Get<T>
getWhereEqualOrDifferent: Get2<T>
getMaxWhereEqual: GetMax<T>
getMaxWhereEqualAndLowerJoin: GetMaxJoin2<T>
getCount: GetCount<T>
getAll: GetAll<T>
getHigherThan: Get<T>
Expand Down Expand Up @@ -275,9 +301,65 @@ class IdentityServerDb<T extends string = never>
get(
table: Collections | T,
fields: string[],
filterFields: Record<string, string | number | Array<string | number>>
filterFields: Record<string, string | number | Array<string | number>>,
order?: string
) {
return this.db.get(table, fields, filterFields)
return this.db.get(table, fields, filterFields, order)
}

//eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/promise-function-async
getWhereEqualOrDifferent(
table: Collections | T,
fields: string[],
filterFields1: Record<string, string | number | Array<string | number>>,
filterFields2: Record<string, string | number | Array<string | number>>,
order?: string
) {
return this.db.getWhereEqualOrDifferent(
table,
fields,
filterFields1,
filterFields2,
order
)
}

//eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/promise-function-async
getMaxWhereEqual(
table: Collections | T,
targetField: string,
fields: string[],
filterFields: Record<string, string | number | Array<string | number>>,
order?: string
) {
return this.db.getMaxWhereEqual(
table,
targetField,
fields,
filterFields,
order
)
}

//eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/promise-function-async
getMaxWhereEqualAndLowerJoin(
tables: Array<T | Collections>,
targetField: string,
fields: string[],
filterFields1: Record<string, string | number | Array<string | number>>,
filterFields2: Record<string, string | number | Array<string | number>>,
joinFields: Record<string, string>,
order?: string
) {
return this.db.getMaxWhereEqualAndLowerJoin(
tables,
targetField,
fields,
filterFields1,
filterFields2,
joinFields,
order
)
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/promise-function-async
Expand Down
Loading
Loading