Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy flow files so that the module returns typed values #51

Merged
merged 11 commits into from
Jan 16, 2019
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"scripts": {
"prepublish": "yarn run build",
"build": "babel ./src -d ./lib",
"build": "babel ./src --ignore **/*/__mocks__,**/test.js -d ./lib",
"prebuild": "flow-copy-source --ignore '**/*/__mocks__/*.js' --ignore '**/*test.js' ./src ./lib",
"lint": "eslint .",
"test": "jest",
"test-inspect": "node --inspect-brk ./node_modules/.bin/jest --runInBand",
Expand Down Expand Up @@ -49,6 +50,7 @@
"eslint-plugin-prettier": "^2.6.2",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "^0.80.0",
"flow-copy-source": "^2.0.2",
"flow-typed": "^2.5.1",
"jest": "^23.6.0",
"jest-fetch-mock": "GrahamTheCoder/jest-fetch-mock#blob-fix",
Expand All @@ -69,4 +71,4 @@
"peerDependencies": {
"@elasticprojects/abstract-cli": "^0.31.0"
}
}
}
2 changes: 1 addition & 1 deletion src/AUTO/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { AbstractInterface } from "../";
import type { AbstractInterface } from "../types";
import AbstractCLI, { type Options as OptionsCLI } from "../AbstractCLI";
import AbstractAPI, { type Options as OptionsAPI } from "../AbstractAPI";

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractAPI/Cursor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @flow */
import type { CursorMeta, CursorPromise, CursorResponse } from "../";
import type { CursorMeta, CursorPromise, CursorResponse } from "../types";

export default class Cursor<T> {
lastResponse: ?Promise<CursorResponse<T> | void>;
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractAPI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
AccessToken,
Activity,
Notification
} from "../";
} from "../types";
import randomTraceId from "./randomTraceId";
import Cursor from "./Cursor";

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractCLI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
LayerDescriptor,
CollectionDescriptor,
AccessTokenOption
} from "../";
} from "../types";

const logSpawn = log.extend("AbstractCLI:spawn");
const logError = log.extend("AbstractCLI:error");
Expand Down
2 changes: 1 addition & 1 deletion src/Client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import type { AbstractInterface, AccessTokenOption } from "../";
import type { AbstractInterface, AccessTokenOption } from "../types";
import { AUTO } from "../transports";

type Options = {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import * as TRANSPORTS from "./transports";

export { client, Sketch, TRANSPORTS };
export { client as Client }; // Deprecated: prefer Abstract.client factory
export type * from "./types";
6 changes: 5 additions & 1 deletion src/sketch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @flow
/* global process NSString PROSketchBootstrap */
import type { ProjectDescriptor, BranchDescriptor, FileDescriptor } from ".";
import type {
ProjectDescriptor,
BranchDescriptor,
FileDescriptor
} from "./types";

export function isSketchPlugin() {
// New versions of skpm set process type to "sketch". For older
Expand Down
2 changes: 1 addition & 1 deletion src/support/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
CommentDescriptor,
UserDescriptor,
AssetDescriptor
} from "../";
} from "../types";

export function buildOptions(options: *) {
return {
Expand Down
38 changes: 17 additions & 21 deletions src/index.js.flow → src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export type CommitDescriptor = {|

export type BranchDescriptor = {|
...ObjectDescriptor,
sha: $PropertyType<ObjectDescriptor, "sha"> | "latest"
sha: $PropertyType<ObjectDescriptor, "sha">
|};

export type FileDescriptor = {|
...ObjectDescriptor,
sha: $PropertyType<ObjectDescriptor, "sha"> | "latest",
sha: $PropertyType<ObjectDescriptor, "sha">,
fileId: string
|};

Expand All @@ -55,7 +55,7 @@ export type PageDescriptor = {|

export type LayerDescriptor = {|
...ObjectDescriptor,
sha: $PropertyType<ObjectDescriptor, "sha"> | "latest",
sha: $PropertyType<ObjectDescriptor, "sha">,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a note here for future us. Flow doesn't appear to be refining the literal "latest" when a desscriptor (like CommitDescriptor) and descriptor that supports latest are in a union

screenshot 2019-01-08 15 53 42

fileId: string,
pageId: string,
layerId: string
Expand All @@ -67,7 +67,7 @@ export type UserDescriptor = {|
userId: string
|};

export type AssetDescriptor ={|
export type AssetDescriptor = {|
assetId: string,
projectId: string
|};
Expand Down Expand Up @@ -332,7 +332,7 @@ export type User = {

export type Organization = {
billingEmail?: string,
features: {[feature: string]: boolean},
features: { [feature: string]: boolean },
hasBillingInfo?: boolean,
id: string,
isUsernameOrganization?: boolean,
Expand Down Expand Up @@ -1281,7 +1281,7 @@ export type Asset = {
projectId: string,
scale: string,
sha: string,
url: string,
url: string
};

export interface CursorPromise<T> extends Promise<T> {
Expand Down Expand Up @@ -1322,7 +1322,9 @@ export interface AbstractInterface {
};

organizations?: {
info: (organizationDescriptor: OrganizationDescriptor) => Promise<Organization>,
info: (
organizationDescriptor: OrganizationDescriptor
) => Promise<Organization>,
list: () => Promise<Organization[]>
};

Expand Down Expand Up @@ -1413,27 +1415,21 @@ export interface AbstractInterface {
objectDescriptor?: OrganizationDescriptor,
options?: ListOptions
) => CursorPromise<Notification[]>,
info: (notificationDescriptor: NotificationDescriptor) => Promise<Notification>
info: (
notificationDescriptor: NotificationDescriptor
) => Promise<Notification>
};

users?: {
list: (
objectDescriptor: OrganizationDescriptor | ProjectDescriptor
) => Promise<User[]>,
info: (
userDescriptor: UserDescriptor
) => Promise<User>
info: (userDescriptor: UserDescriptor) => Promise<User>
};

assets?: {
list: (
objectDescriptor: BranchDescriptor
) => Promise<Asset[]>,
info: (
assetDescriptor: AssetDescriptor
) => Promise<Asset>,
raw: (
assetDescriptor: AssetDescriptor
) => Promise<ArrayBuffer>
}
list: (objectDescriptor: BranchDescriptor) => Promise<Asset[]>,
info: (assetDescriptor: AssetDescriptor) => Promise<Asset>,
raw: (assetDescriptor: AssetDescriptor) => Promise<ArrayBuffer>
};
}
Copy link
Contributor

@amccloud amccloud Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we export some/all of these types in index.js so that we can have access to Abstract.ShareDescriptor or Abstract.types.ShareDescriptor in application code

2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
FileDescriptor,
LayerDescriptor,
ShareDescriptor
} from "./";
} from "./types";

export function objectBranchDescriptor(
objectDescriptor:
Expand Down
Loading