Skip to content

Commit

Permalink
flow types.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Feb 2, 2017
1 parent 554c017 commit 83d1dcf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 9 additions & 1 deletion interfaces/external-modules/kinto-http.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ declare module "kinto-http" {
body: Object,
};

declare type PermissionEntry = {
resource_name: "bucket" | "group" | "collection" | "record",
id: string,
bucket_id: string,
collection_id?: string,
permissions: string[],
};

declare class KintoClient {
remote: string;
defaultReqOptions: {
Expand All @@ -45,7 +53,7 @@ declare module "kinto-http" {
batch(): Promise<BatchResponse[]>;
fetchServerInfo(): Promise<Object>;
listBuckets(): Promise<ListResponseBody<Resource>>;
listPermissions(): Promise<ListResponseBody<Object>>;
listPermissions(): Promise<ListResponseBody<PermissionEntry>>;
}

declare class Bucket {
Expand Down
5 changes: 3 additions & 2 deletions src/sagas/session.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */
import type { ActionType, GetStateFn, SagaGen } from "../types";
import type { PermissionEntry } from "kinto-http";
import type { ActionType, BucketEntry, GetStateFn, SagaGen } from "../types";

import { push as updatePath } from "react-router-redux";
import { call, put } from "redux-saga/effects";
Expand Down Expand Up @@ -34,7 +35,7 @@ export function* sessionLogout(getState: GetStateFn, action: ActionType<typeof a
yield call(clearSession);
}

export function expandBucketsCollections(buckets: Object[], permissions: Object[]) {
export function expandBucketsCollections(buckets: BucketEntry[], permissions: PermissionEntry[]): BucketEntry[] {
// Create a copy to avoid mutating the source object
const bucketsCopy = clone(buckets);

Expand Down
15 changes: 14 additions & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,25 @@ export type TokenAuth = {

export type SagaGen = Generator<*,void,*>;

export type CollectionEntry = {
id: string,
permissions: string[],
readonly: boolean,
};

export type BucketEntry = {
id: string,
permissions: string[],
collections: CollectionEntry[],
readonly: boolean,
};

export type SessionState = {
busy: boolean,
auth: ?AuthData;
authenticated: boolean,
permissions: ?PermissionsListEntry[],
buckets: Object[],
buckets: BucketEntry[],
serverInfo: ServerInfo,
redirectURL: ?string,
};
Expand Down

0 comments on commit 83d1dcf

Please sign in to comment.