mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
chore: rename all \w+DBEntry
as \w+Update
to eliminate understanding (#173)
This commit is contained in:
parent
3690265122
commit
6e9cabe50b
20 changed files with 56 additions and 56 deletions
|
@ -1,5 +1,5 @@
|
|||
/* eslint-disable sql/no-unsafe-query */
|
||||
import { UserDBEntry, Users } from '@logto/schemas';
|
||||
import { UserUpdate, Users } from '@logto/schemas';
|
||||
import decamelize from 'decamelize';
|
||||
|
||||
import RequestError from '@/errors/RequestError';
|
||||
|
@ -42,7 +42,7 @@ describe('buildInsertInto()', () => {
|
|||
});
|
||||
|
||||
it('resolves a promise with single entity when `returning` is true', async () => {
|
||||
const user: UserDBEntry = { id: 'foo', username: '123', primaryEmail: 'foo@bar.com' };
|
||||
const user: UserUpdate = { id: 'foo', username: '123', primaryEmail: 'foo@bar.com' };
|
||||
const pool = createTestPool(
|
||||
[...expectInsertIntoSql, 'returning *'].join('\n'),
|
||||
(_, [id, username, primaryEmail]) => ({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { UserDBEntry, Users } from '@logto/schemas';
|
||||
import { UserUpdate, Users } from '@logto/schemas';
|
||||
|
||||
import RequestError from '@/errors/RequestError';
|
||||
import { createTestPool } from '@/utils/test-utils';
|
||||
|
@ -20,7 +20,7 @@ describe('buildUpdateWhere()', () => {
|
|||
});
|
||||
|
||||
it('resolves a promise with single entity when `returning` is true', async () => {
|
||||
const user: UserDBEntry = { id: 'foo', username: '123', primaryEmail: 'foo@bar.com' };
|
||||
const user: UserUpdate = { id: 'foo', username: '123', primaryEmail: 'foo@bar.com' };
|
||||
const pool = createTestPool(
|
||||
'update "users"\nset "username"=$1, "primary_email"=$2\nwhere "id"=$3\nreturning *',
|
||||
(_, [username, primaryEmail, id]) => ({
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ApplicationDBEntry } from '@logto/schemas';
|
||||
import { ApplicationUpdate } from '@logto/schemas';
|
||||
import dayjs from 'dayjs';
|
||||
import { AdapterFactory, AllClientMetadata } from 'oidc-provider';
|
||||
import snakecaseKeys from 'snakecase-keys';
|
||||
|
@ -23,7 +23,7 @@ export default function postgresAdapter(modelName: string): ReturnType<AdapterFa
|
|||
name: client_name,
|
||||
type,
|
||||
oidcClientMetadata,
|
||||
}: ApplicationDBEntry): AllClientMetadata => ({
|
||||
}: ApplicationUpdate): AllClientMetadata => ({
|
||||
client_id,
|
||||
client_name,
|
||||
application_type: getApplicationTypeString(type),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Application, ApplicationDBEntry, Applications } from '@logto/schemas';
|
||||
import { Application, ApplicationUpdate, Applications } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildFindMany } from '@/database/find-many';
|
||||
|
@ -12,7 +12,7 @@ const { table, fields } = convertToIdentifiers(Applications);
|
|||
|
||||
export const findTotalNumberOfApplications = async () => getTotalRowCount(table);
|
||||
|
||||
const findApplicationMany = buildFindMany<ApplicationDBEntry, Application>(pool, Applications);
|
||||
const findApplicationMany = buildFindMany<ApplicationUpdate, Application>(pool, Applications);
|
||||
|
||||
export const findAllApplications = async (limit: number, offset: number) =>
|
||||
findApplicationMany({ limit, offset });
|
||||
|
@ -24,7 +24,7 @@ export const findApplicationById = async (id: string) =>
|
|||
where ${fields.id}=${id}
|
||||
`);
|
||||
|
||||
export const insertApplication = buildInsertInto<ApplicationDBEntry, Application>(
|
||||
export const insertApplication = buildInsertInto<ApplicationUpdate, Application>(
|
||||
pool,
|
||||
Applications,
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ export const insertApplication = buildInsertInto<ApplicationDBEntry, Application
|
|||
}
|
||||
);
|
||||
|
||||
const updateApplication = buildUpdateWhere<ApplicationDBEntry, Application>(
|
||||
const updateApplication = buildUpdateWhere<ApplicationUpdate, Application>(
|
||||
pool,
|
||||
Applications,
|
||||
true
|
||||
|
@ -40,7 +40,7 @@ const updateApplication = buildUpdateWhere<ApplicationDBEntry, Application>(
|
|||
|
||||
export const updateApplicationById = async (
|
||||
id: string,
|
||||
set: Partial<OmitAutoSetFields<ApplicationDBEntry>>
|
||||
set: Partial<OmitAutoSetFields<ApplicationUpdate>>
|
||||
) => updateApplication({ set, where: { id } });
|
||||
|
||||
export const deleteApplicationById = async (id: string) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Connector, ConnectorDBEntry, Connectors, ConnectorType } from '@logto/schemas';
|
||||
import { Connector, ConnectorUpdate, Connectors, ConnectorType } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
|
@ -14,6 +14,6 @@ export const findConnectorByIdAndType = async (id: string, type: ConnectorType)
|
|||
where ${fields.id}=${id} and ${fields.type}=${type}
|
||||
`);
|
||||
|
||||
export const insertConnector = buildInsertInto<ConnectorDBEntry, Connector>(pool, Connectors, {
|
||||
export const insertConnector = buildInsertInto<ConnectorUpdate, Connector>(pool, Connectors, {
|
||||
returning: true,
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OidcModelInstance,
|
||||
OidcModelInstanceDBEntry,
|
||||
OidcModelInstanceUpdate,
|
||||
OidcModelInstancePayload,
|
||||
OidcModelInstances,
|
||||
} from '@logto/schemas';
|
||||
|
@ -24,7 +24,7 @@ const withConsumed = <T>(data: T, consumedAt?: number | null): WithConsumed<T> =
|
|||
const convertResult = (result: QueryResult | null) =>
|
||||
conditional(result && withConsumed(result.payload, result.consumedAt));
|
||||
|
||||
export const upsertInstance = buildInsertInto<OidcModelInstanceDBEntry>(pool, OidcModelInstances, {
|
||||
export const upsertInstance = buildInsertInto<OidcModelInstanceUpdate>(pool, OidcModelInstances, {
|
||||
onConflict: {
|
||||
fields: [fields.modelName, fields.id],
|
||||
setExcludedFields: [fields.payload, fields.expiresAt],
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Resource, ResourceDBEntry, Resources } from '@logto/schemas';
|
||||
import { Resource, ResourceUpdate, Resources } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
|
@ -43,15 +43,15 @@ export const findResourceById = async (id: string) =>
|
|||
where ${fields.id}=${id}
|
||||
`);
|
||||
|
||||
export const insertResource = buildInsertInto<ResourceDBEntry, Resource>(pool, Resources, {
|
||||
export const insertResource = buildInsertInto<ResourceUpdate, Resource>(pool, Resources, {
|
||||
returning: true,
|
||||
});
|
||||
|
||||
const updateResource = buildUpdateWhere<ResourceDBEntry, Resource>(pool, Resources, true);
|
||||
const updateResource = buildUpdateWhere<ResourceUpdate, Resource>(pool, Resources, true);
|
||||
|
||||
export const updateResourceById = async (
|
||||
id: string,
|
||||
set: Partial<OmitAutoSetFields<ResourceDBEntry>>
|
||||
set: Partial<OmitAutoSetFields<ResourceUpdate>>
|
||||
) => updateResource({ set, where: { id } });
|
||||
|
||||
export const deleteResourceById = async (id: string) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { ResourceScope, ResourceScopeDBEntry, ResourceScopes } from '@logto/schemas';
|
||||
import { ResourceScope, ResourceScopeUpdate, ResourceScopes } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
|
@ -15,7 +15,7 @@ export const findAllScopesWithResourceId = async (resourceId: string) =>
|
|||
where ${fields.resourceId}=${resourceId}
|
||||
`);
|
||||
|
||||
export const insertScope = buildInsertInto<ResourceScopeDBEntry, ResourceScope>(
|
||||
export const insertScope = buildInsertInto<ResourceScopeUpdate, ResourceScope>(
|
||||
pool,
|
||||
ResourceScopes,
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { UserLogDBEntry, UserLogs } from '@logto/schemas';
|
||||
import { UserLogUpdate, UserLogs } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
|
@ -7,10 +7,10 @@ import { convertToIdentifiers } from '@/database/utils';
|
|||
|
||||
const { table, fields } = convertToIdentifiers(UserLogs);
|
||||
|
||||
export const insertUserLog = buildInsertInto<UserLogDBEntry>(pool, UserLogs);
|
||||
export const insertUserLog = buildInsertInto<UserLogUpdate>(pool, UserLogs);
|
||||
|
||||
export const findLogsByUserId = async (userId: string) =>
|
||||
pool.many<UserLogDBEntry>(sql`
|
||||
pool.many<UserLogUpdate>(sql`
|
||||
select ${sql.join(Object.values(fields), sql`,`)}
|
||||
from ${table}
|
||||
where ${fields.userId}=${userId}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { User, UserDBEntry, Users } from '@logto/schemas';
|
||||
import { User, UserUpdate, Users } from '@logto/schemas';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
import { buildInsertInto } from '@/database/insert-into';
|
||||
|
@ -37,7 +37,7 @@ export const hasUserWithId = async (id: string) =>
|
|||
where ${fields.id}=${id}
|
||||
`);
|
||||
|
||||
export const insertUser = buildInsertInto<UserDBEntry, User>(pool, Users, { returning: true });
|
||||
export const insertUser = buildInsertInto<UserUpdate, User>(pool, Users, { returning: true });
|
||||
|
||||
export const findAllUsers = async () =>
|
||||
pool.many<User>(sql`
|
||||
|
@ -45,9 +45,9 @@ export const findAllUsers = async () =>
|
|||
from ${table}
|
||||
`);
|
||||
|
||||
const updateUser = buildUpdateWhere<UserDBEntry, User>(pool, Users, true);
|
||||
const updateUser = buildUpdateWhere<UserUpdate, User>(pool, Users, true);
|
||||
|
||||
export const updateUserById = async (id: string, set: Partial<OmitAutoSetFields<UserDBEntry>>) =>
|
||||
export const updateUserById = async (id: string, set: Partial<OmitAutoSetFields<UserUpdate>>) =>
|
||||
updateUser({ set, where: { id } });
|
||||
|
||||
export const deleteUserById = async (id: string) => {
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from '../foundations';
|
||||
import { ApplicationType } from './custom-types';
|
||||
|
||||
export type ApplicationDBEntry = {
|
||||
export type ApplicationUpdate = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
|
@ -32,7 +32,7 @@ export type Application = {
|
|||
createdAt: number;
|
||||
};
|
||||
|
||||
const guard: Guard<ApplicationDBEntry> = z.object({
|
||||
const guard: Guard<ApplicationUpdate> = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
description: z.string().optional(),
|
||||
|
@ -43,7 +43,7 @@ const guard: Guard<ApplicationDBEntry> = z.object({
|
|||
createdAt: z.number().optional(),
|
||||
});
|
||||
|
||||
export const Applications: GeneratedSchema<ApplicationDBEntry> = Object.freeze({
|
||||
export const Applications: GeneratedSchema<ApplicationUpdate> = Object.freeze({
|
||||
table: 'applications',
|
||||
tableSingular: 'application',
|
||||
fields: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { z } from 'zod';
|
|||
import { ConnectorConfig, connectorConfigGuard, GeneratedSchema, Guard } from '../foundations';
|
||||
import { ConnectorType } from './custom-types';
|
||||
|
||||
export type ConnectorDBEntry = {
|
||||
export type ConnectorUpdate = {
|
||||
id: string;
|
||||
enabled?: boolean;
|
||||
type: ConnectorType;
|
||||
|
@ -21,7 +21,7 @@ export type Connector = {
|
|||
createdAt: number;
|
||||
};
|
||||
|
||||
const guard: Guard<ConnectorDBEntry> = z.object({
|
||||
const guard: Guard<ConnectorUpdate> = z.object({
|
||||
id: z.string(),
|
||||
enabled: z.boolean().optional(),
|
||||
type: z.nativeEnum(ConnectorType),
|
||||
|
@ -29,7 +29,7 @@ const guard: Guard<ConnectorDBEntry> = z.object({
|
|||
createdAt: z.number().optional(),
|
||||
});
|
||||
|
||||
export const Connectors: GeneratedSchema<ConnectorDBEntry> = Object.freeze({
|
||||
export const Connectors: GeneratedSchema<ConnectorUpdate> = Object.freeze({
|
||||
table: 'connectors',
|
||||
tableSingular: 'connector',
|
||||
fields: {
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
Guard,
|
||||
} from '../foundations';
|
||||
|
||||
export type OidcModelInstanceDBEntry = {
|
||||
export type OidcModelInstanceUpdate = {
|
||||
modelName: string;
|
||||
id: string;
|
||||
payload: OidcModelInstancePayload;
|
||||
|
@ -25,7 +25,7 @@ export type OidcModelInstance = {
|
|||
consumedAt: number | null;
|
||||
};
|
||||
|
||||
const guard: Guard<OidcModelInstanceDBEntry> = z.object({
|
||||
const guard: Guard<OidcModelInstanceUpdate> = z.object({
|
||||
modelName: z.string(),
|
||||
id: z.string(),
|
||||
payload: oidcModelInstancePayloadGuard,
|
||||
|
@ -33,7 +33,7 @@ const guard: Guard<OidcModelInstanceDBEntry> = z.object({
|
|||
consumedAt: z.number().optional(),
|
||||
});
|
||||
|
||||
export const OidcModelInstances: GeneratedSchema<OidcModelInstanceDBEntry> = Object.freeze({
|
||||
export const OidcModelInstances: GeneratedSchema<OidcModelInstanceUpdate> = Object.freeze({
|
||||
table: 'oidc_model_instances',
|
||||
tableSingular: 'oidc_model_instance',
|
||||
fields: {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { z } from 'zod';
|
|||
|
||||
import { GeneratedSchema, Guard } from '../foundations';
|
||||
|
||||
export type ResourceScopeDBEntry = {
|
||||
export type ResourceScopeUpdate = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
|
@ -18,14 +18,14 @@ export type ResourceScope = {
|
|||
resourceId: string;
|
||||
};
|
||||
|
||||
const guard: Guard<ResourceScopeDBEntry> = z.object({
|
||||
const guard: Guard<ResourceScopeUpdate> = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
description: z.string(),
|
||||
resourceId: z.string(),
|
||||
});
|
||||
|
||||
export const ResourceScopes: GeneratedSchema<ResourceScopeDBEntry> = Object.freeze({
|
||||
export const ResourceScopes: GeneratedSchema<ResourceScopeUpdate> = Object.freeze({
|
||||
table: 'resource_scopes',
|
||||
tableSingular: 'resource_scope',
|
||||
fields: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { z } from 'zod';
|
|||
import { GeneratedSchema, Guard } from '../foundations';
|
||||
import { AccessTokenFormatType, SignAlgorithmType } from './custom-types';
|
||||
|
||||
export type ResourceDBEntry = {
|
||||
export type ResourceUpdate = {
|
||||
id: string;
|
||||
name: string;
|
||||
identifier: string;
|
||||
|
@ -23,7 +23,7 @@ export type Resource = {
|
|||
signAlgorithm: SignAlgorithmType;
|
||||
};
|
||||
|
||||
const guard: Guard<ResourceDBEntry> = z.object({
|
||||
const guard: Guard<ResourceUpdate> = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
identifier: z.string(),
|
||||
|
@ -32,7 +32,7 @@ const guard: Guard<ResourceDBEntry> = z.object({
|
|||
signAlgorithm: z.nativeEnum(SignAlgorithmType).optional(),
|
||||
});
|
||||
|
||||
export const Resources: GeneratedSchema<ResourceDBEntry> = Object.freeze({
|
||||
export const Resources: GeneratedSchema<ResourceUpdate> = Object.freeze({
|
||||
table: 'resources',
|
||||
tableSingular: 'resource',
|
||||
fields: {
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
Guard,
|
||||
} from '../foundations';
|
||||
|
||||
export type SettingDBEntry = {
|
||||
export type SettingUpdate = {
|
||||
id: string;
|
||||
customDomain?: string | null;
|
||||
adminConsole: AdminConsoleConfig;
|
||||
|
@ -21,13 +21,13 @@ export type Setting = {
|
|||
adminConsole: AdminConsoleConfig;
|
||||
};
|
||||
|
||||
const guard: Guard<SettingDBEntry> = z.object({
|
||||
const guard: Guard<SettingUpdate> = z.object({
|
||||
id: z.string(),
|
||||
customDomain: z.string().optional(),
|
||||
adminConsole: adminConsoleConfigGuard,
|
||||
});
|
||||
|
||||
export const Settings: GeneratedSchema<SettingDBEntry> = Object.freeze({
|
||||
export const Settings: GeneratedSchema<SettingUpdate> = Object.freeze({
|
||||
table: 'settings',
|
||||
tableSingular: 'setting',
|
||||
fields: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { z } from 'zod';
|
|||
import { UserLogPayload, userLogPayloadGuard, GeneratedSchema, Guard } from '../foundations';
|
||||
import { UserLogType, UserLogResult } from './custom-types';
|
||||
|
||||
export type UserLogDBEntry = {
|
||||
export type UserLogUpdate = {
|
||||
id: string;
|
||||
userId: string;
|
||||
type: UserLogType;
|
||||
|
@ -23,7 +23,7 @@ export type UserLog = {
|
|||
createdAt: number;
|
||||
};
|
||||
|
||||
const guard: Guard<UserLogDBEntry> = z.object({
|
||||
const guard: Guard<UserLogUpdate> = z.object({
|
||||
id: z.string(),
|
||||
userId: z.string(),
|
||||
type: z.nativeEnum(UserLogType),
|
||||
|
@ -32,7 +32,7 @@ const guard: Guard<UserLogDBEntry> = z.object({
|
|||
createdAt: z.number().optional(),
|
||||
});
|
||||
|
||||
export const UserLogs: GeneratedSchema<UserLogDBEntry> = Object.freeze({
|
||||
export const UserLogs: GeneratedSchema<UserLogUpdate> = Object.freeze({
|
||||
table: 'user_logs',
|
||||
tableSingular: 'user_log',
|
||||
fields: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { z } from 'zod';
|
|||
import { GeneratedSchema, Guard } from '../foundations';
|
||||
import { PasswordEncryptionMethod } from './custom-types';
|
||||
|
||||
export type UserDBEntry = {
|
||||
export type UserUpdate = {
|
||||
id: string;
|
||||
username?: string | null;
|
||||
primaryEmail?: string | null;
|
||||
|
@ -25,7 +25,7 @@ export type User = {
|
|||
passwordEncryptionSalt: string | null;
|
||||
};
|
||||
|
||||
const guard: Guard<UserDBEntry> = z.object({
|
||||
const guard: Guard<UserUpdate> = z.object({
|
||||
id: z.string(),
|
||||
username: z.string().optional(),
|
||||
primaryEmail: z.string().optional(),
|
||||
|
@ -35,7 +35,7 @@ const guard: Guard<UserDBEntry> = z.object({
|
|||
passwordEncryptionSalt: z.string().optional(),
|
||||
});
|
||||
|
||||
export const Users: GeneratedSchema<UserDBEntry> = Object.freeze({
|
||||
export const Users: GeneratedSchema<UserUpdate> = Object.freeze({
|
||||
table: 'users',
|
||||
tableSingular: 'user',
|
||||
fields: {
|
||||
|
|
|
@ -6,7 +6,7 @@ import { TableWithType } from './types';
|
|||
|
||||
export const generateSchema = ({ name, fields }: TableWithType) => {
|
||||
const modelName = pluralize(camelcase(name, { pascalCase: true }), 1);
|
||||
const databaseEntryType = `${modelName}DBEntry`;
|
||||
const databaseEntryType = `${modelName}Update`;
|
||||
return [
|
||||
`export type ${databaseEntryType} = {`,
|
||||
...fields.map(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { UserDBEntry } from '../db-entries';
|
||||
import { UserUpdate } from '../db-entries';
|
||||
|
||||
export const userInfoSelectFields = Object.freeze([
|
||||
'id',
|
||||
|
@ -7,7 +7,7 @@ export const userInfoSelectFields = Object.freeze([
|
|||
'primaryPhone',
|
||||
] as const);
|
||||
|
||||
export type UserInfo<Keys extends keyof UserDBEntry = typeof userInfoSelectFields[number]> = Pick<
|
||||
UserDBEntry,
|
||||
export type UserInfo<Keys extends keyof UserUpdate = typeof userInfoSelectFields[number]> = Pick<
|
||||
UserUpdate,
|
||||
Keys
|
||||
>;
|
||||
|
|
Loading…
Reference in a new issue