@atproto/api 0.6.17 → 0.6.19

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/client/index.d.ts +10 -3
  3. package/dist/client/lexicons.d.ts +203 -14
  4. package/dist/client/types/app/bsky/actor/searchActors.d.ts +1 -0
  5. package/dist/client/types/app/bsky/actor/searchActorsTypeahead.d.ts +1 -0
  6. package/dist/client/types/app/bsky/feed/searchPosts.d.ts +26 -0
  7. package/dist/client/types/app/bsky/unspecced/defs.d.ts +13 -0
  8. package/dist/client/types/app/bsky/unspecced/searchActorsSkeleton.d.ts +27 -0
  9. package/dist/client/types/app/bsky/unspecced/searchPostsSkeleton.d.ts +26 -0
  10. package/dist/client/types/com/atproto/admin/searchRepos.d.ts +1 -0
  11. package/dist/index.js +395 -90
  12. package/dist/index.js.map +3 -3
  13. package/dist/rich-text/rich-text.d.ts +3 -0
  14. package/package.json +2 -2
  15. package/src/client/index.ts +41 -13
  16. package/src/client/lexicons.ts +229 -23
  17. package/src/client/types/app/bsky/actor/searchActors.ts +3 -0
  18. package/src/client/types/app/bsky/actor/searchActorsTypeahead.ts +3 -0
  19. package/src/client/types/app/bsky/feed/searchPosts.ts +50 -0
  20. package/src/client/types/app/bsky/unspecced/defs.ts +41 -0
  21. package/src/client/types/app/bsky/unspecced/searchActorsSkeleton.ts +52 -0
  22. package/src/client/types/app/bsky/unspecced/searchPostsSkeleton.ts +50 -0
  23. package/src/client/types/com/atproto/admin/searchRepos.ts +2 -0
  24. package/src/rich-text/detection.ts +27 -0
  25. package/src/rich-text/rich-text.ts +13 -0
  26. package/tests/rich-text-detection.test.ts +104 -0
  27. package/dist/client/types/app/bsky/unspecced/applyLabels.d.ts +0 -18
  28. package/src/client/types/app/bsky/unspecced/applyLabels.ts +0 -33
@@ -9,7 +9,9 @@ import { CID } from 'multiformats/cid'
9
9
  import * as ComAtprotoAdminDefs from './defs'
10
10
 
11
11
  export interface QueryParams {
12
+ /** DEPRECATED: use 'q' instead */
12
13
  term?: string
14
+ q?: string
13
15
  invitedBy?: string
14
16
  limit?: number
15
17
  cursor?: string
@@ -69,6 +69,33 @@ export function detectFacets(text: UnicodeString): Facet[] | undefined {
69
69
  })
70
70
  }
71
71
  }
