diff --git a/packages/cli/src/queries/system.ts b/packages/cli/src/queries/system.ts index f4b2716ec..546050bb9 100644 --- a/packages/cli/src/queries/system.ts +++ b/packages/cli/src/queries/system.ts @@ -1,5 +1,5 @@ import type { AlterationState, System } from '@logto/schemas'; -import { Systems, logtoConfigGuards, AlterationStateKey } from '@logto/schemas'; +import { systemGuards, Systems, AlterationStateKey } from '@logto/schemas'; import { convertToIdentifiers } from '@logto/shared'; import type { Nullable } from '@silverhand/essentials'; import type { CommonQueryMethods, DatabaseTransactionConnection } from 'slonik'; @@ -31,7 +31,7 @@ export const getCurrentDatabaseAlterationTimestamp = async (pool: CommonQueryMet const result = await pool.maybeOne( sql`select * from ${table} where ${fields.key}=${AlterationStateKey.AlterationState}` ); - const parsed = logtoConfigGuards[AlterationStateKey.AlterationState].safeParse(result?.value); + const parsed = systemGuards[AlterationStateKey.AlterationState].safeParse(result?.value); return (parsed.success && parsed.data.timestamp) || 0; } catch (error: unknown) { diff --git a/packages/schemas/src/types/index.ts b/packages/schemas/src/types/index.ts index 6faa0a306..116bb8654 100644 --- a/packages/schemas/src/types/index.ts +++ b/packages/schemas/src/types/index.ts @@ -10,3 +10,4 @@ export * from './scope.js'; export * from './role.js'; export * from './verification-code.js'; export * from './application.js'; +export * from './system.js'; diff --git a/packages/schemas/src/types/logto-config.ts b/packages/schemas/src/types/logto-config.ts index ff7d46d87..fc6abd025 100644 --- a/packages/schemas/src/types/logto-config.ts +++ b/packages/schemas/src/types/logto-config.ts @@ -1,26 +1,6 @@ import type { ZodType } from 'zod'; import { z } from 'zod'; -// Alteration state -export enum AlterationStateKey { - AlterationState = 'alterationState', -} - -export type AlterationState = { timestamp: number; updatedAt?: string }; - -export type AlterationStateType = { - [AlterationStateKey.AlterationState]: AlterationState; -}; - -export const alterationStateGuard: Readonly<{ - [key in AlterationStateKey]: ZodType; -}> = Object.freeze({ - [AlterationStateKey.AlterationState]: z.object({ - timestamp: z.number(), - updatedAt: z.string().optional(), - }), -}); - // Logto OIDC config export enum LogtoOidcConfigKey { PrivateKeys = 'oidc.privateKeys', @@ -67,20 +47,16 @@ export const adminConsoleConfigGuard: Readonly<{ }); // Summary -export type LogtoConfigKey = AlterationStateKey | LogtoOidcConfigKey | AdminConsoleConfigKey; -export type LogtoConfigType = AlterationStateType | LogtoOidcConfigType | AdminConsoleConfigType; -export type LogtoConfigGuard = typeof alterationStateGuard & - typeof logtoOidcConfigGuard & - typeof adminConsoleConfigGuard; +export type LogtoConfigKey = LogtoOidcConfigKey | AdminConsoleConfigKey; +export type LogtoConfigType = LogtoOidcConfigType | AdminConsoleConfigType; +export type LogtoConfigGuard = typeof logtoOidcConfigGuard & typeof adminConsoleConfigGuard; export const logtoConfigKeys: readonly LogtoConfigKey[] = Object.freeze([ - ...Object.values(AlterationStateKey), ...Object.values(LogtoOidcConfigKey), ...Object.values(AdminConsoleConfigKey), ]); export const logtoConfigGuards: LogtoConfigGuard = Object.freeze({ - ...alterationStateGuard, ...logtoOidcConfigGuard, ...adminConsoleConfigGuard, }); diff --git a/packages/schemas/src/types/system.ts b/packages/schemas/src/types/system.ts new file mode 100644 index 000000000..4ff99a298 --- /dev/null +++ b/packages/schemas/src/types/system.ts @@ -0,0 +1,35 @@ +import type { ZodType } from 'zod'; +import { z } from 'zod'; + +// Alteration state +export enum AlterationStateKey { + AlterationState = 'alterationState', +} + +export type AlterationState = { timestamp: number; updatedAt?: string }; + +export type AlterationStateType = { + [AlterationStateKey.AlterationState]: AlterationState; +}; + +export const alterationStateGuard: Readonly<{ + [key in AlterationStateKey]: ZodType; +}> = Object.freeze({ + [AlterationStateKey.AlterationState]: z.object({ + timestamp: z.number(), + updatedAt: z.string().optional(), + }), +}); + +// Summary +export type SystemKey = AlterationStateKey; +export type SystemType = AlterationStateType; +export type SystemGuard = typeof alterationStateGuard; + +export const systemKeys: readonly SystemKey[] = Object.freeze([ + ...Object.values(AlterationStateKey), +]); + +export const systemGuards: SystemGuard = Object.freeze({ + ...alterationStateGuard, +});