kopia lustrzana https://github.com/activitypub-js/activitypub-models
fixes
rodzic
c48c93333e
commit
302b1066e9
111
README.md
111
README.md
|
@ -1,26 +1,109 @@
|
|||
# ActivityPub Models
|
||||
|
||||
ActivityPub JS/TS models with official docs. Still in development, not ready for production
|
||||
Extendable ActivityPub JS/TS models with official docs
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<!-- - [About](#about) -->
|
||||
<!-- - [Getting Started](#getting-started) -->
|
||||
<!-- - [Docs](#Docs) -->
|
||||
- [Roadmap](#roadmap)
|
||||
- [Features](#features)
|
||||
- [Docs](#docs)
|
||||
- [Roadmap](#future-plans)
|
||||
- [Contact](#contact)
|
||||
<!-- - [License](#license) -->
|
||||
- [License](#license)
|
||||
|
||||
## Features
|
||||
|
||||
- All models implemented
|
||||
- In-code documentation
|
||||
- Ability to create/extend own models
|
||||
- TypeScript and JavaScript support
|
||||
|
||||
## Docs
|
||||
|
||||
Installation:
|
||||
```
|
||||
# with npm
|
||||
npm i activitypub-models
|
||||
# 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<CustomNoteFields> {
|
||||
static create(fields: CustomNoteFields) {
|
||||
return APBase._create<CustomNoteFields>({
|
||||
type: ASModelType.Note,
|
||||
...fields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const customNote = CustomNote.create({
|
||||
myField: 'I am a new field!'
|
||||
});
|
||||
```
|
||||
|
||||
Creating own models with JavaScript:
|
||||
```javascript
|
||||
import { NoteFields, APBase, ASModelType } from 'activitypub-models';
|
||||
|
||||
/**
|
||||
* @typedef {Object} CustomNoteFields
|
||||
* @property {string | string[]} myField
|
||||
*/
|
||||
|
||||
class CustomNote extends APBase {
|
||||
/** @param {NoteFields & CustomNoteFields} fields */
|
||||
static create(fields) {
|
||||
return APBase._create({
|
||||
type: ASModelType.Note,
|
||||
...fields,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const customNote = CustomNote.create({
|
||||
myField: 'I am a new field!'
|
||||
});
|
||||
```
|
||||
|
||||
## Future plans
|
||||
|
||||
## Roadmap
|
||||
You can check current tasks [here](https://github.com/orgs/activitypub-js/projects/1)
|
||||
|
||||
- [x] Implement all ActivityPub/ActivityStreams models
|
||||
- [x] Prepare infrastructure
|
||||
- [ ] Add complex data types
|
||||
- [ ] Publish as NPM package
|
||||
- [ ] Prepare docs
|
||||
|
||||
## Contact
|
||||
|
||||
We have a lot of plans for future. Any help will be appreciated. You can contact me via [matrix](https://matrix.to/#/@siranweb:matrix.org) or [telegram](https://t.me/KirillG_web)
|
||||
You can contact me via [matrix](https://matrix.to/#/@siranweb:matrix.org) or [telegram](https://t.me/KirillG_web)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
Plik diff jest za duży
Load Diff
14
package.json
14
package.json
|
@ -1,17 +1,17 @@
|
|||
{
|
||||
"name": "activitypub-js-models",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"name": "activitypub-models",
|
||||
"version": "0.0.1",
|
||||
"description": "ActivityPub Models JS/TS implementation",
|
||||
"main": "./dist/index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"tsc": "tsc -p ./tsconfig.json",
|
||||
"tsc:watch": "tsc -w -p ./tsconfig.json",
|
||||
"start": "node --es-module-specifier-resolution=node dist/index.js",
|
||||
"start:dev": "nodemon --es-module-specifier-resolution=node dist/index.js"
|
||||
"tsc:watch": "tsc -w -p ./tsconfig.json"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
} from "../../common/types";
|
||||
|
||||
export interface LinkFields {
|
||||
'@context': never;
|
||||
'@context'?: never;
|
||||
|
||||
/**
|
||||
* Identifies the {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object Object}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"outDir": "./dist",
|
||||
"declaration": true,
|
||||
"target": "es2017",
|
||||
"module": "ES6",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "Node",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
|
Ładowanie…
Reference in New Issue