kopia lustrzana https://github.com/activitypub-js/activitypub-models
finish readme
rodzic
1dd04d25e3
commit
497760f197
26
README.md
26
README.md
|
@ -19,11 +19,12 @@ Extendable ActivityPub JS/TS models with official docs
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
Installation:
|
Install with npm:
|
||||||
```
|
```
|
||||||
# with npm
|
|
||||||
npm i activitypub-models
|
npm i activitypub-models
|
||||||
# with yarn
|
```
|
||||||
|
Install with yarn:
|
||||||
|
```
|
||||||
yarn add activitypub-models
|
yarn add activitypub-models
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -72,17 +73,19 @@ const customNote = CustomNote.create({
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Creating own models with JavaScript:
|
You also can create models with plain JS, but you will lose types. Can be fixed with .d.ts and jsdoc:
|
||||||
```javascript
|
```typescript
|
||||||
import { NoteFields, APBase, ASModelType } from 'activitypub-models';
|
// 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
|
||||||
* @typedef {Object} CustomNoteFields
|
import {APBase, ASModelType} from "activitypub-models";
|
||||||
* @property {string | string[]} myField
|
|
||||||
*/
|
|
||||||
|
|
||||||
class CustomNote extends APBase {
|
class CustomNote extends APBase {
|
||||||
/** @param {NoteFields & CustomNoteFields} fields */
|
|
||||||
static create(fields) {
|
static create(fields) {
|
||||||
return APBase._create({
|
return APBase._create({
|
||||||
type: ASModelType.Note,
|
type: ASModelType.Note,
|
||||||
|
@ -91,6 +94,7 @@ class CustomNote extends APBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {CustomNoteType} */
|
||||||
const customNote = CustomNote.create({
|
const customNote = CustomNote.create({
|
||||||
myField: 'I am a new field!'
|
myField: 'I am a new field!'
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "activitypub-models",
|
"name": "activitypub-models",
|
||||||
"version": "0.0.1",
|
"version": "0.0.3",
|
||||||
"description": "ActivityPub Models JS/TS implementation",
|
"description": "ActivityPub Models JS/TS implementation",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|
Ładowanie…
Reference in New Issue