@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.
- package/dist/.env +7 -0
- package/dist/api/health.js +3 -10
- package/dist/api/index.js +2 -39
- package/dist/api/util.js +6 -10
- package/dist/auth-verifier.js +165 -273
- package/dist/client.js +8 -15
- package/dist/config.js +7 -23
- package/dist/context.js +3 -10
- package/dist/dataplane/client.js +25 -70
- package/dist/dataplane/index.js +2 -18
- package/dist/dataplane/server/background.js +8 -29
- package/dist/dataplane/server/db/database-schema.js +1 -2
- package/dist/dataplane/server/db/db.js +27 -103
- package/dist/dataplane/server/db/index.js +1 -17
- package/dist/dataplane/server/db/migrations/20230309T045948368Z-init.js +7 -11
- package/dist/dataplane/server/db/migrations/20230420T211446071Z-did-cache.js +2 -6
- package/dist/dataplane/server/db/migrations/index.js +2 -38
- package/dist/dataplane/server/db/migrations/provider.js +5 -17
- package/dist/dataplane/server/db/pagination.js +21 -37
- package/dist/dataplane/server/db/tables/actor-sync.js +1 -4
- package/dist/dataplane/server/db/tables/actor.js +1 -4
- package/dist/dataplane/server/db/tables/artist-list-item.js +1 -4
- package/dist/dataplane/server/db/tables/artist.js +1 -4
- package/dist/dataplane/server/db/tables/playlist-idea.js +1 -4
- package/dist/dataplane/server/db/tables/playlist-item.js +1 -4
- package/dist/dataplane/server/db/tables/playlist.js +1 -4
- package/dist/dataplane/server/db/tables/profile.js +1 -4
- package/dist/dataplane/server/db/tables/record.js +1 -4
- package/dist/dataplane/server/db/tables/song.js +1 -4
- package/dist/dataplane/server/db/types.js +1 -2
- package/dist/dataplane/server/db/util.js +18 -26
- package/dist/dataplane/server/index.js +17 -33
- package/dist/dataplane/server/indexing/index.js +39 -89
- package/dist/dataplane/server/indexing/plugins/playlist-idea.js +7 -44
- package/dist/dataplane/server/indexing/plugins/profile.js +5 -42
- package/dist/dataplane/server/indexing/processor.js +11 -29
- package/dist/dataplane/server/routes/identity.js +11 -13
- package/dist/dataplane/server/routes/index.js +10 -15
- package/dist/dataplane/server/routes/profile.js +9 -11
- package/dist/dataplane/server/routes/records.js +14 -51
- package/dist/dataplane/server/routes/sync.js +1 -3
- package/dist/dataplane/server/subscription.js +19 -47
- package/dist/error.js +5 -9
- package/dist/index.js +29 -89
- package/dist/lexicons/index.js +52 -227
- package/dist/lexicons/lexicons.js +5 -8
- package/dist/lexicons/types/com/atproto/admin/defs.js +27 -39
- package/dist/lexicons/types/com/atproto/admin/deleteAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/disableAccountInvites.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/disableInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/enableAccountInvites.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getAccountInfo.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getAccountInfos.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/getSubjectStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/searchAccounts.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/sendEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateAccountPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/admin/updateSubjectStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/defs.js +7 -11
- package/dist/lexicons/types/com/atproto/identity/getRecommendedDidCredentials.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/refreshIdentity.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/requestPlcOperationSignature.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveDid.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/resolveIdentity.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/signPlcOperation.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/submitPlcOperation.js +1 -2
- package/dist/lexicons/types/com/atproto/identity/updateHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/label/defs.js +27 -39
- package/dist/lexicons/types/com/atproto/label/queryLabels.js +1 -2
- package/dist/lexicons/types/com/atproto/label/subscribeLabels.js +12 -18
- package/dist/lexicons/types/com/atproto/lexicon/schema.js +7 -11
- package/dist/lexicons/types/com/atproto/moderation/createReport.js +1 -2
- package/dist/lexicons/types/com/atproto/moderation/defs.js +7 -10
- package/dist/lexicons/types/com/atproto/repo/applyWrites.js +32 -46
- package/dist/lexicons/types/com/atproto/repo/createRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/defs.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/deleteRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/describeRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/getRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/importRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/listMissingBlobs.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/listRecords.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/putRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/repo/strongRef.js +7 -11
- package/dist/lexicons/types/com/atproto/repo/uploadBlob.js +1 -2
- package/dist/lexicons/types/com/atproto/server/activateAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/checkAccountStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/server/confirmEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createAppPassword.js +7 -11
- package/dist/lexicons/types/com/atproto/server/createInviteCode.js +1 -2
- package/dist/lexicons/types/com/atproto/server/createInviteCodes.js +7 -11
- package/dist/lexicons/types/com/atproto/server/createSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/deactivateAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/defs.js +12 -18
- package/dist/lexicons/types/com/atproto/server/deleteAccount.js +1 -2
- package/dist/lexicons/types/com/atproto/server/deleteSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/describeServer.js +12 -18
- package/dist/lexicons/types/com/atproto/server/getAccountInviteCodes.js +1 -2
- package/dist/lexicons/types/com/atproto/server/getServiceAuth.js +1 -2
- package/dist/lexicons/types/com/atproto/server/getSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/listAppPasswords.js +7 -11
- package/dist/lexicons/types/com/atproto/server/refreshSession.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestAccountDelete.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestEmailConfirmation.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestEmailUpdate.js +1 -2
- package/dist/lexicons/types/com/atproto/server/requestPasswordReset.js +1 -2
- package/dist/lexicons/types/com/atproto/server/reserveSigningKey.js +1 -2
- package/dist/lexicons/types/com/atproto/server/resetPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/server/revokeAppPassword.js +1 -2
- package/dist/lexicons/types/com/atproto/server/updateEmail.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getBlob.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getBlocks.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getCheckout.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getHead.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getLatestCommit.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRecord.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRepo.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/getRepoStatus.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/listBlobs.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/listRepos.js +7 -11
- package/dist/lexicons/types/com/atproto/sync/listReposByCollection.js +7 -11
- package/dist/lexicons/types/com/atproto/sync/notifyOfUpdate.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/requestCrawl.js +1 -2
- package/dist/lexicons/types/com/atproto/sync/subscribeRepos.js +32 -46
- package/dist/lexicons/types/com/atproto/temp/addReservedHandle.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/checkSignupQueue.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/fetchLabels.js +1 -2
- package/dist/lexicons/types/com/atproto/temp/requestPhoneVerification.js +1 -2
- package/dist/lexicons/types/com/clioplaylists/alpha/actor/profile.js +7 -11
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/defs.js +12 -18
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/getSongs.js +1 -2
- package/dist/lexicons/types/com/clioplaylists/alpha/feed/playlistIdea.js +17 -25
- package/dist/lexicons/util.js +2 -6
- package/dist/logger.js +10 -16
- package/dist/rpc/clio_connect.js +30 -33
- package/dist/rpc/clio_pb.js +402 -956
- package/dist/util/retry.js +7 -10
- package/dist/util/uris.js +3 -6
- package/dist/util.js +17 -60
- package/package.json +4 -4
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
81
|
-
exports.default = exports.makePlugin;
|
|
44
|
+
export default makePlugin;
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
-
|
|
90
|
-
exports.default = RecordProcessor;
|
|
72
|
+
export default RecordProcessor;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
|
15
|
+
throw new ConnectError('identity not found', Code.NotFound);
|
|
18
16
|
}
|
|
19
17
|
const doc = await idResolver.did.resolve(did);
|
|
20
|
-
if (!doc || did !==
|
|
21
|
-
throw new
|
|
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:
|
|
51
|
-
handle:
|
|
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:
|
|
52
|
+
updated: Timestamp.fromDate(new Date()),
|
|
55
53
|
};
|
|
56
54
|
};
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
17
|
-
|
|
14
|
+
getRecords(db)({ uris: profileUris }),
|
|
15
|
+
getRecords(db)({ uris: chatDeclarationUris }),
|
|
18
16
|
]);
|
|
19
|
-
const byDid =
|
|
17
|
+
const byDid = keyBy(handlesRes, 'did');
|
|
20
18
|
const actors = dids.map((did, i) => {
|
|
21
19
|
const row = byDid.get(did);
|
|
22
|
-
const chatDeclaration =
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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
|
-
?
|
|
27
|
+
? Timestamp.fromDate(createdAtRaw)
|
|
64
28
|
: undefined;
|
|
65
29
|
const indexedAt = row?.indexed_at
|
|
66
|
-
?
|
|
30
|
+
? Timestamp.fromDate(new Date(row?.indexed_at))
|
|
67
31
|
: undefined;
|
|
68
32
|
const recordBytes = ui8.fromString(json, 'utf8');
|
|
69
|
-
return new
|
|
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,46 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
|
43
|
-
this.indexingSvc = new
|
|
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
|
|
80
|
-
const firehose = new
|
|
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) =>
|
|
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
|
-
?
|
|
104
|
-
:
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 =
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 = (
|
|
85
|
-
app.use((
|
|
86
|
-
app.use(
|
|
87
|
-
const dataplane =
|
|
88
|
-
const server =
|
|
89
|
-
const ctx = new
|
|
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 = (
|
|
94
|
-
app.use(
|
|
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 =
|
|
105
|
-
await
|
|
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
|
-
|
|
115
|
-
exports.default = ClioAppView;
|
|
55
|
+
export default ClioAppView;
|