@openpeepshq/common 0.6.4 → 0.8.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/lib/postHelpers.d.ts +23 -1
- package/dist/lib/postHelpers.js +41 -0
- package/dist/types/analytics.d.ts +3 -3
- package/dist/types/api.d.ts +40 -40
- package/dist/types/api.js +2 -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/lib/postHelpers.ts +91 -1
- package/src/types/api.ts +2 -1
- package/src/types/models.ts +65 -15
package/dist/types/stats.d.ts
CHANGED
|
@@ -49,9 +49,9 @@ export type ObjectStatsWithAll = z.infer<typeof objectStatsWithAllSchema>;
|
|
|
49
49
|
export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
50
50
|
id: z.ZodString;
|
|
51
51
|
type: z.ZodEnum<{
|
|
52
|
-
resource: "resource";
|
|
53
52
|
note: "note";
|
|
54
53
|
question: "question";
|
|
54
|
+
resource: "resource";
|
|
55
55
|
event: "event";
|
|
56
56
|
article: "article";
|
|
57
57
|
}>;
|
|
@@ -1968,9 +1968,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
1968
1968
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1969
1969
|
id: z.ZodString;
|
|
1970
1970
|
type: z.ZodEnum<{
|
|
1971
|
-
resource: "resource";
|
|
1972
1971
|
note: "note";
|
|
1973
1972
|
question: "question";
|
|
1973
|
+
resource: "resource";
|
|
1974
1974
|
event: "event";
|
|
1975
1975
|
article: "article";
|
|
1976
1976
|
}>;
|
|
@@ -3659,9 +3659,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
3659
3659
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
3660
3660
|
id: z.ZodString;
|
|
3661
3661
|
type: z.ZodEnum<{
|
|
3662
|
-
resource: "resource";
|
|
3663
3662
|
note: "note";
|
|
3664
3663
|
question: "question";
|
|
3664
|
+
resource: "resource";
|
|
3665
3665
|
event: "event";
|
|
3666
3666
|
article: "article";
|
|
3667
3667
|
}>;
|
|
@@ -5616,9 +5616,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
5616
5616
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
5617
5617
|
id: z.ZodString;
|
|
5618
5618
|
type: z.ZodEnum<{
|
|
5619
|
-
resource: "resource";
|
|
5620
5619
|
note: "note";
|
|
5621
5620
|
question: "question";
|
|
5621
|
+
resource: "resource";
|
|
5622
5622
|
event: "event";
|
|
5623
5623
|
article: "article";
|
|
5624
5624
|
}>;
|
|
@@ -7307,9 +7307,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
7307
7307
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
7308
7308
|
id: z.ZodString;
|
|
7309
7309
|
type: z.ZodEnum<{
|
|
7310
|
-
resource: "resource";
|
|
7311
7310
|
note: "note";
|
|
7312
7311
|
question: "question";
|
|
7312
|
+
resource: "resource";
|
|
7313
7313
|
event: "event";
|
|
7314
7314
|
article: "article";
|
|
7315
7315
|
}>;
|
|
@@ -9000,9 +9000,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
9000
9000
|
repost: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
9001
9001
|
id: z.ZodString;
|
|
9002
9002
|
type: z.ZodEnum<{
|
|
9003
|
-
resource: "resource";
|
|
9004
9003
|
note: "note";
|
|
9005
9004
|
question: "question";
|
|
9005
|
+
resource: "resource";
|
|
9006
9006
|
event: "event";
|
|
9007
9007
|
article: "article";
|
|
9008
9008
|
}>;
|
|
@@ -10690,9 +10690,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
10690
10690
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
10691
10691
|
id: z.ZodString;
|
|
10692
10692
|
type: z.ZodEnum<{
|
|
10693
|
-
resource: "resource";
|
|
10694
10693
|
note: "note";
|
|
10695
10694
|
question: "question";
|
|
10695
|
+
resource: "resource";
|
|
10696
10696
|
event: "event";
|
|
10697
10697
|
article: "article";
|
|
10698
10698
|
}>;
|
|
@@ -12612,9 +12612,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
12612
12612
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12613
12613
|
id: z.ZodString;
|
|
12614
12614
|
type: z.ZodEnum<{
|
|
12615
|
-
resource: "resource";
|
|
12616
12615
|
note: "note";
|
|
12617
12616
|
question: "question";
|
|
12617
|
+
resource: "resource";
|
|
12618
12618
|
event: "event";
|
|
12619
12619
|
article: "article";
|
|
12620
12620
|
}>;
|
|
@@ -14303,9 +14303,9 @@ export declare const publicPostWithActivityScoreSchema: z.ZodObject<{
|
|
|
14303
14303
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
14304
14304
|
id: z.ZodString;
|
|
14305
14305
|
type: z.ZodEnum<{
|
|
14306
|
-
resource: "resource";
|
|
14307
14306
|
note: "note";
|
|
14308
14307
|
question: "question";
|
|
14308
|
+
resource: "resource";
|
|
14309
14309
|
event: "event";
|
|
14310
14310
|
article: "article";
|
|
14311
14311
|
}>;
|
|
@@ -16376,9 +16376,9 @@ export type TopListKey = 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
|
16376
16376
|
declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
16377
16377
|
id: z.ZodString;
|
|
16378
16378
|
type: z.ZodEnum<{
|
|
16379
|
-
resource: "resource";
|
|
16380
16379
|
note: "note";
|
|
16381
16380
|
question: "question";
|
|
16381
|
+
resource: "resource";
|
|
16382
16382
|
event: "event";
|
|
16383
16383
|
article: "article";
|
|
16384
16384
|
}>;
|
|
@@ -18295,9 +18295,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
18295
18295
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
18296
18296
|
id: z.ZodString;
|
|
18297
18297
|
type: z.ZodEnum<{
|
|
18298
|
-
resource: "resource";
|
|
18299
18298
|
note: "note";
|
|
18300
18299
|
question: "question";
|
|
18300
|
+
resource: "resource";
|
|
18301
18301
|
event: "event";
|
|
18302
18302
|
article: "article";
|
|
18303
18303
|
}>;
|
|
@@ -19986,9 +19986,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
19986
19986
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
19987
19987
|
id: z.ZodString;
|
|
19988
19988
|
type: z.ZodEnum<{
|
|
19989
|
-
resource: "resource";
|
|
19990
19989
|
note: "note";
|
|
19991
19990
|
question: "question";
|
|
19991
|
+
resource: "resource";
|
|
19992
19992
|
event: "event";
|
|
19993
19993
|
article: "article";
|
|
19994
19994
|
}>;
|
|
@@ -21943,9 +21943,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
21943
21943
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
21944
21944
|
id: z.ZodString;
|
|
21945
21945
|
type: z.ZodEnum<{
|
|
21946
|
-
resource: "resource";
|
|
21947
21946
|
note: "note";
|
|
21948
21947
|
question: "question";
|
|
21948
|
+
resource: "resource";
|
|
21949
21949
|
event: "event";
|
|
21950
21950
|
article: "article";
|
|
21951
21951
|
}>;
|
|
@@ -23634,9 +23634,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
23634
23634
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
23635
23635
|
id: z.ZodString;
|
|
23636
23636
|
type: z.ZodEnum<{
|
|
23637
|
-
resource: "resource";
|
|
23638
23637
|
note: "note";
|
|
23639
23638
|
question: "question";
|
|
23639
|
+
resource: "resource";
|
|
23640
23640
|
event: "event";
|
|
23641
23641
|
article: "article";
|
|
23642
23642
|
}>;
|
|
@@ -25327,9 +25327,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
25327
25327
|
repost: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
25328
25328
|
id: z.ZodString;
|
|
25329
25329
|
type: z.ZodEnum<{
|
|
25330
|
-
resource: "resource";
|
|
25331
25330
|
note: "note";
|
|
25332
25331
|
question: "question";
|
|
25332
|
+
resource: "resource";
|
|
25333
25333
|
event: "event";
|
|
25334
25334
|
article: "article";
|
|
25335
25335
|
}>;
|
|
@@ -27017,9 +27017,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
27017
27017
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
27018
27018
|
id: z.ZodString;
|
|
27019
27019
|
type: z.ZodEnum<{
|
|
27020
|
-
resource: "resource";
|
|
27021
27020
|
note: "note";
|
|
27022
27021
|
question: "question";
|
|
27022
|
+
resource: "resource";
|
|
27023
27023
|
event: "event";
|
|
27024
27024
|
article: "article";
|
|
27025
27025
|
}>;
|
|
@@ -28939,9 +28939,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
28939
28939
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
28940
28940
|
id: z.ZodString;
|
|
28941
28941
|
type: z.ZodEnum<{
|
|
28942
|
-
resource: "resource";
|
|
28943
28942
|
note: "note";
|
|
28944
28943
|
question: "question";
|
|
28944
|
+
resource: "resource";
|
|
28945
28945
|
event: "event";
|
|
28946
28946
|
article: "article";
|
|
28947
28947
|
}>;
|
|
@@ -30630,9 +30630,9 @@ declare const topPostsListSchema: z.ZodArray<z.ZodObject<{
|
|
|
30630
30630
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
30631
30631
|
id: z.ZodString;
|
|
30632
30632
|
type: z.ZodEnum<{
|
|
30633
|
-
resource: "resource";
|
|
30634
30633
|
note: "note";
|
|
30635
30634
|
question: "question";
|
|
30635
|
+
resource: "resource";
|
|
30636
30636
|
event: "event";
|
|
30637
30637
|
article: "article";
|
|
30638
30638
|
}>;
|
|
@@ -32973,9 +32973,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
32973
32973
|
topPosts: z.ZodArray<z.ZodObject<{
|
|
32974
32974
|
id: z.ZodString;
|
|
32975
32975
|
type: z.ZodEnum<{
|
|
32976
|
-
resource: "resource";
|
|
32977
32976
|
note: "note";
|
|
32978
32977
|
question: "question";
|
|
32978
|
+
resource: "resource";
|
|
32979
32979
|
event: "event";
|
|
32980
32980
|
article: "article";
|
|
32981
32981
|
}>;
|
|
@@ -34892,9 +34892,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
34892
34892
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
34893
34893
|
id: z.ZodString;
|
|
34894
34894
|
type: z.ZodEnum<{
|
|
34895
|
-
resource: "resource";
|
|
34896
34895
|
note: "note";
|
|
34897
34896
|
question: "question";
|
|
34897
|
+
resource: "resource";
|
|
34898
34898
|
event: "event";
|
|
34899
34899
|
article: "article";
|
|
34900
34900
|
}>;
|
|
@@ -36583,9 +36583,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
36583
36583
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
36584
36584
|
id: z.ZodString;
|
|
36585
36585
|
type: z.ZodEnum<{
|
|
36586
|
-
resource: "resource";
|
|
36587
36586
|
note: "note";
|
|
36588
36587
|
question: "question";
|
|
36588
|
+
resource: "resource";
|
|
36589
36589
|
event: "event";
|
|
36590
36590
|
article: "article";
|
|
36591
36591
|
}>;
|
|
@@ -38540,9 +38540,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
38540
38540
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
38541
38541
|
id: z.ZodString;
|
|
38542
38542
|
type: z.ZodEnum<{
|
|
38543
|
-
resource: "resource";
|
|
38544
38543
|
note: "note";
|
|
38545
38544
|
question: "question";
|
|
38545
|
+
resource: "resource";
|
|
38546
38546
|
event: "event";
|
|
38547
38547
|
article: "article";
|
|
38548
38548
|
}>;
|
|
@@ -40231,9 +40231,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
40231
40231
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
40232
40232
|
id: z.ZodString;
|
|
40233
40233
|
type: z.ZodEnum<{
|
|
40234
|
-
resource: "resource";
|
|
40235
40234
|
note: "note";
|
|
40236
40235
|
question: "question";
|
|
40236
|
+
resource: "resource";
|
|
40237
40237
|
event: "event";
|
|
40238
40238
|
article: "article";
|
|
40239
40239
|
}>;
|
|
@@ -41924,9 +41924,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
41924
41924
|
repost: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
41925
41925
|
id: z.ZodString;
|
|
41926
41926
|
type: z.ZodEnum<{
|
|
41927
|
-
resource: "resource";
|
|
41928
41927
|
note: "note";
|
|
41929
41928
|
question: "question";
|
|
41929
|
+
resource: "resource";
|
|
41930
41930
|
event: "event";
|
|
41931
41931
|
article: "article";
|
|
41932
41932
|
}>;
|
|
@@ -43614,9 +43614,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
43614
43614
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
43615
43615
|
id: z.ZodString;
|
|
43616
43616
|
type: z.ZodEnum<{
|
|
43617
|
-
resource: "resource";
|
|
43618
43617
|
note: "note";
|
|
43619
43618
|
question: "question";
|
|
43619
|
+
resource: "resource";
|
|
43620
43620
|
event: "event";
|
|
43621
43621
|
article: "article";
|
|
43622
43622
|
}>;
|
|
@@ -45536,9 +45536,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
45536
45536
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
45537
45537
|
id: z.ZodString;
|
|
45538
45538
|
type: z.ZodEnum<{
|
|
45539
|
-
resource: "resource";
|
|
45540
45539
|
note: "note";
|
|
45541
45540
|
question: "question";
|
|
45541
|
+
resource: "resource";
|
|
45542
45542
|
event: "event";
|
|
45543
45543
|
article: "article";
|
|
45544
45544
|
}>;
|
|
@@ -47227,9 +47227,9 @@ export declare const profileActivitySummarySchema: z.ZodObject<{
|
|
|
47227
47227
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
47228
47228
|
id: z.ZodString;
|
|
47229
47229
|
type: z.ZodEnum<{
|
|
47230
|
-
resource: "resource";
|
|
47231
47230
|
note: "note";
|
|
47232
47231
|
question: "question";
|
|
47232
|
+
resource: "resource";
|
|
47233
47233
|
event: "event";
|
|
47234
47234
|
article: "article";
|
|
47235
47235
|
}>;
|
|
@@ -49311,9 +49311,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
49311
49311
|
topPosts: z.ZodArray<z.ZodObject<{
|
|
49312
49312
|
id: z.ZodString;
|
|
49313
49313
|
type: z.ZodEnum<{
|
|
49314
|
-
resource: "resource";
|
|
49315
49314
|
note: "note";
|
|
49316
49315
|
question: "question";
|
|
49316
|
+
resource: "resource";
|
|
49317
49317
|
event: "event";
|
|
49318
49318
|
article: "article";
|
|
49319
49319
|
}>;
|
|
@@ -51230,9 +51230,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
51230
51230
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
51231
51231
|
id: z.ZodString;
|
|
51232
51232
|
type: z.ZodEnum<{
|
|
51233
|
-
resource: "resource";
|
|
51234
51233
|
note: "note";
|
|
51235
51234
|
question: "question";
|
|
51235
|
+
resource: "resource";
|
|
51236
51236
|
event: "event";
|
|
51237
51237
|
article: "article";
|
|
51238
51238
|
}>;
|
|
@@ -52921,9 +52921,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
52921
52921
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
52922
52922
|
id: z.ZodString;
|
|
52923
52923
|
type: z.ZodEnum<{
|
|
52924
|
-
resource: "resource";
|
|
52925
52924
|
note: "note";
|
|
52926
52925
|
question: "question";
|
|
52926
|
+
resource: "resource";
|
|
52927
52927
|
event: "event";
|
|
52928
52928
|
article: "article";
|
|
52929
52929
|
}>;
|
|
@@ -54878,9 +54878,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
54878
54878
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
54879
54879
|
id: z.ZodString;
|
|
54880
54880
|
type: z.ZodEnum<{
|
|
54881
|
-
resource: "resource";
|
|
54882
54881
|
note: "note";
|
|
54883
54882
|
question: "question";
|
|
54883
|
+
resource: "resource";
|
|
54884
54884
|
event: "event";
|
|
54885
54885
|
article: "article";
|
|
54886
54886
|
}>;
|
|
@@ -56569,9 +56569,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
56569
56569
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
56570
56570
|
id: z.ZodString;
|
|
56571
56571
|
type: z.ZodEnum<{
|
|
56572
|
-
resource: "resource";
|
|
56573
56572
|
note: "note";
|
|
56574
56573
|
question: "question";
|
|
56574
|
+
resource: "resource";
|
|
56575
56575
|
event: "event";
|
|
56576
56576
|
article: "article";
|
|
56577
56577
|
}>;
|
|
@@ -58262,9 +58262,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
58262
58262
|
repost: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
58263
58263
|
id: z.ZodString;
|
|
58264
58264
|
type: z.ZodEnum<{
|
|
58265
|
-
resource: "resource";
|
|
58266
58265
|
note: "note";
|
|
58267
58266
|
question: "question";
|
|
58267
|
+
resource: "resource";
|
|
58268
58268
|
event: "event";
|
|
58269
58269
|
article: "article";
|
|
58270
58270
|
}>;
|
|
@@ -59952,9 +59952,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
59952
59952
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
59953
59953
|
id: z.ZodString;
|
|
59954
59954
|
type: z.ZodEnum<{
|
|
59955
|
-
resource: "resource";
|
|
59956
59955
|
note: "note";
|
|
59957
59956
|
question: "question";
|
|
59957
|
+
resource: "resource";
|
|
59958
59958
|
event: "event";
|
|
59959
59959
|
article: "article";
|
|
59960
59960
|
}>;
|
|
@@ -61874,9 +61874,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
61874
61874
|
latestReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
61875
61875
|
id: z.ZodString;
|
|
61876
61876
|
type: z.ZodEnum<{
|
|
61877
|
-
resource: "resource";
|
|
61878
61877
|
note: "note";
|
|
61879
61878
|
question: "question";
|
|
61879
|
+
resource: "resource";
|
|
61880
61880
|
event: "event";
|
|
61881
61881
|
article: "article";
|
|
61882
61882
|
}>;
|
|
@@ -63565,9 +63565,9 @@ export declare const adminProfileSummarySchema: z.ZodObject<{
|
|
|
63565
63565
|
replyTo: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
63566
63566
|
id: z.ZodString;
|
|
63567
63567
|
type: z.ZodEnum<{
|
|
63568
|
-
resource: "resource";
|
|
63569
63568
|
note: "note";
|
|
63570
63569
|
question: "question";
|
|
63570
|
+
resource: "resource";
|
|
63571
63571
|
event: "event";
|
|
63572
63572
|
article: "article";
|
|
63573
63573
|
}>;
|
package/package.json
CHANGED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visible-text measurement for the post content budget.
|
|
3
|
+
*
|
|
4
|
+
* Counts what a reader sees, not the raw markdown source:
|
|
5
|
+
* - fenced code counts its content verbatim (it renders as visible code)
|
|
6
|
+
* - links and images count their text/alt, not the URL
|
|
7
|
+
* - structural line syntax (table cells/pipes, list markers, setext
|
|
8
|
+
* underlines, thematic breaks, headings, blockquotes) and HTML tags
|
|
9
|
+
* render no characters and do not count
|
|
10
|
+
* - whitespace runs collapse and line edges trim, so the count tracks
|
|
11
|
+
* what renders
|
|
12
|
+
*
|
|
13
|
+
* This is a budget estimate, not a markdown parser: unbounded content is
|
|
14
|
+
* guarded by the raw-length cap (`POST_MAX_RAW_LENGTH`), not by this
|
|
15
|
+
* function.
|
|
16
|
+
*/
|
|
17
|
+
const FENCE_RE = /^[ \t]*```[^\n]*\n?([\s\S]*?)^[ \t]*```[ \t]*$/gm;
|
|
18
|
+
|
|
19
|
+
// Built from a string, not a regex literal: ESLint's no-control-regex
|
|
20
|
+
// rejects control characters in regex sources. U+FFFE is a noncharacter
|
|
21
|
+
// no renderer emits, and stray occurrences are stripped from the content
|
|
22
|
+
// before fencing, so it cannot collide with real input.
|
|
23
|
+
const FENCE_SENTINEL_RE = () => new RegExp('\\uFFFE(\\d+)\\uFFFE', 'g');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A line that renders nothing: table delimiter rows (`| --- | --- |`),
|
|
27
|
+
* setext underlines (`---`, `===`), and thematic breaks (`---`, `***`,
|
|
28
|
+
* `___`). The character class mirrors their allowed symbols; `-` is last
|
|
29
|
+
* so it cannot form a range.
|
|
30
|
+
*/
|
|
31
|
+
const INVISIBLE_LINE_RE = /^[ \t]*\|?[ \t]*[-=*_][ \t:|=*_-]*\|?[ \t]*$/;
|
|
32
|
+
|
|
33
|
+
export const visibleTextLength = (markdown?: string | null): number => {
|
|
34
|
+
if (!markdown) return 0;
|
|
35
|
+
// Stray sentinels in user content must not collide with the fence
|
|
36
|
+
// sentinel (U+FFFE is a noncharacter no renderer emits).
|
|
37
|
+
let text = markdown
|
|
38
|
+
.replace(/\r\n?/g, '\n')
|
|
39
|
+
.replaceAll('\uFFFE', '')
|
|
40
|
+
.replaceAll('\u0000', '');
|
|
41
|
+
// Fenced code renders verbatim, so hold its content aside while the
|
|
42
|
+
// line-structural passes run on the surrounding text.
|
|
43
|
+
const fenced: string[] = [];
|
|
44
|
+
text = text.replace(FENCE_RE, (_match, content: string) => {
|
|
45
|
+
fenced.push(content);
|
|
46
|
+
return `\uFFFE${fenced.length - 1}\uFFFE`;
|
|
47
|
+
});
|
|
48
|
+
// Inline code counts its content, not the backticks.
|
|
49
|
+
text = text.replace(/`([^`]+)`/g, '$1');
|
|
50
|
+
// Autolinks: the URL is the visible text.
|
|
51
|
+
text = text.replace(/<(https?:\/\/[^>\s]+|mailto:[^>\s]+)>/gi, '$1');
|
|
52
|
+
// Images: count the alt text, drop the marker and URL.
|
|
53
|
+
text = text.replace(/!\[([^\]]*)\]\(((?:[^()]+|\([^()]*\))*)\)/g, '$1');
|
|
54
|
+
// Links: count the text, drop the URL (one level of nested parens ok).
|
|
55
|
+
text = text.replace(/\[([^\]]+)\]\(((?:[^()]+|\([^()]*\))*)\)/g, '$1');
|
|
56
|
+
// Reference-style links: count the text, drop the reference.
|
|
57
|
+
text = text.replace(/\[([^\]]+)\]\[[^\]]*\]/g, '$1');
|
|
58
|
+
// HTML tags: drop the tags, keep the inner text.
|
|
59
|
+
text = text.replace(/<\/?[a-zA-Z][^>]*>/g, '');
|
|
60
|
+
text = text
|
|
61
|
+
.split('\n')
|
|
62
|
+
.map((line) => {
|
|
63
|
+
if (INVISIBLE_LINE_RE.test(line)) return '';
|
|
64
|
+
return (
|
|
65
|
+
line
|
|
66
|
+
// Heading and blockquote markers.
|
|
67
|
+
.replace(/^[ \t]*(?:#{1,6}|>)[ \t]*/, '')
|
|
68
|
+
// List markers ("-", "*", "+", "1.", "1)").
|
|
69
|
+
.replace(/^[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]+/, '')
|
|
70
|
+
// Table cells: the pipes and their padding are syntax.
|
|
71
|
+
.replace(/^[ \t]*\|/, '')
|
|
72
|
+
.replace(/\|[ \t]*$/, '')
|
|
73
|
+
.replace(/\|/g, ' ')
|
|
74
|
+
.replace(/^[ \t]+|[\t ]+$/g, '')
|
|
75
|
+
);
|
|
76
|
+
})
|
|
77
|
+
.filter((line) => line.length > 0)
|
|
78
|
+
.join('\n');
|
|
79
|
+
// Emphasis/strikethrough markers. `_` inside a word (snake_case) is kept.
|
|
80
|
+
text = text.replace(/[*~]{1,3}/g, '');
|
|
81
|
+
text = text.replace(/(^|\s)_{1,3}(\S)/gm, '$1$2');
|
|
82
|
+
text = text.replace(/(\S)_{1,3}(\s|$)/gm, '$1$2');
|
|
83
|
+
// Whitespace runs collapse to single spaces (the renderer collapses
|
|
84
|
+
// them), so the count tracks what renders.
|
|
85
|
+
text = text.replace(/[\t ]{2,}/g, ' ');
|
|
86
|
+
// Restore the fenced code content verbatim.
|
|
87
|
+
text = text.replace(FENCE_SENTINEL_RE(), (_match, index: string) => {
|
|
88
|
+
return fenced[Number(index)] ?? '';
|
|
89
|
+
});
|
|
90
|
+
// Count code points so emoji and other astral characters cost what they
|
|
91
|
+
// render, not their UTF-16 surrogate pair.
|
|
92
|
+
return [...text].length;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** Visible-text budget for note/question content. */
|
|
96
|
+
export const POST_MAX_VISIBLE_LENGTH = 500;
|
|
97
|
+
/** Raw markdown backstop for note/question content. */
|
|
98
|
+
export const POST_MAX_RAW_LENGTH = 5000;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whitespace-only content is measured as empty (nothing renders), so the
|
|
102
|
+
* same "is there anything to send" test must ignore whitespace everywhere
|
|
103
|
+
* a composer or schema checks it.
|
|
104
|
+
*/
|
|
105
|
+
export const hasVisibleText = (content?: string | null): boolean =>
|
|
106
|
+
visibleTextLength(content) > 0;
|
|
107
|
+
|
|
108
|
+
/** True when note/question content fits the visible + raw budgets. */
|
|
109
|
+
export const postContentWithinBudget = (content?: string | null): boolean => {
|
|
110
|
+
const raw = content ?? '';
|
|
111
|
+
return (
|
|
112
|
+
visibleTextLength(raw) <= POST_MAX_VISIBLE_LENGTH &&
|
|
113
|
+
raw.length <= POST_MAX_RAW_LENGTH
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Shared composer submit gate over the visible budget. Question composers
|
|
119
|
+
* need visible text for their poll to make sense; note composers accept an
|
|
120
|
+
* attachment instead. In-flight state (submitting, pending uploads,
|
|
121
|
+
* audience/group requirements) stays at the call site.
|
|
122
|
+
*/
|
|
123
|
+
export const canSubmitPostContent = ({
|
|
124
|
+
visibleContentLength,
|
|
125
|
+
attachmentsLength,
|
|
126
|
+
composerType,
|
|
127
|
+
pollOptionsValid = true,
|
|
128
|
+
}: {
|
|
129
|
+
visibleContentLength: number;
|
|
130
|
+
attachmentsLength: number;
|
|
131
|
+
composerType?: 'note' | 'question';
|
|
132
|
+
pollOptionsValid?: boolean;
|
|
133
|
+
}): boolean =>
|
|
134
|
+
composerType === 'question'
|
|
135
|
+
? visibleContentLength > 0 &&
|
|
136
|
+
visibleContentLength <= POST_MAX_VISIBLE_LENGTH &&
|
|
137
|
+
pollOptionsValid
|
|
138
|
+
: visibleContentLength <= POST_MAX_VISIBLE_LENGTH &&
|
|
139
|
+
(visibleContentLength > 0 || attachmentsLength > 0);
|
package/src/lib/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './groupHelpers';
|
|
|
11
11
|
export * from './groupTemplateHelpers';
|
|
12
12
|
export * from './colors';
|
|
13
13
|
export * from './markdownHelpers';
|
|
14
|
+
export * from './contentLength';
|
|
14
15
|
export * from './attachmentHelpers';
|
|
15
16
|
export * from './resources';
|
|
16
17
|
export * from './eventIcs';
|
package/src/lib/postHelpers.ts
CHANGED
|
@@ -813,7 +813,11 @@ export const getPostActionAvailability = (
|
|
|
813
813
|
export const HIDDEN_AUTHOR_HANDLE = 'hidden';
|
|
814
814
|
|
|
815
815
|
export const toHiddenPost = <
|
|
816
|
-
T extends {
|
|
816
|
+
T extends {
|
|
817
|
+
data: PostDataUnion;
|
|
818
|
+
profile: PublicProfile;
|
|
819
|
+
entries?: EntryWithPublicProfile[];
|
|
820
|
+
},
|
|
817
821
|
>(
|
|
818
822
|
post: T,
|
|
819
823
|
): T & { hidden: true } =>
|
|
@@ -824,6 +828,13 @@ export const toHiddenPost = <
|
|
|
824
828
|
...post.data,
|
|
825
829
|
...('content' in post.data ? { content: '' } : {}),
|
|
826
830
|
},
|
|
831
|
+
// create/edit entries each carry a full content snapshot; dropping them
|
|
832
|
+
// keeps the redacted text out of the hidden post's serialized payload.
|
|
833
|
+
entries: post.entries
|
|
834
|
+
? post.entries.filter(
|
|
835
|
+
(entry) => entry.type !== 'create' && entry.type !== 'edit',
|
|
836
|
+
)
|
|
837
|
+
: post.entries,
|
|
827
838
|
profile: {
|
|
828
839
|
...post.profile,
|
|
829
840
|
displayName: undefined,
|
|
@@ -874,6 +885,85 @@ export const isConversationLeavePost = (
|
|
|
874
885
|
return !post.audience?.some((p) => p.id === authorId);
|
|
875
886
|
};
|
|
876
887
|
|
|
888
|
+
export type PostVersionOrder = 'oldest' | 'newest';
|
|
889
|
+
|
|
890
|
+
export type PostEditVersion = {
|
|
891
|
+
id: string;
|
|
892
|
+
createdAt: string;
|
|
893
|
+
data: PostDataUnion;
|
|
894
|
+
/** Author snapshot of the entry that produced this version. */
|
|
895
|
+
profile: EntryWithPublicProfile['profile'];
|
|
896
|
+
/** Create entry is the original text. Each edit entry is that save's text. */
|
|
897
|
+
kind: 'original' | 'edit';
|
|
898
|
+
current: boolean;
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
type SnapshotEntry = Extract<
|
|
902
|
+
EntryWithPublicProfile,
|
|
903
|
+
{ type: 'create' | 'edit' }
|
|
904
|
+
>;
|
|
905
|
+
|
|
906
|
+
const isSnapshotEntry = (
|
|
907
|
+
entry: EntryWithPublicProfile,
|
|
908
|
+
): entry is SnapshotEntry => entry.type === 'create' || entry.type === 'edit';
|
|
909
|
+
|
|
910
|
+
/** True when at least one edit has been saved for this post. */
|
|
911
|
+
export const postHasEditHistory = (
|
|
912
|
+
entries: readonly EntryWithPublicProfile[] | undefined,
|
|
913
|
+
): boolean => !!entries?.some((entry) => entry.type === 'edit');
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Saved versions of a post. The create entry is the original; each edit entry
|
|
917
|
+
* stores the content written at that save. Oldest first unless `order` is newest.
|
|
918
|
+
* Returns nothing until the post has been edited.
|
|
919
|
+
*/
|
|
920
|
+
export const postEditVersions = (
|
|
921
|
+
entries: readonly EntryWithPublicProfile[] | undefined,
|
|
922
|
+
order: PostVersionOrder = 'oldest',
|
|
923
|
+
): PostEditVersion[] => {
|
|
924
|
+
if (!postHasEditHistory(entries)) return [];
|
|
925
|
+
|
|
926
|
+
const chronological = (entries ?? [])
|
|
927
|
+
.map((entry, index) => ({ entry, index }))
|
|
928
|
+
.filter((item): item is { entry: SnapshotEntry; index: number } =>
|
|
929
|
+
isSnapshotEntry(item.entry),
|
|
930
|
+
)
|
|
931
|
+
.sort(
|
|
932
|
+
(a, b) =>
|
|
933
|
+
Date.parse(a.entry.createdAt) - Date.parse(b.entry.createdAt) ||
|
|
934
|
+
a.index - b.index,
|
|
935
|
+
);
|
|
936
|
+
|
|
937
|
+
const last = chronological.length - 1;
|
|
938
|
+
const versions = chronological.map(
|
|
939
|
+
({ entry, index }, position): PostEditVersion => ({
|
|
940
|
+
id: `${entry.type}-${entry.createdAt}-${index}`,
|
|
941
|
+
createdAt: entry.createdAt,
|
|
942
|
+
data: entry.data,
|
|
943
|
+
profile: entry.profile,
|
|
944
|
+
kind: entry.type === 'create' ? 'original' : 'edit',
|
|
945
|
+
current: position === last,
|
|
946
|
+
}),
|
|
947
|
+
);
|
|
948
|
+
|
|
949
|
+
return order === 'newest' ? [...versions].reverse() : versions;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
export const postEditVersionKind = (
|
|
953
|
+
version: Pick<PostEditVersion, 'current' | 'kind'>,
|
|
954
|
+
): 'original' | 'edit' | 'current' =>
|
|
955
|
+
version.current ? 'current' : version.kind;
|
|
956
|
+
|
|
957
|
+
export const postEditVersionTitle = (
|
|
958
|
+
data: PostDataUnion,
|
|
959
|
+
): string | undefined => {
|
|
960
|
+
if (data.type === 'article' || data.type === 'resource') {
|
|
961
|
+
return data.title || undefined;
|
|
962
|
+
}
|
|
963
|
+
if (data.type === 'event') return data.name || undefined;
|
|
964
|
+
return undefined;
|
|
965
|
+
};
|
|
966
|
+
|
|
877
967
|
export const isOneToOneWithBlocked = (
|
|
878
968
|
post: Pick<PublicPost, 'visibility' | 'audience' | 'profile'> & {
|
|
879
969
|
creatorId?: string;
|
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,
|
|
@@ -799,7 +800,7 @@ export type DirectMessageSearchHit = z.infer<
|
|
|
799
800
|
export const postCreationDataSchema = z.object({
|
|
800
801
|
visibility: visibilityTypeSchema,
|
|
801
802
|
type: postTypeSchema,
|
|
802
|
-
data:
|
|
803
|
+
data: postDataInputUnionSchema,
|
|
803
804
|
inReplyToId: z.uuid().nullable().optional(),
|
|
804
805
|
mentions: mentionWithPublicProfileSchema.array().nullable().optional(),
|
|
805
806
|
audience: publicProfileSchema.array().nullable().optional(),
|