Activity Streams 2.0
Based on:
- http://jasnell.github.io/w3c-socialwg-activitystreams/activitystreams-core/index.html
- http://jasnell.github.io/w3c-socialwg-activitystreams/activitystreams-vocabulary/index.html
Includes experimental support for:
Starting with version v0.8.0
, a minimum of Node v4.0.0 / ES6 is required.
Getting Started
Installation
npm install activitystrea.ms
Usage
const as = require('activitystrea.ms');
// Create a simple object
as.object().
name('baz').
content(
as.langmap()
.set('en', 'bar')
.set('fr', 'foo'))
publishedNow().
prettyWrite(function(err,doc) {
console.log(doc);
});
Which produces the output:
{
"@context": "http://www.w3.org/ns/activitystreams#",
"@type": "Object",
"contentMap": {
"en": "bar",
"fr": "foo"
},
"name": "baz",
"published": "2015-07-17T00:50:09.889Z"
}
// Create a simple activity
as.create().
actor('acct:sally@example.org').
object('http://www.example.org/post').
prettyWrite(function(err,doc) {
console.log(doc);
});
Which produces the output:
{
"@context": "http://www.w3.org/ns/activitystreams#",
"@type": "Create",
"actor": "acct:sally@example.org",
"object": "http://www.example.org/post"
}
You can also use the Node.js stream model for parsing:
var fs = require('fs');
var AS2Stream = as.Stream;
var path = require('path');
var through = require('through2');
fs.createReadStream(path.resolve(__dirname,'test.json'))
.pipe(new AS2Stream())
.pipe(through.obj(function(obj,encoding,callback) {
console.log(obj.type);
console.log(obj.name);
}));
And writing:
const as = require('activitystrea.ms');
var through = require('through2');
as.object()
.name('test')
.get()
.pipe(process.stdout);
The API uses a fluent factory pattern for creating AS objects. There are
factory methods for each of the main types of objects defined by the Activity
Streams 2.0 vocabulary. Each takes an optional array of types that will be set
on the object. If the [types]
is unspecified, a default will be assigned
depending on the object being created. Each of the factory methods returns a
builder specific to the kind of object being generated. Once the object has
been built, call the get
method to return the generated object.
as.object([types])
as.activity([types])
as.collection([types])
as.orderedCollection([types])
as.collectionPage([types])
as.orderedCollectionPage([types])
as.link([types])
as.accept([types])
as.tentativeAccept([types])
as.add([types])
as.arrive([types])
as.create([types])
as.delete([types])
as.favorite([types])
as.follow([types])
as.ignore([types])
as.join([types])
as.leave([types])
as.like([types])
as.offer([types])
as.invite([types])
as.reject([types])
as.tentativeReject([types])
as.remove([types])
as.undo([types])
as.update([types])
as.view([types])
as.listen([types])
as.read([types])
as.move([types])
as.travel([types])
as.announce([types])
as.block([types])
as.flag([types])
as.dislike([types])
as.application([types])
as.content([types])
as.group([types])
as.person([types])
as.service([types])
as.article([types])
as.document([types])
as.profile([types])
as.audio([types])
as.image([types])
as.video([types])
as.note([types])
as.page([types])
as.question([types])
as.event([types])
as.place([types])
as.connection([types])
as.mention([types])
as.interval([types])
as.interval.open([types])
as.interval.closed([types])
as.interval.openClosed([types])
as.interval.closedOpen([types])
as.interval.rightOpen([types])
as.interval.leftClosed([types])
as.interval.rightClosed([types])
as.social.population([types])
as.social.everyone([types])
as.social.public([types])
as.social.private([types])
as.social.direct([types])
as.social.common([types])
as.social.interested([types])
as.social.self([types])
as.social.all([types])
as.social.any([types])
as.social.none([types])
The object returned by get
is a read-only view of the Activity Stream object.
It will have property methods that are specific to the object's type. You can
export the built object as an ordinary Javascript object using the export
method. This will generate a JSON-LD compliant Javascript object.
const as = require('activitystrea.ms');
var note = as.note().
name('foo').
content('this is a simple note').
get();
console.log(note.name.valueOf());
console.log(note.content.valueOf());
console.log(note.type);
const as = require('activitystrea.ms');
as.note().
name('foo').
content('this is a simple note').
get().
export(function (err, obj) {
// obj is an ordinary javascript object
console.log(obj['@type']);
console.log(obj['name']);
console.log(obj['content']);
});
To serialize the Activity Streams object out as JSON, use the write
,
prettyWrite
, or pipe
methods
const as = require('activitystrea.ms');
as.note().
name('foo').
content('this is a simple note').
write(function (err, doc) {
// doc is a string
console.log(doc);
});
const as = require('activitystrea.ms');
as.note().
name('foo').
content('this is a simple note').
prettyWrite(function (err, doc) {
// doc is a string
console.log(doc);
});
const as = require('activitystrea.ms');
var through = require('through2');
as.object()
.name('test')
.get()
.pipe(process.stdout);
Note that The export
, write
, and prettyWrite
methods are all async. You
MUST pass in a callback function. This is largely because of the JSON-LD
processing that's happening under the covers.
API
const as = require('activitystrea.ms')
The base module.
<as.models.Object.Builder> as.object([types])
Returns a new as.models.Object.Builder
instance.
<as.models.Activity.Builder> as.activity([types])
Returns a new as.models.Activity.Builder
instance.
<as.models.Collection.Builder> as.collection([types])
Returns a new as.models.Collection.Builder
instance.
<as.models.OrderedCollection.Builder> as.orderedCollection([types])
Returns a new as.models.OrderedCollection.Builder
instance.
<as.models.CollectionPage.Builder> as.collectionPage([types])
Returns a new as.models.CollectionPage.Builder
instance.
<as.models.OrderedCollectionPage.Builder> as.orderedCollectionPage([types])
Returns a new as.models.OrderedCollectionPage.Builder
instance.
<as.models.Link.Builder> as.link([types])
Returns a new as.models.Link.Builder
instance.
<as.models.Activity.Builder> as.accept([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Accept
activity.
<as.models.Activity.Builder> as.tentativeAccept([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#TentativeAccept
activity.
<as.models.Activity.Builder> as.add([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Add
activity.
<as.models.Activity.Builder> as.arrive([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Arrive
activity.
<as.models.Activity.Builder> as.create([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Create
activity.
<as.models.Activity.Builder> as.delete([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Delete
activity.
<as.models.Activity.Builder> as.follow([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Follow
activity.
<as.models.Activity.Builder> as.ignore([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Ignore
activity.
<as.models.Activity.Builder> as.join([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Join
activity.
<as.models.Activity.Builder> as.leave([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Leave
activity.
<as.models.Activity.Builder> as.like([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Like
activity.
<as.models.Activity.Builder> as.offer([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Offer
activity.
<as.models.Activity.Builder> as.invite([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Invite
activity.
<as.models.Activity.Builder> as.reject([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Reject
activity.
<as.models.Activity.Builder> as.tentativeReject([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#TentativeReject
activity.
<as.models.Activity.Builder> as.remove([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Remove
activity.
<as.models.Activity.Builder> as.undo([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Undo
activity.
<as.models.Activity.Builder> as.update([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Update
activity.
<as.models.Activity.Builder> as.view([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#View
activity.
<as.models.Activity.Builder> as.listen([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Listen
activity.
<as.models.Activity.Builder> as.read([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Read
activity.
<as.models.Activity.Builder> as.move([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Move
activity.
<as.models.Activity.Builder> as.travel([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Travel
activity.
<as.models.Activity.Builder> as.announce([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Announce
activity.
<as.models.Activity.Builder> as.block([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Block
activity.
<as.models.Activity.Builder> as.flag([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Flag
activity.
<as.models.Activity.Builder> as.dislike([types])
Returns a new as.models.Activity.Builder
instance generating an http://www.w3.org/ns/activity#Dislike
activity.
<as.models.Object.Builder> as.application([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Application
object.
<as.models.Object.Builder> as.group([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Group
object.
<as.models.Object.Builder> as.person([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Person
object.
<as.models.Object.Builder> as.service([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Service
object.
<as.models.Object.Builder> as.organization([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Organization
object.
<as.models.Object.Builder> as.article([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Article
object.
<as.models.Object.Builder> as.document([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Document
object.
<as.models.Object.Builder> as.audio([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Audio
object.
<as.models.Object.Builder> as.image([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Image
object.
<as.models.Object.Builder> as.video([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Video
object.
<as.models.Object.Builder> as.note([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Note
object.
<as.models.Object.Builder> as.page([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Page
object.
<as.models.Question.Builder> as.question([types])
Returns a new as.models.Question.Builder
instance generating an http://www.w3.org/ns/activity#Question
object.
<as.models.Object.Builder> as.event([types])
Returns a new as.models.Object.Builder
instance generating an http://www.w3.org/ns/activity#Event
object.
<as.models.Relationship.Builder> as.relationship([types])
Returns a new as.models.Relationship.Builder
instance generating an http://www.w3.org/ns/activity#Relationship
object.
<as.models.Profile.Builder> as.profile([types])
Returns a new as.models.Profile.Builder
instance generating an http://www.w3.org/ns/activity#Profile
object.
<as.models.Place.Builder> as.place([types])
Returns a new as.models.Place.Builder
instance generating an http://www.w3.org/ns/activity#Place
object.
<as.models.Link.Builder> as.mention([types])
Returns a new as.models.Link.Builder
instance generating an http://www.w3.org/ns/activity#Mention
link.
<void> as.import(obj, callback)
Imports the specified JavaScript object obj
, performing JSON-LD expansion as necessary. When the import is complete, the callback
function will be invoked with the imported as.model.Object
as the second argument. If an error occurs, the error will be passed as the first argument to the callback
.
var obj = {
'@context': 'http://www.w3.org/ns/activitystreams#',
'@type': 'Person',
name: 'Joe'
};
as.import(obj, function(err, imp) {
if (err) {
console.error(err);
return;
}
console.log(imp.type);
});
as.Stream()
Returns a new Node.js Transform Stream that parses JSON input into an appropriate as.models.Object
instance.
var through = require('through2');
var fs = require('fs');
var fsstr = fs.createReadStream('data.json');
fsstr.pipe(new as.Stream())
.pipe(through.obj(function(chunk,encoding,callback) {
console.log(chunk.name);
callback();
}));
as.Middleware
Express/Connect middleware that parses the request payload as AS2
var app = require('express')();
app.post('/', as.Middleware, function(req,res) {
res.status(200);
res.set({'Content-Type': as.mediaType});
req.body.pipe(res);
});
as.mediaType
Set to a constant value of application/activity+json
as.models.Base(expanded, builder)
as.models.Base
is the base class for all objects. It is not intended to be used directly by developers.
expanded
- The underlying JSON-LD expanded JavaScript objectbuilder
- Aas.model.Base.Builder
subclass
<string> as.models.Base.prototype.id
Property: Returns the value of the JSON-LD @id
property or underfined
.
<string||string[]> as.models.Base.prototype.type
Property: Returns the value of the JSON-LD @type
property. If @type
has only a single value, then a single JavaScript string will be returned. If the @type
has multiple values, a JavaScript Array will be returned. If the @type
is not specified, undefined
will be returned.
<boolean> as.models.Base.prototype.has(key)
Method: Returns true if the object has a value for the specified key
<any> as.models.Base.prototype.get(key)
Method: Returns the value for the specified key
. The return value will vary based on the property being requested. The return value can be a JavaScript primitive, a as.models.Base
instance, or an Iterable of JavaScript primitives or as.models.Base
instances. Will returned undefined
if the no value is specified for the given key
<void> as.models.Base.prototype.export([options, ] callback)
Method: Exports the object by performing a JSON-LD compaction. If export fails, the callback will be called with the error as the first argument. If the export succeeds, the exported JavaScript object will be passed as the second argument of the callback.
var obj = as.object().name('Joe').get();
obj.export(function(err,exp) {
if (err) {
console.error(err);
return;
}
console.log(exp.name);
console.log(exp['@type']);
});
<void> as.models.Base.prototype.write([options, ] callback)
Method: Write the object out to a JSON-LD string. If writing fails, the callback will will be called with the error as the first argument. If the write succeeds, the JSON-LD string will be passed as the second argument of the callback.
var obj = as.object().name('Joe').get();
obj.write(function(err,string) {
if (err) {
console.error(err);
return;
}
console.log(string);
});
<void> as.models.Base.prototype.prettyWrite([options, ] callback)
Method: Write the object out to a JSON-LD string. If writing fails, the callback will will be called with the error as the first argument. If the write succeeds, the JSON-LD string will be passed as the second argument of the callback.
var obj = as.object().name('Joe').get();
obj.prettyWrite(function(err,string) {
if (err) {
console.error(err);
return;
}
console.log(string);
});
<as.models.Base.Builder<?>> as.models.Base.prototype.modify()
Method: Returns a new as.models.Base.Builder
instance that can be used to modify
this object.
<ReadableStream> as.models.Base.prototype.stream()
Method: Returns a Readable Stream instance that can be used to read this object as a stream of JSON-LD data.
<ReadableStream> as.models.Base.prototype.pipe(Writable[, options])
Method: Pipes this objects JSON-LD to the specified writable
var obj = as.person().name('Sally').get();
obj.pipe(process.stdout);
<function> as.models.Base.prototype.template()
Method: Returns a funtion that can be used to create new as.models.Base.Builder
instances using this object as a template. The new Builder will be pre-filled with the properties already specified on this object.
var templ = as.like().actor('http://example.org/sally').get().template();
templ().object('http://example.org/1').pipe(process.stdout);
templ().object('http://example.org/2').pipe(process.stdout);
as.models.Base.Builder(types, base)
Class: The base Builder interface. This is not intended to be used directly by developers. Most of the methods on the Builder instances return a reference back to the Builder itself allowing methods to be chained.
<Builder> as.models.Base.Builder.prototype.id(val)
Method: Set the value of the @id
property. Calling this repeatedly will overwrite the previous value.
<Builder> as.models.Base.Builder.prototype.type(val)
Method: Add a value to the @type
property. Calling this repeatedly will add new values to the previous set.
<Builder> as .models.Base.Builder.prototype.set(key, val[, options])
Method: Set a value for the specified key.
var object = as.object();
object.set('foo', 'bar');
<as.models.Base> as.models.Base.Builder.prototype.get()
Method: Returns the constructed as.models.Base
instance.
as.models.Object
> as.models.Base
The base class for all Activity Streams 2.0 Object instances. Inherits from as.models.Base
as.models.Object.prototype.attachment
Property: Returns the value of the http://www.w3.org/ns/activitystreams#attachment
property. Will be either undefined
or an Iterable of as.model.Base
instances.
Property: `as.models.Object.prototype.attributedTo'
Returns the value of the http://www.w3.org/ns/activitystreams#attributedTo
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.content
Property: Returns the value of the http://www.w3.org/ns/activitystreams#content
property. Will be either undefined
or a as.models.LanguageValue
.
as.models.Object.prototype.context
Property: Returns the value of the http://www.w3.org/ns/activitystreams#context
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.name
Property: Returns the value of the http://www.w3.org/ns/activitystreams#name
property. Will be either undefined
or a as.models.LanguageValue
.
as.models.Object.prototype.summary
Property: Returns the value of the http://www.w3.org/ns/activitystreams#summary
property. Will be either undefined
or a as.models.LanguageValue
.
as.models.Object.prototype.endTime
Property: Returns the value of the http://www.w3.org/ns/activitystreams#endTime
property. Will be either undefined
or a JavaScript Date object.
as.models.Object.prototype.published
Property: Returns the value of the http://www.w3.org/ns/activitystreams#published
property. Will be either undefined
or a JavaScript Date object.
as.models.Object.prototype.startTime
Property: Returns the value of the http://www.w3.org/ns/activitystreams#startTime
property. Will be either undefined
or a JavaScript Date object.
as.models.Object.prototype.updated
Property: Returns the value of the http://www.w3.org/ns/activitystreams#updated
property. Will be either undefined
or a JavaScript Date object.
as.models.Object.prototype.generator
Property: Returns the value of the http://www.w3.org/ns/activitystreams#generator
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.icon
Property: Returns the value of the http://www.w3.org/ns/activitystreams#icon
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.image
Property: Returns the value of the http://www.w3.org/ns/activitystreams#image
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.inReplyTo
Property: Returns the value of the http://www.w3.org/ns/activitystreams#inReplyTo
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.location
Property: Returns the value of the http://www.w3.org/ns/activitystreams#location
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.preview
Property: Returns the value of the http://www.w3.org/ns/activitystreams#preview
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.replies
Property: Returns the value of the http://www.w3.org/ns/activitystreams#replies
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.scope
Property: Returns the value of the http://www.w3.org/ns/activitystreams#scope
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.tag
Property: Returns the value of the http://www.w3.org/ns/activitystreams#tag
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.url
Property: Returns the value of the http://www.w3.org/ns/activitystreams#url
property. Will be either undefined
or an Iterable of as.model.Link
instances.
as.models.Object.prototype.to
Property: Returns the value of the http://www.w3.org/ns/activitystreams#to
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.bto
Property: Returns the value of the http://www.w3.org/ns/activitystreams#bto
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.cc
Property: Returns the value of the http://www.w3.org/ns/activitystreams#cc
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.prototype.bcc
Property: Returns the value of the http://www.w3.org/ns/activitystreams#bcc
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Object.Builder > as.models.Base.Builder
Class: Builder for as.models.Object
instances.
<Builder> as.models.Object.Builder.prototype.attachment(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#attachment
property.
Method: ` as.models.Object.Builder.prototype.attributedTo(val)'
Adds a value to the http://www.w3.org/ns/activitystreams#attributedTo
property.
<Builder> as.models.Object.Builder.prototype.content(val)
Method: Sets an optional language-tagged value for the http://www.w3.org/ns/activitystreams#content
property. To set
language-tagged values, use the as.langmap
method to create a
LanguageValue.Builder.
as.object()
.content('simple content')
.get();
as.object()
.content(
as.langmap()
.set('default content')
.set('es', 'other content')
)
.get();
<Builder> as.models.Object.Builder.prototype.context(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#context
property.
<Builder> as.models.Object.Builder.prototype.name(val)
Method: Sets an optional language-tagged value for the http://www.w3.org/ns/activitystreams#name
property.
as.object()
.name('simple display name')
.get();
as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get();
<Builder> as.models.Object.Builder.prototype.summary(val)
Method: Sets an optional language-tagged value for the http://www.w3.org/ns/activitystreams#summary
property.
as.object()
.summary('simple summary')
.get();
as.object()
.summary(
as.langmap()
.set('default summary')
.set('es', 'other summary')
)
.get();
<Builder> as.models.Object.Builder.prototype.endTime(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#endTime
property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.endTimeNow()
Method: Sets the value of the http://www.w3.org/ns/activitystreams#endTime
property to the current date and time.
<Builder> as.models.Object.Builder.prototype.published(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#published
property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.publishedNow()
Method: Sets the value of the http://www.w3.org/ns/activitystreams#published
property to the current date and time.
<Builder> as.models.Object.Builder.prototype.startTime(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#startTime
property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.startTimeNow()
Method: Sets the value of the http://www.w3.org/ns/activitystreams#startTime
property to the current date and time.
<Builder> as.models.Object.Builder.prototype.updated(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#updated
property.
The value must be a JavaScript Date object.
<Builder> as.models.Object.Builder.prototype.updatedNow()
Method: Sets the value of the http://www.w3.org/ns/activitystreams#updated
property to the current date and time.
<Builder> as.models.Object.Builder.prototype.generator(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#generator
property.
<Builder> as.models.Object.Builder.prototype.icon(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#icon
property.
<Builder> as.models.Object.Builder.prototype.image(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#image
property.
<Builder> as.models.Object.Builder.prototype.inReplyTo(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#inReplyTo
property.
<Builder> as.models.Object.Builder.prototype.location(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#location
property.
<Builder> as.models.Object.Builder.prototype.preview(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#preview
property.
<Builder> as.models.Object.Builder.prototype.replies(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#replies
property.
<Builder> as.models.Object.Builder.prototype.scope(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#scope
property.
<Builder> as.models.Object.Builder.prototype.tag(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#tag
property.
<Builder> as.models.Object.Builder.prototype.url(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#url
property.
<Builder> as.models.Object.Builder.prototype.to(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#to
property.
<Builder> as.models.Object.Builder.prototype.bto(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#bto
property.
<Builder> as.models.Object.Builder.prototype.cc(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#cc
property.
<Builder> as.models.Object.Builder.prototype.bcc(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#bcc
property.
as.models.Activity > as.models.Object
Class: Base class for all Activity Streams 2.0 Activity instances. Inherits from as.models.Object
as.models.Activity.prototype.actor
Property: Returns the value of the http://www.w3.org/ns/activitystreams#actor
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.prototype.object
Property: Returns the value of the http://www.w3.org/ns/activitystreams#object
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.prototype.target
Property: Returns the value of the http://www.w3.org/ns/activitystreams#target
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.prototype.result
Property: Returns the value of the http://www.w3.org/ns/activitystreams#result
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.prototype.origin
Property: Returns the value of the http://www.w3.org/ns/activitystreams#origin
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.prototype.instrument
Property: Returns the value of the http://www.w3.org/ns/activitystreams#instrument
property. Will be either undefined
or an Iterable of as.model.Base
instances.
as.models.Activity.Builder > as.models.Object.Builder
Class: The base class for all as.models.Activity
builder instances. Inherits from as.models.Object.Builder
<Builder> as.models.Activity.Builder.actor(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#actor
property.
<Builder> as.models.Activity.Builder.object(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#object
property.
<Builder> as.models.Activity.Builder.target(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#target
property.
<Builder> as.models.Activity.Builder.result(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#result
property.
<Builder> as.models.Activity.Builder.origin(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#origin
property.
<Builder> as.models.Activity.Builder.instrument(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#instrument
property.
as.models.Collection > as.models.Object
Class: The base class for all Activity Streams 2.0 Collection objects. Inherits from as.models.Object
as.models.Collection.prototype.totalItems
Property: Returns the value of the http://www.w3.org/ns/activitystreams#totalItems
property. The value will either be undefined
or a numeric integer greater than or equal to zero.
as.models.Collection.prototype.current
Property: Returns the value of the http://www.w3.org/ns/activitystreams#current
property. The value will either be undefined
or a as.models.Base
instance.
as.models.Collection.prototype.last
Property: Returns the value of the http://www.w3.org/ns/activitystreams#last
property. The value will either be undefined
or a as.models.Base
instance.
as.models.Collection.prototype.first
Property: Returns the value of the http://www.w3.org/ns/activitystreams#first
property. The value will either be undefined
or a as.models.Base
instance.
as.models.Collection.prototype.items
Property: Returns the value of the http://www.w3.org/ns/activitystreams#items
property as an Iterable of as.models.Base
instances.
as.models.Collection.Builder> as.models.Object.Builder
Class: The base class for all as.models.Collection
builders. Inherits from as.models.Object.Builder
<Builder> as.models.Collection.Builder.prototype.totalItems(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#totalItems
property. The value must be a numeric integer greater than or equal to 0.
<Builder> as.models.Collection.Builder.current(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#current
property. The value must either be a URL string or a as.models.Link
instance.
<Builder> as.models.Collection.Builder.last(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#last
property. The value must either be a URL string or a as.models.Link
instance.
<Builder> as.models.Collection.Builder.first(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#first
property. The value must either be a URL string or a as.models.Link
instance.
<Builder> as.models.Collection.Builder.items(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#items
property.
as.models.OrderedCollection > as.models.Collection
Class: The base class for all Activity Streams 2.0 OrderedCollection objects. Inherits from as.models.Collection
as.models.OrderedCollection.Builder > as.models.Collection.Builder
Class: The base class for all as.models.OrderedCollection
builders. Inherits from as.models.Collection.Builder
as.models.CollectionPage > as.models.Collection
Class: The base class for all as.models.CollectionPage
instances. Inherits from as.models.Collection
as.models.CollectionPage.prototype.next
Property: Returns the value of the http://www.w3.org/ns/activitystreams#next
property. The value will either be undefined
or a as.models.Base
instance.
as.models.CollectionPage.prototype.prev
Property: Returns the value of the http://www.w3.org/ns/activitystreams#prev
property. The value will either be undefined
or a as.models.Base
instance.
as.models.CollectionPage.Builder > as.models.Collection.Builder
Class: The base class for all as.models.CollectionPage
builders. Inherits from as.models.Collection.Builder
<Builder> as.models.CollectionPage.Builder.next(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#next
property. The value must either be a URL string or a as.models.Link
instance.
<Builder> as.models.CollectionPage.Builder.prev(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#prev
property. The value must either be a URL string or a as.models.Link
instance.
as.models.OrderedCollectionPage > as.models.CollectionPage, as.models.OrderedCollection
Class: The base class for all as.models.OrderedCollectionPage
instances. Inherits from both as.models.CollectionPage
and as.models.OrderedCollection
as.models.OrderedCollectionPage.prototype.startIndex
Property: Returns the value of the http://www.w3.org/ns/activitystreams#startIndex
property. The value will either be undefined
or a numeric integer greater than or equal to zero.
as.models.OrderedCollectionPage.Builder > as.models.CollectionPage.Builder, as.models.OrderedCollection.Builder
Class: The base class for all as.models.OrderedCollectionPage
builders. Inherits from both as.models.CollectionPage.Builder
and as.models.OrderedCollection.Builder
.
as.models.OrderedCollectionPage.Builder.prototype.startIndex(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#startIndex
property. The value must be a numeric integer greater than or equal to zero.
as.models.Link > as.models.Base
Class: The base class for all Activity Streams 2.0 Links. Inherits from as.models.Base
as.models.Link.prototype.href
Property: Returns the value of the http://www.w3.org/ns/activitystreams#href
property. The value will either be undefined
or a URL string.
as.models.Link.prototype.rel
Property: Returns the value of the http://www.w3.org/ns/activitystreams#rel
property. The value will either be undefined
or an Iterable of strings.
as.models.Link.prototype.mediaType
Property: Returns the value of the http://www.w3.org/ns/activitystreams#mediaType
property. The value will either be undefined
or a MIME Media Type.
as.models.Link.prototype.name
Property: Returns the value of the http://www.w3.org/ns/activitystreams#name
property as a LanguageValue
.
as.models.Link.prototype.hreflang
Property: Returns the value of the http://www.w3.org/ns/activitystreams#hreflang
property. The value will either be undefined
or an RFC 5646 Language Tag.
as.models.Link.prototype.height
Property: Returns the value of the http://www.w3.org/ns/activitystreams#height
property.The value will either be undefined
or a numeric integer greater than or equal to zero.
as.models.Link.prototype.width
Property: Returns the value of the http://www.w3.org/ns/activitystreams#width
property.The value will either be undefined
or a numeric integer greater than or equal to zero.
as.models.Link.prototype.duration
Property: Returns the value of the http://www.w3.org/ns/activitystreams#duration
property. The value will either be `undefined, a numeric integer, or an ISO 8601 duration string.
as.models.Link.Builder > as.models.Base.Builder
Class: The base class for all as.models.Link
builders. Inherits from as.models.Base.Builder
<Builder> as.models.Link.Builder.prototype.href(val)
Method: Specifies the value of the http://www.w3.org/ns/activitystreams#href
property. The value must be a URL string.
<Builder> as.models.Link.Builder.prototype.rel(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#rel
property;
<Builder> as.models.Link.Builder.prototype.mediaType(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#mediaType
property. The value must be a valid MIME type.
<Builder> as.models.Link.Builder.prototype.name(val)
Method: Specifies an optionally language-tagged name.
as.link()
.name('simple display name')
.get();
as.link()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get();
<Builder> as.models.Link.Builder.prototype.hreflang(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#hreflang
property.
The value must be an RFC 5646 Language Tag.
<Builder> as.models.Link.Builder.prototype.height(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#height
property.
The value is a numeric integer greater than or equal to zero.
<Builder> as.models.Link.Builder.prototype.width(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#width
property.
The value is a numeric integer greater than or equal to zero.
<Builder> as.models.Link.Builder.prototype.duration(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#duration
property.
The value is either a numeric integer indicate a number of seconds, or an
ISO 8601 Duration.
as.models.Place > as.models.Object
Class: The base class for all Activity Streams 2.0 Place objects. Inherits from as.models.Object
as.models.Place.prototype.accuracy
Property: Returns the value of the http://www.w3.org/ns/activitystreams#accuracy
property. The value will either be undefined
or a numeric integer in the range 0 <= n <= 100.
as.models.Place.prototype.altitude
Property: Returns the value of the http://www.w3.org/ns/activitystreams#altitude
property. The value will be either undefined
or a numeric float.
as.models.Place.prototype.latitude
Property: Returns the value of the http://www.w3.org/ns/activitystreams#latitude
property. The value will be either undefined
or a numeric float in the range -90.0 <= n <= 90.0.
as.models.Place.prototype.longitude
Property: Returns the value of the http://www.w3.org/ns/activitystreams#longitude
property. The value will be either undefined
or a numeric float in the range -180.0 <= n <= 180.0.
as.models.Place.prototype.radius
Property: Returns the value of the http://www.w3.org/ns/activitystreams#radius
property.
The value will be either undefined
or a numeric float greater than or equal to zero.
as.models.Place.prototype.units
Property: Returns the value of the http://www.w3.org/ns/activitystreams#units
property. The value will be one of: cm
, feet
, inches
, km
, m
, miles
, or any absolute URI.
as.models.Place.Builder > as.models.Object.Builder
Class: The base class for all as.models.Place
builders. Inherits from as.models.Object.Builder
as.models.Place.Builder.prototype.accuracy(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#accuracy
property.
The value is a numeric integer in the range 0 <= n <= 100
as.models.Place.Builder.prototype.altitude(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#altitude
property. The value is a numeric float.
as.models.Place.Builder.prototype.latitude(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#latitude
property. The value is a numeric float in the range -90.0 <= n <= 90.0.
as.models.Place.Builder.prototype.longitude(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#longitude
property. The value is a numeric float in the range -180.0 <= n <= 180.0.
as.models.Place.Builder.prototype.radius(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#radius
property. The value is a numeric float greater or equal to 0.0
.
as.models.Place.Builder.prototype.units(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#units
property.
The value must be one of: cm
, feet
, inches
, km
, m
, miles
, or any absolute URI.
as.models.Profile > as.models.Object
Class: The base class for all Activity Streams 2.0 Profile objects. Inherits from as.models.Object
as.models.Profile.prototype.describes
Property: as.models.Profile.Builder > as.models.Object.Builder
Class: The base class for all as.models.Profile
builders. Inherits from
as.models.Object.Builder
as.models.Profile.Builder.prototype.describes(val)
Method: Sets the value of the http://www.w3.org/ns/activitystreams#describes
property.
as.models.Question > as.models.Activity
Class: The base class for all Activity Streams 2.0 Question objects. Inherits from
as.models.Activity
;
as.models.Question.prototype.anyOf
Property: Returns the value of the http://www.w3.org/ns/activitystreams#anyOf
property.
The value will either be undefined
or an Iterable of as.models.Base
objects.
as.models.Question.prototype.oneOf
Property: Returns the value of the http://www.w3.org/ns/activitystreams#oneOf
property.
The value will either be undefined
or an Iterable of as.models.Base
objects.
as.models.Question.Builder > as.models.Activity.Builder
Class: The base class for all as.models.Question
builders. Inherits from
as.models.Activity.Builder
;
as.models.Question.Builder.anyOf(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#anyOf
property.
as.models.Question.Builder.oneOf(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#oneOf
property.
as.models.Relationship > as.models.Object
Class: The base class for all Activity Streams 2.0 Relationship objects. Inherits
from as.models.Object
.
as.models.Relationship.prototype.subject
Property: Returns the value of the http://www.w3.org/ns/activitystreams#subject
property. The value will either be undefined
or an as.models.Base
object.
as.models.Relationship.prototype.relationship
Property: Returns the value of the http://www.w3.org/ns/activitystreams#relationship
property. The value will either be undefined
or an Iterable of as.models.Base
objects.
as.models.Relationship.prototype.object
Property: Returns the value of the http://www.w3.org/ns/activitystreams#object
property. The value will either be undefined
or an Iterable of as.models.Base
objects.
as.models.Relationship.Builder > as.models.Object.Builder
Class: The base class for all as.models.Relationship
builders. Inherits from as.models.Object.Builder
.
as.models.Relationship.Builder.prototype.subject(val)
Method: Sets the valu eof the http://ww.w3.org/ns/activitystreams#subject
property.
as.models.Relationship.Builder.prototype.relationship(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#relationship
property.
as.models.Relationship.Builder.prototype.object(val)
Method: Adds a value to the http://www.w3.org/ns/activitystreams#object
property.
LanguageValue
Class: Used to encapsulate language tagged properties within an Activity Streams document.
// assuming the default system locale is `en-US`:
var obj = as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get();
var languagevalue = obj.name;
console.log(languagevalue.get()); // 'default display name'
console.log(languagevalue.get('es')); // 'other display name'
// assuming the default system locale is `sp`:
var obj = as.object()
.name(
as.langmap()
.set('default display name')
.set('es', 'other display name')
)
.get();
var languagevalue = obj.name;
console.log(languagevalue.get()); // 'other display name'
console.log(languagevalue.get('en-US')); // 'default display name'