@nina-protocol/nina-db 0.0.44 → 0.0.45

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,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
+ };
@@ -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
  }
@@ -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.45",
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,41 @@
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
+ /**
36
+ * @param { import("knex").Knex } knex
37
+ * @returns { Promise<void> }
38
+ */
39
+ export const down = function(knex) {
40
+ return knex.schema.dropTableIfExists('tags');
41
+ };
@@ -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
  }
@@ -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,