diff --git a/BCL.csproj b/BCL.csproj index c6bc42f54..12f12153c 100644 --- a/BCL.csproj +++ b/BCL.csproj @@ -116,11 +116,12 @@ file-system.d.ts - - http.d.ts + + + http-request.d.ts - - http.d.ts + + http-request.d.ts image-source-native.d.ts @@ -135,6 +136,7 @@ + application-tests-common.ts @@ -188,7 +190,9 @@ file-system-access.d.ts - + + http.d.ts + diff --git a/camera/camera.d.ts b/camera/camera.d.ts index 81595ba54..9929ae801 100644 --- a/camera/camera.d.ts +++ b/camera/camera.d.ts @@ -1,7 +1,7 @@  declare module "camera" { - import promises = require("promises/promises"); + import promises = require("promises"); import imageSource = require("image-source"); enum CameraPosition { diff --git a/camera/camera.ios.ts b/camera/camera.ios.ts index b2756eb72..09c6939cb 100644 --- a/camera/camera.ios.ts +++ b/camera/camera.ios.ts @@ -1,4 +1,4 @@ -import promises = require("promises/promises"); +import promises = require("promises"); import imageSource = require("image-source"); import types = require("camera/camera-types"); diff --git a/console/console-native.d.ts b/console/console-native.d.ts index 5c94fa29a..40a4c8d7f 100644 --- a/console/console-native.d.ts +++ b/console/console-native.d.ts @@ -1,4 +1,5 @@ -export declare var helper_log: (message: string) => void; +//@private +export declare var helper_log: (message: string) => void; export declare var info: (message: string) => void; export declare var error: (message: string) => void; export declare var warn: (message: string) => void; diff --git a/file-system/file-system-access.d.ts b/file-system/file-system-access.d.ts index ab02b575a..385db188c 100644 --- a/file-system/file-system-access.d.ts +++ b/file-system/file-system-access.d.ts @@ -1,6 +1,4 @@ -// TODO: Implement "hidden" notation so that such declarations are not included in the d.ts file we will provide for the users. -//@hidden - +//@private export declare class FileSystemAccess { getLastModified(path: string): Date; diff --git a/file-system/file-system.d.ts b/file-system/file-system.d.ts index 53fa3ed6d..e330ea3bc 100644 --- a/file-system/file-system.d.ts +++ b/file-system/file-system.d.ts @@ -1,7 +1,7 @@  declare module "file-system" { - import promises = require("promises/promises"); + import promises = require("promises"); export class FileSystemEntity { /** diff --git a/file-system/file-system.impl.ts b/file-system/file-system.impl.ts index 09d26bef1..95bedff7b 100644 --- a/file-system/file-system.impl.ts +++ b/file-system/file-system.impl.ts @@ -1,5 +1,5 @@ import file_access_module = require("file-system/file-system-access"); -import promises = require("promises/promises"); +import promises = require("promises"); // The FileSystemAccess implementation, used through all the APIs. var fileAccess; diff --git a/http/http.android.ts b/http/http-request.android.ts similarity index 95% rename from http/http.android.ts rename to http/http-request.android.ts index 9b40c5e24..c3c577ecf 100644 --- a/http/http.android.ts +++ b/http/http-request.android.ts @@ -1,11 +1,10 @@ /** * Android specific http request implementation. */ -import promises = require("promises/promises"); -import http = require("http"); +import promises = require("promises"); -declare var exports; -require("utils/module-merge").merge(require("http/http-common"), exports); +// this is imported for definition purposes only +import http = require("http"); export function request(options: http.HttpRequestOptions): promises.Promise { var d = promises.defer(); diff --git a/http/http-request.d.ts b/http/http-request.d.ts new file mode 100644 index 000000000..57f71adc6 --- /dev/null +++ b/http/http-request.d.ts @@ -0,0 +1,5 @@ +//@private +import promises = require("promises"); +import http = require("http"); + +export declare var request: (options: http.HttpRequestOptions) => promises.Promise; \ No newline at end of file diff --git a/http/http.ios.ts b/http/http-request.ios.ts similarity index 94% rename from http/http.ios.ts rename to http/http-request.ios.ts index 396653a46..ecae6e6f3 100644 --- a/http/http.ios.ts +++ b/http/http-request.ios.ts @@ -1,12 +1,9 @@ /** * iOS specific http request implementation. */ -import promises = require("promises/promises"); +import promises = require("promises"); import http = require("http"); -declare var exports; -require("utils/module-merge").merge(require("http/http-common"), exports); - export function request(options: http.HttpRequestOptions): promises.Promise { var d = promises.defer(); diff --git a/http/http.d.ts b/http/http.d.ts index 6d4367b2a..660eec6f4 100644 --- a/http/http.d.ts +++ b/http/http.d.ts @@ -1,7 +1,7 @@  declare module "http" { import image = require("image-source"); - import promises = require("promises/promises"); + import promises = require("promises"); function getString(url: string): promises.Promise function getString(options: HttpRequestOptions): promises.Promise diff --git a/http/http-common.ts b/http/http.impl.ts similarity index 60% rename from http/http-common.ts rename to http/http.impl.ts index 146e8a206..743b2a097 100644 --- a/http/http-common.ts +++ b/http/http.impl.ts @@ -1,15 +1,18 @@ import image = require("image-source"); -import promises = require("promises/promises"); -import http = require("http"); +import promises = require("promises"); +import request = require("http/http-request"); + +// merge the exports of the request file with the exports of this file +declare var exports; +require("utils/module-merge").merge(request, exports); /** - * Gets string from url. - */ - +* Gets string from url. +*/ export function getString(arg: any): promises.Promise { var d = promises.defer(); - http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) + request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toString())) .fail(e => d.reject(e)); @@ -22,7 +25,7 @@ export function getString(arg: any): promises.Promise { export function getJSON(arg: any): promises.Promise { var d = promises.defer(); - http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) + request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toJSON())) .fail(e => d.reject(e)); @@ -36,7 +39,7 @@ export function getJSON(arg: any): promises.Promise { export function getImage(arg: any): promises.Promise { var d = promises.defer(); - http.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) + request.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => d.resolve(r.content.toImage())) .fail(e => d.reject(e)); diff --git a/image-source/image-source-native.d.ts b/image-source/image-source-native.d.ts index 3e3646ecf..442a591f0 100644 --- a/image-source/image-source-native.d.ts +++ b/image-source/image-source-native.d.ts @@ -1,7 +1,9 @@ -/** +//@private +/** * This module is used as a native implementation for each of the underlying platforms. * Users will not typically require it as it supports the module infrastructure. */ +// export declare function fromResource(name: string): any; export declare function fromFile(path: string): any; export declare function fromData(data: any): any; diff --git a/image-source/image-source.d.ts b/image-source/image-source.d.ts index b08515e05..f41e6db14 100644 --- a/image-source/image-source.d.ts +++ b/image-source/image-source.d.ts @@ -1,6 +1,6 @@  declare module "image-source" { - import promises = require("promises/promises"); + import promises = require("promises"); /** * Defines the recognized image formats. diff --git a/image-source/image-source.impl.ts b/image-source/image-source.impl.ts index bf679c4e4..eba2264f6 100644 --- a/image-source/image-source.impl.ts +++ b/image-source/image-source.impl.ts @@ -1,6 +1,6 @@ import app = require("application"); import native = require("image-source/image-source-native"); -import promises = require("promises/promises"); +import promises = require("promises"); import http = require("http"); // This is used for definition purposes only, it does not generate JavaScript for it. diff --git a/location/location-manager.d.ts b/location/location-manager.d.ts index 8ba682bd3..918a5c45e 100644 --- a/location/location-manager.d.ts +++ b/location/location-manager.d.ts @@ -1,4 +1,4 @@ - +//@private export declare class Location { latitude: number; longitude: number; diff --git a/location/location.d.ts b/location/location.d.ts index ebc632a3b..c209bcf50 100644 --- a/location/location.d.ts +++ b/location/location.d.ts @@ -1,5 +1,4 @@ - -import promises = require("promises/promises"); +import promises = require("promises"); export declare enum Accuracy { // in meters diff --git a/location/location.impl.ts b/location/location.impl.ts index 0fa5a43f3..18d3aa12f 100644 --- a/location/location.impl.ts +++ b/location/location.impl.ts @@ -1,4 +1,4 @@ -import promises = require("promises/promises"); +import promises = require("promises"); import timer = require("timer/timer"); import types = require("location/location-types"); import locationManagerModule = require("location/location-manager"); diff --git a/promises/promises.d.ts b/promises/promises.d.ts new file mode 100644 index 000000000..38307aaf0 --- /dev/null +++ b/promises/promises.d.ts @@ -0,0 +1,124 @@ + +declare module "promises" { + /** + Module P: Generic Promises for TypeScript + Project, documentation, and license: https://github.com/pragmatrix/Promise + */ + + /** + Returns a new "Deferred" value that may be resolved or rejected. + */ + export function defer(): Deferred; + /** + Converts a value to a resolved promise. + */ + export function resolve(v: Value): Promise; + /** + Returns a rejected promise. + */ + export function reject(err: Rejection): Promise; + /** + http://en.wikipedia.org/wiki/Anamorphism + + Given a seed value, unfold calls the unspool function, waits for the returned promise to be resolved, and then + calls it again if a next seed value was returned. + + All the values of all promise results are collected into the resulting promise which is resolved as soon + the last generated element value is resolved. + */ + export function unfold(unspool: (current: Seed) => { + promise: Promise; + next?: Seed; + }, seed: Seed): Promise; + /** + The status of a Promise. Initially a Promise is Unfulfilled and may + change to Rejected or Resolved. + + Once a promise is either Rejected or Resolved, it can not change its + status anymore. + */ + export enum Status { + Unfulfilled = 0, + Rejected = 1, + Resolved = 2, + } + /** + If a promise gets rejected, at least a message that indicates the error or + reason for the rejection must be provided. + */ + export interface Rejection { + message: string; + } + /** + Both Promise and Deferred share these properties. + */ + export interface PromiseState { + status: Status; + result?: Value; + error?: Rejection; + } + /** + A Promise supports basic composition and registration of handlers that are called when the + promise is fulfilled. + + When multiple handlers are registered with done(), fail(), or always(), they are called in the + same order. + */ + export interface Promise extends PromiseState { + /** + Returns a promise that represents a promise chain that consists of this + promise and the promise that is returned by the function provided. + The function receives the value of this promise as soon it is resolved. + + If this promise fails, the function is never called and the returned promise + will also fail. + */ + then(f: (v: Value) => Promise): Promise; + then(f: (v: Value) => T2): Promise; + done(f: (v: Value) => void): Promise; + fail(f: (err: Rejection) => void): Promise; + always(f: (v?: Value, err?: Rejection) => void): Promise; + } + /** + Deferred supports the explicit resolving and rejecting of the + promise and the registration of fulfillment handlers. + + A Deferred should be only visible to the function that initially sets up + an asynchronous process. Callers of that function should only see the Promise that + is returned by promise(). + */ + export interface Deferred extends PromiseState { + promise(): Promise; + resolve(result?: Value): Deferred; + reject(err: Rejection): Deferred; + done(f: (v: Value) => void): Deferred; + fail(f: (err: Rejection) => void): Deferred; + always(f: (v?: Value, err?: Rejection) => void): Deferred; + } + /** + Creates a promise that gets resolved when all the promises in the argument list get resolved. + As soon one of the arguments gets rejected, the resulting promise gets rejected. + If no promises were provided, the resulting promise is immediately resolved. + */ + export function when(...promises: Promise[]): Promise; + /** + Promise Generators and Iterators. + */ + export interface Generator { + (): Iterator; + } + export interface Iterator { + advance(): Promise; + current: E; + } + export function generator(g: () => () => Promise): Generator; + export function iterator(f: () => Promise): Iterator; + /** + Iterator functions. + */ + export function each(gen: Generator, f: (e: E) => void): Promise<{}>; + /** + std + */ + export function isUndefined(v: any): boolean; +} \ No newline at end of file