kopia lustrzana https://github.com/activitypub-js/activitypub-models
Release 1.0.0 (#5)
* add exports * fixes * add license * finish readme * fix import * remove nodemon * update meta info * set version 1.0.0main
rodzic
8054849fcf
commit
588d8616d8
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) SiranWeb <kirillg.web@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
115
README.md
115
README.md
|
@ -1,26 +1,113 @@
|
||||||
# ActivityPub Models
|
# 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
|
## Table of Contents
|
||||||
|
|
||||||
<!-- - [About](#about) -->
|
- [Features](#features)
|
||||||
<!-- - [Getting Started](#getting-started) -->
|
- [Docs](#docs)
|
||||||
<!-- - [Docs](#Docs) -->
|
- [Roadmap](#future-plans)
|
||||||
- [Roadmap](#roadmap)
|
|
||||||
- [Contact](#contact)
|
- [Contact](#contact)
|
||||||
<!-- - [License](#license) -->
|
- [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<CustomNoteFields> {
|
||||||
|
static create(fields: CustomNoteFields) {
|
||||||
|
return APBase._create<CustomNoteFields>({
|
||||||
|
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> & 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
|
||||||
|
|
||||||
## Roadmap
|
|
||||||
You can check current tasks [here](https://github.com/orgs/activitypub-js/projects/1)
|
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
|
## 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
18
package.json
18
package.json
|
@ -1,22 +1,20 @@
|
||||||
{
|
{
|
||||||
"name": "activitypub-js-models",
|
"name": "activitypub-models",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "ActivityPub Models JS/TS implementation",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tsc": "tsc -p ./tsconfig.json",
|
"tsc": "tsc -p ./tsconfig.json",
|
||||||
"tsc:watch": "tsc -w -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"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist",
|
||||||
|
"LICENSE",
|
||||||
|
"README.md"
|
||||||
],
|
],
|
||||||
"author": "",
|
"author": "SiranWeb <kirillg.web@gmail.com>",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^2.0.20",
|
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './common/constants';
|
||||||
|
export * from './common/types';
|
||||||
|
export * from './models';
|
|
@ -0,0 +1,58 @@
|
||||||
|
export * from './note/Note.model';
|
||||||
|
export * from './note/Note.types';
|
||||||
|
export * from './activity/Activity.model';
|
||||||
|
export * from './activity/Activity.types';
|
||||||
|
export * from './collection/Collection.model';
|
||||||
|
export * from './collection/Collection.types';
|
||||||
|
export * from './mention/Mention.model';
|
||||||
|
export * from './mention/Mention.types';
|
||||||
|
export * from './profile/Profile.model';
|
||||||
|
export * from './profile/Profile.types';
|
||||||
|
export * from './actor/Actor.model';
|
||||||
|
export * from './actor/Actor.types';
|
||||||
|
export * from './collectionPage/CollectionPage.model';
|
||||||
|
export * from './collectionPage/CollectionPage.types';
|
||||||
|
export * from './question/Question.model';
|
||||||
|
export * from './question/Question.types';
|
||||||
|
export * from './apBase/APBase.model';
|
||||||
|
export * from './apBase/APBase.model';
|
||||||
|
export * from './document/Document.model';
|
||||||
|
export * from './document/Document.types';
|
||||||
|
export * from './orderedCollection/OrderedCollection.model';
|
||||||
|
export * from './orderedCollection/OrderedCollection.types';
|
||||||
|
export * from './relationship/Relationship.model';
|
||||||
|
export * from './relationship/Relationship.types';
|
||||||
|
export * from './apEvent/APEvent.model';
|
||||||
|
export * from './apEvent/APEvent.types';
|
||||||
|
export * from './group/Group.model';
|
||||||
|
export * from './group/Group.types';
|
||||||
|
export * from './orderedCollectionPage/OrderedCollectionPage.model';
|
||||||
|
export * from './orderedCollectionPage/OrderedCollectionPage.types';
|
||||||
|
export * from './service/Service.model';
|
||||||
|
export * from './service/Service.types';
|
||||||
|
export * from './apObject/APObject.model';
|
||||||
|
export * from './apObject/APObject.types';
|
||||||
|
export * from './image/Image.model';
|
||||||
|
export * from './image/Image.types';
|
||||||
|
export * from './organization/Organization.model';
|
||||||
|
export * from './organization/Organization.types';
|
||||||
|
export * from './tombstone/Tombstone.model';
|
||||||
|
export * from './tombstone/Tombstone.types';
|
||||||
|
export * from './application/Application.model';
|
||||||
|
export * from './application/Application.types';
|
||||||
|
export * from './page/Page.model';
|
||||||
|
export * from './page/Page.types';
|
||||||
|
export * from './video/Video.model';
|
||||||
|
export * from './video/Video.types';
|
||||||
|
export * from './article/Article.model';
|
||||||
|
export * from './article/Article.types';
|
||||||
|
export * from './intransitiveActivity/IntransitiveActivity.model';
|
||||||
|
export * from './intransitiveActivity/IntransitiveActivity.types';
|
||||||
|
export * from './person/Person.model';
|
||||||
|
export * from './person/Person.types';
|
||||||
|
export * from './audio/Audio.model';
|
||||||
|
export * from './audio/Audio.types';
|
||||||
|
export * from './link/Link.model';
|
||||||
|
export * from './link/Link.types';
|
||||||
|
export * from './place/Place.model';
|
||||||
|
export * from './place/Place.types';
|
|
@ -9,7 +9,7 @@ import {
|
||||||
} from "../../common/types";
|
} from "../../common/types";
|
||||||
|
|
||||||
export interface LinkFields {
|
export interface LinkFields {
|
||||||
'@context': never;
|
'@context'?: never;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies the {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object Object}
|
* Identifies the {@link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object Object}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"target": "es2017",
|
"target": "es2017",
|
||||||
"module": "ES6",
|
"module": "commonjs",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
|
Ładowanie…
Reference in New Issue