@atcute/bluesky 2.0.3 → 2.1.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.
@@ -0,0 +1,2 @@
1
+ import './lexicons.js';
2
+ export * from './utilities/embeds.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import './lexicons.js';
2
+ export * from './utilities/embeds.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import type { AppBskyEmbedRecordWithMedia, AppBskyFeedDefs, AppBskyFeedPost } from '@atcute/client/lexicons';
2
+ export interface RawEmbeds {
3
+ media?: AppBskyEmbedRecordWithMedia.Main['media'];
4
+ record?: AppBskyEmbedRecordWithMedia.Main['record'];
5
+ }
6
+ export type RawMediaEmbed = NonNullable<RawEmbeds['media']>;
7
+ export type RawRecordEmbed = NonNullable<RawEmbeds['record']>;
8
+ /**
9
+ * extracts raw media embed from a post record embed
10
+ * @param embed the embed interface to extract from
11
+ * @returns the extracted raw media embed, if any
12
+ */
13
+ export declare const unwrapRawMediaEmbed: (embed: AppBskyFeedPost.Record["embed"]) => RawEmbeds["media"];
14
+ /**
15
+ * extracts raw record embed from a post record embed
16
+ * @param embed the embed interface to extract from
17
+ * @returns the extracted raw record embed, if any
18
+ */
19
+ export declare const unwrapRawRecordEmbed: (embed: AppBskyFeedPost.Record["embed"]) => RawEmbeds["record"];
20
+ /**
21
+ * extracts raw media and record embeds from a post record embed
22
+ * @param embed the embed interface to extract from
23
+ * @returns the extracted raw media and record embeds, if any
24
+ */
25
+ export declare const unwrapRawEmbed: (embed: AppBskyFeedPost.Record["embed"]) => RawEmbeds;
26
+ export interface Embeds {
27
+ media?: AppBskyEmbedRecordWithMedia.View['media'];
28
+ record?: AppBskyEmbedRecordWithMedia.View['record']['record'];
29
+ }
30
+ export type MediaEmbed = NonNullable<Embeds['media']>;
31
+ export type RecordEmbed = NonNullable<Embeds['record']>;
32
+ /**
33
+ * extracts media embed from a post embed
34
+ * @param embed the embed interface to extract from
35
+ * @returns the extracted media embed, if any
36
+ */
37
+ export declare const unwrapMediaEmbed: (embed: AppBskyFeedDefs.PostView["embed"]) => Embeds["media"];
38
+ /**
39
+ * extracts record embed from a post embed
40
+ * @param embed the embed interface to extract from
41
+ * @returns the extracted record embed, if any
42
+ */
43
+ export declare const unwrapRecordEmbed: (embed: AppBskyFeedDefs.PostView["embed"]) => Embeds["record"];
44
+ /**
45
+ * extracts media and record embeds from a post embed
46
+ * @param embed the embed interface to extract from
47
+ * @returns the extracted media and record embeds, if any
48
+ */
49
+ export declare const unwrapEmbed: (embed: AppBskyFeedDefs.PostView["embed"]) => Embeds;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * extracts raw media embed from a post record embed
3
+ * @param embed the embed interface to extract from
4
+ * @returns the extracted raw media embed, if any
5
+ */
6
+ export const unwrapRawMediaEmbed = (embed) => {
7
+ switch (embed?.$type) {
8
+ case 'app.bsky.embed.recordWithMedia':
9
+ return embed.media;
10
+ case 'app.bsky.embed.record':
11
+ return;
12
+ }
13
+ return embed;
14
+ };
15
+ /**
16
+ * extracts raw record embed from a post record embed
17
+ * @param embed the embed interface to extract from
18
+ * @returns the extracted raw record embed, if any
19
+ */
20
+ export const unwrapRawRecordEmbed = (embed) => {
21
+ switch (embed?.$type) {
22
+ case 'app.bsky.embed.recordWithMedia':
23
+ return embed.record;
24
+ case 'app.bsky.embed.record':
25
+ return embed;
26
+ }
27
+ };
28
+ /**
29
+ * extracts raw media and record embeds from a post record embed
30
+ * @param embed the embed interface to extract from
31
+ * @returns the extracted raw media and record embeds, if any
32
+ */
33
+ export const unwrapRawEmbed = (embed) => {
34
+ return {
35
+ media: unwrapRawMediaEmbed(embed),
36
+ record: unwrapRawRecordEmbed(embed),
37
+ };
38
+ };
39
+ /**
40
+ * extracts media embed from a post embed
41
+ * @param embed the embed interface to extract from
42
+ * @returns the extracted media embed, if any
43
+ */
44
+ export const unwrapMediaEmbed = (embed) => {
45
+ switch (embed?.$type) {
46
+ case 'app.bsky.embed.recordWithMedia#view':
47
+ return embed.media;
48
+ case 'app.bsky.embed.record#view':
49
+ return;
50
+ }
51
+ return embed;
52
+ };
53
+ /**
54
+ * extracts record embed from a post embed
55
+ * @param embed the embed interface to extract from
56
+ * @returns the extracted record embed, if any
57
+ */
58
+ export const unwrapRecordEmbed = (embed) => {
59
+ switch (embed?.$type) {
60
+ case 'app.bsky.embed.recordWithMedia#view':
61
+ return embed.record.record;
62
+ case 'app.bsky.embed.record#view':
63
+ return embed.record;
64
+ }
65
+ };
66
+ /**
67
+ * extracts media and record embeds from a post embed
68
+ * @param embed the embed interface to extract from
69
+ * @returns the extracted media and record embeds, if any
70
+ */
71
+ export const unwrapEmbed = (embed) => {
72
+ return {
73
+ media: unwrapMediaEmbed(embed),
74
+ record: unwrapRecordEmbed(embed),
75
+ };
76
+ };
77
+ //# sourceMappingURL=embeds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embeds.js","sourceRoot":"","sources":["../../lib/utilities/embeds.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAsC,EAAsB,EAAE;IACjG,QAAQ,KAAK,EAAE,KAAK,EAAE,CAAC;QACtB,KAAK,gCAAgC;YACpC,OAAO,KAAK,CAAC,KAAK,CAAC;QACpB,KAAK,uBAAuB;YAC3B,OAAO;IACT,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAsC,EAAuB,EAAE;IACnG,QAAQ,KAAK,EAAE,KAAK,EAAE,CAAC;QACtB,KAAK,gCAAgC;YACpC,OAAO,KAAK,CAAC,MAAM,CAAC;QAErB,KAAK,uBAAuB;YAC3B,OAAO,KAAK,CAAC;IACf,CAAC;AACF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAsC,EAAa,EAAE;IACnF,OAAO;QACN,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;QACjC,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC;KACnC,CAAC;AACH,CAAC,CAAC;AAUF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAwC,EAAmB,EAAE;IAC7F,QAAQ,KAAK,EAAE,KAAK,EAAE,CAAC;QACtB,KAAK,qCAAqC;YACzC,OAAO,KAAK,CAAC,KAAK,CAAC;QACpB,KAAK,4BAA4B;YAChC,OAAO;IACT,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAwC,EAAoB,EAAE;IAC/F,QAAQ,KAAK,EAAE,KAAK,EAAE,CAAC;QACtB,KAAK,qCAAqC;YACzC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAE5B,KAAK,4BAA4B;YAChC,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;AACF,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAwC,EAAU,EAAE;IAC/E,OAAO;QACN,KAAK,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC9B,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC;KAChC,CAAC;AACH,CAAC,CAAC"}
package/lib/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import './lexicons.js';
2
+
3
+ export * from './utilities/embeds.js';
@@ -0,0 +1,103 @@
1
+ import type { AppBskyEmbedRecordWithMedia, AppBskyFeedDefs, AppBskyFeedPost } from '@atcute/client/lexicons';
2
+
3
+ export interface RawEmbeds {
4
+ media?: AppBskyEmbedRecordWithMedia.Main['media'];
5
+ record?: AppBskyEmbedRecordWithMedia.Main['record'];
6
+ }
7
+
8
+ export type RawMediaEmbed = NonNullable<RawEmbeds['media']>;
9
+ export type RawRecordEmbed = NonNullable<RawEmbeds['record']>;
10
+
11
+ /**
12
+ * extracts raw media embed from a post record embed
13
+ * @param embed the embed interface to extract from
14
+ * @returns the extracted raw media embed, if any
15
+ */
16
+ export const unwrapRawMediaEmbed = (embed: AppBskyFeedPost.Record['embed']): RawEmbeds['media'] => {
17
+ switch (embed?.$type) {
18
+ case 'app.bsky.embed.recordWithMedia':
19
+ return embed.media;
20
+ case 'app.bsky.embed.record':
21
+ return;
22
+ }
23
+
24
+ return embed;
25
+ };
26
+
27
+ /**
28
+ * extracts raw record embed from a post record embed
29
+ * @param embed the embed interface to extract from
30
+ * @returns the extracted raw record embed, if any
31
+ */
32
+ export const unwrapRawRecordEmbed = (embed: AppBskyFeedPost.Record['embed']): RawEmbeds['record'] => {
33
+ switch (embed?.$type) {
34
+ case 'app.bsky.embed.recordWithMedia':
35
+ return embed.record;
36
+
37
+ case 'app.bsky.embed.record':
38
+ return embed;
39
+ }
40
+ };
41
+
42
+ /**
43
+ * extracts raw media and record embeds from a post record embed
44
+ * @param embed the embed interface to extract from
45
+ * @returns the extracted raw media and record embeds, if any
46
+ */
47
+ export const unwrapRawEmbed = (embed: AppBskyFeedPost.Record['embed']): RawEmbeds => {
48
+ return {
49
+ media: unwrapRawMediaEmbed(embed),
50
+ record: unwrapRawRecordEmbed(embed),
51
+ };
52
+ };
53
+
54
+ export interface Embeds {
55
+ media?: AppBskyEmbedRecordWithMedia.View['media'];
56
+ record?: AppBskyEmbedRecordWithMedia.View['record']['record'];
57
+ }
58
+
59
+ export type MediaEmbed = NonNullable<Embeds['media']>;
60
+ export type RecordEmbed = NonNullable<Embeds['record']>;
61
+
62
+ /**
63
+ * extracts media embed from a post embed
64
+ * @param embed the embed interface to extract from
65
+ * @returns the extracted media embed, if any
66
+ */
67
+ export const unwrapMediaEmbed = (embed: AppBskyFeedDefs.PostView['embed']): Embeds['media'] => {
68
+ switch (embed?.$type) {
69
+ case 'app.bsky.embed.recordWithMedia#view':
70
+ return embed.media;
71
+ case 'app.bsky.embed.record#view':
72
+ return;
73
+ }
74
+
75
+ return embed;
76
+ };
77
+
78
+ /**
79
+ * extracts record embed from a post embed
80
+ * @param embed the embed interface to extract from
81
+ * @returns the extracted record embed, if any
82
+ */
83
+ export const unwrapRecordEmbed = (embed: AppBskyFeedDefs.PostView['embed']): Embeds['record'] => {
84
+ switch (embed?.$type) {
85
+ case 'app.bsky.embed.recordWithMedia#view':
86
+ return embed.record.record;
87
+
88
+ case 'app.bsky.embed.record#view':
89
+ return embed.record;
90
+ }
91
+ };
92
+
93
+ /**
94
+ * extracts media and record embeds from a post embed
95
+ * @param embed the embed interface to extract from
96
+ * @returns the extracted media and record embeds, if any
97
+ */
98
+ export const unwrapEmbed = (embed: AppBskyFeedDefs.PostView['embed']): Embeds => {
99
+ return {
100
+ media: unwrapMediaEmbed(embed),
101
+ record: unwrapRecordEmbed(embed),
102
+ };
103
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@atcute/bluesky",
4
- "version": "2.0.3",
4
+ "version": "2.1.0",
5
5
  "description": "Bluesky type definitions for atcute",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -15,6 +15,7 @@
15
15
  "!lib/**/*.test.ts"
16
16
  ],
17
17
  "exports": {
18
+ ".": "./dist/index.js",
18
19
  "./lexicons": "./dist/lexicons.js"
19
20
  },
20
21
  "peerDependencies": {