@nina-protocol/nina-db 0.0.83 → 0.0.85

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.
@@ -8,7 +8,6 @@ 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';
12
11
  import { customAlphabet } from 'nanoid';
13
12
  const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
14
13
  const randomStringGenerator = customAlphabet(alphabet, 12);
@@ -52,25 +51,10 @@ export default class Release extends Model {
52
51
  return release;
53
52
  }
54
53
  const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
55
- const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'confirmed' });
54
+ const provider = new anchor.AnchorProvider(connection, {}, { commitment: 'processed' });
56
55
  const program = await anchor.Program.at(process.env.NINA_PROGRAM_ID, provider);
57
56
  const metaplex = new Metaplex(connection);
58
- let attempts = 0;
59
- const releaseAccount = await promiseRetry(async (retry) => {
60
- try {
61
- attempts += 1;
62
- const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
63
- return result;
64
- }
65
- catch (error) {
66
- console.log('error fetching release account', error);
67
- retry(error);
68
- }
69
- }, {
70
- retries: 50,
71
- minTimeout: 500,
72
- maxTimeout: 1500,
73
- });
57
+ const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed');
74
58
  let metadataAccount = (await metaplex.nfts().findAllByMintList({ mints: [releaseAccount.releaseMint] }, { commitment: 'confirmed' }))[0];
75
59
  let json;
