pl-api: try to work on tree-shaking, i guess

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2025-01-02 15:41:08 +01:00
parent 781fb7a86d
commit e3fc390fc6
11 changed files with 512 additions and 359 deletions

View File

@ -10,7 +10,14 @@ A JavaScript library for interacting with Mastodon API-compatible servers, focus
Example:
```ts
import { PlApiClient, type CreateApplicationParams } from 'pl-api';
import {
ALL_SCHEMAS,
importSchemas,
PlApiClient,
type CreateApplicationParams,
} from 'pl-api';
importSchemas(ALL_SCHEMAS);
const { ACCESS_TOKEN } = process.env;

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@ export * from './backup';
export * from './bookmark-folder';
export * from './chat';
export * from './chat-message';
export * from './circle';
export * from './context';
export * from './conversation';
export * from './custom-emoji';
@ -57,6 +58,7 @@ export * from './notification-request';
export * from './oauth-token';
export * from './poll';
export * from './preview-card';
export * from './preview-card-author';
export * from './relationship';
export * from './relationship-severance-event';
export * from './report';

View File

@ -5,3 +5,5 @@ export * from './entities';
export * from './features';
export * from './params';
export * from './responses';
export * from './schemas';
export * from './schemas/all-schemas';

View File

@ -0,0 +1,193 @@
import {
accountSchema,
accountWarningSchema,
adminAccountSchema,
adminAnnouncementSchema,
adminCanonicalEmailBlockSchema,
adminCohortSchema,
adminDimensionSchema,
adminDomainAllowSchema,
adminDomainBlockSchema,
adminDomainSchema,
adminEmailDomainBlockSchema,
adminIpBlockSchema,
adminIpSchema,
adminMeasureSchema,
adminModerationLogEntrySchema,
adminRelaySchema,
adminReportSchema,
adminRuleSchema,
adminTagSchema,
announcementReactionSchema,
announcementSchema,
antennaSchema,
applicationSchema,
backupSchema,
blurhashSchema,
bookmarkFolderSchema,
chatMessageSchema,
chatSchema,
circleSchema,
contextSchema,
conversationSchema,
credentialAccountSchema,
credentialApplicationSchema,
customEmojiSchema,
domainBlockSchema,
emojiReactionSchema,
extendedDescriptionSchema,
familiarFollowersSchema,
featuredTagSchema,
filterKeywordSchema,
filterSchema,
filterStatusSchema,
followRelationshipUpdateSchema,
groupedNotificationsResultsSchema,
groupMemberSchema,
groupRelationshipSchema,
groupSchema,
historySchema,
instanceSchema,
interactionPoliciesSchema,
interactionPolicySchema,
interactionRequestSchema,
listSchema,
locationSchema,
markerSchema,
markersSchema,
mediaAttachmentSchema,
mentionSchema,
mutedAccountSchema,
notificationGroupSchema,
notificationPolicySchema,
notificationRequestSchema,
notificationSchema,
oauthTokenSchema,
pleromaConfigSchema,
pollSchema,
previewCardAuthorSchema,
previewCardSchema,
relationshipSchema,
relationshipSeveranceEventSchema,
reportSchema,
roleSchema,
ruleSchema,
scheduledStatusSchema,
scrobbleSchema,
searchSchema,
statusEditSchema,
statusSchema,
statusSourceSchema,
statusWithoutAccountSchema,
streamingEventSchema,
suggestionSchema,
tagSchema,
tokenSchema,
translationSchema,
trendsLinkSchema,
webPushSubscriptionSchema,
} from '../entities';
const NON_ADMIN_SCHEMAS = {
accountSchema,
accountWarningSchema,
announcementReactionSchema,
announcementSchema,
antennaSchema,
applicationSchema,
backupSchema,
blurhashSchema,
bookmarkFolderSchema,
chatMessageSchema,
chatSchema,
circleSchema,
contextSchema,
conversationSchema,
credentialAccountSchema,
credentialApplicationSchema,
customEmojiSchema,
domainBlockSchema,
emojiReactionSchema,
extendedDescriptionSchema,
familiarFollowersSchema,
featuredTagSchema,
filterKeywordSchema,
filterSchema,
filterStatusSchema,
followRelationshipUpdateSchema,
groupedNotificationsResultsSchema,
groupMemberSchema,
groupRelationshipSchema,
groupSchema,
historySchema,
instanceSchema,
interactionPoliciesSchema,
interactionPolicySchema,
interactionRequestSchema,
listSchema,
locationSchema,
markerSchema,
markersSchema,
mediaAttachmentSchema,
mentionSchema,
mutedAccountSchema,
notificationGroupSchema,
notificationPolicySchema,
notificationRequestSchema,
notificationSchema,
oauthTokenSchema,
pollSchema,
previewCardAuthorSchema,
previewCardSchema,
relationshipSchema,
relationshipSeveranceEventSchema,
reportSchema,
roleSchema,
ruleSchema,
scheduledStatusSchema,
scrobbleSchema,
searchSchema,
statusEditSchema,
statusSchema,
statusSourceSchema,
statusWithoutAccountSchema,
streamingEventSchema,
suggestionSchema,
tagSchema,
tokenSchema,
translationSchema,
trendsLinkSchema,
webPushSubscriptionSchema,
};
const ADMIN_SCHEMAS = {
adminAccountSchema,
adminAnnouncementSchema,
adminCanonicalEmailBlockSchema,
adminCohortSchema,
adminDimensionSchema,
adminDomainAllowSchema,
adminDomainBlockSchema,
adminDomainSchema,
adminEmailDomainBlockSchema,
adminIpBlockSchema,
adminIpSchema,
adminMeasureSchema,
adminModerationLogEntrySchema,
adminRelaySchema,
adminReportSchema,
adminRuleSchema,
adminTagSchema,
pleromaConfigSchema,
};
const ALL_SCHEMAS = {
...ADMIN_SCHEMAS,
...NON_ADMIN_SCHEMAS,
};
export {
ALL_SCHEMAS,
ADMIN_SCHEMAS,
NON_ADMIN_SCHEMAS,
};

View File

@ -0,0 +1,17 @@
import * as v from 'valibot';
import type { ALL_SCHEMAS } from './all-schemas';
const nullSchema = v.fallback(v.null(), null);
const IMPORTED_SCHEMAS = {} as typeof ALL_SCHEMAS;
const SCHEMAS = new Proxy(IMPORTED_SCHEMAS, {
get: (target, p: keyof typeof ALL_SCHEMAS) => p in target ? target[p] : nullSchema,
});
const importSchemas = (schemas: Partial<typeof ALL_SCHEMAS>) =>
// @ts-ignore
Object.entries(schemas).forEach(([key, value]) => IMPORTED_SCHEMAS[key] = value);
export { SCHEMAS, importSchemas };

View File

@ -1,6 +1,6 @@
{
"name": "pl-api",
"version": "1.0.0-rc.10",
"version": "1.0.0-rc.11",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-api",
"repository": {

View File

@ -1,3 +1,4 @@
import './schemas';
import './polyfills';
import React from 'react';

View File

@ -0,0 +1,3 @@
import { ALL_SCHEMAS, importSchemas } from 'pl-api';
importSchemas(ALL_SCHEMAS);

View File

@ -1,6 +1,6 @@
{
"name": "pl-hooks",
"version": "0.0.6",
"version": "0.0.7",
"type": "module",
"homepage": "https://github.com/mkljczk/pl-fe/tree/develop/packages/pl-hooks",
"repository": {
@ -35,9 +35,9 @@
"dependencies": {
"@tanstack/react-query": "^5.59.16",
"lodash": "^4.17.21",
"pl-api": "^1.0.0-rc.1",
"pl-api": "^1.0.0-rc.11",
"react": "^18.3.1",
"valibot": "^0.42.1"
"valibot": "^1.0.0-beta.9"
},
"module": "./dist/main.es.js",
"types": "dist/main.d.ts",

View File

@ -2158,10 +2158,10 @@ pkg-types@^1.0.3, pkg-types@^1.1.1:
mlly "^1.7.1"
pathe "^1.1.2"
pl-api@^1.0.0-rc.1:
version "1.0.0-rc.1"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.1.tgz#e5b1ead42230ed86e57ebaf020f3a2114da3bce0"
integrity sha512-bwV831HoATajRlmZg4USIzQvHgZC9MBAg0/sN/T5uXrM5tcUzfM+qU5ZQIzk+r5gSQ0ZCwqkjbajvhbn9tRcBA==
pl-api@^1.0.0-rc.11:
version "1.0.0-rc.11"
resolved "https://registry.yarnpkg.com/pl-api/-/pl-api-1.0.0-rc.11.tgz#57336fa1907ad62daf46c641e75bc32a93126554"
integrity sha512-7trd+istbYdDYC8lXE7soUVOJGBMlKdYM0RLuBSzdV6UnL8h0TOgJKQ6lD/hc8bFYKXbN0i/vJYW6GDgcuAEAQ==
dependencies:
blurhash "^2.0.5"
http-link-header "^1.1.3"
@ -2171,7 +2171,7 @@ pl-api@^1.0.0-rc.1:
object-to-formdata "^4.5.1"
query-string "^9.1.1"
semver "^7.6.3"
valibot "^0.42.1"
valibot "^1.0.0-beta.9"
possible-typed-array-names@^1.0.0:
version "1.0.0"
@ -2613,10 +2613,10 @@ uri-js@^4.2.2, uri-js@^4.4.1:
dependencies:
punycode "^2.1.0"
valibot@^0.42.1:
version "0.42.1"
resolved "https://registry.yarnpkg.com/valibot/-/valibot-0.42.1.tgz#a31183d8e9d7552f98e22ca0977172cab8815188"
integrity sha512-3keXV29Ar5b//Hqi4MbSdV7lfVp6zuYLZuA9V1PvQUsXqogr+u5lvLPLk3A4f74VUXDnf/JfWMN6sB+koJ/FFw==
valibot@^1.0.0-beta.9:
version "1.0.0-beta.9"
resolved "https://registry.yarnpkg.com/valibot/-/valibot-1.0.0-beta.9.tgz#8ae38ca53429a5c4c4cce4378e3c87cca708a287"
integrity sha512-yEX8gMAZ2R1yI2uwOO4NCtVnJQx36zn3vD0omzzj9FhcoblvPukENIiRZXKZwCnqSeV80bMm8wNiGhQ0S8fiww==
vite-plugin-dts@^4.2.1:
version "4.2.1"