|
1 | 1 | # @webdoc/model |
2 | 2 |
|
3 | | -This package is the API to manipulating loaded documentation tree models. [@webdoc/types](https://github.com/webdoc-js/webdoc/tree/master/packages/webdoc-types) defines the node structure. |
| 3 | +This package is the API for editing and querying in-memory documentation tree models. [@webdoc/types](/packages/webdoc-types) defines the node structure. |
4 | 4 |
|
5 | 5 | ## Installation :package: |
6 | 6 |
|
| 7 | +This package is usually a dependency of templates and other webdoc packages. |
| 8 | + |
7 | 9 | ```bash |
8 | 10 | npm install @webdoc/model |
9 | 11 | ``` |
10 | 12 |
|
11 | | -## Usage |
| 13 | +## Usage :newspaper_roll: |
| 14 | + |
| 15 | +```js |
| 16 | +import * as model from '@webdoc/model'; |
| 17 | +``` |
| 18 | + |
| 19 | +### Constructing and editing documents |
| 20 | + |
| 21 | +```js |
| 22 | +const entity = model.createDoc( |
| 23 | + "DocumentedEntity", |
| 24 | + "ClassDoc", |
| 25 | + { |
| 26 | + "description": "This is a programmatically created document!", |
| 27 | + } |
| 28 | +); |
| 29 | + |
| 30 | +const entityNs = model.doc("Documentation.Entities", documentTree); |
| 31 | + |
| 32 | +model.addChildDoc(entity, entityNs); |
| 33 | +``` |
| 34 | + |
| 35 | +@webdoc/model exports helper functions for creating and searching documents and mounting them into document trees. |
| 36 | + |
| 37 | +### Data types |
12 | 38 |
|
13 | 39 | ```js |
14 | | -const Model = require('@webdoc/model'); |
| 40 | +model.createFunctionType( |
| 41 | + [model.createSimpleKeywordType("Promise")], // params |
| 42 | + model.createSimpleKeywordType("boolean"), // returns |
| 43 | +); |
15 | 44 | ``` |
| 45 | + |
| 46 | +@webdoc/model exports helper functions for creating and joining data types. The `DataType` type is defined in [@webdoc/types](/packages/webdoc-types). |
| 47 | + |
| 48 | +### Querying |
| 49 | + |
| 50 | +```js |
| 51 | +// Gets all the methods named "generic" in DocumentedEntity. Each signature of the method has a separate document. The |
| 52 | +// # operator excludes any static "generic"-named methods. |
| 53 | +const genericSignatures = model.query("Documentation.Entities.DocumentedEntity#generic", documentTree); |
| 54 | +``` |
| 55 | + |
| 56 | +@webdoc/model exports a query engine for its document path language. |
| 57 | + |
| 58 | +### Runtime type-checking |
| 59 | + |
| 60 | +```js |
| 61 | +const isInstantiable = model.isClass(doc) || model.isInterface(doc); |
| 62 | +``` |
| 63 | + |
| 64 | +@webdoc/model exports helper functions for checking the types of document passed. |
0 commit comments