@clioplaylists/clio 0.1.6 → 0.1.8
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/api/well-known.d.ts +3 -0
- package/dist/api/well-known.js +31 -0
- package/dist/auth-verifier.js +165 -273
- package/dist/client.js +8 -15
- package/dist/config.d.ts +2 -0
- package/dist/config.js +17 -23
- package/dist/context.d.ts +3 -0
- package/dist/context.js +6 -10
- package/dist/dataplane/client/hosts.d.ts +21 -0
- package/dist/dataplane/client/hosts.js +25 -0
- package/dist/dataplane/client/index.d.ts +11 -0
- package/dist/dataplane/client/index.js +97 -0
- 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.d.ts +2 -0
- package/dist/index.js +36 -90
- 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/start.js +9 -1
- 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,87 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.Database = void 0;
|
|
40
|
-
const kysely_1 = require("kysely");
|
|
41
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
42
|
-
const node_events_1 = __importDefault(require("node:events"));
|
|
43
|
-
const pg_1 = require("pg");
|
|
44
|
-
const logger_1 = require("../../../logger");
|
|
45
|
-
const migrations = __importStar(require("./migrations"));
|
|
46
|
-
const provider_1 = require("./migrations/provider");
|
|
47
|
-
class Database {
|
|
1
|
+
import { Kysely, Migrator, PostgresDialect, } from 'kysely';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import EventEmitter from 'node:events';
|
|
4
|
+
import { Pool as PgPool, types as pgTypes } from 'pg';
|
|
5
|
+
import { dbLogger } from '../../../logger';
|
|
6
|
+
import * as migrations from './migrations';
|
|
7
|
+
import { CtxMigrationProvider } from './migrations/provider';
|
|
8
|
+
export class Database {
|
|
9
|
+
opts;
|
|
10
|
+
pool;
|
|
11
|
+
db;
|
|
12
|
+
migrator;
|
|
13
|
+
txEvt = new EventEmitter();
|
|
14
|
+
destroyed = false;
|
|
48
15
|
constructor(opts, instances) {
|
|
49
|
-
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: opts
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "pool", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, "db", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: void 0
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, "migrator", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: void 0
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "txEvt", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: new node_events_1.default()
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, "destroyed", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: false
|
|
84
|
-
});
|
|
16
|
+
this.opts = opts;
|
|
85
17
|
// if instances are provided, use those
|
|
86
18
|
if (instances) {
|
|
87
19
|
this.db = instances.db;
|
|
@@ -92,14 +24,14 @@ class Database {
|
|
|
92
24
|
// else create a pool & connect
|
|
93
25
|
const { schema, url } = opts;
|
|
94
26
|
const pool = opts.pool ??
|
|
95
|
-
new
|
|
27
|
+
new PgPool({
|
|
96
28
|
connectionString: url,
|
|
97
29
|
max: opts.poolSize,
|
|
98
30
|
maxUses: opts.poolMaxUses,
|
|
99
31
|
idleTimeoutMillis: opts.poolIdleTimeoutMs,
|
|
100
32
|
});
|
|
101
33
|
// Select count(*) and other pg bigints as js integer
|
|
102
|
-
|
|
34
|
+
pgTypes.setTypeParser(pgTypes.builtins.INT8, (n) => parseInt(n, 10));
|
|
103
35
|
// Setup schema usage, primarily for test parallelism (each test suite runs in its own pg schema)
|
|
104
36
|
if (schema && !/^[a-z_]+$/i.test(schema)) {
|
|
105
37
|
throw new Error(`Postgres schema must only contain [A-Za-z_]: ${schema}`);
|
|
@@ -115,13 +47,13 @@ class Database {
|
|
|
115
47
|
}
|
|
116
48
|
});
|
|
117
49
|
this.pool = pool;
|
|
118
|
-
this.db = new
|
|
119
|
-
dialect: new
|
|
50
|
+
this.db = new Kysely({
|
|
51
|
+
dialect: new PostgresDialect({ pool }),
|
|
120
52
|
});
|
|
121
|
-
this.migrator = new
|
|
53
|
+
this.migrator = new Migrator({
|
|
122
54
|
db: this.db,
|
|
123
55
|
migrationTableSchema: opts.schema,
|
|
124
|
-
provider: new
|
|
56
|
+
provider: new CtxMigrationProvider(migrations, 'pg'),
|
|
125
57
|
});
|
|
126
58
|
}
|
|
127
59
|
get schema() {
|
|
@@ -155,10 +87,10 @@ class Database {
|
|
|
155
87
|
return this.db.isTransaction;
|
|
156
88
|
}
|
|
157
89
|
assertTransaction() {
|
|
158
|
-
(
|
|
90
|
+
assert(this.isTransaction, 'Transaction required');
|
|
159
91
|
}
|
|
160
92
|
assertNotTransaction() {
|
|
161
|
-
(
|
|
93
|
+
assert(!this.isTransaction, 'Cannot be in a transaction');
|
|
162
94
|
}
|
|
163
95
|
onCommit(fn) {
|
|
164
96
|
this.assertTransaction();
|
|
@@ -197,21 +129,13 @@ class Database {
|
|
|
197
129
|
this.destroyed = true;
|
|
198
130
|
}
|
|
199
131
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
const onClientError = (err) => logger_1.dbLogger.error({ err }, 'db client error');
|
|
132
|
+
export default Database;
|
|
133
|
+
const onPoolError = (err) => dbLogger.error({ err }, 'db pool error');
|
|
134
|
+
const onClientError = (err) => dbLogger.error({ err }, 'db client error');
|
|
204
135
|
// utils
|
|
205
136
|
// -------
|
|
206
137
|
class LeakyTxPlugin {
|
|
207
|
-
|
|
208
|
-
Object.defineProperty(this, "txOver", {
|
|
209
|
-
enumerable: true,
|
|
210
|
-
configurable: true,
|
|
211
|
-
writable: true,
|
|
212
|
-
value: false
|
|
213
|
-
});
|
|
214
|
-
}
|
|
138
|
+
txOver = false;
|
|
215
139
|
endTx() {
|
|
216
140
|
this.txOver = true;
|
|
217
141
|
}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./db"), exports);
|
|
1
|
+
export * from './db';
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.up = up;
|
|
4
|
-
exports.down = down;
|
|
5
|
-
const kysely_1 = require("kysely");
|
|
1
|
+
import { sql } from 'kysely';
|
|
6
2
|
// @TODO subject indexes, naming?
|
|
7
3
|
// @TODO drop indexes in down()?
|
|
8
|
-
async function up(db) {
|
|
4
|
+
export async function up(db) {
|
|
9
5
|
try {
|
|
10
6
|
// Add trigram support, supporting user search.
|
|
11
7
|
// Explicitly add to public schema, so the extension can be seen in all schemas.
|
|
12
|
-
await
|
|
8
|
+
await sql `create extension if not exists pg_trgm with schema public`.execute(db);
|
|
13
9
|
}
|
|
14
10
|
catch (err) {
|
|
15
11
|
// The "if not exists" isn't bulletproof against races, and we see test suites racing to
|
|
@@ -39,7 +35,7 @@ async function up(db) {
|
|
|
39
35
|
.addColumn('createdAt', 'varchar', (col) => col.notNull())
|
|
40
36
|
.addColumn('indexedAt', 'varchar', (col) => col.notNull())
|
|
41
37
|
.addColumn('sortAt', 'varchar', (col) => col
|
|
42
|
-
.generatedAlwaysAs(
|
|
38
|
+
.generatedAlwaysAs(sql `least("createdAt", "indexedAt")`)
|
|
43
39
|
.stored()
|
|
44
40
|
.notNull())
|
|
45
41
|
.addUniqueConstraint('follow_unique_subject', ['creator', 'subjectDid'])
|
|
@@ -61,7 +57,7 @@ async function up(db) {
|
|
|
61
57
|
.addColumn('createdAt', 'varchar', (col) => col.notNull())
|
|
62
58
|
.addColumn('indexedAt', 'varchar', (col) => col.notNull())
|
|
63
59
|
.addColumn('sortAt', 'varchar', (col) => col
|
|
64
|
-
.generatedAlwaysAs(
|
|
60
|
+
.generatedAlwaysAs(sql `least("createdAt", "indexedAt")`)
|
|
65
61
|
.stored()
|
|
66
62
|
.notNull())
|
|
67
63
|
// Aids in index uniqueness plus post like counts
|
|
@@ -86,7 +82,7 @@ async function up(db) {
|
|
|
86
82
|
.createIndex(`actor_handle_tgrm_idx`)
|
|
87
83
|
.on('actor')
|
|
88
84
|
.using('gist')
|
|
89
|
-
.expression(
|
|
85
|
+
.expression(sql `"handle" gist_trgm_ops`)
|
|
90
86
|
.execute();
|
|
91
87
|
//record
|
|
92
88
|
await db.schema
|
|
@@ -99,7 +95,7 @@ async function up(db) {
|
|
|
99
95
|
.addColumn('takedownId', 'integer') // foreign key created in moderation-init migration
|
|
100
96
|
.execute();
|
|
101
97
|
}
|
|
102
|
-
async function down(db) {
|
|
98
|
+
export async function down(db) {
|
|
103
99
|
// record
|
|
104
100
|
await db.schema.dropTable('record').execute();
|
|
105
101
|
// actor
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.up = up;
|
|
4
|
-
exports.down = down;
|
|
5
|
-
async function up(db) {
|
|
1
|
+
export async function up(db) {
|
|
6
2
|
await db.schema
|
|
7
3
|
.createTable('did_cache')
|
|
8
4
|
.addColumn('did', 'varchar', (col) => col.primaryKey())
|
|
@@ -10,6 +6,6 @@ async function up(db) {
|
|
|
10
6
|
.addColumn('updatedAt', 'bigint', (col) => col.notNull())
|
|
11
7
|
.execute();
|
|
12
8
|
}
|
|
13
|
-
async function down(db) {
|
|
9
|
+
export async function down(db) {
|
|
14
10
|
await db.schema.dropTable('did_cache').execute();
|
|
15
11
|
}
|
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// NOTE this file can be edited by hand, but it is also appended to by the migration:create command.
|
|
3
2
|
// It's important that every migration is exported from here with the proper name. We'd simplify
|
|
4
3
|
// this with kysely's FileMigrationProvider, but it doesn't play nicely with the build process.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports._20230420T211446071Z = exports._20230309T045948368Z = void 0;
|
|
40
|
-
exports._20230309T045948368Z = __importStar(require("./20230309T045948368Z-init"));
|
|
41
|
-
exports._20230420T211446071Z = __importStar(require("./20230420T211446071Z-did-cache"));
|
|
4
|
+
export * as _20230309T045948368Z from './20230309T045948368Z-init';
|
|
5
|
+
export * as _20230420T211446071Z from './20230420T211446071Z-did-cache';
|
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CtxMigrationProvider = void 0;
|
|
4
1
|
// Passes a context argument to migrations. We use this to thread the dialect into migrations
|
|
5
|
-
class CtxMigrationProvider {
|
|
2
|
+
export class CtxMigrationProvider {
|
|
3
|
+
migrations;
|
|
4
|
+
ctx;
|
|
6
5
|
constructor(migrations, ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: migrations
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(this, "ctx", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: ctx
|
|
18
|
-
});
|
|
6
|
+
this.migrations = migrations;
|
|
7
|
+
this.ctx = ctx;
|
|
19
8
|
}
|
|
20
9
|
async getMigrations() {
|
|
21
10
|
const ctxMigrations = {};
|
|
@@ -28,4 +17,3 @@ class CtxMigrationProvider {
|
|
|
28
17
|
return ctxMigrations;
|
|
29
18
|
}
|
|
30
19
|
}
|
|
31
|
-
exports.CtxMigrationProvider = CtxMigrationProvider;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.paginate = exports.IndexedAtDidKeyset = exports.CreatedAtDidKeyset = exports.TimeCidKeyset = exports.GenericKeyset = void 0;
|
|
4
|
-
const xrpc_server_1 = require("@atproto/xrpc-server");
|
|
5
|
-
const kysely_1 = require("kysely");
|
|
1
|
+
import { InvalidRequestError } from '@atproto/xrpc-server';
|
|
2
|
+
import { sql } from 'kysely';
|
|
6
3
|
/**
|
|
7
4
|
* The GenericKeyset is an abstract class that sets-up the interface and partial implementation
|
|
8
5
|
* of a keyset-paginated cursor with two parts. There are three types involved:
|
|
@@ -17,20 +14,12 @@ const kysely_1 = require("kysely");
|
|
|
17
14
|
* Result -*-> LabeledResult <-*-> Cursor <--> packed/string cursor
|
|
18
15
|
* ↳ SQL Condition
|
|
19
16
|
*/
|
|
20
|
-
class GenericKeyset {
|
|
17
|
+
export class GenericKeyset {
|
|
18
|
+
primary;
|
|
19
|
+
secondary;
|
|
21
20
|
constructor(primary, secondary) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true,
|
|
26
|
-
value: primary
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(this, "secondary", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
configurable: true,
|
|
31
|
-
writable: true,
|
|
32
|
-
value: secondary
|
|
33
|
-
});
|
|
21
|
+
this.primary = primary;
|
|
22
|
+
this.secondary = secondary;
|
|
34
23
|
}
|
|
35
24
|
packFromResult(results) {
|
|
36
25
|
const result = Array.isArray(results) ? results.at(-1) : results;
|
|
@@ -61,7 +50,7 @@ class GenericKeyset {
|
|
|
61
50
|
const result = cursorStr.split('__');
|
|
62
51
|
const [primary, secondary, ...others] = result;
|
|
63
52
|
if (!primary || !secondary || others.length > 0) {
|
|
64
|
-
throw new
|
|
53
|
+
throw new InvalidRequestError('Malformed cursor');
|
|
65
54
|
}
|
|
66
55
|
return {
|
|
67
56
|
primary,
|
|
@@ -74,25 +63,24 @@ class GenericKeyset {
|
|
|
74
63
|
if (tryIndex) {
|
|
75
64
|
// The tryIndex param will likely disappear and become the default implementation: here for now for gradual rollout query-by-query.
|
|
76
65
|
if (direction === 'asc') {
|
|
77
|
-
return
|
|
66
|
+
return sql `((${this.primary}, ${this.secondary}) > (${labeled.primary}, ${labeled.secondary}))`;
|
|
78
67
|
}
|
|
79
68
|
else {
|
|
80
|
-
return
|
|
69
|
+
return sql `((${this.primary}, ${this.secondary}) < (${labeled.primary}, ${labeled.secondary}))`;
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
else {
|
|
84
73
|
// @NOTE this implementation can struggle to use an index on (primary, secondary) for pagination due to the "or" usage.
|
|
85
74
|
if (direction === 'asc') {
|
|
86
|
-
return
|
|
75
|
+
return sql `((${this.primary} > ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} > ${labeled.secondary}))`;
|
|
87
76
|
}
|
|
88
77
|
else {
|
|
89
|
-
return
|
|
78
|
+
return sql `((${this.primary} < ${labeled.primary}) or (${this.primary} = ${labeled.primary} and ${this.secondary} < ${labeled.secondary}))`;
|
|
90
79
|
}
|
|
91
80
|
}
|
|
92
81
|
}
|
|
93
82
|
}
|
|
94
|
-
|
|
95
|
-
class TimeCidKeyset extends GenericKeyset {
|
|
83
|
+
export class TimeCidKeyset extends GenericKeyset {
|
|
96
84
|
labelResult(result) {
|
|
97
85
|
return { primary: result.sortAt, secondary: result.cid };
|
|
98
86
|
}
|
|
@@ -105,7 +93,7 @@ class TimeCidKeyset extends GenericKeyset {
|
|
|
105
93
|
cursorToLabeledResult(cursor) {
|
|
106
94
|
const primaryDate = new Date(parseInt(cursor.primary, 10));
|
|
107
95
|
if (isNaN(primaryDate.getTime())) {
|
|
108
|
-
throw new
|
|
96
|
+
throw new InvalidRequestError('Malformed cursor');
|
|
109
97
|
}
|
|
110
98
|
return {
|
|
111
99
|
primary: primaryDate.toISOString(),
|
|
@@ -113,20 +101,17 @@ class TimeCidKeyset extends GenericKeyset {
|
|
|
113
101
|
};
|
|
114
102
|
}
|
|
115
103
|
}
|
|
116
|
-
|
|
117
|
-
class CreatedAtDidKeyset extends TimeCidKeyset {
|
|
104
|
+
export class CreatedAtDidKeyset extends TimeCidKeyset {
|
|
118
105
|
labelResult(result) {
|
|
119
106
|
return { primary: result.createdAt, secondary: result.did };
|
|
120
107
|
}
|
|
121
108
|
}
|
|
122
|
-
|
|
123
|
-
class IndexedAtDidKeyset extends TimeCidKeyset {
|
|
109
|
+
export class IndexedAtDidKeyset extends TimeCidKeyset {
|
|
124
110
|
labelResult(result) {
|
|
125
111
|
return { primary: result.indexedAt, secondary: result.did };
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
|
-
|
|
129
|
-
const paginate = (qb, opts) => {
|
|
114
|
+
export const paginate = (qb, opts) => {
|
|
130
115
|
const { limit, cursor, keyset, direction = 'desc', tryIndex, nullsLast, } = opts;
|
|
131
116
|
const keysetSql = keyset.getSql(keyset.unpack(cursor), direction, tryIndex);
|
|
132
117
|
return qb
|
|
@@ -134,11 +119,10 @@ const paginate = (qb, opts) => {
|
|
|
134
119
|
.if(!nullsLast, (q) => q.orderBy(keyset.primary, direction).orderBy(keyset.secondary, direction))
|
|
135
120
|
.if(!!nullsLast, (q) => q
|
|
136
121
|
.orderBy(direction === 'asc'
|
|
137
|
-
?
|
|
138
|
-
:
|
|
122
|
+
? sql `${keyset.primary} asc nulls last`
|
|
123
|
+
: sql `${keyset.primary} desc nulls last`)
|
|
139
124
|
.orderBy(direction === 'asc'
|
|
140
|
-
?
|
|
141
|
-
:
|
|
125
|
+
? sql `${keyset.secondary} asc nulls last`
|
|
126
|
+
: sql `${keyset.secondary} desc nulls last`))
|
|
142
127
|
.if(!!keysetSql, (qb) => (keysetSql ? qb.where(keysetSql) : qb));
|
|
143
128
|
};
|
|
144
|
-
exports.paginate = paginate;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,48 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.dummyDialect = exports.valuesList = exports.noMatch = exports.excluded = exports.countAll = exports.softDeleted = exports.notSoftDeletedClause = exports.actorWhereClause = void 0;
|
|
4
|
-
const kysely_1 = require("kysely");
|
|
5
|
-
const actorWhereClause = (actor) => {
|
|
1
|
+
import { DummyDriver, SqliteAdapter, SqliteIntrospector, SqliteQueryCompiler, sql, } from 'kysely';
|
|
2
|
+
export const actorWhereClause = (actor) => {
|
|
6
3
|
if (actor.startsWith('did:')) {
|
|
7
|
-
return
|
|
4
|
+
return sql `"actor"."did" = ${actor}`;
|
|
8
5
|
}
|
|
9
6
|
else {
|
|
10
|
-
return
|
|
7
|
+
return sql `"actor"."handle" = ${actor}`;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
exports.actorWhereClause = actorWhereClause;
|
|
14
10
|
// Applies to actor or record table
|
|
15
|
-
const notSoftDeletedClause = (alias) => {
|
|
16
|
-
return
|
|
11
|
+
export const notSoftDeletedClause = (alias) => {
|
|
12
|
+
return sql `${alias}."takedownRef" is null`;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
const softDeleted = (actorOrRecord) => {
|
|
14
|
+
export const softDeleted = (actorOrRecord) => {
|
|
20
15
|
return actorOrRecord.takedownRef !== null;
|
|
21
16
|
};
|
|
22
|
-
|
|
23
|
-
exports.countAll = (0, kysely_1.sql) `count(*)`;
|
|
17
|
+
export const countAll = sql `count(*)`;
|
|
24
18
|
// For use with doUpdateSet()
|
|
25
|
-
const excluded = (db, col) => {
|
|
26
|
-
return
|
|
19
|
+
export const excluded = (db, col) => {
|
|
20
|
+
return sql `${db.dynamic.ref(`excluded.${col}`)}`;
|
|
27
21
|
};
|
|
28
|
-
|
|
29
|
-
exports.noMatch = (0, kysely_1.sql) `1 = 0`;
|
|
22
|
+
export const noMatch = sql `1 = 0`;
|
|
30
23
|
// Can be useful for large where-in clauses, to get the db to use a hash lookup on the list
|
|
31
|
-
const valuesList = (vals) => {
|
|
32
|
-
return
|
|
24
|
+
export const valuesList = (vals) => {
|
|
25
|
+
return sql `(values (${sql.join(vals, sql `), (`)}))`;
|
|
33
26
|
};
|
|
34
|
-
|
|
35
|
-
exports.dummyDialect = {
|
|
27
|
+
export const dummyDialect = {
|
|
36
28
|
createAdapter() {
|
|
37
|
-
return new
|
|
29
|
+
return new SqliteAdapter();
|
|
38
30
|
},
|
|
39
31
|
createDriver() {
|
|
40
|
-
return new
|
|
32
|
+
return new DummyDriver();
|
|
41
33
|
},
|
|
42
34
|
createIntrospector(db) {
|
|
43
|
-
return new
|
|
35
|
+
return new SqliteIntrospector(db);
|
|
44
36
|
},
|
|
45
37
|
createQueryCompiler() {
|
|
46
|
-
return new
|
|
38
|
+
return new SqliteQueryCompiler();
|
|
47
39
|
},
|
|
48
40
|
};
|