@thisismissem/adonisjs-atproto-tap 1.0.1 → 2.0.0
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/build/providers/tap_provider.d.ts +3 -7
- package/build/providers/tap_provider.js +2 -28
- package/build/src/api.d.ts +7 -2
- package/build/src/api.js +22 -1
- package/build/src/define_config.d.ts +1 -1
- package/build/src/define_config.js +7 -7
- package/build/src/types.d.ts +1 -2
- package/build/stubs/config/tap.stub +1 -3
- package/build/stubs/start/indexer.stub +15 -1
- package/package.json +3 -3
- package/build/services/indexer.d.ts +0 -3
- package/build/services/indexer.js +0 -14
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { Tap
|
|
1
|
+
import { Tap } from '@atproto/tap';
|
|
2
2
|
import type { ApplicationService } from '@adonisjs/core/types';
|
|
3
3
|
import TapApi from '../src/api.js';
|
|
4
|
+
import { ContainerProviderContract } from '@adonisjs/core/types/app';
|
|
4
5
|
declare module '@adonisjs/core/types' {
|
|
5
6
|
interface ContainerBindings {
|
|
6
7
|
'tap.client': Tap;
|
|
7
|
-
'tap.indexer': SimpleIndexer;
|
|
8
8
|
'tap.api': TapApi;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export default class TapProvider {
|
|
11
|
+
export default class TapProvider implements ContainerProviderContract {
|
|
12
12
|
protected app: ApplicationService;
|
|
13
|
-
private channel?;
|
|
14
13
|
constructor(app: ApplicationService);
|
|
15
14
|
register(): void;
|
|
16
|
-
boot(): Promise<void>;
|
|
17
|
-
start(): Promise<void>;
|
|
18
|
-
shutdown(): Promise<void>;
|
|
19
15
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { RuntimeException } from '@adonisjs/core/exceptions';
|
|
2
|
-
import { Tap
|
|
2
|
+
import { Tap } from '@atproto/tap';
|
|
3
3
|
import TapApi from '../src/api.js';
|
|
4
4
|
export default class TapProvider {
|
|
5
5
|
app;
|
|
6
|
-
channel;
|
|
7
6
|
constructor(app) {
|
|
8
7
|
this.app = app;
|
|
9
8
|
}
|
|
@@ -13,36 +12,11 @@ export default class TapProvider {
|
|
|
13
12
|
if (!config || !config.url) {
|
|
14
13
|
throw new RuntimeException('Invalid config exported from "config/tap.ts" file. Make sure to return an object with the url property defined');
|
|
15
14
|
}
|
|
16
|
-
// FIXME: Workaround for https://github.com/bluesky-social/atproto/issues/4476
|
|
17
|
-
if (config.url.endsWith('/')) {
|
|
18
|
-
config.url = config.url.slice(0, -1);
|
|
19
|
-
}
|
|
20
15
|
return new Tap(config.url, config.config ?? {});
|
|
21
16
|
});
|
|
22
|
-
this.app.container.singleton('tap.indexer', () => {
|
|
23
|
-
return new SimpleIndexer();
|
|
24
|
-
});
|
|
25
17
|
this.app.container.singleton('tap.api', async (resolver) => {
|
|
26
18
|
const client = await resolver.make('tap.client');
|
|
27
|
-
return new TapApi(client);
|
|
19
|
+
return new TapApi(client, this.app);
|
|
28
20
|
});
|
|
29
21
|
}
|
|
30
|
-
async boot() {
|
|
31
|
-
const logger = await this.app.container.make('logger');
|
|
32
|
-
const indexer = await this.app.container.make('tap.indexer');
|
|
33
|
-
indexer.error((err) => logger.error(err, 'Tap indexer error'));
|
|
34
|
-
}
|
|
35
|
-
async start() {
|
|
36
|
-
if (this.app.getEnvironment() === 'web') {
|
|
37
|
-
const tap = await this.app.container.make('tap.client');
|
|
38
|
-
const indexer = await this.app.container.make('tap.indexer');
|
|
39
|
-
this.channel = tap.channel(indexer);
|
|
40
|
-
this.channel.start();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async shutdown() {
|
|
44
|
-
if (this.channel) {
|
|
45
|
-
await this.channel.destroy();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
22
|
}
|
package/build/src/api.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { Tap as TapClient } from '@atproto/tap';
|
|
1
|
+
import { Tap as TapClient, TapHandler } from '@atproto/tap';
|
|
2
2
|
import { Tap } from './types.js';
|
|
3
|
+
import { ApplicationService } from '@adonisjs/core/types';
|
|
3
4
|
export default class TapApi implements Tap {
|
|
5
|
+
#private;
|
|
4
6
|
protected client: TapClient;
|
|
5
|
-
|
|
7
|
+
protected app: ApplicationService;
|
|
8
|
+
constructor(client: TapClient, app: ApplicationService);
|
|
9
|
+
setIndexer(indexer: TapHandler): void;
|
|
10
|
+
startIndexer(): void;
|
|
6
11
|
addRepos(dids: string[]): Promise<void>;
|
|
7
12
|
removeRepos(dids: string[]): Promise<void>;
|
|
8
13
|
resolveDid(did: string): Promise<{
|
package/build/src/api.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
import { RuntimeException } from '@adonisjs/core/exceptions';
|
|
1
2
|
export default class TapApi {
|
|
2
3
|
client;
|
|
3
|
-
|
|
4
|
+
app;
|
|
5
|
+
#channel;
|
|
6
|
+
#indexer;
|
|
7
|
+
constructor(client, app) {
|
|
4
8
|
this.client = client;
|
|
9
|
+
this.app = app;
|
|
10
|
+
}
|
|
11
|
+
setIndexer(indexer) {
|
|
12
|
+
this.#indexer = indexer;
|
|
13
|
+
}
|
|
14
|
+
startIndexer() {
|
|
15
|
+
if (!this.#indexer) {
|
|
16
|
+
throw new RuntimeException('tap.setIndexer was never called');
|
|
17
|
+
}
|
|
18
|
+
if (this.#channel) {
|
|
19
|
+
throw new RuntimeException('tap.startIndexer invoked multiple times');
|
|
20
|
+
}
|
|
21
|
+
this.#channel = this.client.channel(this.#indexer);
|
|
22
|
+
this.#channel.start();
|
|
23
|
+
this.app.terminating(async () => {
|
|
24
|
+
await this.#channel?.destroy();
|
|
25
|
+
});
|
|
5
26
|
}
|
|
6
27
|
async addRepos(dids) {
|
|
7
28
|
return this.client.addRepos(dids);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Config, TapProviderConfig } from './types.js';
|
|
2
|
-
export declare function defineConfig<T extends Config>(config: T): TapProviderConfig;
|
|
2
|
+
export declare function defineConfig<T extends Config>({ url, ...config }: T): TapProviderConfig;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export function defineConfig(config) {
|
|
1
|
+
export function defineConfig({ url, ...config }) {
|
|
2
2
|
const tapConfig = {
|
|
3
|
-
url
|
|
4
|
-
config
|
|
3
|
+
url,
|
|
4
|
+
config,
|
|
5
5
|
};
|
|
6
6
|
// Sensible default:
|
|
7
7
|
if (typeof tapConfig.url === 'undefined') {
|
|
8
|
-
|
|
8
|
+
tapConfig.url = 'http://localhost:2480';
|
|
9
9
|
}
|
|
10
|
-
//
|
|
11
|
-
if (
|
|
12
|
-
tapConfig.
|
|
10
|
+
// FIXME: Workaround for https://github.com/bluesky-social/atproto/issues/4476
|
|
11
|
+
if (tapConfig.url.endsWith('/')) {
|
|
12
|
+
tapConfig.url = tapConfig.url.slice(0, -1);
|
|
13
13
|
}
|
|
14
14
|
return tapConfig;
|
|
15
15
|
}
|
package/build/src/types.d.ts
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
{{#var atUri = '`at://${evt.did}/${evt.collection}/${evt.rkey}`' }}
|
|
6
6
|
{{#var upsertEvt = '`${evt.action}: ${uri}`' }}
|
|
7
7
|
{{#var deleteEvt = '`deleted: ${uri}`' }}
|
|
8
|
-
import
|
|
8
|
+
import tap from '@thisismissem/adonisjs-atproto-tap/services/tap'
|
|
9
|
+
import { SimpleIndexer } from '@atproto/tap'
|
|
10
|
+
|
|
11
|
+
// You can also use LexIndexer for a lexicon aware indexer:
|
|
12
|
+
const indexer = new SimpleIndexer()
|
|
9
13
|
|
|
10
14
|
indexer.identity(async (evt) => {
|
|
11
15
|
console.log({{ identityEvt }})
|
|
@@ -19,3 +23,13 @@ indexer.record(async (evt) => {
|
|
|
19
23
|
console.log({{ deleteEvt }})
|
|
20
24
|
}
|
|
21
25
|
})
|
|
26
|
+
|
|
27
|
+
// Set the indexer to use with Tap:
|
|
28
|
+
tap.setIndexer(indexer)
|
|
29
|
+
|
|
30
|
+
// In production, you'll probably want to use a separate process to run the
|
|
31
|
+
// indexer. e.g., have a node ace command that starts the app, and then calls
|
|
32
|
+
// tap.startIndexer() one the app has started.
|
|
33
|
+
if (app.getEnvironment() === 'web' && app.inDev) {
|
|
34
|
+
tap.startIndexer()
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisismissem/adonisjs-atproto-tap",
|
|
3
3
|
"description": "Adonis.js provider for AT Protocol Tap Client",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
".": "./build/index.js",
|
|
21
21
|
"./provider": "./build/providers/tap_provider.js",
|
|
22
22
|
"./services/tap": "./build/services/tap.js",
|
|
23
|
-
"./services/indexer": "./build/services/indexer.js",
|
|
24
23
|
"./types": "./build/src/types.js"
|
|
25
24
|
},
|
|
26
25
|
"keywords": [
|
|
@@ -48,6 +47,7 @@
|
|
|
48
47
|
"@adonisjs/prettier-config": "^1.4.0",
|
|
49
48
|
"@adonisjs/tsconfig": "^1.3.0",
|
|
50
49
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
50
|
+
"@atproto/tap": "^0.1.3",
|
|
51
51
|
"@changesets/changelog-github": "^0.5.2",
|
|
52
52
|
"@changesets/cli": "^2.29.8",
|
|
53
53
|
"@japa/assert": "^4.2.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@adonisjs/core": "^6.2.0",
|
|
69
|
-
"@atproto/tap": "^0.
|
|
69
|
+
"@atproto/tap": "^0.1.3"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/transmit
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import app from '@adonisjs/core/services/app';
|
|
10
|
-
let indexer;
|
|
11
|
-
await app.booted(async () => {
|
|
12
|
-
indexer = await app.container.make('tap.indexer');
|
|
13
|
-
});
|
|
14
|
-
export { indexer as default };
|