@nina-protocol/nina-db 0.0.63 → 0.0.65
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/20231116215117_add_tags.js +1 -0
- package/dist/models/Release.js +20 -1
- package/dist/models/Tag.js +48 -0
- package/dist/models/index.js +2 -0
- package/package.json +1 -1
- package/src/migrations/20231116215117_add_tags.js +1 -0
- package/src/models/Release.js +20 -1
- package/src/models/Tag.js +52 -0
- package/src/models/index.js +2 -0
package/dist/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import Tag from './Tag.js';
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import { customAlphabet } from 'nanoid';
|
|
11
12
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
@@ -95,6 +96,12 @@ export default class Release extends Model {
|
|
|
95
96
|
price: `${price}`,
|
|
96
97
|
paymentMint,
|
|
97
98
|
});
|
|
99
|
+
if (metadata.properties.tags) {
|
|
100
|
+
for await (let tag of metadata.properties.tags) {
|
|
101
|
+
const tagRecord = await Tag.findOrCreate(tag);
|
|
102
|
+
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
98
105
|
await this.processRevenueShares(releaseAccount, release);
|
|
99
106
|
tweetNewRelease(metadata, publisherId, slug);
|
|
100
107
|
return release;
|
|
@@ -231,6 +238,18 @@ export default class Release extends Model {
|
|
|
231
238
|
},
|
|
232
239
|
to: 'accounts.id',
|
|
233
240
|
},
|
|
234
|
-
}
|
|
241
|
+
},
|
|
242
|
+
tags: {
|
|
243
|
+
relation: Model.ManyToManyRelation,
|
|
244
|
+
modelClass: Tag,
|
|
245
|
+
join: {
|
|
246
|
+
from: 'releases.id',
|
|
247
|
+
through: {
|
|
248
|
+
from: 'tags_content.releaseId',
|
|
249
|
+
to: 'tags_content.tagId',
|
|
250
|
+
},
|
|
251
|
+
to: 'tags.id',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
235
254
|
});
|
|
236
255
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
export default class Tag extends Model {
|
|
3
|
+
static tableName = 'tags';
|
|
4
|
+
static idColumn = 'id';
|
|
5
|
+
static jsonSchema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
required: ['value'],
|
|
8
|
+
properties: {
|
|
9
|
+
value: { type: 'string' },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
async findOrCreate(value) {
|
|
13
|
+
let tag = await Tag.query().where('value', value).first();
|
|
14
|
+
if (!tag) {
|
|
15
|
+
tag = await Tag.query().insert({ value });
|
|
16
|
+
}
|
|
17
|
+
return tag;
|
|
18
|
+
}
|
|
19
|
+
async format() {
|
|
20
|
+
delete this.id;
|
|
21
|
+
}
|
|
22
|
+
static relationMappings = () => ({
|
|
23
|
+
posts: {
|
|
24
|
+
relation: Model.ManyToManyRelation,
|
|
25
|
+
modelClass: 'Post',
|
|
26
|
+
join: {
|
|
27
|
+
from: 'tags.id',
|
|
28
|
+
through: {
|
|
29
|
+
from: 'tags_content.tagId',
|
|
30
|
+
to: 'tags_content.postId',
|
|
31
|
+
},
|
|
32
|
+
to: 'posts.id',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
releases: {
|
|
36
|
+
relation: Model.ManyToManyRelation,
|
|
37
|
+
modelClass: 'Release',
|
|
38
|
+
join: {
|
|
39
|
+
from: 'tags.id',
|
|
40
|
+
through: {
|
|
41
|
+
from: 'tags_content.tagId',
|
|
42
|
+
to: 'tags_content.releaseId',
|
|
43
|
+
},
|
|
44
|
+
to: 'releases.id',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
package/dist/models/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import Hub from './Hub.js';
|
|
|
4
4
|
import Post from './Post.js';
|
|
5
5
|
import Release from './Release.js';
|
|
6
6
|
import Subscription from './Subscription.js';
|
|
7
|
+
import Tag from './Tag.js';
|
|
7
8
|
import Transaction from './Transaction.js';
|
|
8
9
|
import Verification from './Verification.js';
|
|
9
10
|
const models = {
|
|
@@ -13,6 +14,7 @@ const models = {
|
|
|
13
14
|
Post,
|
|
14
15
|
Release,
|
|
15
16
|
Subscription,
|
|
17
|
+
Tag,
|
|
16
18
|
Transaction,
|
|
17
19
|
Verification,
|
|
18
20
|
};
|
package/package.json
CHANGED
package/src/models/Release.js
CHANGED
|
@@ -6,6 +6,7 @@ import Account from './Account.js';
|
|
|
6
6
|
import Exchange from './Exchange.js';
|
|
7
7
|
import Hub from './Hub.js';
|
|
8
8
|
import Post from './Post.js';
|
|
9
|
+
import Tag from './Tag.js';
|
|
9
10
|
import axios from 'axios';
|
|
10
11
|
import { customAlphabet } from 'nanoid';
|
|
11
12
|
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
@@ -106,6 +107,12 @@ export default class Release extends Model {
|
|
|
106
107
|
price: `${price}`,
|
|
107
108
|
paymentMint,
|
|
108
109
|
})
|
|
110
|
+
if (metadata.properties.tags) {
|
|
111
|
+
for await (let tag of metadata.properties.tags) {
|
|
112
|
+
const tagRecord = await Tag.findOrCreate(tag);
|
|
113
|
+
await Release.relatedQuery('tags').for(release.id).relate(tagRecord.id);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
109
116
|
await this.processRevenueShares(releaseAccount, release);
|
|
110
117
|
tweetNewRelease(metadata, publisherId, slug);
|
|
111
118
|
return release;
|
|
@@ -247,6 +254,18 @@ export default class Release extends Model {
|
|
|
247
254
|
},
|
|
248
255
|
to: 'accounts.id',
|
|
249
256
|
},
|
|
250
|
-
}
|
|
257
|
+
},
|
|
258
|
+
tags: {
|
|
259
|
+
relation: Model.ManyToManyRelation,
|
|
260
|
+
modelClass: Tag,
|
|
261
|
+
join: {
|
|
262
|
+
from: 'releases.id',
|
|
263
|
+
through: {
|
|
264
|
+
from: 'tags_content.releaseId',
|
|
265
|
+
to: 'tags_content.tagId',
|
|
266
|
+
},
|
|
267
|
+
to: 'tags.id',
|
|
268
|
+
},
|
|
269
|
+
},
|
|
251
270
|
})
|
|
252
271
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Model } from 'objection';
|
|
2
|
+
|
|
3
|
+
export default class Tag extends Model {
|
|
4
|
+
static tableName = 'tags';
|
|
5
|
+
static idColumn = 'id';
|
|
6
|
+
static jsonSchema = {
|
|
7
|
+
type: 'object',
|
|
8
|
+
required: ['value'],
|
|
9
|
+
properties: {
|
|
10
|
+
value: { type: 'string' },
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async findOrCreate(value) {
|
|
15
|
+
let tag = await Tag.query().where('value', value).first();
|
|
16
|
+
if (!tag) {
|
|
17
|
+
tag = await Tag.query().insert({ value });
|
|
18
|
+
}
|
|
19
|
+
return tag;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async format () {
|
|
23
|
+
delete this.id
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static relationMappings = () => ({
|
|
27
|
+
posts: {
|
|
28
|
+
relation: Model.ManyToManyRelation,
|
|
29
|
+
modelClass: 'Post',
|
|
30
|
+
join: {
|
|
31
|
+
from: 'tags.id',
|
|
32
|
+
through: {
|
|
33
|
+
from: 'tags_content.tagId',
|
|
34
|
+
to: 'tags_content.postId',
|
|
35
|
+
},
|
|
36
|
+
to: 'posts.id',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
releases: {
|
|
40
|
+
relation: Model.ManyToManyRelation,
|
|
41
|
+
modelClass: 'Release',
|
|
42
|
+
join: {
|
|
43
|
+
from: 'tags.id',
|
|
44
|
+
through: {
|
|
45
|
+
from: 'tags_content.tagId',
|
|
46
|
+
to: 'tags_content.releaseId',
|
|
47
|
+
},
|
|
48
|
+
to: 'releases.id',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
package/src/models/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import Hub from './Hub.js';
|
|
|
4
4
|
import Post from './Post.js';
|
|
5
5
|
import Release from './Release.js';
|
|
6
6
|
import Subscription from './Subscription.js';
|
|
7
|
+
import Tag from './Tag.js';
|
|
7
8
|
import Transaction from './Transaction.js';
|
|
8
9
|
import Verification from './Verification.js';
|
|
9
10
|
|
|
@@ -14,6 +15,7 @@ const models = {
|
|
|
14
15
|
Post,
|
|
15
16
|
Release,
|
|
16
17
|
Subscription,
|
|
18
|
+
Tag,
|
|
17
19
|
Transaction,
|
|
18
20
|
Verification,
|
|
19
21
|
};
|