From 0a8e42b72b8e1debadcd33dea6fb35edf96f0b13 Mon Sep 17 00:00:00 2001 From: Convly Date: Fri, 18 Oct 2024 16:22:07 +0200 Subject: [PATCH 01/20] Add API Reference and Guides for TypeScript in docs Created new markdown files for API Reference and Guides under TypeScript development. Updated sidebar configuration to include these new sections and added corresponding links and placeholders. --- .gitignore | 1 + .../docs/dev-docs/typescript/development.md | 21 +++++----- .../typescript/development/api-reference.md | 13 ++++++ .../dev-docs/typescript/development/guides.md | 16 ++++++++ docusaurus/sidebars.js | 41 ++++++++++++++----- 5 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 .gitignore create mode 100644 docusaurus/docs/dev-docs/typescript/development/api-reference.md create mode 100644 docusaurus/docs/dev-docs/typescript/development/guides.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..9f11b755a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index 5e815d4afd..2552891ecb 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -9,18 +9,19 @@ tags: --- -import NotV5 from '/docs/snippets/_not-updated-to-v5.md' - # TypeScript Development with Strapi - +## :open_book: API Reference + +The API reference is an exhaustive list of the types exported by Strapi. + +It's automatically generated based on the code and can be found [here](/dev-docs/typescript/development/api-reference). + +## :books: Guides -While developing a [TypeScript](/dev-docs/typescript)-based application with Strapi, you can: +The guides are a curated list of common examples in which you might need to use Strapi types in your application. -- access [typings for the `Strapi`](#use-strapi-typescript-typings) class with autocompletion, -- [generate typings](#generate-typings-for-content-types-schemas) for your project's content-types, -- [start Strapi programmatically](#start-strapi-programmatically), -- and follow some TypeScript-specific instructions for [plugins development](#develop-a-plugin-using-typescript). +You can find the list of available guides [here](/dev-docs/typescript/development/guides). ## Use `Strapi` TypeScript typings @@ -32,10 +33,10 @@ To experience TypeScript-based autocomplete while developing Strapi applications 2. Declare the `strapi` argument as type `Strapi` within the global `register` method: ```typescript title="./src/index.ts" - import { Strapi } from '@strapi/strapi'; + import type { Core } from '@strapi/strapi'; export default { - register({ strapi }: { strapi: Strapi }) { + register({ strapi }: { strapi: Core.Strapi }) { // ... }, }; diff --git a/docusaurus/docs/dev-docs/typescript/development/api-reference.md b/docusaurus/docs/dev-docs/typescript/development/api-reference.md new file mode 100644 index 0000000000..3d0a12fcf9 --- /dev/null +++ b/docusaurus/docs/dev-docs/typescript/development/api-reference.md @@ -0,0 +1,13 @@ +--- +title: TypeScript - API Reference +sidebar_label: API Reference +description: API Reference for Strapi Type System +tags: +- typescript +- api +- reference +--- + +# API Reference + +:building_construction: **Still under construction, come back later** :construction: diff --git a/docusaurus/docs/dev-docs/typescript/development/guides.md b/docusaurus/docs/dev-docs/typescript/development/guides.md new file mode 100644 index 0000000000..20326b7ea4 --- /dev/null +++ b/docusaurus/docs/dev-docs/typescript/development/guides.md @@ -0,0 +1,16 @@ +--- +title: TypeScript - Guides +sidebar_label: Guides +description: List of TypeScript guides to get started with Strapi and TypeScript +tags: +- typescript +- guides +--- + +# TypeScript Guides + + + + + + diff --git a/docusaurus/sidebars.js b/docusaurus/sidebars.js index 816585536d..148673d8be 100644 --- a/docusaurus/sidebars.js +++ b/docusaurus/sidebars.js @@ -123,7 +123,7 @@ const sidebars = { id: 'dev-docs/deployment', }, items: [ - { + { type: 'doc', label: 'Introduction to deployment', id: 'dev-docs/deployment', @@ -318,7 +318,28 @@ const sidebars = { }, items: [ 'dev-docs/typescript', - 'dev-docs/typescript/development', + { + type: 'category', + label: 'TypeScript Development', + link: { + type: 'doc', + id: 'dev-docs/typescript/development' + }, + items: [ + 'dev-docs/typescript/development/api-reference', + { + type: 'category', + label: 'Guides', + link: { + type: 'doc', + id: 'dev-docs/typescript/development/guides' + }, + items: [ + 'dev-docs/typescript/development/guides/documents-and-entries' + ], + } + ], + }, 'dev-docs/typescript/adding-support-to-existing-project', ] }, @@ -762,9 +783,9 @@ const sidebars = { id: "user-docs/settings/introduction", }, items: [ - 'user-docs/settings/introduction', - 'user-docs/settings/configuring-users-permissions-plugin-settings', - 'user-docs/settings/audit-logs', + 'user-docs/settings/introduction', + 'user-docs/settings/configuring-users-permissions-plugin-settings', + 'user-docs/settings/audit-logs', { type: 'category', collapsed: false, @@ -813,7 +834,7 @@ const sidebars = { { type: "category", label: "Project deployment", - link: { type: "doc", id: "cloud/getting-started/deployment-options" }, + link: {type: "doc", id: "cloud/getting-started/deployment-options"}, customProps: { updated: false, }, @@ -831,7 +852,7 @@ const sidebars = { customProps: { new: true, }, - }, + }, ], }, { @@ -1033,7 +1054,7 @@ const sidebars = { type: 'category', collapsed: false, label: 'Filters, Locale, Publication State', - link: {type: 'doc', id: 'dev-docs/api/rest/filters-locale-publication' }, + link: {type: 'doc', id: 'dev-docs/api/rest/filters-locale-publication'}, items: [ { type: 'link', @@ -1066,7 +1087,7 @@ const sidebars = { type: 'category', collapsed: false, label: 'Sort and Pagination', - link: { type: 'doc', id: 'dev-docs/api/rest/sort-pagination'}, + link: {type: 'doc', id: 'dev-docs/api/rest/sort-pagination'}, items: [ { type: 'link', @@ -1269,7 +1290,7 @@ const sidebars = { type: 'category', label: 'Specific resources', collapsed: false, - link: { type: 'doc', id: 'dev-docs/migration/v4-to-v5/additional-resources/introduction' }, + link: {type: 'doc', id: 'dev-docs/migration/v4-to-v5/additional-resources/introduction'}, items: [ 'dev-docs/migration/v4-to-v5/additional-resources/introduction', 'dev-docs/migration/v4-to-v5/additional-resources/from-entity-service-to-document-service', From 910186b3a80d4b6825e747e78ee617b3446f5d83 Mon Sep 17 00:00:00 2001 From: Convly Date: Fri, 18 Oct 2024 16:22:38 +0200 Subject: [PATCH 02/20] Add TypeScript guide for manipulating Strapi documents and entries This guide covers prerequisites, type imports, and usage examples for working with Strapi documents and components using TypeScript. It includes detailed sections on generic and known entities, advanced use-cases, and type argument inference to enhance type safety and development efficiency. --- .../guides/documents-and-entries.md | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md new file mode 100644 index 0000000000..6e4db2baf5 --- /dev/null +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -0,0 +1,204 @@ +--- +title: TypeScript - Manipulating Documents and Entries +sidebar_label: Manipulating Documents and Entries +description: TypeScript guide to get started with manipulating documents and entries +tags: +- typescript +- guides +- data +- document +- component +- uid +- entries +--- + +# Manipulating documents and entries + +## Prerequisites + +- **Strapi Application:** A Strapi v5 application. If you don't have one, follow the [documentation](/dev-docs/quick-start) to get started. +- **TypeScript:** Ensure TypeScript is set up in your Strapi project. You can follow Strapi's [official guide](/dev-docs/typescript#getting-started-with-typescript-in-strapi) on configuring TypeScript. +- **Generated Types:** Application types [have been generated](/dev-docs/typescript/development#generate-typings-for-content-types-schemas) and are accessible. + +## Type Imports + +The `UID` namespace contains literal unions representing the available resources in the application. + +```typescript +import type { UID } from '@strapi/strapi'; +``` + +- `UID.ContentType` represents a union of every content-type identifier in the application +- `UID.Component` represents a union of every component identifier in the application +- `UID.Schema` represents a union of every schema (content-type or component) identifier in the application +- And others... + +--- + +Strapi provides a `Data` namespace containing several built-in types for entity representation. + +```typescript +import type { Data } from '@strapi/strapi'; +``` + +- `Data.ContentType` represents a Strapi document object +- `Data.Component` represents a Strapi component object +- `Data.Entity` represents either a document or a component + +:::tip +Both the entities' type definitions and UIDs are based on the generated schema types for your application. + +In case of a mismatch or error, you can always [regenerate the types](/dev-docs/typescript/development#generate-typings-for-content-types-schemas). +::: + +## Usage + +### Generic Entities + +When dealing with generic data, it is recommended to use non-parametrized forms of the `Data` types. + +#### Generic Documents + +```typescript +async function save(name: string, document: Data.ContentType) { + await writeCSV(name, document); + // ^ { + // id: Data.ID; + // documentId: string; + // createdAt?: DateTimeValue; + // updatedAt?: DateTimeValue; + // publishedAt?: DateTimeValue; + // ... + // } +} +``` + +:::warning +In the preceding example, the resolved properties for `document` are those common to every content-type. + +Other properties have to be checked manually using type guards. + +```typescript +if ('my_prop' in document) { + return document.my_prop; +} +``` +::: + +#### Generic Components + +```typescript +function renderComponent(parent: Node, component: Data.Component) { + const elements: Element[] = []; + const properties = Object.entries(component); + + for (const [name, value] of properties) { + // ^ ^ + // string any + const paragraph = document.createElement('p'); + + paragraph.textContent = `Key: ${name}, Value: ${value}`; + + elements.push(paragraph); + } + + parent.append(...elements); +} +``` + +### Known Entities + +When manipulating known entities, it is possible to parametrize `Data` types for better type safety and intellisense. + +#### Known Documents + +```typescript +const ALL_CATEGORIES = ['food', 'tech', 'travel']; + +function validateArticle(article: Data.ContentType<'api::article.article'>) { + const { title, category } = article; + // ^? ^? + // string Data.ContentType<'api::category.category'> + + if (title.length < 5) { + throw new Error('Title too short'); + } + + if (!ALL_CATEGORIES.includes(category.name)) { + throw new Error(`Unknown category ${category.name}`); + } +} +``` + +#### Known Components + +```typescript +function processUsageMetrics(id: string, metrics: Data.Component<'app.metrics'>) { + telemetry.send(id, { clicks: metrics.clicks, views: metrics.views }); +} +``` +### Advanced Use-Cases + +#### Entities Subsets + +Using the types' second parameter (`TKeys`), it is possible to obtain a subset of an entity. + +```typescript +type Credentials = Data.ContentType<'api::acount.acount', 'email' | 'password'>; +// ^? { email: string; password: string } +``` + +```typescript +type UsageMetrics = Data.Component<'app.metrics', 'clicks' | 'views'>; +// ^? { clicks: number; views: number } +``` + +#### Type Argument Inference + +It is possible to bind and restrict an entity type based on other function parameters. + +In the following example, the `uid` type is inferred upon usage as `T` and used as a type parameter for the `document`. + +```typescript +import type { UID } from '@strapi/strapi'; + +function display(uid: T, document: Data.ContentType) { + switch (uid) { + case 'api::article.article': { + return document.title; + // ^? string + // ^? Data.ContentType<'api::article.article'> + } + case 'api::category.category': { + return document.name; + // ^? string + // ^? Data.ContentType<'api::category.category'> + } + case 'api::account.account': { + return document.email; + // ^? string + // ^? Data.ContentType<'api::account.account'> + } + default: { + throw new Error(`unknown content-type uid: "${uid}"`); + } + } +} +``` + +When calling the function, the `document` type needs to match the given `uid`. + +```typescript +declare const article: Data.Document<'api::article.article'>; +declare const category: Data.Document<'api::category.category'>; +declare const account: Data.Document<'api::account.account'>; + +display('api::article.article', article); +display('api::category.category', category); +display('api::account.account', account); +// ^ ✅ + +display('api::article.article', category); +// ^ Error: "category" is not assignable to parameter of type ContentType<'api::article.article'> + +``` From 638b2e7ae09f2cfd93cbd5cacf842eba81b9a5d5 Mon Sep 17 00:00:00 2001 From: Convly Date: Fri, 18 Oct 2024 16:23:04 +0200 Subject: [PATCH 03/20] Add new tags to TypeScript development docs Updated the tags in the TypeScript development documentation to include 'api reference' and 'guides' for better categorization and easier navigation. This helps users find relevant information more efficiently. --- docusaurus/docs/dev-docs/typescript/development.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index 2552891ecb..ba0de7b8e1 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -6,6 +6,8 @@ tags: - strapi.compile() function - typescript - plugins development +- api reference +- guides --- From e613ccb5ac5f8a27865553b70fea8cbaa9e30950 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:30:23 +0200 Subject: [PATCH 04/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 6e4db2baf5..f0e4e28b35 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -57,7 +57,7 @@ In case of a mismatch or error, you can always [regenerate the types](/dev-docs/ When dealing with generic data, it is recommended to use non-parametrized forms of the `Data` types. -#### Generic Documents +#### Generic documents ```typescript async function save(name: string, document: Data.ContentType) { From da7e8420c7c5f62a539535a9e8e2f4af4d3dec42 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:30:39 +0200 Subject: [PATCH 05/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index f0e4e28b35..f5c64c56ed 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -85,7 +85,7 @@ if ('my_prop' in document) { ``` ::: -#### Generic Components +#### Generic components ```typescript function renderComponent(parent: Node, component: Data.Component) { From e797774ef69b11e0fa8b85f73546a0dab31269c7 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:30:53 +0200 Subject: [PATCH 06/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index f5c64c56ed..0d280664a5 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -106,7 +106,7 @@ function renderComponent(parent: Node, component: Data.Component) { } ``` -### Known Entities +### Known entities When manipulating known entities, it is possible to parametrize `Data` types for better type safety and intellisense. From 7b41cefd98fdcb4d9e159ab8459564281e49d9d2 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:40:35 +0200 Subject: [PATCH 07/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 0d280664a5..8563f69d11 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -110,7 +110,7 @@ function renderComponent(parent: Node, component: Data.Component) { When manipulating known entities, it is possible to parametrize `Data` types for better type safety and intellisense. -#### Known Documents +#### Known documents ```typescript const ALL_CATEGORIES = ['food', 'tech', 'travel']; From 4ea2f48ff8a6249814a5909ca115a8c91f5831df Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:40:50 +0200 Subject: [PATCH 08/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 8563f69d11..46e59689d2 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -130,7 +130,7 @@ function validateArticle(article: Data.ContentType<'api::article.article'>) { } ``` -#### Known Components +#### Known components ```typescript function processUsageMetrics(id: string, metrics: Data.Component<'app.metrics'>) { From 3a92d2147cac56141483314c86cd2e41c0762489 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:41:05 +0200 Subject: [PATCH 09/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 46e59689d2..245d9f99e4 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -137,7 +137,7 @@ function processUsageMetrics(id: string, metrics: Data.Component<'app.metrics'>) telemetry.send(id, { clicks: metrics.clicks, views: metrics.views }); } ``` -### Advanced Use-Cases +### Advanced use cases #### Entities Subsets From 512e1fbda4adf3b93ef71f2d68932c0ec91783ba Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:41:40 +0200 Subject: [PATCH 10/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 245d9f99e4..1223dcac3e 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -139,7 +139,7 @@ function processUsageMetrics(id: string, metrics: Data.Component<'app.metrics'>) ``` ### Advanced use cases -#### Entities Subsets +#### Entities subsets Using the types' second parameter (`TKeys`), it is possible to obtain a subset of an entity. From 2813ffc67106e7ccf0983f28d866ca866ab701a2 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:42:01 +0200 Subject: [PATCH 11/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 1223dcac3e..3344649f29 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -153,7 +153,7 @@ type UsageMetrics = Data.Component<'app.metrics', 'clicks' | 'views'>; // ^? { clicks: number; views: number } ``` -#### Type Argument Inference +#### Type argument inference It is possible to bind and restrict an entity type based on other function parameters. From 8f0b412466568677c0fc38bd7cf1ab932f70e567 Mon Sep 17 00:00:00 2001 From: Pierre Wizla Date: Wed, 23 Oct 2024 16:42:13 +0200 Subject: [PATCH 12/20] Update docusaurus/sidebars.js --- docusaurus/sidebars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/sidebars.js b/docusaurus/sidebars.js index 148673d8be..41f18a3b6b 100644 --- a/docusaurus/sidebars.js +++ b/docusaurus/sidebars.js @@ -320,7 +320,7 @@ const sidebars = { 'dev-docs/typescript', { type: 'category', - label: 'TypeScript Development', + label: 'TypeScript development', link: { type: 'doc', id: 'dev-docs/typescript/development' From 7c434b1336378ce40a3a4765600d2e4af3ad8aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Herbaux?= Date: Wed, 23 Oct 2024 18:06:14 +0200 Subject: [PATCH 13/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md Co-authored-by: Pierre Wizla --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 3344649f29..af56869e61 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -14,7 +14,7 @@ tags: # Manipulating documents and entries -## Prerequisites +:::prerequisites - **Strapi Application:** A Strapi v5 application. If you don't have one, follow the [documentation](/dev-docs/quick-start) to get started. - **TypeScript:** Ensure TypeScript is set up in your Strapi project. You can follow Strapi's [official guide](/dev-docs/typescript#getting-started-with-typescript-in-strapi) on configuring TypeScript. From 406a8d5641a0b33900068857cfd86cfa4ff263ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Herbaux?= Date: Wed, 23 Oct 2024 18:06:22 +0200 Subject: [PATCH 14/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md Co-authored-by: Pierre Wizla --- .../typescript/development/guides/documents-and-entries.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index af56869e61..3dd902f220 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -19,6 +19,7 @@ tags: - **Strapi Application:** A Strapi v5 application. If you don't have one, follow the [documentation](/dev-docs/quick-start) to get started. - **TypeScript:** Ensure TypeScript is set up in your Strapi project. You can follow Strapi's [official guide](/dev-docs/typescript#getting-started-with-typescript-in-strapi) on configuring TypeScript. - **Generated Types:** Application types [have been generated](/dev-docs/typescript/development#generate-typings-for-content-types-schemas) and are accessible. +::: ## Type Imports From 619142c77caf73c43ae8c41d920ab247e1d68f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Herbaux?= Date: Wed, 23 Oct 2024 18:06:34 +0200 Subject: [PATCH 15/20] Update docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md Co-authored-by: Pierre Wizla --- .../typescript/development/guides/documents-and-entries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 3dd902f220..777b4447f5 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -54,7 +54,7 @@ In case of a mismatch or error, you can always [regenerate the types](/dev-docs/ ## Usage -### Generic Entities +### Generic entities When dealing with generic data, it is recommended to use non-parametrized forms of the `Data` types. From c0f23ce1c415f72b704190b1d0af660aca61d342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Herbaux?= Date: Wed, 23 Oct 2024 18:09:20 +0200 Subject: [PATCH 16/20] Update docusaurus/docs/dev-docs/typescript/development.md Co-authored-by: Pierre Wizla --- docusaurus/docs/dev-docs/typescript/development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index ba0de7b8e1..d5e32002e7 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -6,7 +6,7 @@ tags: - strapi.compile() function - typescript - plugins development -- api reference +- api - guides --- From b26d5ce4ba17f8df14bd0663c5d6fad9f575edba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Herbaux?= Date: Wed, 23 Oct 2024 18:09:58 +0200 Subject: [PATCH 17/20] Update docusaurus/docs/dev-docs/typescript/development.md Co-authored-by: Pierre Wizla --- docusaurus/docs/dev-docs/typescript/development.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index d5e32002e7..f505813803 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -13,7 +13,9 @@ tags: # TypeScript Development with Strapi -## :open_book: API Reference +:::strapi :open_book: API reference +We are preparing an API reference page, which will include an exhaustive list of the types exported by Strapi. Please come back soon! 👀 +::: The API reference is an exhaustive list of the types exported by Strapi. From b77060c1a08ed034f4aa6a89fe185f6abe292f5e Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 6 Nov 2024 11:26:45 +0100 Subject: [PATCH 18/20] add summaries and fixes --- .../docs/dev-docs/typescript/development.md | 40 +- .../typescript/development/api-reference.md | 7 +- .../dev-docs/typescript/development/guides.md | 8 +- .../guides/documents-and-entries.md | 47 +- docusaurus/sidebars.js | 461 +++++++++--------- 5 files changed, 292 insertions(+), 271 deletions(-) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index f505813803..d213b3dcdc 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -2,19 +2,20 @@ title: TypeScript development description: Learn more about TypeScript usage with Strapi 5 tags: -- strapi() factory -- strapi.compile() function -- typescript -- plugins development -- api -- guides - + - strapi() factory + - strapi.compile() function + - typescript + - plugins development + - api + - guides --- -# TypeScript Development with Strapi +# TypeScript Development with Strapi + +This page provides a comprehensive guide to developing with TypeScript in Strapi v5, covering key patterns and configurations for integrating TypeScript effectively. You'll find sections on using Strapi’s provided types, generating and managing typings for content types, configuring Strapi programmatically, and building plugins with TypeScript. Each section includes practical steps and example code to help you set up and troubleshoot TypeScript-based workflows in your Strapi project. :::strapi :open_book: API reference -We are preparing an API reference page, which will include an exhaustive list of the types exported by Strapi. Please come back soon! 👀 +We are preparing an API reference page, which will include an exhaustive list of the types exported by Strapi. Please come back soon! 👀 ::: The API reference is an exhaustive list of the types exported by Strapi. @@ -36,15 +37,15 @@ To experience TypeScript-based autocomplete while developing Strapi applications 1. Open the `./src/index.ts` file from your code editor. 2. Declare the `strapi` argument as type `Strapi` within the global `register` method: - ```typescript title="./src/index.ts" - import type { Core } from '@strapi/strapi'; + ```typescript title="./src/index.ts" + import type { Core } from '@strapi/strapi'; - export default { - register({ strapi }: { strapi: Core.Strapi }) { - // ... - }, - }; - ``` + export default { + register({ strapi }: { strapi: Core.Strapi }) { + // ... + }, + }; + ``` 3. Within the body of the `register` method, start typing `strapi.` and use keyboard arrows to browse the available properties. @@ -121,10 +122,9 @@ To start Strapi programmatically in a TypeScript project the Strapi instance req Strapi can be run programmatically by using the `strapi.createStrapi()` factory. Since the code of TypeScript projects is compiled in a specific directory, the parameter `distDir` should be passed to the factory to indicate where the compiled code should be read: ```js title="./server.js" - const strapi = require('@strapi/strapi'); const app = strapi.createStrapi({ distDir: './dist' }); -app.start(); +app.start(); ``` ### Use the `strapi.compile()` function @@ -134,7 +134,7 @@ The `strapi.compile()` function should be mostly used for developing tools that ```js const strapi = require('@strapi/strapi'); -strapi.compile().then(appContext => strapi(appContext).start()); +strapi.compile().then((appContext) => strapi(appContext).start()); ``` ## Develop a plugin using TypeScript diff --git a/docusaurus/docs/dev-docs/typescript/development/api-reference.md b/docusaurus/docs/dev-docs/typescript/development/api-reference.md index 3d0a12fcf9..58486e18b7 100644 --- a/docusaurus/docs/dev-docs/typescript/development/api-reference.md +++ b/docusaurus/docs/dev-docs/typescript/development/api-reference.md @@ -3,11 +3,10 @@ title: TypeScript - API Reference sidebar_label: API Reference description: API Reference for Strapi Type System tags: -- typescript -- api -- reference + - typescript + - api --- # API Reference -:building_construction: **Still under construction, come back later** :construction: +:building_construction: **Still under construction, come back later** :construction: diff --git a/docusaurus/docs/dev-docs/typescript/development/guides.md b/docusaurus/docs/dev-docs/typescript/development/guides.md index 20326b7ea4..db67c57c2d 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides.md @@ -3,11 +3,13 @@ title: TypeScript - Guides sidebar_label: Guides description: List of TypeScript guides to get started with Strapi and TypeScript tags: -- typescript -- guides + - typescript + - guides --- -# TypeScript Guides +# TypeScript Guides + +This page includes a curated list of common examples useful to use types while [developing a Strapi TypeScript application](/dev-docs/typescript/development). diff --git a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md index 777b4447f5..ec288d7b2f 100644 --- a/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md +++ b/docusaurus/docs/dev-docs/typescript/development/guides/documents-and-entries.md @@ -3,23 +3,25 @@ title: TypeScript - Manipulating Documents and Entries sidebar_label: Manipulating Documents and Entries description: TypeScript guide to get started with manipulating documents and entries tags: -- typescript -- guides -- data -- document -- component -- uid -- entries + - typescript + - guides + - data + - document + - component + - uid + - entries --- # Manipulating documents and entries +This guide will explore TypeScript patterns for manipulating documents and entries in a Strapi v5 application, including how to leverage Strapi's `UID` and `Data` namespaces to interact with both generic and known entity types safely. If you're working on a TypeScript-based Strapi project, mastering these approaches will help you take full advantage of type safety and code completion, ensuring robust, error-free interactions with your application’s content and components. + :::prerequisites - **Strapi Application:** A Strapi v5 application. If you don't have one, follow the [documentation](/dev-docs/quick-start) to get started. - **TypeScript:** Ensure TypeScript is set up in your Strapi project. You can follow Strapi's [official guide](/dev-docs/typescript#getting-started-with-typescript-in-strapi) on configuring TypeScript. - **Generated Types:** Application types [have been generated](/dev-docs/typescript/development#generate-typings-for-content-types-schemas) and are accessible. -::: + ::: ## Type Imports @@ -31,7 +33,7 @@ import type { UID } from '@strapi/strapi'; - `UID.ContentType` represents a union of every content-type identifier in the application - `UID.Component` represents a union of every component identifier in the application -- `UID.Schema` represents a union of every schema (content-type or component) identifier in the application +- `UID.Schema` represents a union of every schema (content-type or component) identifier in the application - And others... --- @@ -49,7 +51,7 @@ import type { Data } from '@strapi/strapi'; :::tip Both the entities' type definitions and UIDs are based on the generated schema types for your application. -In case of a mismatch or error, you can always [regenerate the types](/dev-docs/typescript/development#generate-typings-for-content-types-schemas). +In case of a mismatch or error, you can always [regenerate the types](/dev-docs/typescript/development#generate-typings-for-content-types-schemas). ::: ## Usage @@ -84,6 +86,7 @@ if ('my_prop' in document) { return document.my_prop; } ``` + ::: #### Generic components @@ -97,19 +100,19 @@ function renderComponent(parent: Node, component: Data.Component) { // ^ ^ // string any const paragraph = document.createElement('p'); - + paragraph.textContent = `Key: ${name}, Value: ${value}`; - + elements.push(paragraph); } - + parent.append(...elements); } ``` ### Known entities -When manipulating known entities, it is possible to parametrize `Data` types for better type safety and intellisense. +When manipulating known entities, it is possible to parametrize `Data` types for better type safety and code completion. #### Known documents @@ -134,10 +137,14 @@ function validateArticle(article: Data.ContentType<'api::article.article'>) { #### Known components ```typescript -function processUsageMetrics(id: string, metrics: Data.Component<'app.metrics'>) { +function processUsageMetrics( + id: string, + metrics: Data.Component<'app.metrics'> +) { telemetry.send(id, { clicks: metrics.clicks, views: metrics.views }); } ``` + ### Advanced use cases #### Entities subsets @@ -163,7 +170,10 @@ In the following example, the `uid` type is inferred upon usage as `T` and used ```typescript import type { UID } from '@strapi/strapi'; -function display(uid: T, document: Data.ContentType) { +function display( + uid: T, + document: Data.ContentType +) { switch (uid) { case 'api::article.article': { return document.title; @@ -190,9 +200,9 @@ function display(uid: T, document: Data.ContentType; +declare const article: Data.Document<'api::article.article'>; declare const category: Data.Document<'api::category.category'>; -declare const account: Data.Document<'api::account.account'>; +declare const account: Data.Document<'api::account.account'>; display('api::article.article', article); display('api::category.category', category); @@ -201,5 +211,4 @@ display('api::account.account', account); display('api::article.article', category); // ^ Error: "category" is not assignable to parameter of type ContentType<'api::article.article'> - ``` diff --git a/docusaurus/sidebars.js b/docusaurus/sidebars.js index 41f18a3b6b..0183115f85 100644 --- a/docusaurus/sidebars.js +++ b/docusaurus/sidebars.js @@ -15,11 +15,12 @@ /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ const sidebars = { devDocsSidebar: [ - { // Getting Started + { + // Getting Started type: 'category', collapsed: false, label: '🚀 Getting Started', - link: {type: 'doc', id: 'dev-docs/intro'}, + link: { type: 'doc', id: 'dev-docs/intro' }, items: [ { type: 'doc', @@ -40,15 +41,16 @@ const sidebars = { id: 'dev-docs/whats-new', label: "What's new?", customProps: { - udpated: true - } + updated: true, + }, }, 'dev-docs/faq', 'dev-docs/community', 'dev-docs/usage-information', - ] + ], }, - { // Setup & Deployment + { + // Setup & Deployment type: 'category', collapsed: false, label: '⚙️ Setup & Deployment', @@ -65,7 +67,7 @@ const sidebars = { { type: 'category', label: 'Installation', - link: {type: 'doc', id: 'dev-docs/installation'}, + link: { type: 'doc', id: 'dev-docs/installation' }, customProps: { updated: true, }, @@ -83,7 +85,7 @@ const sidebars = { }, }, 'dev-docs/installation/docker', - ] + ], }, 'dev-docs/project-structure', { @@ -133,15 +135,16 @@ const sidebars = { label: '☁️ Strapi Cloud', id: 'cloud/getting-started/deployment', }, - ] - } - ] + ], + }, + ], }, - { // Content APIs + { + // Content APIs type: 'category', collapsed: false, label: '📦 Content API', - link: {type: 'doc', id: 'dev-docs/api/content-api'}, + link: { type: 'doc', id: 'dev-docs/api/content-api' }, items: [ { type: 'doc', @@ -159,7 +162,7 @@ const sidebars = { }, link: { type: 'doc', - id: 'dev-docs/api/rest' + id: 'dev-docs/api/rest', }, items: [ { @@ -174,7 +177,7 @@ const sidebars = { 'dev-docs/api/rest/relations', 'dev-docs/api/rest/interactive-query-builder', 'dev-docs/api/rest/guides/intro', - ] + ], }, { type: 'doc', @@ -222,68 +225,69 @@ const sidebars = { label: 'Document Service API', link: { type: 'doc', - id: 'dev-docs/api/document-service' + id: 'dev-docs/api/document-service', }, customProps: { - new: true + new: true, }, items: [ { type: 'doc', label: 'Introduction & Concepts', - id: 'dev-docs/api/document' + id: 'dev-docs/api/document', }, { type: 'doc', label: 'Available methods', - id: 'dev-docs/api/document-service' + id: 'dev-docs/api/document-service', }, { type: 'doc', label: 'Filters', - id: 'dev-docs/api/document-service/filters' + id: 'dev-docs/api/document-service/filters', }, { type: 'doc', label: 'Populate', - id: 'dev-docs/api/document-service/populate' + id: 'dev-docs/api/document-service/populate', }, { type: 'doc', label: 'Fields', - id: 'dev-docs/api/document-service/fields' + id: 'dev-docs/api/document-service/fields', }, { type: 'doc', label: 'Sort & Pagination', - id: 'dev-docs/api/document-service/sort-pagination' + id: 'dev-docs/api/document-service/sort-pagination', }, { type: 'doc', label: 'Locale', - id: 'dev-docs/api/document-service/locale' + id: 'dev-docs/api/document-service/locale', }, { type: 'doc', label: 'Status', - id: 'dev-docs/api/document-service/status' + id: 'dev-docs/api/document-service/status', }, { type: 'doc', label: 'Middlewares', - id: 'dev-docs/api/document-service/middlewares' + id: 'dev-docs/api/document-service/middlewares', }, - ] + ], }, - ] + ], }, - { // Advanced features + { + // Advanced features type: 'category', label: '🔧 Advanced features', collapsed: false, link: { type: 'doc', - id: 'dev-docs/advanced-features' + id: 'dev-docs/advanced-features', }, items: [ { @@ -314,7 +318,7 @@ const sidebars = { label: 'TypeScript', link: { type: 'doc', - id: 'dev-docs/typescript' + id: 'dev-docs/typescript', }, items: [ 'dev-docs/typescript', @@ -323,25 +327,24 @@ const sidebars = { label: 'TypeScript development', link: { type: 'doc', - id: 'dev-docs/typescript/development' + id: 'dev-docs/typescript/development', }, items: [ - 'dev-docs/typescript/development/api-reference', { type: 'category', label: 'Guides', link: { type: 'doc', - id: 'dev-docs/typescript/development/guides' + id: 'dev-docs/typescript/development/guides', }, items: [ - 'dev-docs/typescript/development/guides/documents-and-entries' + 'dev-docs/typescript/development/guides/documents-and-entries', ], - } + }, ], }, 'dev-docs/typescript/adding-support-to-existing-project', - ] + ], }, { type: 'doc', @@ -354,7 +357,7 @@ const sidebars = { id: 'dev-docs/templates', customProps: { updated: true, - } + }, }, { type: 'category', @@ -375,16 +378,17 @@ const sidebars = { type: 'doc', label: 'Data transfer', id: 'dev-docs/data-management/transfer', - } + }, ], }, 'dev-docs/database-migrations', 'dev-docs/database-transactions', 'dev-docs/testing', 'dev-docs/error-handling', - ] + ], }, - { // Customization + { + // Customization type: 'category', collapsed: false, label: '🛠 Customization', @@ -409,7 +413,7 @@ const sidebars = { }, link: { type: 'doc', - id: 'dev-docs/backend-customization' + id: 'dev-docs/backend-customization', }, items: [ { @@ -428,7 +432,7 @@ const sidebars = { 'dev-docs/backend-customization/services', 'dev-docs/backend-customization/models', 'dev-docs/backend-customization/webhooks', - ] + ], }, { type: 'category', @@ -452,11 +456,12 @@ const sidebars = { 'dev-docs/admin-panel-customization/wysiwyg-editor', 'dev-docs/admin-panel-customization/extension', 'dev-docs/admin-panel-customization/deployment', - ] + ], }, - ] + ], }, - { // Plugins + { + // Plugins type: 'category', collapsed: false, label: '🔌 Plugins', @@ -468,20 +473,20 @@ const sidebars = { { type: 'doc', label: 'Plugins Introduction & Concepts', - id: 'dev-docs/plugins' + id: 'dev-docs/plugins', }, { type: 'category', label: 'Using plugins', link: { type: 'doc', - id: 'dev-docs/plugins/using-plugins' + id: 'dev-docs/plugins/using-plugins', }, items: [ { type: 'doc', label: 'Introduction to using plugins', - id: 'dev-docs/plugins/using-plugins' + id: 'dev-docs/plugins/using-plugins', }, { type: 'doc', @@ -514,7 +519,7 @@ const sidebars = { label: 'Users & Permissions', id: 'dev-docs/plugins/users-permissions', }, - ] + ], }, { type: 'category', @@ -530,7 +535,7 @@ const sidebars = { { type: 'doc', label: 'Introduction to developing plugins', - id: 'dev-docs/plugins/developing-plugins' + id: 'dev-docs/plugins/developing-plugins', }, 'dev-docs/plugins/development/create-a-plugin', { @@ -571,8 +576,8 @@ const sidebars = { customProps: { new: true, }, - } - ] + }, + ], }, { type: 'doc', @@ -592,13 +597,14 @@ const sidebars = { 'dev-docs/plugins/guides/store-and-access-data', 'dev-docs/plugins/guides/pass-data-from-server-to-admin', 'dev-docs/plugins/development/create-a-plugin', - ] - } - ] - } - ] + ], + }, + ], + }, + ], }, - { // Update & Migration + { + // Update & Migration type: 'category', collapsed: false, label: '♻️ Upgrades', @@ -624,19 +630,19 @@ const sidebars = { collapsed: false, link: { type: 'doc', - id: 'dev-docs/migration/v4-to-v5/introduction-and-faq' + id: 'dev-docs/migration/v4-to-v5/introduction-and-faq', }, label: 'Upgrade to Strapi 5', items: [ { type: 'doc', label: 'Introduction and FAQ', - id: 'dev-docs/migration/v4-to-v5/introduction-and-faq' + id: 'dev-docs/migration/v4-to-v5/introduction-and-faq', }, { type: 'doc', label: 'Step-by-step guide', - id: 'dev-docs/migration/v4-to-v5/step-by-step' + id: 'dev-docs/migration/v4-to-v5/step-by-step', }, { type: 'doc', @@ -648,8 +654,8 @@ const sidebars = { label: 'Specific resources', id: 'dev-docs/migration/v4-to-v5/additional-resources/introduction', }, - ] - } + ], + }, ], }, ], @@ -659,8 +665,8 @@ const sidebars = { collapsed: false, label: 'Getting Started', link: { - type: "doc", - id: "user-docs/intro", + type: 'doc', + id: 'user-docs/intro', }, items: [ 'user-docs/intro', @@ -673,7 +679,7 @@ const sidebars = { collapsed: false, link: { type: 'doc', - id: 'user-docs/content-manager/introduction-to-content-manager' + id: 'user-docs/content-manager/introduction-to-content-manager', }, label: 'Content Manager', items: [ @@ -685,7 +691,7 @@ const sidebars = { id: 'user-docs/content-manager/working-with-content-history', customProps: { new: true, - } + }, }, 'user-docs/content-manager/managing-relational-fields', 'user-docs/content-manager/translating-content', @@ -695,7 +701,7 @@ const sidebars = { id: 'user-docs/content-manager/saving-and-publishing-content', customProps: { updated: true, - } + }, }, 'user-docs/content-manager/adding-content-to-releases', ], @@ -705,38 +711,38 @@ const sidebars = { collapsed: false, label: 'Content-type Builder', link: { - type: "doc", - id: "user-docs/content-type-builder/introduction-to-content-types-builder", + type: 'doc', + id: 'user-docs/content-type-builder/introduction-to-content-types-builder', }, items: [ { type: 'autogenerated', - dirName: 'user-docs/content-type-builder' - } - ] + dirName: 'user-docs/content-type-builder', + }, + ], }, { type: 'category', collapsed: false, label: 'Media Library', link: { - type: "doc", - id: "user-docs/media-library/introduction-to-the-media-library", + type: 'doc', + id: 'user-docs/media-library/introduction-to-the-media-library', }, items: [ { type: 'autogenerated', - dirName: 'user-docs/media-library' - } - ] + dirName: 'user-docs/media-library', + }, + ], }, { - type: "category", + type: 'category', collapsed: false, - label: "Releases", + label: 'Releases', link: { - type: "doc", - id: "user-docs/releases/introduction", + type: 'doc', + id: 'user-docs/releases/introduction', }, items: [ 'user-docs/releases/introduction', @@ -749,38 +755,38 @@ const sidebars = { collapsed: false, label: 'Users, Roles & Permissions', link: { - type: "doc", - id: "user-docs/users-roles-permissions/introduction-to-users-roles-permissions", + type: 'doc', + id: 'user-docs/users-roles-permissions/introduction-to-users-roles-permissions', }, items: [ { type: 'autogenerated', - dirName: 'user-docs/users-roles-permissions' - } - ] + dirName: 'user-docs/users-roles-permissions', + }, + ], }, { type: 'category', collapsed: false, label: 'Plugins', link: { - type: "doc", - id: "user-docs/plugins/introduction-to-plugins", + type: 'doc', + id: 'user-docs/plugins/introduction-to-plugins', }, items: [ { type: 'autogenerated', - dirName: 'user-docs/plugins' - } - ] + dirName: 'user-docs/plugins', + }, + ], }, { type: 'category', collapsed: false, label: 'Settings', link: { - type: "doc", - id: "user-docs/settings/introduction", + type: 'doc', + id: 'user-docs/settings/introduction', }, items: [ 'user-docs/settings/introduction', @@ -792,7 +798,7 @@ const sidebars = { label: 'Configuring global settings', link: { type: 'doc', - id: 'user-docs/settings/introduction' + id: 'user-docs/settings/introduction', }, items: [ 'user-docs/settings/admin-panel', @@ -807,48 +813,48 @@ const sidebars = { }, 'user-docs/settings/single-sign-on', 'user-docs/settings/transfer-tokens', - ] + ], }, ], }, ], cloudSidebar: [ { - type: "category", + type: 'category', collapsed: false, - label: "Getting Started", + label: 'Getting Started', link: { - type: "doc", - id: "cloud/getting-started/intro", + type: 'doc', + id: 'cloud/getting-started/intro', }, items: [ - "cloud/getting-started/intro", + 'cloud/getting-started/intro', { - type: "doc", - label: "Cloud fundamentals", - id: "cloud/getting-started/cloud-fundamentals", + type: 'doc', + label: 'Cloud fundamentals', + id: 'cloud/getting-started/cloud-fundamentals', customProps: { new: false, }, }, { - type: "category", - label: "Project deployment", - link: {type: "doc", id: "cloud/getting-started/deployment-options"}, + type: 'category', + label: 'Project deployment', + link: { type: 'doc', id: 'cloud/getting-started/deployment-options' }, customProps: { updated: false, }, items: [ { - type: "doc", - id: "cloud/getting-started/deployment", + type: 'doc', + id: 'cloud/getting-started/deployment', customProps: { updated: true, }, }, { - type: "doc", - id: "cloud/getting-started/deployment-cli", + type: 'doc', + id: 'cloud/getting-started/deployment-cli', customProps: { new: true, }, @@ -856,66 +862,66 @@ const sidebars = { ], }, { - type: "doc", - id: "cloud/getting-started/usage-billing", + type: 'doc', + id: 'cloud/getting-started/usage-billing', customProps: { updated: false, }, }, - "cloud/getting-started/caching", + 'cloud/getting-started/caching', { - type: "doc", - label: "Notifications", - id: "cloud/projects/notifications", + type: 'doc', + label: 'Notifications', + id: 'cloud/projects/notifications', }, ], }, { - type: "category", + type: 'category', collapsed: false, - label: "Projects management", + label: 'Projects management', link: { - type: "doc", - id: "cloud/projects/overview", + type: 'doc', + id: 'cloud/projects/overview', }, items: [ - "cloud/projects/overview", + 'cloud/projects/overview', { - type: "doc", - label: "Project settings", - id: "cloud/projects/settings", + type: 'doc', + label: 'Project settings', + id: 'cloud/projects/settings', customProps: { updated: true, }, }, - "cloud/projects/collaboration", - "cloud/projects/runtime-logs", + 'cloud/projects/collaboration', + 'cloud/projects/runtime-logs', ], }, { - type: "category", + type: 'category', collapsed: false, - label: "Deployments", + label: 'Deployments', link: { - type: "doc", - id: "cloud/projects/deploys", + type: 'doc', + id: 'cloud/projects/deploys', }, - items: ["cloud/projects/deploys", "cloud/projects/deploys-history"], + items: ['cloud/projects/deploys', 'cloud/projects/deploys-history'], }, { - type: "category", + type: 'category', collapsed: false, - label: "Account management", + label: 'Account management', link: { - type: "doc", - id: "cloud/account/account-settings", + type: 'doc', + id: 'cloud/account/account-settings', }, items: [ - "cloud/account/account-settings", + 'cloud/account/account-settings', { - type: "doc", - id: "cloud/account/account-billing", - label: "Account billing & invoices", + type: 'doc', + id: 'cloud/account/account-billing', + label: 'Account billing & invoices', customProps: { updated: false, }, @@ -923,18 +929,18 @@ const sidebars = { ], }, { - type: "category", + type: 'category', collapsed: false, - label: "Command Line Interface", + label: 'Command Line Interface', link: { - type: "doc", - id: "cloud/cli/cloud-cli", + type: 'doc', + id: 'cloud/cli/cloud-cli', }, items: [ { - type: "doc", - id: "cloud/cli/cloud-cli", - label: "Strapi Cloud CLI", + type: 'doc', + id: 'cloud/cli/cloud-cli', + label: 'Strapi Cloud CLI', customProps: { updated: true, }, @@ -942,27 +948,27 @@ const sidebars = { ], }, { - type: "category", + type: 'category', collapsed: false, - label: "Advanced configuration", + label: 'Advanced configuration', link: { - type: "doc", - id: "cloud/advanced/database", + type: 'doc', + id: 'cloud/advanced/database', }, items: [ - "cloud/advanced/database", + 'cloud/advanced/database', { - type: "doc", - id: "cloud/advanced/email", - label: "Email provider", + type: 'doc', + id: 'cloud/advanced/email', + label: 'Email provider', customProps: { new: false, }, }, { - type: "doc", - id: "cloud/advanced/upload", - label: "Upload provider", + type: 'doc', + id: 'cloud/advanced/upload', + label: 'Upload provider', customProps: { new: false, }, @@ -974,7 +980,7 @@ const sidebars = { { type: 'link', label: '⬅️ Back to Dev Docs content', - href: '/dev-docs/intro' + href: '/dev-docs/intro', }, { type: 'category', @@ -982,13 +988,13 @@ const sidebars = { label: 'REST API reference', link: { type: 'doc', - id: 'dev-docs/api/rest' + id: 'dev-docs/api/rest', }, items: [ { type: 'category', label: 'Endpoints and basic requests', - link: {type: 'doc', id: 'dev-docs/api/rest'}, + link: { type: 'doc', id: 'dev-docs/api/rest' }, collapsed: false, items: [ { @@ -999,43 +1005,43 @@ const sidebars = { { type: 'link', label: 'Get documents', - href: '/dev-docs/api/rest#get-all' + href: '/dev-docs/api/rest#get-all', }, { type: 'link', label: 'Get a document', - href: '/dev-docs/api/rest#get' + href: '/dev-docs/api/rest#get', }, { type: 'link', label: 'Create a document', - href: '/dev-docs/api/rest#create' + href: '/dev-docs/api/rest#create', }, { type: 'link', label: 'Update a document', - href: '/dev-docs/api/rest#update' + href: '/dev-docs/api/rest#update', }, { type: 'link', label: 'Delete a document', - href: '/dev-docs/api/rest#delete' + href: '/dev-docs/api/rest#delete', }, - ] + ], }, { type: 'doc', id: 'dev-docs/api/rest/interactive-query-builder', - label: '✨ Interactive Query Builder' + label: '✨ Interactive Query Builder', }, { type: 'doc', - id: 'dev-docs/api/rest/parameters' + id: 'dev-docs/api/rest/parameters', }, { type: 'category', label: 'Populate and Select', - link: {type: 'doc', id: 'dev-docs/api/rest/populate-select'}, + link: { type: 'doc', id: 'dev-docs/api/rest/populate-select' }, collapsed: false, items: [ { @@ -1048,18 +1054,21 @@ const sidebars = { label: 'Population', href: '/dev-docs/api/rest/populate-select#population', }, - ] + ], }, { type: 'category', collapsed: false, label: 'Filters, Locale, Publication State', - link: {type: 'doc', id: 'dev-docs/api/rest/filters-locale-publication'}, + link: { + type: 'doc', + id: 'dev-docs/api/rest/filters-locale-publication', + }, items: [ { type: 'link', label: 'Filtering', - href: '/dev-docs/api/rest/filters-locale-publication#filtering' + href: '/dev-docs/api/rest/filters-locale-publication#filtering', }, { type: 'link', @@ -1087,58 +1096,58 @@ const sidebars = { type: 'category', collapsed: false, label: 'Sort and Pagination', - link: {type: 'doc', id: 'dev-docs/api/rest/sort-pagination'}, + link: { type: 'doc', id: 'dev-docs/api/rest/sort-pagination' }, items: [ { type: 'link', label: 'Sorting', - href: '/dev-docs/api/rest/sort-pagination#sorting' + href: '/dev-docs/api/rest/sort-pagination#sorting', }, { type: 'link', label: 'Pagination', - href: '/dev-docs/api/rest/sort-pagination#pagination' + href: '/dev-docs/api/rest/sort-pagination#pagination', }, { type: 'link', label: 'Pagination by page', - href: '/dev-docs/api/rest/sort-pagination#pagination-by-page' + href: '/dev-docs/api/rest/sort-pagination#pagination-by-page', }, { type: 'link', label: 'Pagination by offset', - href: '/dev-docs/api/rest/sort-pagination#pagination-by-offset' + href: '/dev-docs/api/rest/sort-pagination#pagination-by-offset', }, - ] + ], }, { type: 'category', collapsed: false, label: 'Relations', - link: {type: 'doc', id: 'dev-docs/api/rest/relations'}, + link: { type: 'doc', id: 'dev-docs/api/rest/relations' }, items: [ { type: 'link', label: 'connect', - href: '/dev-docs/api/rest/relations#connect' + href: '/dev-docs/api/rest/relations#connect', }, { type: 'link', label: 'disconnect', - href: '/dev-docs/api/rest/relations#disconnect' + href: '/dev-docs/api/rest/relations#disconnect', }, { type: 'link', label: 'set', - href: '/dev-docs/api/rest/relations#set' + href: '/dev-docs/api/rest/relations#set', }, - ] + ], }, - ] + ], }, { - type: "category", - label: "Rest API guides", + type: 'category', + label: 'Rest API guides', collapsed: false, link: { type: 'doc', @@ -1146,28 +1155,28 @@ const sidebars = { }, items: [ { - type: "doc", - label: "Understanding populate", + type: 'doc', + label: 'Understanding populate', id: 'dev-docs/api/rest/guides/understanding-populate', }, { - type: "doc", - label: "How to populate creator fields", + type: 'doc', + label: 'How to populate creator fields', id: 'dev-docs/api/rest/guides/populate-creator-fields', }, { type: 'link', label: 'Additional resources', - href: '/dev-docs/api/rest/guides/intro#additional-resources' + href: '/dev-docs/api/rest/guides/intro#additional-resources', }, ], - } + }, ], devDocsConfigSidebar: [ { type: 'link', label: '⬅️ Back to Dev Docs content', - href: '/dev-docs/intro' + href: '/dev-docs/intro', }, { type: 'category', @@ -1189,7 +1198,7 @@ const sidebars = { label: 'Base configurations', link: { type: 'doc', - id: 'dev-docs/configurations' + id: 'dev-docs/configurations', }, items: [ 'dev-docs/configurations/database', @@ -1197,7 +1206,7 @@ const sidebars = { 'dev-docs/configurations/admin-panel', 'dev-docs/configurations/middlewares', 'dev-docs/configurations/api', - ] + ], }, { type: 'category', @@ -1205,7 +1214,7 @@ const sidebars = { collapsed: false, link: { type: 'doc', - id: 'dev-docs/configurations' + id: 'dev-docs/configurations', }, items: [ 'dev-docs/configurations/plugins', @@ -1216,7 +1225,7 @@ const sidebars = { 'dev-docs/configurations/environment', 'dev-docs/configurations/sso', 'dev-docs/configurations/features', - ] + ], }, { type: 'category', @@ -1224,7 +1233,7 @@ const sidebars = { collapsed: false, link: { type: 'doc', - id: 'dev-docs/configurations' + id: 'dev-docs/configurations', }, items: [ 'dev-docs/configurations/guides/rbac', @@ -1232,23 +1241,23 @@ const sidebars = { 'dev-docs/configurations/guides/access-cast-environment-variables', 'dev-docs/configurations/guides/access-configuration-values', 'dev-docs/configurations/guides/use-cron-jobs', - ] - } - ] + ], + }, + ], }, ], devDocsMigrationV5Sidebar: [ { type: 'link', label: '⬅️ Back to Dev Docs content', - href: '/dev-docs/intro' + href: '/dev-docs/intro', }, { type: 'category', collapsed: false, link: { type: 'doc', - id: 'dev-docs/migration/v4-to-v5/introduction-and-faq' + id: 'dev-docs/migration/v4-to-v5/introduction-and-faq', }, label: 'Upgrade to Strapi 5', customProps: { @@ -1256,52 +1265,54 @@ const sidebars = { }, items: [ { - type: "doc", - label: "Introduction and FAQ", - id: "dev-docs/migration/v4-to-v5/introduction-and-faq" + type: 'doc', + label: 'Introduction and FAQ', + id: 'dev-docs/migration/v4-to-v5/introduction-and-faq', }, { - type: "doc", - label: "Step-by-step guide", - id: "dev-docs/migration/v4-to-v5/step-by-step" + type: 'doc', + label: 'Step-by-step guide', + id: 'dev-docs/migration/v4-to-v5/step-by-step', }, { - type: "doc", - label: "Upgrade tool reference", + type: 'doc', + label: 'Upgrade tool reference', id: 'dev-docs/upgrade-tool', }, { - type: "category", + type: 'category', collapsible: true, collapsed: true, - label: "Breaking changes", + label: 'Breaking changes', link: { type: 'doc', - id: 'dev-docs/migration/v4-to-v5/breaking-changes' + id: 'dev-docs/migration/v4-to-v5/breaking-changes', }, items: [ { - type: "autogenerated", - dirName: 'dev-docs/migration/v4-to-v5/breaking-changes' + type: 'autogenerated', + dirName: 'dev-docs/migration/v4-to-v5/breaking-changes', }, - ] + ], }, { type: 'category', label: 'Specific resources', collapsed: false, - link: {type: 'doc', id: 'dev-docs/migration/v4-to-v5/additional-resources/introduction'}, + link: { + type: 'doc', + id: 'dev-docs/migration/v4-to-v5/additional-resources/introduction', + }, items: [ 'dev-docs/migration/v4-to-v5/additional-resources/introduction', 'dev-docs/migration/v4-to-v5/additional-resources/from-entity-service-to-document-service', 'dev-docs/migration/v4-to-v5/additional-resources/plugins-migration', 'dev-docs/migration/v4-to-v5/additional-resources/helper-plugin', - ] - } - ] + ], + }, + ], }, - - ] + ], }; module.exports = sidebars; From 42e6e3f2868f3024d5dd8c612ec14cdfb05a6e92 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 6 Nov 2024 12:18:46 +0100 Subject: [PATCH 19/20] remove link to api reference --- docusaurus/docs/dev-docs/typescript/development.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index d213b3dcdc..4d002eefd5 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -18,10 +18,6 @@ This page provides a comprehensive guide to developing with TypeScript in Strapi We are preparing an API reference page, which will include an exhaustive list of the types exported by Strapi. Please come back soon! 👀 ::: -The API reference is an exhaustive list of the types exported by Strapi. - -It's automatically generated based on the code and can be found [here](/dev-docs/typescript/development/api-reference). - ## :books: Guides The guides are a curated list of common examples in which you might need to use Strapi types in your application. From 38faf6d3e68d0c257665d8435bdc3f4543d7440a Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 6 Nov 2024 14:18:19 +0100 Subject: [PATCH 20/20] Update docusaurus/docs/dev-docs/typescript/development.md --- docusaurus/docs/dev-docs/typescript/development.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docusaurus/docs/dev-docs/typescript/development.md b/docusaurus/docs/dev-docs/typescript/development.md index 4d002eefd5..a2181acfc1 100644 --- a/docusaurus/docs/dev-docs/typescript/development.md +++ b/docusaurus/docs/dev-docs/typescript/development.md @@ -14,7 +14,7 @@ tags: This page provides a comprehensive guide to developing with TypeScript in Strapi v5, covering key patterns and configurations for integrating TypeScript effectively. You'll find sections on using Strapi’s provided types, generating and managing typings for content types, configuring Strapi programmatically, and building plugins with TypeScript. Each section includes practical steps and example code to help you set up and troubleshoot TypeScript-based workflows in your Strapi project. -:::strapi :open_book: API reference +:::strapi API reference We are preparing an API reference page, which will include an exhaustive list of the types exported by Strapi. Please come back soon! 👀 :::