@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
package/dist/config.js CHANGED
@@ -1,24 +1,9 @@
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
- exports.ServerConfig = void 0;
7
- const node_assert_1 = __importDefault(require("node:assert"));
8
- class ServerConfig {
1
+ import assert from 'node:assert';
2
+ export class ServerConfig {
3
+ cfg;
4
+ assignedPort;
9
5
  constructor(cfg) {
10
- Object.defineProperty(this, "cfg", {
11
- enumerable: true,
12
- configurable: true,
13
- writable: true,
14
- value: cfg
15
- });
16
- Object.defineProperty(this, "assignedPort", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: void 0
21
- });
6
+ this.cfg = cfg;
22
7
  }
23
8
  static readEnv(overrides) {
24
9
  const version = overrides?.version || process.env.CLIO_VERSION || undefined;
@@ -39,7 +24,7 @@ class ServerConfig {
39
24
  });
40
25
  }
41
26
  assignPort(port) {
42
- (0, node_assert_1.default)(!this.cfg.port || this.cfg.port === port, 'Conflicting port in config');
27
+ assert(!this.cfg.port || this.cfg.port === port, 'Conflicting port in config');
43
28
  this.assignedPort = port;
44
29
  }
45
30
  get version() {
@@ -52,7 +37,7 @@ class ServerConfig {
52
37
  return this.assignedPort || this.cfg.port;
53
38
  }
54
39
  get localUrl() {
55
- (0, node_assert_1.default)(this.port, 'No port assigned');
40
+ assert(this.port, 'No port assigned');
56
41
  return `http://localhost:${this.port}`;
57
42
  }
58
43
  get serverDid() {
@@ -62,4 +47,3 @@ class ServerConfig {
62
47
  return this.cfg.didPlcUrl;
63
48
  }
64
49
  }
65
- exports.ServerConfig = ServerConfig;
package/dist/context.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class AppContext {
1
+ export default class AppContext {
2
+ opts;
4
3
  constructor(opts) {
5
- Object.defineProperty(this, "opts", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: opts
10
- });
4
+ this.opts = opts;
11
5
  }
12
6
  get cfg() {
13
7
  return this.opts.cfg;
@@ -16,4 +10,3 @@ class AppContext {
16
10
  return this.opts.dataplane;
17
11
  }
18
12
  }
19
- exports.default = AppContext;
@@ -1,68 +1,28 @@
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.getKeyAsDidKey = exports.getServiceEndpoint = exports.unpackIdentityKeys = exports.unpackIdentityServices = exports.isDataplaneError = exports.Code = exports.createDataPlaneClient = void 0;
40
- const identity_1 = require("@atproto/identity");
41
- const connect_1 = require("@connectrpc/connect");
42
- Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return connect_1.Code; } });
43
- const connect_node_1 = require("@connectrpc/connect-node");
44
- const node_assert_1 = __importDefault(require("node:assert"));
45
- const node_crypto_1 = require("node:crypto");
46
- const ui8 = __importStar(require("uint8arrays"));
47
- const clio_connect_1 = require("../rpc/clio_connect");
1
+ import { getDidKeyFromMultibase } from '@atproto/identity';
2
+ import { Code, ConnectError, createClient, makeAnyClient, } from '@connectrpc/connect';
3
+ import { createGrpcTransport } from '@connectrpc/connect-node';
4
+ import assert from 'node:assert';
5
+ import { randomInt } from 'node:crypto';
6
+ import * as ui8 from 'uint8arrays';
7
+ import { ClioService } from '../rpc/clio_connect';
48
8
  const MAX_RETRIES = 3;
