@live-change/content-service 0.2.50
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/definition.js +11 -0
- package/index.js +68 -0
- package/model.js +66 -0
- package/package.json +32 -0
package/definition.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const app = require("@live-change/framework").app()
|
|
2
|
+
|
|
3
|
+
const relationsPlugin = require('@live-change/relations-plugin')
|
|
4
|
+
const accessControlService = require('@live-change/user-service')
|
|
5
|
+
|
|
6
|
+
const definition = app.createServiceDefinition({
|
|
7
|
+
name: "content",
|
|
8
|
+
use: [ relationsPlugin, accessControlService ]
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
module.exports = definition
|
package/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const App = require("@live-change/framework")
|
|
2
|
+
const app = App.app()
|
|
3
|
+
|
|
4
|
+
const definition = require('./definition.js')
|
|
5
|
+
|
|
6
|
+
const config = definition.config
|
|
7
|
+
const {
|
|
8
|
+
contentReaderRoles = ['reader'],
|
|
9
|
+
contentWriterRoles = ['writer']
|
|
10
|
+
} = config
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const { Content, Session } = require("./model.js")
|
|
14
|
+
const Snapshot = definition.foreignModel("prosemirror", "Snapshot")
|
|
15
|
+
|
|
16
|
+
definition.view({
|
|
17
|
+
name: "content",
|
|
18
|
+
properties: {
|
|
19
|
+
objectType: {
|
|
20
|
+
type: String,
|
|
21
|
+
validation: ['nonEmpty']
|
|
22
|
+
},
|
|
23
|
+
object: {
|
|
24
|
+
type: String,
|
|
25
|
+
validation: ['nonEmpty']
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
returns: {
|
|
29
|
+
type: Object,
|
|
30
|
+
properties: {
|
|
31
|
+
content: {
|
|
32
|
+
type: Object,
|
|
33
|
+
},
|
|
34
|
+
timestamp: {
|
|
35
|
+
type: Date
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
accessControl: {
|
|
40
|
+
roles: ['reader']
|
|
41
|
+
},
|
|
42
|
+
daoPath({ objectType, object }, { client, service }, method) {
|
|
43
|
+
const contentId = App.encodeIdentifier([objectType, object])
|
|
44
|
+
return ['database', 'queryObject', app.databaseName, `(${
|
|
45
|
+
async (input, output, { contentTableName, snapshotTableName, contentId }) => {
|
|
46
|
+
const snapshotTable = input.table(snapshotTableName)
|
|
47
|
+
let storedSnapshotId = undefined
|
|
48
|
+
await input.table(contentTableName).object(contentId).onChange(async (obj, oldObj) => {
|
|
49
|
+
const snapshot = obj && await snapshotTable.object(obj.snapshot).get()
|
|
50
|
+
const oldSnapshot = storedSnapshotId && await snapshotTable.object(storedSnapshotId).get()
|
|
51
|
+
const newResult = snapshot && {
|
|
52
|
+
content: snapshot.content,
|
|
53
|
+
timestamp: snapshot.timestamp
|
|
54
|
+
}
|
|
55
|
+
const oldResult = oldSnapshot && {
|
|
56
|
+
content: oldSnapshot.content,
|
|
57
|
+
timestamp: oldSnapshot.timestamp
|
|
58
|
+
}
|
|
59
|
+
output.change(newResult, oldResult)
|
|
60
|
+
storedSnapshotId = obj?.snapshot
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
})`, { contentTableName: Content.tableName, snapshotTableName: Snapshot.tableName, contentId }]
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
module.exports = definition
|
package/model.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const App = require("@live-change/framework")
|
|
2
|
+
const app = App.app()
|
|
3
|
+
const definition = require('./definition.js')
|
|
4
|
+
|
|
5
|
+
const config = definition.config
|
|
6
|
+
const {
|
|
7
|
+
contentReaderRoles = ['reader'],
|
|
8
|
+
contentWriterRoles = ['writer']
|
|
9
|
+
} = config
|
|
10
|
+
|
|
11
|
+
const contentProperties = {
|
|
12
|
+
snapshot: {
|
|
13
|
+
type: String
|
|
14
|
+
},
|
|
15
|
+
dependencies: { // automatically generated list of static dependencies(images, documents etc.)
|
|
16
|
+
type: Array,
|
|
17
|
+
of: {
|
|
18
|
+
type: Array // Path - generated with frontend
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const Content = definition.model({
|
|
24
|
+
name: 'Content',
|
|
25
|
+
propertyOfAny: {
|
|
26
|
+
readAccessControl: {
|
|
27
|
+
roles: contentReaderRoles
|
|
28
|
+
},
|
|
29
|
+
writeAccessControl: {
|
|
30
|
+
roles: contentWriterRoles
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
properties: {
|
|
34
|
+
...contentProperties
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const AdditionalContent = definition.model({
|
|
39
|
+
name: 'AdditionalContent',
|
|
40
|
+
itemOf: {
|
|
41
|
+
what: Content,
|
|
42
|
+
readAccessControl: {
|
|
43
|
+
roles: contentReaderRoles
|
|
44
|
+
},
|
|
45
|
+
writeAccessControl: {
|
|
46
|
+
roles: contentWriterRoles
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
properties: {
|
|
50
|
+
...contentProperties
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const Page = definition.model({
|
|
55
|
+
name: 'Page',
|
|
56
|
+
entity: {
|
|
57
|
+
readAccessControl: {
|
|
58
|
+
roles: ['reader']
|
|
59
|
+
},
|
|
60
|
+
writeAccessControl: {
|
|
61
|
+
roles: ['writer']
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
module.exports = { Content, AdditionalContent, Page }
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@live-change/content-service",
|
|
3
|
+
"version": "0.2.50",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "NODE_ENV=test tape tests/*"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-services.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/live-change/live-change-services/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-services",
|
|
18
|
+
"author": {
|
|
19
|
+
"email": "michal@laszczewski.pl",
|
|
20
|
+
"name": "Michał Łaszczewski",
|
|
21
|
+
"url": "https://www.viamage.com/"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@live-change/framework": "0.6.14",
|
|
25
|
+
"@live-change/relations-plugin": "0.6.14",
|
|
26
|
+
"lru-cache": "^7.12.0",
|
|
27
|
+
"pluralize": "8.0.0",
|
|
28
|
+
"progress-stream": "^2.0.0",
|
|
29
|
+
"prosemirror-model": "^1.18.1"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "8d09f0f01547edd2c1321a8d7341e33aff4c562d"
|
|
32
|
+
}
|