Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

activitystreams2

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activitystreams2 - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

.editorconfig

31

package.json
{
"name": "activitystreams2",
"version": "0.0.2",
"version": "0.1.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "build/index.js",
"types": "build/index.d.ts",
"author": "",
"license": "ISC",
"scripts": {
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'bin/**/*.ts'",
"lint-fix": "tslint --fix -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'bin/**/*.ts'",
"test": "ts-node src/test",
"tsc": "tsc",
"build": "npm run tsc"
"tsfmt": "tsfmt -r",
"build": "npm run tsc",
"check": "gts check",
"clean": "gts clean",
"compile": "tsc -p .",
"lint": "npm run check",
"lint-fix": "npm run fix",
"fix": "gts fix",
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run check",
"preversion": "npm test"
},
"devDependencies": {
"@types/node": "^10.3.2",
"@types/node": "^12.7.4",
"activitystreams2-spec-scraped": "0.0.3",
"gts": "^0.6.0",
"ts-node": "^6.1.0",
"tslint": "^5.10.0",
"typescript": "^2.9.1"
}
"typescript": "^3.6.2",
"typescript-formatter": "^7.2.2"
},
"dependencies": {}
}

@@ -6,1 +6,3 @@ # activitystreams2

This was originally created for [distbin](https://github.com/gobengo/distbin) and has worked well. But there is likely room for improvement. Please file issues if you notice bugs or would like to request new features that other systems handling ActivityStreams 2.0 data might need.
![UML Class Diagram](./docs/diagram.png)

@@ -1,137 +0,2 @@

export const jsonLdProfile = "https://www.w3.org/ns/activitystreams"
// application/ld+json; profile="https://www.w3.org/ns/activitystreams"
export const ASJsonLdProfileContentType = `application/ld+json; profile="${jsonLdProfile}"`
type ISO8601 = string;
type xsdAnyUri = string;
type OneOrMore<T> = T | T[];
// ASLinked Data
type LDIdentifier = xsdAnyUri;
export type LDValue<T> = (LDIdentifier | T);
export type LDValues<T> = T | T[];
export type LDObject<T> = {
[P in keyof T]?: LDValues<T[P]>;
};
type JSONLDContext = OneOrMore<string | {
"@vocab"?: string
"@language"?: string
[key: string]: string | {[key: string]: string},
}>;
export class JSONLD {
public "@id": string;
}
class ASBase {
public "@context"?: JSONLDContext;
}
// @TODO (bengo): enumerate known values?
type LinkRelation = string;
export class ASLink {
public type: ASObjectType<"Link">;
public href: string;
public mediaType?: string;
public rel?: LinkRelation;
}
export const Link = ASLink
export const isASLink = (obj: any): obj is ASLink => {
return obj.type === "Link";
}
// @TODO (bengo)
type RdfLangString = string
interface INaturalLanguageValue {
// @TODO (bengo) this could be more specific about keys than just string
[key: string]: string
}
type ASObjectType<T> = T | T[]
export type ASValue = string | ASObject | ASLink
// W3C ActivityStreams 2.0
export class ASObject extends ASBase {
public attachment?: OneOrMore<ASObject|ASLink>
public attributedTo?: LDValue<ASObject>
public bcc?: LDValue<ASObject>
public cc?: OneOrMore<LDValue<ASObject>>
public content?: string
public generator?: LDValue<ASObject>
public id?: string
public image?: OneOrMore<string|ASLink|ASImage>
public inReplyTo?: LDValue<ASObject>
public location?: ASObject
public name?: string
public nameMap?: INaturalLanguageValue
public preview?: ASValue
public published?: ISO8601
public replies?: LDValue<Collection<ASObject>>
public summary?: string|RdfLangString
public tag?: ASObject|ASLink
public to?: LDValue<ASObject>
public bto?: LDValue<ASObject>
public type?: ASObjectType<string>
public url?: OneOrMore<xsdAnyUri|ASLink>
}
export const isASObject = (obj: any): obj is ASObject => {
return typeof obj === "object"
}
class ASImage extends ASObject {}
// https://www.w3.org/TR/activitystreams-vocabulary/#activity-types
export const activitySubtypes = [
"Accept", "Add", "Announce", "Arrive", "Block", "Create", "Delete",
"Dislike", "Flag", "Follow", "Ignore", "Invite", "Join", "Leave", "Like",
"Listen", "Move", "Offer", "Question", "Reject", "Read", "Remove",
"TentativeReject", "TentativeAccept", "Travel", "Undo", "Update", "View",
]
const ActivitySubtypes = strEnum(activitySubtypes)
type ActivitySubtype = keyof typeof ActivitySubtypes
export class Activity extends ASObject {
public type: ASObjectType<"Activity" | ActivitySubtype>
public actor?: ASValue
public object?: LDValue<ASObject>
public target?: ASValue
constructor(props: any) {
super()
this.type = this.constructor.name
Object.assign(this, props)
}
}
export const isActivity = (activity: any): activity is Activity => {
if (typeof activity === "object") {
return activitySubtypes.includes(activity.type)
}
return false
}
export class Collection<T> extends ASObject {
public items?: T[]
public totalItems?: number
}
export class Note extends ASObject {
public type: ASObjectType<"Note">
}
export class Place extends ASObject {
public accuracy?: number
public latitude?: number
public longitude?: number
public altitude?: number
public radius?: number
public units?: "cm" | "feet" | "inches" | "km" | "m" | "miles" | xsdAnyUri
}
function strEnum<T extends string>(o: T[]): {[K in T]: K} {
return o.reduce((res, key) => {
res[key] = key
return res
}, Object.create(null))
}
export * from './core';
export * from './vocabulary';

@@ -1,12 +0,26 @@

import * as assert from "assert"
import * as activitystreams2 from "../"
import * as assert from 'assert';
import {ParsedClass, scrapeVocabulary} from '../../../activitystreams2-spec-scraped';
import {jsonLdProfileContentType} from '../core';
import * as vocab from '../vocabulary';
if (require.main === module) {
main()
.then(() => process.exit())
.catch(() => process.exit(1))
main().then(() => process.exit()).catch((error) => {
console.error(error);
process.exit(1);
});
}
function testActivityType(activityType: ParsedClass) {
assert.equal(
activityType.name in vocab, true,
`vocab exports activityType ${activityType.name}`);
}
async function main() {
assert.equal(typeof activitystreams2.ASJsonLdProfileContentType, "string")
assert.equal(typeof jsonLdProfileContentType, 'string');
const scrapedVocab = await scrapeVocabulary();
for (const activityType of scrapedVocab.sections.activityTypes.members) {
testActivityType(activityType);
}
}
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": true,
"types": ["node"],
"outDir": "dist",
"rootDir": "./src",
"outDir": "build",
// rest of compilerOptions from google/ts-style
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2016"],
"module": "commonjs",
"target": "es5",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"pretty": true,
"lib": [
"es7",
"es2017"
],
"sourceMap": true,
"declaration": true
"strict": true,
"target": "es2016"
},
"include": [
"src/*.ts",
"src/**/*.ts",
],
"exclude": [
"node_modules",
"dist"
"test/*.ts",
"test/**/*.ts"
]
}
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
"defaultSeverity": "error",
"extends": [
"gts/tslint.json"
],
"jsRules": {},
"rules": {
"completed-docs": [
false,
{
"classes": true,
"types": true
}
],
"jsRules": {},
"rules": {
"max-classes-per-file": false,
"semicolon": false
},
"rulesDirectory": []
}
"max-classes-per-file": false,
"no-unused-variable": true,
"semicolon": false
},
"rulesDirectory": []
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc