@nina-protocol/nina-db 0.0.44 → 0.0.46

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.
@@ -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.table('posts', table => {
7
+ table.string('version').notNullable().defaultTo('0.0.0');
8
+ });
9
+ };
10
+ /**
11
+ * @param { import("knex").Knex } knex
12
+ * @returns { Promise<void> }
13
+ */
14
+ export const down = function (knex) {
15
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ export const up = function (knex) {
6
+ return Promise.all([
7
+ knex.schema.createTable('tags', table => {
8
+ table.increments('id').primary();
9
+ table.string('value').notNullable();
10
+ }),
11
+ knex.schema.createTable('tags_content', table => {
12
+ table.primary(['tagId', 'releaseId', 'postId']);
13
+ table.integer('releaseId')
14
+ .unsigned()
15
+ .references('id')
16
+ .inTable('releases')
17
+ .onDelete('CASCADE')
18
+ .index();
19
+ table.integer('postId')
20
+ .unsigned()
21
+ .references('id')
22
+ .inTable('accounts')
23
+ .onDelete('CASCADE')
24
+ .index();
25
+ table.integer('tagId')
26
+ .unsigned()
27
+ .references('id')
28
+ .inTable('accounts')
29
+ .onDelete('CASCADE')
30
+ .index();
31
+ }),
32
+ ]);
33
+ };
34
+ /**
35
+ * @param { import("knex").Knex } knex
36
+ * @returns { Promise<void> }
37
+ */
38
+ export const down = function (knex) {
39
+ return knex.schema.dropTableIfExists('tags');
40
+ };
@@ -0,0 +1,16 @@
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.number('price').defaultTo(0);
8
+ table.string('paymentMint');
9
+ });
10
+ };
11
+ /**
12
+ * @param { import("knex").Knex } knex
13
+ * @returns { Promise<void> }
14
+ */
15
+ export const down = function (knex) {
16
+ };
@@ -13,11 +13,12 @@ class Post extends Model {
13
13
  static get jsonSchema() {
14
14
  return {
15
15
  type: 'object',
16
- required: ['publicKey', 'data', 'datetime'],
16
+ required: ['publicKey', 'data', 'datetime', 'version'],
17
17
  properties: {
18
18
  publicKey: { type: 'string' },
19
19
  data: { type: 'object' },
20
20
  datetime: { type: 'string' },
21
+ version: { type: 'string' },
21
22
  },
22
23
  };
23
24
  }
@@ -15,7 +15,7 @@ export default class Release extends Model {
15
15
  static idColumn = 'id';
16
16
  static jsonSchema = {
17
17
  type: 'object',
18
- required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug'],
18
+ required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug', 'price'],
19
19
  properties: {
20
20
  publicKey: { type: 'string' },
21
21
  mint: { type: 'string' },
@@ -40,9 +40,10 @@ export default class Release extends Model {
40
40
  }
41
41
  }
42
42
  },
43
+ price: { type: 'number' },
43
44
  },
44
45
  };
