@atproto/bsky 0.0.9 → 0.0.11

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 (63) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/config.d.ts +2 -0
  3. package/dist/context.d.ts +3 -0
  4. package/dist/db/index.js +55 -3
  5. package/dist/db/index.js.map +3 -3
  6. package/dist/index.js +1125 -301
  7. package/dist/index.js.map +3 -3
  8. package/dist/lexicon/index.d.ts +14 -2
  9. package/dist/lexicon/lexicons.d.ts +302 -14
  10. package/dist/lexicon/types/app/bsky/actor/searchActors.d.ts +1 -0
  11. package/dist/lexicon/types/app/bsky/actor/searchActorsTypeahead.d.ts +1 -0
  12. package/dist/lexicon/types/app/bsky/feed/searchPosts.d.ts +37 -0
  13. package/dist/lexicon/types/app/bsky/unspecced/defs.d.ts +13 -0
  14. package/dist/lexicon/types/app/bsky/unspecced/searchActorsSkeleton.d.ts +38 -0
  15. package/dist/lexicon/types/app/bsky/unspecced/searchPostsSkeleton.d.ts +37 -0
  16. package/dist/lexicon/types/com/atproto/admin/searchRepos.d.ts +1 -0
  17. package/dist/lexicon/types/com/atproto/server/confirmEmail.d.ts +27 -0
  18. package/dist/lexicon/types/com/atproto/server/createSession.d.ts +1 -0
  19. package/dist/lexicon/types/com/atproto/server/getSession.d.ts +1 -0
  20. package/dist/lexicon/types/com/atproto/server/requestEmailConfirmation.d.ts +19 -0
  21. package/dist/lexicon/types/com/atproto/server/requestEmailUpdate.d.ts +30 -0
  22. package/dist/lexicon/types/{app/bsky/unspecced/applyLabels.d.ts → com/atproto/server/updateEmail.d.ts} +3 -2
  23. package/dist/services/actor/index.d.ts +2 -2
  24. package/dist/services/util/search.d.ts +3 -3
  25. package/package.json +13 -14
  26. package/src/api/app/bsky/actor/searchActors.ts +36 -16
  27. package/src/api/app/bsky/actor/searchActorsTypeahead.ts +24 -11
  28. package/src/api/app/bsky/graph/getSuggestedFollowsByActor.ts +1 -0
  29. package/src/api/com/atproto/admin/searchRepos.ts +6 -4
  30. package/src/auto-moderator/index.ts +1 -17
  31. package/src/config.ts +7 -0
  32. package/src/context.ts +6 -0
  33. package/src/index.ts +5 -0
  34. package/src/lexicon/index.ts +84 -12
  35. package/src/lexicon/lexicons.ts +351 -23
  36. package/src/lexicon/types/app/bsky/actor/searchActors.ts +3 -0
  37. package/src/lexicon/types/app/bsky/actor/searchActorsTypeahead.ts +3 -0
  38. package/src/lexicon/types/app/bsky/feed/searchPosts.ts +54 -0
  39. package/src/lexicon/types/app/bsky/unspecced/defs.ts +41 -0
  40. package/src/lexicon/types/app/bsky/unspecced/searchActorsSkeleton.ts +56 -0
  41. package/src/lexicon/types/app/bsky/unspecced/searchPostsSkeleton.ts +54 -0
  42. package/src/lexicon/types/com/atproto/admin/searchRepos.ts +2 -0
  43. package/src/lexicon/types/{app/bsky/unspecced/applyLabels.ts → com/atproto/server/confirmEmail.ts} +3 -2
  44. package/src/lexicon/types/com/atproto/server/createSession.ts +1 -0
  45. package/src/lexicon/types/com/atproto/server/getSession.ts +1 -0
  46. package/src/lexicon/types/com/atproto/server/requestEmailConfirmation.ts +31 -0
  47. package/src/lexicon/types/com/atproto/server/requestEmailUpdate.ts +43 -0
  48. package/src/lexicon/types/com/atproto/server/updateEmail.ts +41 -0
  49. package/src/services/actor/index.ts +9 -9
  50. package/src/services/indexing/plugins/block.ts +1 -1
  51. package/src/services/indexing/plugins/feed-generator.ts +1 -1
  52. package/src/services/indexing/plugins/follow.ts +1 -1
  53. package/src/services/indexing/plugins/like.ts +1 -1
  54. package/src/services/indexing/plugins/list-block.ts +1 -1
  55. package/src/services/indexing/plugins/list-item.ts +1 -1
  56. package/src/services/indexing/plugins/list.ts +1 -1
  57. package/src/services/indexing/plugins/post.ts +1 -1
  58. package/src/services/indexing/plugins/repost.ts +1 -1
  59. package/src/services/indexing/plugins/thread-gate.ts +1 -1
  60. package/src/services/label/index.ts +1 -1
  61. package/src/services/util/search.ts +24 -23
  62. package/dist/services/indexing/util.d.ts +0 -1
  63. package/src/services/indexing/util.ts +0 -16
