@nina-protocol/nina-db 0.0.102 → 0.0.104
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 +11 -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 +12 -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,6 @@ 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 { getTokenMetadata } from '@solana/spl-token';
|
|
15
13
|
const ensureHttps = (uri) => {
|
|
16
14
|
if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
|
|
17
15
|
return `https://${uri}`;
|
|
@@ -54,25 +52,21 @@ export default class Release extends Model {
|
|
|
54
52
|
archived: { type: 'boolean' },
|
|
55
53
|
},
|
|
56
54
|
};
|
|
57
|
-
static findOrCreate = async (publicKey, hubPublicKey = null
|
|
55
|
+
static findOrCreate = async (publicKey, hubPublicKey = null) => {
|
|
58
56
|
try {
|
|
59
|
-
console.log('Release.findOrCreate', publicKey, programId);
|
|
60
57
|
let release = await Release.query().findOne({ publicKey });
|
|
61
58
|
if (release) {
|
|
62
|
-
console.log('release found', release);
|
|
63
59
|
return release;
|
|
64
60
|
}
|
|
65
|
-
let anchor = programId === process.env.NINA_PROGRAM_V2_ID ? anchorCoral : anchorSerum;
|
|
66
61
|
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
67
62
|
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';
|
|
63
|
+
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
70
64
|
const metaplex = new Metaplex(connection);
|
|
71
65
|
let attempts = 0;
|
|
72
66
|
const releaseAccount = await promiseRetry(async (retry) => {
|
|
73
67
|
try {
|
|
74
68
|
attempts += 1;
|
|
75
|
-
const result = await program.account
|
|
69
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
76
70
|
return result;
|
|
77
71
|
}
|
|
78
72
|
catch (error) {
|
|
@@ -84,13 +78,7 @@ export default class Release extends Model {
|
|
|
84
78
|
minTimeout: 500,
|
|
85
79
|
maxTimeout: 1500,
|
|
86
80
|
});
|
|
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
|
-
}
|
|
81
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
94
82
|
if (!metadataAccount) {
|
|
95
83
|
throw new Error('No metadata account found for release - is not a complete release');
|
|
96
84
|
}
|
|
@@ -105,13 +93,12 @@ export default class Release extends Model {
|
|
|
105
93
|
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
106
94
|
release = await this.createRelease({
|
|
107
95
|
publicKey,
|
|
108
|
-
mint:
|
|
96
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
109
97
|
metadata: json,
|
|
110
|
-
datetime:
|
|
98
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
111
99
|
slug,
|
|
112
100
|
publisherId: publisher.id,
|
|
113
|
-
releaseAccount
|
|
114
|
-
programId,
|
|
101
|
+
releaseAccount
|
|
115
102
|
});
|
|
116
103
|
if (hubPublicKey) {
|
|
117
104
|
const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
|
|
@@ -127,7 +114,7 @@ export default class Release extends Model {
|
|
|
127
114
|
return null;
|
|
128
115
|
}
|
|
129
116
|
};
|
|
130
|
-
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount
|
|
117
|
+
static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
|
|
131
118
|
const slug = await this.generateSlug(metadata);
|
|
132
119
|
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
133
120
|
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
@@ -140,8 +127,7 @@ export default class Release extends Model {
|
|
|
140
127
|
publisherId,
|
|
141
128
|
price: `${price}`,
|
|
142
129
|
paymentMint,
|
|
143
|
-
archived: false
|
|
144
|
-
programId,
|
|
130
|
+
archived: false
|
|
145
131
|
});
|
|
146
132
|
if (metadata.properties.tags) {
|
|
147
133
|
for await (let tag of metadata.properties.tags) {
|
|
@@ -149,9 +135,7 @@ export default class Release extends Model {
|
|
|
149
135
|
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
150
136
|
}
|
|
151
137
|
}
|
|
152
|
-
|
|
153
|
-
await this.processRevenueShares(releaseAccount, release);
|
|
154
|
-
}
|
|
138
|
+
await this.processRevenueShares(releaseAccount, release);
|
|
155
139
|
tweetNewRelease(metadata, publisherId, slug);
|
|
156
140
|
return release;
|
|
157
141
|
};
|
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.104",
|
|
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,6 @@ 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 { getTokenMetadata } from '@solana/spl-token';
|
|
15
13
|
|
|
16
14
|
const ensureHttps = (uri) => {
|
|
17
15
|
if (!uri.startsWith('http://') && !uri.startsWith('https://')) {
|
|
@@ -58,30 +56,27 @@ export default class Release extends Model {
|
|
|
58
56
|
},
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
static findOrCreate = async (publicKey, hubPublicKey=null
|
|
59
|
+
static findOrCreate = async (publicKey, hubPublicKey=null) => {
|
|
62
60
|
try {
|
|
63
|
-
console.log('Release.findOrCreate', publicKey, programId)
|
|
64
61
|
let release = await Release.query().findOne({ publicKey });
|
|
65
62
|
if (release) {
|
|
66
|
-
console.log('release found', release)
|
|
67
63
|
return release;
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
let anchor = programId === process.env.NINA_PROGRAM_V2_ID ? anchorCoral : anchorSerum;
|
|
71
66
|
const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
|
|
72
67
|
const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'confirmed'})
|
|
73
68
|
const program = await anchor.Program.at(
|
|
74
|
-
|
|
69
|
+
process.env.NINA_PROGRAM_ID,
|
|
75
70
|
provider,
|
|
76
71
|
)
|
|
77
|
-
const programModelName = programId === process.env.NINA_PROGRAM_V2_ID ? 'releaseV2' : 'release';
|
|
78
72
|
const metaplex = new Metaplex(connection);
|
|
79
73
|
let attempts = 0;
|
|
74
|
+
|
|
80
75
|
const releaseAccount = await promiseRetry(
|
|
81
76
|
async (retry) => {
|
|
82
77
|
try {
|
|
83
78
|
attempts += 1
|
|
84
|
-
const result = await program.account
|
|
79
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
85
80
|
return result
|
|
86
81
|
} catch (error) {
|
|
87
82
|
console.log('error fetching release account', error)
|
|
@@ -94,12 +89,7 @@ export default class Release extends Model {
|
|
|
94
89
|
}
|
|
95
90
|
)
|
|
96
91
|
|
|
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
|
-
}
|
|
92
|
+
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
103
93
|
if (!metadataAccount) {
|
|
104
94
|
throw new Error('No metadata account found for release - is not a complete release')
|
|
105
95
|
}
|
|
@@ -114,13 +104,12 @@ export default class Release extends Model {
|
|
|
114
104
|
let publisher = await Account.findOrCreate(releaseAccount.authority.toBase58());
|
|
115
105
|
release = await this.createRelease({
|
|
116
106
|
publicKey,
|
|
117
|
-
mint:
|
|
107
|
+
mint: releaseAccount.releaseMint.toBase58(),
|
|
118
108
|
metadata: json,
|
|
119
|
-
datetime:
|
|
109
|
+
datetime: new Date(releaseAccount.releaseDatetime.toNumber() * 1000).toISOString(),
|
|
120
110
|
slug,
|
|
121
111
|
publisherId: publisher.id,
|
|
122
|
-
releaseAccount
|
|
123
|
-
programId,
|
|
112
|
+
releaseAccount
|
|
124
113
|
});
|
|
125
114
|
|
|
126
115
|
if (hubPublicKey) {
|
|
@@ -139,7 +128,7 @@ export default class Release extends Model {
|
|
|
139
128
|
}
|
|
140
129
|
}
|
|
141
130
|
|
|
142
|
-
static createRelease = async ({publicKey, mint, metadata, datetime, publisherId, releaseAccount
|
|
131
|
+
static createRelease = async ({publicKey, mint, metadata, datetime, publisherId, releaseAccount}) => {
|
|
143
132
|
const slug = await this.generateSlug(metadata);
|
|
144
133
|
const price = releaseAccount.account?.price?.toNumber() || releaseAccount?.price?.toNumber() || 0;
|
|
145
134
|
const paymentMint = releaseAccount.account?.paymentMint.toBase58() || releaseAccount?.paymentMint.toBase58();
|
|
@@ -152,8 +141,7 @@ export default class Release extends Model {
|
|
|
152
141
|
publisherId,
|
|
153
142
|
price: `${price}`,
|
|
154
143
|
paymentMint,
|
|
155
|
-
archived: false
|
|
156
|
-
programId,
|
|
144
|
+
archived: false
|
|
157
145
|
})
|
|
158
146
|
if (metadata.properties.tags) {
|
|
159
147
|
for await (let tag of metadata.properties.tags) {
|
|
@@ -161,9 +149,7 @@ export default class Release extends Model {
|
|
|
161
149
|
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict(['tagId', 'releaseId']).ignore();
|
|
162
150
|
}
|
|
163
151
|
}
|
|
164
|
-
|
|
165
|
-
await this.processRevenueShares(releaseAccount, release);
|
|
166
|
-
}
|
|
152
|
+
await this.processRevenueShares(releaseAccount, release);
|
|
167
153
|
tweetNewRelease(metadata, publisherId, slug);
|
|
168
154
|
return release;
|
|
169
155
|
}
|
|
@@ -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
|
-
};
|