@nina-protocol/nina-db 0.0.88 → 0.0.90
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/migrations/20250120215722_add_ref_columns.js +18 -0
- package/dist/models/Release.js +17 -1
- package/dist/models/Subscription.js +2 -3
- package/package.json +2 -1
- package/src/migrations/20250120215722_add_ref_columns.js +19 -0
- package/src/models/Release.js +23 -3
- package/src/models/Subscription.js +2 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function (knex) {
|
|
6
|
+
return knex.schema.table('subscriptions', table => {
|
|
7
|
+
table.string('ref').nullable();
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @param { import("knex").Knex } knex
|
|
12
|
+
* @returns { Promise<void> }
|
|
13
|
+
*/
|
|
14
|
+
export const down = function (knex) {
|
|
15
|
+
return knex.schema.table('subscriptions', table => {
|
|
16
|
+
table.dropColumn('ref');
|
|
17
|
+
});
|
|
18
|
+
};
|
package/dist/models/Release.js
CHANGED
|
@@ -8,6 +8,7 @@ import Hub from './Hub.js';
|
|
|
8
8
|
import Post from './Post.js';
|
|
9
9
|
import Tag from './Tag.js';
|
|
10
10
|
import axios from 'axios';
|
|
11
|
+
import promiseRetry from 'promise-retry';
|
|
11
12
|
import { customAlphabet } from 'nanoid';
|
|
12
13
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
13
14
|
const randomStringGenerator = customAlphabet(alphabet, 12);
|
|
@@ -55,7 +56,22 @@ export default class Release extends Model {
|
|
|
55
56
|
const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
|
|
56
57
|
const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
|
|
57
58
|
const metaplex = new Metaplex(connection);
|
|
58
|
-
|
|
59
|
+
let attempts = 0;
|
|
60
|
+
const releaseAccount = await promiseRetry(async (retry) => {
|
|
61
|
+
try {
|
|
62
|
+
attempts += 1;
|
|
63
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('error fetching release account', error);
|
|
68
|
+
retry(error);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
retries: 50,
|
|
72
|
+
minTimeout: 500,
|
|
73
|
+
maxTimeout: 1500,
|
|
74
|
+
});
|
|
59
75
|
let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
|
|
60
76
|
if (!metadataAccount) {
|
|
61
77
|
throw new Error('No metadata account found for release - is not a complete release');
|
|
@@ -13,7 +13,6 @@ class Subscription extends Model {
|
|
|
13
13
|
type: 'object',
|
|
14
14
|
required: ['datetime'],
|
|
15
15
|
properties: {
|
|
16
|
-
publicKey: { type: 'string' },
|
|
17
16
|
datetime: { type: 'string' },
|
|
18
17
|
from: { type: 'string' },
|
|
19
18
|
to: { type: 'string' },
|
|
@@ -24,7 +23,7 @@ class Subscription extends Model {
|
|
|
24
23
|
},
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
static async findOrCreate({
|
|
26
|
+
static async findOrCreate({ from, to, datetime, subscriptionType }) {
|
|
28
27
|
let subscription = await Subscription.query().findOne({ from, to });
|
|
29
28
|
if (subscription) {
|
|
30
29
|
return subscription;
|
|
@@ -32,7 +31,7 @@ class Subscription extends Model {
|
|
|
32
31
|
subscription = await Subscription.query().insert({
|
|
33
32
|
from, to, datetime, subscriptionType
|
|
34
33
|
});
|
|
35
|
-
console.log('Inserted subscription: ',
|
|
34
|
+
console.log('Inserted subscription: ', from, to);
|
|
36
35
|
return subscription;
|
|
37
36
|
}
|
|
38
37
|
async format() {
|
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.90",
|
|
4
4
|
"description": "",
|
|
5
5
|
"source": "src/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"nanoid": "^4.0.2",
|
|
30
30
|
"objection": "2.2.15",
|
|
31
31
|
"pg": "^8.7.3",
|
|
32
|
+
"promise-retry": "^2.0.1",
|
|
32
33
|
"striptags": "^3.2.0",
|
|
33
34
|
"twitter-api-v2": "^1.12.9"
|
|
34
35
|
},
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param { import("knex").Knex } knex
|
|
3
|
+
* @returns { Promise<void> }
|
|
4
|
+
*/
|
|
5
|
+
export const up = function(knex) {
|
|
6
|
+
return knex.schema.table('subscriptions', table => {
|
|
7
|
+
table.string('ref').nullable();
|
|
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('subscriptions', table => {
|
|
17
|
+
table.dropColumn('ref');
|
|
18
|
+
});
|
|
19
|
+
};
|
package/src/models/Release.js
CHANGED
|
@@ -8,10 +8,12 @@ import Hub from './Hub.js';
|
|
|
8
8
|
import Post from './Post.js';
|
|
9
9
|
import Tag from './Tag.js';
|
|
10
10
|
import axios from 'axios';
|
|
11
|
+
import promiseRetry from 'promise-retry';
|
|
11
12
|
import { customAlphabet } from 'nanoid';
|
|
13
|
+
import promiseRetry from 'promise-retry';
|
|
14
|
+
|
|
12
15
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
13
16
|
const randomStringGenerator = customAlphabet(alphabet, 12);
|
|
14
|
-
|
|
15
17
|
export default class Release extends Model {
|
|
16
18
|
static tableName = 'releases';
|
|
17
19
|
|
|
@@ -47,7 +49,7 @@ export default class Release extends Model {
|
|
|
47
49
|
archived: { type: 'boolean' },
|
|
48
50
|
},
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
|
|
51
53
|
static findOrCreate = async (publicKey, hubPublicKey=null) => {
|
|
52
54
|
try {
|
|
53
55
|
let release = await Release.query().findOne({ publicKey });
|
|
@@ -62,7 +64,25 @@ export default class Release extends Model {
|
|
|
62
64
|
provider,
|
|
63
65
|
)
|
|
64
66
|
const metaplex = new Metaplex(connection);
|
|
65
|
-
|
|
67
|
+
let attempts = 0;
|
|
68
|
+
|
|
69
|
+
const releaseAccount = await promiseRetry(
|
|
70
|
+
async (retry) => {
|
|
71
|
+
try {
|
|
72
|
+
attempts += 1
|
|
73
|
+
const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
|
|
74
|
+
return result
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.log('error fetching release account', error)
|
|
77
|
+
retry(error)
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
retries: 50,
|
|
81
|
+
minTimeout: 500,
|
|
82
|
+
maxTimeout: 1500,
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
|
|
66
86
|
let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
|
|
67
87
|
if (!metadataAccount) {
|
|
68
88
|
throw new Error('No metadata account found for release - is not a complete release')
|
|
@@ -14,7 +14,6 @@ class Subscription extends Model {
|
|
|
14
14
|
type: 'object',
|
|
15
15
|
required: ['datetime'],
|
|
16
16
|
properties: {
|
|
17
|
-
publicKey: { type: 'string' },
|
|
18
17
|
datetime: { type: 'string' },
|
|
19
18
|
from: { type: 'string' },
|
|
20
19
|
to: { type: 'string' },
|
|
@@ -26,7 +25,7 @@ class Subscription extends Model {
|
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
static async findOrCreate({
|
|
28
|
+
static async findOrCreate({from, to, datetime, subscriptionType}) {
|
|
30
29
|
let subscription = await Subscription.query().findOne({ from, to });
|
|
31
30
|
if (subscription) {
|
|
32
31
|
return subscription;
|
|
@@ -35,7 +34,7 @@ class Subscription extends Model {
|
|
|
35
34
|
subscription = await Subscription.query().insert({
|
|
36
35
|
from, to, datetime, subscriptionType
|
|
37
36
|
});
|
|
38
|
-
console.log('Inserted subscription: ',
|
|
37
|
+
console.log('Inserted subscription: ', from, to)
|
|
39
38
|
return subscription;
|
|
40
39
|
}
|
|
41
40
|
|