@nina-protocol/nina-db 0.0.102 → 0.0.103
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/Account.js +3 -2
- package/dist/models/Hub.js +3 -2
- package/dist/models/Release.js +12 -27
- package/dist/models/Transaction.js +0 -2
- package/package.json +3 -4
- package/src/models/Account.js +3 -2
- package/src/models/Hub.js +3 -2
- package/src/models/Release.js +13 -26
- package/src/models/Transaction.js +0 -2
- package/src/migrations/20250616215722_program_id.js +0 -19
- package/src/migrations/20250630215722_transaction_program_id.js +0 -19
package/dist/models/Account.js
CHANGED
|
@@ -37,8 +37,9 @@ export default class Account extends Model {
|
|
|
37
37
|
this.verifications = verifications;
|
|
38
38
|
}
|
|
39
39
|
delete this.id;
|
|
40
|
-
|
|
41
|
-
this.
|
|
40
|
+
// Use count() instead of range(0,0) to avoid temporary object creation
|
|
41
|
+
const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
|
|
42
|
+
this.followers = parseInt(followersCount.count);
|
|
42
43
|
};
|
|
43
44
|
static relationMappings = () => ({
|
|
44
45
|
published: {
|
package/dist/models/Hub.js
CHANGED
|
@@ -31,8 +31,9 @@ export default class Hub extends Model {
|
|
|
31
31
|
delete this.authorityId;
|
|
32
32
|
delete this.id;
|
|
33
33
|
stripHtmlIfNeeded(this.data, 'description');
|
|
34
|
-
|
|
35
|
-
this.
|
|
34
|
+
// Use count() instead of range(0,0) to avoid temporary object creation
|
|
35
|
+
const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
|
|
36
|
+
this.followers = parseInt(followersCount.count);
|
|
36
37
|
}
|
|
37
38
|
static relationMappings = () => ({
|
|
38
39
|
authority: {
|
package/dist/models/Release.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as anchorCoral from '@coral-xyz/anchor';
|
|
1
|
+
import anchor from '@project-serum/anchor';
|
|
3
2
|
import { Metaplex } from '@metaplex-foundation/js';
|
|
4
3
|
import { Model } from 'objection';
|
|
5
4
|
import { stripHtmlIfNeeded, tweetNewRelease } from '../utils/index.js';
|
|
@@ -11,7 +10,7 @@ import Tag from './Tag.js';
|
|
|
11
10
|
import axios from 'axios';
|
|
12
11
|
import promiseRetry from 'promise-retry';
|
|
13
12
|
import { customAlphabet } from 'nanoid';
|
|
14
|
-
import
|
|
13
|
+
import promiseRetry from 'promise-retry';
|
|
15
14
|
const ensureHttps = (uri) => {
|
|
16
15
|
if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
|
|
17
16
|
return `https://${uri}`;
|
|
@@ -54,25 +53,21 @@ export default class Release extends Model {
|
|
|
54
53
|
archived: { type: 'boolean' },
|
|
55
54
|
},
|
|
56
55
|
};
|
|
57
|
-
static findOrCreate = async (publicKey, hubPublicKey = null
|
|
56
|
+
static findOrCreate = async (publicKey, hubPublicKey = null) => {
|
|
58
57
|
try {
|
|
59
|
-
console.log('Release.findOrCreate', publicKey, programId);
|
|
60
58
|
let release = await Release.query().findOne({ publicKey });
|
|
61
59
|
if (release) {
|
|
62
|
-
console.log('release found', release);
|
|
63
60
|
return release;
|
|
64
61
|
}
|
|
65
|
-
let anchor = programId === process.env.NINA_PROGRAM_V2_ID ? anchorCoral : anchorSerum;
|
|
66
62
|
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
67
63
|
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
|
|
68
|
-
const program = await anchor.Program.at(
|
|
69
|
-
const programModelName = programId === process.env.NINA_PROGRAM_V2_ID ? 'releaseV2' : 'release';
|
|
64
|
+
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
70
65
|
const metaplex = new Metaplex(connection);
|
|
71
66
|
let attempts = 0;
|
|
72
67
|
const releaseAccount = await promiseRetry(async (retry) => {
|
|
73
68
|
try {
|
|
74
69
|
attempts += 1;
|
|
75
|
-
const result = await program.account
|
|
70
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
76
71
|
return result;
|
|
77
72
|
}
|
|
78
73
|
catch (error) {
|
|
@@ -84,13 +79,7 @@ export default class Release extends Model {
|
|
|
84
79
|
minTimeout: 500,
|
|
85
80
|
maxTimeout: 1500,
|
|
86
81
|
});
|
|
87
|
-
let metadataAccount;
|
|
88
|
-
if (programId === process.env.NINA_PROGRAM_V2_ID) {
|
|
89
|
-
metadataAccount = await getTokenMetadata(connection, releaseAccount.mint, 'confirmed');
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
93
|
-
}
|
|
82
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
94
83
|
if (!metadataAccount) {
|
|
95
84
|
throw new Error('No metadata account found for release - is not a complete release');
|
|
96
85
|
}
|
|
@@ -105,13 +94,12 @@ export default class Release extends Model {
|
|
|
105
94
|
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
106
95
|
release = await this.createRelease({
|
|
107
96
|
publicKey,
|
|
108
|
-
mint:
|
|
97
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
109
98
|
metadata: json,
|
|
110
|
-
datetime:
|
|
99
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
111
100
|
slug,
|
|
112
101
|
publisherId: publisher.id,
|
|
113
|
-
releaseAccount
|
|
114
|
-
programId,
|
|
102
|
+
releaseAccount
|
|
115
103
|
});
|
|
116
104
|
if (hubPublicKey) {
|
|
117
105
|
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
@@ -127,7 +115,7 @@ export default class Release extends Model {
|
|
|
127
115
|
return null;
|
|
128
116
|
}
|
|
129
117
|
};
|
|
130
|
-
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount
|
|
118
|
+
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
|
|
131
119
|
const slug = await this.generateSlug(metadata);
|
|
132
120
|
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
133
121
|
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
@@ -140,8 +128,7 @@ export default class Release extends Model {
|
|
|
140
128
|
publisherId,
|
|
141
129
|
price: `${price}`,
|
|
142
130
|
paymentMint,
|
|
143
|
-
archived: false
|
|
144
|
-
programId,
|
|
131
|
+
archived: false
|
|
145
132
|
});
|
|
146
133
|
if (metadata.properties.tags) {
|
|
147
134
|
for await (let tag of metadata.properties.tags) {
|
|
@@ -149,9 +136,7 @@ export default class Release extends Model {
|
|
|
149
136
|
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
150
137
|
}
|
|
151
138
|
}
|
|
152
|
-
|
|
153
|
-
await this.processRevenueShares(releaseAccount, release);
|
|
154
|
-
}
|
|
139
|
+
await this.processRevenueShares(releaseAccount, release);
|
|
155
140
|
tweetNewRelease(metadata, publisherId, slug);
|
|
156
141
|
return release;
|
|
157
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nina-protocol/nina-db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
24
24
|
"@babel/preset-es2015": "^7.0.0-beta.53",
|
|
25
25
|
"@metaplex-foundation/js": "^0.18.1",
|
|
26
|
-
"@
|
|
27
|
-
"@solana/spl-token": "^0.4.9",
|
|
26
|
+
"@project-serum/anchor": "^0.25.0",
|
|
28
27
|
"axios": "^0.27.2",
|
|
29
28
|
"knex": "^2.2.0",
|
|
30
29
|
"nanoid": "^4.0.2",
|
|
@@ -47,6 +46,6 @@
|
|
|
47
46
|
"rollup-plugin-babel": "^4.4.0",
|
|
48
47
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
49
48
|
"rollup-plugin-terser": "^7.0.2",
|
|
50
|
-
"typescript": "
|
|
49
|
+
"typescript": "4.3.5"
|
|
51
50
|
}
|
|
52
51
|
}
|
package/src/models/Account.js
CHANGED
|
@@ -42,8 +42,9 @@ export default class Account extends Model {
|
|
|
42
42
|
this.verifications = verifications;
|
|
43
43
|
}
|
|
44
44
|
delete this.id
|
|
45
|
-
|
|
46
|
-
this.
|
|
45
|
+
// Use count() instead of range(0,0) to avoid temporary object creation
|
|
46
|
+
const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
|
|
47
|
+
this.followers = parseInt(followersCount.count);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
static relationMappings = () => ({
|
package/src/models/Hub.js
CHANGED
|
@@ -35,8 +35,9 @@ export default class Hub extends Model {
|
|
|
35
35
|
|
|
36
36
|
stripHtmlIfNeeded(this.data, 'description');
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
this.
|
|
38
|
+
// Use count() instead of range(0,0) to avoid temporary object creation
|
|
39
|
+
const followersCount = await Subscription.query().where('to', this.publicKey).count('* as count').first();
|
|
40
|
+
this.followers = parseInt(followersCount.count);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
static relationMappings = () => ({
|
package/src/models/Release.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as anchorCoral from '@coral-xyz/anchor';
|
|
1
|
+
import anchor from '@project-serum/anchor';
|
|
3
2
|
import { Metaplex } from '@metaplex-foundation/js';
|
|
4
3
|
import { Model } from 'objection';
|
|
5
4
|
import { stripHtmlIfNeeded, tweetNewRelease }from '../utils/index.js';
|
|
@@ -11,7 +10,7 @@ import Tag from './Tag.js';
|
|
|
11
10
|
import axios from 'axios';
|
|
12
11
|
import promiseRetry from 'promise-retry';
|
|
13
12
|
import { customAlphabet } from 'nanoid';
|
|
14
|
-
import
|
|
13
|
+
import promiseRetry from 'promise-retry';
|
|
15
14
|
|
|
16
15
|
const ensureHttps = (uri) => {
|
|
17
16
|
if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
|
|
@@ -58,30 +57,27 @@ export default class Release extends Model {
|
|
|
58
57
|
},
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
static findOrCreate = async (publicKey, hubPublicKey=null
|
|
60
|
+
static findOrCreate = async (publicKey, hubPublicKey=null) => {
|
|
62
61
|
try {
|
|
63
|
-
console.log('Release.findOrCreate', publicKey, programId)
|
|
64
62
|
let release = await Release.query().findOne({ publicKey });
|
|
65
63
|
if (release) {
|
|
66
|
-
console.log('release found', release)
|
|
67
64
|
return release;
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
let anchor = programId === process.env.NINA_PROGRAM_V2_ID ? anchorCoral : anchorSerum;
|
|
71
67
|
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
72
68
|
const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'confirmed'})
|
|
73
69
|
const program = await anchor.Program.at(
|
|
74
|
-
|
|
70
|
+
process.env.NINA_PROGRAM_ID,
|
|
75
71
|
provider,
|
|
76
72
|
)
|
|
77
|
-
const programModelName = programId === process.env.NINA_PROGRAM_V2_ID ? 'releaseV2' : 'release';
|
|
78
73
|
const metaplex = new Metaplex(connection);
|
|
79
74
|
let attempts = 0;
|
|
75
|
+
|
|
80
76
|
const releaseAccount = await promiseRetry(
|
|
81
77
|
async (retry) => {
|
|
82
78
|
try {
|
|
83
79
|
attempts += 1
|
|
84
|
-
const result = await program.account
|
|
80
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
85
81
|
return result
|
|
86
82
|
} catch (error) {
|
|
87
83
|
console.log('error fetching release account', error)
|
|
@@ -94,12 +90,7 @@ export default class Release extends Model {
|
|
|
94
90
|
}
|
|
95
91
|
)
|
|
96
92
|
|
|
97
|
-
let metadataAccount
|
|
98
|
-
if (programId === process.env.NINA_PROGRAM_V2_ID) {
|
|
99
|
-
metadataAccount = await getTokenMetadata(connection, releaseAccount.mint, 'confirmed')
|
|
100
|
-
} else {
|
|
101
|
-
metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
102
|
-
}
|
|
93
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
103
94
|
if (!metadataAccount) {
|
|
104
95
|
throw new Error('No metadata account found for release - is not a complete release')
|
|
105
96
|
}
|
|
@@ -114,13 +105,12 @@ export default class Release extends Model {
|
|
|
114
105
|
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
115
106
|
release = await this.createRelease({
|
|
116
107
|
publicKey,
|
|
117
|
-
mint:
|
|
108
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
118
109
|
metadata: json,
|
|
119
|
-
datetime:
|
|
110
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
120
111
|
slug,
|
|
121
112
|
publisherId: publisher.id,
|
|
122
|
-
releaseAccount
|
|
123
|
-
programId,
|
|
113
|
+
releaseAccount
|
|
124
114
|
});
|
|
125
115
|
|
|
126
116
|
if (hubPublicKey) {
|
|
@@ -139,7 +129,7 @@ export default class Release extends Model {
|
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
131
|
|
|
142
|
-
static createRelease = async ({publicKey, mint, metadata, datetime, publisherId, releaseAccount
|
|
132
|
+
static createRelease = async ({publicKey, mint, metadata, datetime, publisherId, releaseAccount}) => {
|
|
143
133
|
const slug = await this.generateSlug(metadata);
|
|
144
134
|
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
145
135
|
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
@@ -152,8 +142,7 @@ export default class Release extends Model {
|
|
|
152
142
|
publisherId,
|
|
153
143
|
price: `${price}`,
|
|
154
144
|
paymentMint,
|
|
155
|
-
archived: false
|
|
156
|
-
programId,
|
|
145
|
+
archived: false
|
|
157
146
|
})
|
|
158
147
|
if (metadata.properties.tags) {
|
|
159
148
|
for await (let tag of metadata.properties.tags) {
|
|
@@ -161,9 +150,7 @@ export default class Release extends Model {
|
|
|
161
150
|
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
162
151
|
}
|
|
163
152
|
}
|
|
164
|
-
|
|
165
|
-
await this.processRevenueShares(releaseAccount, release);
|
|
166
|
-
}
|
|
153
|
+
await this.processRevenueShares(releaseAccount, release);
|
|
167
154
|
tweetNewRelease(metadata, publisherId, slug);
|
|
168
155
|
return release;
|
|
169
156
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param { import("knex").Knex } knex
|
|
3
|
-
* @returns { Promise<void> }
|
|
4
|
-
*/
|
|
5
|
-
export const up = function(knex) {
|
|
6
|
-
return knex.schema.table('releases', table => {
|
|
7
|
-
table.string('programId').notNullable().defaultTo(process.env.NINA_PROGRAM_ID);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param { import("knex").Knex } knex
|
|
13
|
-
* @returns { Promise<void> }
|
|
14
|
-
*/
|
|
15
|
-
export const down = function(knex) {
|
|
16
|
-
return knex.schema.table('releases', table => {
|
|
17
|
-
table.dropColumn('programId');
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param { import("knex").Knex } knex
|
|
3
|
-
* @returns { Promise<void> }
|
|
4
|
-
*/
|
|
5
|
-
export const up = function(knex) {
|
|
6
|
-
return knex.schema.table('transactions', table => {
|
|
7
|
-
table.string('programId').notNullable().defaultTo(process.env.NINA_PROGRAM_ID);
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param { import("knex").Knex } knex
|
|
13
|
-
* @returns { Promise<void> }
|
|
14
|
-
*/
|
|
15
|
-
export const down = function(knex) {
|
|
16
|
-
return knex.schema.table('transactions', table => {
|
|
17
|
-
table.dropColumn('programId');
|
|
18
|
-
});
|
|
19
|
-
};
|