@openpeepshq/common 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/contentLength.d.ts +25 -0
- package/dist/lib/contentLength.js +118 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/types/analytics.d.ts +3 -3
- package/dist/types/api.d.ts +53 -40
- package/dist/types/api.js +19 -2
- package/dist/types/db.d.ts +8 -8
- package/dist/types/internal.d.ts +14 -14
- package/dist/types/models.d.ts +373 -3
- package/dist/types/models.js +42 -8
- package/dist/types/stats.d.ts +36 -36
- package/package.json +1 -1
- package/src/lib/contentLength.ts +139 -0
- package/src/lib/index.ts +1 -0
- package/src/types/api.ts +27 -1
- package/src/types/models.ts +65 -15
package/src/types/api.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type MediaAttachment,
|
|
28
28
|
mediaAttachmentSchema,
|
|
29
29
|
mentionDataSchema,
|
|
30
|
+
postDataInputUnionSchema,
|
|
30
31
|
postDataUnionSchema,
|
|
31
32
|
postTypeSchema,
|
|
32
33
|
profileDataSchema,
|
|
@@ -729,6 +730,8 @@ export type ReportCreationData = z.infer<typeof reportCreationDataSchema>;
|
|
|
729
730
|
export const jamStateSchema = z.object({
|
|
730
731
|
active: z.boolean(),
|
|
731
732
|
participants: z.uuid().array(),
|
|
733
|
+
/** Count of hidden `EG_` sessions (observer links, recording/RTMP egress). */
|
|
734
|
+
observers: z.number().optional(),
|
|
732
735
|
});
|
|
733
736
|
export type JamState = z.infer<typeof jamStateSchema>;
|
|
734
737
|
|
|
@@ -762,6 +765,29 @@ export type OffsetInfiniteQueryParams =
|
|
|
762
765
|
| z.infer<typeof offsetInfiniteQueryParamsSchema>
|
|
763
766
|
| undefined;
|
|
764
767
|
|
|
768
|
+
/** Span cap of the date-range event feeds (events calendar). */
|
|
769
|
+
export const EVENT_RANGE_MAX_SPAN_MS = 62 * 24 * 60 * 60 * 1000;
|
|
770
|
+
|
|
771
|
+
/** Default page size of the date-range event feeds (events calendar). */
|
|
772
|
+
export const EVENT_RANGE_DEFAULT_LIMIT = 500;
|
|
773
|
+
|
|
774
|
+
/** Query params of the date-range event feeds (events calendar). */
|
|
775
|
+
export const eventRangeQueryParamsSchema = z
|
|
776
|
+
.object({
|
|
777
|
+
from: z.string().datetime({ offset: true }),
|
|
778
|
+
to: z.string().datetime({ offset: true }),
|
|
779
|
+
offset: z.coerce.number().optional(),
|
|
780
|
+
limit: z.coerce.number().optional(),
|
|
781
|
+
})
|
|
782
|
+
.refine(
|
|
783
|
+
(value) =>
|
|
784
|
+
new Date(value.from).getTime() < new Date(value.to).getTime() &&
|
|
785
|
+
new Date(value.to).getTime() - new Date(value.from).getTime() <=
|
|
786
|
+
EVENT_RANGE_MAX_SPAN_MS,
|
|
787
|
+
{ message: 'from < to with a span of at most 62 days' },
|
|
788
|
+
);
|
|
789
|
+
export type EventRangeQueryParams = z.infer<typeof eventRangeQueryParamsSchema>;
|
|
790
|
+
|
|
765
791
|
export const searchResultItemSchema = (baseSchema: z.ZodType) =>
|
|
766
792
|
z.object({
|
|
767
793
|
score: z.number(),
|
|
@@ -799,7 +825,7 @@ export type DirectMessageSearchHit = z.infer<
|
|
|
799
825
|
export const postCreationDataSchema = z.object({
|
|
800
826
|
visibility: visibilityTypeSchema,
|
|
801
827
|
type: postTypeSchema,
|
|
802
|
-
data:
|
|
828
|
+
data: postDataInputUnionSchema,
|
|
803
829
|
inReplyToId: z.uuid().nullable().optional(),
|
|
804
830
|
mentions: mentionWithPublicProfileSchema.array().nullable().optional(),
|
|
805
831
|
audience: publicProfileSchema.array().nullable().optional(),
|
package/src/types/models.ts
CHANGED
|
@@ -3,6 +3,7 @@ import validator from 'validator';
|
|
|
3
3
|
import ISO6391 from 'iso-639-1';
|
|
4
4
|
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
5
5
|
import { isEndBeforeStart } from '../lib/eventTime';
|
|
6
|
+
import { hasVisibleText, postContentWithinBudget } from '../lib/contentLength';
|
|
6
7
|
import { groupRelationships } from './capabilities';
|
|
7
8
|
import { capabilitiesSchema } from './config';
|
|
8
9
|
import {
|
|
@@ -498,23 +499,43 @@ export const customEmojiSchema = z
|
|
|
498
499
|
.openapi('CustomEmoji');
|
|
499
500
|
export type CustomEmoji = z.infer<typeof customEmojiSchema>;
|
|
500
501
|
|
|
501
|
-
|
|
502
|
-
.
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
502
|
+
const noteBaseSchema = z.object({
|
|
503
|
+
type: z.literal('note'),
|
|
504
|
+
content: z.string().optional(),
|
|
505
|
+
sensitive: z.boolean().optional(),
|
|
506
|
+
spoilerText: z.string().optional(),
|
|
507
|
+
attachments: z.array(mediaAttachmentDataSchema).optional(),
|
|
508
|
+
customEmojis: z.array(customEmojiSchema).optional(),
|
|
509
|
+
language: z.enum(ISO6391.getAllCodes() as [string, ...string[]]).optional(),
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// A note must carry something a reader can see: visible text or an
|
|
513
|
+
// attachment. Whitespace-only text renders nothing, so it is not enough.
|
|
514
|
+
const hasContentRefine = {
|
|
515
|
+
message: 'posts.form.contentRequired',
|
|
516
|
+
path: ['content'],
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// Note/question carry the visible-text + raw budgets; the longer post
|
|
520
|
+
// flavors (article, resource, event) extend the base without them.
|
|
521
|
+
const contentBudgetRefine = {
|
|
522
|
+
message: 'posts.form.contentTooLong',
|
|
523
|
+
path: ['content'],
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
// The refines are write-side checks only: they must live on the input
|
|
527
|
+
// schemas the write endpoints validate against, not on the members of
|
|
528
|
+
// `postDataUnionSchema`. That union also validates API *responses*
|
|
529
|
+
// (`publicPostSchema`, reply/entry data), where a contentless note is
|
|
530
|
+
// legitimate — repost shells and system "left" notes have neither
|
|
531
|
+
// content nor attachments, and output validation must not reject them.
|
|
532
|
+
export const noteSchema = noteBaseSchema.openapi('Note');
|
|
512
533
|
export type Note = z.infer<typeof noteSchema>;
|
|
513
534
|
|
|
514
535
|
/** Poll choices are stored short so they fit the vote UI on small screens. */
|
|
515
536
|
export const POLL_OPTION_MAX_LENGTH = 30;
|
|
516
537
|
|
|
517
|
-
export const questionSchema =
|
|
538
|
+
export const questionSchema = noteBaseSchema
|
|
518
539
|
.extend({
|
|
519
540
|
type: z.literal('question'),
|
|
520
541
|
options: z
|
|
@@ -531,7 +552,23 @@ export const questionSchema = noteSchema
|
|
|
531
552
|
|
|
532
553
|
export type Question = z.infer<typeof questionSchema>;
|
|
533
554
|
|
|
534
|
-
export const
|
|
555
|
+
export const noteInputSchema = noteBaseSchema
|
|
556
|
+
.refine(
|
|
557
|
+
(data) =>
|
|
558
|
+
hasVisibleText(data.content) || (data.attachments?.length ?? 0) > 0,
|
|
559
|
+
hasContentRefine,
|
|
560
|
+
)
|
|
561
|
+
.refine((data) => postContentWithinBudget(data.content), contentBudgetRefine);
|
|
562
|
+
|
|
563
|
+
export const questionInputSchema = questionSchema
|
|
564
|
+
.refine(
|
|
565
|
+
(data) =>
|
|
566
|
+
hasVisibleText(data.content) || (data.attachments?.length ?? 0) > 0,
|
|
567
|
+
hasContentRefine,
|
|
568
|
+
)
|
|
569
|
+
.refine((data) => postContentWithinBudget(data.content), contentBudgetRefine);
|
|
570
|
+
|
|
571
|
+
export const articleSchema = noteBaseSchema
|
|
535
572
|
.extend({
|
|
536
573
|
type: z.literal('article'),
|
|
537
574
|
image: z.url().optional(),
|
|
@@ -544,7 +581,7 @@ export type Article = z.infer<typeof articleSchema>;
|
|
|
544
581
|
/** Resource titles are library headings, so they stay much shorter than the description. */
|
|
545
582
|
export const RESOURCE_TITLE_MAX_LENGTH = 200;
|
|
546
583
|
|
|
547
|
-
export const resourcePostSchema =
|
|
584
|
+
export const resourcePostSchema = noteBaseSchema
|
|
548
585
|
.extend({
|
|
549
586
|
type: z.literal('resource'),
|
|
550
587
|
title: z.string().max(RESOURCE_TITLE_MAX_LENGTH),
|
|
@@ -607,7 +644,7 @@ export type EventOccurrenceException = z.infer<
|
|
|
607
644
|
typeof eventOccurrenceExceptionSchema
|
|
608
645
|
>;
|
|
609
646
|
|
|
610
|
-
export const eventSchema =
|
|
647
|
+
export const eventSchema = noteBaseSchema
|
|
611
648
|
.extend({
|
|
612
649
|
type: z.literal('event'),
|
|
613
650
|
name: z.string().optional(),
|
|
@@ -646,6 +683,19 @@ export const postDataUnionSchema = z.discriminatedUnion('type', [
|
|
|
646
683
|
|
|
647
684
|
export type PostDataUnion = z.infer<typeof postDataUnionSchema>;
|
|
648
685
|
|
|
686
|
+
// Write-side union: the server POST/PUT endpoints validate *incoming*
|
|
687
|
+
// post payloads with this. The budget/requirement refines must not sit
|
|
688
|
+
// on the response-facing `postDataUnionSchema` members (see above).
|
|
689
|
+
export const postDataInputUnionSchema = z.discriminatedUnion('type', [
|
|
690
|
+
noteInputSchema,
|
|
691
|
+
questionInputSchema,
|
|
692
|
+
eventSchema,
|
|
693
|
+
articleSchema,
|
|
694
|
+
resourcePostSchema,
|
|
695
|
+
]);
|
|
696
|
+
|
|
697
|
+
export type PostDataInputUnion = z.infer<typeof postDataInputUnionSchema>;
|
|
698
|
+
|
|
649
699
|
export const postDataSchema = z.object({
|
|
650
700
|
type: postTypeSchema,
|
|
651
701
|
visibility: visibilityTypeSchema,
|