chore(docs): DML API Reference (#7863)
* added dml options * added tsdocs + configurations
This commit is contained in:
1 parent
9ded63cc62
commit
72f7500c84
20 files changed
+742
-104
No files matched your search
@@ -65,6 +65,11 @@ export type PropertyType<T> = {
|
|||||||
* Options accepted by all the relationships
|
* Options accepted by all the relationships
|
||||||
*/
|
*/
|
||||||
export type RelationshipOptions = {
|
export type RelationshipOptions = {
|
||||||
|
/**
|
||||||
|
* The name of the relationship as defined
|
||||||
|
* in the other data model. This is only required
|
||||||
|
* by the `belongsTo` relationship method.
|
||||||
|
*/
|
||||||
mappedBy?: string
|
mappedBy?: string
|
||||||
} & Record<string, any>
|
} & Record<string, any>
|
||||||
|
|
||||||
@@ -152,6 +157,10 @@ export type ExtractEntityRelations<
|
|||||||
* relationship.
|
* relationship.
|
||||||
*/
|
*/
|
||||||
export type EntityCascades<Relationships> = {
|
export type EntityCascades<Relationships> = {
|
||||||
|
/**
|
||||||
|
* The related models to delete when a record of this data model
|
||||||
|
* is deleted.
|
||||||
|
*/
|
||||||
delete?: Relationships
|
delete?: Relationships
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,9 +195,23 @@ export type EntityIndex<
|
|||||||
TSchema extends DMLSchema = DMLSchema,
|
TSchema extends DMLSchema = DMLSchema,
|
||||||
TWhere = string
|
TWhere = string
|
||||||
> = {
|
> = {
|
||||||
|
/**
|
||||||
|
* The name of the index. If not provided,
|
||||||
|
* Medusa generates the name.
|
||||||
|
*/
|
||||||
name?: string
|
name?: string
|
||||||
|
/**
|
||||||
|
* When enabled, a unique index is created on the specified
|
||||||
|
* properties.
|
||||||
|
*/
|
||||||
unique?: boolean
|
unique?: boolean
|
||||||
|
/**
|
||||||
|
* The list of properties to create the index on.
|
||||||
|
*/
|
||||||
on: InferIndexableProperties<IDmlEntity<TSchema>>[]
|
on: InferIndexableProperties<IDmlEntity<TSchema>>[]
|
||||||
|
/**
|
||||||
|
* Conditions to restrict which records are indexed.
|
||||||
|
*/
|
||||||
where?: TWhere
|
where?: TWhere
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,43 @@ import { ManyToMany } from "./relations/many-to-many"
|
|||||||
*/
|
*/
|
||||||
const IMPLICIT_PROPERTIES = ["created_at", "updated_at", "deleted_at"]
|
const IMPLICIT_PROPERTIES = ["created_at", "updated_at", "deleted_at"]
|
||||||
|
|
||||||
type DefineOptions = string | { name?: string; tableName: string }
|
export type DefineOptions = string | {
|
||||||
|
/**
|
||||||
|
* The data model's name.
|
||||||
|
*/
|
||||||
|
name?: string
|
||||||
|
/**
|
||||||
|
* The name of the data model's table in the database.
|
||||||
|
*/
|
||||||
|
tableName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ManyToManyOptions = RelationshipOptions &
|
||||||
|
(
|
||||||
|
| {
|
||||||
|
/**
|
||||||
|
* The name of the pivot table
|
||||||
|
* created in the database for this relationship.
|
||||||
|
*/
|
||||||
|
pivotTable?: string
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
pivotEntity?: never
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
pivotTable?: never
|
||||||
|
/**
|
||||||
|
* A function that returns the data model
|
||||||
|
* representing the pivot table created in the
|
||||||
|
* database for this relationship.
|
||||||
|
*/
|
||||||
|
pivotEntity?: () => DmlEntity<any>
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity builder exposes the API to create an entity and define its
|
* Entity builder exposes the API to create an entity and define its
|
||||||
@@ -44,8 +80,23 @@ export class EntityBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an entity or a model. The name should be unique across
|
* This method defines a data model.
|
||||||
* all the entities.
|
*
|
||||||
|
* @typeParam Schema - The type of the accepted schema in the second parameter of the method.
|
||||||
|
*
|
||||||
|
* @param {DefineOptions} nameOrConfig - Either the data model's name, or configurations to name the data model.
|
||||||
|
* The data model's name must be unique.
|
||||||
|
* @param {Schema} schema - The schema of the data model's properties.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* name: model.text(),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
*/
|
*/
|
||||||
define<Schema extends DMLSchema>(
|
define<Schema extends DMLSchema>(
|
||||||
nameOrConfig: DefineOptions,
|
nameOrConfig: DefineOptions,
|
||||||
@@ -62,36 +113,102 @@ export class EntityBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an id property. Id properties are marked
|
* This method defines an automatically generated string ID property.
|
||||||
* primary by default
|
*
|
||||||
|
* By default, this property is considered to be the data model’s primary key.
|
||||||
|
*
|
||||||
|
* @param {ConstructorParameters<typeof IdProperty>[0]} options - The ID's options.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
id(options?: ConstructorParameters<typeof IdProperty>[0]) {
|
id(options?: ConstructorParameters<typeof IdProperty>[0]) {
|
||||||
return new IdProperty(options)
|
return new IdProperty(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a text/string based column
|
* This method defines a string property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* name: model.text(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
text() {
|
text() {
|
||||||
return new TextProperty()
|
return new TextProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a boolean column
|
* This method defines a boolean property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* hasAccount: model.boolean(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
boolean() {
|
boolean() {
|
||||||
return new BooleanProperty()
|
return new BooleanProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an integer column
|
* This method defines a number property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* age: model.number(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
number() {
|
number() {
|
||||||
return new NumberProperty()
|
return new NumberProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a numeric column. This property produces an additional
|
* This method defines a number property that expects large numbers, such as prices.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* price: model.bigNumber(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
|
*
|
||||||
|
* @privateRemarks
|
||||||
|
* This property produces an additional
|
||||||
* column - raw_{{ property_name }}, which stores the configuration
|
* column - raw_{{ property_name }}, which stores the configuration
|
||||||
* of bignumber (https://github.com/MikeMcl/bignumber.js)
|
* of bignumber (https://github.com/MikeMcl/bignumber.js)
|
||||||
*/
|
*/
|
||||||
@@ -100,94 +217,198 @@ export class EntityBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an array column
|
* This method defines an array of strings property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* names: model.array(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
array() {
|
array() {
|
||||||
return new ArrayProperty()
|
return new ArrayProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a timestampz column
|
* This method defines a timestamp property.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* date_of_birth: model.dateTime(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
dateTime() {
|
dateTime() {
|
||||||
return new DateTimeProperty()
|
return new DateTimeProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a JSON column to store data as a
|
* This method defines a property whose value is a stringified JSON object.
|
||||||
* JSON string
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* metadata: model.json(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
json() {
|
json() {
|
||||||
return new JSONProperty()
|
return new JSONProperty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an enum column where only a pre-defined set
|
* This method defines a property whose value can only be one of the specified values.
|
||||||
* of values are allowed.
|
*
|
||||||
|
* @typeParam Values - The type of possible values. By default, it's `string`.
|
||||||
|
*
|
||||||
|
* @param {Values[]} values - An array of possible values.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* color: model.enum(["black", "white"]),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Types
|
||||||
*/
|
*/
|
||||||
enum<const Values extends unknown>(values: Values[]) {
|
enum<const Values extends unknown>(values: Values[]) {
|
||||||
return new EnumProperty<Values>(values)
|
return new EnumProperty<Values>(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has one relationship defines a relationship between two entities
|
* This method defines a relationship between two data models,
|
||||||
* where the owner of the relationship has exactly one instance
|
* where the owner of the relationship has one record of the related
|
||||||
* of the related entity.
|
* data model.
|
||||||
*
|
*
|
||||||
* For example: A user "hasOne" profile
|
* For example: A user "hasOne" email.
|
||||||
*
|
*
|
||||||
* You may use the "belongsTo" relationship to define the inverse
|
* Use the {@link belongsTo} method to define the inverse of this relationship in
|
||||||
* of the "hasOne" relationship
|
* the other data model.
|
||||||
|
*
|
||||||
|
* @typeParam T - The type of the entity builder passed as a first parameter. By default, it's
|
||||||
|
* a function returning the related model.
|
||||||
|
*
|
||||||
|
* @param {T} entityBuilder - A function that returns the data model this model is related to.
|
||||||
|
* @param {RelationshipOptions} options - The relationship's options.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const User = model.define("user", {
|
||||||
|
* id: model.id(),
|
||||||
|
* email: model.hasOne(() => Email),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @customNamespace Relationship Methods
|
||||||
*/
|
*/
|
||||||
hasOne<T>(entityBuilder: T, options?: RelationshipOptions) {
|
hasOne<T>(entityBuilder: T, options?: RelationshipOptions) {
|
||||||
return new HasOne<T>(entityBuilder, options || {})
|
return new HasOne<T>(entityBuilder, options || {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define inverse of "hasOne" and "hasMany" relationship.
|
* This method defines the inverse of the {@link hasOne} or {@link hasMany} relationship.
|
||||||
|
*
|
||||||
|
* For example, a product "belongsTo" a store.
|
||||||
|
*
|
||||||
|
* @typeParam T - The type of the entity builder passed as a first parameter. By default, it's
|
||||||
|
* a function returning the related model.
|
||||||
|
*
|
||||||
|
* @param {T} entityBuilder - A function that returns the data model this model is related to.
|
||||||
|
* @param {RelationshipOptions} options - The relationship's options.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const Product = model.define("product", {
|
||||||
|
* id: model.id(),
|
||||||
|
* store: model.belongsTo(() => Store, {
|
||||||
|
* mappedBy: "products",
|
||||||
|
* }),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @customNamespace Relationship Methods
|
||||||
*/
|
*/
|
||||||
belongsTo<T>(entityBuilder: T, options?: RelationshipOptions) {
|
belongsTo<T>(entityBuilder: T, options?: RelationshipOptions) {
|
||||||
return new BelongsTo<T>(entityBuilder, options || {})
|
return new BelongsTo<T>(entityBuilder, options || {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has many relationship defines a relationship between two entities
|
* This method defines a relationship between two data models,
|
||||||
* where the owner of the relationship has many instance of the
|
* where the owner of the relationship has many records of the related
|
||||||
* related entity.
|
* data model, but the related data model only has one owner.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example, a store "hasMany" products.
|
||||||
*
|
*
|
||||||
* - A user "hasMany" books
|
* @typeParam T - The type of the entity builder passed as a first parameter. By default, it's
|
||||||
* - A user "hasMany" addresses
|
* a function returning the related model.
|
||||||
|
*
|
||||||
|
* @param {T} entityBuilder - A function that returns the data model this model is related to.
|
||||||
|
* @param {RelationshipOptions} options - The relationship's options.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const Store = model.define("store", {
|
||||||
|
* id: model.id(),
|
||||||
|
* products: model.hasMany(() => Product),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @customNamespace Relationship Methods
|
||||||
*/
|
*/
|
||||||
hasMany<T>(entityBuilder: T, options?: RelationshipOptions) {
|
hasMany<T>(entityBuilder: T, options?: RelationshipOptions) {
|
||||||
return new HasMany<T>(entityBuilder, options || {})
|
return new HasMany<T>(entityBuilder, options || {})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManyToMany relationship defines a relationship between two entities
|
* This method defines a relationship between two data models,
|
||||||
* where the owner of the relationship has many instance of the
|
* where both data models have many related records.
|
||||||
* related entity via a pivot table.
|
|
||||||
*
|
*
|
||||||
* For example:
|
* For example, an order is associated with many products, and a product
|
||||||
|
* is associated with many orders.
|
||||||
*
|
*
|
||||||
* - A user has many teams. But a team has many users as well. So this
|
* @typeParam T - The type of the entity builder passed as a first parameter. By default, it's
|
||||||
* relationship requires a pivot table to establish a many to many
|
* a function returning the related model.
|
||||||
* relationship between two entities
|
*
|
||||||
|
* @param {T} entityBuilder - A function that returns the data model this model is related to.
|
||||||
|
* @param {RelationshipOptions} options - The relationship's options.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const Order = model.define("order", {
|
||||||
|
* id: model.id(),
|
||||||
|
* products: model.manyToMany(() => Product),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* const Product = model.define("product", {
|
||||||
|
* id: model.id(),
|
||||||
|
* order: model.manyToMany(() => Order),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @customNamespace Relationship Methods
|
||||||
*/
|
*/
|
||||||
manyToMany<T>(
|
manyToMany<T>(
|
||||||
entityBuilder: T,
|
entityBuilder: T,
|
||||||
options?: RelationshipOptions &
|
options?: ManyToManyOptions
|
||||||
(
|
|
||||||
| {
|
|
||||||
pivotTable?: string
|
|
||||||
pivotEntity?: never
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
pivotTable?: never
|
|
||||||
pivotEntity?: () => DmlEntity<any>
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return new ManyToMany<T>(entityBuilder, options || {})
|
return new ManyToMany<T>(entityBuilder, options || {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,10 +94,27 @@ export class DmlEntity<Schema extends DMLSchema> implements IDmlEntity<Schema> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete actions to be performed when the entity is deleted. For example:
|
* This method configures which related data models an operation, such as deletion,
|
||||||
|
* should be cascaded to.
|
||||||
*
|
*
|
||||||
* You can configure relationship data to be deleted when the current
|
* For example, if a store is deleted, its product should also be deleted.
|
||||||
* entity is deleted.
|
*
|
||||||
|
* @param options - The cascades configurations. They object's keys are the names of
|
||||||
|
* the actions, such as `deleted`, and the value is an array of relations that the
|
||||||
|
* action should be cascaded to.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const Store = model.define("store", {
|
||||||
|
* id: model.id(),
|
||||||
|
* products: model.hasMany(() => Product),
|
||||||
|
* })
|
||||||
|
* .cascades({
|
||||||
|
* delete: ["products"],
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @customNamespace Model Methods
|
||||||
*/
|
*/
|
||||||
cascades(
|
cascades(
|
||||||
options: EntityCascades<
|
options: EntityCascades<
|
||||||
@@ -123,7 +140,77 @@ export class DmlEntity<Schema extends DMLSchema> implements IDmlEntity<Schema> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds indexes to be created at during model creation on the DML entity.
|
* This method defines indices on the data model. An index can be on multiple columns
|
||||||
|
* and have conditions.
|
||||||
|
*
|
||||||
|
* @param indexes - The index's configuration.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* An example of a simple index:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* name: model.text(),
|
||||||
|
* age: model.number()
|
||||||
|
* }).indexes([
|
||||||
|
* {
|
||||||
|
* on: ["name", "age"],
|
||||||
|
* },
|
||||||
|
* ])
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To add a condition on the index, use the `where` option:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* name: model.text(),
|
||||||
|
* age: model.number()
|
||||||
|
* }).indexes([
|
||||||
|
* {
|
||||||
|
* on: ["name", "age"],
|
||||||
|
* where: {
|
||||||
|
* age: 30
|
||||||
|
* }
|
||||||
|
* },
|
||||||
|
* ])
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* The condition can also be a negation. For example:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* name: model.text(),
|
||||||
|
* age: model.number()
|
||||||
|
* }).indexes([
|
||||||
|
* {
|
||||||
|
* on: ["name", "age"],
|
||||||
|
* where: {
|
||||||
|
* age: {
|
||||||
|
* $ne: 30
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* },
|
||||||
|
* ])
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* In this example, the index is created when the value of `age` doesn't equal `30`.
|
||||||
|
*
|
||||||
|
* @customNamespace Model Methods
|
||||||
*/
|
*/
|
||||||
indexes(indexes: EntityIndex<Schema, string | QueryCondition<Schema>>[]) {
|
indexes(indexes: EntityIndex<Schema, string | QueryCondition<Schema>>[]) {
|
||||||
for (const index of indexes) {
|
for (const index of indexes) {
|
||||||
|
|||||||
@@ -30,14 +30,43 @@ export abstract class BaseProperty<T> implements PropertyType<T> {
|
|||||||
declare $dataType: T
|
declare $dataType: T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply nullable modifier on the schema
|
* This method indicates that a property's value can be `null`.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* price: model.bigNumber().nullable(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
*/
|
*/
|
||||||
nullable() {
|
nullable() {
|
||||||
return new NullableModifier<T, this>(this)
|
return new NullableModifier<T, this>(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define an index on the property
|
* This method defines an index on a property.
|
||||||
|
*
|
||||||
|
* @param {string} name - The index's name. If not provided,
|
||||||
|
* Medusa generates the name.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* id: model.id(),
|
||||||
|
* name: model.text().index(
|
||||||
|
* "IDX_MY_CUSTOM_NAME"
|
||||||
|
* ),
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
*/
|
*/
|
||||||
index(name?: string) {
|
index(name?: string) {
|
||||||
this.#indexes.push({ name, type: "index" })
|
this.#indexes.push({ name, type: "index" })
|
||||||
@@ -45,7 +74,23 @@ export abstract class BaseProperty<T> implements PropertyType<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a unique index on the property
|
* This method indicates that a property's value must be unique in the database.
|
||||||
|
* A unique index is created on the property.
|
||||||
|
*
|
||||||
|
* @param {string} name - The unique index's name. If not provided,
|
||||||
|
* Medusa generates the name.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const User = model.define("user", {
|
||||||
|
* email: model.text().unique(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default User
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
*/
|
*/
|
||||||
unique(name?: string) {
|
unique(name?: string) {
|
||||||
this.#indexes.push({ name, type: "unique" })
|
this.#indexes.push({ name, type: "unique" })
|
||||||
@@ -53,7 +98,26 @@ export abstract class BaseProperty<T> implements PropertyType<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define default value for the property
|
* This method defines the default value of a property.
|
||||||
|
*
|
||||||
|
* @param {T} value - The default value.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* color: model
|
||||||
|
* .enum(["black", "white"])
|
||||||
|
* .default("black"),
|
||||||
|
* age: model
|
||||||
|
* .number()
|
||||||
|
* .default(0),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
*/
|
*/
|
||||||
default(value: T) {
|
default(value: T) {
|
||||||
this.#defaultValue = value
|
this.#defaultValue = value
|
||||||
|
|||||||
@@ -13,7 +13,21 @@ export class IdProperty extends BaseProperty<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(options?: { primaryKey?: boolean; prefix?: string }) {
|
constructor(options?: {
|
||||||
|
/**
|
||||||
|
* Whether the ID is the data model's primary key.
|
||||||
|
*
|
||||||
|
* @defaultValue true
|
||||||
|
*/
|
||||||
|
primaryKey?: boolean
|
||||||
|
/**
|
||||||
|
* By default, Medusa shortens the data model's name and uses it as the
|
||||||
|
* prefix of all IDs. For example, `cm_123`.
|
||||||
|
*
|
||||||
|
* Use this option to specify the prefix to use instead.
|
||||||
|
*/
|
||||||
|
prefix?: string
|
||||||
|
}) {
|
||||||
super()
|
super()
|
||||||
this.dataType = {
|
this.dataType = {
|
||||||
name: "id",
|
name: "id",
|
||||||
|
|||||||
@@ -12,12 +12,42 @@ export class TextProperty extends BaseProperty<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method indicates that the property is the data model's primary key.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* code: model.text().primaryKey(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
|
*/
|
||||||
primaryKey() {
|
primaryKey() {
|
||||||
this.dataType.options.primaryKey = true
|
this.dataType.options.primaryKey = true
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method indicates that a text property is searchable.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* import { model } from "@medusajs/utils"
|
||||||
|
*
|
||||||
|
* const MyCustom = model.define("my_custom", {
|
||||||
|
* name: model.text().searchable(),
|
||||||
|
* // ...
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* export default MyCustom
|
||||||
|
*
|
||||||
|
* @customNamespace Property Configuration Methods
|
||||||
|
*/
|
||||||
searchable() {
|
searchable() {
|
||||||
this.dataType.options.searchable = true
|
this.dataType.options.searchable = true
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
|
|||||||
@@ -2130,6 +2130,44 @@ export const sidebar = sidebarAttachHrefCommonOptions([
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model",
|
||||||
|
// title: "Data Model API",
|
||||||
|
// childSidebarTitle: "Data Model API Reference",
|
||||||
|
// isChildSidebar: true,
|
||||||
|
// children: [
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model/define",
|
||||||
|
// title: "Define Method",
|
||||||
|
// hasTitleStyling: true,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model/property-types",
|
||||||
|
// title: "Property Types",
|
||||||
|
// hasTitleStyling: true,
|
||||||
|
// autogenerate_path: "/references/dml/Property_Types/methods",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model/relationship-methods",
|
||||||
|
// title: "Relationship Methods",
|
||||||
|
// hasTitleStyling: true,
|
||||||
|
// autogenerate_path: "/references/dml/Relationship_Methods/methods",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model/model-methods",
|
||||||
|
// title: "Model Methods",
|
||||||
|
// hasTitleStyling: true,
|
||||||
|
// autogenerate_path: "/references/dml/Model_Methods/methods",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// path: "/references/data-model/property-configuration",
|
||||||
|
// title: "Property Configuration Methods",
|
||||||
|
// hasTitleStyling: true,
|
||||||
|
// autogenerate_path:
|
||||||
|
// "/references/dml/Property_Configuration_Methods/methods",
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,16 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
|||||||
name: "auth-provider",
|
name: "auth-provider",
|
||||||
parentIgnore: true,
|
parentIgnore: true,
|
||||||
}),
|
}),
|
||||||
|
dml: getOptions({
|
||||||
|
entryPointPath: [
|
||||||
|
"packages/core/utils/src/dml/entity-builder.ts",
|
||||||
|
"packages/core/utils/src/dml/entity.ts",
|
||||||
|
"packages/core/utils/src/dml/properties/base.ts",
|
||||||
|
],
|
||||||
|
tsConfigName: "utils.json",
|
||||||
|
name: "dml",
|
||||||
|
generateNamespaces: true,
|
||||||
|
}),
|
||||||
file: getOptions({
|
file: getOptions({
|
||||||
entryPointPath: "packages/core/utils/src/file/abstract-file-provider.ts",
|
entryPointPath: "packages/core/utils/src/file/abstract-file-provider.ts",
|
||||||
tsConfigName: "utils.json",
|
tsConfigName: "utils.json",
|
||||||
@@ -28,29 +38,11 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
|||||||
name: "fulfillment-provider",
|
name: "fulfillment-provider",
|
||||||
parentIgnore: true,
|
parentIgnore: true,
|
||||||
}),
|
}),
|
||||||
"js-client": getOptions({
|
|
||||||
entryPointPath: "packages/medusa-js/src/resources",
|
|
||||||
tsConfigName: "js-client.json",
|
|
||||||
name: "js-client",
|
|
||||||
plugin: ["typedoc-plugin-rename-defaults"],
|
|
||||||
exclude: [
|
|
||||||
...(baseOptions.exclude || []),
|
|
||||||
path.join(rootPathPrefix, "packages/medusa-js/src/resources/base.ts"),
|
|
||||||
],
|
|
||||||
ignoreApi: true,
|
|
||||||
}),
|
|
||||||
"medusa-config": getOptions({
|
"medusa-config": getOptions({
|
||||||
entryPointPath: "packages/core/types/src/common/config-module.ts",
|
entryPointPath: "packages/core/types/src/common/config-module.ts",
|
||||||
tsConfigName: "types.json",
|
tsConfigName: "types.json",
|
||||||
name: "medusa-config",
|
name: "medusa-config",
|
||||||
}),
|
}),
|
||||||
"medusa-react": getOptions({
|
|
||||||
entryPointPath: "packages/medusa-react/src/index.ts",
|
|
||||||
tsConfigName: "medusa-react.json",
|
|
||||||
name: "medusa-react",
|
|
||||||
generateNamespaces: true,
|
|
||||||
ignoreApi: true,
|
|
||||||
}),
|
|
||||||
medusa: getOptions({
|
medusa: getOptions({
|
||||||
entryPointPath: "packages/medusa/src/index.js",
|
entryPointPath: "packages/medusa/src/index.js",
|
||||||
tsConfigName: "medusa.json",
|
tsConfigName: "medusa.json",
|
||||||
@@ -96,11 +88,6 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
|||||||
tsConfigName: "utils.json",
|
tsConfigName: "utils.json",
|
||||||
name: "search",
|
name: "search",
|
||||||
}),
|
}),
|
||||||
services: getOptions({
|
|
||||||
entryPointPath: "packages/medusa/src/services/index.ts",
|
|
||||||
tsConfigName: "medusa.json",
|
|
||||||
name: "services",
|
|
||||||
}),
|
|
||||||
"tax-provider": getOptions({
|
"tax-provider": getOptions({
|
||||||
entryPointPath: "packages/core/types/src/tax/provider.ts",
|
entryPointPath: "packages/core/types/src/tax/provider.ts",
|
||||||
tsConfigName: "types.json",
|
tsConfigName: "types.json",
|
||||||
@@ -117,11 +104,6 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
|||||||
...modules.map((moduleName) => `**/${moduleName}/**/*.ts`),
|
...modules.map((moduleName) => `**/${moduleName}/**/*.ts`),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
workflows: getOptions({
|
|
||||||
entryPointPath: "packages/core/workflows-sdk/src/utils/composer/index.ts",
|
|
||||||
tsConfigName: "workflows.json",
|
|
||||||
name: "workflows",
|
|
||||||
}),
|
|
||||||
utils: getOptions({
|
utils: getOptions({
|
||||||
entryPointPath: "packages/core/utils/src/index.ts",
|
entryPointPath: "packages/core/utils/src/index.ts",
|
||||||
tsConfigName: "utils.json",
|
tsConfigName: "utils.json",
|
||||||
@@ -146,6 +128,11 @@ const customOptions: Record<string, Partial<TypeDocOptions>> = {
|
|||||||
"**/totals/**",
|
"**/totals/**",
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
workflows: getOptions({
|
||||||
|
entryPointPath: "packages/core/workflows-sdk/src/utils/composer/index.ts",
|
||||||
|
tsConfigName: "workflows.json",
|
||||||
|
name: "workflows",
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
export default customOptions
|
export default customOptions
|
||||||
+124
@@ -0,0 +1,124 @@
|
|||||||
|
import { FormattingOptionsType } from "types"
|
||||||
|
import baseSectionsOptions from "../base-section-options.js"
|
||||||
|
|
||||||
|
const dmlOptions: FormattingOptionsType = {
|
||||||
|
"^dml": {
|
||||||
|
expandMembers: true,
|
||||||
|
sections: {
|
||||||
|
...baseSectionsOptions,
|
||||||
|
member_getterSetter: false,
|
||||||
|
member_returns: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^modules/dml/page\\.mdx": {
|
||||||
|
reflectionDescription:
|
||||||
|
"This section of the documentation provides an API reference to the property types and methods used to create a data model.",
|
||||||
|
reflectionGroups: {
|
||||||
|
Classes: false,
|
||||||
|
Variables: false,
|
||||||
|
Properties: false,
|
||||||
|
Modules: false,
|
||||||
|
},
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
fullReplacement: "Data Models API Reference",
|
||||||
|
},
|
||||||
|
hideTocHeaders: true,
|
||||||
|
},
|
||||||
|
"^dml/.*define": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/define",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "Method - API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/.*Property_Types/page\\.mdx": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/property-types",
|
||||||
|
},
|
||||||
|
reflectionDescription:
|
||||||
|
"The following methods are used to define the type of a property in a data model.",
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "- API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/Property_Types": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/property-types/{{alias-lower}}",
|
||||||
|
sidebar_label: "{{alias}}",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "Property Method - API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/.*Relationship_Methods/page\\.mdx": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/relationship-methods",
|
||||||
|
},
|
||||||
|
reflectionDescription:
|
||||||
|
"The following methods are used to define a relationship between two data models.",
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "- API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/Relationship_Methods": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/relationship-methods/{{alias-lower}}",
|
||||||
|
sidebar_label: "{{alias}}",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "Relationship Method - API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/.*Model_Methods/page\\.mdx": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/model-methods",
|
||||||
|
},
|
||||||
|
reflectionDescription:
|
||||||
|
"The following methods are used on a module to configure it.",
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "- API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/Model_Methods": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/model-methods/{{alias-lower}}",
|
||||||
|
sidebar_label: "{{alias}}",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "Method - API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/.*Property_Configuration_Methods/page\\.mdx": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/property-configuration",
|
||||||
|
},
|
||||||
|
reflectionDescription:
|
||||||
|
"The following methods are used on a property to configure it.",
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "- API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/Property_Configuration_Methods": {
|
||||||
|
frontmatterData: {
|
||||||
|
slug: "/references/data-model/property-configuration/{{alias-lower}}",
|
||||||
|
sidebar_label: "{{alias}}",
|
||||||
|
},
|
||||||
|
reflectionTitle: {
|
||||||
|
suffix: "Method - API Reference",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"^dml/.*/types/.*": {
|
||||||
|
sections: {
|
||||||
|
...baseSectionsOptions,
|
||||||
|
member_getterSetter: false,
|
||||||
|
member_returns: false,
|
||||||
|
member_declaration_children: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default dmlOptions
|
||||||
+2
@@ -11,9 +11,11 @@ import paymentProviderOptions from "./payment-provider.js"
|
|||||||
import searchOptions from "./search.js"
|
import searchOptions from "./search.js"
|
||||||
import taxProviderOptions from "./tax-provider.js"
|
import taxProviderOptions from "./tax-provider.js"
|
||||||
import workflowsOptions from "./workflows.js"
|
import workflowsOptions from "./workflows.js"
|
||||||
|
import dmlOptions from "./dml.js"
|
||||||
|
|
||||||
const mergerCustomOptions: FormattingOptionsType = {
|
const mergerCustomOptions: FormattingOptionsType = {
|
||||||
...authProviderOptions,
|
...authProviderOptions,
|
||||||
|
...dmlOptions,
|
||||||
...fileOptions,
|
...fileOptions,
|
||||||
...fulfillmentProviderOptions,
|
...fulfillmentProviderOptions,
|
||||||
...jsClientOptions,
|
...jsClientOptions,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const mergerOptions: Partial<TypeDocOptions> = {
|
|||||||
objectLiteralTypeDeclarationStyle: "component",
|
objectLiteralTypeDeclarationStyle: "component",
|
||||||
mdxOutput: true,
|
mdxOutput: true,
|
||||||
maxLevel: 3,
|
maxLevel: 3,
|
||||||
allReflectionsHaveOwnDocument: [...modules, "workflows"],
|
allReflectionsHaveOwnDocument: [...modules, "dml", "workflows"],
|
||||||
allReflectionsHaveOwnDocumentInNamespace: ["Utilities"],
|
allReflectionsHaveOwnDocumentInNamespace: ["Utilities"],
|
||||||
formatting: {
|
formatting: {
|
||||||
"*": {
|
"*": {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const modules = [
|
|||||||
const allReferences = [
|
const allReferences = [
|
||||||
...modules,
|
...modules,
|
||||||
"auth-provider",
|
"auth-provider",
|
||||||
|
"dml",
|
||||||
"file",
|
"file",
|
||||||
"fulfillment-provider",
|
"fulfillment-provider",
|
||||||
"medusa-config",
|
"medusa-config",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
Converter,
|
Converter,
|
||||||
DeclarationReflection,
|
DeclarationReflection,
|
||||||
ParameterType,
|
ParameterType,
|
||||||
|
Reflection,
|
||||||
ReflectionCategory,
|
ReflectionCategory,
|
||||||
ReflectionKind,
|
ReflectionKind,
|
||||||
} from "typedoc"
|
} from "typedoc"
|
||||||
@@ -31,7 +32,7 @@ export class GenerateNamespacePlugin {
|
|||||||
this.declareOptions()
|
this.declareOptions()
|
||||||
|
|
||||||
this.app.converter.on(
|
this.app.converter.on(
|
||||||
Converter.EVENT_CREATE_DECLARATION,
|
Converter.EVENT_RESOLVE,
|
||||||
this.handleCreateDeclarationEvent.bind(this)
|
this.handleCreateDeclarationEvent.bind(this)
|
||||||
)
|
)
|
||||||
this.app.converter.on(
|
this.app.converter.on(
|
||||||
@@ -145,14 +146,17 @@ export class GenerateNamespacePlugin {
|
|||||||
* create categories in the last namespace if the
|
* create categories in the last namespace if the
|
||||||
* reflection has a category
|
* reflection has a category
|
||||||
*/
|
*/
|
||||||
attachCategories(reflection: DeclarationReflection) {
|
attachCategories(
|
||||||
|
reflection: DeclarationReflection,
|
||||||
|
comments: Comment | undefined
|
||||||
|
) {
|
||||||
if (!this.currentNamespaceHeirarchy.length) {
|
if (!this.currentNamespaceHeirarchy.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentNamespace =
|
const parentNamespace =
|
||||||
this.currentNamespaceHeirarchy[this.currentNamespaceHeirarchy.length - 1]
|
this.currentNamespaceHeirarchy[this.currentNamespaceHeirarchy.length - 1]
|
||||||
reflection.comment?.blockTags
|
comments?.blockTags
|
||||||
.filter((tag) => tag.tag === "@category")
|
.filter((tag) => tag.tag === "@category")
|
||||||
.forEach((tag) => {
|
.forEach((tag) => {
|
||||||
const categoryName = tag.content[0].text
|
const categoryName = tag.content[0].text
|
||||||
@@ -170,10 +174,10 @@ export class GenerateNamespacePlugin {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCreateDeclarationEvent(
|
handleCreateDeclarationEvent(context: Context, reflection: Reflection) {
|
||||||
context: Context,
|
if (!(reflection instanceof DeclarationReflection)) {
|
||||||
reflection: DeclarationReflection
|
return
|
||||||
) {
|
}
|
||||||
this.readOptions()
|
this.readOptions()
|
||||||
if (this.options?.parentNamespace && !this.parentNamespace) {
|
if (this.options?.parentNamespace && !this.parentNamespace) {
|
||||||
this.parentNamespace =
|
this.parentNamespace =
|
||||||
@@ -185,7 +189,8 @@ export class GenerateNamespacePlugin {
|
|||||||
this.currentNamespaceHeirarchy.push(this.parentNamespace)
|
this.currentNamespaceHeirarchy.push(this.parentNamespace)
|
||||||
}
|
}
|
||||||
this.currentContext = context
|
this.currentContext = context
|
||||||
reflection.comment?.blockTags
|
const comments = this.getReflectionComments(reflection)
|
||||||
|
comments?.blockTags
|
||||||
.filter((tag) => tag.tag === "@customNamespace")
|
.filter((tag) => tag.tag === "@customNamespace")
|
||||||
.forEach((tag) => {
|
.forEach((tag) => {
|
||||||
this.generateNamespaceFromTag({
|
this.generateNamespaceFromTag({
|
||||||
@@ -202,8 +207,8 @@ export class GenerateNamespacePlugin {
|
|||||||
this.currentContext?.addChild(reflection)
|
this.currentContext?.addChild(reflection)
|
||||||
})
|
})
|
||||||
|
|
||||||
reflection.comment?.removeTags("@customNamespace")
|
comments?.removeTags("@customNamespace")
|
||||||
this.attachCategories(reflection)
|
this.attachCategories(reflection, comments)
|
||||||
this.currentContext = undefined
|
this.currentContext = undefined
|
||||||
this.currentNamespaceHeirarchy = []
|
this.currentNamespaceHeirarchy = []
|
||||||
}
|
}
|
||||||
@@ -251,6 +256,20 @@ export class GenerateNamespacePlugin {
|
|||||||
this.scannedComments = true
|
this.scannedComments = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getReflectionComments(
|
||||||
|
reflection: DeclarationReflection
|
||||||
|
): Comment | undefined {
|
||||||
|
if (reflection.comment) {
|
||||||
|
return reflection.comment
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to retrieve comment from signature
|
||||||
|
if (!reflection.signatures?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return reflection.signatures.find((signature) => signature.comment)?.comment
|
||||||
|
}
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
printCurrentHeirarchy() {
|
printCurrentHeirarchy() {
|
||||||
return this.currentNamespaceHeirarchy.map((heirarchy) => heirarchy.name)
|
return this.currentNamespaceHeirarchy.map((heirarchy) => heirarchy.name)
|
||||||
|
|||||||
+4
-1
@@ -9,7 +9,10 @@ export default function (theme: MarkdownTheme) {
|
|||||||
function (this: SignatureReflection, options: Handlebars.HelperOptions) {
|
function (this: SignatureReflection, options: Handlebars.HelperOptions) {
|
||||||
this.parent =
|
this.parent =
|
||||||
getCorrectDeclarationReflection(this.parent, theme) || this.parent
|
getCorrectDeclarationReflection(this.parent, theme) || this.parent
|
||||||
return this.type && !this.parent?.kindOf(ReflectionKind.Constructor)
|
const { sections } = theme.getFormattingOptionsForLocation()
|
||||||
|
return sections?.member_returns !== false &&
|
||||||
|
this.type &&
|
||||||
|
!this.parent?.kindOf(ReflectionKind.Constructor)
|
||||||
? options.fn(this)
|
? options.fn(this)
|
||||||
: options.inverse(this)
|
: options.inverse(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -17,13 +17,19 @@ export default function (theme: MarkdownTheme) {
|
|||||||
const parameters = this.reduce(
|
const parameters = this.reduce(
|
||||||
(acc: ReflectionParameterType[], current) => parseParams(current, acc),
|
(acc: ReflectionParameterType[], current) => parseParams(current, acc),
|
||||||
[]
|
[]
|
||||||
).map((parameter) =>
|
|
||||||
reflectionComponentFormatter({
|
|
||||||
reflection: parameter,
|
|
||||||
level: 1,
|
|
||||||
maxLevel,
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
.filter((parameter) => {
|
||||||
|
// remove parameters that are supposed to be nested
|
||||||
|
return !parameter.name.includes(".")
|
||||||
|
})
|
||||||
|
.map((parameter) =>
|
||||||
|
reflectionComponentFormatter({
|
||||||
|
reflection: parameter,
|
||||||
|
level: 1,
|
||||||
|
maxLevel,
|
||||||
|
project: theme.project,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return formatParameterComponent({
|
return formatParameterComponent({
|
||||||
parameterComponent,
|
parameterComponent,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export default function (theme: MarkdownTheme) {
|
|||||||
const md: string[] = []
|
const md: string[] = []
|
||||||
|
|
||||||
const { hideInPageTOC } = theme
|
const { hideInPageTOC } = theme
|
||||||
|
const { hideTocHeaders } = theme.getFormattingOptionsForLocation()
|
||||||
|
|
||||||
const isVisible = this.groups?.some((group) =>
|
const isVisible = this.groups?.some((group) =>
|
||||||
group.allChildrenHaveOwnDocument()
|
group.allChildrenHaveOwnDocument()
|
||||||
@@ -44,7 +45,9 @@ export default function (theme: MarkdownTheme) {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (!hideInPageTOC || group.allChildrenHaveOwnDocument()) {
|
if (!hideInPageTOC || group.allChildrenHaveOwnDocument()) {
|
||||||
md.push(`${headingLevel} ${groupTitle}\n\n`)
|
if (!hideTocHeaders) {
|
||||||
|
md.push(`${headingLevel} ${groupTitle}\n\n`)
|
||||||
|
}
|
||||||
pushGroup(group, md)
|
pushGroup(group, md)
|
||||||
md.push("\n")
|
md.push("\n")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ export function reflectionComponentFormatter({
|
|||||||
: getTypeChildren({
|
: getTypeChildren({
|
||||||
reflectionType: reflection.type!,
|
reflectionType: reflection.type!,
|
||||||
project: project || reflection.project,
|
project: project || reflection.project,
|
||||||
maxLevel,
|
maxLevel: maxLevel || MarkdownTheme.MAX_LEVEL,
|
||||||
})
|
})
|
||||||
|
|
||||||
children
|
children
|
||||||
|
|||||||
+2
@@ -29,6 +29,7 @@ export type SectionKey =
|
|||||||
| "member_sources_definedIn"
|
| "member_sources_definedIn"
|
||||||
| "members_group_categories"
|
| "members_group_categories"
|
||||||
| "members_categories"
|
| "members_categories"
|
||||||
|
| "member_returns"
|
||||||
| "title_reflectionPath"
|
| "title_reflectionPath"
|
||||||
| "reflection_comment"
|
| "reflection_comment"
|
||||||
| "reflection_typeParameters"
|
| "reflection_typeParameters"
|
||||||
@@ -78,6 +79,7 @@ export type FormattingOptionType = {
|
|||||||
startSections?: string[]
|
startSections?: string[]
|
||||||
endSections?: string[]
|
endSections?: string[]
|
||||||
shouldIncrementAfterStartSections?: boolean
|
shouldIncrementAfterStartSections?: boolean
|
||||||
|
hideTocHeaders?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare module "typedoc" {
|
export declare module "typedoc" {
|
||||||
|
|||||||
@@ -34,6 +34,19 @@ export function getTypeChildren({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
case "union":
|
||||||
|
reflectionType.types.forEach((childItem) => {
|
||||||
|
// TODO this should ensure that the items are unique.
|
||||||
|
children.push(
|
||||||
|
...getTypeChildren({
|
||||||
|
reflectionType: childItem,
|
||||||
|
project,
|
||||||
|
level: level + 1,
|
||||||
|
maxLevel,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
break
|
||||||
case "reference":
|
case "reference":
|
||||||
// eslint-disable-next-line no-case-declarations
|
// eslint-disable-next-line no-case-declarations
|
||||||
const referencedReflection = reflectionType.reflection
|
const referencedReflection = reflectionType.reflection
|
||||||
@@ -53,7 +66,7 @@ export function getTypeChildren({
|
|||||||
children = getTypeChildren({
|
children = getTypeChildren({
|
||||||
reflectionType: referencedReflection.type,
|
reflectionType: referencedReflection.type,
|
||||||
project,
|
project,
|
||||||
level: level + 1,
|
level,
|
||||||
maxLevel,
|
maxLevel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user