@atproto/ozone 0.14.2 → 0.15.1

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 (95) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/api/index.js +4 -0
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/api/moderation/emitEvent.d.ts.map +1 -1
  6. package/dist/api/moderation/emitEvent.js +32 -0
  7. package/dist/api/moderation/emitEvent.js.map +1 -1
  8. package/dist/api/moderation/emitEvents.d.ts +4 -0
  9. package/dist/api/moderation/emitEvents.d.ts.map +1 -0
  10. package/dist/api/moderation/emitEvents.js +54 -0
  11. package/dist/api/moderation/emitEvents.js.map +1 -0
  12. package/dist/api/moderation/util-event.d.ts +18 -0
  13. package/dist/api/moderation/util-event.d.ts.map +1 -0
  14. package/dist/api/moderation/util-event.js +367 -0
  15. package/dist/api/moderation/util-event.js.map +1 -0
  16. package/dist/api/report/closeReports.d.ts.map +1 -1
  17. package/dist/api/report/closeReports.js +2 -1
  18. package/dist/api/report/closeReports.js.map +1 -1
  19. package/dist/api/report/queryModeratorActivity.d.ts +4 -0
  20. package/dist/api/report/queryModeratorActivity.d.ts.map +1 -0
  21. package/dist/api/report/queryModeratorActivity.js +17 -0
  22. package/dist/api/report/queryModeratorActivity.js.map +1 -0
  23. package/dist/lexicons/index.d.ts +0 -1
  24. package/dist/lexicons/index.d.ts.map +1 -1
  25. package/dist/lexicons/index.js +0 -1
  26. package/dist/lexicons/index.js.map +1 -1
  27. package/dist/lexicons/tools/ozone/moderation/emitEvent.defs.d.ts +8 -0
  28. package/dist/lexicons/tools/ozone/moderation/emitEvent.defs.d.ts.map +1 -1
  29. package/dist/lexicons/tools/ozone/moderation/emitEvent.defs.js +1 -1
  30. package/dist/lexicons/tools/ozone/moderation/emitEvent.defs.js.map +1 -1
  31. package/dist/lexicons/tools/ozone/moderation/emitEvents.d.ts +3 -0
  32. package/dist/lexicons/tools/ozone/moderation/emitEvents.d.ts.map +1 -0
  33. package/dist/lexicons/tools/ozone/moderation/emitEvents.defs.d.ts +81 -0
  34. package/dist/lexicons/tools/ozone/moderation/emitEvents.defs.d.ts.map +1 -0
  35. package/dist/lexicons/tools/ozone/moderation/emitEvents.defs.js +25 -0
  36. package/dist/lexicons/tools/ozone/moderation/emitEvents.defs.js.map +1 -0
  37. package/dist/lexicons/tools/ozone/moderation/emitEvents.js +6 -0
  38. package/dist/lexicons/tools/ozone/moderation/emitEvents.js.map +1 -0
  39. package/dist/lexicons/tools/ozone/moderation.d.ts +1 -0
  40. package/dist/lexicons/tools/ozone/moderation.d.ts.map +1 -1
  41. package/dist/lexicons/tools/ozone/moderation.js +1 -0
  42. package/dist/lexicons/tools/ozone/moderation.js.map +1 -1
  43. package/dist/lexicons/tools/ozone/report/closeReports.defs.d.ts +3 -1
  44. package/dist/lexicons/tools/ozone/report/closeReports.defs.d.ts.map +1 -1
  45. package/dist/lexicons/tools/ozone/report/closeReports.defs.js +2 -2
  46. package/dist/lexicons/tools/ozone/report/closeReports.defs.js.map +1 -1
  47. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.d.ts +3 -0
  48. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.d.ts.map +1 -0
  49. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.defs.d.ts +70 -0
  50. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.defs.d.ts.map +1 -0
  51. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.defs.js +18 -0
  52. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.defs.js.map +1 -0
  53. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.js +6 -0
  54. package/dist/lexicons/tools/ozone/report/queryModeratorActivity.js.map +1 -0
  55. package/dist/lexicons/tools/ozone/report.d.ts +1 -0
  56. package/dist/lexicons/tools/ozone/report.d.ts.map +1 -1
  57. package/dist/lexicons/tools/ozone/report.js +1 -0
  58. package/dist/lexicons/tools/ozone/report.js.map +1 -1
  59. package/dist/mod-service/index.d.ts +1 -1
  60. package/dist/mod-service/index.d.ts.map +1 -1
  61. package/dist/mod-service/index.js +2 -2
  62. package/dist/mod-service/index.js.map +1 -1
  63. package/dist/mod-service/profile.d.ts +1 -1
  64. package/dist/mod-service/profile.d.ts.map +1 -1
  65. package/dist/mod-service/profile.js +1 -0
  66. package/dist/mod-service/profile.js.map +1 -1
  67. package/dist/mod-service/report.d.ts +15 -11
  68. package/dist/mod-service/report.d.ts.map +1 -1
  69. package/dist/mod-service/report.js +109 -45
  70. package/dist/mod-service/report.js.map +1 -1
  71. package/dist/report/moderator-activity.d.ts +7 -0
  72. package/dist/report/moderator-activity.d.ts.map +1 -0
  73. package/dist/report/moderator-activity.js +116 -0
  74. package/dist/report/moderator-activity.js.map +1 -0
  75. package/package.json +3 -3
  76. package/dist/lexicons/internal/bsky/actor/getProfiles.d.ts +0 -3
  77. package/dist/lexicons/internal/bsky/actor/getProfiles.d.ts.map +0 -1
  78. package/dist/lexicons/internal/bsky/actor/getProfiles.defs.d.ts +0 -43
  79. package/dist/lexicons/internal/bsky/actor/getProfiles.defs.d.ts.map +0 -1
  80. package/dist/lexicons/internal/bsky/actor/getProfiles.defs.js +0 -15
  81. package/dist/lexicons/internal/bsky/actor/getProfiles.defs.js.map +0 -1
  82. package/dist/lexicons/internal/bsky/actor/getProfiles.js +0 -6
  83. package/dist/lexicons/internal/bsky/actor/getProfiles.js.map +0 -1
  84. package/dist/lexicons/internal/bsky/actor.d.ts +0 -2
  85. package/dist/lexicons/internal/bsky/actor.d.ts.map +0 -1
  86. package/dist/lexicons/internal/bsky/actor.js +0 -5
  87. package/dist/lexicons/internal/bsky/actor.js.map +0 -1
  88. package/dist/lexicons/internal/bsky.d.ts +0 -2
  89. package/dist/lexicons/internal/bsky.d.ts.map +0 -1
  90. package/dist/lexicons/internal/bsky.js +0 -5
  91. package/dist/lexicons/internal/bsky.js.map +0 -1
  92. package/dist/lexicons/internal.d.ts +0 -2
  93. package/dist/lexicons/internal.d.ts.map +0 -1
  94. package/dist/lexicons/internal.js +0 -5
  95. package/dist/lexicons/internal.js.map +0 -1
