From 7c54ed84aaa98e7d6d9d3124a36a52b6b78502d4 Mon Sep 17 00:00:00 2001 From: Kirill Date: Sat, 11 Mar 2023 15:36:38 +0300 Subject: [PATCH] Update README.md --- README.md | 115 +----------------------------------------------------- 1 file changed, 2 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 2027709..c08495b 100644 --- a/README.md +++ b/README.md @@ -1,113 +1,2 @@ -# ActivityPub Models - -Extendable ActivityPub JS/TS models with official docs - -## Table of Contents - -- [Features](#features) -- [Docs](#docs) -- [Roadmap](#future-plans) -- [Contact](#contact) -- [License](#license) - -## Features - -- All models implemented -- In-code documentation -- Ability to create/extend own models -- TypeScript and JavaScript support - -## Docs - -Install with npm: -``` -npm i activitypub-models -``` -Install with yarn: -``` -yarn add activitypub-models -``` - -Use of models: -```typescript -import { Note, Link, contexts } from 'activitypub-models'; - -// "type" already provided, but can be rewrited -const imageLink = Link.create({ - href: 'https://example.org/martin/image.jpg', - mediaType: 'image/jpeg' -}); - -const note = Note.create({ - '@context': contexts.activityStreamsV2, - mediaType: 'text/plain', - image: imageLink, // supports nested objects -}); - -note.content = 'some content'; -note.content = 123; // TypeError: only string available for "content" - -const obj = note.toPlain(); // convert to simple JS object -const json = note.toJSON(); // convert to JSON -``` - -Creating own models with TypeScript: -```typescript -import { NoteFields, APBase, ASModelType } from 'activitypub-models'; - -interface CustomNoteFields extends NoteFields { - myField: string | string[]; -} - -class CustomNote extends APBase { - static create(fields: CustomNoteFields) { - return APBase._create({ - type: ASModelType.Note, - ...fields, - }); - } -} - -const customNote = CustomNote.create({ - myField: 'I am a new field!' -}); -``` - -You also can create models with plain JS, but you will lose types. Can be fixed with .d.ts and jsdoc: -```typescript -// CustomNote.d.ts -import { APBase, NoteFields, WithContext } from "activitypub-models"; -export interface CustomNotesFields extends NoteFields { - myField: string | string[]; -} -export type CustomNoteType = APBase & CustomNotesFields & WithContext; - -// CustomNote.js -import {APBase, ASModelType} from "activitypub-models"; - -class CustomNote extends APBase { - static create(fields) { - return APBase._create({ - type: ASModelType.Note, - ...fields, - }); - } -} - -/** @type {CustomNoteType} */ -const customNote = CustomNote.create({ - myField: 'I am a new field!' -}); -``` - -## Future plans - -You can check current tasks [here](https://github.com/orgs/activitypub-js/projects/1) - -## Contact - -You can contact me via [matrix](https://matrix.to/#/@siranweb:matrix.org) or [telegram](https://t.me/KirillG_web) - -## License - -[MIT](LICENSE) \ No newline at end of file +# Check new repo +Please use [activitypub-types](https://github.com/SiranWeb/activitypub-types) instead. It contains all ActivityPub types as Typescript interfaces, so you can write your model logic as you want