@@ -7,17 +7,17 @@ import { GenericKeyset, paginate } from '../../db/pagination'
7
7
  export const getUserSearchQuery = (
8
8
  db: Database,
9
9
  opts: {
10
- term: string
10
+ query: string
11
11
  limit: number
12
12
  cursor?: string
13
13
  includeSoftDeleted?: boolean
14
14
  },
15
15
  ) => {
16
16
  const { ref } = db.db.dynamic
17
- const { term, limit, cursor, includeSoftDeleted } = opts
17
+ const { query, limit, cursor, includeSoftDeleted } = opts
18
18
  // Matching user accounts based on handle
19
- const distanceAccount = distance(term, ref('handle'))
20
- let accountsQb = getMatchingAccountsQb(db, { term, includeSoftDeleted })
19
+ const distanceAccount = distance(query, ref('handle'))
20
+ let accountsQb = getMatchingAccountsQb(db, { query, includeSoftDeleted })
21
21
  accountsQb = paginate(accountsQb, {
22
22
  limit,
23
23
  cursor,
@@ -25,8 +25,8 @@ export const getUserSearchQuery = (
25
25
  keyset: new SearchKeyset(distanceAccount, ref('actor.did')),
26
26
  })
27
27
  // Matching profiles based on display name
28
- const distanceProfile = distance(term, ref('displayName'))
29
- let profilesQb = getMatchingProfilesQb(db, { term, includeSoftDeleted })
28
+ const distanceProfile = distance(query, ref('displayName'))
29
+ let profilesQb = getMatchingProfilesQb(db, { query, includeSoftDeleted })
30
30
  profilesQb = paginate(profilesQb, {
31
31
  limit,
32
32
  cursor,
@@ -46,18 +46,18 @@ export const getUserSearchQuery = (
46
46
  export const getUserSearchQuerySimple = (
47
47
  db: Database,
48
48
  opts: {
49
- term: string
49
+ query: string
50
50
  limit: number
51
51
  },
52
52
  ) => {
53
53
  const { ref } = db.db.dynamic
54
- const { term, limit } = opts
54
+ const { query, limit } = opts
55
55
  // Matching user accounts based on handle
56
- const accountsQb = getMatchingAccountsQb(db, { term })
56
+ const accountsQb = getMatchingAccountsQb(db, { query })
57
57
  .orderBy('distance', 'asc')
58
58
  .limit(limit)
59
59
  // Matching profiles based on display name
60
- const profilesQb = getMatchingProfilesQb(db, { term })
60
+ const profilesQb = getMatchingProfilesQb(db, { query })
61
61
  .orderBy('distance', 'asc')
62
62
  .limit(limit)
63
63
  // Combine and paginate result set
@@ -71,29 +71,29 @@ export const getUserSearchQuerySimple = (
71
71
  // Matching user accounts based on handle
72
72
  const getMatchingAccountsQb = (
73
73
  db: Database,
74
- opts: { term: string; includeSoftDeleted?: boolean },
74
+ opts: { query: string; includeSoftDeleted?: boolean },
75
75
  ) => {
76
76
  const { ref } = db.db.dynamic
77
- const { term, includeSoftDeleted } = opts
78
- const distanceAccount = distance(term, ref('handle'))
77
+ const { query, includeSoftDeleted } = opts
78
+ const distanceAccount = distance(query, ref('handle'))
79
79
  return db.db
80
80
  .selectFrom('actor')
81
81
  .if(!includeSoftDeleted, (qb) =>
82
82
  qb.where(notSoftDeletedClause(ref('actor'))),
83
83
  )
84
84
  .where('actor.handle', 'is not', null)
85
- .where(similar(term, ref('handle'))) // Coarse filter engaging trigram index
85
+ .where(similar(query, ref('handle'))) // Coarse filter engaging trigram index
86
86
  .select(['actor.did as did', distanceAccount.as('distance')])
87
87
  }
88
88
 
89
89
  // Matching profiles based on display name
90
90
  const getMatchingProfilesQb = (
91
91
  db: Database,
92
- opts: { term: string; includeSoftDeleted?: boolean },
92
+ opts: { query: string; includeSoftDeleted?: boolean },
93
93
  ) => {
94
94
  const { ref } = db.db.dynamic
95
- const { term, includeSoftDeleted } = opts
96
- const distanceProfile = distance(term, ref('displayName'))
95
+ const { query, includeSoftDeleted } = opts
96
+ const distanceProfile = distance(query, ref('displayName'))
97
97
  return db.db
98
98
  .selectFrom('profile')
99
99
  .innerJoin('actor', 'actor.did', 'profile.creator')
@@ -101,7 +101,7 @@ const getMatchingProfilesQb = (
101
101
  qb.where(notSoftDeletedClause(ref('actor'))),
102
102
  )
103
103
  .where('actor.handle', 'is not', null)
104
- .where(similar(term, ref('displayName'))) // Coarse filter engaging trigram index
104
+ .where(similar(query, ref('displayName'))) // Coarse filter engaging trigram index
105
105
  .select(['profile.creator as did', distanceProfile.as('distance')])
106
106
  }
107
107
 
@@ -133,15 +133,16 @@ const combineAccountsAndProfilesQb = (
133
133
  }
134
134
 
135
135
  // Remove leading @ in case a handle is input that way
136
- export const cleanTerm = (term: string) => term.trim().replace(/^@/g, '')
136
+ export const cleanQuery = (query: string) => query.trim().replace(/^@/g, '')
137
137
 
138
- // Uses pg_trgm strict word similarity to check similarity between a search term and a stored value
139
- const distance = (term: string, ref: DbRef) =>
140
- sql<number>`(${term} <<-> ${ref})`
138
+ // Uses pg_trgm strict word similarity to check similarity between a search query and a stored value
139
+ const distance = (query: string, ref: DbRef) =>
140
+ sql<number>`(${query} <<-> ${ref})`
141
141
 
142
142
  // Can utilize trigram index to match on strict word similarity.
143
143
  // The word_similarity_threshold is set to .4 (i.e. distance < .6) in db/index.ts.
144
- const similar = (term: string, ref: DbRef) => sql<boolean>`(${term} <% ${ref})`
144
+ const similar = (query: string, ref: DbRef) =>
145
+ sql<boolean>`(${query} <% ${ref})`
145
146
 
146
147
  type Result = { distance: number; did: string }
147
148
  type LabeledResult = { primary: number; secondary: string }
@@ -1 +0,0 @@
1
- export declare function toSimplifiedISOSafe(dateStr: string): string;
@@ -1,16 +0,0 @@
1
- import { isValidISODateString } from 'iso-datestring-validator'
2
-
3
- // Normalize date strings to simplified ISO so that the lexical sort preserves temporal sort.
4
- // Rather than failing on an invalid date format, returns valid unix epoch.
5
- export function toSimplifiedISOSafe(dateStr: string) {
6
- const date = new Date(dateStr)
7
- if (isNaN(date.getTime())) {
8
- return new Date(0).toISOString()
9
- }
10
- const iso = date.toISOString()
11
- if (!isValidISODateString(iso)) {
12
- // Occurs in rare cases, e.g. where resulting UTC year is negative. These also don't preserve lexical sort.
13
- return new Date(0).toISOString()
14
- }
15
- return iso // YYYY-MM-DDTHH:mm:ss.sssZ
16
- }