@atproto/ozone 0.2.4 → 0.2.5

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 (78) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/api/label/queryLabels.d.ts.map +1 -1
  3. package/dist/api/label/queryLabels.js +13 -21
  4. package/dist/api/label/queryLabels.js.map +1 -1
  5. package/dist/assignment/index.d.ts.map +1 -1
  6. package/dist/assignment/index.js +9 -12
  7. package/dist/assignment/index.js.map +1 -1
  8. package/dist/daemon/event-pusher.d.ts +7 -1
  9. package/dist/daemon/event-pusher.d.ts.map +1 -1
  10. package/dist/db/index.d.ts +4 -5
  11. package/dist/db/index.d.ts.map +1 -1
  12. package/dist/db/index.js +2 -1
  13. package/dist/db/index.js.map +1 -1
  14. package/dist/db/migrations/20241220T144630860Z-stats-materialized-views.d.ts +1 -2
  15. package/dist/db/migrations/20241220T144630860Z-stats-materialized-views.d.ts.map +1 -1
  16. package/dist/db/migrations/20241220T144630860Z-stats-materialized-views.js.map +1 -1
  17. package/dist/db/migrations/20250718T150931000Z-update-appeal-reason-stats.d.ts +1 -2
  18. package/dist/db/migrations/20250718T150931000Z-update-appeal-reason-stats.d.ts.map +1 -1
  19. package/dist/db/migrations/20250718T150931000Z-update-appeal-reason-stats.js.map +1 -1
  20. package/dist/db/migrations/provider.d.ts +2 -1
  21. package/dist/db/migrations/provider.d.ts.map +1 -1
  22. package/dist/db/migrations/provider.js.map +1 -1
  23. package/dist/db/pagination.d.ts +4 -3
  24. package/dist/db/pagination.d.ts.map +1 -1
  25. package/dist/db/pagination.js +4 -4
  26. package/dist/db/pagination.js.map +1 -1
  27. package/dist/db/types.d.ts +1 -1
  28. package/dist/db/types.d.ts.map +1 -1
  29. package/dist/db/types.js.map +1 -1
  30. package/dist/mod-service/index.d.ts.map +1 -1
  31. package/dist/mod-service/index.js +28 -52
  32. package/dist/mod-service/index.js.map +1 -1
  33. package/dist/mod-service/report.d.ts.map +1 -1
  34. package/dist/mod-service/report.js.map +1 -1
  35. package/dist/mod-service/status.d.ts +23 -128
  36. package/dist/mod-service/status.d.ts.map +1 -1
  37. package/dist/mod-service/views.js +7 -11
  38. package/dist/mod-service/views.js.map +1 -1
  39. package/dist/queue/service.js +1 -3
  40. package/dist/queue/service.js.map +1 -1
  41. package/dist/report/activity.d.ts +12 -1
  42. package/dist/report/activity.d.ts.map +1 -1
  43. package/dist/report/stats.d.ts.map +1 -1
  44. package/dist/report/stats.js.map +1 -1
  45. package/dist/scheduled-action/service.d.ts.map +1 -1
  46. package/dist/scheduled-action/service.js +16 -20
  47. package/dist/scheduled-action/service.js.map +1 -1
  48. package/dist/set/service.d.ts +10 -1
  49. package/dist/set/service.d.ts.map +1 -1
  50. package/dist/set/service.js +5 -2
  51. package/dist/set/service.js.map +1 -1
  52. package/dist/team/index.d.ts.map +1 -1
  53. package/dist/team/index.js +5 -4
  54. package/dist/team/index.js.map +1 -1
  55. package/dist/verification/issuer.d.ts +13 -3
  56. package/dist/verification/issuer.d.ts.map +1 -1
  57. package/dist/verification/service.d.ts +13 -1
  58. package/dist/verification/service.d.ts.map +1 -1
  59. package/dist/verification/service.js +1 -1
  60. package/dist/verification/service.js.map +1 -1
  61. package/package.json +7 -7
  62. package/src/api/label/queryLabels.ts +11 -14
  63. package/src/assignment/index.ts +15 -18
  64. package/src/db/index.ts +1 -1
  65. package/src/db/migrations/20241220T144630860Z-stats-materialized-views.ts +1 -2
  66. package/src/db/migrations/20250718T150931000Z-update-appeal-reason-stats.ts +1 -2
  67. package/src/db/migrations/provider.ts +2 -1
  68. package/src/db/pagination.ts +18 -18
  69. package/src/db/types.ts +3 -1
  70. package/src/mod-service/index.ts +78 -71
  71. package/src/mod-service/report.ts +5 -3
  72. package/src/mod-service/views.ts +16 -16
  73. package/src/queue/service.ts +5 -5
  74. package/src/report/stats.ts +5 -3
  75. package/src/scheduled-action/service.ts +22 -20
  76. package/src/set/service.ts +17 -14
  77. package/src/team/index.ts +6 -5
  78. package/src/verification/service.ts +2 -2
