Browse Source

Load fix for transport chooser

master 0.8.1
Kegan Myers 8 years ago
parent
commit
85c5fe3d0d
  1. 2
      bower.json
  2. 102
      build/typertext.d.ts
  3. 298
      build/typertext.js
  4. 2
      build/typertext.js.map
  5. 2
      build/typertext.min.js
  6. 2
      build/typertext.min.js.map
  7. 4
      lib/Typertext/Http/HttpRequest.ts
  8. 2
      package.json

2
bower.json

@ -1,6 +1,6 @@
{
"name": "Typertext",
"version": "0.8.0",
"version": "0.8.1",
"homepage": "https://github.com/terribleplan/Typertext",
"authors": [
"Kegan Myers <kegan@keganmyers.com>"

102
build/typertext.d.ts

@ -9,20 +9,6 @@ declare module Typertext {
public GetCustom(): T;
}
}
declare module Typertext.Transport {
interface TransportConstructor {
new(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: Http.HttpResponseHandler): GenericTransport;
}
}
declare module Typertext {
interface GenericRequest<T extends GenericResponseHandler<GenericResponse<any>>> {
Delete(request: Http.HttpUrl, callback: T): void;
Get(request: Http.HttpUrl, callback: T): void;
Post(request: Http.HttpUrl, postData: Http.HttpPostData, callback: T): void;
Put(request: Http.HttpUrl, putData: Http.HttpPostData, callback: T): void;
RawRequest(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: T, transport?: Transport.TransportConstructor): void;
}
}
declare module Typertext {
class GenericResponse<T> {
private status;
@ -42,10 +28,6 @@ declare module Typertext {
(response: T): void;
}
}
declare module Typertext.Http {
class HttpException extends BaseException<HttpResponse> {
}
}
declare module Typertext.Http {
enum HttpMethod {
DELETE = 0,
@ -62,6 +44,46 @@ declare module Typertext.Http {
[index: string]: string;
}
}
declare module Typertext.Http {
class HttpUrl {
private domain;
private path;
private port;
private protocol;
private queryString;
static DefaultPort(protocol: HttpProtocol): number;
static FromUrl(location: string): HttpUrl;
static DecodeQueryString(queryString: string): HttpQueryString;
static EncodeQueryString(query: HttpQueryString): string;
static UrlEncodeObject(data: HttpQueryString): string;
static UrlDecodeString(queryString: string): HttpQueryString;
private static splitString(input, separator, limit?);
constructor(domain: string, protocol?: HttpProtocol, path?: string, queryString?: HttpQueryString, port?: number);
public ToString(): string;
public GetPort(): number;
public GetDomain(): string;
public GetProtocol(): HttpProtocol;
public SameOriginCheck(url: HttpUrl): boolean;
}
}
declare module Typertext.Transport {
interface TransportConstructor {
new(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: Http.HttpResponseHandler): GenericTransport;
}
}
declare module Typertext {
interface GenericRequest<T extends GenericResponseHandler<GenericResponse<any>>> {
Delete(request: Http.HttpUrl, callback: T): void;
Get(request: Http.HttpUrl, callback: T): void;
Post(request: Http.HttpUrl, postData: Http.HttpPostData, callback: T): void;
Put(request: Http.HttpUrl, putData: Http.HttpPostData, callback: T): void;
RawRequest(method: Http.HttpMethod, request: Http.HttpUrl, postData?: Http.HttpPostData, callback?: T, transport?: Transport.TransportConstructor): void;
}
}
declare module Typertext.Http {
class HttpException extends BaseException<HttpResponse> {
}
}
declare module Typertext.Http {
enum HttpProtocol {
http = 0,
@ -73,6 +95,17 @@ declare module Typertext.Http {
[index: string]: string;
}
}
declare module Typertext.Transport {
interface GenericTransport {
Send(): void;
Destroy(): void;
}
}
declare module Typertext.Transport {
class TransportChooser {
static Transport(method: Http.HttpMethod, request: Http.HttpUrl, postData: Http.HttpPostData, callback: Http.HttpResponseHandler): TransportConstructor;
}
}
declare module Typertext.Http {
class HttpRequest implements GenericRequest<HttpResponseHandler> {
constructor();
@ -102,28 +135,6 @@ declare module Typertext.Http {
timeout = 5,
}
}
declare module Typertext.Http {
class HttpUrl {
private domain;
private path;
private port;
private protocol;
private queryString;
static DefaultPort(protocol: HttpProtocol): number;
static FromUrl(location: string): HttpUrl;
static DecodeQueryString(queryString: string): HttpQueryString;
static EncodeQueryString(query: HttpQueryString): string;
static UrlEncodeObject(data: HttpQueryString): string;
static UrlDecodeString(queryString: string): HttpQueryString;
private static splitString(input, separator, limit?);
constructor(domain: string, protocol?: HttpProtocol, path?: string, queryString?: HttpQueryString, port?: number);
public ToString(): string;
public GetPort(): number;
public GetDomain(): string;
public GetProtocol(): HttpProtocol;
public SameOriginCheck(url: HttpUrl): boolean;
}
}
declare module Typertext.Json {
class JsonException extends BaseException<void> {
constructor(message: string, code: number);
@ -159,17 +170,6 @@ declare module Typertext.Json {
interface JsonResponseHandler extends GenericResponseHandler<JsonResponse> {
}
}
declare module Typertext.Transport {
interface GenericTransport {
Send(): void;
Destroy(): void;
}
}
declare module Typertext.Transport {
class TransportChooser {
static Transport(method: Http.HttpMethod, request: Http.HttpUrl, postData: Http.HttpPostData, callback: Http.HttpResponseHandler): TransportConstructor;
}
}
declare module Typertext.Transport {
class XDR implements GenericTransport {
private xdr;

298
build/typertext.js

@ -20,16 +20,6 @@ var Typertext;
return BaseException;
})();
Typertext.BaseException = BaseException;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Transport) {
})(Typertext.Transport || (Typertext.Transport = {}));
var Transport = Typertext.Transport;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
@ -63,26 +53,6 @@ var Typertext;
})();
Typertext.GenericResponse = GenericResponse;
})(Typertext || (Typertext = {}));
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Typertext;
(function (Typertext) {
(function (Http) {
var HttpException = (function (_super) {
__extends(HttpException, _super);
function HttpException() {
_super.apply(this, arguments);
}
return HttpException;
})(Typertext.BaseException);
Http.HttpException = HttpException;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
@ -100,89 +70,6 @@ var Typertext;
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
(function (HttpProtocol) {
HttpProtocol[HttpProtocol["http"] = 0] = "http";
HttpProtocol[HttpProtocol["https"] = 1] = "https";
})(Http.HttpProtocol || (Http.HttpProtocol = {}));
var HttpProtocol = Http.HttpProtocol;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
var TransportChooser = Typertext.Transport.TransportChooser;
var HttpRequest = (function () {
function HttpRequest() {
}
HttpRequest.prototype.Delete = function (request, callback) {
this.RawRequest(5 /* PUT */, request, {}, callback);
};
HttpRequest.prototype.Get = function (request, callback) {
this.RawRequest(1 /* GET */, request, {}, callback);
};
HttpRequest.prototype.Post = function (request, postData, callback) {
this.RawRequest(4 /* POST */, request, postData, callback);
};
HttpRequest.prototype.Put = function (request, putData, callback) {
this.RawRequest(5 /* PUT */, request, putData, callback);
};
HttpRequest.prototype.RawRequest = function (method, request, postData, callback, transport) {
if (typeof postData === "undefined") { postData = {}; }
if (!callback)
callback = function (c) {
return null;
};
if (!transport)
transport = TransportChooser.Transport(method, request, postData, callback);
var transportInstance = new transport(method, request, postData, callback);
transportInstance.Send();
};
return HttpRequest;
})();
Http.HttpRequest = HttpRequest;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
var HttpResponse = (function (_super) {
__extends(HttpResponse, _super);
function HttpResponse(status, responseHeaderGetter, httpResponseCode, responseBody) {
_super.call(this, status, responseHeaderGetter, httpResponseCode, responseBody);
}
return HttpResponse;
})(Typertext.GenericResponse);
Http.HttpResponse = HttpResponse;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
(function (HttpResponseStatus) {
HttpResponseStatus[HttpResponseStatus["success"] = 0] = "success";
HttpResponseStatus[HttpResponseStatus["serverError"] = 1] = "serverError";
HttpResponseStatus[HttpResponseStatus["clientError"] = 2] = "clientError";
HttpResponseStatus[HttpResponseStatus["responseError"] = 3] = "responseError";
HttpResponseStatus[HttpResponseStatus["unknownError"] = 4] = "unknownError";
HttpResponseStatus[HttpResponseStatus["timeout"] = 5] = "timeout";
})(Http.HttpResponseStatus || (Http.HttpResponseStatus = {}));
var HttpResponseStatus = Http.HttpResponseStatus;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
var HttpUrl = (function () {
@ -307,6 +194,155 @@ var Typertext;
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Transport) {
})(Typertext.Transport || (Typertext.Transport = {}));
var Transport = Typertext.Transport;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
})(Typertext || (Typertext = {}));
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Typertext;
(function (Typertext) {
(function (Http) {
var HttpException = (function (_super) {
__extends(HttpException, _super);
function HttpException() {
_super.apply(this, arguments);
}
return HttpException;
})(Typertext.BaseException);
Http.HttpException = HttpException;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
(function (HttpProtocol) {
HttpProtocol[HttpProtocol["http"] = 0] = "http";
HttpProtocol[HttpProtocol["https"] = 1] = "https";
})(Http.HttpProtocol || (Http.HttpProtocol = {}));
var HttpProtocol = Http.HttpProtocol;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Transport) {
var HttpUrl = Typertext.Http.HttpUrl;
var TransportChooser = (function () {
function TransportChooser() {
}
TransportChooser.Transport = function (method, request, postData, callback) {
var ieTestDiv = document.createElement("div");
ieTestDiv.innerHTML = "<!--[if lte IE 7]><i></i><![endif]-->";
if (ieTestDiv.getElementsByTagName("i").length === 1) {
throw {};
}
ieTestDiv.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->";
var ieLte9 = (ieTestDiv.getElementsByTagName("i").length === 1);
var origin = HttpUrl.FromUrl(window.location.href);
if (origin.SameOriginCheck(origin) || !ieLte9) {
return Typertext.Transport.XHR;
}
if (origin.GetProtocol() === request.GetProtocol()) {
return Typertext.Transport.XDR;
}
throw {};
};
return TransportChooser;
})();
Transport.TransportChooser = TransportChooser;
})(Typertext.Transport || (Typertext.Transport = {}));
var Transport = Typertext.Transport;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
var TransportChooser = Typertext.Transport.TransportChooser;
var HttpRequest = (function () {
function HttpRequest() {
}
HttpRequest.prototype.Delete = function (request, callback) {
this.RawRequest(5 /* PUT */, request, {}, callback);
};
HttpRequest.prototype.Get = function (request, callback) {
this.RawRequest(1 /* GET */, request, {}, callback);
};
HttpRequest.prototype.Post = function (request, postData, callback) {
this.RawRequest(4 /* POST */, request, postData, callback);
};
HttpRequest.prototype.Put = function (request, putData, callback) {
this.RawRequest(5 /* PUT */, request, putData, callback);
};
HttpRequest.prototype.RawRequest = function (method, request, postData, callback, transport) {
if (typeof postData === "undefined") { postData = {}; }
if (!callback)
callback = function (c) {
return null;
};
if (!transport)
transport = TransportChooser.Transport(method, request, postData, callback);
var transportInstance = new transport(method, request, postData, callback);
transportInstance.Send();
};
return HttpRequest;
})();
Http.HttpRequest = HttpRequest;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
var HttpResponse = (function (_super) {
__extends(HttpResponse, _super);
function HttpResponse(status, responseHeaderGetter, httpResponseCode, responseBody) {
_super.call(this, status, responseHeaderGetter, httpResponseCode, responseBody);
}
return HttpResponse;
})(Typertext.GenericResponse);
Http.HttpResponse = HttpResponse;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Http) {
(function (HttpResponseStatus) {
HttpResponseStatus[HttpResponseStatus["success"] = 0] = "success";
HttpResponseStatus[HttpResponseStatus["serverError"] = 1] = "serverError";
HttpResponseStatus[HttpResponseStatus["clientError"] = 2] = "clientError";
HttpResponseStatus[HttpResponseStatus["responseError"] = 3] = "responseError";
HttpResponseStatus[HttpResponseStatus["unknownError"] = 4] = "unknownError";
HttpResponseStatus[HttpResponseStatus["timeout"] = 5] = "timeout";
})(Http.HttpResponseStatus || (Http.HttpResponseStatus = {}));
var HttpResponseStatus = Http.HttpResponseStatus;
})(Typertext.Http || (Typertext.Http = {}));
var Http = Typertext.Http;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Json) {
var JsonException = (function (_super) {
@ -407,42 +443,6 @@ var Typertext;
var Json = Typertext.Json;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Transport) {
var HttpUrl = Typertext.Http.HttpUrl;
var TransportChooser = (function () {
function TransportChooser() {
}
TransportChooser.Transport = function (method, request, postData, callback) {
var ieTestDiv = document.createElement("div");
ieTestDiv.innerHTML = "<!--[if lte IE 7]><i></i><![endif]-->";
if (ieTestDiv.getElementsByTagName("i").length === 1) {
throw {};
}
ieTestDiv.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->";
var ieLte9 = (ieTestDiv.getElementsByTagName("i").length === 1);
var origin = HttpUrl.FromUrl(window.location.href);
if (origin.SameOriginCheck(origin) || !ieLte9) {
return Typertext.Transport.XHR;
}
if (origin.GetProtocol() === request.GetProtocol()) {
return Typertext.Transport.XDR;
}
throw {};
};
return TransportChooser;
})();
Transport.TransportChooser = TransportChooser;
})(Typertext.Transport || (Typertext.Transport = {}));
var Transport = Typertext.Transport;
})(Typertext || (Typertext = {}));
var Typertext;
(function (Typertext) {
(function (Transport) {
var HttpMethod = Typertext.Http.HttpMethod;

2
build/typertext.js.map
File diff suppressed because it is too large
View File

2
build/typertext.min.js
File diff suppressed because it is too large
View File

2
build/typertext.min.js.map
File diff suppressed because it is too large
View File

4
lib/Typertext/Http/HttpRequest.ts

@ -1,4 +1,6 @@
/// <reference path="../Transport/TransportConstructor.ts" />
/// <reference path="../Transport/GenericTransport.ts" />
/// <reference path="../Transport/TransportChooser.ts" />
//TODO add support for IE8-9 CORS via XDomain
//TODO better error handling, ala exceptions

2
package.json

@ -5,7 +5,7 @@
"type": "git",
"url": "https://github.com/terribleplan/Typertext.git"
},
"version": "0.8.0",
"version": "0.8.1",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-cli": "~0.1.13",