@@ -0,0 +1,116 @@
1
+ import { sql } from 'kysely';
2
+ import { isDatetimeString } from '@atproto/lex-schema';
3
+ import { InvalidRequestError } from '@atproto/xrpc-server';
4
+ import { getReportsByIds } from '../mod-service/report.js';
5
+ import { formatActivityView } from './activity.js';
6
+ function unpackCursor(token) {
7
+ try {
8
+ if (token.length > 512 || !/^[A-Za-z0-9_-]+$/.test(token))
9
+ throw new Error();
10
+ const key = JSON.parse(Buffer.from(token, 'base64url').toString());
11
+ if (!key ||
12
+ !isDatetimeString(key.createdAt) ||
13
+ !['event', 'activity'].includes(key.source) ||
14
+ !Number.isSafeInteger(key.id) ||
15
+ key.id < 1)
16
+ throw new Error();
17
+ return key;
18
+ }
19
+ catch {
20
+ throw new InvalidRequestError('Invalid activity cursor');
21
+ }
22
+ }
23
+ /** Read a bounded chronological page from existing human activity records. */
24
+ export async function queryModeratorActivity(ctx, params, signal) {
25
+ if (Date.parse(params.createdAfter) >= Date.parse(params.createdBefore)) {
26
+ throw new InvalidRequestError('Activity start must precede end');
27
+ }
28
+ const previous = params.cursor ? unpackCursor(params.cursor) : undefined;
29
+ const options = {
30
+ signal,
31
+ inflightQueryAbortStrategy: 'cancel query',
32
+ };
33
+ const limit = params.limit;
34
+ const seek = (alias, source) => previous
35
+ ? sql `(${sql.ref(`${alias}.createdAt`)}, ${source}::text, ${sql.ref(`${alias}.id`)}) < (${previous.createdAt}, ${previous.source}::text, ${previous.id})`
36
+ : sql `true`;
37
+ const types = (column) => params.types?.length
38
+ ? sql `${sql.ref(column)} IN (${sql.join(params.types)})`
39
+ : sql `true`;
40
+ const candidates = await sql `
41
+ SELECT * FROM (
42
+ (SELECT e.id, e."createdAt", 'event'::text AS source
43
+ FROM moderation_event e
44
+ WHERE e."createdBy" = ${params.moderator}
45
+ AND e."createdAt" >= ${params.createdAfter} AND e."createdAt" < ${params.createdBefore}
46
+ AND ${types('e.action')} AND ${seek('e', 'event')}
47
+ AND (e."modTool" -> 'meta' ->> 'isAutomated') IS DISTINCT FROM 'true'
48
+ ORDER BY e."createdAt" DESC, e.id DESC LIMIT ${limit + 1})
49
+ UNION ALL
50
+ (SELECT a.id, a."createdAt", 'activity'::text AS source
51
+ FROM report_activity a
52
+ WHERE a."createdBy" = ${params.moderator}
53
+ AND a."createdAt" >= ${params.createdAfter} AND a."createdAt" < ${params.createdBefore}
54
+ AND ${types('a.activityType')} AND ${seek('a', 'activity')}
55
+ AND a."isAutomated" = false
56
+ ORDER BY a."createdAt" DESC, a.id DESC LIMIT ${limit + 1})
57
+ ) candidates ORDER BY "createdAt" DESC, source DESC, id DESC LIMIT ${limit + 1}
58
+ `.execute(ctx.db.db, options);
59
+ const page = candidates.rows.slice(0, limit);
60
+ const eventIds = page.filter((r) => r.source === 'event').map((r) => r.id);
61
+ const activityIds = page
62
+ .filter((r) => r.source === 'activity')
63
+ .map((r) => r.id);
64
+ const modService = ctx.modService(ctx.db);
65
+ const events = await modService.getEventsByIds(eventIds, signal);
66
+ const activities = activityIds.length
67
+ ? await ctx.db.db
68
+ .selectFrom('report_activity')
69
+ .selectAll()
70
+ .where('id', 'in', activityIds)
71
+ .execute(options)
72
+ : [];
73
+ const reports = await getReportsByIds(ctx.db, [...new Set(activities.map((a) => a.reportId))], signal);
74
+ const reportMap = new Map(reports.map((r) => [r.id, r]));
75
+ const rows = new Map();
76
+ for (const event of events) {
77
+ rows.set(`event:${event.id}`, {
78
+ source: 'event',
79
+ id: event.id,
80
+ type: event.action,
81
+ createdAt: event.createdAt,
82
+ createdBy: event.createdBy,
83
+ subject: event.subjectUri ?? event.subjectDid,
84
+ event: modService.views.formatEvent(event),
85
+ });
86
+ }
87
+ for (const activity of activities) {
88
+ const report = reportMap.get(activity.reportId);
89
+ if (!report)
90
+ continue;
91
+ const meta = activity.meta;
92
+ const actionEventId = meta?.actionEventId;
93
+ rows.set(`activity:${activity.id}`, {
94
+ source: 'activity',
95
+ id: activity.id,
96
+ type: activity.activityType,
97
+ createdAt: activity.createdAt,
98
+ createdBy: activity.createdBy,
99
+ subject: report.subjectUri ?? report.subjectDid,
100
+ reportId: activity.reportId,
101
+ actionEventId: typeof actionEventId === 'number' &&
102
+ Number.isSafeInteger(actionEventId) &&
103
+ actionEventId > 0
104
+ ? actionEventId
105
+ : undefined,
106
+ activity: formatActivityView(activity),
107
+ });
108
+ }
109
+ return {
110
+ rows: page.flatMap((row) => rows.get(`${row.source}:${row.id}`) ?? []),
111
+ cursor: candidates.rows.length > limit
112
+ ? Buffer.from(JSON.stringify(page.at(-1))).toString('base64url')
113
+ : undefined,
114
+ };
115
+ }
116
+ //# sourceMappingURL=moderator-activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moderator-activity.js","sourceRoot":"","sources":["../../src/report/moderator-activity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAMlD,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,EAAE,CAAA;QAC5E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;QAClE,IACE,CAAC,GAAG;YACJ,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;YAChC,CAAC,CAAC,O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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;YAChE,CAAC,CAAC,SAAS;KAChB,CAAA;AACH,CAAC","sourcesContent":["import { sql } from 'kysely'\nimport { isDatetimeString } from '@atproto/lex-schema'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport type { AppContext } from '../context.js'\nimport type { tools } from '../lexicons/index.js'\nimport { getReportsByIds } from '../mod-service/report.js'\nimport { formatActivityView } from './activity.js'\n\ntype Params = tools.ozone.report.queryModeratorActivity.$Params\ntype Row = tools.ozone.report.queryModeratorActivity.ActivityRow\ntype ActivityKey = Pick<Row, 'id' | 'createdAt' | 'source'>\n\nfunction unpackCursor(token: string): ActivityKey {\n try {\n if (token.length > 512 || !/^[A-Za-z0-9_-]+$/.test(token)) throw new Error()\n const key = JSON.parse(Buffer.from(token, 'base64url').toString())\n if (\n !key ||\n !isDatetimeString(key.createdAt) ||\n !['event', 'activity'].includes(key.source) ||\n !Number.isSafeInteger(key.id) ||\n key.id < 1\n )\n throw new Error()\n return key\n } catch {\n throw new InvalidRequestError('Invalid activity cursor')\n }\n}\n\n/** Read a bounded chronological page from existing human activity records. */\nexport async function queryModeratorActivity(\n ctx: AppContext,\n params: Params,\n signal: AbortSignal,\n): Promise<tools.ozone.report.queryModeratorActivity.$OutputBody> {\n if (Date.parse(params.createdAfter) >= Date.parse(params.createdBefore)) {\n throw new InvalidRequestError('Activity start must precede end')\n }\n const previous = params.cursor ? unpackCursor(params.cursor) : undefined\n const options = {\n signal,\n inflightQueryAbortStrategy: 'cancel query' as const,\n }\n const limit = params.limit\n const seek = (alias: string, source: ActivityKey['source']) =>\n previous\n ? sql<boolean>`(${sql.ref(`${alias}.createdAt`)}, ${source}::text, ${sql.ref(`${alias}.id`)}) < (${previous.createdAt}, ${previous.source}::text, ${previous.id})`\n : sql<boolean>`true`\n const types = (column: string) =>\n params.types?.length\n ? sql<boolean>`${sql.ref(column)} IN (${sql.join(params.types)})`\n : sql<boolean>`true`\n const candidates = await sql<ActivityKey>`\n SELECT * FROM (\n (SELECT e.id, e.\"createdAt\", 'event'::text AS source\n FROM moderation_event e\n WHERE e.\"createdBy\" = ${params.moderator}\n AND e.\"createdAt\" >= ${params.createdAfter} AND e.\"createdAt\" < ${params.createdBefore}\n AND ${types('e.action')} AND ${seek('e', 'event')}\n AND (e.\"modTool\" -> 'meta' ->> 'isAutomated') IS DISTINCT FROM 'true'\n ORDER BY e.\"createdAt\" DESC, e.id DESC LIMIT ${limit + 1})\n UNION ALL\n (SELECT a.id, a.\"createdAt\", 'activity'::text AS source\n FROM report_activity a\n WHERE a.\"createdBy\" = ${params.moderator}\n AND a.\"createdAt\" >= ${params.createdAfter} AND a.\"createdAt\" < ${params.createdBefore}\n AND ${types('a.activityType')} AND ${seek('a', 'activity')}\n AND a.\"isAutomated\" = false\n ORDER BY a.\"createdAt\" DESC, a.id DESC LIMIT ${limit + 1})\n ) candidates ORDER BY \"createdAt\" DESC, source DESC, id DESC LIMIT ${limit + 1}\n `.execute(ctx.db.db, options)\n const page = candidates.rows.slice(0, limit)\n const eventIds = page.filter((r) => r.source === 'event').map((r) => r.id)\n const activityIds = page\n .filter((r) => r.source === 'activity')\n .map((r) => r.id)\n const modService = ctx.modService(ctx.db)\n const events = await modService.getEventsByIds(eventIds, signal)\n const activities = activityIds.length\n ? await ctx.db.db\n .selectFrom('report_activity')\n .selectAll()\n .where('id', 'in', activityIds)\n .execute(options)\n : []\n const reports = await getReportsByIds(\n ctx.db,\n [...new Set(activities.map((a) => a.reportId))],\n signal,\n )\n const reportMap = new Map(reports.map((r) => [r.id, r]))\n const rows = new Map<string, Row>()\n for (const event of events) {\n rows.set(`event:${event.id}`, {\n source: 'event',\n id: event.id,\n type: event.action,\n createdAt: event.createdAt,\n createdBy: event.createdBy,\n subject: event.subjectUri ?? event.subjectDid,\n event: modService.views.formatEvent(event),\n })\n }\n for (const activity of activities) {\n const report = reportMap.get(activity.reportId)\n if (!report) continue\n const meta = activity.meta as { actionEventId?: unknown } | null\n const actionEventId = meta?.actionEventId\n rows.set(`activity:${activity.id}`, {\n source: 'activity',\n id: activity.id,\n type: activity.activityType,\n createdAt: activity.createdAt,\n createdBy: activity.createdBy,\n subject: report.subjectUri ?? report.subjectDid,\n reportId: activity.reportId,\n actionEventId:\n typeof actionEventId === 'number' &&\n Number.isSafeInteger(actionEventId) &&\n actionEventId > 0\n ? actionEventId\n : undefined,\n activity: formatActivityView(activity),\n })\n }\n return {\n rows: page.flatMap((row) => rows.get(`${row.source}:${row.id}`) ?? []),\n cursor:\n candidates.rows.length > limit\n ? Buffer.from(JSON.stringify(page.at(-1))).toString('base64url')\n : undefined,\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/ozone",
3
- "version": "0.14.2",
3
+ "version": "0.15.1",
4
4
  "license": "MIT",