72
+ {
73
+ const re = /(?:^|\s)(#[^\d\s]\S*)(?=\s)?/g
74
+ while ((match = re.exec(text.utf16))) {
75
+ let [tag] = match
76
+ const hasLeadingSpace = /^\s/.test(tag)
77
+
78
+ tag = tag.trim().replace(/\p{P}+$/gu, '') // strip ending punctuation
79
+
80
+ // inclusive of #, max of 64 chars
81
+ if (tag.length > 66) continue
82
+
83
+ const index = match.index + (hasLeadingSpace ? 1 : 0)
84
+
85
+ facets.push({
86
+ index: {
87
+ byteStart: text.utf16IndexToUtf8Index(index),
88
+ byteEnd: text.utf16IndexToUtf8Index(index + tag.length), // inclusive of last char
89
+ },
90
+ features: [
91
+ {
92
+ $type: 'app.bsky.richtext.facet#tag',
93
+ tag: tag.replace(/^#/, ''),
94
+ },
95
+ ],
96
+ })
97
+ }
98
+ }
72
99
  return facets.length > 0 ? facets : undefined
73
100
  }
74
101
 
@@ -100,6 +100,7 @@ import { detectFacets } from './detection'
100
100
  export type Facet = AppBskyRichtextFacet.Main
101
101
  export type FacetLink = AppBskyRichtextFacet.Link
102
102
  export type FacetMention = AppBskyRichtextFacet.Mention
103
+ export type FacetTag = AppBskyRichtextFacet.Tag
103
104
  export type Entity = AppBskyFeedPost.Entity
104
105
 
105
106
  export interface RichTextProps {
@@ -141,6 +142,18 @@ export class RichTextSegment {
141
142
  isMention() {
142
143
  return !!this.mention
143
144
  }
145
+
146
+ get tag(): FacetTag | undefined {
147
+ const tag = this.facet?.features.find(AppBskyRichtextFacet.isTag)
148
+ if (AppBskyRichtextFacet.isTag(tag)) {
149
+ return tag
150
+ }
151
+ return undefined
152
+ }
153
+
154
+ isTag() {
155
+ return !!this.tag
156
+ }
144
157
  }
145
158
 
146
159
  export class RichText {
@@ -1,4 +1,5 @@
1
1
  import { AtpAgent, RichText, RichTextSegment } from '../src'
2
+ import { isTag } from '../src/client/types/app/bsky/richtext/facet'
2
3
 
3
4
  describe('detectFacets', () => {
4
5
  const agent = new AtpAgent({ service: 'http://localhost' })
@@ -208,6 +209,109 @@ describe('detectFacets', () => {
208
209
  expect(Array.from(rt.segments(), segmentToOutput)).toEqual(outputs[i])
209
210
  }
210
211
  })
212
+
213
+ it('correctly detects tags inline', async () => {
214
+ const inputs: [
215
+ string,
216
+ string[],
217
+ { byteStart: number; byteEnd: number }[],
218
+ ][] = [
219
+ ['#a', ['a'], [{ byteStart: 0, byteEnd: 2 }]],
220
+ [
221
+ '#a #b',
222
+ ['a', 'b'],
223
+ [
224
+ { byteStart: 0, byteEnd: 2 },
225
+ { byteStart: 3, byteEnd: 5 },
226
+ ],
227
+ ],
228
+ ['#1', [], []],
229
+ ['#tag', ['tag'], [{ byteStart: 0, byteEnd: 4 }]],
230
+ ['body #tag', ['tag'], [{ byteStart: 5, byteEnd: 9 }]],
231
+ ['#tag body', ['tag'], [{ byteStart: 0, byteEnd: 4 }]],
232
+ ['body #tag body', ['tag'], [{ byteStart: 5, byteEnd: 9 }]],
233
+ ['body #1', [], []],
234
+ ['body #a1', ['a1'], [{ byteStart: 5, byteEnd: 8 }]],
235
+ ['#', [], []],
236
+ ['text #', [], []],
237
+ ['text # text', [], []],
238
+ [
239
+ 'body #thisisa64characterstring_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
240
+ ['thisisa64characterstring_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'],
241
+ [{ byteStart: 5, byteEnd: 71 }],
242
+ ],
243
+ [
244
+ 'body #thisisa65characterstring_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab',
245
+ [],
246
+ [],
247
+ ],
248
+ [
249
+ 'its a #double#rainbow',
250
+ ['double#rainbow'],
251
+ [{ byteStart: 6, byteEnd: 21 }],
252
+ ],
253
+ ['##hashash', ['#hashash'], [{ byteStart: 0, byteEnd: 9 }]],
254
+ ['some #n0n3s@n5e!', ['n0n3s@n5e'], [{ byteStart: 5, byteEnd: 15 }]],
255
+ [
256
+ 'works #with,punctuation',
257
+ ['with,punctuation'],
258
+ [{ byteStart: 6, byteEnd: 23 }],
259
+ ],
260
+ [
261
+ 'strips trailing #punctuation, #like. #this!',
262
+ ['punctuation', 'like', 'this'],
263
+ [
264
+ { byteStart: 16, byteEnd: 28 },
265
+ { byteStart: 30, byteEnd: 35 },
266
+ { byteStart: 37, byteEnd: 42 },
267
+ ],
268
+ ],
269
+ [
270
+ 'strips #multi_trailing___...',
271
+ ['multi_trailing'],
272
+ [{ byteStart: 7, byteEnd: 22 }],
273
+ ],
274
+ [
275
+ 'works with #🦋 emoji, and #butter🦋fly',
276
+ ['🦋', 'butter🦋fly'],
277
+ [
278
+ { byteStart: 11, byteEnd: 16 },
279
+ { byteStart: 28, byteEnd: 42 },
280
+ ],
281
+ ],
282
+ [
283
+ '#same #same #but #diff',
284
+ ['same', 'same', 'but', 'diff'],
285
+ [
286
+ { byteStart: 0, byteEnd: 5 },
287
+ { byteStart: 6, byteEnd: 11 },
288
+ { byteStart: 12, byteEnd: 16 },
289
+ { byteStart: 17, byteEnd: 22 },
290
+ ],
291
+ ],
292
+ ]
293
+
294
+ for (const [input, tags, indices] of inputs) {
295
+ const rt = new RichText({ text: input })
296
+ await rt.detectFacets(agent)
297
+
298
+ let detectedTags: string[] = []
299
+ let detectedIndices: { byteStart: number; byteEnd: number }[] = []
300
+
301
+ for (const { facet, ...rest } of rt.segments()) {
302
+ if (!facet) continue
303
+ for (const feature of facet.features) {
304
+ if (isTag(feature)) {
305
+ detectedTags.push(feature.tag)
306
+ }
307
+ }
308
+ detectedIndices.push(facet.index)
309
+ }
310
+
311
+ expect(detectedTags).toEqual(tags)
312
+ expect(detectedIndices).toEqual(indices)
313
+ }
314
+ })
211
315
  })
212
316
 
213
317
  function segmentToOutput(segment: RichTextSegment): string[] {
@@ -1,18 +0,0 @@
1
- import { Headers } from '@atproto/xrpc';
2
- import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs';
3
- export interface QueryParams {
4
- }
5
- export interface InputSchema {
6
- labels: ComAtprotoLabelDefs.Label[];
7
- [k: string]: unknown;
8
- }
9
- export interface CallOptions {
10
- headers?: Headers;
11
- qp?: QueryParams;
12
- encoding: 'application/json';
13
- }
14
- export interface Response {
15
- success: boolean;
16
- headers: Headers;
17
- }
18
- export declare function toKnownErr(e: any): any;
@@ -1,33 +0,0 @@
1
- /**
2
- * GENERATED CODE - DO NOT MODIFY
3
- */
4
- import { Headers, XRPCError } from '@atproto/xrpc'
5
- import { ValidationResult, BlobRef } from '@atproto/lexicon'
6
- import { isObj, hasProp } from '../../../../util'
7
- import { lexicons } from '../../../../lexicons'
8
- import { CID } from 'multiformats/cid'
9
- import * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs'
10
-
11
- export interface QueryParams {}
12
-
13
- export interface InputSchema {
14
- labels: ComAtprotoLabelDefs.Label[]
15
- [k: string]: unknown
16
- }
17
-
18
- export interface CallOptions {
19
- headers?: Headers
20
- qp?: QueryParams
21
- encoding: 'application/json'
22
- }
23
-
24
- export interface Response {
25
- success: boolean
26
- headers: Headers
27
- }
28
-
29
- export function toKnownErr(e: any) {
30
- if (e instanceof XRPCError) {
31
- }
32
- return e
33
- }