@clioplaylists/clio 0.1.6 → 0.1.7

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 (145) hide show
  1. package/dist/.env +7 -0
  2. package/dist/api/health.js +3 -10
  3. package/dist/api/index.js +2 -39
  4. package/dist/api/util.js +6 -10
  5. package/dist/auth-verifier.js +165 -273
  6. package/dist/client.js +8 -15
  7. package/dist/config.js +7 -23
  8. package/dist/context.js +3 -10
  9. package/dist/dataplane/client.js +25 -70
  10. package/dist/dataplane/index.js +2 -18
  11. package/dist/dataplane/server/background.js +8 -29
  12. package/dist/dataplane/server/db/database-schema.js +1 -2
  13. package/dist/dataplane/server/db/db.js +27 -103
  14. package/dist/dataplane/server/db/index.js +1 -17
  15. package/dist/dataplane/server/db/migrations/20230309T045948368Z-init.js +7 -11
  16. package/dist/dataplane/server/db/migrations/20230420T211446071Z-did-cache.js +2 -6
  17. package/dist/dataplane/server/db/migrations/index.js +2 -38
  18. package/dist/dataplane/server/db/migrations/provider.js +5 -17
  19. package/dist/dataplane/server/db/pagination.js +21 -37
  20. package/dist/dataplane/server/db/tables/actor-sync.js +1 -4
  21. package/dist/dataplane/server/db/tables/actor.js +1 -4
  22. package/dist/dataplane/server/db/tables/artist-list-item.js +1 -4
  23. package/dist/dataplane/server/db/tables/artist.js +1 -4
  24. package/dist/dataplane/server/db/tables/playlist-idea.js +1 -4
  25. package/dist/dataplane/server/db/tables/playlist-item.js +1 -4
  26. package/dist/dataplane/server/db/tables/playlist.js +1 -4
  27. package/dist/dataplane/server/db/tables/profile.js +1 -4
  28. package/dist/dataplane/server/db/tables/record.js +1 -4
  29. package/dist/dataplane/server/db/tables/song.js +1 -4
  30. package/dist/dataplane/server/db/types.js +1 -2
  31. package/dist/dataplane/server/db/util.js +18 -26
  32. package/dist/dataplane/server/index.js +17 -33
  33. package/dist/dataplane/server/indexing/index.js +39 -89
  34. package/dist/dataplane/server/indexing/plugins/playlist-idea.js +7 -44
  35. package/dist/dataplane/server/indexing/plugins/profile.js +5 -42
  36. package/dist/dataplane/server/indexing/processor.js +11 -29
  37. package/dist/dataplane/server/routes/identity.js +11 -13
  38. package/dist/dataplane/server/routes/index.js +10 -15
  39. package/dist/dataplane/server/routes/profile.js +9 -11
  40. package/dist/dataplane/server/routes/records.js +14 -51
  41. package/dist/dataplane/server/routes/sync.js +1 -3
  42. package/dist/dataplane/server/subscription.js +19 -47
  43. package/dist/error.js +5 -9
  44. package/dist/index.js +29 -89
  45. package/dist/lexicons/index.js +52 -227
  46. package/dist/lexicons/lexicons.js +5 -8
  47. package/dist/lexicons/types/com/atproto/admin/defs.js +27 -39
  48. package/dist/lexicons/types/com/atproto/admin/deleteAccount.js +1 -2
  49. package/dist/lexicons/types/com/atproto/admin/disableAccountInvites.js +1 -2
  50. package/dist/lexicons/types/com/atproto/admin/disableInviteCodes.js +1 -2
  51. package/dist/lexicons/types/com/atproto/admin/enableAccountInvites.js +1 -2
  52. package/dist/lexicons/types/com/atproto/admin/getAccountInfo.js +1 -2
  53. package/dist/lexicons/types/com/atproto/admin/getAccountInfos.js +1 -2
  54. package/dist/lexicons/types/com/atproto/admin/getInviteCodes.js +1 -2
  55. package/dist/lexicons/types/com/atproto/admin/getSubjectStatus.js +1 -2
  56. package/dist/lexicons/types/com/atproto/admin/searchAccounts.js +1 -2
  57. package/dist/lexicons/types/com/atproto/admin/sendEmail.js +1 -2
  58. package/dist/lexicons/types/com/atproto/admin/updateAccountEmail.js +1 -2
  59. package/dist/lexicons/types/com/atproto/admin/updateAccountHandle.js +1 -2
  60. package/dist/lexicons/types/com/atproto/admin/updateAccountPassword.js +1 -2
  61. package/dist/lexicons/types/com/atproto/admin/updateSubjectStatus.js +1 -2
  62. package/dist/lexicons/types/com/atproto/identity/defs.js +7 -11
  63. package/dist/lexicons/types/com/atproto/identity/getRecommendedDidCredentials.js +1 -2
  64. package/dist/lexicons/types/com/atproto/identity/refreshIdentity.js +1 -2
  65. package/dist/lexicons/types/com/atproto/identity/requestPlcOperationSignature.js +1 -2
  66. package/dist/lexicons/types/com/atproto/identity/resolveDid.js +1 -2
  67. package/dist/lexicons/types/com/atproto/identity/resolveHandle.js +1 -2
  68. package/dist/lexicons/types/com/atproto/identity/resolveIdentity.js +1 -2
  69. package/dist/lexicons/types/com/atproto/identity/signPlcOperation.js +1 -2
  70. package/dist/lexicons/types/com/atproto/identity/submitPlcOperation.js +1 -2
  71. package/dist/lexicons/types/com/atproto/identity/updateHandle.js +1 -2
  72. package/dist/lexicons/types/com/atproto/label/defs.js +27 -39
  73. package/dist/lexicons/types/com/atproto/label/queryLabels.js +1 -2
  74. package/dist/lexicons/types/com/atproto/label/subscribeLabels.js +12 -18
  75. package/dist/lexicons/types/com/atproto/lexicon/schema.js +7 -11
  76. package/dist/lexicons/types/com/atproto/moderation/createReport.js +1 -2
  77. package/dist/lexicons/types/com/atproto/moderation/defs.js +7 -10
  78. package/dist/lexicons/types/com/atproto/repo/applyWrites.js +32 -46
  79. package/dist/lexicons/types/com/atproto/repo/createRecord.js +1 -2
  80. package/dist/lexicons/types/com/atproto/repo/defs.js +7 -11
  81. package/dist/lexicons/types/com/atproto/repo/deleteRecord.js +1 -2
  82. package/dist/lexicons/types/com/atproto/repo/describeRepo.js +1 -2
  83. package/dist/lexicons/types/com/atproto/repo/getRecord.js +1 -2
  84. package/dist/lexicons/types/com/atproto/repo/importRepo.js +1 -2
  85. package/dist/lexicons/types/com/atproto/repo/listMissingBlobs.js +7 -11
  86. package/dist/lexicons/types/com/atproto/repo/listRecords.js +7 -11
  87. package/dist/lexicons/types/com/atproto/repo/putRecord.js +1 -2
  88. package/dist/lexicons/types/com/atproto/repo/strongRef.js +7 -11
  89. package/dist/lexicons/types/com/atproto/repo/uploadBlob.js +1 -2
  90. package/dist/lexicons/types/com/atproto/server/activateAccount.js +1 -2
  91. package/dist/lexicons/types/com/atproto/server/checkAccountStatus.js +1 -2
  92. package/dist/lexicons/types/com/atproto/server/confirmEmail.js +1 -2
  93. package/dist/lexicons/types/com/atproto/server/createAccount.js +1 -2
  94. package/dist/lexicons/types/com/atproto/server/createAppPassword.js +7 -11
  95. package/dist/lexicons/types/com/atproto/server/createInviteCode.js +1 -2
  96. package/dist/lexicons/types/com/atproto/server/createInviteCodes.js +7 -11
  97. package/dist/lexicons/types/com/atproto/server/createSession.js +1 -2
  98. package/dist/lexicons/types/com/atproto/server/deactivateAccount.js +1 -2
  99. package/dist/lexicons/types/com/atproto/server/defs.js +12 -18
  100. package/dist/lexicons/types/com/atproto/server/deleteAccount.js +1 -2
  101. package/dist/lexicons/types/com/atproto/server/deleteSession.js +1 -2
  102. package/dist/lexicons/types/com/atproto/server/describeServer.js +12 -18
  103. package/dist/lexicons/types/com/atproto/server/getAccountInviteCodes.js +1 -2
  104. package/dist/lexicons/types/com/atproto/server/getServiceAuth.js +1 -2
  105. package/dist/lexicons/types/com/atproto/server/getSession.js +1 -2
  106. package/dist/lexicons/types/com/atproto/server/listAppPasswords.js +7 -11
  107. package/dist/lexicons/types/com/atproto/server/refreshSession.js +1 -2
  108. package/dist/lexicons/types/com/atproto/server/requestAccountDelete.js +1 -2
  109. package/dist/lexicons/types/com/atproto/server/requestEmailConfirmation.js +1 -2
  110. package/dist/lexicons/types/com/atproto/server/requestEmailUpdate.js +1 -2
  111. package/dist/lexicons/types/com/atproto/server/requestPasswordReset.js +1 -2
  112. package/dist/lexicons/types/com/atproto/server/reserveSigningKey.js +1 -2
  113. package/dist/lexicons/types/com/atproto/server/resetPassword.js +1 -2
  114. package/dist/lexicons/types/com/atproto/server/revokeAppPassword.js +1 -2
  115. package/dist/lexicons/types/com/atproto/server/updateEmail.js +1 -2
  116. package/dist/lexicons/types/com/atproto/sync/getBlob.js +1 -2
  117. package/dist/lexicons/types/com/atproto/sync/getBlocks.js +1 -2
  118. package/dist/lexicons/types/com/atproto/sync/getCheckout.js +1 -2
  119. package/dist/lexicons/types/com/atproto/sync/getHead.js +1 -2
  120. package/dist/lexicons/types/com/atproto/sync/getLatestCommit.js +1 -2
  121. package/dist/lexicons/types/com/atproto/sync/getRecord.js +1 -2
  122. package/dist/lexicons/types/com/atproto/sync/getRepo.js +1 -2
  123. package/dist/lexicons/types/com/atproto/sync/getRepoStatus.js +1 -2
  124. package/dist/lexicons/types/com/atproto/sync/listBlobs.js +1 -2
  125. package/dist/lexicons/types/com/atproto/sync/listRepos.js +7 -11
  126. package/dist/lexicons/types/com/atproto/sync/listReposByCollection.js +7 -11
  127. package/dist/lexicons/types/com/atproto/sync/notifyOfUpdate.js +1 -2
  128. package/dist/lexicons/types/com/atproto/sync/requestCrawl.js +1 -2
  129. package/dist/lexicons/types/com/atproto/sync/subscribeRepos.js +32 -46
  130. package/dist/lexicons/types/com/atproto/temp/addReservedHandle.js +1 -2
  131. package/dist/lexicons/types/com/atproto/temp/checkSignupQueue.js +1 -2
  132. package/dist/lexicons/types/com/atproto/temp/fetchLabels.js +1 -2
  133. package/dist/lexicons/types/com/atproto/temp/requestPhoneVerification.js +1 -2
  134. package/dist/lexicons/types/com/clioplaylists/alpha/actor/profile.js +7 -11
  135. package/dist/lexicons/types/com/clioplaylists/alpha/feed/defs.js +12 -18
  136. package/dist/lexicons/types/com/clioplaylists/alpha/feed/getSongs.js +1 -2
  137. package/dist/lexicons/types/com/clioplaylists/alpha/feed/playlistIdea.js +17 -25
  138. package/dist/lexicons/util.js +2 -6
  139. package/dist/logger.js +10 -16
  140. package/dist/rpc/clio_connect.js +30 -33
  141. package/dist/rpc/clio_pb.js +402 -956
  142. package/dist/util/retry.js +7 -10
  143. package/dist/util/uris.js +3 -6
  144. package/dist/util.js +17 -60
  145. package/package.json +4 -4
