mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add ss-utils
This commit is contained in:
parent
86dbea8fc3
commit
c3dd962e94
41
ss-utils/ss-utils-tests.ts
Normal file
41
ss-utils/ss-utils-tests.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/// <reference path="../jquery/jquery.d.ts" />
|
||||
/// <reference path="ss-utils.d.ts" />
|
||||
|
||||
declare var EventSource : sse.IEventSourceStatic;
|
||||
|
||||
declare module sse {
|
||||
interface IEventSourceStatic extends EventTarget {
|
||||
new (url: string, eventSourceInitDict?: IEventSourceInit):IEventSourceStatic;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface IEventSourceInit {
|
||||
withCredentials?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
function test_ssutils() {
|
||||
$.ss.eventReceivers = { "document": document };
|
||||
|
||||
var source = new EventSource("/event-stream?channels=home,work");
|
||||
$(source).handleServerEvents({
|
||||
handlers: {
|
||||
onConnect: function(connect:SSUtilsSSEConnect) {},
|
||||
onHeartbeat: function(msg:SSUtilsSSEHeartbeat, e:MessageEvent){},
|
||||
onJoin: function(msg:SSUtilsSSEJoin) {},
|
||||
onLeave: function(msg:SSUtilsSSELeave) {}
|
||||
},
|
||||
receivers: {
|
||||
tv: {
|
||||
watch: function(){}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).bindHandlers({
|
||||
announce: function (msg:string) {}
|
||||
})
|
||||
.on('customEvent', function (e, msg, msgEvent) { });
|
||||
|
||||
$.ss.handlers["changeChannel"]("home");
|
||||
}
|
||||
113
ss-utils/ss-utils.d.ts
vendored
Normal file
113
ss-utils/ss-utils.d.ts
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
// Type definitions for ServiceStack Utils v0.0.1
|
||||
// Project: https://servicestack.net/
|
||||
// Definitions by: Demis Bellot <https://github.com/mythz/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../jquery/jquery.d.ts" />
|
||||
|
||||
interface JQuery {
|
||||
setFieldError: (name: string, msg: string) => void;
|
||||
serializeMap: () => { [index: string]: any };
|
||||
applyErrors: (status: ResponseStatus, opt?: SSUtilsApplyErrorsOptions) => JQuery;
|
||||
clearErrors: () => JQuery;
|
||||
bindForm: (opt?: SSUtilsApplyErrorsOptions) => JQuery;
|
||||
applyValues: (values: { [index: string]: string }) => JQuery;
|
||||
bindHandlers: (handlers: { [index: string]: Function }) => JQuery;
|
||||
setActiveLinks: () => JQuery;
|
||||
handleServerEvents: (opt?: SSUtilsHandleServerEventsOptions) => void;
|
||||
}
|
||||
|
||||
interface SSUtilsValidation {
|
||||
overrideMessages: boolean;
|
||||
messages: { [index: string]: string };
|
||||
errorFilter: (errorMsg: string, errorCode: string, type: string) => void;
|
||||
}
|
||||
|
||||
interface SSUtilsValidationOptional {
|
||||
overrideMessages?: boolean;
|
||||
messages?: { [index: string]: string };
|
||||
errorFilter?: (errorMsg: string, errorCode: string, type: string) => void;
|
||||
}
|
||||
|
||||
interface SSUtilsApplyErrorsOptions extends SSUtilsValidationOptional {
|
||||
}
|
||||
|
||||
interface SSUtilsBindFormOptions {
|
||||
validation?: SSUtilsValidationOptional;
|
||||
validate?: (form: HTMLFormElement) => boolean;
|
||||
onSubmitDisable?: string;
|
||||
complete?: (...args: any[]) => void;
|
||||
error?: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
interface SSUtilsHandleServerEventsOptions {
|
||||
handlers?: { [index: string]: Function };
|
||||
validate?: (op?: string, target?: string, msg?: string, json?: string) => boolean;
|
||||
heartbeatUrl?: string;
|
||||
heartbeatIntervalMs?: number;
|
||||
unRegisterUrl?: string;
|
||||
receivers?: { [index: string]: any };
|
||||
success?: (selector: string, msg: string, e: any) => void;
|
||||
}
|
||||
|
||||
interface ResponseStatus {
|
||||
errorCode: string;
|
||||
message: string;
|
||||
stackTrace: string;
|
||||
errors: ResponseError[];
|
||||
}
|
||||
interface ResponseError {
|
||||
errorCode: string;
|
||||
fieldName: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
interface SSUtilsStatic {
|
||||
handlers: { [index: string]: Function };
|
||||
onSubmitDisable: string;
|
||||
validation: SSUtilsValidation;
|
||||
clearAdjacentError: () => void;
|
||||
todate: (s: string) => Date;
|
||||
todfmt: (s: string) => string;
|
||||
dfmt: (d: Date) => string;
|
||||
dfmthm: (d: Date) => string;
|
||||
tfmt12: (d: Date) => string;
|
||||
splitOnFirst: (s: string) => string[];
|
||||
splitOnLast: (s: string) => string[];
|
||||
getSelection: () => string;
|
||||
queryString: (url: string) => { [index: string]: string };
|
||||
createUrl: (route: string, args?: any) => string;
|
||||
humanize: (s: string) => string;
|
||||
|
||||
listenOn: string;
|
||||
eventReceivers: any;
|
||||
reconnectServerEvents: (opt: SSUtilsReconnectServerEventsOptions) => any;
|
||||
}
|
||||
|
||||
interface SSUtilsReconnectServerEventsOptions {
|
||||
url?: string;
|
||||
onerror?: (...args: any[]) => void;
|
||||
onmessage?: (...args: any[]) => void;
|
||||
errorArgs: any[];
|
||||
}
|
||||
|
||||
interface JQueryStatic {
|
||||
ss: SSUtilsStatic;
|
||||
}
|
||||
|
||||
interface SSUtilsSSECommand {
|
||||
userId: string;
|
||||
displayName: string;
|
||||
channels: string;
|
||||
profileUrl: string;
|
||||
}
|
||||
interface SSUtilsSSEHeartbeat extends SSUtilsSSECommand {}
|
||||
interface SSUtilsSSEJoin extends SSUtilsSSECommand {}
|
||||
interface SSUtilsSSELeave extends SSUtilsSSECommand {}
|
||||
interface SSUtilsSSEConnect extends SSUtilsSSECommand {
|
||||
id: string;
|
||||
unRegisterUrl: string;
|
||||
heartbeatUrl: string;
|
||||
heartbeatIntervalMs: number;
|
||||
idleTimeoutMs: number;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user