Skip to content

Commit

Permalink
46
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchaffer committed Mar 17, 2019
1 parent bd61300 commit b20f89a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/dandi-contrib/data-pg/src/pg-db-client.ts
Expand Up @@ -13,14 +13,14 @@ export class PgDbClient extends PgDbQueryableBase<PgDbPool> implements DbClient,

constructor(
@Inject(PgDbPool) private pool: PgDbPool,
@Inject(ModelBuilder) modelValidator: ModelBuilder,
@Inject(ModelBuilder) modelBuilder: ModelBuilder,
@Inject(Injector) private injector: Injector,
@Inject(Logger) private logger: Logger,
@Inject(PgDbModelBuilderOptions)
@Optional()
modelBuilderOptions?: ModelBuilderOptions,
) {
super(modelValidator, modelBuilderOptions)
super(modelBuilder, modelBuilderOptions)
}

public query(cmd: string, ...args: any[]): Promise<any[]> {
Expand Down
Expand Up @@ -61,13 +61,13 @@ export class PgDbTransactionClient extends PgDbQueryableBase<PgDbPoolClient> imp

constructor(
@Inject(PgDbPoolClient) client: PgDbPoolClient,
@Inject(ModelBuilder) modelValidator: ModelBuilder,
@Inject(ModelBuilder) modelBuilder: ModelBuilder,
@Inject(Logger) private logger: Logger,
@Inject(PgDbModelBuilderOptions)
@Optional()
modelBuilderOptions?: ModelBuilderOptions,
) {
super(modelValidator, modelBuilderOptions)
super(modelBuilder, modelBuilderOptions)

this.mutex = AsyncMutex.for(client)
}
Expand Down
24 changes: 24 additions & 0 deletions packages/dandi/model-builder/src/model-builder.ts
Expand Up @@ -6,16 +6,40 @@ import { DataTransformer, KeyTransformFn } from './data-transformer'
import { localOpinionatedToken } from './local-token'
import { ModelValidator } from './model-validator'

/**
* Options for customizing behavior of [[ModelBuilder.constructMember]]
*/
export interface MemberBuilderOptions {
/**
* An array of [[ModelValidator]]s the check constructed objects against
*/
validators?: ModelValidator[]

/**
* A [[KeyTransformFn]] that will be used to transform keys of the source object before constructing the model
*/
keyTransform?: KeyTransformFn
}

/**
* Options for customizing behavior of [[ModelBuilder]] services.
*/
export interface ModelBuilderOptions extends MemberBuilderOptions {
/**
* An array of [[DataTransformer]]s that will be run against source objects before constructing a model
*/
dataTransformers?: DataTransformer[]
}

/**
* A utility that allows creating [[Provider]] objects for [[ModelBuilderOptions]]
*/
export const ModelBuilderOptions = {
/**
* Creates a [[Provider<ModelBuilderOptions>]] object using the specified `token` and `options` object.
* @param token
* @param options
*/
provider(token: InjectionToken<ModelBuilderOptions>, options: ModelBuilderOptions): Provider<ModelBuilderOptions> {
return {
provide: token,
Expand Down
29 changes: 29 additions & 0 deletions util/typedoc/typedoc-plugin-module-name-by-package/src/plugin.ts
Expand Up @@ -160,6 +160,34 @@ export class ModuleNameByPackagePlugin extends ConverterComponent {
})
}

execOnCommentText(module: Reflection, fn: (module: Reflection, text: string) => string): void {
if (!module.comment || !module.comment.hasVisibleComponent()) {
return
}
if (module.comment.text) {
module.comment.text = fn(module, module.comment.text)
}
if (module.comment.shortText) {
module.comment.shortText = fn(module, module.comment.shortText)
}
if (module.comment.returns) {
module.comment.returns = fn(module, module.comment.returns)
}
if (module.comment.tags) {
// auto-import README.md content for each package
module.comment.tags.forEach(tag => {
tag.text = fn(module, tag.text)
})
}
}

fixGenericCommentReferences(module: Reflection, text: string): string {
return text.replace(/\[\[\w+<\w+>]]/g, typeRef =>
typeRef.replace(/\[\[(\w+)<(\w+)>]]/, (match, type, gType) =>
`[[${type}]]<[[${gType}]]>`
))
}

onResolveBegin(context: Context) {
this.fixProjectMarkdownPaths(context.project)
const packageModules = [...this.packageModules.values()]
Expand All @@ -169,6 +197,7 @@ export class ModuleNameByPackagePlugin extends ConverterComponent {

for(const ref of Object.values(context.project.reflections)) {
this.importIncludedMarkdown(ref)
this.execOnCommentText(ref, this.fixGenericCommentReferences)

// rename decorators
if (this.isDecorator(ref)) {
Expand Down

0 comments on commit b20f89a

Please sign in to comment.