@@ -1,4 +1,4 @@
1
- import { DynamicModule, sql } from 'kysely'
1
+ import { DynamicModule, SqlBool, sql } from 'kysely'
2
2
  import { InvalidRequestError } from '@atproto/xrpc-server'
3
3
  import { AnyQb, DbRef } from './types.js'
4
4
 
@@ -66,16 +66,16 @@ export abstract class GenericKeyset<R, LR extends LabeledResult> {
66
66
  if (tryIndex) {
67
67
  // The tryIndex param will likely disappear and become the default implementation: here for now for gradual rollout query-by-query.
68
68
  if (direction === 'asc') {
69
- return sql`((${this.primary}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}))`
69
+ return sql<SqlBool>`((${this.primary}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}))`
70
70
  } else {
71
- return sql`((${this.primary}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}))`
71
+ return sql<SqlBool>`((${this.primary}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}))`
72
72
  }
73
73
  } else {
74
74
  // @NOTE this implementation can struggle to use an index on (primary, secondary) for pagination due to the "or" usage.
75
75
  if (direction === 'asc') {
76
- return sql`((${this.primary} > ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} > ${labeled.secondary}))`
76
+ return sql<SqlBool>`((${this.primary} > ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} > ${labeled.secondary}))`
77
77
  } else {
78
- return sql`((${this.primary} < ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} < ${labeled.secondary}))`
78
+ return sql<SqlBool>`((${this.primary} < ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} < ${labeled.secondary}))`
79
79
  }
80
80
  }
81
81
  }
@@ -91,7 +91,7 @@ export class StatusKeyset extends GenericKeyset<StatusKeysetParam, Cursor> {
91
91
  labelResult(result: StatusKeysetParam): Cursor
92
92
  labelResult(result: StatusKeysetParam) {
93
93
  const primaryField = (
94
- this.primary as ReturnType<DynamicModule['ref']>
94
+ this.primary as ReturnType<DynamicModule<unknown>['ref']>
95
95
  ).dynamicReference.includes('lastReviewedAt')
96
96
  ? 'lastReviewedAt'
97
97
  : 'lastReportedAt'
@@ -134,12 +134,12 @@ export class StatusKeyset extends GenericKeyset<StatusKeysetParam, Cursor> {
134
134
  if (labeled === undefined) return
135
135
  if (direction === 'asc') {
136
136
  return !labeled.primary
137
- ? sql`(${this.primary} IS NULL AND ${this.secondary} > ${labeled.secondary})`
138
- : sql`((${this.primary}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}) OR (${this.primary} is null))`
137
+ ? sql<SqlBool>`(${this.primary} IS NULL AND ${this.secondary} > ${labeled.secondary})`
138
+ : sql<SqlBool>`((${this.primary}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}) OR (${this.primary} is null))`
139
139
  } else {
140
140
  return !labeled.primary
141
- ? sql`(${this.primary} IS NULL AND ${this.secondary} < ${labeled.secondary})`
142
- : sql`((${this.primary}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}) OR (${this.primary} is null))`
141
+ ? sql<SqlBool>`(${this.primary} IS NULL AND ${this.secondary} < ${labeled.secondary})`
142
+ : sql<SqlBool>`((${this.primary}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}) OR (${this.primary} is null))`
143
143
  }
144
144
  }
145
145
  }
@@ -244,15 +244,15 @@ export class EndAtIdKeyset extends GenericKeyset<EndAtIdKeysetParam, Cursor> {
244
244
  const primaryRef = sql`COALESCE(${this.primary}, ${PERMANENT_ENDSAT})`
245
245
  if (tryIndex) {
246
246
  if (direction === 'asc') {
247
- return sql`((${primaryRef}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}))`
247
+ return sql<SqlBool>`((${primaryRef}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}))`
248
248
  } else {
249
- return sql`((${primaryRef}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}))`
249
+ return sql<SqlBool>`((${primaryRef}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}))`
250
250
  }
251
251
  } else {
252
252
  if (direction === 'asc') {
253
- return sql`((${primaryRef} > ${labeled.primary}) or (${primaryRef} = ${labeled.primary} and ${this.secondary} > ${labeled.secondary}))`
253
+ return sql<SqlBool>`((${primaryRef} > ${labeled.primary}) or (${primaryRef} = ${labeled.primary} and ${this.secondary} > ${labeled.secondary}))`
254
254
  } else {
255
- return sql`((${primaryRef} < ${labeled.primary}) or (${primaryRef} = ${labeled.primary} and ${this.secondary} < ${labeled.secondary}))`
255
+ return sql<SqlBool>`((${primaryRef} < ${labeled.primary}) or (${primaryRef} = ${labeled.primary} and ${this.secondary} < ${labeled.secondary}))`
256
256
  }
257
257
  }
258
258
  }
@@ -314,11 +314,11 @@ export const paginate = <
314
314
  } = opts
