mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
feat(core): add custom_data
to the user schema (#230)
This commit is contained in:
parent
86ce5a9640
commit
e8cbe00d3a
4 changed files with 19 additions and 6 deletions
|
@ -7,7 +7,7 @@ import { buildFindMany } from './find-many';
|
||||||
describe('buildFindMany()', () => {
|
describe('buildFindMany()', () => {
|
||||||
it('matches expected sql', async () => {
|
it('matches expected sql', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany();
|
await findMany();
|
||||||
|
@ -15,7 +15,7 @@ describe('buildFindMany()', () => {
|
||||||
|
|
||||||
it('matches expected sql with where conditions', async () => {
|
it('matches expected sql with where conditions', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nwhere "id"=$1'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"\nwhere "id"=$1'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany({ where: { id: '123' } });
|
await findMany({ where: { id: '123' } });
|
||||||
|
@ -23,7 +23,7 @@ describe('buildFindMany()', () => {
|
||||||
|
|
||||||
it('matches expected sql with limit', async () => {
|
it('matches expected sql with limit', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nlimit $1'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"\nlimit $1'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany({ limit: 10 });
|
await findMany({ limit: 10 });
|
||||||
|
@ -31,7 +31,7 @@ describe('buildFindMany()', () => {
|
||||||
|
|
||||||
it('matches expected sql with offset', async () => {
|
it('matches expected sql with offset', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\noffset $1'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"\noffset $1'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany({ offset: 10 });
|
await findMany({ offset: 10 });
|
||||||
|
@ -39,7 +39,7 @@ describe('buildFindMany()', () => {
|
||||||
|
|
||||||
it('matches expected sql with offset 0', async () => {
|
it('matches expected sql with offset 0', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany({ offset: 0 });
|
await findMany({ offset: 0 });
|
||||||
|
@ -47,7 +47,7 @@ describe('buildFindMany()', () => {
|
||||||
|
|
||||||
it('matches expected sql with where conditions, limit and offset', async () => {
|
it('matches expected sql with where conditions, limit and offset', async () => {
|
||||||
const pool = createTestPool(
|
const pool = createTestPool(
|
||||||
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities"\nfrom "users"\nwhere "id"=$1\nlimit $2\noffset $3'
|
'select "id", "username", "primary_email", "primary_phone", "password_encrypted", "password_encryption_method", "password_encryption_salt", "name", "avatar", "role_names", "identities", "custom_data"\nfrom "users"\nwhere "id"=$1\nlimit $2\noffset $3'
|
||||||
);
|
);
|
||||||
const findMany = buildFindMany(pool, Users);
|
const findMany = buildFindMany(pool, Users);
|
||||||
await findMany({ where: { id: '123' }, limit: 20, offset: 20 });
|
await findMany({ where: { id: '123' }, limit: 20, offset: 20 });
|
||||||
|
|
|
@ -7,6 +7,8 @@ import {
|
||||||
roleNamesGuard,
|
roleNamesGuard,
|
||||||
Identities,
|
Identities,
|
||||||
identitiesGuard,
|
identitiesGuard,
|
||||||
|
CustomData,
|
||||||
|
customDataGuard,
|
||||||
GeneratedSchema,
|
GeneratedSchema,
|
||||||
Guard,
|
Guard,
|
||||||
} from '../foundations';
|
} from '../foundations';
|
||||||
|
@ -24,6 +26,7 @@ export type CreateUser = {
|
||||||
avatar?: string | null;
|
avatar?: string | null;
|
||||||
roleNames?: RoleNames;
|
roleNames?: RoleNames;
|
||||||
identities?: Identities;
|
identities?: Identities;
|
||||||
|
customData?: CustomData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
|
@ -38,6 +41,7 @@ export type User = {
|
||||||
avatar: string | null;
|
avatar: string | null;
|
||||||
roleNames: RoleNames;
|
roleNames: RoleNames;
|
||||||
identities: Identities;
|
identities: Identities;
|
||||||
|
customData: CustomData;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createGuard: Guard<CreateUser> = z.object({
|
const createGuard: Guard<CreateUser> = z.object({
|
||||||
|
@ -52,6 +56,7 @@ const createGuard: Guard<CreateUser> = z.object({
|
||||||
avatar: z.string().nullable().optional(),
|
avatar: z.string().nullable().optional(),
|
||||||
roleNames: roleNamesGuard.optional(),
|
roleNames: roleNamesGuard.optional(),
|
||||||
identities: identitiesGuard.optional(),
|
identities: identitiesGuard.optional(),
|
||||||
|
customData: customDataGuard.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Users: GeneratedSchema<CreateUser> = Object.freeze({
|
export const Users: GeneratedSchema<CreateUser> = Object.freeze({
|
||||||
|
@ -69,6 +74,7 @@ export const Users: GeneratedSchema<CreateUser> = Object.freeze({
|
||||||
avatar: 'avatar',
|
avatar: 'avatar',
|
||||||
roleNames: 'role_names',
|
roleNames: 'role_names',
|
||||||
identities: 'identities',
|
identities: 'identities',
|
||||||
|
customData: 'custom_data',
|
||||||
},
|
},
|
||||||
fieldKeys: [
|
fieldKeys: [
|
||||||
'id',
|
'id',
|
||||||
|
@ -82,6 +88,7 @@ export const Users: GeneratedSchema<CreateUser> = Object.freeze({
|
||||||
'avatar',
|
'avatar',
|
||||||
'roleNames',
|
'roleNames',
|
||||||
'identities',
|
'identities',
|
||||||
|
'customData',
|
||||||
],
|
],
|
||||||
createGuard,
|
createGuard,
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,6 +54,11 @@ export const identitiesGuard = z.record(identityGuard);
|
||||||
export type Identity = z.infer<typeof identityGuard>;
|
export type Identity = z.infer<typeof identityGuard>;
|
||||||
export type Identities = z.infer<typeof identitiesGuard>;
|
export type Identities = z.infer<typeof identitiesGuard>;
|
||||||
|
|
||||||
|
// TODO: LOG-1553 support empty shape of object
|
||||||
|
export const customDataGuard = z.object({}).catchall(z.unknown());
|
||||||
|
|
||||||
|
export type CustomData = z.infer<typeof customDataGuard>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User Logs
|
* User Logs
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,5 +12,6 @@ create table users (
|
||||||
avatar varchar(256),
|
avatar varchar(256),
|
||||||
role_names jsonb /* @use RoleNames */ not null default '[]'::jsonb,
|
role_names jsonb /* @use RoleNames */ not null default '[]'::jsonb,
|
||||||
identities jsonb /* @use Identities */ not null default '{}'::jsonb,
|
identities jsonb /* @use Identities */ not null default '{}'::jsonb,
|
||||||
|
custom_data jsonb /* @use CustomData */ not null default '{}'::jsonb,
|
||||||
primary key (id)
|
primary key (id)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue