@nina-protocol/nina-db 0.0.87 → 0.0.88
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/models/Release.js +41 -32
- package/dist/models/Subscription.js +3 -3
- package/dist/seeds/1_accounts_profile.js +22 -0
- package/package.json +1 -1
- package/src/migrations/20241121155034_subscription_public_key_nullable.js +15 -0
- package/src/models/Release.js +48 -40
- package/src/models/Subscription.js +3 -3
- package/src/seeds/1_accounts_profile.js +23 -0
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20230306215736_add_hub_updated_at.js +0 -15
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20231031200439_add_profile.js +0 -15
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20231112031833_post_version.js +0 -15
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20231112031850_post_version.js +0 -15
- package/src/node_modules/@nina-protocol/nina-db/dist/migrations/20231116215059_add_tags.js +0 -15
- package/yarn-error.log +0 -6817
package/dist/models/Release.js
CHANGED
|
@@ -46,42 +46,51 @@ export default class Release extends Model {
|
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
static findOrCreate = async (publicKey, hubPublicKey = null) => {
|
|
49
|
-
let release = await Release.query().findOne({ publicKey });
|
|
50
|
-
if (release) {
|
|
51
|
-
return release;
|
|
52
|
-
}
|
|
53
|
-
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
54
|
-
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'processed' });
|
|
55
|
-
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
56
|
-
const metaplex = new Metaplex(connection);
|
|
57
|
-
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
58
|
-
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
59
|
-
let json;
|
|
60
49
|
try {
|
|
61
|
-
|
|
50
|
+
let release = await Release.query().findOne({ publicKey });
|
|
51
|
+
if (release) {
|
|
52
|
+
return release;
|
|
53
|
+
}
|
|
54
|
+
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
55
|
+
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
|
|
56
|
+
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
57
|
+
const metaplex = new Metaplex(connection);
|
|
58
|
+
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
59
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
60
|
+
if (!metadataAccount) {
|
|
61
|
+
throw new Error('No metadata account found for release - is not a complete release');
|
|
62
|
+
}
|
|
63
|
+
let json;
|
|
64
|
+
try {
|
|
65
|
+
json = (await axios.get(metadataAccount.uri.replace('www.', '').replace('arweave.net', 'gateway.irys.xyz'))).data;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data;
|
|
69
|
+
}
|
|
70
|
+
const slug = await this.generateSlug(json);
|
|
71
|
+
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
72
|
+
release = await this.createRelease({
|
|
73
|
+
publicKey,
|
|
74
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
75
|
+
metadata: json,
|
|
76
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
77
|
+
slug,
|
|
78
|
+
publisherId: publisher.id,
|
|
79
|
+
releaseAccount
|
|
80
|
+
});
|
|
81
|
+
if (hubPublicKey) {
|
|
82
|
+
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
83
|
+
await release.$query().patch({ hubId: hub.id });
|
|
84
|
+
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
85
|
+
visible: true,
|
|
86
|
+
}).where({ id: release.id });
|
|
87
|
+
}
|
|
88
|
+
return release;
|
|
62
89
|
}
|
|
63
90
|
catch (error) {
|
|
64
|
-
|
|
91
|
+
console.log('error finding or creating release: ', error);
|
|
92
|
+
return null;
|
|
65
93
|
}
|
|
66
|
-
const slug = await this.generateSlug(json);
|
|
67
|
-
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
68
|
-
release = await this.createRelease({
|
|
69
|
-
publicKey,
|
|
70
|
-
mint: releaseAccount.releaseMint.toBase58(),
|
|
71
|
-
metadata: json,
|
|
72
|
-
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
73
|
-
slug,
|
|
74
|
-
publisherId: publisher.id,
|
|
75
|
-
releaseAccount
|
|
76
|
-
});
|
|
77
|
-
if (hubPublicKey) {
|
|
78
|
-
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
79
|
-
await release.$query().patch({ hubId: hub.id });
|
|
80
|
-
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
81
|
-
visible: true,
|
|
82
|
-
}).where({ id: release.id });
|
|
83
|
-
}
|
|
84
|
-
return release;
|
|
85
94
|
};
|
|
86
95
|
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
|
|
87
96
|
const slug = await this.generateSlug(metadata);
|
|
@@ -11,7 +11,7 @@ class Subscription extends Model {
|
|
|
11
11
|
static get jsonSchema() {
|
|
12
12
|
return {
|
|
13
13
|
type: 'object',
|
|
14
|
-
required: ['
|
|
14
|
+
required: ['datetime'],
|
|
15
15
|
properties: {
|
|
16
16
|
publicKey: { type: 'string' },
|
|
17
17
|
datetime: { type: 'string' },
|
|
@@ -25,12 +25,12 @@ class Subscription extends Model {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
static async findOrCreate({ publicKey, from, to, datetime, subscriptionType }) {
|
|
28
|
-
let subscription = await Subscription.query().findOne({
|
|
28
|
+
let subscription = await Subscription.query().findOne({ from, to });
|
|
29
29
|
if (subscription) {
|
|
30
30
|
return subscription;
|
|
31
31
|
}
|
|
32
32
|
subscription = await Subscription.query().insert({
|
|
33
|
-
|
|
33
|
+
from, to, datetime, subscriptionType
|
|
34
34
|
});
|
|
35
35
|
console.log('Inserted subscription: ', publicKey);
|
|
36
36
|
return subscription;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { Account, connectDb } from '../index.js';
|
|
4
|
+
export const seed = async () => {
|
|
5
|
+
await connectDb();
|
|
6
|
+
const accountsWithoutHandle = await Account.query().whereNull('handle');
|
|
7
|
+
for await (let account of accountsWithoutHandle) {
|
|
8
|
+
try {
|
|
9
|
+
const response = await axios.get(`${process.env.ID_SERVER_ENDPOINT}/profile/${account.publicKey}`);
|
|
10
|
+
await account.$query().patch({
|
|
11
|
+
handle: response.data.profile.handle,
|
|
12
|
+
displayName: response.data.profile.displayName,
|
|
13
|
+
image: response.data.profile.image,
|
|
14
|
+
description: response.data.profile.description,
|
|
15
|
+
});
|
|
16
|
+
console.log('Updated Account:', account.handle, account.publicKey);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.log('Error updating Account', account.publicKey, error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function(knex) {
|
|
6
|
+
return knex.schema.alterTable('subscriptions', table => {
|
|
7
|
+
table.dropColumn('publicKey');
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @param { import("knex").Knex } knex
|
|
12
|
+
* @returns { Promise<void> }
|
|
13
|
+
*/
|
|
14
|
+
export const down = function(knex) {
|
|
15
|
+
};
|
package/src/models/Release.js
CHANGED
|
@@ -49,49 +49,57 @@ export default class Release extends Model {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
static findOrCreate = async (publicKey, hubPublicKey=null) => {
|
|
52
|
-
let release = await Release.query().findOne({ publicKey });
|
|
53
|
-
if (release) {
|
|
54
|
-
return release;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
58
|
-
const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'processed'})
|
|
59
|
-
const program = await anchor.Program.at(
|
|
60
|
-
process.env.NINA_PROGRAM_ID,
|
|
61
|
-
provider,
|
|
62
|
-
)
|
|
63
|
-
const metaplex = new Metaplex(connection);
|
|
64
|
-
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
65
|
-
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
66
|
-
let json
|
|
67
52
|
try {
|
|
68
|
-
|
|
53
|
+
let release = await Release.query().findOne({ publicKey });
|
|
54
|
+
if (release) {
|
|
55
|
+
return release;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
59
|
+
const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'confirmed'})
|
|
60
|
+
const program = await anchor.Program.at(
|
|
61
|
+
process.env.NINA_PROGRAM_ID,
|
|
62
|
+
provider,
|
|
63
|
+
)
|
|
64
|
+
const metaplex = new Metaplex(connection);
|
|
65
|
+
const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
66
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
67
|
+
if (!metadataAccount) {
|
|
68
|
+
throw new Error('No metadata account found for release - is not a complete release')
|
|
69
|
+
}
|
|
70
|
+
let json
|
|
71
|
+
try {
|
|
72
|
+
json = (await axios.get(metadataAccount.uri.replace('www.','').replace('arweave.net', 'gateway.irys.xyz'))).data
|
|
73
|
+
} catch (error) {
|
|
74
|
+
json = (await axios.get(metadataAccount.uri.replace('gateway.irys.xyz', 'arweave.net'))).data
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const slug = await this.generateSlug(json);
|
|
78
|
+
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
79
|
+
release = await this.createRelease({
|
|
80
|
+
publicKey,
|
|
81
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
82
|
+
metadata: json,
|
|
83
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
84
|
+
slug,
|
|
85
|
+
publisherId: publisher.id,
|
|
86
|
+
releaseAccount
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (hubPublicKey) {
|
|
90
|
+
|
|
91
|
+
const hub = await Hub.query().findOne({ publicKey: hubPublicKey })
|
|
92
|
+
await release.$query().patch({ hubId: hub.id })
|
|
93
|
+
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
94
|
+
visible: true,
|
|
95
|
+
}).where( {id: release.id });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return release;
|
|
69
99
|
} catch (error) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const slug = await this.generateSlug(json);
|
|
74
|
-
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
75
|
-
release = await this.createRelease({
|
|
76
|
-
publicKey,
|
|
77
|
-
mint: releaseAccount.releaseMint.toBase58(),
|
|
78
|
-
metadata: json,
|
|
79
|
-
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
80
|
-
slug,
|
|
81
|
-
publisherId: publisher.id,
|
|
82
|
-
releaseAccount
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (hubPublicKey) {
|
|
86
|
-
|
|
87
|
-
const hub = await Hub.query().findOne({ publicKey: hubPublicKey })
|
|
88
|
-
await release.$query().patch({ hubId: hub.id })
|
|
89
|
-
await Hub.relatedQuery('releases').for(hub.id).patch({
|
|
90
|
-
visible: true,
|
|
91
|
-
}).where( {id: release.id });
|
|
100
|
+
console.log('error finding or creating release: ', error)
|
|
101
|
+
return null;
|
|
92
102
|
}
|
|
93
|
-
|
|
94
|
-
return release;
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
static createRelease = async ({publicKey, mint, metadata, datetime, publisherId, releaseAccount}) => {
|
|
@@ -12,7 +12,7 @@ class Subscription extends Model {
|
|
|
12
12
|
static get jsonSchema() {
|
|
13
13
|
return {
|
|
14
14
|
type: 'object',
|
|
15
|
-
required: ['
|
|
15
|
+
required: ['datetime'],
|
|
16
16
|
properties: {
|
|
17
17
|
publicKey: { type: 'string' },
|
|
18
18
|
datetime: { type: 'string' },
|
|
@@ -27,13 +27,13 @@ class Subscription extends Model {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
static async findOrCreate({publicKey, from, to, datetime, subscriptionType}) {
|
|
30
|
-
let subscription = await Subscription.query().findOne({
|
|
30
|
+
let subscription = await Subscription.query().findOne({ from, to });
|
|
31
31
|
if (subscription) {
|
|
32
32
|
return subscription;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
subscription = await Subscription.query().insert({
|
|
36
|
-
|
|
36
|
+
from, to, datetime, subscriptionType
|
|
37
37
|
});
|
|
38
38
|
console.log('Inserted subscription: ', publicKey)
|
|
39
39
|
return subscription;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { Account, connectDb } from '../index.js';
|
|
4
|
+
export const seed = async () => {
|
|
5
|
+
await connectDb();
|
|
6
|
+
|
|
7
|
+
const accountsWithoutHandle = await Account.query().whereNull('handle');
|
|
8
|
+
|
|
9
|
+
for await (let account of accountsWithoutHandle) {
|
|
10
|
+
try {
|
|
11
|
+
const response = await axios.get(`${process.env.ID_SERVER_ENDPOINT}/profile/${account.publicKey}`);
|
|
12
|
+
await account.$query().patch({
|
|
13
|
+
handle: response.data.profile.handle,
|
|
14
|
+
displayName: response.data.profile.displayName,
|
|
15
|
+
image: response.data.profile.image,
|
|
16
|
+
description: response.data.profile.description,
|
|
17
|
+
});
|
|
18
|
+
console.log('Updated Account:', account.handle, account.publicKey);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.log('Error updating Account', account.publicKey, error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|