0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(schemas): logs schema and log payload type (#561)

This commit is contained in:
IceHe.xyz 2022-04-18 15:44:36 +08:00 committed by GitHub
parent 3a5854f566
commit 5386bcee23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 8 deletions

View file

@ -3,6 +3,7 @@
export * from './custom-types';
export * from './application';
export * from './connector';
export * from './log';
export * from './oidc-model-instance';
export * from './passcode';
export * from './resource';

View file

@ -0,0 +1,39 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import { z } from 'zod';
import { ArbitraryObject, arbitraryObjectGuard, GeneratedSchema, Guard } from '../foundations';
export type CreateLog = {
id: string;
type: string;
payload?: ArbitraryObject;
createdAt?: number;
};
export type Log = {
id: string;
type: string;
payload: ArbitraryObject;
createdAt: number;
};
const createGuard: Guard<CreateLog> = z.object({
id: z.string(),
type: z.string(),
payload: arbitraryObjectGuard.optional(),
createdAt: z.number().optional(),
});
export const Logs: GeneratedSchema<CreateLog> = Object.freeze({
table: 'logs',
tableSingular: 'log',
fields: {
id: 'id',
type: 'type',
payload: 'payload',
createdAt: 'created_at',
},
fieldKeys: ['id', 'type', 'payload', 'createdAt'],
createGuard,
});

View file

@ -1,5 +1,13 @@
import { z } from 'zod';
/**
* Commonly Used
*/
export const arbitraryObjectGuard = z.object({}).catchall(z.unknown());
export type ArbitraryObject = z.infer<typeof arbitraryObjectGuard>;
/**
* OIDC Model Instances
*/
@ -62,6 +70,7 @@ export type Identities = z.infer<typeof identitiesGuard>;
* User Logs
*/
/** @deprecated */
export const userLogPayloadGuard = z.object({
ip: z.string().optional(),
userAgent: z.string().optional(),
@ -70,6 +79,7 @@ export const userLogPayloadGuard = z.object({
details: z.object({}).optional(), // NOT intend to be parsed
});
/** @deprecated */
export type UserLogPayload = z.infer<typeof userLogPayloadGuard>;
/**
@ -147,11 +157,3 @@ export type SignInMethods = z.infer<typeof signInMethodsGuard>;
export const connectorIdsGuard = z.string().array();
export type ConnectorIds = z.infer<typeof connectorIdsGuard>;
/**
* Commonly Used
*/
export const arbitraryObjectGuard = z.object({}).catchall(z.unknown());
export type ArbitraryObject = z.infer<typeof arbitraryObjectGuard>;

View file

@ -0,0 +1,11 @@
create table logs
(
id varchar(21) not null,
type varchar(64) not null,
payload jsonb /* @use ArbitraryObject */ not null default '{}'::jsonb,
created_at timestamptz not null default (now()),
primary key (id)
);
create index logs__type on logs (type);
create index logs__created_at on logs (created_at);