45
- static findOrCreate = async (publicKey) => {
46
+ static findOrCreate = async (publicKey, hubPublicKey = null) => {
46
47
  let release = await Release.query().findOne({ publicKey });
47
48
  if (release) {
48
49
  return release;
@@ -71,6 +72,13 @@ export default class Release extends Model {
71
72
  publisherId: publisher.id,
72
73
  releaseAccount
73
74
  });
75
+ if (hubPublicKey) {
76
+ const hub = await Hub.query().findOne({ publicKey: hubPublicKey });
77
+ await release.$query().patch({ hubId: hub.id });
78
+ await Hub.relatedQuery('releases').for(hub.id).patch({
79
+ visible: true,
80
+ }).where({ id: release.id });
81
+ }
74
82
  return release;
75
83
  };
76
84
  static createRelease = async ({ publicKey, mint, metadata, datetime, publisherId, releaseAccount }) => {
@@ -82,6 +90,8 @@ export default class Release extends Model {
82
90
  slug,
83
91
  datetime,
84
92
  publisherId,
93
+ price: releaseAccount.price.toNumber(),
94
+ paymentMint: releaseAccount.paymentMint.toBase58(),
85
95
  });
86
96
  await this.processRevenueShares(releaseAccount, release);
87
97
  tweetNewRelease(metadata, publisherId);
@@ -1,6 +1,7 @@
1
1
  import striptags from 'striptags';
2
2
  import { TwitterApi } from 'twitter-api-v2';
3
3
  import Account from '../models/Account.js';
4
+ const TWEET_DELAY = 180000; // 3 minutes
4
5
  const removeQuotesFromStartAndEndOfString = (string) => {
5
6
  return string.substring(1, string.length - 1).substring(-1, string.length - 1);
6
7
  };
@@ -18,7 +19,7 @@ export const decode = (byteArray) => {
18
19
  export const tweetNewRelease = async (metadata, publisherId) => {
19
20
  if (process.env.TWITTER_API_SECRET) {
20
21
  try {
21
- await new Promise(resolve => setTimeout(resolve, 60000));
22
+ await new Promise(resolve => setTimeout(resolve, TWEET_DELAY));
22
23
  const client = new TwitterApi({
23
24
  appKey: process.env.TWITTER_API_KEY,
24
25
  appSecret: process.env.TWITTER_API_SECRET,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nina-protocol/nina-db",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "description": "",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @param { import("knex").Knex } knex
3
+ * @returns { Promise<void> }
4
+ */
5
+ export const up = function(knex) {
6
+ return knex.schema.table('posts' , table => {
7
+ table.string('version').notNullable().defaultTo('0.0.0');
8
+ });
9
+ };
10
+
11
+ /**
12
+ * @param { import("knex").Knex } knex
13
+ * @returns { Promise<void> }
14
+ */
15
+ export const down = function(knex) {
16
+
17
+ };
@@ -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('releases' , table => {
7
+ table.number('price').defaultTo(0);
8
+ table.string('paymentMint');
9
+ });
10
+ };
11
+
12
+ /**
13
+ * @param { import("knex").Knex } knex
14
+ * @returns { Promise<void> }
15
+ */
16
+ export const down = function(knex) {
17
+
18
+ };
@@ -14,11 +14,12 @@ class Post extends Model {
14
14
  static get jsonSchema() {
15
15
  return {
16
16
  type: 'object',
17
- required: ['publicKey', 'data', 'datetime'],
17
+ required: ['publicKey', 'data', 'datetime', 'version'],
18
18
  properties: {
19
19
  publicKey: { type: 'string' },
20
20
  data: { type: 'object' },
21
21
  datetime: { type: 'string' },
22
+ version: { type: 'string' },
22
23
  },
23
24
  };
24
25
  }
@@ -18,7 +18,7 @@ export default class Release extends Model {
18
18
  static idColumn = 'id';
19
19
  static jsonSchema = {
20
20
  type: 'object',
21
- required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug'],
21
+ required: ['publicKey', 'mint', 'metadata', 'datetime', 'slug', 'price'],
22
22
  properties: {
23
23
  publicKey: { type: 'string' },
24
24
  mint: { type: 'string' },
@@ -43,10 +43,11 @@ export default class Release extends Model {
43
43
  }
44
44
  }
45
45
  },
46
+ price: { type: 'number' },
46
47
  },
47
48
  }
48
49
 
49
- static findOrCreate = async (publicKey) => {
50
+ static findOrCreate = async (publicKey, hubPublicKey=null) => {
50
51
  let release = await Release.query().findOne({ publicKey });
51
52
  if (release) {
52
53
  return release;
@@ -79,6 +80,16 @@ export default class Release extends Model {
79
80
  publisherId: publisher.id,
80
81
  releaseAccount
81
82
  });
83
+
84
+ if (hubPublicKey) {
85
+
86
+ const hub = await Hub.query().findOne({ publicKey: hubPublicKey })
87
+ await release.$query().patch({ hubId: hub.id })
88
+ await Hub.relatedQuery('releases').for(hub.id).patch({
89
+ visible: true,
90
+ }).where( {id: release.id });
91
+ }
92
+
82
93
  return release;
83
94
  }
84
95
 
@@ -92,6 +103,8 @@ export default class Release extends Model {
92
103
  slug,
93
104
  datetime,
94
105
  publisherId,
106
+ price: releaseAccount.price.toNumber(),
107
+ paymentMint: releaseAccount.paymentMint.toBase58(),
95
108
  })
96
109
  await this.processRevenueShares(releaseAccount, release);
97
110
  tweetNewRelease(metadata, publisherId);
@@ -2,6 +2,8 @@ import striptags from 'striptags';
2
2
  import { TwitterApi } from 'twitter-api-v2';
3
3
  import Account from '../models/Account.js';
4
4
 
5
+ const TWEET_DELAY = 180000; // 3 minutes
6
+
5
7
  const removeQuotesFromStartAndEndOfString = (string) => {
6
8
  return string.substring(1, string.length - 1).substring(-1, string.length - 1);
7
9
  }
@@ -22,7 +24,7 @@ export const decode = (byteArray) => {
22
24
  export const tweetNewRelease = async (metadata, publisherId) => {
23
25
  if (process.env.TWITTER_API_SECRET) {
24
26
  try {
25
- await new Promise(resolve => setTimeout(resolve, 60000))
27
+ await new Promise(resolve => setTimeout(resolve, TWEET_DELAY))
26
28
  const client = new TwitterApi({
27
29
  appKey: process.env.TWITTER_API_KEY,
28
30
  appSecret: process.env.TWITTER_API_SECRET,