76
60
  try {
@@ -117,7 +101,7 @@ export default class Release extends Model {
117
101
  if (metadata.properties.tags) {
118
102
  for await (let tag of metadata.properties.tags) {
119
103
  const tagRecord = await Tag.findOrCreate(tag);
120
- await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
104
+ await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict('tags_releases_pkey').ignore();
121
105
  }
122
106
  }
123
107
  await this.processRevenueShares(releaseAccount, release);
@@ -11,8 +11,9 @@ class Subscription extends Model {
11
11
  static get jsonSchema() {
12
12
  return {
13
13
  type: 'object',
14
- required: ['datetime'],
14
+ required: ['publicKey', 'datetime'],
15
15
  properties: {
16
+ publicKey: { type: 'string' },
16
17
  datetime: { type: 'string' },
17
18
  from: { type: 'string' },
18
19
  to: { type: 'string' },
@@ -23,15 +24,15 @@ class Subscription extends Model {
23
24
  },
24
25
  };
25
26
  }
26
- static async findOrCreate({ from, to, datetime, subscriptionType }) {
27
- let subscription = await Subscription.query().findOne({ from, to });
27
+ static async findOrCreate({ publicKey, from, to, datetime, subscriptionType }) {
28
+ let subscription = await Subscription.query().findOne({ publicKey });
28
29
  if (subscription) {
29
30
  return subscription;
30
31
  }
31
32
  subscription = await Subscription.query().insert({
32
- from, to, datetime, subscriptionType
33
+ publicKey, from, to, datetime, subscriptionType
33
34
  });
34
- console.log('Inserted subscription: ', from, to);
35
+ console.log('Inserted subscription: ', publicKey);
35
36
  return subscription;
36
37
  }
37
38
  async format() {
@@ -15,7 +15,7 @@ export default class Tag extends Model {
15
15
  const sanitizedValue = this.sanitizeValue(value);
16
16
  let tag = await Tag.query().where('value', sanitizedValue).first();
17
17
  if (!tag) {
18
- tag = await Tag.query().insert({ value: sanitizedValue });
18
+ tag = await Tag.query().insert({ value: sanitizedValue }).onConflict('value').ignore();
19
19
  }
20
20
  return tag;
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nina-protocol/nina-db",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "description": "",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
@@ -8,10 +8,10 @@ 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';
12
11
  import { customAlphabet } from 'nanoid';
13
12
  const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
14
13
  const randomStringGenerator = customAlphabet(alphabet, 12);
14
+
15
15
  export default class Release extends Model {
16
16
  static tableName = 'releases';
17
17
 
@@ -47,7 +47,7 @@ export default class Release extends Model {
47
47
  archived: { type: 'boolean' },
48
48
  },
49
49
  }
50
-
50
+
51
51
  static findOrCreate = async (publicKey, hubPublicKey=null) => {
52
52
  let release = await Release.query().findOne({ publicKey });
53
53
  if (release) {
@@ -55,31 +55,13 @@ export default class Release extends Model {
55
55
  }
56
56
 
57
57
  const connection = new anchor.web3.Connection(process.env.SOLANA_CLUSTER_URL);
58
- const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'confirmed'})
58
+ const provider = new anchor.AnchorProvider(connection, {}, {commitment: 'processed'})
59
59
  const program = await anchor.Program.at(
60
60
  process.env.NINA_PROGRAM_ID,
61
61
  provider,
62
62
  )
63
63
  const metaplex = new Metaplex(connection);
64
-
65
- let attempts = 0;
66
- const releaseAccount = await promiseRetry(
67
- async (retry) => {
68
- try {
69
- attempts += 1
70
- const result = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
71
- return result
72
- } catch (error) {
73
- console.log('error fetching release account', error)
74
- retry(error)
75
- }
76
- }, {
77
- retries: 50,
78
- minTimeout: 500,
79
- maxTimeout: 1500,
80
- }
81
- )
82
-
64
+ const releaseAccount = await program.account.release.fetch(new anchor.web3.PublicKey(publicKey), 'confirmed')
83
65
  let metadataAccount = (await metaplex.nfts().findAllByMintList({mints: [releaseAccount.releaseMint]}, { commitment: 'confirmed' }))[0];
84
66
  let json
85
67
  try {
@@ -130,7 +112,7 @@ export default class Release extends Model {
130
112
  if (metadata.properties.tags) {
131
113
  for await (let tag of metadata.properties.tags) {
132
114
  const tagRecord = await Tag.findOrCreate(tag);
133
- await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
115
+ await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id).onConflict('tags_releases_pkey').ignore();
134
116
  }
135
117
  }
136
118
  await this.processRevenueShares(releaseAccount, release);
@@ -12,8 +12,9 @@ class Subscription extends Model {
12
12
  static get jsonSchema() {
13
13
  return {
14
14
  type: 'object',
15
- required: ['datetime'],
15
+ required: ['publicKey', 'datetime'],
16
16
  properties: {
17
+ publicKey: { type: 'string' },
17
18
  datetime: { type: 'string' },
18
19
  from: { type: 'string' },
19
20
  to: { type: 'string' },
@@ -25,16 +26,16 @@ class Subscription extends Model {
25
26
  };
26
27
  }
27
28
 
28
- static async findOrCreate({from, to, datetime, subscriptionType}) {
29
- let subscription = await Subscription.query().findOne({ from, to });
29
+ static async findOrCreate({publicKey, from, to, datetime, subscriptionType}) {
30
+ let subscription = await Subscription.query().findOne({ publicKey });
30
31
  if (subscription) {
31
32
  return subscription;
32
33
  }
33
34
 
34
35
  subscription = await Subscription.query().insert({
35
- from, to, datetime, subscriptionType
36
+ publicKey, from, to, datetime, subscriptionType
36
37
  });
37
- console.log('Inserted subscription: ', from, to)
38
+ console.log('Inserted subscription: ', publicKey)
38
39
  return subscription;
39
40
  }
40
41
 
package/src/models/Tag.js CHANGED
@@ -18,7 +18,7 @@ export default class Tag extends Model {
18
18
  const sanitizedValue = this.sanitizeValue(value);
19
19
  let tag = await Tag.query().where('value', sanitizedValue).first();
20
20
  if (!tag) {
21
- tag = await Tag.query().insert({ value: sanitizedValue });
21
+ tag = await Tag.query().insert({ value: sanitizedValue }).onConflict('value').ignore();
22
22
  }
23
23
  return tag;
24
24
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ exports.up = function(knex) {
6
+
7
+ };
8
+
9
+ /**
10
+ * @param { import("knex").Knex } knex
11
+ * @returns { Promise<void> }
12
+ */
13
+ exports.down = function(knex) {
14
+
15
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ exports.up = function(knex) {
6
+
7
+ };
8
+
9
+ /**
10
+ * @param { import("knex").Knex } knex
11
+ * @returns { Promise<void> }
12
+ */
13
+ exports.down = function(knex) {
14
+
15
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ exports.up = function(knex) {
6
+
7
+ };
8
+
9
+ /**
10
+ * @param { import("knex").Knex } knex
11
+ * @returns { Promise<void> }
12
+ */
13
+ exports.down = function(knex) {
14
+
15
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ exports.up = function(knex) {
6
+
7
+ };
8
+
9
+ /**
10
+ * @param { import("knex").Knex } knex
11
+ * @returns { Promise<void> }
12
+ */
13
+ exports.down = function(knex) {
14
+
15
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ exports.up = function(knex) {
6
+
7
+ };
8
+
9
+ /**
10
+ * @param { import("knex").Knex } knex
11
+ * @returns { Promise<void> }
12
+ */
13
+ exports.down = function(knex) {
14
+
15
+ };