Skip to content

Commit

Permalink
Move typing to type.ts (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidubov authored Jun 22, 2020
1 parent 6f9c5ea commit e7f80af
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 173 deletions.
156 changes: 0 additions & 156 deletions src/@types/rest-definitions.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/script/acquisition-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpdateCheckResponse, UpdateCheckRequest, DeploymentStatusReport, DownloadReport } from "rest-definitions";
import { UpdateCheckResponse, UpdateCheckRequest, DeploymentStatusReport, DownloadReport } from "./types";
import { CodePushHttpError, CodePushDeployStatusError, CodePushPackageError } from "../utils/code-push-error"

export module Http {
Expand Down
171 changes: 162 additions & 9 deletions src/script/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,173 @@
export { AccessKeyRequest, Account, App, AppCreationRequest, CollaboratorMap, CollaboratorProperties, Deployment, DeploymentMetrics, Package, PackageInfo, AccessKey as ServerAccessKey, UpdateMetrics } from "rest-definitions";
/**
* Annotations for properties on 'inout' interfaces:
* - generated: This property cannot be specified on any input requests (PUT/PATCH/POST).
* As a result, generated properties are always marked as optional.
* - key: This property is the identifier for an object, with certain uniqueness constraints.
*/

interface AccessKeyBase {
createdBy?: string;
/*legacy*/ description?: string;
/*key*/ friendlyName?: string;
/*generated key*/ name?: string;
}

/*out*/
export interface ServerAccessKey extends AccessKeyBase {
/*generated*/ createdTime?: number;
expires: number;
/*generated*/ isSession?: boolean;
}

/*in*/
export interface AccessKeyRequest extends AccessKeyBase {
ttl?: number;
}

/*out*/
export interface DeploymentMetrics {
[packageLabelOrAppVersion: string]: UpdateMetrics;
}

/*in*/
export interface DeploymentStatusReport {
app_version: string;
client_unique_id?: string;
deployment_key: string;
previous_deployment_key?: string;
previous_label_or_app_version?: string;
label?: string;
status?: string;
}

/*in*/
export interface DownloadReport {
client_unique_id: string;
deployment_key: string;
label: string;
}

/*inout*/
export interface PackageInfo {
appVersion?: string;
description?: string;
isDisabled?: boolean;
isMandatory?: boolean;
/*generated*/ label?: string;
/*generated*/ packageHash?: string;
rollout?: number;
}

/*out*/
export interface UpdateCheckResponse {
download_url?: string;
description?: string;
is_available: boolean;
is_disabled?: boolean;
target_binary_range: string;
/*generated*/ label?: string;
/*generated*/ package_hash?: string;
package_size?: number;
should_run_binary_version?: boolean;
update_app_version?: boolean;
is_mandatory?: boolean;
}

/*in*/
export interface UpdateCheckRequest {
app_version: string;
client_unique_id?: string;
deployment_key: string;
is_companion?: boolean;
label?: string;
package_hash?: string;
}

/*out*/
export interface UpdateMetrics {
active: number;
downloaded?: number;
failed?: number;
installed?: number;
}

/*out*/
export interface Account {
/*key*/ email: string;
name: string;
linkedProviders: string[];
}

/*out*/
export interface CollaboratorProperties {
isCurrentAccount?: boolean;
permission: string;
}

/*out*/
export interface CollaboratorMap {
[email: string]: CollaboratorProperties;
}

/*inout*/
export interface App {
/*generated*/ collaborators?: CollaboratorMap;
/*key*/ name: string;
/* generated */ deployments?: string[];
os?: string;
platform?: string;
}

/*in*/
export interface AppCreationRequest extends App {
manuallyProvisionDeployments?: boolean;
}

/*inout*/
export interface Deployment {
/*generated key*/ key?: string;
/*key*/ name: string;
/*generated*/ package?: Package;
}

/*out*/
export interface BlobInfo {
size: number;
url: string;
}

/*out*/
export interface PackageHashToBlobInfoMap {
[packageHash: string]: BlobInfo;
}

/*inout*/
export interface Package extends PackageInfo {
/*generated*/ blobUrl: string;
/*generated*/ diffPackageMap?: PackageHashToBlobInfoMap;
/*generated*/ originalLabel?: string; // Set on "Promote" and "Rollback"
/*generated*/ originalDeployment?: string; // Set on "Promote"
/*generated*/ releasedBy?: string; // Set by commitPackage
/*generated*/ releaseMethod?: string; // "Upload", "Promote" or "Rollback". Unknown if unspecified
/*generated*/ size: number;
/*generated*/ uploadTime: number;
}

export interface CodePushError {
message: string;
statusCode: number;
message: string;
statusCode: number;
}

export interface AccessKey {
createdTime: number;
expires: number;
name: string;
key?: string;
createdTime: number;
expires: number;
name: string;
key?: string;
}

export interface Session {
loggedInTime: number;
machineName: string;
loggedInTime: number;
machineName: string;
}

export type Headers = { [headerName: string]: string };
10 changes: 5 additions & 5 deletions src/test/acquisition-rest-mock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as querystring from "querystring";

import * as acquisitionSdk from "../script/acquisition-sdk";
import * as rest from "rest-definitions";
import * as types from "../script/types";

export var validDeploymentKey = "Valid Deployment Key";
export var latestPackage = <rest.UpdateCheckResponse>{
export var latestPackage = <types.UpdateCheckResponse>{
download_url: "http://www.windowsazure.com/blobs/awperoiuqpweru",
description: "Angry flappy birds",
target_binary_range: "1.5.0",
Expand Down Expand Up @@ -74,7 +74,7 @@ class Server {
}

public static onUpdateCheck(params: any, callback: acquisitionSdk.Callback<acquisitionSdk.Http.Response>): void {
var updateRequest: rest.UpdateCheckRequest = {
var updateRequest: types.UpdateCheckRequest = {
deployment_key: params.deployment_key,
app_version: params.app_version,
package_hash: params.package_hash,
Expand All @@ -85,14 +85,14 @@ class Server {
if (!updateRequest.deployment_key || !updateRequest.app_version) {
callback(/*error=*/ null, { statusCode: 400 });
} else {
var updateInfo = <rest.UpdateCheckResponse>{ is_available: false };
var updateInfo = <types.UpdateCheckResponse>{ is_available: false };
if (updateRequest.deployment_key === validDeploymentKey) {
if (updateRequest.is_companion || updateRequest.app_version === latestPackage.target_binary_range) {
if (updateRequest.package_hash !== latestPackage.package_hash) {
updateInfo = latestPackage;
}
} else if (updateRequest.app_version < latestPackage.target_binary_range) {
updateInfo = <rest.UpdateCheckResponse><any>{ update_app_version: true, target_binary_range: latestPackage.target_binary_range };
updateInfo = <types.UpdateCheckResponse><any>{ update_app_version: true, target_binary_range: latestPackage.target_binary_range };
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as assert from "assert";

import * as acquisitionSdk from "../script/acquisition-sdk";
import * as acquisitionRestMock from "./acquisition-rest-mock";
import * as rest from "rest-definitions";
import * as types from "../script/types";
import { CodePushPackageError } from "../utils/code-push-error"

const mockApi = acquisitionRestMock;
var latestPackage: rest.UpdateCheckResponse = clone(mockApi.latestPackage);
var latestPackage: types.UpdateCheckResponse = clone(mockApi.latestPackage);

var configuration: acquisitionSdk.Configuration = {
appVersion: "1.5.0",
Expand Down

0 comments on commit e7f80af

Please sign in to comment.