5
5
  "description": "Backend service for moderating the Bluesky network.",
6
6
  "keywords": [
@@ -69,10 +69,10 @@
69
69
  "ws": "^8.12.0"
70
70
  },
71
71
  "devDependencies": {
72
- "@atproto/api": "^0.31.2",
72
+ "@atproto/api": "^0.32.1",
73
73
  "@atproto/lex": "^0.4.8",
74
74
  "@atproto/lexicon": "^0.7.19",
75
- "@atproto/pds": "^0.5.58",
75
+ "@atproto/pds": "^0.5.60",
76
76
  "@did-plc/server": "^0.0.1",
77
77
  "@jest/globals": "^30.0.0",
78
78
  "@types/cors": "^2.8.12",
@@ -1,3 +0,0 @@
1
- export * from "./getProfiles.defs.js";
2
- export { main as default } from "./getProfiles.defs.js";
3
- //# sourceMappingURL=getProfiles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getProfiles.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/internal/bsky/actor/getProfiles.ts"],"names":[],"mappings":"AAIA,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,43 +0,0 @@
1
- import { l } from "@atproto/lex-schema";
2
- import * as ActorDefs from "../../../app/bsky/actor/defs.defs.js";
3
- declare const $nsid = "internal.bsky.actor.getProfiles";
4
- type $nsid = typeof $nsid;
5
- export { $nsid };
6
- export declare const $params: l.ParamsSchema<{
7
- readonly dids: l.ArraySchema<l.StringSchema<{
8
- readonly format: "did";
9
- }>>;
10
- readonly viewer: l.OptionalSchema<l.StringSchema<{
11
- readonly format: "did";
12
- }>>;
13
- readonly socialProof: l.OptionalSchema<l.ArraySchema<l.StringSchema<{
14
- readonly format: "did";
15
- }>>>;
16
- readonly includeTakedowns: l.OptionalSchema<l.WithDefaultSchema<l.BooleanSchema>>;
17
- }>;
18
- export type $Params = l.InferOutput<typeof $params>;
19
- export declare const $output: l.Payload<"application/json", l.ObjectSchema<{
20
- profiles: l.ArraySchema<l.RefSchema<l.Validator<ActorDefs.ProfileViewDetailed, ActorDefs.ProfileViewDetailed>>>;
21
- }>>;
22
- export type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>;
23
- export type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<typeof $output, B>;
24
- /** Get detailed profile views of multiple actors, hydrating social proof (known followers) only for a subset of them. Intended for internal service-to-service use. */
25
- declare const main: l.Query<"internal.bsky.actor.getProfiles", l.ParamsSchema<{
26
- readonly dids: l.ArraySchema<l.StringSchema<{
27
- readonly format: "did";
28
- }>>;
29
- readonly viewer: l.OptionalSchema<l.StringSchema<{
30
- readonly format: "did";
31
- }>>;
32
- readonly socialProof: l.OptionalSchema<l.ArraySchema<l.StringSchema<{
33
- readonly format: "did";
34
- }>>>;
35
- readonly includeTakedowns: l.OptionalSchema<l.WithDefaultSchema<l.BooleanSchema>>;
36
- }>, l.Payload<"application/json", l.ObjectSchema<{
37
- profiles: l.ArraySchema<l.RefSchema<l.Validator<ActorDefs.ProfileViewDetailed, ActorDefs.ProfileViewDetailed>>>;
38
- }>>, undefined>;
39
- export { main };
40
- declare const $lxm = "internal.bsky.actor.getProfiles";
41
- type $lxm = typeof $lxm;
42
- export { $lxm };
43
- //# sourceMappingURL=getProfiles.defs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getProfiles.defs.d.ts","sourceRoot":"","sources":["../../../../../src/lexicons/internal/bsky/actor/getProfiles.defs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAElE,QAAA,MAAM,KAAK,oCAAoC,CAAC;AAEhD,KAAK,KAAK,GAAG,OAAO,KAAK,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,eAAO,MAAM,OAAO;;;;;;;;;;;EAAwa,CAAC;AAE7b,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC;AAEpD,eAAO,MAAM,OAAO;;GAAsK,CAAC;AAE3L,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,YAAY,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC;AAC1E,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,gBAAgB,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC;AAElF,uKAAuK;AACvK,QAAA,MAAM,IAAI;;;;;;;;;;;;;eAAiD,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,QAAA,MAAM,IAAI,oCAAQ,CAAC;AAEnB,KAAK,IAAI,GAAG,OAAO,IAAI,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -1,15 +0,0 @@
1
- /*
2
- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
- */
4
- import { l } from "@atproto/lex-schema";
5
- import * as ActorDefs from "../../../app/bsky/actor/defs.defs.js";
6
- const $nsid = "internal.bsky.actor.getProfiles";
7
- export { $nsid };
8
- export const $params = /*#__PURE__*/ l.params({ "dids": /*#__PURE__*/ l.array(/*#__PURE__*/ l.string({ "format": "did" }), { "maxLength": 200 }), "viewer": /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({ "format": "did" })), "socialProof": /*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({ "format": "did" }), { "maxLength": 200 })), "includeTakedowns": /*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.boolean(), false)) });
9
- export const $output = /*#__PURE__*/ l.jsonPayload({ "profiles": /*#__PURE__*/ l.array(/*#__PURE__*/ l.ref((() => ActorDefs.profileViewDetailed))) });
10
- /** Get detailed profile views of multiple actors, hydrating social proof (known followers) only for a subset of them. Intended for internal service-to-service use. */
11
- const main = /*#__PURE__*/ l.query($nsid, $params, $output);
12
- export { main };
13
- const $lxm = $nsid;
14
- export { $lxm };
15
- //# sourceMappingURL=getProfiles.defs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getProfiles.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/internal/bsky/actor/getProfiles.defs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAC;AAElE,MAAM,KAAK,GAAG,iCAAiC,CAAC;AAIhD,OAAO,EAAE,KAAK,EAAE,CAAC;AAEjB,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAC,MAAM,EAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,KAAK,EAAC,CAAC,EAAE,EAAC,WAAW,EAAC,GAAG,EAAC,CAAC,EAAC,QAAQ,EAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,KAAK,EAAC,CAAC,CAAC,EAAC,aAAa,EAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,KAAK,EAAC,CAAC,EAAE,EAAC,WAAW,EAAC,GAAG,EAAC,CAAC,CAAC,EAAC,kBAAkB,EAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,EAAC,CAAC,CAAC;AAI7b,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,EAAC,UAAU,EAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAgC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,mBAAmB,CAAQ,CAAC,CAAG,EAAC,CAAC,CAAC;AAK3L,uKAAuK;AACvK,MAAM,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,MAAM,IAAI,GAAG,KAAK,CAAC;AAInB,OAAO,EAAE,IAAI,EAAE,CAAC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from \"@atproto/lex-schema\";\nimport * as ActorDefs from \"../../../app/bsky/actor/defs.defs.js\";\n\nconst $nsid = \"internal.bsky.actor.getProfiles\";\n\ntype $nsid = typeof $nsid;\n\nexport { $nsid };\n\nexport const $params = /*#__PURE__*/ l.params({\"dids\":/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({\"format\":\"did\"}), {\"maxLength\":200}),\"viewer\":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.string({\"format\":\"did\"})),\"socialProof\":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.array(/*#__PURE__*/ l.string({\"format\":\"did\"}), {\"maxLength\":200})),\"includeTakedowns\":/*#__PURE__*/ l.optional(/*#__PURE__*/ l.withDefault(/*#__PURE__*/ l.boolean(), false))});\n\nexport type $Params = l.InferOutput<typeof $params>;\n\nexport const $output = /*#__PURE__*/ l.jsonPayload({\"profiles\":/*#__PURE__*/ l.array(/*#__PURE__*/ l.ref<ActorDefs.ProfileViewDetailed>((() => ActorDefs.profileViewDetailed) as any), )});\n\nexport type $Output<B = l.BinaryData> = l.InferPayload<typeof $output, B>;\nexport type $OutputBody<B = l.BinaryData> = l.InferPayloadBody<typeof $output, B>;\n\n/** Get detailed profile views of multiple actors, hydrating social proof (known followers) only for a subset of them. Intended for internal service-to-service use. */\nconst main = /*#__PURE__*/ l.query($nsid, $params, $output);\n\nexport { main };\n\nconst $lxm = $nsid;\n\ntype $lxm = typeof $lxm;\n\nexport { $lxm };\n"]}
@@ -1,6 +0,0 @@
1
- /*
2
- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
- */
4
- export * from "./getProfiles.defs.js";
5
- export { main as default } from "./getProfiles.defs.js";
6
- //# sourceMappingURL=getProfiles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getProfiles.js","sourceRoot":"","sources":["../../../../../src/lexicons/internal/bsky/actor/getProfiles.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * from \"./getProfiles.defs.js\";\nexport { main as default } from \"./getProfiles.defs.js\";\n"]}
@@ -1,2 +0,0 @@
1
- export * as getProfiles from "./actor/getProfiles.js";
2
- //# sourceMappingURL=actor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actor.d.ts","sourceRoot":"","sources":["../../../../src/lexicons/internal/bsky/actor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC"}
@@ -1,5 +0,0 @@
1
- /*
2
- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
- */
4
- export * as getProfiles from "./actor/getProfiles.js";
5
- //# sourceMappingURL=actor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actor.js","sourceRoot":"","sources":["../../../../src/lexicons/internal/bsky/actor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as getProfiles from \"./actor/getProfiles.js\";\n"]}
@@ -1,2 +0,0 @@
1
- export * as actor from "./bsky/actor.js";
2
- //# sourceMappingURL=bsky.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bsky.d.ts","sourceRoot":"","sources":["../../../src/lexicons/internal/bsky.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC"}
@@ -1,5 +0,0 @@
1
- /*
2
- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
- */
4
- export * as actor from "./bsky/actor.js";
5
- //# sourceMappingURL=bsky.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bsky.js","sourceRoot":"","sources":["../../../src/lexicons/internal/bsky.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as actor from \"./bsky/actor.js\";\n"]}
@@ -1,2 +0,0 @@
1
- export * as bsky from "./internal/bsky.js";
2
- //# sourceMappingURL=internal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/lexicons/internal.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC"}
@@ -1,5 +0,0 @@
1
- /*
2
- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3
- */
4
- export * as bsky from "./internal/bsky.js";
5
- //# sourceMappingURL=internal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/lexicons/internal.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as bsky from \"./internal/bsky.js\";\n"]}