-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: port channel, channel-parameter and schema models (#547)
1 parent
3627d02
commit ae4b0ff
Showing
35 changed files
with
1,635 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { BaseModel } from "./base"; | ||
|
||
export interface ExtensionInterface extends BaseModel { | ||
id(): string; | ||
name(): string; | ||
version(): string; | ||
value(): any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,56 @@ | ||
import type { BaseModel } from "./base"; | ||
import type { ExtensionsMixinInterface } from "./mixins"; | ||
import type { ExtensionsMixinInterface, ExternalDocumentationMixinInterface } from "./mixins"; | ||
|
||
export interface SchemaInterface extends BaseModel, ExtensionsMixinInterface {} | ||
export interface SchemaInterface extends BaseModel, ExtensionsMixinInterface, ExternalDocumentationMixinInterface { | ||
uid(): string; | ||
$comment(): string | undefined; | ||
$id(): string | undefined; | ||
$schema(): string; | ||
additionalItems(): boolean | SchemaInterface; | ||
additionalProperties(): boolean | SchemaInterface; | ||
allOf(): Array<SchemaInterface> | undefined; | ||
anyOf(): Array<SchemaInterface> | undefined; | ||
const(): any; | ||
contains(): SchemaInterface | undefined; | ||
contentEncoding(): string | undefined; | ||
contentMediaType(): string | undefined; | ||
default(): any; | ||
definitions(): Record<string, SchemaInterface> | undefined; | ||
description(): string | undefined; | ||
dependencies(): Record<string, SchemaInterface | Array<string>> | undefined; | ||
deprecated(): boolean; | ||
discriminator(): string | undefined; | ||
else(): SchemaInterface | undefined; | ||
enum(): Array<any> | undefined; | ||
examples(): Array<any> | undefined; | ||
exclusiveMaximum(): number | undefined; | ||
exclusiveMinimum(): number | undefined; | ||
format(): string | undefined; | ||
isBooleanSchema(): boolean; | ||
if(): SchemaInterface | undefined; | ||
isCircular(): boolean; | ||
items(): SchemaInterface | Array<SchemaInterface> | undefined; | ||
maximum(): number | undefined; | ||
maxItems(): number | undefined; | ||
maxLength(): number | undefined; | ||
maxProperties(): number | undefined; | ||
minimum(): number | undefined; | ||
minItems(): number | undefined; | ||
minLength(): number | undefined; | ||
minProperties(): number | undefined; | ||
multipleOf(): number | undefined; | ||
not(): SchemaInterface | undefined; | ||
oneOf(): Array<SchemaInterface> | undefined; | ||
pattern(): string | undefined; | ||
patternProperties(): Record<string, SchemaInterface> | undefined; | ||
properties(): Record<string, SchemaInterface> | undefined; | ||
property(key: string): SchemaInterface | undefined; | ||
propertyNames(): SchemaInterface | undefined; | ||
readOnly(): boolean | undefined; | ||
required(): Array<string> | undefined; | ||
then(): SchemaInterface | undefined; | ||
title(): string | undefined; | ||
type(): string | Array<string> | undefined; | ||
uniqueItems(): boolean | undefined; | ||
writeOnly(): boolean | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { BaseModel } from "../base"; | ||
import { Schema } from "./schema"; | ||
|
||
import { Mixin } from '../utils'; | ||
import { DescriptionMixin } from './mixins/description'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
|
||
import type { ModelMetadata } from "../base"; | ||
import type { ChannelParameterInterface } from "../channel-parameter"; | ||
import type { SchemaInterface } from "../schema"; | ||
|
||
export class ChannelParameter extends Mixin(BaseModel, DescriptionMixin, ExtensionsMixin) implements ChannelParameterInterface { | ||
constructor( | ||
_json: Record<string,any>, | ||
protected readonly _meta: ModelMetadata & { id: string } = {} as any | ||
) { | ||
super(_json, _meta); | ||
} | ||
|
||
id(): string { | ||
return this._meta.id; | ||
} | ||
|
||
hasSchema(): boolean { | ||
return !!this._json.schema; | ||
} | ||
|
||
schema(): SchemaInterface | undefined { | ||
if (!this._json.schema) return undefined; | ||
return this.createModel(Schema, this._json.schema, { pointer: `${this._meta.pointer}/schema` }); | ||
} | ||
|
||
hasLocation(): boolean { | ||
return !!this._json.location; | ||
} | ||
|
||
location(): string | undefined { | ||
return this._json.location; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Collection } from '../collection'; | ||
|
||
import type { ChannelParametersInterface } from '../channel-parameters'; | ||
import type { ChannelParameterInterface } from '../channel-parameter'; | ||
|
||
export class ChannelParameters extends Collection<ChannelParameterInterface> implements ChannelParametersInterface { | ||
override get(id: string): ChannelParameterInterface | undefined { | ||
return this.collections.find(parameter => parameter.id() === id); | ||
} | ||
|
||
override has(id: string): boolean { | ||
return this.collections.some(parameter => parameter.id() === id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { BaseModel } from "../base"; | ||
import { ChannelParameters } from './channel-parameters'; | ||
import { ChannelParameter } from './channel-parameter'; | ||
import { Messages } from './messages'; | ||
import { Operations } from './operations'; | ||
import { Operation } from './operation'; | ||
import { Servers } from './servers'; | ||
import { Server } from './server'; | ||
|
||
import { Mixin } from '../utils'; | ||
import { BindingsMixin } from './mixins/bindings'; | ||
import { DescriptionMixin } from './mixins/description'; | ||
import { ExtensionsMixin } from './mixins/extensions'; | ||
|
||
import type { ModelMetadata } from "../base"; | ||
import type { ChannelInterface } from "../channel"; | ||
import type { ChannelParametersInterface } from "../channel-parameters"; | ||
import type { OperationsInterface } from "../operations"; | ||
import type { OperationInterface } from "../operation"; | ||
import type { ServersInterface } from "../servers"; | ||
import type { ServerInterface } from "../server"; | ||
|
||
export class Channel extends Mixin(BaseModel, BindingsMixin, DescriptionMixin, ExtensionsMixin) implements ChannelInterface { | ||
constructor( | ||
_json: Record<string,any>, | ||
protected readonly _meta: ModelMetadata & { id: string, address: string } = {} as any | ||
) { | ||
super(_json, _meta); | ||
} | ||
|
||
id(): string { | ||
return this._meta.id; | ||
} | ||
|
||
address(): string { | ||
return this._meta.address; | ||
} | ||
|
||
servers(): ServersInterface { | ||
const servers: ServerInterface[] = []; | ||
const allowedServers: string[] = this._json.servers || []; | ||
Object.entries(this._meta.asyncapi?.parsed.servers || {}).map(([serverName, server]) => { | ||
if (allowedServers.length === 0 || allowedServers.includes(serverName)) { | ||
servers.push(this.createModel(Server, server, { id: serverName, pointer: `/servers/${serverName}` })); | ||
} | ||
}); | ||
return new Servers(servers); | ||
} | ||
|
||
operations(): OperationsInterface { | ||
const operations: OperationInterface[] = [] | ||
if (this._json.publish) { | ||
operations.push( | ||
this.createModel(Operation, this._json.publish, { id: 'publish', action: 'publish', pointer: `${this._meta.pointer}/publish` }), | ||
); | ||
} | ||
if (this._json.subscribe) { | ||
operations.push( | ||
this.createModel(Operation, this._json.subscribe, { id: 'subscribe', action: 'subscribe', pointer: `${this._meta.pointer}/subscribe` }), | ||
); | ||
} | ||
return new Operations(operations); | ||
} | ||
|
||
parameters(): ChannelParametersInterface { | ||
return new ChannelParameters( | ||
Object.entries(this._json.parameters || {}).map(([channelParameterName, channelParameter]) => { | ||
return this.createModel(ChannelParameter, channelParameter, { | ||
id: channelParameterName, | ||
pointer: `${this._meta.pointer}/parameters/${channelParameterName}` | ||
}) | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Collection } from '../collection'; | ||
|
||
import type { ChannelsInterface } from '../channels'; | ||
import type { ChannelInterface } from '../channel'; | ||
|
||
export class Channels extends Collection<ChannelInterface> implements ChannelsInterface { | ||
override get(id: string): ChannelInterface | undefined { | ||
return this.collections.find(channel => channel.id() === id); | ||
} | ||
|
||
override has(id: string): boolean { | ||
return this.collections.some(channel => channel.id() === id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.