docs: general updates and fixes (#13374)

* docs: general updates and fixes

* fix lint errors
This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-09-02 09:07:07 +03:00
1 parent c717535ca2
commit 24199fa47a
25 files changed
+477 -396

No files matched your search

@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method creates one or more records of the data model.
This method of a module's service creates one or more records of a data model.
The method's name is of the format `createDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Create One Record
@@ -22,7 +24,7 @@ const post = await postModuleService.createPosts({
})
```
If an object is passed of the method, an object of the created record is also returned.
If an object is passed to the method, the created record object is returned.
---
@@ -41,4 +43,4 @@ const posts = await postModuleService.createPosts([
])
```
If an array is passed of the method, an array of the created records is also returned.
If an array of objects is passed to the method, an array containing the created records is returned.
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method deletes one or more records.
This method of a module's service deletes one or more records.
The method's name is `deleteDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Delete One Record
@@ -16,7 +18,7 @@ This method deletes one or more records.
await postModuleService.deletePosts("123")
```
To delete one record, pass its ID as a parameter of the method.
To delete one record, pass its ID as a parameter to the method.
---
@@ -29,7 +31,7 @@ await postModuleService.deletePosts([
])
```
To delete multiple records, pass an array of IDs as a parameter of the method.
To delete multiple records, pass an array of IDs as a parameter to the method.
---
@@ -41,10 +43,10 @@ await postModuleService.deletePosts({
})
```
To delete records matching a set of filters, pass an object of filters as a parameter.
To delete records matching a set of filters, pass an object of filters as a parameter to the method.
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method retrieves a list of records.
This method of a module's service retrieves a list of records.
The method's name is `listDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Retrieve List of Records
@@ -30,11 +32,11 @@ const posts = await postModuleService.listPosts({
### Parameters
To retrieve records matching a set of filters, pass an object of the filters as a first parameter.
To retrieve records matching a set of filters, pass an object of the filters as the first parameter.
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
@@ -60,7 +62,7 @@ const posts = await postModuleService.listPosts({}, {
### Parameters
To retrieve records with their relations, pass as a second parameter an object having a `relations` property. `relations`'s value is an array of relation names.
To retrieve records with their relations, pass an object with a `relations` property as the second parameter. `relations`'s value is an array of relation names.
### Returns
@@ -78,7 +80,7 @@ const posts = await postModuleService.listPosts({}, {
### Parameters
By default, retrieved records have all their properties. To select specific properties to retrieve, pass in the second object parameter a `select` property.
By default, retrieved records have all their properties. To select specific properties to retrieve, pass a `select` property in the second object parameter.
`select`'s value is an array of property names to retrieve.
@@ -88,7 +90,7 @@ The method returns an array of the first `15` records matching the filters.
---
## Paginate Relations
## Paginate Records
```ts
const posts = await postModuleService.listPosts({}, {
@@ -122,7 +124,7 @@ const posts = await postModuleService.listPosts({}, {
### Parameters
To sort records by one or more properties, pass to the second object parameter the `order` property. Its value is an object whose keys are the property names, and values can either be:
To sort records by one or more properties, pass an `order` property in the second object parameter. Its value is an object whose keys are the property names, and values can either be:
- `ASC` to sort by this property in the ascending order.
- `DESC` to sort by this property in the descending order.
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method retrieves a list of records with the total count.
This method of a module's service retrieves a list of records with the total count.
The method's name is `listAndCountDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Retrieve List of Records
@@ -33,11 +35,11 @@ const [posts, count] = await postModuleService.listAndCountPosts({
### Parameters
To retrieve records matching a set of filters, pass an object of the filters as a first parameter.
To retrieve records matching a set of filters, pass an object of the filters as the first parameter.
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
@@ -66,7 +68,7 @@ const [posts, count] = await postModuleService.listAndCountPosts({}, {
### Parameters
To retrieve records with their relations, pass as a second parameter an object having a `relations` property. Its value is an array of relation names.
To retrieve records with their relations, pass an object with a `relations` property as the second parameter. Its value is an array of relation names.
### Returns
@@ -87,7 +89,7 @@ const [posts, count] = await postModuleService.listAndCountPosts({}, {
### Parameters
By default, retrieved records have all their properties. To select specific properties to retrieve, pass in the second object parameter a `select` property.
By default, retrieved records have all their properties. To select specific properties to retrieve, pass a `select` property in the second object parameter.
`select`'s value is an array of property names to retrieve.
@@ -100,7 +102,7 @@ The method returns an array with two items:
---
## Paginate Relations
## Paginate Records
```ts
const [posts, count] = await postModuleService.listAndCountPosts({}, {
@@ -137,7 +139,7 @@ const [posts, count] = await postModuleService.listAndCountPosts({}, {
### Parameters
To sort records by one or more properties, pass to the second object parameter the `order` property. Its value is an object whose keys are the property names, and values can either be:
To sort records by one or more properties, pass an `order` property in the second object parameter. Its value is an object whose keys are the property names, and values can either be:
- `ASC` to sort by this property in the ascending order.
- `DESC` to sort by this property in the descending order.
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method restores one or more records of the data model that were [soft-deleted](../soft-delete/page.mdx).
This method of a module's service restores one or more records of a data model that were [soft-deleted](../soft-delete/page.mdx).
The method's name is of the format `restoreDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Restore One Record
@@ -18,7 +20,7 @@ const restoredPosts = await postModuleService.restorePosts("123")
### Parameters
To restore one record, pass its ID as a parameter of the method.
To restore one record, pass its ID as a parameter to the method.
### Returns
@@ -26,9 +28,9 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
restoredPosts = {
post_id: ["123"],
```json
{
"post_id": ["123"],
}
```
@@ -45,7 +47,7 @@ const restoredPosts = await postModuleService.restorePosts([
### Parameters
To restore multiple records, pass an array of IDs as a parameter of the method.
To restore multiple records, pass an array of IDs as a parameter to the method.
### Returns
@@ -53,9 +55,9 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
restoredPosts = {
post_id: [
```json
{
"post_id": [
"123",
"321",
],
@@ -74,11 +76,11 @@ const restoredPosts = await postModuleService.restorePosts({
### Parameters
To restore records matching a set of filters, pass an object of fitlers as a parameter of the method.
To restore records matching a set of filters, pass an object of filters as a parameter to the method.
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
@@ -88,9 +90,9 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
restoredPosts = {
post_id: [
```json
{
"post_id": [
"123",
],
}
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method retrieves one record of the data model by its ID.
This method retrieves one record of a data model by its ID.
The method's name is `retrieveDataModel`, where `DataModel` is the singular pascal-case name of the data model.
## Retrieve a Record
@@ -42,7 +44,7 @@ const post = await postModuleService.retrievePost("123", {
### Parameters
To retrieve the data model with relations, pass as a second parameter of the method an object with the property `relations`. `relations`'s value is an array of relation names.
To retrieve the data model with relations, pass an object with the property `relations` as the second parameter. `relations`'s value is an array of relation names.
### Returns
@@ -60,7 +62,7 @@ const post = await postModuleService.retrievePost("123", {
### Parameters
By default, all of the record's properties are retrieved. To select specific ones, pass in the second object parameter a `select` property. Its value is an array of property names.
By default, all of the record's properties are retrieved. To select specific ones, pass a `select` property in the second object parameter. Its value is an array of property names.
### Returns
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method soft deletes one or more records of the data model.
This method of a module's service soft deletes one or more records of a data model.
The method's name is of the format `softDeleteDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Soft Delete One Record
@@ -20,7 +22,7 @@ const deletedPosts = await postModuleService.softDeletePosts(
### Parameters
To soft delete a record, pass its ID as a parameter of the method.
To soft delete a record, pass its ID as a parameter to the method.
### Returns
@@ -28,9 +30,9 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
deletedPosts = {
post_id: ["123"],
```json
{
"post_id": ["123"]
}
```
@@ -47,7 +49,7 @@ const deletedPosts = await postModuleService.softDeletePosts([
### Parameters
To soft delete multiple records, pass an array of IDs as a parameter of the method.
To soft delete multiple records, pass an array of IDs as a parameter to the method.
### Returns
@@ -55,12 +57,12 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
deletedPosts = {
post_id: [
```json
{
"post_id": [
"123",
"321",
],
"321"
]
}
```
@@ -76,11 +78,11 @@ const deletedPosts = await postModuleService.softDeletePosts({
### Parameters
To soft delete records matching a set of filters, pass an object of filters as a parameter.
To soft delete records matching a set of filters, pass an object of filters as a parameter to the method.
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
@@ -90,8 +92,8 @@ The method returns an object, whose keys are of the format `{camel_case_data_mod
For example, the returned object of the above example is:
```ts
deletedPosts = {
post_id: ["123"],
```json
{
"post_id": ["123"]
}
```
@@ -8,7 +8,9 @@ export const metadata = {
# {metadata.title}
This method updates one or more records of the data model.
This method of a module's service updates one or more records.
The method's name is `updateDataModel`, where `DataModel` is the plural pascal-case name of the data model.
## Update One Record
@@ -21,7 +23,7 @@ const post = await postModuleService.updatePosts({
### Parameters
To update one record, pass an object that at least has an `id` property, identifying the ID of the record to update.
To update one record, pass an object that has at least an `id` property, identifying the ID of the record to update.
You can pass in the same object any other properties to update.
@@ -48,13 +50,13 @@ const posts = await postModuleService.updatePosts([
### Parameters
To update multiple records, pass an array of objects. Each object has at least an `id` property, identifying the ID of the record to update.
To update multiple records, pass an array of objects. Each object must have at least an `id` property, identifying the ID of the record to update.
You can pass in each object any other properties to update.
### Returns
The method returns an array of objects of updated records.
The method returns an array of updated record objects.
---
@@ -73,7 +75,7 @@ const posts = await postModuleService.updatePosts({
### Parameters
To update records that match specified filters, pass as a parameter an object having two properties:
To update records that match specified filters, pass an object with two properties as a parameter:
- `selector`: An object of filters that a record must match to be updated.
- `data`: An object of the properties to update in every record that match the filters in `selector`.
@@ -82,13 +84,13 @@ In the example above, you update the `published_at` property of every post recor
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
### Returns
The method returns an array of objects of updated records.
The method returns an array of updated record objects.
---
@@ -128,19 +130,23 @@ In the example above, you update the `published_at` property of post records who
<Note>
Learn more about accepted filters in [this documentation](../../tips/filtering/page.mdx).
Refer to the [Filtering](../../tips/filtering/page.mdx) reference for more information on accepted filters and examples.
</Note>
### Returns
The method returns an array of objects of updated records.
The method returns an array of updated record objects.
---
## Update a JSON Property
```ts
export const highlights = [
["4", "metadata", "`metadata` is a JSON property."]
]
```ts highlights={highlights}
const post = await postModuleService.updatePosts({
id: "123",
name: "My Post",
@@ -151,13 +157,14 @@ const post = await postModuleService.updatePosts({
})
```
When you have a JSON property in your data model, you can update it by adding, updating, or removing properties within that JSON object. Medusa will merge the properties you pass in the `update` method with the existing JSON object.
When you have a [JSON property](!docs!/learn/fundamentals/data-models/json-properties) in your data model, you can update it by adding, updating, or removing properties within that JSON object. Medusa will merge the properties you pass in the `update` method with the existing JSON object.
### Remove a Property from the JSON Property
```ts
```ts highlights={highlights}
const post = await postModuleService.updatePosts({
id: "123",
name: "My Post",
metadata: {
is_featured: "",
},
@@ -18,22 +18,22 @@ Refer to the [Service Factory](!docs!/learn/fundamentals/modules/service-factory
When your module's main service extends the service factory, Medusa will:
1. Generate data-management methods in your main service for each of the data models passed to the `MedusaService` function.
2. Generate internal services for each of the data models passed to the `MedusaService` function, which can be resolved in loaders.
1. Generate [data-management methods in your main service](#main-service-methods) for each of the data models passed to the `MedusaService` function.
2. Generate [internal services](#internal-generated-service-methods) for each of the data models passed to the `MedusaService` function, which can be resolved in loaders.
### Main Service Methods
The names of the generated methods for a service extending the service factory are of the format `{operationName}_{dataModelName}`, where:
The names of the generated methods for a service extending the service factory are of the format `{operationName}{DataModelName}`, where:
- `{operationName}` is the name of the operation. For example, `create`.
- `{dataModelName}` is the pascal-case version of the data model's key that's passed in the object parameter of `MedusaService`. The name is pluralized for all operations except the `retrieve` operation.
- `{DataModelName}` is the pascal-case version of the data model's key that's passed in the object parameter of `MedusaService`. The name is pluralized for all operations except the `retrieve` operation.
Some examples of method names:
- `createPosts`
- `createMyPosts`
- `retrievePost`
- `listPosts`
- `createPosts` (`Post` data model)
- `createMyPosts` (`MyPost` data model)
- `retrievePost` (`Post` data model)
- `listPosts` (`Post` data model)
### Internal Generated Service Methods