kopia lustrzana https://github.com/activitypub-js/activitypub-models
git init
commit
609485b378
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules/
|
||||||
|
build/
|
||||||
|
.idea/
|
Plik diff jest za duży
Load Diff
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "activitypub-js-models",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"ts:watch": "tsc -p ./tsconfig.json",
|
||||||
|
"start": "node --es-module-specifier-resolution=node build/index.js",
|
||||||
|
"start:dev": "nodemon --es-module-specifier-resolution=node build/index.js"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^2.0.20",
|
||||||
|
"typescript": "^4.8.4"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import express from 'express';
|
||||||
|
import { ObjectAP } from './models/Object.model';
|
||||||
|
|
||||||
|
// const app = express();
|
||||||
|
// app.listen(3000, () => console.log('Listening on port 3000!'));
|
||||||
|
|
||||||
|
const obj = new ObjectAP({
|
||||||
|
id: 'someId',
|
||||||
|
});
|
||||||
|
const obj2 = new ObjectAP({
|
||||||
|
cc: '123',
|
||||||
|
content: obj,
|
||||||
|
}).addContext();
|
||||||
|
|
||||||
|
console.log(obj2.plain());
|
||||||
|
console.log(obj2.json());
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {ModelBaseAP} from "./Base.model";
|
||||||
|
import {IntransitiveActivityAPFields} from "./IntransitiveActivity.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#activities
|
||||||
|
export interface ActivityAPFields extends IntransitiveActivityAPFields {
|
||||||
|
object?: any; // Object?
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ActivityAP extends ModelBaseAP<ActivityAPFields>{
|
||||||
|
constructor(fields: ActivityAPFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
import {ModelBaseAP} from "./Base.model";
|
||||||
|
import {ObjectAPFields} from "./Object.model";
|
||||||
|
|
||||||
|
export enum ActorTypes {
|
||||||
|
Application = 'Application',
|
||||||
|
Group = 'Group',
|
||||||
|
Organization = 'Organization',
|
||||||
|
Person = 'Person',
|
||||||
|
Service = 'Service'
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#actors
|
||||||
|
export interface ActorAPFields extends ObjectAPFields {
|
||||||
|
type?: any | ActorTypes; // ?
|
||||||
|
actor?: any; // Actor?
|
||||||
|
target?: any;
|
||||||
|
origin?: any;
|
||||||
|
result?: any;
|
||||||
|
instrument?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ActorAP extends ModelBaseAP<ActorAPFields>{
|
||||||
|
constructor(fields: ActorAPFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
// TODO: types
|
||||||
|
export type Context = string | any[];
|
||||||
|
|
||||||
|
export interface ModelBaseAPWithContext {
|
||||||
|
'@context'?: Context;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ModelBaseAP<T> {
|
||||||
|
public fields: T & ModelBaseAPWithContext;
|
||||||
|
|
||||||
|
constructor(fields: T) {
|
||||||
|
// TODO: make recursive copy
|
||||||
|
this.fields = {
|
||||||
|
...fields,
|
||||||
|
} as T & ModelBaseAPWithContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: rewrite (better option to handle multiple contexts)
|
||||||
|
public addContext(context?: Context): this {
|
||||||
|
this.fields = {
|
||||||
|
['@context']: context || 'https://www.w3.org/ns/activitystreams',
|
||||||
|
...this.fields
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public plain(): Record<string, any> {
|
||||||
|
const result = {} as Record<string, any>;
|
||||||
|
for (const [key, node] of Object.entries(this.fields)) {
|
||||||
|
if (node instanceof ModelBaseAP) {
|
||||||
|
result[key] = node.plain();
|
||||||
|
} else {
|
||||||
|
result[key] = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO make recursive copy
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public json() {
|
||||||
|
return JSON.stringify(this.plain());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import {ModelBaseAP} from "./Base.model";
|
||||||
|
import {ObjectAPFields} from "./Object.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
|
||||||
|
export interface IntransitiveActivityAPFields extends ObjectAPFields {
|
||||||
|
actor?: any; // Actor?
|
||||||
|
target?: any;
|
||||||
|
origin?: any;
|
||||||
|
result?: any;
|
||||||
|
instrument?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class IntransitiveActivityAP extends ModelBaseAP<IntransitiveActivityAPFields>{
|
||||||
|
constructor(fields: IntransitiveActivityAPFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
import {ModelBaseAP} from "./Base.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#dfn-link
|
||||||
|
export interface ObjectAPFields {
|
||||||
|
id?: any;
|
||||||
|
name?: any;
|
||||||
|
hreflang?: any;
|
||||||
|
mediaType?: any;
|
||||||
|
rel?: any;
|
||||||
|
height?: any;
|
||||||
|
width?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LinkAP extends ModelBaseAP<ObjectAPFields>{
|
||||||
|
constructor(fields: ObjectAPFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
import {ModelBaseAP} from "./Base.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#object
|
||||||
|
export interface ObjectAPFields {
|
||||||
|
id?: any;
|
||||||
|
type?: any;
|
||||||
|
attachment?: any;
|
||||||
|
attributedTo?: any;
|
||||||
|
audience?: any;
|
||||||
|
content?: any;
|
||||||
|
name?: any;
|
||||||
|
endTime?: any;
|
||||||
|
generator?: any;
|
||||||
|
icon?: any;
|
||||||
|
image?: any; // Link?
|
||||||
|
inReplyTo?: any;
|
||||||
|
location?: any;
|
||||||
|
preview?: any;
|
||||||
|
published?: any;
|
||||||
|
replies?: any;
|
||||||
|
startTime?: any;
|
||||||
|
summary?: any;
|
||||||
|
tag?: any;
|
||||||
|
updated?: any;
|
||||||
|
url?: any;
|
||||||
|
to?: any;
|
||||||
|
bto?: any;
|
||||||
|
cc?: any;
|
||||||
|
bcc?: any;
|
||||||
|
mediaType?: any;
|
||||||
|
duration?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ObjectAP extends ModelBaseAP<ObjectAPFields>{
|
||||||
|
constructor(fields: ObjectAPFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"watch": true,
|
||||||
|
"outDir": "./build",
|
||||||
|
"target": "es2016",
|
||||||
|
"module": "ES6",
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "**/*.spec.ts"],
|
||||||
|
}
|
Ładowanie…
Reference in New Issue