|
| 1 | +export interface ISmithyModel { |
| 2 | + smithy: "2.0"; |
| 3 | + metadata: { |
| 4 | + suppressions: { id: string; namespace: string }[]; |
| 5 | + }; |
| 6 | + shapes: Record<ISmithyModelShapeId, ISmithyModelShape>; |
| 7 | +} |
| 8 | + |
| 9 | +export interface ISmithyModelShape { |
| 10 | + type: string; |
| 11 | +} |
| 12 | + |
| 13 | +export interface ISmithyModelServiceShape extends ISmithyModelShape { |
| 14 | + type: "service"; |
| 15 | + version: string; |
| 16 | + operations: { target: ISmithyModelShapeId }[]; |
| 17 | + traits: ISmithyModelTraits; |
| 18 | +} |
| 19 | + |
| 20 | +export interface ISmithyModelStructureShape extends ISmithyModelShape { |
| 21 | + type: "structure"; |
| 22 | + members: { |
| 23 | + [memberName: string]: { |
| 24 | + target: ISmithyModelShapeId; |
| 25 | + traits: ISmithyModelTraits; |
| 26 | + }; |
| 27 | + }; |
| 28 | + traits: ISmithyModelTraits; |
| 29 | +} |
| 30 | + |
| 31 | +export interface ISmithyModelOperationShape extends ISmithyModelShape { |
| 32 | + type: "operation"; |
| 33 | + input: { |
| 34 | + target: ISmithyModelShapeId; |
| 35 | + }; |
| 36 | + output: { |
| 37 | + target: ISmithyModelShapeId; |
| 38 | + }; |
| 39 | + errors: { target: ISmithyModelShapeId }[]; |
| 40 | + traits: ISmithyModelTraits; |
| 41 | +} |
| 42 | + |
| 43 | +export type ISmithyModelTraits = { |
| 44 | + "smithy.api#http"?: { |
| 45 | + method: string; |
| 46 | + uri: string; |
| 47 | + code: number; |
| 48 | + }; |
| 49 | + "smithy.api#httpLabel"?: {} | undefined; |
| 50 | + "smithy.api#httpHeader"?: string; |
| 51 | + "smithy.api#httpQuery"?: string; |
| 52 | + "smithy.api#httpPayload"?: {} | undefined; |
| 53 | + "smithy.api#jsonName"?: string; |
| 54 | + "smithy.api#httpResponseCode"?: {} | undefined; |
| 55 | + [traitName: string]: unknown; |
| 56 | +}; |
| 57 | + |
| 58 | +export type ISmithyModelShapeId = `${string}#${string}`; |
| 59 | + |
| 60 | +export class SmithyModel implements ISmithyModel { |
| 61 | + public smithy: ISmithyModel["smithy"]; |
| 62 | + public metadata: ISmithyModel["metadata"]; |
| 63 | + public shapes: ISmithyModel["shapes"]; |
| 64 | + |
| 65 | + public static from(model: ISmithyModel) { |
| 66 | + if (model instanceof SmithyModel) { |
| 67 | + return model; |
| 68 | + } |
| 69 | + return new SmithyModel(model); |
| 70 | + } |
| 71 | + |
| 72 | + public constructor(public readonly _jsonObject: ISmithyModel) { |
| 73 | + this.smithy = _jsonObject.smithy; |
| 74 | + this.metadata = _jsonObject.metadata; |
| 75 | + this.shapes = _jsonObject.shapes; |
| 76 | + } |
| 77 | +} |
0 commit comments