@sockethub/activity-streams 4.4.0-alpha.4 → 4.4.0-alpha.5
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/README.md +109 -9
- package/dist/activity-streams.js +462 -0
- package/dist/activity-streams.min.js +19 -2
- package/package.json +27 -31
- package/coverage/tmp/coverage-39176-1663949475687-0.json +0 -1
- package/dist/activity-streams.min.js.LICENSE.txt +0 -16
- package/karma.config.js +0 -22
- package/src/activity-streams.d.ts +0 -1
- package/src/activity-streams.js +0 -224
- package/src/activity-streams.test.js +0 -192
- package/webpack.config.js +0 -10
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* activity-streams
|
|
3
|
-
* https://github.com/silverbucket/activity-streams
|
|
4
|
-
*
|
|
5
|
-
* Developed and Maintained by:
|
|
6
|
-
* Nick Jennings <nick@silverbucket.net>
|
|
7
|
-
*
|
|
8
|
-
* activity-streams is released under the MIT (see LICENSE).
|
|
9
|
-
*
|
|
10
|
-
* You don't have to do anything special to choose one license or the other
|
|
11
|
-
* and you don't have to notify anyone which license you are using.
|
|
12
|
-
* Please see the corresponding license file for details of these licenses.
|
|
13
|
-
* You are free to use, modify and distribute this software, but all copyright
|
|
14
|
-
* information must remain.
|
|
15
|
-
*
|
|
16
|
-
*/
|
package/karma.config.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = function (config) {
|
|
2
|
-
config.set({
|
|
3
|
-
frameworks: ['mocha', 'chai'],
|
|
4
|
-
files: [
|
|
5
|
-
'dist/**/*.js',
|
|
6
|
-
'src/**/*.test.js'
|
|
7
|
-
],
|
|
8
|
-
reporters: ['progress'],
|
|
9
|
-
port: 9876, // karma web server port
|
|
10
|
-
colors: true,
|
|
11
|
-
logLevel: config.LOG_INFO,
|
|
12
|
-
browsers: ['ChromeHeadless', 'Firefox', 'FirefoxDeveloper', 'FirefoxNightly', 'IE'],
|
|
13
|
-
autoWatch: false,
|
|
14
|
-
concurrency: Infinity,
|
|
15
|
-
customLaunchers: {
|
|
16
|
-
FirefoxHeadless: {
|
|
17
|
-
base: 'Firefox',
|
|
18
|
-
flags: ['-headless'],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module '@sockethub/activity-streams';
|
package/src/activity-streams.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* activity-streams
|
|
3
|
-
* https://github.com/silverbucket/activity-streams
|
|
4
|
-
*
|
|
5
|
-
* Developed and Maintained by:
|
|
6
|
-
* Nick Jennings <nick@silverbucket.net>
|
|
7
|
-
*
|
|
8
|
-
* activity-streams is released under the MIT (see LICENSE).
|
|
9
|
-
*
|
|
10
|
-
* You don't have to do anything special to choose one license or the other
|
|
11
|
-
* and you don't have to notify anyone which license you are using.
|
|
12
|
-
* Please see the corresponding license file for details of these licenses.
|
|
13
|
-
* You are free to use, modify and distribute this software, but all copyright
|
|
14
|
-
* information must remain.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const EventEmitter = require('event-emitter');
|
|
20
|
-
|
|
21
|
-
const ee = EventEmitter(),
|
|
22
|
-
baseProps = {
|
|
23
|
-
stream: [
|
|
24
|
-
'id', 'type', 'actor', 'target', 'object', 'context', 'context',
|
|
25
|
-
'published', 'error'
|
|
26
|
-
],
|
|
27
|
-
object: [
|
|
28
|
-
'id', 'type', 'context',
|
|
29
|
-
'alias', 'attachedTo', 'attachment', 'attributedTo', 'attributedWith',
|
|
30
|
-
'content', 'contentMap', 'context', 'contextOf', 'name', 'endTime', 'generator',
|
|
31
|
-
'generatorOf', 'group', 'icon', 'image', 'inReplyTo', 'members', 'memberOf',
|
|
32
|
-
'message', 'location', 'locationOf', 'objectOf', 'originOf', 'presence',
|
|
33
|
-
'preview', 'previewOf', 'provider', 'providerOf', 'published', 'rating',
|
|
34
|
-
'relationship', 'resultOf', 'replies', 'role', 'scope', 'scopeOf', 'startTime',
|
|
35
|
-
'status', 'summary', 'topic', 'tag', 'tagOf', 'targetOf', 'title', 'titleMap',
|
|
36
|
-
'updated', 'url'
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
rename = {
|
|
40
|
-
'@id': 'id',
|
|
41
|
-
'@type': 'type',
|
|
42
|
-
'verb': 'type',
|
|
43
|
-
'displayName': 'name',
|
|
44
|
-
'objectType': 'type',
|
|
45
|
-
'platform': 'context'
|
|
46
|
-
},
|
|
47
|
-
expand = {
|
|
48
|
-
'actor' : {
|
|
49
|
-
'primary': 'id',
|
|
50
|
-
'props': baseProps
|
|
51
|
-
},
|
|
52
|
-
'target': {
|
|
53
|
-
'primary': 'id',
|
|
54
|
-
'props': baseProps
|
|
55
|
-
},
|
|
56
|
-
'object': {
|
|
57
|
-
'primary': 'content',
|
|
58
|
-
'props': baseProps
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
let objs = new Map(),
|
|
63
|
-
failOnUnknownObjectProperties = false,
|
|
64
|
-
warnOnUnknownObjectProperties = true,
|
|
65
|
-
specialObjs = [], // the objects don't get rejected for bad props
|
|
66
|
-
customProps = {};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
function matchesCustomProp(type, key) {
|
|
70
|
-
return !!((typeof customProps[type] === 'object') && (customProps[type].includes(key)));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function renameProp(obj, key) {
|
|
74
|
-
obj[rename[key]] = obj[key];
|
|
75
|
-
delete obj[key];
|
|
76
|
-
return obj;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function validateObject(type, obj = {}) {
|
|
80
|
-
const unknownKeys = Object.keys(obj).filter((key) => {
|
|
81
|
-
if (! baseProps[type].includes(key)) {
|
|
82
|
-
return key;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
for (let key of unknownKeys) {
|
|
87
|
-
if (rename[key]) {
|
|
88
|
-
// rename property instead of fail
|
|
89
|
-
obj = renameProp(obj, key);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (matchesCustomProp(obj.type, key)) {
|
|
94
|
-
// custom property matches, continue
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (! specialObjs.includes(obj.type)) {
|
|
99
|
-
// not defined as a special prop
|
|
100
|
-
// don't know what to do with it, so throw error
|
|
101
|
-
const err = `invalid property: "${key}"`;
|
|
102
|
-
if (failOnUnknownObjectProperties) {
|
|
103
|
-
throw new Error(err);
|
|
104
|
-
} else if (warnOnUnknownObjectProperties) {
|
|
105
|
-
console.warn(err);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
function ensureProps(obj) {
|
|
113
|
-
// ensure the name property, which can general be inferred from the id
|
|
114
|
-
// name = obj.match(/(?(?\w+):\/\/)(?:.+@)?(.+?)(?:\/|$)/)[1]
|
|
115
|
-
return obj;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function expandStream(meta) {
|
|
119
|
-
let stream = {};
|
|
120
|
-
for (let key of Object.keys(meta)) {
|
|
121
|
-
if (typeof meta[key] === 'string') {
|
|
122
|
-
stream[key] = objs.get(meta[key]) || meta[key];
|
|
123
|
-
} else if (Array.isArray(meta[key])) {
|
|
124
|
-
stream[key] = [];
|
|
125
|
-
for (let entry of meta[key]) {
|
|
126
|
-
if (typeof entry === 'string') {
|
|
127
|
-
stream[key].push(objs.get(entry) || entry);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
stream[key] = meta[key];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// only expand string into objects if they are in the expand list
|
|
136
|
-
for (let key of Object.keys(expand)) {
|
|
137
|
-
if (typeof stream[key] === 'string') {
|
|
138
|
-
const idx = expand[key].primary;
|
|
139
|
-
let obj = {};
|
|
140
|
-
obj[idx] = stream[key];
|
|
141
|
-
stream[key] = obj;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return stream;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function Stream(meta) {
|
|
148
|
-
validateObject('stream', meta);
|
|
149
|
-
if (typeof meta.object === 'object') {
|
|
150
|
-
validateObject('object', meta.object);
|
|
151
|
-
}
|
|
152
|
-
const stream = expandStream(meta);
|
|
153
|
-
ee.emit('activity-stream', stream);
|
|
154
|
-
return stream;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const _Object = {
|
|
159
|
-
create: function (obj) {
|
|
160
|
-
validateObject('object', obj);
|
|
161
|
-
obj = ensureProps(obj);
|
|
162
|
-
objs.set(obj.id, obj);
|
|
163
|
-
ee.emit('activity-object-create', obj);
|
|
164
|
-
return obj;
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
delete: function (id) {
|
|
168
|
-
const result = objs.delete(id);
|
|
169
|
-
if (result) {
|
|
170
|
-
ee.emit('activity-object-delete', id);
|
|
171
|
-
}
|
|
172
|
-
return result;
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
get: function (id, expand) {
|
|
176
|
-
let obj = objs.get(id);
|
|
177
|
-
if (! obj) {
|
|
178
|
-
if (! expand) {
|
|
179
|
-
return id;
|
|
180
|
-
}
|
|
181
|
-
obj = {'id': id};
|
|
182
|
-
}
|
|
183
|
-
return ensureProps(obj);
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
list: function () {
|
|
187
|
-
return objs.keys();
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
function ASFactory(opts = {}) {
|
|
193
|
-
specialObjs = opts.specialObjs || [];
|
|
194
|
-
failOnUnknownObjectProperties = typeof opts.failOnUnknownObjectProperties === 'boolean' ?
|
|
195
|
-
opts.failOnUnknownObjectProperties : failOnUnknownObjectProperties;
|
|
196
|
-
warnOnUnknownObjectProperties = typeof opts.warnOnUnknownObjectProperties === 'boolean' ?
|
|
197
|
-
opts.warnOnUnknownObjectProperties : warnOnUnknownObjectProperties;
|
|
198
|
-
for (let propName of Object.keys(opts.customProps || {})) {
|
|
199
|
-
if (typeof opts.customProps[propName] === 'object') {
|
|
200
|
-
customProps[propName] = opts.customProps[propName];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
Stream: Stream,
|
|
206
|
-
Object: _Object,
|
|
207
|
-
on: function (event, func) {
|
|
208
|
-
return ee.on(event, func);
|
|
209
|
-
},
|
|
210
|
-
once: function (event, func) {
|
|
211
|
-
return ee.once(event, func);
|
|
212
|
-
},
|
|
213
|
-
off: function (event, funcName) {
|
|
214
|
-
return ee.off(event, funcName);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (typeof module === 'object' && module.exports) {
|
|
220
|
-
module.exports = ASFactory;
|
|
221
|
-
}
|
|
222
|
-
if (typeof window === 'object') {
|
|
223
|
-
window.ASFactory = ASFactory;
|
|
224
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
if (typeof ASFactory !== 'function') {
|
|
2
|
-
ASFactory = require('./activity-streams');
|
|
3
|
-
}
|
|
4
|
-
if (typeof chai !== 'object') {
|
|
5
|
-
chai = require('chai');
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const assert = chai.assert;
|
|
9
|
-
const expect = chai.expect;
|
|
10
|
-
|
|
11
|
-
describe('warn test', () => {
|
|
12
|
-
let activity;
|
|
13
|
-
|
|
14
|
-
before('initialize activity module', () => {
|
|
15
|
-
assert.typeOf(ASFactory, 'function');
|
|
16
|
-
activity = ASFactory();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('rejects nondefined special types', () => {
|
|
20
|
-
expect(() => {
|
|
21
|
-
activity.Stream({
|
|
22
|
-
'type': 'lol',
|
|
23
|
-
platform: 'irc',
|
|
24
|
-
actor: 'thingy',
|
|
25
|
-
object: {'type': 'hola', content: 'har', secure: true},
|
|
26
|
-
target: ['thingy1', 'thingy2']
|
|
27
|
-
})
|
|
28
|
-
}).not.to.throw(Error);
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('no special props', () => {
|
|
33
|
-
let activity;
|
|
34
|
-
|
|
35
|
-
before('initialize activity module', () => {
|
|
36
|
-
assert.typeOf(ASFactory, 'function');
|
|
37
|
-
activity = ASFactory({specialObjs: [ 'send' ],});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('returns expected object with no special types', () => {
|
|
41
|
-
expect(activity.Stream({
|
|
42
|
-
'type': 'send',
|
|
43
|
-
context: 'irc',
|
|
44
|
-
actor: 'thingy',
|
|
45
|
-
object: {'type': 'hola', content: 'har'},
|
|
46
|
-
target: ['thingy1', 'thingy2']
|
|
47
|
-
})).to.eql({
|
|
48
|
-
'type': 'send',
|
|
49
|
-
context: 'irc',
|
|
50
|
-
actor: { 'id': 'thingy' },
|
|
51
|
-
object: { 'type': 'hola', content: 'har' },
|
|
52
|
-
target: [ 'thingy1', 'thingy2' ]
|
|
53
|
-
});
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('basic tests', () => {
|
|
58
|
-
const config = {
|
|
59
|
-
customProps: {
|
|
60
|
-
credentials: [ 'secure' ]
|
|
61
|
-
},
|
|
62
|
-
specialObjs: [ 'dude'],
|
|
63
|
-
failOnUnknownObjectProperties: true
|
|
64
|
-
};
|
|
65
|
-
let activity;
|
|
66
|
-
|
|
67
|
-
before('initialize activity module', () => {
|
|
68
|
-
assert.typeOf(ASFactory, 'function');
|
|
69
|
-
activity = ASFactory(config);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('object tests', () => {
|
|
73
|
-
it('has expected structure', () => {
|
|
74
|
-
assert.typeOf(activity, 'object');
|
|
75
|
-
assert.typeOf(activity.Object, 'object');
|
|
76
|
-
assert.typeOf(activity.Stream, 'function');
|
|
77
|
-
assert.typeOf(activity.on, 'function');
|
|
78
|
-
assert.typeOf(activity.once, 'function');
|
|
79
|
-
assert.typeOf(activity.off, 'function');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('returns undefined when no params are passed', () => {
|
|
83
|
-
assert.equal(activity.Object.get(), undefined);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('returns object when given a valid lookup id', () => {
|
|
87
|
-
expect(activity.Object.create({id: 'thingy1'})).to.deep.equal({'id': 'thingy1'});
|
|
88
|
-
expect(activity.Object.get('thingy1')).to.deep.equal({'id':'thingy1'});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('throws an exception when called with no identifier', () => {
|
|
92
|
-
expect(activity.Object.create).to.throw(Error);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('creates a second object and returns is as expected', () => {
|
|
96
|
-
expect(activity.Object.create({id: 'thingy2'})).to.deep.equal({'id':'thingy2'});
|
|
97
|
-
expect(activity.Object.get('thingy2')).to.deep.equal({'id':'thingy2'});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('returns a basic ActivtyObject when receiving an unknown id with expand=true', () => {
|
|
101
|
-
expect(activity.Object.get('thingy3', true)).to.deep.equal({'id':'thingy3'});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns given id param when lookup fails and expand=false', () => {
|
|
105
|
-
expect(activity.Object.get({'id': 'thingy3', 'foo': 'bar'})).to.deep.equal({'id': 'thingy3', 'foo': 'bar'});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('stream tests', () => {
|
|
110
|
-
let stream;
|
|
111
|
-
|
|
112
|
-
beforeEach(() => {
|
|
113
|
-
stream = activity.Stream({
|
|
114
|
-
verb: 'lol',
|
|
115
|
-
platform: 'irc',
|
|
116
|
-
actor: 'thingy1',
|
|
117
|
-
context: 'irc',
|
|
118
|
-
object: { objectType: 'credentials', content: 'har', secure: true },
|
|
119
|
-
target: [ 'thingy1', 'thingy2' ]
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('renames mapped props', () => {
|
|
124
|
-
expect(stream.type).to.equal('lol');
|
|
125
|
-
expect(stream.verb).to.not.exist;
|
|
126
|
-
expect(stream.context).to.equal('irc');
|
|
127
|
-
expect(stream.platform).to.not.exist;
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('expands existing objects', () => {
|
|
131
|
-
expect(stream.target).to.deep.equal([
|
|
132
|
-
{ 'id': 'thingy1' },
|
|
133
|
-
{ 'id': 'thingy2' }
|
|
134
|
-
]);
|
|
135
|
-
expect(stream.actor).to.deep.equal({ 'id': 'thingy1' });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('handles customProps as expected', () => {
|
|
139
|
-
expect(stream.object).to.deep.equal(
|
|
140
|
-
{ 'type': 'credentials', content: 'har', secure: true }
|
|
141
|
-
);
|
|
142
|
-
expect(stream.object.objectType).to.not.exist;
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('respects specialObj properties', () => {
|
|
146
|
-
let stream2 = activity.Stream({
|
|
147
|
-
'type': 'lol',
|
|
148
|
-
platform: 'irc',
|
|
149
|
-
actor: 'thingy',
|
|
150
|
-
object: { 'type': 'dude', foo: 'bar', content: 'har', secure: true },
|
|
151
|
-
target: [ 'thingy1', 'thingy2' ]
|
|
152
|
-
});
|
|
153
|
-
expect(stream2).to.deep.equal({
|
|
154
|
-
'type': 'lol',
|
|
155
|
-
context: 'irc',
|
|
156
|
-
actor: { 'id': 'thingy' },
|
|
157
|
-
target: [ { 'id': 'thingy1' }, { 'id': 'thingy2' }],
|
|
158
|
-
object: { 'type': 'dude', foo: 'bar', content: 'har', secure: true }
|
|
159
|
-
});
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('rejects nondefined special types', () => {
|
|
163
|
-
expect(() => {
|
|
164
|
-
activity.Stream({
|
|
165
|
-
'type': 'lol',
|
|
166
|
-
platform: 'irc',
|
|
167
|
-
actor: 'thingy',
|
|
168
|
-
object: { 'type': 'hola', foo: 'bar', content: 'har', secure: true },
|
|
169
|
-
target: [ 'thingy1', 'thingy2' ]
|
|
170
|
-
})
|
|
171
|
-
}).to.throw('invalid property: "foo"');
|
|
172
|
-
})
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('emitters', () => {
|
|
176
|
-
it('emits an event on object creation', () => {
|
|
177
|
-
function onHandler(obj) {
|
|
178
|
-
expect(obj).to.deep.equal({ 'id': 'thingy3' });
|
|
179
|
-
activity.off('activity-object-create', onHandler);
|
|
180
|
-
}
|
|
181
|
-
activity.on('activity-object-create', onHandler);
|
|
182
|
-
activity.Object.create({ id:'thingy3' });
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('emits an event on object deletion', () => {
|
|
186
|
-
activity.once('activity-object-delete', (id) => {
|
|
187
|
-
expect(id).to.equal('thingy2');
|
|
188
|
-
});
|
|
189
|
-
activity.Object.delete('thingy2');
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|