pl-api: replace lodash omit/pick with our own util

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-24 13:31:24 +01:00
parent d91cbcfd3f
commit b50a4e7224
11 changed files with 34 additions and 63 deletions

View File

@ -1,10 +1,9 @@
import omit from 'lodash.omit';
import pick from 'lodash.pick';
import * as v from 'valibot';
import { accountSchema, groupedNotificationsResultsSchema } from '../entities';
import { filteredArray } from '../entities/utils';
import { type RequestMeta } from '../request';
import { pick, omit } from '../utils';
import type { PlApiBaseClient } from '../client-base';
import type {
@ -69,7 +68,7 @@ const _groupNotifications = (
status_id: notification.status?.id,
// @ts-expect-error used optional chaining
target_id: notification.target?.id,
});
} as NotificationGroup);
}
}
@ -224,15 +223,7 @@ const groupedNotifications = (
}
return client.notifications.getUnreadNotificationCount(
pick(params || {}, [
'max_id',
'since_id',
'limit',
'min_id',
'types',
'exclude_types',
'account_id',
]),
pick(params || {}, ['limit', 'types', 'exclude_types', 'account_id']),
);
},
};

View File

@ -1,6 +1,6 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../utils';
import { isDefaultAvatar, isDefaultHeader } from '../utils/accounts';
import { guessFqn } from '../utils/domain';
@ -107,7 +107,7 @@ const preprocessAccount = v.transform((account: any) => {
...pick(account.akkoma || {}, ['permit_followback']),
is_cat: isCat,
speak_as_cat: speakAsCat,
...(pick(account.other_settings || {}), ['birthday', 'location']),
...pick(account.other_settings || {}, ['birthday', 'location']),
__meta: pick(account, ['pleroma', 'source']),
...account,
display_name:

View File

@ -1,6 +1,6 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../../utils';
import { announcementSchema } from '../announcement';
/**
@ -11,7 +11,7 @@ const adminAnnouncementSchema = v.pipe(
v.any(),
v.transform((announcement: any) => ({
...announcement,
...pick(announcement.pleroma, 'raw_content'),
...pick(announcement.pleroma, ['raw_content']),
})),
v.object({
...announcementSchema.entries,

View File

@ -1,6 +1,6 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../../utils';
import { ruleSchema } from '../rule';
import { statusWithoutAccountSchema } from '../status';
import { datetimeSchema, filteredArray } from '../utils';

View File

@ -1,6 +1,7 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../utils';
import { accountSchema } from './account';
import { accountWarningSchema } from './account-warning';
import { chatMessageSchema } from './chat-message';

View File

@ -1,6 +1,7 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../utils';
import { accountSchema } from './account';
import { accountWarningSchema } from './account-warning';
import { chatMessageSchema } from './chat-message';

View File

@ -1,6 +1,7 @@
import pick from 'lodash.pick';
import * as v from 'valibot';
import { pick } from '../utils';
import { type Account, accountSchema } from './account';
import { customEmojiSchema } from './custom-emoji';
import { emojiReactionSchema } from './emoji-reaction';

View File

@ -9,7 +9,7 @@ interface GetGroupedNotificationsParams extends PaginationParams {
/** Types to exclude from the results. */
exclude_types?: Array<string>;
/** Return only notifications received from the specified account. */
acccount_id?: string;
account_id?: string;
/** One of `full` (default) or `partial_avatars`. When set to `partial_avatars`, some accounts will not be rendered in full in the returned `accounts` list but will be instead returned in stripped-down form in the `partial_accounts` list. The most recent account in a notification group is always rendered in full in the `accounts` attribute. */
expand_accounts?: 'full' | 'partial_avatars';
/** Restrict which notification types can be grouped. Use this if there are notification types for which your client does not support grouping. If omitted, the server will group notifications of all types it supports (currently, `favourite`, `follow` and `reblog`). If you do not want any notification grouping, use GET `/api/v1/notifications` instead. Notifications that would be grouped if not for this parameter will instead be returned as individual single-notification groups with a unique `group_key` that can be assumed to be of the form `ungrouped-{notification_id}`. Please note that neither the streaming API nor the individual notification APIs are aware of this parameter and will always include a “proper” `group_key` that can be different from what is returned here, meaning that you may have to ignore `group_key` for such notifications that you do not want grouped and use `ungrouped-{notification_id}` instead for consistency. */

View File

@ -0,0 +1,19 @@
const pick = <T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> => {
const result = {} as Pick<T, K>;
for (const key of keys) {
if (key in obj) {
result[key] = obj[key];
}
}
return result;
};
const omit = <T extends Record<string, any>, K extends string>(obj: T, keys: K[]): Omit<T, K> => {
const result = { ...obj };
for (const key of keys) {
delete result[key];
}
return result;
};
export { pick, omit };

View File

@ -30,8 +30,6 @@
"blurhash": "^2.0.5",
"http-link-header": "^1.1.3",
"isows": "^1.0.7",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"object-to-formdata": "^4.5.1",
"query-string": "^9.3.1",
"semver": "^7.7.4",
@ -39,8 +37,6 @@
},
"devDependencies": {
"@types/http-link-header": "^1.0.7",
"@types/lodash.omit": "^4.5.9",
"@types/lodash.pick": "^4.4.9",
"@types/node": "^25.3.0",
"@types/semver": "^7.7.1",
"oxfmt": "^0.35.0",

38
pnpm-lock.yaml generated
View File

@ -33,12 +33,6 @@ importers:
isows:
specifier: ^1.0.7
version: 1.0.7(ws@8.19.0)
lodash.omit:
specifier: ^4.5.0
version: 4.5.0
lodash.pick:
specifier: ^4.4.0
version: 4.4.0
object-to-formdata:
specifier: ^4.5.1
version: 4.5.1
@ -55,12 +49,6 @@ importers:
'@types/http-link-header':
specifier: ^1.0.7
version: 1.0.7
'@types/lodash.omit':
specifier: ^4.5.9
version: 4.5.9
'@types/lodash.pick':
specifier: ^4.4.9
version: 4.4.9
'@types/node':
specifier: ^25.3.0
version: 25.3.0
@ -2800,12 +2788,6 @@ packages:
'@types/leaflet@1.9.21':
resolution: {integrity: sha512-TbAd9DaPGSnzp6QvtYngntMZgcRk+igFELwR2N99XZn7RXUdKgsXMR+28bUO0rPsWp8MIu/f47luLIQuSLYv/w==}
'@types/lodash.omit@4.5.9':
resolution: {integrity: sha512-zuAVFLUPJMOzsw6yawshsYGgq2hWUHtsZgeXHZmSFhaQQFC6EQ021uDKHkSjOpNhSvtNSU9165/o3o/Q51GpTw==}
'@types/lodash.pick@4.4.9':
resolution: {integrity: sha512-hDpr96x9xHClwy1KX4/RXRejqjDFTEGbEMT3t6wYSYeFDzxmMnSKB/xHIbktRlPj8Nii2g8L5dtFDRaNFBEzUQ==}
'@types/lodash@4.17.20':
resolution: {integrity: sha512-H3MHACvFUEiujabxhaI/ImO6gUrd8oOurg7LQtS7mbwIXA/cUqWrvBsaeJ23aZEPk1TAYkurjfMbSELfoCXlGA==}
@ -4828,14 +4810,6 @@ packages:
lodash.merge@4.6.2:
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
lodash.omit@4.5.0:
resolution: {integrity: sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==}
deprecated: This package is deprecated. Use destructuring assignment syntax instead.
lodash.pick@4.4.0:
resolution: {integrity: sha512-hXt6Ul/5yWjfklSGvLQl8vM//l3FtyHZeuelpzK6mm99pNvN9yTDruNZPEJZD1oWrqo+izBmB7oUfWgcCX7s4Q==}
deprecated: This package is deprecated. Use destructuring assignment syntax instead.
lodash.sortby@4.7.0:
resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==}
@ -9176,14 +9150,6 @@ snapshots:
dependencies:
'@types/geojson': 7946.0.16
'@types/lodash.omit@4.5.9':
dependencies:
'@types/lodash': 4.17.20
'@types/lodash.pick@4.4.9':
dependencies:
'@types/lodash': 4.17.20
'@types/lodash@4.17.20': {}
'@types/lodash@4.17.24': {}
@ -11419,10 +11385,6 @@ snapshots:
lodash.merge@4.6.2: {}
lodash.omit@4.5.0: {}
lodash.pick@4.4.0: {}
lodash.sortby@4.7.0: {}
lodash.truncate@4.4.2: {}