@@ -1,41 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.makePlugin = void 0;
37
- const lex = __importStar(require("../../../../lexicons/lexicons"));
38
- const processor_1 = require("../processor");
1
+ import * as lex from '../../../../lexicons/lexicons';
2
+ import { RecordProcessor } from '../processor';
39
3
  const lexId = lex.ids.ComClioplaylistsAlphaActorProfile;
40
4
  const insertFn = async (db, uri, cid, obj, timestamp) => {
41
5
  if (uri.rkey !== 'self')
@@ -69,13 +33,12 @@ const deleteFn = async (db, uri) => {
69
33
  .executeTakeFirst();
70
34
  return deleted || null;
71
35
  };
72
- const makePlugin = (db) => {
73
- return new processor_1.RecordProcessor(db, {
36
+ export const makePlugin = (db) => {
37
+ return new RecordProcessor(db, {
74
38
  lexId,
75
39
  insertFn,
76
40
  findDuplicate,
77
41
  deleteFn,
78
42
  });
79
43
  };
80
- exports.makePlugin = makePlugin;
81
- exports.default = exports.makePlugin;
44
+ export default makePlugin;
@@ -1,28 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecordProcessor = void 0;
4
- const lexicon_1 = require("@atproto/lexicon");
5
- const lexicons_1 = require("../../../lexicons/lexicons");
6
- class RecordProcessor {
1
+ import { stringifyLex } from '@atproto/lexicon';
2
+ import { lexicons } from '../../../lexicons/lexicons';
3
+ export class RecordProcessor {
4
+ params;
5
+ collection;
6
+ db;
7
7
  constructor(appDb, params) {
8
- Object.defineProperty(this, "params", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: params
13
- });
14
- Object.defineProperty(this, "collection", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "db", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
8
+ this.params = params;
26
9
  this.db = appDb.db;
27
10
  this.collection = this.params.lexId;
28
11
  }
@@ -36,7 +19,7 @@ class RecordProcessor {
36
19
  }
37
20
  }
38
21
  assertValidRecord(obj) {
39
- lexicons_1.lexicons.assertValidRecord(this.params.lexId, obj);
22
+ lexicons.assertValidRecord(this.params.lexId, obj);
40
23
  }
41
24
  async insertRecord(uri, cid, obj, timestamp) {
42
25
  this.assertValidRecord(obj);
@@ -46,7 +29,7 @@ class RecordProcessor {
46
29
  uri: uri.toString(),
47
30
  cid: cid.toString(),
48
31
  did: uri.host,
49
- json: (0, lexicon_1.stringifyLex)(obj),
32
+ json: stringifyLex(obj),
50
33
  indexed_at: timestamp,
51
34
  })
52
35
  .onConflict((oc) => oc.doNothing())
@@ -64,7 +47,7 @@ class RecordProcessor {
64
47
  .where('uri', '=', uri.toString())
65
48
  .set({
66
49
  cid: cid.toString(),
67
- json: (0, lexicon_1.stringifyLex)(obj),
50
+ json: stringifyLex(obj),
68
51
  indexed_at: timestamp,
69
52
  })
70
53
  .execute();
@@ -86,5 +69,4 @@ class RecordProcessor {
86
69
  await this.params.deleteFn(this.db, uri);
87
70
  }
88
71
  }
89
- exports.RecordProcessor = RecordProcessor;
90
- exports.default = RecordProcessor;
72
+ export default RecordProcessor;
@@ -1,24 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const identity_1 = require("@atproto/identity");
4
- const protobuf_1 = require("@bufbuild/protobuf");
5
- const connect_1 = require("@connectrpc/connect");
6
- exports.default = (_db, idResolver) => ({
1
+ import { getDid, getHandle } from '@atproto/identity';
2
+ import { Timestamp } from '@bufbuild/protobuf';
3
+ import { Code, ConnectError } from '@connectrpc/connect';
4
+ export default (_db, idResolver) => ({
7
5
  async getIdentityByDid(req) {
8
6
  const doc = await idResolver.did.resolve(req.did);
9
7
  if (!doc) {
10
- throw new connect_1.ConnectError('identity not found', connect_1.Code.NotFound);
8
+ throw new ConnectError('identity not found', Code.NotFound);
11
9
  }
12
10
  return getResultFromDoc(doc);
13
11
  },
14
12
  async getIdentityByHandle(req) {
15
13
  const did = await idResolver.handle.resolve(req.handle);
16
14
  if (!did) {
17
- throw new connect_1.ConnectError('identity not found', connect_1.Code.NotFound);
15
+ throw new ConnectError('identity not found', Code.NotFound);
18
16
  }
19
17
  const doc = await idResolver.did.resolve(did);
20
- if (!doc || did !== (0, identity_1.getDid)(doc)) {
21
- throw new connect_1.ConnectError('identity not found', connect_1.Code.NotFound);
18
+ if (!doc || did !== getDid(doc)) {
19
+ throw new ConnectError('identity not found', Code.NotFound);
22
20
  }
23
21
  return getResultFromDoc(doc);
24
22
  },
@@ -47,10 +45,10 @@ const getResultFromDoc = (doc) => {
47
45
  };
48
46
  });
49
47
  return {
50
- did: (0, identity_1.getDid)(doc),
51
- handle: (0, identity_1.getHandle)(doc),
48
+ did: getDid(doc),
49
+ handle: getHandle(doc),
52
50
  keys: Buffer.from(JSON.stringify(keys)),
53
51
  services: Buffer.from(JSON.stringify(services)),
54
- updated: protobuf_1.Timestamp.fromDate(new Date()),
52
+ updated: Timestamp.fromDate(new Date()),
55
53
  };
56
54
  };
@@ -1,18 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const clio_connect_1 = require("../../../rpc/clio_connect");
7
- const identity_1 = __importDefault(require("./identity"));
8
- const profile_1 = __importDefault(require("./profile"));
9
- const records_1 = __importDefault(require("./records"));
10
- const sync_1 = __importDefault(require("./sync"));
11
- exports.default = (db, idResolver) => (router) => router.service(clio_connect_1.ClioService, {
12
- ...(0, identity_1.default)(db, idResolver),
13
- ...(0, profile_1.default)(db),
14
- ...(0, records_1.default)(db),
15
- ...(0, sync_1.default)(db),
1
+ import { ClioService } from '../../../rpc/clio_connect';
2
+ import identity from './identity';
3
+ import profile from './profile';
4
+ import records from './records';
5
+ import sync from './sync';
6
+ export default (db, idResolver) => (router) => router.service(ClioService, {
7
+ ...identity(db, idResolver),
8
+ ...profile(db),
9
+ ...records(db),
10
+ ...sync(db),
16
11
  async healthCheck() {
17
12
  return {};
18
13
  },
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("@atproto/common");
4
- const util_1 = require("../../../util");
5
- const records_1 = require("./records");
6
- exports.default = (db) => ({
1
+ import { keyBy } from '@atproto/common';
2
+ import { parseRecordBytes } from '../../../util';
3
+ import { getRecords } from './records';
4
+ export default (db) => ({
7
5
  async getActors(req) {
8
6
  const { dids } = req;
9
7
  if (dids.length === 0) {
@@ -13,13 +11,13 @@ exports.default = (db) => ({
13
11
  const chatDeclarationUris = dids.map((did) => `at://${did}/chat.bsky.actor.declaration/self`);
14
12
  const [handlesRes, profiles, chatDeclarations] = await Promise.all([
15
13
  db.db.selectFrom('actor').selectAll().execute(),
16
- (0, records_1.getRecords)(db)({ uris: profileUris }),
17
- (0, records_1.getRecords)(db)({ uris: chatDeclarationUris }),
14
+ getRecords(db)({ uris: profileUris }),
15
+ getRecords(db)({ uris: chatDeclarationUris }),
18
16
  ]);
19
- const byDid = (0, common_1.keyBy)(handlesRes, 'did');
17
+ const byDid = keyBy(handlesRes, 'did');
20
18
  const actors = dids.map((did, i) => {
21
19
  const row = byDid.get(did);
22
- const chatDeclaration = (0, util_1.parseRecordBytes)(chatDeclarations.records[i].record);
20
+ const chatDeclaration = parseRecordBytes(chatDeclarations.records[i].record);
23
21
  return {
24
22
  exists: !!row,
25
23
  handle: row?.handle ?? undefined,
@@ -46,7 +44,7 @@ exports.default = (db) => ({
46
44
  .where('handle', 'in', handles)
47
45
  .selectAll()
48
46
  .execute();
49
- const byHandle = (0, common_1.keyBy)(res, 'handle');
47
+ const byHandle = keyBy(res, 'handle');
50
48
  const dids = handles.map((handle) => byHandle.get(handle)?.did ?? '');
51
49
  return { dids };
52
50
  },
@@ -1,51 +1,15 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
1
+ import { keyBy } from '@atproto/common';
2
+ import { AtUri } from '@atproto/syntax';
3
+ import { Timestamp } from '@bufbuild/protobuf';
4
+ import * as ui8 from 'uint8arrays';
5
+ import { ids } from '../../../lexicons/lexicons';
6
+ import { Record } from '../../../rpc/clio_pb';
7
+ export default (db) => ({
8
+ getProfileRecords: getRecords(db, ids.ComClioplaylistsAlphaActorProfile),
17
9
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getRecords = void 0;
37
- const common_1 = require("@atproto/common");
38
- const syntax_1 = require("@atproto/syntax");
39
- const protobuf_1 = require("@bufbuild/protobuf");
40
- const ui8 = __importStar(require("uint8arrays"));
41
- const lexicons_1 = require("../../../lexicons/lexicons");
42
- const clio_pb_1 = require("../../../rpc/clio_pb");
43
- exports.default = (db) => ({
44
- getProfileRecords: (0, exports.getRecords)(db, lexicons_1.ids.ComClioplaylistsAlphaActorProfile),
45
- });
46
- const getRecords = (db, collection) => async (req) => {
10
+ export const getRecords = (db, collection) => async (req) => {
47
11
  const validUris = collection
48
- ? req.uris.filter((uri) => new syntax_1.AtUri(uri).collection === collection)
12
+ ? req.uris.filter((uri) => new AtUri(uri).collection === collection)
49
13
  : req.uris;
50
14
  const res = validUris.length
51
15
  ? await db.db
@@ -54,19 +18,19 @@ const getRecords = (db, collection) => async (req) => {
54
18
  .where('uri', 'in', validUris)
55
19
  .execute()
56
20
  : [];
57
- const byUri = (0, common_1.keyBy)(res, 'uri');
21
+ const byUri = keyBy(res, 'uri');
58
22
  const records = req.uris.map((uri) => {
59
23
  const row = byUri.get(uri);
60
24
  const json = row ? row.json : JSON.stringify(null);
61
25
  const createdAtRaw = new Date(JSON.parse(json)?.['createdAt']);
62
26
  const createdAt = !isNaN(createdAtRaw.getTime())
63
- ? protobuf_1.Timestamp.fromDate(createdAtRaw)
27
+ ? Timestamp.fromDate(createdAtRaw)
64
28
  : undefined;
65
29
  const indexedAt = row?.indexed_at
66
- ? protobuf_1.Timestamp.fromDate(new Date(row?.indexed_at))
30
+ ? Timestamp.fromDate(new Date(row?.indexed_at))
67
31
  : undefined;
68
32
  const recordBytes = ui8.fromString(json, 'utf8');
69
- return new clio_pb_1.Record({
33
+ return new Record({
70
34
  record: recordBytes,
71
35
  cid: row?.cid,
72
36
  createdAt,
@@ -78,7 +42,6 @@ const getRecords = (db, collection) => async (req) => {
78
42
  });
79
43
  return { records };
80
44
  };
81
- exports.getRecords = getRecords;
82
45
  const compositeTime = (ts1, ts2) => {
83
46
  if (!ts1)
84
47
  return ts2;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = (db) => ({
1
+ export default (db) => ({
4
2
  async getLatestRev(req) {
5
3
  const res = await db.db
6
4
  .selectFrom('actor_sync')
@@ -1,46 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RepoSubscription = void 0;
4
- const repo_1 = require("@atproto/repo");
5
- const sync_1 = require("@atproto/sync");
6
- const logger_1 = require("../../logger");
7
- const background_1 = require("./background");
8
- const indexing_1 = require("./indexing");
9
- class RepoSubscription {
1
+ import { WriteOpAction } from '@atproto/repo';
2
+ import { Firehose, MemoryRunner } from '@atproto/sync';
3
+ import { subLogger as log } from '../../logger';
4
+ import { BackgroundQueue } from './background';
5
+ import { IndexingService } from './indexing';
6
+ export class RepoSubscription {
7
+ opts;
8
+ firehose;
9
+ runner;
10
+ background;
11
+ indexingSvc;
10
12
  constructor(opts) {
11
- Object.defineProperty(this, "opts", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: opts
16
- });
17
- Object.defineProperty(this, "firehose", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
- Object.defineProperty(this, "runner", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: void 0
28
- });
29
- Object.defineProperty(this, "background", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: void 0
34
- });
35
- Object.defineProperty(this, "indexingSvc", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: void 0
40
- });
13
+ this.opts = opts;
41
14
  const { service, db, idResolver } = opts;
42
- this.background = new background_1.BackgroundQueue(db);
43
- this.indexingSvc = new indexing_1.IndexingService(db, idResolver);
15
+ this.background = new BackgroundQueue(db);
16
+ this.indexingSvc = new IndexingService(db, idResolver);
44
17
  const { runner, firehose } = createFirehose({
45
18
  idResolver,
46
19
  service,
@@ -73,17 +46,16 @@ class RepoSubscription {
73
46
  await this.background.processAll();
74
47
  }
75
48
  }
76
- exports.RepoSubscription = RepoSubscription;
77
49
  const createFirehose = (opts) => {
78
50
  const { idResolver, service, indexingSvc } = opts;
79
- const runner = new sync_1.MemoryRunner({ startCursor: 0 });
80
- const firehose = new sync_1.Firehose({
51
+ const runner = new MemoryRunner({ startCursor: 0 });
52
+ const firehose = new Firehose({
81
53
  idResolver,
82
54
  runner,
83
55
  service,
84
56
  unauthenticatedHandles: true, // indexing service handles these
85
57
  unauthenticatedCommits: true, // @TODO there seems to be a very rare issue where the authenticator thinks a block is missing in deletion ops
86
- onError: (err) => logger_1.subLogger.error({ err }, 'error in subscription'),
58
+ onError: (err) => log.error({ err }, 'error in subscription'),
87
59
  handleEvent: async (evt) => {
88
60
  if (evt.event === 'identity') {
89
61
  await indexingSvc.indexHandle(evt.did, evt.time, true);
@@ -100,8 +72,8 @@ const createFirehose = (opts) => {
100
72
  const indexFn = evt.event === 'delete'
101
73
  ? indexingSvc.deleteRecord(evt.uri)
102
74
  : indexingSvc.indexRecord(evt.uri, evt.cid, evt.record, evt.event === 'create'
103
- ? repo_1.WriteOpAction.Create
104
- : repo_1.WriteOpAction.Update, evt.time);
75
+ ? WriteOpAction.Create
76
+ : WriteOpAction.Update, evt.time);
105
77
  await Promise.all([
106
78
  indexFn,
107
79
  indexingSvc.setCommitLastSeen(evt.did, evt.commit, evt.rev),
package/dist/error.js CHANGED
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = void 0;
4
- const xrpc_server_1 = require("@atproto/xrpc-server");
5
- const logger_1 = require("./logger");
6
- const handler = (err, _req, res, next) => {
7
- logger_1.httpLogger.error(err, 'unexpected internal server error');
1
+ import { XRPCError } from '@atproto/xrpc-server';
2
+ import { httpLogger as log } from './logger';
3
+ export const handler = (err, _req, res, next) => {
4
+ log.error(err, 'unexpected internal server error');
8
5
  if (res.headersSent) {
9
6
  return next(err);
10
7
  }
11
- const serverError = xrpc_server_1.XRPCError.fromError(err);
8
+ const serverError = XRPCError.fromError(err);
12
9
  res.status(serverError.type).json(serverError.payload);
13
10
  };
14
- exports.handler = handler;
package/dist/index.js CHANGED
@@ -1,97 +1,38 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ClioAppView = void 0;
40
- const common_1 = require("@atproto/common");
41
- const cors_1 = __importDefault(require("cors"));
42
- const dotenv_1 = require("dotenv");
43
- const events_1 = __importDefault(require("events"));
44
- const express_1 = __importDefault(require("express"));
45
- const http_terminator_1 = require("http-terminator");
46
- const api_1 = __importStar(require("./api"));
47
- const client_1 = require("./client");
48
- const context_1 = __importDefault(require("./context"));
49
- const error = __importStar(require("./error"));
50
- const lexicons_1 = require("./lexicons");
51
- const logger_1 = require("./logger");
52
- (0, dotenv_1.config)();
53
- class ClioAppView {
1
+ import { DAY, SECOND } from '@atproto/common';
2
+ import cors from 'cors';
3
+ import { config } from 'dotenv';
4
+ import events from 'events';
5
+ import express from 'express';
6
+ import { createHttpTerminator } from 'http-terminator';
7
+ import API, { health } from './api';
8
+ import { createBaseClient } from './client';
9
+ import AppContext from './context';
10
+ import * as error from './error';
11
+ import { createServer } from './lexicons';
12
+ import { loggerMiddleware } from './logger';
13
+ config();
14
+ export class ClioAppView {
15
+ ctx;
16
+ app;
17
+ server;
18
+ terminator;
54
19
  constructor(opts) {
55
- Object.defineProperty(this, "ctx", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
- Object.defineProperty(this, "app", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
67
- Object.defineProperty(this, "server", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: void 0
72
- });
73
- Object.defineProperty(this, "terminator", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
20
  this.ctx = opts.ctx;
80
21
  this.app = opts.app;
81
22
  }
82
23
  static create(opts) {
83
24
  const { config } = opts;
84
- const app = (0, express_1.default)();
85
- app.use((0, cors_1.default)({ maxAge: common_1.DAY / common_1.SECOND }));
86
- app.use(logger_1.loggerMiddleware);
87
- const dataplane = (0, client_1.createBaseClient)('http://localhost:4000', {});
88
- const server = (0, lexicons_1.createServer)();
89
- const ctx = new context_1.default({
25
+ const app = express();
26
+ app.use(cors({ maxAge: DAY / SECOND }));
27
+ app.use(loggerMiddleware);
28
+ const dataplane = createBaseClient('http://localhost:4000', {});
29
+ const server = createServer();
30
+ const ctx = new AppContext({
90
31
  cfg: config,
91
32
  dataplane,
92
33
  });
93
- const api = (0, api_1.default)(server, ctx);
94
- app.use(api_1.health.createRouter(ctx));
34
+ const api = API(server, ctx);
35
+ app.use(health.createRouter(ctx));
95
36
  app.use(api.xrpc.router);
96
37
  app.use(error.handler);
97
38
  return new ClioAppView({ ctx, app });
@@ -101,8 +42,8 @@ class ClioAppView {
101
42
  const server = this.app.listen(this.ctx.cfg.port);
102
43
  this.server = server;
103
44
  server.keepAliveTimeout = 90000;
104
- this.terminator = (0, http_terminator_1.createHttpTerminator)({ server });
105
- await events_1.default.once(server, 'listening');
45
+ this.terminator = createHttpTerminator({ server });
46
+ await events.once(server, 'listening');
106
47
  const { port } = server.address();
107
48
  this.ctx.cfg.assignPort(port);
108
49
  return server;
@@ -111,5 +52,4 @@ class ClioAppView {
111
52
  await this.terminator?.terminate();
112
53
  }
113
54
  }
114
- exports.ClioAppView = ClioAppView;
115
- exports.default = ClioAppView;
55
+ export default ClioAppView;