49
- const createDataPlaneClient = (baseUrls, opts) => {
9
+ export const createDataPlaneClient = (baseUrls, opts) => {
50
10
  const clients = baseUrls.map((baseUrl) => createBaseClient(baseUrl, opts));
51
- (0, node_assert_1.default)(clients.length > 0, 'no clients available');
52
- return (0, connect_1.makeAnyClient)(clio_connect_1.ClioService, (method) => {
11
+ assert(clients.length > 0, 'no clients available');
12
+ return makeAnyClient(ClioService, (method) => {
53
13
  return async (...args) => {
54
14
  let tries = 0;
55
15
  let error;
56
16
  let remainingClients = clients;
57
17
  while (tries < MAX_RETRIES) {
58
18
  const client = randomElement(remainingClients);
59
- (0, node_assert_1.default)(client, 'no clients available');
19
+ assert(client, 'no clients available');
60
20
  try {
61
21
  return await client.lib[method.localName](...args);
62
22
  }
63
23
  catch (err) {
64
- if (err instanceof connect_1.ConnectError &&
65
- (err.code === connect_1.Code.Unavailable || err.code === connect_1.Code.Aborted)) {
24
+ if (err instanceof ConnectError &&
25
+ (err.code === Code.Unavailable || err.code === Code.Aborted)) {
66
26
  tries++;
67
27
  error = err;
68
28
  remainingClients = getRemainingClients(remainingClients, client);
@@ -72,29 +32,28 @@ const createDataPlaneClient = (baseUrls, opts) => {
72
32
  }
73
33
  }
74
34
  }
75
- (0, node_assert_1.default)(error);
35
+ assert(error);
76
36
  throw error;
77
37
  };
78
38
  });
79
39
  };
80
- exports.createDataPlaneClient = createDataPlaneClient;
81
- const isDataplaneError = (err, code) => {
82
- if (err instanceof connect_1.ConnectError) {
40
+ export { Code };
41
+ export const isDataplaneError = (err, code) => {
42
+ if (err instanceof ConnectError) {
83
43
  return !code || err.code === code;
84
44
  }
85
45
  return false;
86
46
  };
87
- exports.isDataplaneError = isDataplaneError;
88
47
  const createBaseClient = (baseUrl, opts) => {
89
48
  const { httpVersion = '2', rejectUnauthorized = true } = opts;
90
- const transport = (0, connect_node_1.createGrpcTransport)({
49
+ const transport = createGrpcTransport({
91
50
  baseUrl,
92
51
  httpVersion,
93
52
  acceptCompression: [],
94
53
  nodeOptions: { rejectUnauthorized },
95
54
  });
96
55
  return {
97
- lib: (0, connect_1.createClient)(clio_connect_1.ClioService, transport),
56
+ lib: createClient(ClioService, transport),
98
57
  url: new URL(baseUrl),
99
58
  };
100
59
  };
@@ -113,38 +72,34 @@ const getRemainingClients = (clients, lastClient) => {
113
72
  const randomElement = (arr) => {
114
73
  if (arr.length === 0)
115
74
  return;
116
- return arr[(0, node_crypto_1.randomInt)(arr.length)];
75
+ return arr[randomInt(arr.length)];
117
76
  };
118
- const unpackIdentityServices = (servicesBytes) => {
77
+ export const unpackIdentityServices = (servicesBytes) => {
119
78
  const servicesStr = ui8.toString(servicesBytes, 'utf8');
120
79
  if (!servicesStr)
121
80
  return {};
122
81
  return JSON.parse(servicesStr);
123
82
  };
124
- exports.unpackIdentityServices = unpackIdentityServices;
125
- const unpackIdentityKeys = (keysBytes) => {
83
+ export const unpackIdentityKeys = (keysBytes) => {
126
84
  const keysStr = ui8.toString(keysBytes, 'utf8');
127
85
  if (!keysStr)
128
86
  return {};
129
87
  return JSON.parse(keysStr);
130
88
  };
131
- exports.unpackIdentityKeys = unpackIdentityKeys;
132
- const getServiceEndpoint = (services, opts) => {
89
+ export const getServiceEndpoint = (services, opts) => {
133
90
  const endpoint = services[opts.id] &&
134
91
  services[opts.id].Type === opts.type &&
135
92
  validateUrl(services[opts.id].URL);
136
93
  return endpoint || undefined;
137
94
  };
138
- exports.getServiceEndpoint = getServiceEndpoint;
139
- const getKeyAsDidKey = (keys, opts) => {
95
+ export const getKeyAsDidKey = (keys, opts) => {
140
96
  const key = keys[opts.id] &&
141
- (0, identity_1.getDidKeyFromMultibase)({
97
+ getDidKeyFromMultibase({
142
98
  type: keys[opts.id].Type,
143
99
  publicKeyMultibase: keys[opts.id].PublicKeyMultibase,
144
100
  });
145
101
  return key || undefined;
146
102
  };
147
- exports.getKeyAsDidKey = getKeyAsDidKey;
148
103
  const validateUrl = (urlStr) => {
149
104
  let url;
150
105
  try {
@@ -1,18 +1,2 @@
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 __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("./client"), exports);
18
- __exportStar(require("./server"), exports);
1
+ export * from './client';
2
+ export * from './server';
@@ -1,32 +1,12 @@
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
- exports.BackgroundQueue = void 0;
7
- const p_queue_1 = __importDefault(require("p-queue"));
8
- const logger_1 = require("../../logger");
1
+ import PQueue from 'p-queue';
2
+ import { dbLogger } from '../../logger';
9
3
  // A simple queue for in-process, out-of-band/backgrounded work
10
- class BackgroundQueue {
4
+ export class BackgroundQueue {
5
+ db;
6
+ queue = new PQueue();
7
+ destroyed = false;
11
8
  constructor(db) {
12
- Object.defineProperty(this, "db", {
13
- enumerable: true,
14
- configurable: true,
15
- writable: true,
16
- value: db
17
- });
18
- Object.defineProperty(this, "queue", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: new p_queue_1.default()
23
- });
24
- Object.defineProperty(this, "destroyed", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: false
29
- });
9
+ this.db = db;
30
10
  }
31
11
  add(task) {
32
12
  if (this.destroyed) {
@@ -35,7 +15,7 @@ class BackgroundQueue {
35
15
  this.queue
36
16
  .add(() => task(this.db))
37
17
  .catch((err) => {
38
- logger_1.dbLogger.error(err, 'background queue task failed');
18
+ dbLogger.error(err, 'background queue task failed');
39
19
  });
40
20
  }
41
21
  async processAll() {
@@ -48,4 +28,3 @@ class BackgroundQueue {
48
28
  await this.queue.onIdle();
49
29
  }
50
30
  }
51
- exports.BackgroundQueue = BackgroundQueue;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,87 +1,19 @@
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.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
- Object.defineProperty(this, "opts", {
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 pg_1.Pool({
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
- pg_1.types.setTypeParser(pg_1.types.builtins.INT8, (n) => parseInt(n, 10));
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 kysely_1.Kysely({
119
- dialect: new kysely_1.PostgresDialect({ pool }),
50
+ this.db = new Kysely({
51
+ dialect: new PostgresDialect({ pool }),
120
52
  });
121
- this.migrator = new kysely_1.Migrator({
53
+ this.migrator = new Migrator({
122
54
  db: this.db,
123
55
  migrationTableSchema: opts.schema,
124
- provider: new provider_1.CtxMigrationProvider(migrations, 'pg'),
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
- (0, node_assert_1.default)(this.isTransaction, 'Transaction required');
90
+ assert(this.isTransaction, 'Transaction required');
159
91
  }
160
92
  assertNotTransaction() {
161
- (0, node_assert_1.default)(!this.isTransaction, 'Cannot be in a transaction');
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
- exports.Database = Database;
201
- exports.default = Database;
202
- const onPoolError = (err) => logger_1.dbLogger.error({ err }, 'db pool error');
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
- constructor() {
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
- "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 __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
- "use strict";
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 (0, kysely_1.sql) `create extension if not exists pg_trgm with schema public`.execute(db);
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((0, kysely_1.sql) `least("createdAt", "indexedAt")`)
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((0, kysely_1.sql) `least("createdAt", "indexedAt")`)
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((0, kysely_1.sql) `"handle" gist_trgm_ops`)
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
- "use strict";
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
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
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
- Object.defineProperty(this, "migrations", {
8
- enumerable: true,
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;