315
315
  const keysetSql = keyset.getSql(keyset.unpack(cursor), direction, tryIndex)
316
316
  return qb
317
- .if(!!limit, (q) => q.limit(limit as number))
318
- .if(!nullsLast, (q) =>
317
+ .$if(!!limit, (q) => q.limit(limit as number))
318
+ .$if(!nullsLast, (q) =>
319
319
  q.orderBy(keyset.primary, direction).orderBy(keyset.secondary, direction),
320
320
  )
321
- .if(!!nullsLast, (q) =>
321
+ .$if(!!nullsLast, (q) =>
322
322
  q
323
323
  .orderBy(
324
324
  direction === 'asc'
@@ -331,5 +331,5 @@ export const paginate = <
331
331
  : sql`${keyset.secondary} desc nulls last`,
332
332
  ),
333
333
  )
334
- .if(!!keysetSql, (qb) => (keysetSql ? qb.where(keysetSql) : qb)) as QB
334
+ .$if(!!keysetSql, (qb) => (keysetSql ? qb.where(keysetSql) : qb)) as QB
335
335
  }
package/src/db/types.ts CHANGED
@@ -3,7 +3,9 @@ import { DynamicModule, RawBuilder, SelectQueryBuilder, sql } from 'kysely'
3
3
  import pg from 'pg'
4
4
  type PgPool = pg.Pool
5
5
 
6
- export type DbRef = RawBuilder | ReturnType<DynamicModule['ref']>
6
+ export type DbRef =
7
+ | RawBuilder<unknown>
8
+ | ReturnType<DynamicModule<unknown>['ref']>
7
9
 
8
10
  export type AnyQb = SelectQueryBuilder<any, any, any>
9
11
 
@@ -1,4 +1,4 @@
1
- import { Insertable, RawBuilder, sql } from 'kysely'
1
+ import { Expression, Insertable, sql } from 'kysely'
2
2
  import { CID } from 'multiformats/cid'
3
3
  import { AtpAgent, ToolsOzoneModerationDefs } from '@atproto/api'
4
4
  import { addHoursToDate, chunkArray } from '@atproto/common'
@@ -267,21 +267,24 @@ export class ModerationService {
267
267
 
268
268
  // If subjectType is set to 'account' let that take priority and ignore collections filter
269
269
  if (collections.length && subjectType !== 'account') {
270
- builder = builder.where('subjectUri', 'is not', null).where((qb) => {
271
- collections.forEach((collection) => {
272
- qb = qb.orWhere('subjectUri', 'like', `%/${collection}/%`)
273
- })
274
- return qb
275
- })
270
+ builder = builder
271
+ .where('subjectUri', 'is not', null)
272
+ .where((eb) =>
273
+ eb.or(
274
+ collections.map((collection) =>
275
+ eb('subjectUri', 'like', `%/${collection}/%`),
276
+ ),
277
+ ),
278
+ )
276
279
  }
277
280
 
278
281
  if (types.length) {
279
- builder = builder.where((qb) => {
282
+ builder = builder.where((eb) => {
280
283
  if (types.length === 1) {
281
- return qb.where('action', '=', types[0])
284
+ return eb('action', '=', types[0])
282
285
  }
283
286
 
284
- return qb.where('action', 'in', types)
287
+ return eb('action', 'in', types)
285
288
  })
286
289
  }
287
290
  if (createdBy) {
@@ -298,12 +301,11 @@ export class ModerationService {
298
301
  // the input may end in || in which case, there may be item in the array which is just '' and we want to ignore those
299
302
  const keywords = comment.split('||').filter((keyword) => !!keyword.trim())
300
303
  if (keywords.length > 1) {
301
- builder = builder.where((qb) => {
302
- keywords.forEach((keyword) => {
303
- qb = qb.orWhere('comment', 'ilike', `%${keyword}%`)
304
- })
305
- return qb
306
- })
304
+ builder = builder.where((eb) =>
305
+ eb.or(
306
+ keywords.map((keyword) => eb('comment', 'ilike', `%${keyword}%`)),
307
+ ),
308
+ )
307
309
  } else if (keywords.length === 1) {
308
310
  builder = builder.where('comment', 'ilike', `%${keywords[0]}%`)
309
311
  }
@@ -324,23 +326,26 @@ export class ModerationService {
324
326
  })
325
327
  }
326
328
  if (addedTags.length) {
327
- builder = builder.where(sql`${ref('addedTags')} @> ${jsonb(addedTags)}`)
329
+ builder = builder.where(
330
+ sql<boolean>`${ref('addedTags')} @> ${jsonb(addedTags)}`,
331
+ )
328
332
  }
329
333
  if (removedTags.length) {
330
334
  builder = builder.where(
331
- sql`${ref('removedTags')} @> ${jsonb(removedTags)}`,
335
+ sql<boolean>`${ref('removedTags')} @> ${jsonb(removedTags)}`,
332
336
  )
333
337
  }
334
338
  if (reportTypes?.length) {
335
339
  builder = builder.where(sql`meta->>'reportType'`, 'in', reportTypes)
336
340
  }
337
341
  if (policies?.length) {
338
- builder = builder.where((qb) => {
339
- policies.forEach((policy) => {
340
- qb = qb.orWhere(sql`meta->>'policies'`, 'ilike', `%${policy}%`)
341
- })
342
- return qb
343
- })
342
+ builder = builder.where((eb) =>
343
+ eb.or(
344
+ policies.map((policy) =>
345
+ eb(sql`meta->>'policies'`, 'ilike', `%${policy}%`),
346
+ ),
347
+ ),
348
+ )
344
349
  }
345
350
  if (modTool?.length) {
346
351
  builder = builder
@@ -446,8 +451,8 @@ export class ModerationService {
446
451
  const subjectsToBeResolved = await this.db.db
447
452
  .selectFrom('moderation_subject_status')
448
453
  .where('did', '=', did)
449
- .where((qb) =>
450
- qb.where('recordPath', '!=', '').orWhere('convoId', '!=', ''),
454
+ .where((eb) =>
455
+ eb.or([eb('recordPath', '!=', ''), eb('convoId', '!=', '')]),
451
456
  )
452
457
  .where('reviewState', 'in', [REVIEWESCALATED, REVIEWOPEN])
453
458
  .selectAll()
@@ -816,8 +821,9 @@ export class ModerationService {
816
821
  const now = new Date().toISOString()
817
822
  const subjects = await this.db.db
818
823
  .selectFrom('moderation_subject_status')
819
- .where('suspendUntil', '<', now)
820
- .orWhere('muteUntil', '<', now)
824
+ .where((eb) =>
825
+ eb.or([eb('suspendUntil', '<', now), eb('muteUntil', '<', now)]),
826
+ )
821
827
  .selectAll()
822
828
  .execute()
823
829
 
@@ -1206,16 +1212,17 @@ export class ModerationService {
1206
1212
  if (subjectType !== 'account' && collections?.length) {
1207
1213
  builder = builder
1208
1214
  .where('moderation_subject_status.recordPath', '!=', '')
1209
- .where((qb) => {
1210
- for (const collection of collections) {
1211
- qb = qb.orWhere(
1212
- 'moderation_subject_status.recordPath',
1213
- 'like',
1214
- `${collection}/%`,
1215
- )
1216
- }
1217
- return qb
1218
- })
1215
+ .where((eb) =>
1216
+ eb.or(
1217
+ collections.map((collection) =>
1218
+ eb(
1219
+ 'moderation_subject_status.recordPath',
1220
+ 'like',
1221
+ `${collection}/%`,
1222
+ ),
1223
+ ),
1224
+ ),
1225
+ )
1219
1226
  }
1220
1227
 
1221
1228
  if (ignoreSubjects?.length) {
@@ -1325,30 +1332,32 @@ export class ModerationService {
1325
1332
  }
1326
1333
 
1327
1334
  if (!includeMuted) {
1328
- builder = builder.where((qb) =>
1329
- qb
1330
- .where(
1335
+ builder = builder.where((eb) =>
1336
+ eb.or([
1337
+ eb(
1331
1338
  'moderation_subject_status.muteUntil',
1332
1339
  '<',
1333
1340
  new Date().toISOString(),
1334
- )
1335
- .orWhere('moderation_subject_status.muteUntil', 'is', null),
1341
+ ),
1342
+ eb('moderation_subject_status.muteUntil', 'is', null),
1343
+ ]),
1336
1344
  )
1337
1345
  }
1338
1346
 
1339
1347
  if (onlyMuted) {
1340
- builder = builder.where((qb) =>
1341
- qb
1342
- .where(
1348
+ builder = builder.where((eb) =>
1349
+ eb.or([
1350
+ eb(
1343
1351
  'moderation_subject_status.muteUntil',
1344
1352
  '>',
1345
1353
  new Date().toISOString(),
1346
- )
1347
- .orWhere(
1354
+ ),
1355
+ eb(
1348
1356
  'moderation_subject_status.muteReportingUntil',
1349
1357
  '>',
1350
1358
  new Date().toISOString(),
1351
1359
  ),
1360
+ ]),
1352
1361
  )
1353
1362
  }
1354
1363
 
@@ -1356,30 +1365,28 @@ export class ModerationService {
1356
1365
  const conditions = parseTags(tags)
1357
1366
  if (conditions?.length) {
1358
1367
  // [["tag1"], ["tag2", "tag3"], ["tag4"]] => (tags ? 'tag1') OR (tags ? 'tag2' AND tags ? 'tag3') OR (tags ? 'tag4')
1359
- builder = builder.where((qb) => {
1360
- for (const subTags of conditions) {
1361
- // OR between every conditions items (subTags)
1362
- qb = qb.orWhere((qb) => {
1368
+ builder = builder.where((eb) =>
1369
+ // OR between every conditions items (subTags)
1370
+ eb.or(
1371
+ conditions.map((subTags) =>
1363
1372
  // AND between every subTags items (subTag)
1364
- for (const subTag of subTags) {
1365
- qb = qb.where(
1366
- sql`${ref('moderation_subject_status.tags')} ? ${subTag}`,
1367
- )
1368
- }
1369
- return qb
1370
- })
1371
- }
1372
- return qb
1373
- })
1373
+ eb.and(
1374
+ subTags.map(
1375
+ (subTag) =>
1376
+ sql<boolean>`${ref('moderation_subject_status.tags')} ? ${subTag}`,
1377
+ ),
1378
+ ),
1379
+ ),
1380
+ ),
1381
+ )
1374
1382
  }
1375
1383
 
1376
1384
  if (excludeTags?.length) {
1377
- builder = builder.where((qb) =>
1378
- qb
1379
- .where(
1380
- sql`NOT(${ref('moderation_subject_status.tags')} ?| array[${sql.join(excludeTags)}]::TEXT[])`,
1381
- )
1382
- .orWhere('tags', 'is', null),
1385
+ builder = builder.where((eb) =>
1386
+ eb.or([
1387
+ sql<boolean>`NOT(${ref('moderation_subject_status.tags')} ?| array[${sql.join(excludeTags)}]::TEXT[])`,
1388
+ eb('tags', 'is', null),
1389
+ ]),
1383
1390
  )
1384
1391
  }
1385
1392
 
@@ -1620,15 +1627,15 @@ export class ModerationService {
1620
1627
  const countAll = () => {
1621
1628
  return sql<number>`COUNT(*)`
1622
1629
  }
1623
- const countAllDistinctBy = (ref: RawBuilder) => {
1630
+ const countAllDistinctBy = (ref: Expression<unknown>) => {
1624
1631
  return sql<number>`COUNT(DISTINCT ${ref})`
1625
1632
  }
1626
- const countTakedownsDistinctBy = (ref: RawBuilder) => {
1633
+ const countTakedownsDistinctBy = (ref: Expression<unknown>) => {
1627
1634
  return sql<number>`COUNT(DISTINCT ${ref}) FILTER (
1628
1635
  WHERE actions."action" = 'tools.ozone.moderation.defs#modEventTakedown'
1629
1636
  )`
1630
1637
  }
1631
- const countLabelsDistinctBy = (ref: RawBuilder) => {
1638
+ const countLabelsDistinctBy = (ref: Expression<unknown>) => {
1632
1639
  return sql<number>`COUNT(DISTINCT ${ref}) FILTER (
1633
1640
  WHERE actions."action" = 'tools.ozone.moderation.defs#modEventLabel'
1634
1641
  )`
@@ -74,7 +74,9 @@ export async function queryReports(
74
74
  const collectionConditions = params.collections.map(
75
75
  (collection) => sql`r."recordPath" LIKE ${`${collection}/%`}`,
76
76
  )
77
- builder = builder.where(sql`(${sql.join(collectionConditions, sql` OR `)})`)
77
+ builder = builder.where(
78
+ sql<boolean>`(${sql.join(collectionConditions, sql` OR `)})`,
79
+ )
78
80
  }
79
81
 
80
82
  if (params.reportTypes?.length) {
@@ -112,12 +114,12 @@ export async function queryReports(
112
114
  const [sortValue, id] = params.cursor.split('::')
113
115
  const sortCol = sortField === 'updatedAt' ? 'r.updatedAt' : 'r.createdAt'
114
116
  if (sortDirection === 'desc') {
115
- builder = builder.where(sql`(
117
+ builder = builder.where(sql<boolean>`(
116
118
  ${sql.ref(sortCol)} < ${sortValue}
117
119
  OR (${sql.ref(sortCol)} = ${sortValue} AND r.id < ${Number(id)})
118
120
  )`)
119
121
  } else {
120
- builder = builder.where(sql`(
122
+ builder = builder.where(sql<boolean>`(
121
123
  ${sql.ref(sortCol)} > ${sortValue}
122
124
  OR (${sql.ref(sortCol)} = ${sortValue} AND r.id > ${Number(id)})
123
125
  )`)
@@ -602,7 +602,7 @@ export class ModerationViews {
602
602
  this.db.db,
603
603
  )
604
604
  .where(
605
- sql<string>`${ref(
605
+ sql<boolean>`${ref(
606
606
  'moderation_subject_status.blobCids',
607
607
  )} @> ${JSON.stringify(blobs.map((blob) => blob.ref.toString()))}`,
608
608
  )
@@ -642,10 +642,10 @@ export class ModerationViews {
642
642
  const res = await this.db.db
643
643
  .selectFrom('label')
644
644
  .where('label.uri', 'in', subjects)
645
- .where((qb) =>
646
- qb.where('label.exp', 'is', null).orWhere('label.exp', '>', now),
645
+ .where((eb) =>
646
+ eb.or([eb('label.exp', 'is', null), eb('label.exp', '>', now)]),
647
647
  )
648
- .if(!includeNeg, (qb) => qb.where('neg', '=', false))
648
+ .$if(!includeNeg, (qb) => qb.where('neg', '=', false))
649
649
  .selectAll()
650
650
  .execute()
651
651
 
@@ -688,21 +688,21 @@ export class ModerationViews {
688
688
 
689
689
  const builder = moderationSubjectStatusQueryBuilder(this.db.db)
690
690
  //
691
- .where((qb) => {
692
- for (const sub of parsedSubjects) {
693
- qb = qb.orWhere((qb) =>
694
- qb
695
- .where('moderation_subject_status.did', '=', sub.did)
696
- .where(
691
+ .where((eb) =>
692
+ eb.or(
693
+ parsedSubjects.map((sub) =>
694
+ eb.and([
695
+ eb('moderation_subject_status.did', '=', sub.did),
696
+ eb(
697
697
  'moderation_subject_status.recordPath',
698
698
  '=',
699
699
  sub.recordPath ?? '',
700
- )
701
- .where('moderation_subject_status.convoId', '=', ''),
702
- )
703
- }
704
- return qb
705
- })
700
+ ),
701
+ eb('moderation_subject_status.convoId', '=', ''),
702
+ ]),
703
+ ),
704
+ ),
705
+ )
706
706
 
707
707
  const [statusRes, accountsByDid] = await Promise.all([
708
708
  builder.execute(),
@@ -204,7 +204,7 @@ export class QueueService {
204
204
  }
205
205
 
206
206
  if (subjectType !== undefined) {
207
- qb = qb.where(sql`"subjectTypes" @> ${jsonb([subjectType])}`)
207
+ qb = qb.where(sql<boolean>`"subjectTypes" @> ${jsonb([subjectType])}`)
208
208
  }
209
209
 
210
210
  if (collection !== undefined) {
@@ -215,7 +215,7 @@ export class QueueService {
215
215
  const conditions = reportTypes.map(
216
216
  (t) => sql`"reportTypes" @> ${jsonb([t])}`,
217
217
  )
218
- qb = qb.where(sql`(${sql.join(conditions, sql` OR `)})`)
218
+ qb = qb.where(sql<boolean>`(${sql.join(conditions, sql` OR `)})`)
219
219
  }
220
220
 
221
221
  const keyset = new TimeIdKeyset(ref('createdAt'), ref('id'))
@@ -309,9 +309,9 @@ export class QueueService {
309
309
  .limit(params.limit)
310
310
 
311
311
  if (opts?.includeUnmatched) {
312
- query = query.where((qb) => {
313
- return qb.orWhere('r.queueId', 'is', null).orWhere('r.queueId', '=', -1)
314
- })
312
+ query = query.where((eb) =>
313
+ eb.or([eb('r.queueId', 'is', null), eb('r.queueId', '=', -1)]),
314
+ )
315
315
  } else {
316
316
  query = query.where('r.queueId', 'is', null)
317
317
  }
@@ -672,7 +672,7 @@ export class ReportStatsService {
672
672
  del =
673
673
  r.reportTypes !== null
674
674
  ? del.where(
675
- sql`"reportTypes"::jsonb = ${jsonb(r.reportTypes)}::jsonb`,
675
+ sql<boolean>`"reportTypes"::jsonb = ${jsonb(r.reportTypes)}::jsonb`,
676
676
  )
677
677
  : del.where('reportTypes', 'is', null)
678
678
  await del.execute()
@@ -720,7 +720,7 @@ export class ReportStatsService {
720
720
  }
721
721
  if (group.reportTypes !== null) {
722
722
  qb = qb.where(
723
- sql`"reportTypes"::jsonb = ${jsonb(group.reportTypes)}::jsonb`,
723
+ sql<boolean>`"reportTypes"::jsonb = ${jsonb(group.reportTypes)}::jsonb`,
724
724
  )
725
725
  } else {
726
726
  qb = qb.where('reportTypes', 'is', null)
@@ -786,7 +786,9 @@ export class ReportStatsService {
786
786
  qb = qb.where('moderatorDid', 'is', null)
787
787
  }
788
788
  if (reportTypes !== null) {
789
- qb = qb.where(sql`"reportTypes"::jsonb = ${jsonb(reportTypes)}::jsonb`)
789
+ qb = qb.where(
790
+ sql<boolean>`"reportTypes"::jsonb = ${jsonb(reportTypes)}::jsonb`,
791
+ )
790
792
  } else {
791
793
  qb = qb.where('reportTypes', 'is', null)
792
794
  }
@@ -151,24 +151,25 @@ export class ScheduledActionService {
151
151
  }
152
152
 
153
153
  if (startTime) {
154
- query = query.where((qb) => {
155
- return qb
156
- .orWhere('executeAt', '>=', startTime.toISOString())
157
- .orWhere('executeAfter', '>=', startTime.toISOString())
158
- })
154
+ query = query.where((eb) =>
155
+ eb.or([
156
+ eb('executeAt', '>=', startTime.toISOString()),
157
+ eb('executeAfter', '>=', startTime.toISOString()),
158
+ ]),
159
+ )
159
160
  }
160
161
 
161
162
  if (endTime) {
162
- query = query.where((qb) => {
163
- return qb
164
- .orWhere('executeAt', '<=', endTime.toISOString())
165
- .orWhere('executeUntil', '<=', endTime.toISOString())
166
- .orWhere((sqb) => {
167
- return sqb
168
- .where('executeUntil', 'is', null)
169
- .where('executeAfter', '<=', endTime.toISOString())
170
- })
171
- })
163
+ query = query.where((eb) =>
164
+ eb.or([
165
+ eb('executeAt', '<=', endTime.toISOString()),
166
+ eb('executeUntil', '<=', endTime.toISOString()),
167
+ eb.and([
168
+ eb('executeUntil', 'is', null),
169
+ eb('executeAfter', '<=', endTime.toISOString()),
170
+ ]),
171
+ ]),
172
+ )
172
173
  }
173
174
 
174
175
  if (cursor) {
@@ -235,11 +236,12 @@ export class ScheduledActionService {
235
236
  .selectFrom('scheduled_action')
236
237
  .selectAll()
237
238
  .where('status', '=', 'pending')
238
- .where((qb) => {
239
- return qb
240
- .orWhere('executeAfter', '<=', now.toISOString())
241
- .orWhere('executeAt', '<=', now.toISOString())
242
- })
239
+ .where((eb) =>
240
+ eb.or([
241
+ eb('executeAfter', '<=', now.toISOString()),
242
+ eb('executeAt', '<=', now.toISOString()),
243
+ ]),
244
+ )
243
245
  .execute()
244
246
  }
245
247
 
@@ -1,4 +1,4 @@
1
- import { Selectable } from 'kysely'
1
+ import { NotNull, Selectable } from 'kysely'
2
2
  import { Database } from '../db/index.js'
3
3
  import { TimeIdKeyset, paginate } from '../db/pagination.js'
4
4
  import { SetDetail } from '../db/schema/ozone_set.js'
@@ -14,19 +14,22 @@ export class SetService {
14
14
  }
15
15
 
16
16
  buildQueryForSetWithSize() {
17
- return this.db.db.selectFrom('set_detail as s').select([
18
- 's.id',
19
- 's.name',
20
- 's.description',
21
- 's.createdAt',
22
- 's.updatedAt',
23
- (eb) =>
24
- eb
25
- .selectFrom('set_value')
26
- .select((e) => e.fn.count<number>('setId').as('count'))
27
- .whereRef('setId', '=', 's.id')
28
- .as('setSize'),
29
- ])
17
+ return this.db.db
18
+ .selectFrom('set_detail as s')
19
+ .select([
20
+ 's.id',
21
+ 's.name',
22
+ 's.description',
23
+ 's.createdAt',
24
+ 's.updatedAt',
25
+ (eb) =>
26
+ eb
27
+ .selectFrom('set_value')
28
+ .select((e) => e.fn.count<number>('setId').as('count'))
29
+ .whereRef('setId', '=', 's.id')
30
+ .as('setSize'),
31
+ ])
32
+ .$narrowType<{ setSize: NotNull }>()
30
33
  }
31
34
 
32
35
  async query({
package/src/team/index.ts CHANGED
@@ -67,10 +67,11 @@ export class TeamService {
67
67
  builder = builder.where('disabled', disabled ? 'is' : 'is not', true)
68
68
  }
69
69
  if (q) {
70
- builder = builder.where((qb) =>
71
- qb
72
- .orWhere('handle', 'ilike', `%${q}%`)
73
- .orWhere('displayName', 'ilike', `%${q}%`),
70
+ builder = builder.where((eb) =>
71
+ eb.or([
72
+ eb('handle', 'ilike', `%${q}%`),
73
+ eb('displayName', 'ilike', `%${q}%`),
74
+ ]),
74
75
  )
75
76
  }
76
77
 
@@ -245,7 +246,7 @@ export class TeamService {
245
246
  .selectFrom('member')
246
247
  .select(['did'])
247
248
  .limit(25)
248
- .if(!!lastDid, (q) => q.where('did', '>', lastDid))
249
+ .$if(!!lastDid, (q) => q.where('did', '>', lastDid))
249
250
  .orderBy('did', 'asc')
250
251
  .execute()
251
252
 
@@ -197,8 +197,8 @@ export class VerificationService {
197
197
  .updateTable('firehose_cursor')
198
198
  .set({ cursor })
199
199
  .where('service', '=', 'verification')
200
- .where((qb) =>
201
- qb.where('cursor', '<', cursor).orWhere('cursor', 'is', null),
200
+ .where((eb) =>
201
+ eb.or([eb('cursor', '<', cursor), eb('cursor', 'is', null)]),
202
202
  )
203
203
  .returningAll()
204
204
  .executeTakeFirst()