kopia lustrzana https://github.com/activitypub-js/activitypub-models
rename & add collections
rodzic
460081d924
commit
423e86f86e
|
@ -1,9 +1,9 @@
|
||||||
import { ObjectAP } from './models/Object.model';
|
import { ASObject } from './models/ASObject.model';
|
||||||
|
|
||||||
const obj = new ObjectAP({
|
const obj = new ASObject({
|
||||||
id: 'someId',
|
id: 'someId',
|
||||||
});
|
});
|
||||||
const obj2 = new ObjectAP({
|
const obj2 = new ASObject({
|
||||||
cc: '123',
|
cc: '123',
|
||||||
content: obj,
|
content: obj,
|
||||||
}).addContext();
|
}).addContext();
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
// TODO: types
|
// TODO: types
|
||||||
|
// TODO: renaming/refactor
|
||||||
export type Context = string | any[];
|
export type Context = string | any[];
|
||||||
|
|
||||||
export interface ModelBaseAPWithContext {
|
export interface ModelBaseAPWithContext {
|
||||||
'@context'?: Context;
|
'@context'?: Context;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ModelBaseAP<T> {
|
export class ASBase<T> {
|
||||||
public fields: T & ModelBaseAPWithContext;
|
public fields: T & ModelBaseAPWithContext;
|
||||||
|
|
||||||
constructor(fields: T) {
|
constructor(fields: T) {
|
||||||
|
@ -27,7 +28,7 @@ export class ModelBaseAP<T> {
|
||||||
public plain(): Record<string, any> {
|
public plain(): Record<string, any> {
|
||||||
const result = {} as Record<string, any>;
|
const result = {} as Record<string, any>;
|
||||||
for (const [key, node] of Object.entries(this.fields)) {
|
for (const [key, node] of Object.entries(this.fields)) {
|
||||||
if (node instanceof ModelBaseAP) {
|
if (node instanceof ASBase) {
|
||||||
result[key] = node.plain();
|
result[key] = node.plain();
|
||||||
} else {
|
} else {
|
||||||
result[key] = node;
|
result[key] = node;
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { ASObject, ASObjectFields } from "./ASObject.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#collection
|
||||||
|
export interface ASCollectionBaseFields extends ASObjectFields {
|
||||||
|
totalItems?: any;
|
||||||
|
first?: any;
|
||||||
|
last?: any;
|
||||||
|
current?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ASCollectionBase extends ASObject {
|
||||||
|
constructor(fields: ASCollectionBaseFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import {ModelBaseAP} from "./Base.model";
|
import {ASBase} from "./ASBase.model";
|
||||||
|
|
||||||
// TODO: types
|
// TODO: types
|
||||||
// https://www.w3.org/TR/activitystreams-core/#object
|
// https://www.w3.org/TR/activitystreams-core/#object
|
||||||
export interface ObjectAPFields {
|
export interface ASObjectFields {
|
||||||
id?: any;
|
id?: any;
|
||||||
type?: any;
|
type?: any;
|
||||||
attachment?: any;
|
attachment?: any;
|
||||||
|
@ -32,8 +32,8 @@ export interface ObjectAPFields {
|
||||||
duration?: any;
|
duration?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ObjectAP extends ModelBaseAP<ObjectAPFields>{
|
export class ASObject extends ASBase<ASObjectFields>{
|
||||||
constructor(fields: ObjectAPFields) {
|
constructor(fields: ASObjectFields) {
|
||||||
super(fields);
|
super(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
import {ModelBaseAP} from "./Base.model";
|
import {ASBase} from "./ASBase.model";
|
||||||
import {IntransitiveActivityAPFields} from "./IntransitiveActivity.model";
|
import {IntransitiveActivityFields} from "./IntransitiveActivity.model";
|
||||||
|
|
||||||
// TODO: types
|
// TODO: types
|
||||||
// https://www.w3.org/TR/activitystreams-core/#activities
|
// https://www.w3.org/TR/activitystreams-core/#activities
|
||||||
export interface ActivityAPFields extends IntransitiveActivityAPFields {
|
export interface ActivityFields extends IntransitiveActivityFields {
|
||||||
object?: any; // Object?
|
object?: any; // Object?
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ActivityAP extends ModelBaseAP<ActivityAPFields>{
|
export class Activity extends ASBase<ActivityFields>{
|
||||||
constructor(fields: ActivityAPFields) {
|
constructor(fields: ActivityFields) {
|
||||||
super(fields);
|
super(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import {ModelBaseAP} from "./Base.model";
|
import {ASBase} from "./ASBase.model";
|
||||||
import {ObjectAPFields} from "./Object.model";
|
import {ASObjectFields} from "./ASObject.model";
|
||||||
|
|
||||||
export enum ActorTypes {
|
export enum ActorTypes {
|
||||||
Application = 'Application',
|
Application = 'Application',
|
||||||
|
@ -11,17 +11,12 @@ export enum ActorTypes {
|
||||||
|
|
||||||
// TODO: types
|
// TODO: types
|
||||||
// https://www.w3.org/TR/activitystreams-core/#actors
|
// https://www.w3.org/TR/activitystreams-core/#actors
|
||||||
export interface ActorAPFields extends ObjectAPFields {
|
export interface ActorFields extends ASObjectFields {
|
||||||
type?: any | ActorTypes; // ?
|
type?: any | ActorTypes; // ?
|
||||||
actor?: any; // Actor?
|
|
||||||
target?: any;
|
|
||||||
origin?: any;
|
|
||||||
result?: any;
|
|
||||||
instrument?: any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ActorAP extends ModelBaseAP<ActorAPFields>{
|
export class Actor extends ASBase<ActorFields>{
|
||||||
constructor(fields: ActorAPFields) {
|
constructor(fields: ActorFields) {
|
||||||
super(fields);
|
super(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {ASCollectionBase, ASCollectionBaseFields} from "./ASCollectionBase.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#collection
|
||||||
|
export interface CollectionFields extends ASCollectionBaseFields {
|
||||||
|
items?: any; // Objects? Links?
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Collection extends ASCollectionBase {
|
||||||
|
constructor(fields: CollectionFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import {ASCollectionBase, ASCollectionBaseFields} from "./ASCollectionBase.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#collection
|
||||||
|
export interface CollectionPageFields extends ASCollectionBaseFields {
|
||||||
|
partOf?: any;
|
||||||
|
first?: any;
|
||||||
|
next?: any;
|
||||||
|
prev?: any;
|
||||||
|
last?: any;
|
||||||
|
current?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CollectionPage extends ASCollectionBase {
|
||||||
|
constructor(fields: CollectionPageFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import {ModelBaseAP} from "./Base.model";
|
import {ASBase} from "./ASBase.model";
|
||||||
import {ObjectAPFields} from "./Object.model";
|
import {ASObjectFields} from "./ASObject.model";
|
||||||
|
|
||||||
// TODO: types
|
// TODO: types
|
||||||
// https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
|
// https://www.w3.org/TR/activitystreams-core/#intransitiveactivities
|
||||||
export interface IntransitiveActivityAPFields extends ObjectAPFields {
|
export interface IntransitiveActivityFields extends ASObjectFields {
|
||||||
actor?: any; // Actor?
|
actor?: any; // Actor?
|
||||||
target?: any;
|
target?: any;
|
||||||
origin?: any;
|
origin?: any;
|
||||||
|
@ -11,8 +11,8 @@ export interface IntransitiveActivityAPFields extends ObjectAPFields {
|
||||||
instrument?: any;
|
instrument?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class IntransitiveActivityAP extends ModelBaseAP<IntransitiveActivityAPFields>{
|
export class IntransitiveActivity extends ASBase<IntransitiveActivityFields>{
|
||||||
constructor(fields: IntransitiveActivityAPFields) {
|
constructor(fields: IntransitiveActivityFields) {
|
||||||
super(fields);
|
super(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import {ModelBaseAP} from "./Base.model";
|
import {ASBase} from "./ASBase.model";
|
||||||
|
|
||||||
// TODO: types
|
// TODO: types
|
||||||
// https://www.w3.org/TR/activitystreams-core/#dfn-link
|
// https://www.w3.org/TR/activitystreams-core/#dfn-link
|
||||||
export interface ObjectAPFields {
|
export interface LinkFields {
|
||||||
id?: any;
|
id?: any;
|
||||||
name?: any;
|
name?: any;
|
||||||
hreflang?: any;
|
hreflang?: any;
|
||||||
|
@ -12,8 +12,8 @@ export interface ObjectAPFields {
|
||||||
width?: any;
|
width?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LinkAP extends ModelBaseAP<ObjectAPFields>{
|
export class Link extends ASBase<LinkFields>{
|
||||||
constructor(fields: ObjectAPFields) {
|
constructor(fields: LinkFields) {
|
||||||
super(fields);
|
super(fields);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {ASCollectionBase, ASCollectionBaseFields} from "./ASCollectionBase.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#collection
|
||||||
|
export interface OrderedCollectionFields extends ASCollectionBaseFields {
|
||||||
|
orderedItems?: any; // Objects? Links?
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: sort method?
|
||||||
|
export class OrderedCollection extends ASCollectionBase {
|
||||||
|
constructor(fields: OrderedCollectionFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {CollectionPage, CollectionPageFields} from "./CollectionPage.model";
|
||||||
|
|
||||||
|
// TODO: types
|
||||||
|
// TODO: is it correct?
|
||||||
|
// https://www.w3.org/TR/activitystreams-core/#collection
|
||||||
|
export interface OrderedCollectionPageFields extends CollectionPageFields {
|
||||||
|
startIndex?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OrderedCollectionPage extends CollectionPage {
|
||||||
|
constructor(fields: OrderedCollectionPageFields) {
|
||||||
|
super(fields);
|
||||||
|
}
|
||||||
|
}
|
Ładowanie…
Reference in New Issue