chore(api-ref): add documentation on strapi and container

This commit is contained in:
nathan-pichon 2023-02-08 14:53:11 +01:00
parent 1102869575
commit 59bc546ec7
No known key found for this signature in database
6 changed files with 179 additions and 7 deletions

9
.eslintrc.docs.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
parserOptions: {
sourceType: 'module',
},
plugins: ['react'],
rules: {
'react/prop-types': 0,
},
};

50
docs/docs/api/Strapi.mdx Normal file
View File

@ -0,0 +1,50 @@
---
title: Strapi
slug: /api/Strapi
tags:
- class
- public
- global
toc_min_heading_level: 2
toc_max_heading_level: 5
---
import Type from '@site/docs/api/components/Type';
# Strapi
:::info
Current state: **Stable**
:::
The Strapi class is the main object used in Strapi projects.
An instance of Strapi class is available as a global in any Strapi project: `global.strapi`.
## Class: Strapi
### `new Strapi(opts)`
- `opts`: <Type>Object</Type> Options that can be used on Strapi startup
- `autoReload`: <Type>Boolean</Type> **Default:** true
- If false, deactivate auto reload
- If you modify any file in your Strapi project, it reloads your nodejs app
- If any content-type is changed, it will reload the nodejs app
- `serveAdminPanel`: <Type>Boolean</Type> **Default:** true
- Should the admin panel be loaded and serve as a web client
- The admin panel build will not be delivered if false
- `appDir`: <Type>String</Type> **Default:** `process.cwd()`
- The directory relative or absolute path where Strapi will write every file (schemas, generated APIs, controllers or services)
- `distDir`: <Type>String</Type> **Default:** appDir value
- The directory relative or absolute path where Strapi will read configurations, schemas and any compiled code
Instances of the Strapi class can be created using the new keyword.
```javascript
const strapiInstance = new Strapi();
```
### `strapi.container`
This is where all registries are stored.

View File

@ -0,0 +1,13 @@
import React from 'react';
export default function Type({ children }) {
return (
<span
style={{
color: '#017501',
}}
>
&lt;{children}&gt;
</span>
);
}

View File

@ -0,0 +1,99 @@
---
title: Container
slug: /api/container
tags:
- module
- public
toc_min_heading_level: 2
toc_max_heading_level: 5
---
import Type from '@site/docs/api/components/Type';
# Container
:::info
Current state: **Stable**
:::
The container module permits to generate containers.
## Module: container
### `createContainer(strapi)`
- `strapi`: <Type>Strapi</Type> [See Strapi class documentation](Strapi.mdx)
- Returns: <Type>Container</Type>
```javascript
const container = createContainer(strapi);
container.register('config', {
get: (configName) => {},
set: (configName, value) => {}
});
const dbConfig = container.get('config').get('database');
```
### `container.get(name, args)`
- `name`: <Type>String</Type> UID of the content
- `args`: <Type>Any</Type> Value that will be passed to the resolver (if function)
Get the value stored for a specific `name`.
```javascript
const container = createContainer(strapi);
container.register('config', { db: 'sqlite' });
const config = container.get('config');
// config.db === 'sqlite'
```
⚠️ If the **resolver**, used in the [register function](#containerregistername-resolver), is a **function**, the value will be the result of this resolver function with `args` as parameter on the first call to `get`.
```javascript
const container = createContainer(strapi);
container.register('boolean', (bool) => bool);
// First call - The value is resolved through the resolver above "(bool) => bool"
container.get('boolean', true);
// true
// Any further call will use the previously set value
container.get('boolean');
// true
// Even if we try to push a new value
container.get('boolean', false);
// true
```
### `container.register(name, resolver)`
- `name`: <Type>String</Type> UID of the content
- `resolver`: <Type>Function</Type> | <Type>Any</Type>
- As a function, the function will be executed when the first get method is called on this content. The result of this function will define the content of this UID.
- `resolver(context, args)`
- `context`: <Type>{ Strapi }</Type> [See Strapi class documentation](Strapi.mdx)
- `args`: <Type>Any</Type> Anything to be used by the resolver function
- As anything else, this value will be resolved when getting this specified content through its UID.
Register a new content to be accessed inside the container. If the name is already used, it will throw an error.
```javascript
const container = createContainer(strapi);
container.register('config', () => {});
// or
container.register('services', {});
```
### `container.extend()`
To be developed

View File

@ -1 +0,0 @@
# API

View File

@ -10,6 +10,8 @@ toc_min_heading_level: 2
toc_max_heading_level: 5
---
import Type from '@site/docs/api/components/Type';
# Name of Module
:::info
@ -42,9 +44,9 @@ const myClass = new Class();
### `class.method(param1, param2)`
- `param1`: &lt; String &gt; (can be linked to other API doc page).
- `param2`: &lt; Object &gt;
- `options1`: &lt; Number &gt;
- `param1`: <Type>String</Type> (can be linked to other API doc page).
- `param2`: <Type>Object</Type>
- `options1`: <Type>Number</Type>
The `class.method()` method display the `param1` and then skip `param2` lines.
@ -67,9 +69,9 @@ for (const text of textLines) {
## Function: `name_of_the_function(param1, param2)`
- `param1`: &lt; String &gt; (can be linked to other API doc page)
- `param2`: &lt; Object &gt;
- `options1`: &lt; Number &gt;
- `param1`: <Type>String</Type> (can be linked to other API doc page)
- `param2`: <Type>Object</Type>
- `options1`: <Type>Number</Type>
The `name_of_the_function()` method display the `param1` and then skip `param2` lines.