mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
refactor(core): adopt new schemas
This commit is contained in:
parent
1b6a755376
commit
89cf297eff
3 changed files with 22 additions and 19 deletions
|
@ -7,22 +7,25 @@ import {
|
|||
revokeInstanceByGrantId,
|
||||
upsertInstance,
|
||||
} from '@/queries/oidc-model-instance';
|
||||
import { findClientById } from '@/queries/oidc-client';
|
||||
import { OidcClientDBEntry } from '@logto/schemas';
|
||||
import { findApplicationByClientId } from '@/queries/application';
|
||||
import { ApplicationDBEntry } from '@logto/schemas';
|
||||
|
||||
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
||||
if (modelName === 'Client') {
|
||||
const reject = async () => Promise.reject(new Error('Not implemented'));
|
||||
const tranpileClient = ({ clientId, metadata }: OidcClientDBEntry): AllClientMetadata => ({
|
||||
client_id: clientId,
|
||||
const tranpileClient = ({
|
||||
oidcClientId,
|
||||
oidcClientMetadata,
|
||||
}: ApplicationDBEntry): AllClientMetadata => ({
|
||||
client_id: oidcClientId,
|
||||
grant_types: ['authorization_code', 'refresh_token'],
|
||||
token_endpoint_auth_method: 'none',
|
||||
...metadata,
|
||||
...oidcClientMetadata,
|
||||
});
|
||||
|
||||
return {
|
||||
upsert: reject,
|
||||
find: async (id) => tranpileClient(await findClientById(id)),
|
||||
find: async (id) => tranpileClient(await findApplicationByClientId(id)),
|
||||
findByUserCode: reject,
|
||||
findByUid: reject,
|
||||
consume: reject,
|
||||
|
|
13
packages/core/src/queries/application.ts
Normal file
13
packages/core/src/queries/application.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import pool from '@/database/pool';
|
||||
import { convertToIdentifiers } from '@/database/utils';
|
||||
import { ApplicationDBEntry, Applications } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
const { table, fields } = convertToIdentifiers(Applications);
|
||||
|
||||
export const findApplicationByClientId = async (clientId: string) =>
|
||||
pool.one<ApplicationDBEntry>(sql`
|
||||
select ${sql.join(Object.values(fields), sql`, `)}
|
||||
from ${table}
|
||||
where ${fields.oidcClientId}=${clientId}
|
||||
`);
|
|
@ -1,13 +0,0 @@
|
|||
import pool from '@/database/pool';
|
||||
import { convertToIdentifiers } from '@/database/utils';
|
||||
import { OidcClientDBEntry, OidcClients } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
const { table, fields } = convertToIdentifiers(OidcClients);
|
||||
|
||||
export const findClientById = async (clientId: string) =>
|
||||
pool.one<OidcClientDBEntry>(sql`
|
||||
select ${sql.join(Object.values(fields), sql`, `)}
|
||||
from ${table}
|
||||
where ${fields.clientId}=${clientId}
|
||||
`);
|
Loading…
Reference in a new issue