@ossy/resources 1.0.1
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/package.json +26 -0
- package/src/index.js +2 -0
- package/src/resource.aggregate.js +83 -0
- package/src/resources.events.js +97 -0
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ossy/resources",
|
|
3
|
+
"description": "Resource domain — aggregate and events for the Ossy resource model",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"module": "./src/index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"ossy": {
|
|
15
|
+
"src": "./src"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"/src",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"gitHead": "df6c1ca73bc04210e7f284df680536b8501be770"
|
|
26
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export class Resource {
|
|
2
|
+
|
|
3
|
+
static AggregateType = 'Resource'
|
|
4
|
+
|
|
5
|
+
static View(events, savedState = {}) {
|
|
6
|
+
return events.reduce((resource, event) => {
|
|
7
|
+
switch (event.type) {
|
|
8
|
+
|
|
9
|
+
case 'Created': {
|
|
10
|
+
const content = event?.payload?.content || {}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
...resource,
|
|
14
|
+
id: event.aggregateId,
|
|
15
|
+
name: event.payload.name,
|
|
16
|
+
location: event.payload.location,
|
|
17
|
+
belongsTo: event.payload.belongsTo,
|
|
18
|
+
type: event.payload.type,
|
|
19
|
+
createdBy: event.createdBy,
|
|
20
|
+
created: event.created,
|
|
21
|
+
lastUpdated: event.created,
|
|
22
|
+
content: content,
|
|
23
|
+
access: event.payload.access || 'restricted',
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
case 'NameUpdated':
|
|
28
|
+
return {
|
|
29
|
+
...resource,
|
|
30
|
+
lastUpdated: event.created,
|
|
31
|
+
name: event.payload.name
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
case 'LocationUpdated':
|
|
35
|
+
return {
|
|
36
|
+
...resource,
|
|
37
|
+
lastUpdated: event.created,
|
|
38
|
+
location: event.payload.location
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case 'ContentUpdated':
|
|
42
|
+
return {
|
|
43
|
+
...resource,
|
|
44
|
+
lastUpdated: event.created,
|
|
45
|
+
content: event.payload.content
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
case 'AccessUpdated':
|
|
49
|
+
return {
|
|
50
|
+
...resource,
|
|
51
|
+
lastUpdated: event.created,
|
|
52
|
+
access: event.payload.access
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
case 'NamedVersionUploaded': {
|
|
56
|
+
const mediaKey = event.payload.Key
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...resource,
|
|
60
|
+
lastUpdated: event.created,
|
|
61
|
+
content: {
|
|
62
|
+
...resource.content,
|
|
63
|
+
sizes: {
|
|
64
|
+
...(resource.content.sizes || {}),
|
|
65
|
+
[event.payload.namedVersion]: mediaKey
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
case 'Deleted':
|
|
72
|
+
return {
|
|
73
|
+
status: ['removed'],
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
return resource
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
}, savedState)
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database queries related to workspace events
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
export class ResourcesEvents {
|
|
6
|
+
|
|
7
|
+
static Created({
|
|
8
|
+
aggregateId, //optional
|
|
9
|
+
createdBy,
|
|
10
|
+
belongsTo,
|
|
11
|
+
location,
|
|
12
|
+
type,
|
|
13
|
+
name,
|
|
14
|
+
...specificTypeProps
|
|
15
|
+
}) {
|
|
16
|
+
return ({
|
|
17
|
+
aggregateId: aggregateId,
|
|
18
|
+
type: 'Created',
|
|
19
|
+
aggregateType: 'Resource',
|
|
20
|
+
createdBy: createdBy,
|
|
21
|
+
payload: {
|
|
22
|
+
...specificTypeProps,
|
|
23
|
+
belongsTo: belongsTo,
|
|
24
|
+
location: location,
|
|
25
|
+
type: type,
|
|
26
|
+
name: name
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static ContentUpdated({ createdBy, content }) {
|
|
32
|
+
return ({
|
|
33
|
+
type: 'ContentUpdated',
|
|
34
|
+
createdBy: createdBy,
|
|
35
|
+
payload: {
|
|
36
|
+
content: content
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static NameUpdated({ createdBy, name }) {
|
|
42
|
+
return ({
|
|
43
|
+
type: 'NameUpdated',
|
|
44
|
+
createdBy: createdBy,
|
|
45
|
+
payload: {
|
|
46
|
+
name: name
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static AccessUpdated({ createdBy, access }) {
|
|
52
|
+
return ({
|
|
53
|
+
type: 'AccessUpdated',
|
|
54
|
+
createdBy: createdBy,
|
|
55
|
+
payload: {
|
|
56
|
+
access: access
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static LocationUpdated({ createdBy, location }) {
|
|
62
|
+
return ({
|
|
63
|
+
type: 'LocationUpdated',
|
|
64
|
+
createdBy: createdBy,
|
|
65
|
+
payload: {
|
|
66
|
+
location: location
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static Deleted({ createdBy }) {
|
|
72
|
+
return ({
|
|
73
|
+
type: 'Deleted',
|
|
74
|
+
createdBy: createdBy
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static NamedVersionUploaded({
|
|
79
|
+
createdBy,
|
|
80
|
+
namedVersion,
|
|
81
|
+
ContentLength,
|
|
82
|
+
ContentType,
|
|
83
|
+
Key
|
|
84
|
+
}) {
|
|
85
|
+
return ({
|
|
86
|
+
type: 'NamedVersionUploaded',
|
|
87
|
+
createdBy: createdBy,
|
|
88
|
+
payload: {
|
|
89
|
+
namedVersion,
|
|
90
|
+
Key,
|
|
91
|
+
ContentLength,
|
|
92
|
+
ContentType,
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|