From 103c03141f35a0ad4d2259eba15fa364e3a349bb Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 24 Jan 2023 18:21:02 +0100 Subject: [PATCH 01/36] chore(docs): add api reference example --- docs/docs/api/structure-example.md | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 docs/docs/api/structure-example.md diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md new file mode 100644 index 0000000000..4d87780a8e --- /dev/null +++ b/docs/docs/api/structure-example.md @@ -0,0 +1,87 @@ +--- +title: API Reference example +tags: + - utils + - class + - public + - global + +toc_min_heading_level: 1 +toc_max_heading_level: 5 +--- + +# Name of Module + +> Current state: Stable | Legacy | Deprecated + +_**Stable** - can be use as is_ + +_**Legacy** - Old code that needs refactoring to match the current architecture of the code_ + +_**Deprecated** - Should **NOT** be used, this will be deleted anytime soon_ + +_Description with a general example on how to use this Class / Module_ + +## Class: Name of the class + +### Public variable (e.g. in an EventEmitter class `Event: 'close'`) + +### Static methods (e.g. `Static method: Class.default()`) + +### `new Class()` + +Instances of the Class class can be created using the new keyword. + +```javascript +const myClass = new Class(); +``` + +### `class.method(param1, param2)` + +- `param1`: \ (can be linked to other API doc page). +- `param2`: \ + - `options1`: \ + +The `class.method()` method display the `param1` and then skip `param2` lines. + +Example usage: + +```javascript +const { Class } = require('pathToClassFile'); +const textLines = ['Welcome', "That's all", 'Thanks']; + +const classInstance = new Class(); + +for (const text of textLines) { + classInstance.method(text, 1); +} +// Prints: +// Welcome +// That's all +// Thanks +``` + +## Function: `name_of_the_function(param1, param2)` + +- `param1`: \ (can be linked to other API doc page) +- `param2`: \ + - `options1`: \ + +The `name_of_the_function()` method display the `param1` and then skip `param2` lines. + +Example usage: + +```javascript +const { name_of_the_function } = require('pathToFunctionFile'); +const textLines = ['Welcome', "That's all", 'Thanks']; + +for (const text of textLines) { + name_of_the_function(text, 1); +} +// Prints: +// Welcome +// That's all +// Thanks +``` + +This structure is highly based on NodeJS API reference documentation. https://nodejs.org/api From 8132c0ec237901a05641bbf5bbe009c59807a59e Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Fri, 13 Jan 2023 16:30:49 +0100 Subject: [PATCH 02/36] chore: contributor docs WIP --- packages/core/strapi/lib/Strapi.js | 206 ++++++++++++++++++ .../core/strapi/lib/services/server/index.js | 26 +++ .../strapi/lib/utils/update-notifier/index.js | 10 + 3 files changed, 242 insertions(+) diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 6c3a5c2ddb..e943edd512 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -70,8 +70,49 @@ const resolveWorkingDirectories = (opts) => { return { app: appDir, dist: distDir }; }; +// TODO put this in /docs/docs/API/Strapi +/* + +The Strapi class is the main class of a Strapi project + +The instance of Strapi class is used to manipulate everything related to strapi content management system. + +> Example + + + */ /** @implements {import('@strapi/strapi').Strapi} */ class Strapi { + // TODO put this in /docs/docs/API/Strapi + /* + What is opts? + opts is a JS Object + { + autoReload: true, + serveAdminPanel: true, + distDir: '', + appDir: '', + } + + autoReload: + 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: + Should the admin panel be loaded and serve as a FE + FE build wont be delivered if false + Is the content-manager controller loaded if false? + + * Behavior: + * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services) + * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code + * + * Default values: + * - If `appDir` is `undefined`, it'll be set to `process.cwd()` + * - If `distDir` is `undefined`, it'll be set to `appDir` + + */ constructor(opts = {}) { destroyOnSignal(this); @@ -80,6 +121,31 @@ class Strapi { // Load the app configuration from the dist directory const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts); + // TODO put this in /docs/docs/API/Strapi + /* + Where all registries are stored + Object + register(name, resolver): + Add an attribute 'name' to the container and assign 'resolver' + name: + String + resolver: + Can be any type. + If Function, call function at first get (link to get) occurrence + Parameters of the function: + { strapi: current Strapi instance } + args -> any + get(name, args): + Get the content of the mapped attribute 'name'. + name: + String + + args: + If resolver was a Function, send args to the resolver function on first used of get on this attribute + + extend(): + TODO + */ // Instantiate the Strapi container this.container = createContainer(this); @@ -100,23 +166,137 @@ class Strapi { this.container.register('sanitizers', sanitizersRegistry(this)); // Create a mapping of every useful directory (for the app, dist and static directories) + // TODO put this in /docs/docs/API/Strapi + /* + Javascript Object + Stored paths of file system + + dist -> Link to StrapiPathObject + Builded folder + app -> Link to StrapiPathObject + Source folder + StrapiPathObject: + root: + Root path to (app|dist) + src: + Source root path to project files + api: + Path to the folder where user API files are stored (content-types, controllers, services, routes, etc..) + components: + Path to the folder where the Strapi user components are stored + policies: + Path to the folder where the Strapi user policies are stored + Function that check state of the data and prevent access to the API if falsy returned + middlewares: + Path to the folder where the Strapi user middleware are stored + Function that wrap around a route + config: + Path to the folder containing user config files + static: + Define path to directories involving client display + public: + Path to the folder to serve publicly (like files, images, etc..) + */ this.dirs = utils.getDirs(rootDirs, { strapi: this }); // Strapi state management variables + // TODO put this in /docs/docs/API/Strapi + /* + Boolean + false if there is still something to load (registers / bootstrap) + true if everything have been loaded + */ this.isLoaded = false; + // TODO put this in /docs/docs/API/Strapi + /* + function to reload the app + + To define + */ this.reload = this.reload(); // Instantiate the Koa app & the HTTP server + // TODO put this in /docs/docs/API/Strapi + /* + Strapi server object + + Link to server/index.js + */ this.server = createServer(this); // Strapi utils instanciation + // TODO put this in /docs/docs/API/Strapi + /* + Wrapper around fs module + writeAppFile(optPath, data): deprecated + writePluginFile(plugin, optPath, data): deprecated + removeAppFile(optPath): deprecated + appendFile(optPath, data): + normalize path (root dir) + fs.appendFileSync + */ this.fs = createStrapiFs(this); + + // TODO put this in /docs/docs/API/Strapi + /* + eventHub instance of EventEmitter = require('events'); + Link to nodejs events doc + */ this.eventHub = createEventHub(); + + // TODO put this in /docs/docs/API/Strapi + /** + * Object containing predefined logger functions + * Logs for Strapi startup + * + * logStats() + * Display stats about Strapi instance + * TODO list stats + * logFirstStartupMessage() + * Display the first startup message (asking to create an administrator) + * logDefaultStartupMessage() + * Display startup message + * logStartupMessage({ isInitialized } = {}) + * Call either logFirstStartupMessage or logDefaultStartupMessage depending on ENV_VAR STRAPI_HIDE_STARTUP_MESSAGE + */ this.startupLogger = createStartupLogger(this); + + // TODO put this in /docs/docs/API/Strapi + /** + * Logger + * + * winston -> link to winston doc + */ this.log = createLogger(this.config.get('logger', {})); + + // TODO put this in /docs/docs/API/Strapi + /** + * CRON module that use node-schedule + * + * TODO add every method + */ this.cron = createCronService(); + // TODO put this in /docs/docs/API/Strapi + /** + * Service used to send statistical data to Amplitude + */ this.telemetry = createTelemetry(this); + + // TODO put this in /docs/docs/API/Strapi + /** + * TODO ask JS | Alex + * Wrapper around async_hooks AsyncLocalStorage + */ this.requestContext = requestContext; + + // TODO put this in /docs/docs/API/Strapi + /** + * Object + * register(customField): + * Add a new custom field to the Strapi instance + * + * customField: + * TODO describe custom field + */ this.customFields = createCustomFields(this); createUpdateNotifier(this).notify(); @@ -130,6 +310,32 @@ class Strapi { }); } + // TODO put this in /docs/docs/API/Strapi + /* + config attribute (JS Object) + Describe all possibilities inside Strapi config + + launchedAt (Number, Date.now() by default): + Date in milliseconds when the server has started + + serveAdminPanel (boolean, true by default) -> link to opts.serveAdminPanel + autoReload (boolean, false by default) -> link to opts.autoReload + environment (string): + process.env.NODE_ENV + uuid (optional): + uuid describe in the project's package.json + Generated automatically (used by Amplitude) by strapi project generator. Used to identify the project (for stats purposes). + packageJsonStrapi: + strapi object can contain any attribute to describe the Strapi project + uuid is omitted in this config attribute + + telemetryDisabled (boolean, undefined): + If true, disable the telemetry for the app (connected to Amplitude) + + TODO: find where this config is used and list all possible attributes + info: + Package.json + strapi version + */ get config() { return this.container.get('config'); } diff --git a/packages/core/strapi/lib/services/server/index.js b/packages/core/strapi/lib/services/server/index.js index 217cb2381b..e220912863 100644 --- a/packages/core/strapi/lib/services/server/index.js +++ b/packages/core/strapi/lib/services/server/index.js @@ -54,6 +54,32 @@ const createServer = (strapi) => { mounted: false, }; + /* + Strapi server object + + app: + Koa server instance -> Link to Koa doc + router: + Koa router -> Link to @koa/router doc + httpServer: + Http server -> Link to http doc + api(name): + Getter for apis available in Strapi + 'content-api': + Used by users + TODO + admin: + Used by admin panel + TODO + use(...args): + routes(routes): + mount(): + async initRouting(): + async initMiddleware(): + listRoutes(): + listen(...args): + async destroy(): + */ return { app, router, diff --git a/packages/core/strapi/lib/utils/update-notifier/index.js b/packages/core/strapi/lib/utils/update-notifier/index.js index 08d336adc0..c1822a4ef3 100644 --- a/packages/core/strapi/lib/utils/update-notifier/index.js +++ b/packages/core/strapi/lib/utils/update-notifier/index.js @@ -31,6 +31,16 @@ Check out the new releases at: ${releaseLink} `.trim(); }; +/** + * Utility that record if the user is using the last Strapi version + * Store information in .strapi-updater.json file + * + * JS Object + * notify(): + * check if notification interval have been reach. if so, display a message in the console + * default interval : 1 week + * Check every day at max + */ const createUpdateNotifier = (strapi) => { let config = null; From 11028695754a1d921bdb0f3d253a4df74b52b311 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Thu, 2 Feb 2023 12:23:53 +0100 Subject: [PATCH 03/36] chore(api-docs): update structure example --- docs/docs/api/structure-example.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md index 4d87780a8e..99a362c761 100644 --- a/docs/docs/api/structure-example.md +++ b/docs/docs/api/structure-example.md @@ -6,13 +6,17 @@ tags: - public - global -toc_min_heading_level: 1 +toc_min_heading_level: 2 toc_max_heading_level: 5 --- # Name of Module -> Current state: Stable | Legacy | Deprecated +:::info + +Current state: **Stable** | **Legacy** | **Deprecated** + +::: _**Stable** - can be use as is_ @@ -38,9 +42,9 @@ const myClass = new Class(); ### `class.method(param1, param2)` -- `param1`: \ (can be linked to other API doc page). -- `param2`: \ - - `options1`: \ +- `param1`: < String > (can be linked to other API doc page). +- `param2`: < Object > + - `options1`: < Number > The `class.method()` method display the `param1` and then skip `param2` lines. @@ -63,9 +67,9 @@ for (const text of textLines) { ## Function: `name_of_the_function(param1, param2)` -- `param1`: \ (can be linked to other API doc page) -- `param2`: \ - - `options1`: \ +- `param1`: < String > (can be linked to other API doc page) +- `param2`: < Object > + - `options1`: < Number > The `name_of_the_function()` method display the `param1` and then skip `param2` lines. From 59bc546ec76ea44e164b7c7125e15dc62fbb3e14 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 14:53:11 +0100 Subject: [PATCH 04/36] chore(api-ref): add documentation on strapi and container --- .eslintrc.docs.js | 9 +++ docs/docs/api/Strapi.mdx | 50 +++++++++++++++ docs/docs/api/components/type.jsx | 13 ++++ docs/docs/api/container.mdx | 99 ++++++++++++++++++++++++++++++ docs/docs/api/index.md | 1 - docs/docs/api/structure-example.md | 14 +++-- 6 files changed, 179 insertions(+), 7 deletions(-) create mode 100644 .eslintrc.docs.js create mode 100644 docs/docs/api/Strapi.mdx create mode 100644 docs/docs/api/components/type.jsx create mode 100644 docs/docs/api/container.mdx delete mode 100644 docs/docs/api/index.md diff --git a/.eslintrc.docs.js b/.eslintrc.docs.js new file mode 100644 index 0000000000..11a4680ce0 --- /dev/null +++ b/.eslintrc.docs.js @@ -0,0 +1,9 @@ +module.exports = { + parserOptions: { + sourceType: 'module', + }, + plugins: ['react'], + rules: { + 'react/prop-types': 0, + }, +}; diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx new file mode 100644 index 0000000000..d598fe0147 --- /dev/null +++ b/docs/docs/api/Strapi.mdx @@ -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`: Object Options that can be used on Strapi startup + - `autoReload`: Boolean **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`: Boolean **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`: String **Default:** `process.cwd()` + - The directory relative or absolute path where Strapi will write every file (schemas, generated APIs, controllers or services) + - `distDir`: String **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. diff --git a/docs/docs/api/components/type.jsx b/docs/docs/api/components/type.jsx new file mode 100644 index 0000000000..e1f2c5e7b6 --- /dev/null +++ b/docs/docs/api/components/type.jsx @@ -0,0 +1,13 @@ +import React from 'react'; + +export default function Type({ children }) { + return ( + + <{children}> + + ); +} diff --git a/docs/docs/api/container.mdx b/docs/docs/api/container.mdx new file mode 100644 index 0000000000..b42c0012ae --- /dev/null +++ b/docs/docs/api/container.mdx @@ -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`: Strapi [See Strapi class documentation](Strapi.mdx) +- Returns: Container + +```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`: String UID of the content +- `args`: Any 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`: String UID of the content +- `resolver`: Function | Any + - 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`: { Strapi } [See Strapi class documentation](Strapi.mdx) + - `args`: Any 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 \ No newline at end of file diff --git a/docs/docs/api/index.md b/docs/docs/api/index.md deleted file mode 100644 index 593279293f..0000000000 --- a/docs/docs/api/index.md +++ /dev/null @@ -1 +0,0 @@ -# API diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md index 99a362c761..6547cbfc5a 100644 --- a/docs/docs/api/structure-example.md +++ b/docs/docs/api/structure-example.md @@ -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`: < String > (can be linked to other API doc page). -- `param2`: < Object > - - `options1`: < Number > +- `param1`: String (can be linked to other API doc page). +- `param2`: Object + - `options1`: Number 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`: < String > (can be linked to other API doc page) -- `param2`: < Object > - - `options1`: < Number > +- `param1`: String (can be linked to other API doc page) +- `param2`: Object + - `options1`: Number The `name_of_the_function()` method display the `param1` and then skip `param2` lines. From 05c0c1cad7aabe52361d2685e390cc9dd6491c1b Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 15:11:30 +0100 Subject: [PATCH 05/36] chore(docs): add container link to Strapi class --- docs/docs/api/Strapi.mdx | 3 +++ docs/docs/api/container.mdx | 43 +++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index d598fe0147..796232197c 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -48,3 +48,6 @@ const strapiInstance = new Strapi(); ### `strapi.container` This is where all registries are stored. + +See [Container](./container). + diff --git a/docs/docs/api/container.mdx b/docs/docs/api/container.mdx index b42c0012ae..86cb474af2 100644 --- a/docs/docs/api/container.mdx +++ b/docs/docs/api/container.mdx @@ -38,6 +38,26 @@ container.register('config', { const dbConfig = container.get('config').get('database'); ``` +### `container.register(name, resolver)` + +- `name`: String UID of the content +- `resolver`: Function | Any + - 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`: { Strapi } [See Strapi class documentation](Strapi.mdx) + - `args`: Any 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', ({ strapi }, args) => {}); +// or +container.register('services', {}); +``` + ### `container.get(name, args)` - `name`: String UID of the content @@ -56,6 +76,8 @@ const config = container.get('config'); ⚠️ 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`. +Please pay attention that the resolver result value isn't awaited. So if resolver returns a promise, the value stored will be a promise. + ```javascript const container = createContainer(strapi); @@ -73,27 +95,6 @@ container.get('boolean'); container.get('boolean', false); // true ``` - -### `container.register(name, resolver)` - -- `name`: String UID of the content -- `resolver`: Function | Any - - 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`: { Strapi } [See Strapi class documentation](Strapi.mdx) - - `args`: Any 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 \ No newline at end of file From 0134bcb0543b7c0670739c4b16c4b77ee746a74c Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 17:25:47 +0100 Subject: [PATCH 06/36] chore(docs): clean some js doc --- packages/core/strapi/lib/Strapi.js | 66 ------------------------------ 1 file changed, 66 deletions(-) diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index e943edd512..38c77f0615 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -70,49 +70,8 @@ const resolveWorkingDirectories = (opts) => { return { app: appDir, dist: distDir }; }; -// TODO put this in /docs/docs/API/Strapi -/* - -The Strapi class is the main class of a Strapi project - -The instance of Strapi class is used to manipulate everything related to strapi content management system. - -> Example - - - */ /** @implements {import('@strapi/strapi').Strapi} */ class Strapi { - // TODO put this in /docs/docs/API/Strapi - /* - What is opts? - opts is a JS Object - { - autoReload: true, - serveAdminPanel: true, - distDir: '', - appDir: '', - } - - autoReload: - 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: - Should the admin panel be loaded and serve as a FE - FE build wont be delivered if false - Is the content-manager controller loaded if false? - - * Behavior: - * - `appDir` is the directory where Strapi will write every file (schemas, generated APIs, controllers or services) - * - `distDir` is the directory where Strapi will read configurations, schemas and any compiled code - * - * Default values: - * - If `appDir` is `undefined`, it'll be set to `process.cwd()` - * - If `distDir` is `undefined`, it'll be set to `appDir` - - */ constructor(opts = {}) { destroyOnSignal(this); @@ -121,31 +80,6 @@ class Strapi { // Load the app configuration from the dist directory const appConfig = loadConfiguration({ appDir: rootDirs.app, distDir: rootDirs.dist }, opts); - // TODO put this in /docs/docs/API/Strapi - /* - Where all registries are stored - Object - register(name, resolver): - Add an attribute 'name' to the container and assign 'resolver' - name: - String - resolver: - Can be any type. - If Function, call function at first get (link to get) occurrence - Parameters of the function: - { strapi: current Strapi instance } - args -> any - get(name, args): - Get the content of the mapped attribute 'name'. - name: - String - - args: - If resolver was a Function, send args to the resolver function on first used of get on this attribute - - extend(): - TODO - */ // Instantiate the Strapi container this.container = createContainer(this); From 0fea2f6c5677a175f4f0e58cd31b3f3e743c10e0 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 17:42:21 +0100 Subject: [PATCH 07/36] chore(docs): Strapi Class - dirs --- docs/docs/api/Strapi.mdx | 24 ++++++++++++++++++++++- docs/docs/api/structure-example.md | 2 +- packages/core/strapi/lib/Strapi.js | 31 ------------------------------ 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 796232197c..c2c26420f4 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -7,7 +7,7 @@ tags: - global toc_min_heading_level: 2 -toc_max_heading_level: 5 +toc_max_heading_level: 3 --- import Type from '@site/docs/api/components/Type'; @@ -51,3 +51,25 @@ This is where all registries are stored. See [Container](./container). +### `strapi.dirs` + +Stored paths of file system. + +- `dirs.dist`: [StrapiPathObject](#strapipathobject) + - Build folder +- `dirs.app`: [StrapiPathObject](#strapipathobject) + - Sources folder +- `dirs.static`: Object Define path to directories involving web client display + - `public`: String Path to the folder to serve publicly (like files, images, etc..) + +#### StrapiPathObject +- `root`: String Root path +- `src`: String Sources route path to project files +- `api`: String Path to the folder containing project developers' API files (content-types, controllers, services, routes, etc..) +- `components`: String Path to the folder containing project developers' components +- `policies`: String Path to the folder where the Strapi project developers' policies are stored + - A set of functions that check the state of the data and prevent the access to the API accordingly +- `middlewares`: String Path to the folder where the Strapi project developers' middlewares are stored + - A set of function that wrap around routes and requests +- `config`: String Path to the folder containing project developers' config files + diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md index 6547cbfc5a..e52b602da5 100644 --- a/docs/docs/api/structure-example.md +++ b/docs/docs/api/structure-example.md @@ -7,7 +7,7 @@ tags: - global toc_min_heading_level: 2 -toc_max_heading_level: 5 +toc_max_heading_level: 3 --- import Type from '@site/docs/api/components/Type'; diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 38c77f0615..e622a7db5c 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -100,37 +100,6 @@ class Strapi { this.container.register('sanitizers', sanitizersRegistry(this)); // Create a mapping of every useful directory (for the app, dist and static directories) - // TODO put this in /docs/docs/API/Strapi - /* - Javascript Object - Stored paths of file system - - dist -> Link to StrapiPathObject - Builded folder - app -> Link to StrapiPathObject - Source folder - StrapiPathObject: - root: - Root path to (app|dist) - src: - Source root path to project files - api: - Path to the folder where user API files are stored (content-types, controllers, services, routes, etc..) - components: - Path to the folder where the Strapi user components are stored - policies: - Path to the folder where the Strapi user policies are stored - Function that check state of the data and prevent access to the API if falsy returned - middlewares: - Path to the folder where the Strapi user middleware are stored - Function that wrap around a route - config: - Path to the folder containing user config files - static: - Define path to directories involving client display - public: - Path to the folder to serve publicly (like files, images, etc..) - */ this.dirs = utils.getDirs(rootDirs, { strapi: this }); // Strapi state management variables From 634845081c0db06cce5f825286b4db660c89479f Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 17:46:52 +0100 Subject: [PATCH 08/36] chore(docs): Strapi Class - isLoaded --- docs/docs/api/Strapi.mdx | 7 +++++++ packages/core/strapi/lib/Strapi.js | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index c2c26420f4..6f8c677fdd 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -73,3 +73,10 @@ Stored paths of file system. - A set of function that wrap around routes and requests - `config`: String Path to the folder containing project developers' config files +### `strapi.isLoaded` + +Boolean + +- `true`: Everything have been loaded +- `false`: There is something loading + diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index e622a7db5c..303808ce30 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -103,12 +103,6 @@ class Strapi { this.dirs = utils.getDirs(rootDirs, { strapi: this }); // Strapi state management variables - // TODO put this in /docs/docs/API/Strapi - /* - Boolean - false if there is still something to load (registers / bootstrap) - true if everything have been loaded - */ this.isLoaded = false; // TODO put this in /docs/docs/API/Strapi /* From 46cb652ba7b5ef78ea004a070c4ee5b8ba0c0ffe Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 17:48:32 +0100 Subject: [PATCH 09/36] chore(docs): Strapi Class - reload --- docs/docs/api/Strapi.mdx | 6 ++++++ packages/core/strapi/lib/Strapi.js | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 6f8c677fdd..9723c56ad2 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -80,3 +80,9 @@ Stored paths of file system. - `true`: Everything have been loaded - `false`: There is something loading +### `strapi.reload` + +Function to reload the app. + +This function defines itself at the construction of the Strapi class. + diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 303808ce30..5e66719f42 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -104,12 +104,6 @@ class Strapi { // Strapi state management variables this.isLoaded = false; - // TODO put this in /docs/docs/API/Strapi - /* - function to reload the app - - To define - */ this.reload = this.reload(); // Instantiate the Koa app & the HTTP server From acb2f190b0938a8e5a560a18516d2b8f30401b11 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 8 Feb 2023 18:13:54 +0100 Subject: [PATCH 10/36] chore(docs): StrapiServer module --- docs/docs/api/Strapi.mdx | 19 +++++++++++--- docs/docs/api/strapi-server.mdx | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 docs/docs/api/strapi-server.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 9723c56ad2..dcf6d0c13c 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -46,12 +46,14 @@ const strapiInstance = new Strapi(); ``` ### `strapi.container` +- [Container](./container) This is where all registries are stored. See [Container](./container). ### `strapi.dirs` +- Object Stored paths of file system. @@ -63,6 +65,10 @@ Stored paths of file system. - `public`: String Path to the folder to serve publicly (like files, images, etc..) #### StrapiPathObject +- Object + +A set of path to specific Strapi project parts. + - `root`: String Root path - `src`: String Sources route path to project files - `api`: String Path to the folder containing project developers' API files (content-types, controllers, services, routes, etc..) @@ -74,15 +80,20 @@ Stored paths of file system. - `config`: String Path to the folder containing project developers' config files ### `strapi.isLoaded` +- Boolean -Boolean - -- `true`: Everything have been loaded -- `false`: There is something loading + - `true`: Everything have been loaded + - `false`: There is something loading ### `strapi.reload` +- Function Function to reload the app. This function defines itself at the construction of the Strapi class. +### `strapi.server` +- [StrapiServer](./strapi-server) + +Strapi server object. + diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx new file mode 100644 index 0000000000..8c123cd902 --- /dev/null +++ b/docs/docs/api/strapi-server.mdx @@ -0,0 +1,46 @@ +--- +title: Strapi server +slug: /api/strapi-server +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 5 +--- +import Type from '@site/docs/api/components/Type'; + +# Strapi Server + +:::info + +Current state: **Stable** + +::: + +The Strapi server module permits to generate a Strapi http server. + +## Module: Strapi server + +### `createServer(strapi)` + +- `strapi`: [Strapi](Strapi) +- Returns: StrapiServer + +```javascript +const server = createServer(strapi); + +server.listRoutes(); +``` + +### `StrapiServer.app` +### `StrapiServer.router` +### `StrapiServer.httpServer` +### `StrapiServer.api(name)` +### `StrapiServer.use(...args)` +### `StrapiServer.routes(routes)` +### `StrapiServer.mount()` +### `StrapiServer.initRouting()` +### `StrapiServer.initMiddlewares()` +### `StrapiServer.listRoutes()` +### `StrapiServer.listen(...args)` \ No newline at end of file From 2ec478af3c2d49917ae8256291e50837038fe87f Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 14 Feb 2023 18:18:25 +0100 Subject: [PATCH 11/36] docs(api): add doc for Strapi server --- docs/docs/api/api.mdx | 27 +++++++++++++++++++++++ docs/docs/api/strapi-server.mdx | 39 ++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 docs/docs/api/api.mdx diff --git a/docs/docs/api/api.mdx b/docs/docs/api/api.mdx new file mode 100644 index 0000000000..278e37892e --- /dev/null +++ b/docs/docs/api/api.mdx @@ -0,0 +1,27 @@ +--- +title: API +slug: /api/API +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# API + +:::info + +Current state: **Stable** + +::: + +The Strapi API module permits to generate a Strapi API object that wrap all the functionalities around Strapi endpoints + +## Module: API + +### `createAPI(strapi, opts)` + +// TODO \ No newline at end of file diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx index 8c123cd902..f79b4be202 100644 --- a/docs/docs/api/strapi-server.mdx +++ b/docs/docs/api/strapi-server.mdx @@ -34,13 +34,50 @@ server.listRoutes(); ``` ### `StrapiServer.app` + +[KoaJS](https://devdocs.io/koa/index) https://devdocs.io/koa/index + +Strapi projects are using KoaJS to run the NodeJS server. + ### `StrapiServer.router` + +[@koa/router](https://github.com/ZijianHe/koa-router#router-) https://github.com/ZijianHe/koa-router#router- + +Strapi projects are using a dependency of KoaJS called @koa/router. + ### `StrapiServer.httpServer` + +[http.Server](https://nodejs.org/docs/latest-v18.x/api/http.html) + +The Strapi's HTTP server. + ### `StrapiServer.api(name)` + +- `name`: String +- Returns: [StrapiAPIs](#strapiapis) + +Getter for apis available in Strapi + ### `StrapiServer.use(...args)` + +[KoaApp.use](https://devdocs.io/koa/index#appusefunction) https://devdocs.io/koa/index#appusefunction + +Shortcut for Koa `app.use(...args)` method. + ### `StrapiServer.routes(routes)` ### `StrapiServer.mount()` ### `StrapiServer.initRouting()` ### `StrapiServer.initMiddlewares()` ### `StrapiServer.listRoutes()` -### `StrapiServer.listen(...args)` \ No newline at end of file +### `StrapiServer.listen(...args)` +### `StrapiServer.destroy()` + +### `StrapiAPIs` +Object + +- `content-api`: [API](API) + - API used by external requesters +- `admin`: [API](API) + - API used by admin panel + +Strapi APIs is a map of all APIs available inside the Strapi project. \ No newline at end of file From b45459020f8e5cc9b0e28b32d24bcb007740cd60 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 15 Feb 2023 10:04:50 +0100 Subject: [PATCH 12/36] docs(api-ref): add strapi fs --- docs/docs/api/Strapi.mdx | 4 +++ docs/docs/api/strapi-fs.mdx | 42 ++++++++++++++++++++++++++++++ docs/docs/api/strapi-server.mdx | 10 +++---- packages/core/strapi/lib/Strapi.js | 15 ----------- 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 docs/docs/api/strapi-fs.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index dcf6d0c13c..e734bd161f 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -97,3 +97,7 @@ This function defines itself at the construction of the Strapi class. Strapi server object. +### `strapi.fs` +- [StrapiFS](StrapiFS) + +Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.html). \ No newline at end of file diff --git a/docs/docs/api/strapi-fs.mdx b/docs/docs/api/strapi-fs.mdx new file mode 100644 index 0000000000..0f6fb27fb1 --- /dev/null +++ b/docs/docs/api/strapi-fs.mdx @@ -0,0 +1,42 @@ +--- +title: StrapiFS +slug: /api/StrapiFS +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# Strapi File System + +:::info + +Current state: **Stable** + +::: + +The Strapi FS module is a wrapper around FS NodeJS module to manipulate local files. + +## Module: StrapiFS + +### `createStrapiFs(strapi)` + +### `strapiFs.writeAppFile(optPath, data)` +:::caution +Deprecated +::: + +### `strapiFs.writePluginFile(plugin, optPath, data)` +:::caution +Deprecated +::: + +### `strapiFs.removeAppFile(optPath)` +:::caution +Deprecated +::: + +### `strapiFs.appendFile(optPath, data)` \ No newline at end of file diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx index f79b4be202..b64e0d86f4 100644 --- a/docs/docs/api/strapi-server.mdx +++ b/docs/docs/api/strapi-server.mdx @@ -35,19 +35,19 @@ server.listRoutes(); ### `StrapiServer.app` -[KoaJS](https://devdocs.io/koa/index) https://devdocs.io/koa/index +- [KoaJS](https://devdocs.io/koa/index) Strapi projects are using KoaJS to run the NodeJS server. ### `StrapiServer.router` -[@koa/router](https://github.com/ZijianHe/koa-router#router-) https://github.com/ZijianHe/koa-router#router- +- [@koa/router](https://github.com/ZijianHe/koa-router#router-) Strapi projects are using a dependency of KoaJS called @koa/router. ### `StrapiServer.httpServer` -[http.Server](https://nodejs.org/docs/latest-v18.x/api/http.html) +- [http.Server](https://nodejs.org/docs/latest-v18.x/api/http.html) The Strapi's HTTP server. @@ -60,7 +60,7 @@ Getter for apis available in Strapi ### `StrapiServer.use(...args)` -[KoaApp.use](https://devdocs.io/koa/index#appusefunction) https://devdocs.io/koa/index#appusefunction +- [KoaApp.use](https://devdocs.io/koa/index#appusefunction) Shortcut for Koa `app.use(...args)` method. @@ -73,7 +73,7 @@ Shortcut for Koa `app.use(...args)` method. ### `StrapiServer.destroy()` ### `StrapiAPIs` -Object +- Object - `content-api`: [API](API) - API used by external requesters diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 5e66719f42..8af7ebf16d 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -107,24 +107,9 @@ class Strapi { this.reload = this.reload(); // Instantiate the Koa app & the HTTP server - // TODO put this in /docs/docs/API/Strapi - /* - Strapi server object - - Link to server/index.js - */ this.server = createServer(this); // Strapi utils instanciation - // TODO put this in /docs/docs/API/Strapi - /* - Wrapper around fs module - writeAppFile(optPath, data): deprecated - writePluginFile(plugin, optPath, data): deprecated - removeAppFile(optPath): deprecated - appendFile(optPath, data): - normalize path (root dir) + fs.appendFileSync - */ this.fs = createStrapiFs(this); // TODO put this in /docs/docs/API/Strapi From a2e8c9a2f24fc32c423c683a33d3b98d461efe93 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 15 Feb 2023 10:09:00 +0100 Subject: [PATCH 13/36] docs(api-ref): adding event hub doc --- docs/docs/api/Strapi.mdx | 8 +++++++- docs/docs/api/event-hub.mdx | 27 +++++++++++++++++++++++++++ packages/core/strapi/lib/Strapi.js | 5 ----- 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 docs/docs/api/event-hub.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index e734bd161f..b26fc98659 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -100,4 +100,10 @@ Strapi server object. ### `strapi.fs` - [StrapiFS](StrapiFS) -Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.html). \ No newline at end of file +Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.html). + +### `strapi.eventHub` +- [EventHub](EventHub) + +Module to manipulate events around Strapi project. It is an instance of [EventEmitter](https://nodejs.org/docs/latest-v18.x/api/events.html#class-eventemitter) from NodeJS. + diff --git a/docs/docs/api/event-hub.mdx b/docs/docs/api/event-hub.mdx new file mode 100644 index 0000000000..1e21fe5de4 --- /dev/null +++ b/docs/docs/api/event-hub.mdx @@ -0,0 +1,27 @@ +--- +title: EventHub +slug: /api/EventHub +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# Strapi Event Hub + +:::info + +Current state: **Stable** + +::: + +Strapi Event Hub module - description to be done + +## Module: EventHub + +### `createEventHub()` + +//TODO \ No newline at end of file diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 8af7ebf16d..86838dc293 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -112,11 +112,6 @@ class Strapi { // Strapi utils instanciation this.fs = createStrapiFs(this); - // TODO put this in /docs/docs/API/Strapi - /* - eventHub instance of EventEmitter = require('events'); - Link to nodejs events doc - */ this.eventHub = createEventHub(); // TODO put this in /docs/docs/API/Strapi From 41423f05897bfece64a8320b6fdae46fa447e1d5 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Wed, 15 Feb 2023 10:14:43 +0100 Subject: [PATCH 14/36] docs(api-ref): adding wip information on pages --- docs/docs/api/api.mdx | 2 +- docs/docs/api/event-hub.mdx | 2 +- docs/docs/api/strapi-fs.mdx | 2 +- docs/docs/api/strapi-server.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs/api/api.mdx b/docs/docs/api/api.mdx index 278e37892e..4ba62e39de 100644 --- a/docs/docs/api/api.mdx +++ b/docs/docs/api/api.mdx @@ -1,5 +1,5 @@ --- -title: API +title: API (WIP) slug: /api/API tags: - module diff --git a/docs/docs/api/event-hub.mdx b/docs/docs/api/event-hub.mdx index 1e21fe5de4..de8711460b 100644 --- a/docs/docs/api/event-hub.mdx +++ b/docs/docs/api/event-hub.mdx @@ -1,5 +1,5 @@ --- -title: EventHub +title: EventHub (WIP) slug: /api/EventHub tags: - module diff --git a/docs/docs/api/strapi-fs.mdx b/docs/docs/api/strapi-fs.mdx index 0f6fb27fb1..a28b636ddd 100644 --- a/docs/docs/api/strapi-fs.mdx +++ b/docs/docs/api/strapi-fs.mdx @@ -1,5 +1,5 @@ --- -title: StrapiFS +title: StrapiFS (WIP) slug: /api/StrapiFS tags: - module diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx index b64e0d86f4..9655589a93 100644 --- a/docs/docs/api/strapi-server.mdx +++ b/docs/docs/api/strapi-server.mdx @@ -1,5 +1,5 @@ --- -title: Strapi server +title: Strapi server (WIP) slug: /api/strapi-server tags: - module From 6b1448c124779d741ecac985c9e2b33bceb113d7 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Mon, 3 Apr 2023 10:41:29 +0200 Subject: [PATCH 15/36] docs(api-ref): add startup logger documentation --- docs/docs/api/Strapi.mdx | 5 +++ docs/docs/api/startup-logger.mdx | 72 ++++++++++++++++++++++++++++++ packages/core/strapi/lib/Strapi.js | 15 ------- 3 files changed, 77 insertions(+), 15 deletions(-) create mode 100644 docs/docs/api/startup-logger.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index b26fc98659..67d49aa8e0 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -107,3 +107,8 @@ Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.ht Module to manipulate events around Strapi project. It is an instance of [EventEmitter](https://nodejs.org/docs/latest-v18.x/api/events.html#class-eventemitter) from NodeJS. +### `strapi.startupLogger` +- [StartupLogger](StartupLogger) + +Object containing predefined logger functions. Used for Strapi startup. (do not use as a logger elsewhere) + diff --git a/docs/docs/api/startup-logger.mdx b/docs/docs/api/startup-logger.mdx new file mode 100644 index 0000000000..3d64158955 --- /dev/null +++ b/docs/docs/api/startup-logger.mdx @@ -0,0 +1,72 @@ +--- +title: Startup Logger +slug: /api/StartupLogger +tags: +- module +- private + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# API + +:::info + +Current state: **Stable** + +::: + +This module is a simple logger for starting up Strapi with some useful information. + +## Module: Startup Logger + +### `logStats()` + +This log will display information about the instance of Strapi. The time launched, how many times it took and important configuration information. + +``` + Project information + +┌────────────────────┬──────────────────────────────────────────────────┐ +│ Time │ Wed Jan 01 2000 00:00:01 GMT+0200 (Central Euro… │ +│ Launched in │ 2000 ms │ +│ Environment │ development │ +│ Process PID │ 42 │ +│ Version │ 4.9.0 (node v18.12.1) │ +│ Edition │ Enterprise │ +│ Database │ postgres │ +└────────────────────┴──────────────────────────────────────────────────┘ +``` + +### `logFirstStartupMessage()` + +This log will display the first time Strapi project is launched. It will ask the user to create its first admin user in the admin panel. + +### `logDefaultStartupMessage()` + +Default message to display when the Strapi server is started. + +``` + Actions available + +Welcome back! +To manage your project 🚀, go to the administration panel at: +http://localhost:1337/admin + +To access the server ⚡️, go to: +http://localhost:1337 +``` + +### `logStartupMessage({ isInitialized })` + +- `isInitialized`: Boolean Has the Strapi project already been initialized? + +Will display the correct start-up message according to the specified boolean. + +:::note + +Can be disabled by setting `STRAPI_HIDE_STARTUP_MESSAGE` to `true`. + +::: diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 86838dc293..0dacf0efec 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -114,21 +114,6 @@ class Strapi { this.eventHub = createEventHub(); - // TODO put this in /docs/docs/API/Strapi - /** - * Object containing predefined logger functions - * Logs for Strapi startup - * - * logStats() - * Display stats about Strapi instance - * TODO list stats - * logFirstStartupMessage() - * Display the first startup message (asking to create an administrator) - * logDefaultStartupMessage() - * Display startup message - * logStartupMessage({ isInitialized } = {}) - * Call either logFirstStartupMessage or logDefaultStartupMessage depending on ENV_VAR STRAPI_HIDE_STARTUP_MESSAGE - */ this.startupLogger = createStartupLogger(this); // TODO put this in /docs/docs/API/Strapi From 0f9506877b1f302240e9c5f57c37b3c6c798f278 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Mon, 3 Apr 2023 11:34:52 +0200 Subject: [PATCH 16/36] docs(api-ref): add logger documentation --- docs/docs/api/Strapi.mdx | 30 ++++++++++++++++++++++++++++++ packages/core/strapi/lib/Strapi.js | 6 ------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 67d49aa8e0..f267fd98d1 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -112,3 +112,33 @@ Module to manipulate events around Strapi project. It is an instance of [EventEm Object containing predefined logger functions. Used for Strapi startup. (do not use as a logger elsewhere) +### `strapi.log` +- [Winston](https://github.com/winstonjs/winston#creating-your-own-logger) + +A logger provided by Strapi that uses the Winston logging library. It is the result of calling the `winston.createLogger()` function with the configuration defined by the user of the Strapi application. + +The logger provides various methods for logging messages at different levels of severity, including error, warn, info, verbose, debug, and silly. The logging level can be set via the configuration to control which messages are logged. + +#### Examples +```javascript +// Log an error message +strapi.log.error('Failed to start server', { error: err }); + +// Log a warning message +strapi.log.warn('Server is running in development mode'); + +// Log an informational message +strapi.log.info(`Server started on port ${PORT}`); + +// Log a verbose message +strapi.log.verbose('Application state', { user: currentUser }); + +// Log a debug message +strapi.log.debug('API request received', { method: req.method, path: req.path }); + +// Log a silly message +strapi.log.silly('Entered loop', { count: i }); +``` +In these examples, we are logging messages at different levels of severity, including error, warn, info, verbose, debug, and silly. We are also passing in metadata as an object in the second parameter of each logging method. + +The messages logged by strapi.log will be output according to the logging configuration set by the user of the Strapi application. This configuration determines which messages are logged and where they are logged (e.g. console, file, etc.). \ No newline at end of file diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 0dacf0efec..6ff738a32f 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -116,12 +116,6 @@ class Strapi { this.startupLogger = createStartupLogger(this); - // TODO put this in /docs/docs/API/Strapi - /** - * Logger - * - * winston -> link to winston doc - */ this.log = createLogger(this.config.get('logger', {})); // TODO put this in /docs/docs/API/Strapi From e477b521961b7a1e22557d036df771feb68232f0 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Mon, 3 Apr 2023 11:35:08 +0200 Subject: [PATCH 17/36] docs(api-ref): enhance event hub documentation on Strapi class --- docs/docs/api/Strapi.mdx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index f267fd98d1..b08f94a0f9 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -105,7 +105,25 @@ Wrapper around [FS NodeJS module](https://nodejs.org/docs/latest-v18.x/api/fs.ht ### `strapi.eventHub` - [EventHub](EventHub) -Module to manipulate events around Strapi project. It is an instance of [EventEmitter](https://nodejs.org/docs/latest-v18.x/api/events.html#class-eventemitter) from NodeJS. +The `strapi.eventHub` object is used to manipulate events within a Strapi project. It is an instance of the built-in EventEmitter class from Node.js, which provides a simple way to emit and listen for events. + +The `strapi.eventHub` object is created using the `createEventHub()` function in the [EventHub](EventHub) module of the Strapi core. This function returns a new instance of the EventHub class, which extends the EventEmitter class and adds some additional functionality specific to Strapi. + + +#### Examples: + +```javascript +// Listen for a 'user.updated' event and log the data +strapi.eventHub.on('user.updated', (data) => { +console.log(`User ${data.id} has been updated`); +}); + +// Emit a 'user.created' event with some data +strapi.eventHub.emit('user.created', { username: 'johndoe', email: 'johndoe@example.com' }); +``` +In this example, we are emitting a `user.created` event with some data attached to it, and then listening for a user.updated event and logging the data. These events can be used to trigger actions within the Strapi application or to communicate with external systems. + +For more information on how to use the EventEmitter class and its methods, see the [Node.js documentation](ttps://nodejs.org/docs/latest-v18.x/api/events.html#class-eventemitter). ### `strapi.startupLogger` - [StartupLogger](StartupLogger) From 1302eac88e0b9eb1b18ad64033e9fc1383f849e7 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Mon, 3 Apr 2023 12:25:24 +0200 Subject: [PATCH 18/36] docs(api-ref): add cron service documentation --- docs/docs/api/Strapi.mdx | 8 +- docs/docs/api/cron.mdx | 193 +++++++++++++++++++++++++++++ packages/core/strapi/lib/Strapi.js | 6 - 3 files changed, 200 insertions(+), 7 deletions(-) create mode 100644 docs/docs/api/cron.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index b08f94a0f9..db47b4ce4b 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -159,4 +159,10 @@ strapi.log.silly('Entered loop', { count: i }); ``` In these examples, we are logging messages at different levels of severity, including error, warn, info, verbose, debug, and silly. We are also passing in metadata as an object in the second parameter of each logging method. -The messages logged by strapi.log will be output according to the logging configuration set by the user of the Strapi application. This configuration determines which messages are logged and where they are logged (e.g. console, file, etc.). \ No newline at end of file +The messages logged by strapi.log will be output according to the logging configuration set by the user of the Strapi application. This configuration determines which messages are logged and where they are logged (e.g. console, file, etc.). + +### `strapi.cron` +- [CronService](Cron) + +Module to schedule cron jobs for Strapi project. It is an instance of a custom Cron object. + diff --git a/docs/docs/api/cron.mdx b/docs/docs/api/cron.mdx new file mode 100644 index 0000000000..0e0ce0b3a9 --- /dev/null +++ b/docs/docs/api/cron.mdx @@ -0,0 +1,193 @@ +--- +title: Cron Service +slug: /api/Cron +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# Cron + +:::info + +Current state: **Stable** + +::: + +The Strapi Cron Service provides a way to add, remove, start, and stop cron jobs in a Strapi application. + + +## Module: Cron Service + +### createCronService() + +The `createCronService()` function returns an object that provides methods to manage cron jobs. + +## Methods + +### `cron.add(tasks)` + +- `tasks`: Object +- Returns: `this` + +Adds one or more cron tasks to the service. + +- Each key of the `tasks` object is the name of the task. +- Each value of the `tasks` object can be either a function, or an object with two properties: `task` and `options`. +- If the value is a function, it is used as the task to be executed when the cron expression is met. +- If the value is an object, its `task` property is used as the task function, and its `options` property is used as the cron expression options. + +#### Example +```javascript +const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); + +const cron = createCronService(); + +const task = () => { + console.log('Task executed!'); +}; + +cron.add({ + myTask: { + task, + options: '*/5 * * * *', // Executes every 5 minutes. + }, +}); +``` + +### `cron.remove(name)` + +- `name`: String +- Returns: `this` + +Removes a cron task from the service. + +- The `name` parameter is the name of the task to remove. + +#### Example +```javascript +const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); + +const cron = createCronService(); + +const task = () => { + console.log('Task executed!'); +}; + +cron.add({ + myTask: { + task, + options: '*/5 * * * *', // Executes every 5 minutes. + }, +}); + +cron.remove('myTask'); +``` + +### `cron.start()` + +- Returns: `this` + +Starts the cron service. + +- Schedules all the cron jobs. + +#### Example +```javascript +const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); + +const cron = createCronService(); + +const task = () => { + console.log('Task executed!'); +}; + +cron.add({ + myTask: { + task, + options: '*/5 * * * *', // Executes every 5 minutes. + }, +}); + +cron.start(); +``` + +### `cron.stop()` + +- Returns: `this` + +Stops the cron service. + +- Cancels all the scheduled jobs. + +#### Example +```javascript +const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); + +const cron = createCronService(); + +const task = () => { + console.log('Task executed!'); +}; + +cron.add({ + myTask: { + task, + options: '*/5 * * * *', // Executes every 5 minutes. + }, +}); + +// Start the scheduled cron jobs +cron.start(); +// Stops the cron jobs +cron.stop(); +``` + +### `cron.destroy()` + +- Returns: `this` + +Destroys the cron service. + +- Calls the `stop()` method. +- Clears the list of cron jobs. + +#### Example +```javascript +const { createCronService } = require('packages/core/strapi/lib/services/cron.js'); + +const cron = createCronService(); + +const task = () => { + console.log('Task executed!'); +}; + +cron.add({ + myTask: { + task, + options: '*/5 * * * *', // Executes every 5 minutes. + }, +}); + +// Start the scheduled cron jobs +cron.start(); +// Stops the cron jobs and remove all scheduled tasks +cron.destroy(); +``` + +## Properties + +### `cron.jobs` +- Array + + - Object + + - `job`: [Job](https://github.com/node-schedule/node-schedule) - Job object by node-schedule + - `options`: String - String representing the recurrence of the job ( like '*/5 * * * *' ) + - `name`: String - The name of the task associated to the job + +An array of the cron jobs added to the service. diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 6ff738a32f..9bfbe5932e 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -118,12 +118,6 @@ class Strapi { this.log = createLogger(this.config.get('logger', {})); - // TODO put this in /docs/docs/API/Strapi - /** - * CRON module that use node-schedule - * - * TODO add every method - */ this.cron = createCronService(); // TODO put this in /docs/docs/API/Strapi /** From a8a52a3fad21333206880b3c948335b66fcd33e9 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Mon, 3 Apr 2023 14:38:08 +0200 Subject: [PATCH 19/36] docs(api-ref): add telemetry documentation --- docs/docs/api/Strapi.mdx | 6 +++ docs/docs/api/structure-example.md | 4 +- docs/docs/api/telemetry.mdx | 86 ++++++++++++++++++++++++++++++ packages/core/strapi/lib/Strapi.js | 2 +- 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 docs/docs/api/telemetry.mdx diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index db47b4ce4b..9111fa8575 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -166,3 +166,9 @@ The messages logged by strapi.log will be output according to the logging config Module to schedule cron jobs for Strapi project. It is an instance of a custom Cron object. +### `strapi.telemetry` +- [TelemetryService](Telemetry) + +The `strapi.telemetry` property provides access to the telemetry service instance. This service collects anonymous usage data about your Strapi application to help the Strapi team improve the product. + +By default, the telemetry service is enabled, but you can disable it by setting the telemetryDisabled property to true in your application's package.json file, or by setting the `STRAPI_TELEMETRY_DISABLED` environment variable to true. You can also disable telemetry programmatically by setting the isDisabled property of the `strapi.telemetry` instance to true. \ No newline at end of file diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md index e52b602da5..b6f29b075b 100644 --- a/docs/docs/api/structure-example.md +++ b/docs/docs/api/structure-example.md @@ -50,7 +50,7 @@ const myClass = new Class(); The `class.method()` method display the `param1` and then skip `param2` lines. -Example usage: +#### Examples ```javascript const { Class } = require('pathToClassFile'); @@ -75,7 +75,7 @@ for (const text of textLines) { The `name_of_the_function()` method display the `param1` and then skip `param2` lines. -Example usage: +#### Examples ```javascript const { name_of_the_function } = require('pathToFunctionFile'); diff --git a/docs/docs/api/telemetry.mdx b/docs/docs/api/telemetry.mdx new file mode 100644 index 0000000000..461de074e9 --- /dev/null +++ b/docs/docs/api/telemetry.mdx @@ -0,0 +1,86 @@ +--- +title: Telemetry Service +slug: /api/Telemetry +tags: +- module +- public + +toc_min_heading_level: 2 +toc_max_heading_level: 3 +--- +import Type from '@site/docs/api/components/Type'; + +# Telemetry + +:::info + +Current state: **Stable** + +::: + +The telemetry service is responsible for collecting and sending anonymous usage data to Strapi. This service is disabled by default, but can be enabled or disabled via configuration. + +## Usage Information +The collected usage data is used to help Strapi improve the product by identifying areas of improvement, tracking feature adoption, and measuring performance. You can learn more about the usage data that is collected by visiting the following link: + +https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html + +## Module: Telemetry Service + +### createTelemetryInstance() + +- strapi: [Strapi](Strapi) - A strapi instance. + +The `createTelemetryInstance()` function returns an instance of the Telemetry service. + +#### Examples + +```javascript +const createTelemetryInstance = require('path/to/telemetry'); + +const telemetry = createTelemetryInstance(strapi); +``` + +## Methods + +### `telemetry.register()` + +Registers the telemetry instance. + +#### Examples + +```javascript +telemetry.register(); +``` + +### `telemetry.bootstrap()` + +Bootstraps the telemetry instance. + +#### Examples + +```javascript +telemetry.bootstrap(); +``` + +### `telemetry.destroy()` + +Destroys the telemetry instance. + +#### Examples + +```javascript +telemetry.destroy(); +``` + +### `telemetry.send(event, payload)` +- event: String - The event to be sent. +- payload: Object - The payload to be sent with the event. + +Sends telemetry event with the given payload. + +#### Examples + +```javascript +telemetry.send('event_name', { key: 'value' }); +``` diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 9bfbe5932e..f26260827f 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -119,7 +119,7 @@ class Strapi { this.log = createLogger(this.config.get('logger', {})); this.cron = createCronService(); - // TODO put this in /docs/docs/API/Strapi + /** * Service used to send statistical data to Amplitude */ From 1b64353fc4a9e7028cf4650cad5689668640fd2d Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 10:13:23 +0200 Subject: [PATCH 20/36] docs(api-ref): add request context documentation --- docs/docs/api/Strapi.mdx | 12 +++++++++++- packages/core/strapi/lib/Strapi.js | 16 +--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 9111fa8575..1f598498ef 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -171,4 +171,14 @@ Module to schedule cron jobs for Strapi project. It is an instance of a custom C The `strapi.telemetry` property provides access to the telemetry service instance. This service collects anonymous usage data about your Strapi application to help the Strapi team improve the product. -By default, the telemetry service is enabled, but you can disable it by setting the telemetryDisabled property to true in your application's package.json file, or by setting the `STRAPI_TELEMETRY_DISABLED` environment variable to true. You can also disable telemetry programmatically by setting the isDisabled property of the `strapi.telemetry` instance to true. \ No newline at end of file +By default, the telemetry service is enabled, but you can disable it by setting the telemetryDisabled property to true in your application's package.json file, or by setting the `STRAPI_TELEMETRY_DISABLED` environment variable to true. You can also disable telemetry programmatically by setting the isDisabled property of the `strapi.telemetry` instance to true. + +### `strapi.requestContext` +- Object - Context Storage + - 'run(store, cb)': Function + - 'store': Any - Value that should be retrieved + - 'cb': Function - Callback + - 'get()': Function + +The request context stores the ctx object from KoaJS on each request. This allows users to have access to the context from anywhere through the Strapi instance. + diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index f26260827f..4ea71bf49f 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -109,27 +109,13 @@ class Strapi { // Instantiate the Koa app & the HTTP server this.server = createServer(this); - // Strapi utils instanciation + // Strapi utils instantiation this.fs = createStrapiFs(this); - this.eventHub = createEventHub(); - this.startupLogger = createStartupLogger(this); - this.log = createLogger(this.config.get('logger', {})); - this.cron = createCronService(); - - /** - * Service used to send statistical data to Amplitude - */ this.telemetry = createTelemetry(this); - - // TODO put this in /docs/docs/API/Strapi - /** - * TODO ask JS | Alex - * Wrapper around async_hooks AsyncLocalStorage - */ this.requestContext = requestContext; // TODO put this in /docs/docs/API/Strapi From d83a4608b441dd4eee1cdd32aaf68024098eb0fc Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 10:19:32 +0200 Subject: [PATCH 21/36] docs(api-ref): fix typo --- docs/docs/api/Strapi.mdx | 11 ++++++----- docs/docs/api/telemetry.mdx | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 1f598498ef..2d0018c39d 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -174,11 +174,12 @@ The `strapi.telemetry` property provides access to the telemetry service instanc By default, the telemetry service is enabled, but you can disable it by setting the telemetryDisabled property to true in your application's package.json file, or by setting the `STRAPI_TELEMETRY_DISABLED` environment variable to true. You can also disable telemetry programmatically by setting the isDisabled property of the `strapi.telemetry` instance to true. ### `strapi.requestContext` -- Object - Context Storage - - 'run(store, cb)': Function - - 'store': Any - Value that should be retrieved - - 'cb': Function - Callback - - 'get()': Function +- Object Context Storage + + - `run(store, cb)`: Function + - `store`: Any Value that should be retrieved + - `cb`: Function Callback + - `get()` Function The request context stores the ctx object from KoaJS on each request. This allows users to have access to the context from anywhere through the Strapi instance. diff --git a/docs/docs/api/telemetry.mdx b/docs/docs/api/telemetry.mdx index 461de074e9..60bf8ae59c 100644 --- a/docs/docs/api/telemetry.mdx +++ b/docs/docs/api/telemetry.mdx @@ -74,8 +74,8 @@ telemetry.destroy(); ``` ### `telemetry.send(event, payload)` -- event: String - The event to be sent. -- payload: Object - The payload to be sent with the event. +- `event`: String - The event to be sent. +- `payload`: Object - The payload to be sent with the event. Sends telemetry event with the given payload. From 456bfd459f9d7fe3f77efc27436538c21aa0a478 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 10:32:33 +0200 Subject: [PATCH 22/36] docs(api-ref): add customFields documentation --- docs/docs/api/Strapi.mdx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 2d0018c39d..579f26e9f0 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -183,3 +183,19 @@ By default, the telemetry service is enabled, but you can disable it by setting The request context stores the ctx object from KoaJS on each request. This allows users to have access to the context from anywhere through the Strapi instance. +### `strapi.customFields` +- Object + + - `register(customField)`: Function Register a new custom field + +This property is a shortcut to `strapi.container.get('custom-fields').add(customField)`. + +#### Examples +```javascript + strapi.customFields.register({ + name: 'color', + plugin: 'color-picker', + type: 'string', + }); +``` + From 907f2f57d32875a9350c5e5a7ab5e148f6c56dd1 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 14:39:22 +0200 Subject: [PATCH 23/36] docs(api-ref): listing Strapi documentation methods and properties --- docs/docs/api/Strapi.mdx | 234 ++++++++++++++++++++++++++++- docs/docs/api/telemetry.mdx | 1 + packages/core/strapi/lib/Strapi.js | 10 -- 3 files changed, 232 insertions(+), 13 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 579f26e9f0..91636d2f5b 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -85,10 +85,9 @@ A set of path to specific Strapi project parts. - `true`: Everything have been loaded - `false`: There is something loading -### `strapi.reload` -- Function +### `strapi.reload()` -Function to reload the app. +Reload the app. This function defines itself at the construction of the Strapi class. @@ -199,3 +198,232 @@ This property is a shortcut to `strapi.container.get('custom-fields').add(custom }); ``` +### `strapi.config` +- Object + +Shortcut to `strapi.container.get('config')`. + +See the [config container](#config). + +### `strapi.services` +- Object[] + +Shortcut to `strapi.container.get('services').getAll()`. + +See the [services' container](#services). + +### `strapi.service(uid)` +- `uid`: String + +Shortcut to `strapi.container.get('services').get(uid)`. + +See the [services' container](#services). + +### `strapi.controllers` +- Object[] + +Shortcut to `strapi.container.get('controllers').getAll()`. + +See the [controllers' container](#controllers). + +### `strapi.controller(uid)` +- `uid`: String + +Shortcut to `strapi.container.get('controllers').get(uid)`. + +See the [controllers' container](#controllers). + +### `strapi.contentTypes` +- Object[] + +Shortcut to `strapi.container.get('content-types').getAll()`. + +See the [content-types' container](#content-types). + +### `strapi.contentType(name)` +- `name`: String + +Shortcut to `strapi.container.get('content-types').get(name)`. + +See the [content-types' container](#content-types). + +### `strapi.policies` +- Object[] + +Shortcut to `strapi.container.get('policies').getAll()`. + +See the [policies' container](#policies). + +### `strapi.policy(name)` +- `name`: String + +Shortcut to `strapi.container.get('policies').get(name)`. + +See the [policies' container](#policies). + +### `strapi.middlewares` +- Object[] + +Shortcut to `strapi.container.get('middlewares').getAll()`. + +See the [middlewares container](#middlewares). + +### `strapi.middleware(name)` +- `name`: String + +Shortcut to `strapi.container.get('middlewares').get(name)`. + +See the [middlewares container](#middlewares). + +### `strapi.plugins` +- Object[] + +Shortcut to `strapi.container.get('plugins').getAll()`. + +See the [plugins' container](#plugins). + +### `strapi.plugin(name)` +- `name`: String + +Shortcut to `strapi.container.get('plugins').get(name)`. + +See the [plugins' container](#plugins). + +### `strapi.hooks` +- Object[] + +Shortcut to `strapi.container.get('hooks').getAll()`. + +See the [hooks' container](#hooks). + +### `strapi.hook(name)` +- `name`: String + +Shortcut to `strapi.container.get('hooks').get(name)`. + +See the [hooks' container](#hooks). + +### `strapi.api` +- Object[] + +Shortcut to `strapi.container.get('apis').getAll()`. + +See the [apis container](#apis). + +### `strapi.auth` +- Object + +Shortcut to `strapi.container.get('auth')`. + +See the [auth' container](#auth). + +### `strapi.contentAPI` +- Object + +Shortcut to `strapi.container.get('content-api')`. + +See the [content-api container](#content-api). + +### `strapi.sanitizers` +- Object + +Shortcut to `strapi.container.get('sanitizers')`. + +See the [sanitizers' container](#sanitizers). + +### `strapi.start()` +- Returns: Promise + +### `strapi.destroy()` +- Returns: Promise + +### `strapi.sendStartupTelemetry()` + +### `strapi.openAdmin({ isInitialized })` +- Returns: Promise + +### `strapi.postListen()` +- Returns: Promise + +### `strapi.listen()` +- Returns: Promise + +### `strapi.stopWithError()` + +### `strapi.stop(exitCode)` + +### `strapi.loadAdmin()` +- Returns: Promise + +### `strapi.loadPlugins()` +- Returns: Promise + +### `strapi.loadPolicies()` +- Returns: Promise + +### `strapi.loadAPIs()` +- Returns: Promise + +### `strapi.loadComponents()` +- Returns: Promise + +### `strapi.loadMiddlewares()` +- Returns: Promise + +### `strapi.loadApp()` +- Returns: Promise + +### `strapi.loadSanitizers()` +- Returns: Promise + +### `strapi.registerInternalHooks()` + +### `strapi.register()` +- Returns: Promise + +### `strapi.bootstrap()` +- Returns: Promise + +### `strapi.load()` +- Returns: Promise + +### `strapi.startWebhooks()` +- Returns: Promise + +### `strapi.reload()` + +### `strapi.runLifecyclesFunctions()` +- Returns: Promise + +### `strapi.getModel(uid)` +- `uid`: String + +### `strapi.query(uid)` +- `uid`: String + +## Strapi containers + +The strapi containers are accessible via `strapi.container.get('name-of-the-container')`. + +### `config` + +### `services` + +### `controllers` + +### `content-types` + +### `policies` + +### `plugins` + +### `hooks` + +### `apis` + +### `auth` + +### `content-api` + +### `sanitizers` + diff --git a/docs/docs/api/telemetry.mdx b/docs/docs/api/telemetry.mdx index 60bf8ae59c..60b607868b 100644 --- a/docs/docs/api/telemetry.mdx +++ b/docs/docs/api/telemetry.mdx @@ -76,6 +76,7 @@ telemetry.destroy(); ### `telemetry.send(event, payload)` - `event`: String - The event to be sent. - `payload`: Object - The payload to be sent with the event. +- Returns: Promise Sends telemetry event with the given payload. diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index 4ea71bf49f..e550ffa3e2 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -117,16 +117,6 @@ class Strapi { this.cron = createCronService(); this.telemetry = createTelemetry(this); this.requestContext = requestContext; - - // TODO put this in /docs/docs/API/Strapi - /** - * Object - * register(customField): - * Add a new custom field to the Strapi instance - * - * customField: - * TODO describe custom field - */ this.customFields = createCustomFields(this); createUpdateNotifier(this).notify(); From 28d12b5dc214bc10147cc9e82cdee63fd6709fdc Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 15:34:33 +0200 Subject: [PATCH 24/36] docs(api-ref): add config container description --- docs/docs/api/Strapi.mdx | 96 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 91636d2f5b..e66ebcd109 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -334,96 +334,192 @@ See the [sanitizers' container](#sanitizers). ### `strapi.start()` - Returns: Promise +//TODO + ### `strapi.destroy()` - Returns: Promise +//TODO + ### `strapi.sendStartupTelemetry()` +//TODO + ### `strapi.openAdmin({ isInitialized })` - Returns: Promise +//TODO + ### `strapi.postListen()` - Returns: Promise +//TODO + ### `strapi.listen()` - Returns: Promise +//TODO + ### `strapi.stopWithError()` +//TODO + ### `strapi.stop(exitCode)` +//TODO + ### `strapi.loadAdmin()` - Returns: Promise +//TODO + ### `strapi.loadPlugins()` - Returns: Promise +//TODO + ### `strapi.loadPolicies()` - Returns: Promise +//TODO + ### `strapi.loadAPIs()` - Returns: Promise +//TODO + ### `strapi.loadComponents()` - Returns: Promise +//TODO + ### `strapi.loadMiddlewares()` - Returns: Promise +//TODO + ### `strapi.loadApp()` - Returns: Promise +//TODO + ### `strapi.loadSanitizers()` - Returns: Promise +//TODO + ### `strapi.registerInternalHooks()` +//TODO + ### `strapi.register()` - Returns: Promise +//TODO + ### `strapi.bootstrap()` - Returns: Promise +//TODO + ### `strapi.load()` - Returns: Promise +//TODO + ### `strapi.startWebhooks()` - Returns: Promise +//TODO + ### `strapi.reload()` +//TODO + ### `strapi.runLifecyclesFunctions()` - Returns: Promise +//TODO + ### `strapi.getModel(uid)` - `uid`: String +//TODO + ### `strapi.query(uid)` - `uid`: String +//TODO + ## Strapi containers The strapi containers are accessible via `strapi.container.get('name-of-the-container')`. ### `config` +- Object + + - `get(path, defaultValue)`: Function + - `path`: String + - `defaultValue`: Any + - Returns: Any - The value located at `path` or, if undefined, `defaultValue`. + - `set(path, value)`: Function + - `path`: String - Where the value should be stored + - `value`: Any + - `has(path)`: Function + - `path`: String + - Returns: Boolean - Does the `path` match a value stored in the config container. + - `launchedAt`: Number **Default:** `Date.now()` + Date in milliseconds when the server has started + - `serveAdminPanel`: Boolean **Default:** `true` + See [Strapi constructor](#new-strapiopts) options + - `autoReload`: Boolean **Default:** `false` + See [Strapi constructor](#new-strapiopts) options + - `environment`: String - process.env.NODE_ENV + - `uuid`: String - string extracted from `package.json` located in `strapi.uuid` + - `packageJsonStrapi`: Object - object extracted from `package.json` located in `strapi` (except uuid) + - `info`: Object + - everything stored in the `package.json` + - `strapi`: String - Current version of Strapi + +Every file stored under the `config` folder will be injected in this config container object. ### `services` +//TODO + ### `controllers` +//TODO + ### `content-types` +//TODO + ### `policies` +//TODO + ### `plugins` +//TODO + ### `hooks` +//TODO + ### `apis` +//TODO + ### `auth` +//TODO + ### `content-api` +//TODO + ### `sanitizers` +//TODO + From 6bd5c29b91493a21cd55b53b146756a7fdea9272 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 16:05:40 +0200 Subject: [PATCH 25/36] docs(api-ref): clean Strapi class documentation --- docs/docs/api/Strapi.mdx | 2 +- packages/core/strapi/lib/Strapi.js | 26 -------------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index e66ebcd109..ae067246c1 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -1,5 +1,5 @@ --- -title: Strapi +title: Strapi (WIP) slug: /api/Strapi tags: - class diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index e550ffa3e2..293bfe1a4d 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -130,32 +130,6 @@ class Strapi { }); } - // TODO put this in /docs/docs/API/Strapi - /* - config attribute (JS Object) - Describe all possibilities inside Strapi config - - launchedAt (Number, Date.now() by default): - Date in milliseconds when the server has started - - serveAdminPanel (boolean, true by default) -> link to opts.serveAdminPanel - autoReload (boolean, false by default) -> link to opts.autoReload - environment (string): - process.env.NODE_ENV - uuid (optional): - uuid describe in the project's package.json - Generated automatically (used by Amplitude) by strapi project generator. Used to identify the project (for stats purposes). - packageJsonStrapi: - strapi object can contain any attribute to describe the Strapi project - uuid is omitted in this config attribute - - telemetryDisabled (boolean, undefined): - If true, disable the telemetry for the app (connected to Amplitude) - - TODO: find where this config is used and list all possible attributes - info: - Package.json + strapi version - */ get config() { return this.container.get('config'); } From 84e058730f9509f693f45a38dc88a68103b2282a Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 4 Apr 2023 16:15:07 +0200 Subject: [PATCH 26/36] docs(api-ref): clean comments --- .../core/strapi/lib/services/server/index.js | 26 ------------------- .../strapi/lib/utils/update-notifier/index.js | 10 ------- 2 files changed, 36 deletions(-) diff --git a/packages/core/strapi/lib/services/server/index.js b/packages/core/strapi/lib/services/server/index.js index e220912863..217cb2381b 100644 --- a/packages/core/strapi/lib/services/server/index.js +++ b/packages/core/strapi/lib/services/server/index.js @@ -54,32 +54,6 @@ const createServer = (strapi) => { mounted: false, }; - /* - Strapi server object - - app: - Koa server instance -> Link to Koa doc - router: - Koa router -> Link to @koa/router doc - httpServer: - Http server -> Link to http doc - api(name): - Getter for apis available in Strapi - 'content-api': - Used by users - TODO - admin: - Used by admin panel - TODO - use(...args): - routes(routes): - mount(): - async initRouting(): - async initMiddleware(): - listRoutes(): - listen(...args): - async destroy(): - */ return { app, router, diff --git a/packages/core/strapi/lib/utils/update-notifier/index.js b/packages/core/strapi/lib/utils/update-notifier/index.js index c1822a4ef3..08d336adc0 100644 --- a/packages/core/strapi/lib/utils/update-notifier/index.js +++ b/packages/core/strapi/lib/utils/update-notifier/index.js @@ -31,16 +31,6 @@ Check out the new releases at: ${releaseLink} `.trim(); }; -/** - * Utility that record if the user is using the last Strapi version - * Store information in .strapi-updater.json file - * - * JS Object - * notify(): - * check if notification interval have been reach. if so, display a message in the console - * default interval : 1 week - * Check every day at max - */ const createUpdateNotifier = (strapi) => { let config = null; From 2cd342bff72f63fe78a52348c55e5b24afc01fd1 Mon Sep 17 00:00:00 2001 From: derrickmehaffy Date: Fri, 14 Apr 2023 11:48:32 -0700 Subject: [PATCH 27/36] cleanup file ref for case sensitivity --- docs/docs/api/Strapi.mdx | 2 +- docs/docs/api/api.mdx | 4 ++-- docs/docs/api/container.mdx | 4 ++-- docs/docs/api/cron.mdx | 2 +- docs/docs/api/event-hub.mdx | 4 ++-- docs/docs/api/startup-logger.mdx | 2 +- docs/docs/api/strapi-fs.mdx | 4 ++-- docs/docs/api/strapi-server.mdx | 4 ++-- docs/docs/api/structure-example.md | 2 +- docs/docs/api/telemetry.mdx | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index ae067246c1..62379da402 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -9,7 +9,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Strapi diff --git a/docs/docs/api/api.mdx b/docs/docs/api/api.mdx index 4ba62e39de..f185e48ce4 100644 --- a/docs/docs/api/api.mdx +++ b/docs/docs/api/api.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # API @@ -24,4 +24,4 @@ The Strapi API module permits to generate a Strapi API object that wrap all the ### `createAPI(strapi, opts)` -// TODO \ No newline at end of file +// TODO diff --git a/docs/docs/api/container.mdx b/docs/docs/api/container.mdx index 86cb474af2..b1fe6bbc81 100644 --- a/docs/docs/api/container.mdx +++ b/docs/docs/api/container.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 5 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Container @@ -97,4 +97,4 @@ container.get('boolean', false); ``` ### `container.extend()` -To be developed \ No newline at end of file +To be developed diff --git a/docs/docs/api/cron.mdx b/docs/docs/api/cron.mdx index 0e0ce0b3a9..94f11dde62 100644 --- a/docs/docs/api/cron.mdx +++ b/docs/docs/api/cron.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Cron diff --git a/docs/docs/api/event-hub.mdx b/docs/docs/api/event-hub.mdx index de8711460b..eb6034f5e9 100644 --- a/docs/docs/api/event-hub.mdx +++ b/docs/docs/api/event-hub.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Strapi Event Hub @@ -24,4 +24,4 @@ Strapi Event Hub module - description to be done ### `createEventHub()` -//TODO \ No newline at end of file +//TODO diff --git a/docs/docs/api/startup-logger.mdx b/docs/docs/api/startup-logger.mdx index 3d64158955..9939c38764 100644 --- a/docs/docs/api/startup-logger.mdx +++ b/docs/docs/api/startup-logger.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # API diff --git a/docs/docs/api/strapi-fs.mdx b/docs/docs/api/strapi-fs.mdx index a28b636ddd..8695482e06 100644 --- a/docs/docs/api/strapi-fs.mdx +++ b/docs/docs/api/strapi-fs.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Strapi File System @@ -39,4 +39,4 @@ Deprecated Deprecated ::: -### `strapiFs.appendFile(optPath, data)` \ No newline at end of file +### `strapiFs.appendFile(optPath, data)` diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx index 9655589a93..826f9d1e45 100644 --- a/docs/docs/api/strapi-server.mdx +++ b/docs/docs/api/strapi-server.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 5 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Strapi Server @@ -80,4 +80,4 @@ Shortcut for Koa `app.use(...args)` method. - `admin`: [API](API) - API used by admin panel -Strapi APIs is a map of all APIs available inside the Strapi project. \ No newline at end of file +Strapi APIs is a map of all APIs available inside the Strapi project. diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure-example.md index b6f29b075b..2e603cbd5b 100644 --- a/docs/docs/api/structure-example.md +++ b/docs/docs/api/structure-example.md @@ -10,7 +10,7 @@ toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Name of Module diff --git a/docs/docs/api/telemetry.mdx b/docs/docs/api/telemetry.mdx index 60b607868b..45ccd55cda 100644 --- a/docs/docs/api/telemetry.mdx +++ b/docs/docs/api/telemetry.mdx @@ -8,7 +8,7 @@ tags: toc_min_heading_level: 2 toc_max_heading_level: 3 --- -import Type from '@site/docs/api/components/Type'; +import Type from '@site/docs/api/components/type'; # Telemetry From a6f440d8e818c53977197c30cc71f0c51ea3d0c2 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Thu, 20 Apr 2023 16:57:11 +0200 Subject: [PATCH 28/36] chore(docs): add several details to api ref pages --- docs/docs/api/Strapi.mdx | 7 +++++-- docs/docs/api/telemetry.mdx | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 62379da402..9b8c787887 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -48,7 +48,8 @@ const strapiInstance = new Strapi(); ### `strapi.container` - [Container](./container) -This is where all registries are stored. +The container provides a simple and efficient way to register and manage these resources, making it easy to access and use them throughout the application. +By registering a registry with the container, it can be easily retrieved by other parts of the application, making it a powerful tool for organizing and reusing code across the entire codebase. See [Container](./container). @@ -82,9 +83,11 @@ A set of path to specific Strapi project parts. ### `strapi.isLoaded` - Boolean - - `true`: Everything have been loaded + - `true`: Everything (all `register` and `bootstrap` functions available in your strapi project) have been loaded - `false`: There is something loading +Note: `register` functions are called before the `bootstrap` functions. + ### `strapi.reload()` Reload the app. diff --git a/docs/docs/api/telemetry.mdx b/docs/docs/api/telemetry.mdx index 45ccd55cda..8f07aba17f 100644 --- a/docs/docs/api/telemetry.mdx +++ b/docs/docs/api/telemetry.mdx @@ -75,7 +75,7 @@ telemetry.destroy(); ### `telemetry.send(event, payload)` - `event`: String - The event to be sent. -- `payload`: Object - The payload to be sent with the event. +- `payload`: [TelemetryPayload](#telemetrypayload) - The payload to be sent with the event. - Returns: Promise Sends telemetry event with the given payload. @@ -85,3 +85,18 @@ Sends telemetry event with the given payload. ```javascript telemetry.send('event_name', { key: 'value' }); ``` + +## Types + +### `TelemetryPayload` +- Object + + - `eventProperties`: Object An object that contains additional information about the event. + - `userProperties`: Object An object that defines the identity of the user who triggered the event. + - `groupProperties`: Object An object that defines properties of the application or environment in which the event occurred. + +Examples of event properties in Strapi include model, containsRelationalFields, displayedFields, kind, and hasDraftAndPublish. These properties are specific to the event and are used to provide additional context about what happened. + +User properties can include information such as the user's operating system, node version, and hostname. These properties are typically used to group events by user or to filter events based on certain user characteristics. + +Group properties can include information such as the language(s) used in the application, the database being used, and the number of locales. These properties are typically used to group events by application version, environment, or other characteristics. \ No newline at end of file From adac6e5e767eeb9576d2d083bf9876ff246a057b Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Thu, 20 Apr 2023 17:01:16 +0200 Subject: [PATCH 29/36] chore(docs): typo --- docs/docs/api/Strapi.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 9b8c787887..a553a418b9 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -83,7 +83,7 @@ A set of path to specific Strapi project parts. ### `strapi.isLoaded` - Boolean - - `true`: Everything (all `register` and `bootstrap` functions available in your strapi project) have been loaded + - `true`: Everything (all `register` and `bootstrap` functions available in your strapi project) has been loaded - `false`: There is something loading Note: `register` functions are called before the `bootstrap` functions. From 76017de6c5b54ec5e62d5214db2c51e19a5b7d3d Mon Sep 17 00:00:00 2001 From: Nathan Pichon Date: Tue, 2 May 2023 09:55:47 +0200 Subject: [PATCH 30/36] chore(contrib-docs): typo Co-authored-by: Alexandre BODIN --- docs/docs/api/Strapi.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index a553a418b9..539b51c1cf 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -48,7 +48,7 @@ const strapiInstance = new Strapi(); ### `strapi.container` - [Container](./container) -The container provides a simple and efficient way to register and manage these resources, making it easy to access and use them throughout the application. +The container provides a simple and efficient way to register and manage resources, making it easy to access and use them throughout the application. By registering a registry with the container, it can be easily retrieved by other parts of the application, making it a powerful tool for organizing and reusing code across the entire codebase. See [Container](./container). From 41d8f15eb9ac59ecafbbbfc3b187db84e45744e5 Mon Sep 17 00:00:00 2001 From: Nathan Pichon Date: Tue, 2 May 2023 09:55:56 +0200 Subject: [PATCH 31/36] chore(contrib-docs): typo Co-authored-by: Alexandre BODIN --- docs/docs/api/Strapi.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 539b51c1cf..20d26461b8 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -68,7 +68,7 @@ Stored paths of file system. #### StrapiPathObject - Object -A set of path to specific Strapi project parts. +A set of paths to specific Strapi project parts. - `root`: String Root path - `src`: String Sources route path to project files From 136d7b972b5ef4bbbdb5536380a814aafbfc0919 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 2 May 2023 15:13:45 +0200 Subject: [PATCH 32/36] docs: replace todos by callout todos --- docs/docs/api/Strapi.mdx | 140 +++++++++++++++++++++++++++--------- docs/docs/api/api.mdx | 4 +- docs/docs/api/container.mdx | 4 +- docs/docs/api/event-hub.mdx | 4 +- 4 files changed, 114 insertions(+), 38 deletions(-) diff --git a/docs/docs/api/Strapi.mdx b/docs/docs/api/Strapi.mdx index 20d26461b8..3f6c457174 100644 --- a/docs/docs/api/Strapi.mdx +++ b/docs/docs/api/Strapi.mdx @@ -337,122 +337,172 @@ See the [sanitizers' container](#sanitizers). ### `strapi.start()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.destroy()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.sendStartupTelemetry()` -//TODO +:::info +TODO +::: ### `strapi.openAdmin({ isInitialized })` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.postListen()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.listen()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.stopWithError()` -//TODO +:::info +TODO +::: ### `strapi.stop(exitCode)` -//TODO +:::info +TODO +::: ### `strapi.loadAdmin()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadPlugins()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadPolicies()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadAPIs()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadComponents()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadMiddlewares()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadApp()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.loadSanitizers()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.registerInternalHooks()` -//TODO +:::info +TODO +::: ### `strapi.register()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.bootstrap()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.load()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.startWebhooks()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.reload()` -//TODO +:::info +TODO +::: ### `strapi.runLifecyclesFunctions()` - Returns: Promise -//TODO +:::info +TODO +::: ### `strapi.getModel(uid)` - `uid`: String -//TODO +:::info +TODO +::: ### `strapi.query(uid)` - `uid`: String -//TODO +:::info +TODO +::: ## Strapi containers @@ -488,41 +538,61 @@ Every file stored under the `config` folder will be injected in this config cont ### `services` -//TODO +:::info +TODO +::: ### `controllers` -//TODO +:::info +TODO +::: ### `content-types` -//TODO +:::info +TODO +::: ### `policies` -//TODO +:::info +TODO +::: ### `plugins` -//TODO +:::info +TODO +::: ### `hooks` -//TODO +:::info +TODO +::: ### `apis` -//TODO +:::info +TODO +::: ### `auth` -//TODO +:::info +TODO +::: ### `content-api` -//TODO +:::info +TODO +::: ### `sanitizers` -//TODO +:::info +TODO +::: diff --git a/docs/docs/api/api.mdx b/docs/docs/api/api.mdx index f185e48ce4..52f9eb66a6 100644 --- a/docs/docs/api/api.mdx +++ b/docs/docs/api/api.mdx @@ -24,4 +24,6 @@ The Strapi API module permits to generate a Strapi API object that wrap all the ### `createAPI(strapi, opts)` -// TODO +:::info +TODO +::: diff --git a/docs/docs/api/container.mdx b/docs/docs/api/container.mdx index b1fe6bbc81..4d3884999f 100644 --- a/docs/docs/api/container.mdx +++ b/docs/docs/api/container.mdx @@ -97,4 +97,6 @@ container.get('boolean', false); ``` ### `container.extend()` -To be developed +:::info + To be developed +::: diff --git a/docs/docs/api/event-hub.mdx b/docs/docs/api/event-hub.mdx index eb6034f5e9..aa86958594 100644 --- a/docs/docs/api/event-hub.mdx +++ b/docs/docs/api/event-hub.mdx @@ -24,4 +24,6 @@ Strapi Event Hub module - description to be done ### `createEventHub()` -//TODO +:::info +TODO +::: From b888b703eb41826a354014e0e0004e6a3300add2 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 2 May 2023 15:14:08 +0200 Subject: [PATCH 33/36] docs: move example file --- docs/docs/api/{structure-example.md => structure.example} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/docs/api/{structure-example.md => structure.example} (100%) diff --git a/docs/docs/api/structure-example.md b/docs/docs/api/structure.example similarity index 100% rename from docs/docs/api/structure-example.md rename to docs/docs/api/structure.example From c2d82a20d72eadcf4ebc401d2b49d724e6848ea8 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 2 May 2023 15:17:54 +0200 Subject: [PATCH 34/36] chore(contrib-docs): move eslint file to docs folder --- .eslintrc.docs.js => docs/.eslintrc.docs.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .eslintrc.docs.js => docs/.eslintrc.docs.js (100%) diff --git a/.eslintrc.docs.js b/docs/.eslintrc.docs.js similarity index 100% rename from .eslintrc.docs.js rename to docs/.eslintrc.docs.js From 4d7e0c2c0e12b7a56ef2cad62e578f129f6e74cb Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 2 May 2023 15:19:58 +0200 Subject: [PATCH 35/36] docs(contrib): add some todos --- docs/docs/api/strapi-server.mdx | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/docs/api/strapi-server.mdx b/docs/docs/api/strapi-server.mdx index 826f9d1e45..e0ab038814 100644 --- a/docs/docs/api/strapi-server.mdx +++ b/docs/docs/api/strapi-server.mdx @@ -65,13 +65,47 @@ Getter for apis available in Strapi Shortcut for Koa `app.use(...args)` method. ### `StrapiServer.routes(routes)` + +:::info +TODO +::: + ### `StrapiServer.mount()` + +:::info +TODO +::: + ### `StrapiServer.initRouting()` + +:::info +TODO +::: + ### `StrapiServer.initMiddlewares()` + +:::info +TODO +::: + ### `StrapiServer.listRoutes()` + +:::info +TODO +::: + ### `StrapiServer.listen(...args)` + +:::info +TODO +::: + ### `StrapiServer.destroy()` +:::info +TODO +::: + ### `StrapiAPIs` - Object From 021024dd7a78a87e926f3d801093dd6c2c6e9882 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 2 May 2023 15:25:13 +0200 Subject: [PATCH 36/36] docs(api): update cron with examples --- docs/docs/api/cron.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/docs/api/cron.mdx b/docs/docs/api/cron.mdx index 94f11dde62..5c12116cbf 100644 --- a/docs/docs/api/cron.mdx +++ b/docs/docs/api/cron.mdx @@ -39,6 +39,7 @@ Adds one or more cron tasks to the service. - Each key of the `tasks` object is the name of the task. - Each value of the `tasks` object can be either a function, or an object with two properties: `task` and `options`. - If the value is a function, it is used as the task to be executed when the cron expression is met. + - The key will be considered as the cron expression - If the value is an object, its `task` property is used as the task function, and its `options` property is used as the cron expression options. #### Example @@ -56,6 +57,7 @@ cron.add({ task, options: '*/5 * * * *', // Executes every 5 minutes. }, + '*/1 * * * *': () => console.log('A minute has passed.'), }); ```