mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -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,
|
revokeInstanceByGrantId,
|
||||||
upsertInstance,
|
upsertInstance,
|
||||||
} from '@/queries/oidc-model-instance';
|
} from '@/queries/oidc-model-instance';
|
||||||
import { findClientById } from '@/queries/oidc-client';
|
import { findApplicationByClientId } from '@/queries/application';
|
||||||
import { OidcClientDBEntry } from '@logto/schemas';
|
import { ApplicationDBEntry } from '@logto/schemas';
|
||||||
|
|
||||||
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
export default function postgresAdapter(modelName: string): ReturnType<AdapterFactory> {
|
||||||
if (modelName === 'Client') {
|
if (modelName === 'Client') {
|
||||||
const reject = async () => Promise.reject(new Error('Not implemented'));
|
const reject = async () => Promise.reject(new Error('Not implemented'));
|
||||||
const tranpileClient = ({ clientId, metadata }: OidcClientDBEntry): AllClientMetadata => ({
|
const tranpileClient = ({
|
||||||
client_id: clientId,
|
oidcClientId,
|
||||||
|
oidcClientMetadata,
|
||||||
|
}: ApplicationDBEntry): AllClientMetadata => ({
|
||||||
|
client_id: oidcClientId,
|
||||||
grant_types: ['authorization_code', 'refresh_token'],
|
grant_types: ['authorization_code', 'refresh_token'],
|
||||||
token_endpoint_auth_method: 'none',
|
token_endpoint_auth_method: 'none',
|
||||||
...metadata,
|
...oidcClientMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
upsert: reject,
|
upsert: reject,
|
||||||
find: async (id) => tranpileClient(await findClientById(id)),
|
find: async (id) => tranpileClient(await findApplicationByClientId(id)),
|
||||||
findByUserCode: reject,
|
findByUserCode: reject,
|
||||||
findByUid: reject,
|
findByUid: reject,
|
||||||
consume: 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…
Add table
Reference in a new issue