mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-06 09:19:08 +00:00
Merge pull request #10653 from westy92/master
Add redis-scripto, redis-rate-limiter, and replacement auth0 typings with tests. Renamed original auth0 -> auth0-js.
This commit is contained in:
23
auth0-js/auth0-js-tests.ts
Normal file
23
auth0-js/auth0-js-tests.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/// <reference path="auth0-js.d.ts" />
|
||||
|
||||
var auth0 = new Auth0({
|
||||
domain: 'mine.auth0.com',
|
||||
clientID: 'dsa7d77dsa7d7',
|
||||
callbackURL: 'http://my-app.com/callback',
|
||||
callbackOnLocationHash: true
|
||||
});
|
||||
|
||||
auth0.login({
|
||||
connection: 'google-oauth2',
|
||||
popup: true,
|
||||
popupOptions: {
|
||||
width: 450,
|
||||
height: 800
|
||||
}
|
||||
}, (err, profile, idToken, accessToken, state) => {
|
||||
if (err) {
|
||||
alert("something went wrong: " + err.message);
|
||||
return;
|
||||
}
|
||||
alert('hello ' + profile.name);
|
||||
});
|
||||
132
auth0-js/auth0-js.d.ts
vendored
Normal file
132
auth0-js/auth0-js.d.ts
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
// Type definitions for Auth0.js
|
||||
// Project: https://github.com/auth0/auth0.js
|
||||
// Definitions by: Robert McLaws <https://github.com/advancedrei>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/** Extensions to the browser Window object. */
|
||||
interface Window {
|
||||
/** Allows you to pass the id_token to other APIs, as specified in https://docs.auth0.com/apps-apis */
|
||||
token: string;
|
||||
}
|
||||
|
||||
/** This is the interface for the main Auth0 client. */
|
||||
interface Auth0Static {
|
||||
|
||||
new(options: Auth0ClientOptions): Auth0Static;
|
||||
changePassword(options: any, callback?: Function): void;
|
||||
decodeJwt(jwt: string): any;
|
||||
login(options: any, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
loginWithPopup(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
loginWithResourceOwner(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: any) => any): void;
|
||||
loginWithUsernamePassword(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
logout(query: string): void;
|
||||
getConnections(callback?: Function): void;
|
||||
refreshToken(refreshToken: string, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void;
|
||||
getDelegationToken(targetClientId: string, id_token: string, options: any, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void;
|
||||
getProfile(id_token: string, callback?: Function): Auth0UserProfile;
|
||||
getSSOData(withActiveDirectories: any, callback?: Function): void;
|
||||
parseHash(hash: string): Auth0DecodedHash;
|
||||
signup(options: Auth0SignupOptions, callback: Function): void;
|
||||
validateUser(options: any, callback: (error?: Auth0Error, valid?: any) => any): void;
|
||||
}
|
||||
|
||||
/** Represents constructor options for the Auth0 client. */
|
||||
interface Auth0ClientOptions {
|
||||
clientID: string;
|
||||
callbackURL: string;
|
||||
callbackOnLocationHash?: boolean;
|
||||
domain: string;
|
||||
forceJSONP?: boolean;
|
||||
}
|
||||
|
||||
/** Represents a normalized UserProfile. */
|
||||
interface Auth0UserProfile {
|
||||
email: string;
|
||||
family_name: string;
|
||||
gender: string;
|
||||
given_name: string;
|
||||
locale: string;
|
||||
name: string;
|
||||
nickname: string;
|
||||
picture: string;
|
||||
user_id: string;
|
||||
/** Represents one or more Identities that may be associated with the User. */
|
||||
identities: Auth0Identity[];
|
||||
user_metadata?: any;
|
||||
app_metadata?: any;
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has a Microsoft Account as the primary identity. */
|
||||
interface MicrosoftUserProfile extends Auth0UserProfile {
|
||||
emails: string[];
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has an Office365 account as the primary identity. */
|
||||
interface Office365UserProfile extends Auth0UserProfile {
|
||||
tenantid: string;
|
||||
upn: string;
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has an Active Directory account as the primary identity. */
|
||||
interface AdfsUserProfile extends Auth0UserProfile {
|
||||
issuer: string;
|
||||
}
|
||||
|
||||
/** Represents multiple identities assigned to a user. */
|
||||
interface Auth0Identity {
|
||||
access_token: string;
|
||||
connection: string;
|
||||
isSocial: boolean;
|
||||
provider: string;
|
||||
user_id: string;
|
||||
}
|
||||
|
||||
interface Auth0DecodedHash {
|
||||
access_token: string;
|
||||
id_token: string;
|
||||
profile: Auth0UserProfile;
|
||||
state: any;
|
||||
}
|
||||
|
||||
interface Auth0PopupOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface Auth0LoginOptions {
|
||||
auto_login?: boolean;
|
||||
connection?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
popup?: boolean;
|
||||
popupOptions?: Auth0PopupOptions;
|
||||
}
|
||||
|
||||
interface Auth0SignupOptions extends Auth0LoginOptions {
|
||||
auto_login: boolean;
|
||||
}
|
||||
|
||||
interface Auth0Error {
|
||||
code: any;
|
||||
details: any;
|
||||
name: string;
|
||||
message: string;
|
||||
status: any;
|
||||
}
|
||||
|
||||
/** Represents the response from an API Token Delegation request. */
|
||||
interface Auth0DelegationToken {
|
||||
/** The length of time in seconds the token is valid for. */
|
||||
expires_in: string;
|
||||
/** The JWT for delegated access. */
|
||||
id_token: string;
|
||||
/** The type of token being returned. Possible values: "Bearer" */
|
||||
token_type: string;
|
||||
}
|
||||
|
||||
declare var Auth0: Auth0Static;
|
||||
|
||||
declare module "auth0" {
|
||||
export = Auth0
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path="../auth0/auth0.d.ts" />
|
||||
/// <reference path="../auth0-js/auth0-js.d.ts" />
|
||||
/// <reference path="auth0.lock.d.ts" />
|
||||
|
||||
const CLIENT_ID = "YOUR_AUTH0_APP_CLIENTID";
|
||||
|
||||
2
auth0.lock/auth0.lock.d.ts
vendored
2
auth0.lock/auth0.lock.d.ts
vendored
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Brian Caruso <https://github.com/carusology>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../auth0/auth0.d.ts" />
|
||||
/// <reference path="../auth0-js/auth0-js.d.ts" />
|
||||
|
||||
interface Auth0LockAdditionalSignUpFieldOption {
|
||||
value: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// <reference path="../auth0/auth0.d.ts" />
|
||||
/// <reference path="../auth0-js/auth0-js.d.ts" />
|
||||
/// <reference path="auth0.widget.d.ts" />
|
||||
|
||||
var widget: Auth0WidgetStatic = new Auth0Widget({
|
||||
|
||||
2
auth0.widget/auth0.widget.d.ts
vendored
2
auth0.widget/auth0.widget.d.ts
vendored
@@ -3,7 +3,7 @@
|
||||
// Definitions by: Robert McLaws <https://github.com/advancedrei>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../auth0/auth0.d.ts" />
|
||||
/// <reference path="../auth0-js/auth0-js.d.ts" />
|
||||
|
||||
|
||||
interface Auth0WidgetStatic {
|
||||
|
||||
@@ -1,23 +1,51 @@
|
||||
/// <reference path="../auth0/auth0.d.ts" />
|
||||
/// <reference path="auth0.d.ts" />
|
||||
|
||||
var auth0 = new Auth0({
|
||||
domain: 'mine.auth0.com',
|
||||
clientID: 'dsa7d77dsa7d7',
|
||||
callbackURL: 'http://my-app.com/callback',
|
||||
callbackOnLocationHash: true
|
||||
import * as auth0 from 'auth0';
|
||||
|
||||
const management = new auth0.ManagementClient({
|
||||
token: '{YOUR_API_V2_TOKEN}',
|
||||
domain: '{YOUR_ACCOUNT}.auth0.com'
|
||||
});
|
||||
|
||||
auth0.login({
|
||||
connection: 'google-oauth2',
|
||||
popup: true,
|
||||
popupOptions: {
|
||||
width: 450,
|
||||
height: 800
|
||||
}
|
||||
}, (err, profile, idToken, accessToken, state) => {
|
||||
if (err) {
|
||||
alert("something went wrong: " + err.message);
|
||||
return;
|
||||
}
|
||||
alert('hello ' + profile.name);
|
||||
});
|
||||
const auth = new auth0.AuthenticationClient({
|
||||
domain: '{YOUR_ACCOUNT}.auth0.com',
|
||||
clientId: '{OPTIONAL_CLIENT_ID}'
|
||||
});
|
||||
|
||||
// Using a callback.
|
||||
management.getUsers((err: Error, users: auth0.User[]) => {
|
||||
if (err) {
|
||||
// Handle error.
|
||||
}
|
||||
console.log(users);
|
||||
});
|
||||
|
||||
// Using a Promise.
|
||||
management
|
||||
.getUsers()
|
||||
.then((users) => {
|
||||
console.log(users);
|
||||
})
|
||||
.catch((err) => {
|
||||
// Handle the error.
|
||||
});
|
||||
|
||||
management
|
||||
.createUser({
|
||||
connection: 'My-Connection',
|
||||
email: 'hi@me.co',
|
||||
}).then((user) => {
|
||||
console.log(user);
|
||||
}).catch((err) => {
|
||||
// Handle the error.
|
||||
});
|
||||
|
||||
auth
|
||||
.requestChangePasswordEmail({
|
||||
connection: 'My-Connection',
|
||||
email: 'hi@me.co',
|
||||
}).then((response) => {
|
||||
console.log(response);
|
||||
}).catch((err) => {
|
||||
// Handle the error.
|
||||
});
|
||||
|
||||
199
auth0/auth0.d.ts
vendored
199
auth0/auth0.d.ts
vendored
@@ -1,132 +1,95 @@
|
||||
// Type definitions for Auth0.js
|
||||
// Project: http://auth0.com
|
||||
// Definitions by: Robert McLaws <https://github.com/advancedrei>
|
||||
// Type definitions for auth0 v2.3.1
|
||||
// Project: https://github.com/auth0/node-auth0
|
||||
// Definitions by: Seth Westphal <https://github.com/westy92>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/** Extensions to the browser Window object. */
|
||||
interface Window {
|
||||
/** Allows you to pass the id_token to other APIs, as specified in https://docs.auth0.com/apps-apis */
|
||||
/// <reference path="../bluebird/bluebird.d.ts" />
|
||||
|
||||
declare module "auth0" {
|
||||
|
||||
import * as Promise from 'bluebird';
|
||||
|
||||
export interface ManagementClientOptions {
|
||||
token: string;
|
||||
}
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
/** This is the interface for the main Auth0 client. */
|
||||
interface Auth0Static {
|
||||
|
||||
new(options: Auth0ClientOptions): Auth0Static;
|
||||
changePassword(options: any, callback?: Function): void;
|
||||
decodeJwt(jwt: string): any;
|
||||
login(options: any, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
loginWithPopup(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
loginWithResourceOwner(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: any) => any): void;
|
||||
loginWithUsernamePassword(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?: Auth0UserProfile, id_token?: string, access_token?: string, state?: string) => any): void;
|
||||
logout(query: string): void;
|
||||
getConnections(callback?: Function): void;
|
||||
refreshToken(refreshToken: string, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void;
|
||||
getDelegationToken(targetClientId: string, id_token: string, options: any, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void;
|
||||
getProfile(id_token: string, callback?: Function): Auth0UserProfile;
|
||||
getSSOData(withActiveDirectories: any, callback?: Function): void;
|
||||
parseHash(hash: string): Auth0DecodedHash;
|
||||
signup(options: Auth0SignupOptions, callback: Function): void;
|
||||
validateUser(options: any, callback: (error?: Auth0Error, valid?: any) => any): void;
|
||||
}
|
||||
|
||||
/** Represents constructor options for the Auth0 client. */
|
||||
interface Auth0ClientOptions {
|
||||
clientID: string;
|
||||
callbackURL: string;
|
||||
callbackOnLocationHash?: boolean;
|
||||
domain: string;
|
||||
forceJSONP?: boolean;
|
||||
}
|
||||
|
||||
/** Represents a normalized UserProfile. */
|
||||
interface Auth0UserProfile {
|
||||
email: string;
|
||||
family_name: string;
|
||||
gender: string;
|
||||
given_name: string;
|
||||
locale: string;
|
||||
name: string;
|
||||
nickname: string;
|
||||
picture: string;
|
||||
user_id: string;
|
||||
/** Represents one or more Identities that may be associated with the User. */
|
||||
identities: Auth0Identity[];
|
||||
user_metadata?: any;
|
||||
app_metadata?: any;
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has a Microsoft Account as the primary identity. */
|
||||
interface MicrosoftUserProfile extends Auth0UserProfile {
|
||||
emails: string[];
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has an Office365 account as the primary identity. */
|
||||
interface Office365UserProfile extends Auth0UserProfile {
|
||||
tenantid: string;
|
||||
upn: string;
|
||||
}
|
||||
|
||||
/** Represents an Auth0UserProfile that has an Active Directory account as the primary identity. */
|
||||
interface AdfsUserProfile extends Auth0UserProfile {
|
||||
issuer: string;
|
||||
}
|
||||
|
||||
/** Represents multiple identities assigned to a user. */
|
||||
interface Auth0Identity {
|
||||
access_token: string;
|
||||
export interface UserData {
|
||||
connection: string;
|
||||
isSocial: boolean;
|
||||
provider: string;
|
||||
user_id: string;
|
||||
}
|
||||
|
||||
interface Auth0DecodedHash {
|
||||
access_token: string;
|
||||
id_token: string;
|
||||
profile: Auth0UserProfile;
|
||||
state: any;
|
||||
}
|
||||
|
||||
interface Auth0PopupOptions {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface Auth0LoginOptions {
|
||||
auto_login?: boolean;
|
||||
connection?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
popup?: boolean;
|
||||
popupOptions?: Auth0PopupOptions;
|
||||
}
|
||||
phone_number?: string;
|
||||
user_metadata?: {};
|
||||
email_verified?: boolean;
|
||||
app_metadata?: {};
|
||||
}
|
||||
|
||||
interface Auth0SignupOptions extends Auth0LoginOptions {
|
||||
auto_login: boolean;
|
||||
}
|
||||
export interface GetUsersData {
|
||||
per_page?: number;
|
||||
page?: number;
|
||||
include_totals?: boolean;
|
||||
sort?: string;
|
||||
connection?: string;
|
||||
fields?: string;
|
||||
include_fields?: boolean;
|
||||
q?: string;
|
||||
search_engine?: string;
|
||||
}
|
||||
|
||||
interface Auth0Error {
|
||||
code: any;
|
||||
details: any;
|
||||
name: string;
|
||||
message: string;
|
||||
status: any;
|
||||
}
|
||||
export interface User {
|
||||
email?: string;
|
||||
email_verified?: boolean;
|
||||
username?: string;
|
||||
phone_number?: string;
|
||||
phone_verified?: boolean;
|
||||
user_id?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
identities?: Identity[];
|
||||
app_metadata?: {};
|
||||
user_metadata?: {};
|
||||
picture?: string;
|
||||
name?: string;
|
||||
nickname?: string;
|
||||
multifactor?: string[];
|
||||
last_ip?: string;
|
||||
last_login?: string;
|
||||
logins_count?: number;
|
||||
blocked?: boolean;
|
||||
}
|
||||
|
||||
/** Represents the response from an API Token Delegation request. */
|
||||
interface Auth0DelegationToken {
|
||||
/** The length of time in seconds the token is valid for. */
|
||||
expires_in: string;
|
||||
/** The JWT for delegated access. */
|
||||
id_token: string;
|
||||
/** The type of token being returned. Possible values: "Bearer" */
|
||||
token_type: string;
|
||||
}
|
||||
export interface Identity {
|
||||
connection: string;
|
||||
user_id: string;
|
||||
provider: string;
|
||||
isSocial: boolean;
|
||||
}
|
||||
|
||||
declare var Auth0: Auth0Static;
|
||||
export class ManagementClient {
|
||||
constructor(options: ManagementClientOptions);
|
||||
|
||||
getUsers(params?: GetUsersData): Promise<User[]>;
|
||||
getUsers(params?: GetUsersData, cb?: (err: Error, users: User[]) => void): void;
|
||||
createUser(data: UserData): Promise<User>;
|
||||
createUser(data: UserData, cb: (err: Error, data: User) => void): void;
|
||||
}
|
||||
|
||||
export interface AuthenticationClientOptions {
|
||||
clientId?: string;
|
||||
domain: string;
|
||||
}
|
||||
|
||||
export interface RequestChangePasswordEmailData {
|
||||
connection: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export class AuthenticationClient {
|
||||
constructor(options: AuthenticationClientOptions);
|
||||
|
||||
requestChangePasswordEmail(data: RequestChangePasswordEmailData): Promise<string>;
|
||||
requestChangePasswordEmail(data: RequestChangePasswordEmailData, cb: (err: Error, message: string) => void): void;
|
||||
}
|
||||
|
||||
declare module "auth0" {
|
||||
export = Auth0
|
||||
}
|
||||
|
||||
41
redis-rate-limiter/redis-rate-limiter-tests.ts
Normal file
41
redis-rate-limiter/redis-rate-limiter-tests.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
/// <reference path="redis-rate-limiter.d.ts" />
|
||||
|
||||
import * as express from 'express';
|
||||
import * as redis from 'redis';
|
||||
import * as rateLimiter from 'redis-rate-limiter';
|
||||
|
||||
var num: number;
|
||||
var str: string;
|
||||
var options: redis.ClientOpts;
|
||||
var redisClient = redis.createClient(num, str, options);
|
||||
|
||||
var limit = rateLimiter.create({
|
||||
redis: redisClient,
|
||||
key: function(x) { return x.ip },
|
||||
rate: '100/minute'
|
||||
});
|
||||
|
||||
var request = {} as express.Request;
|
||||
limit(request, function(err, rate) {
|
||||
if (err) {
|
||||
console.warn('Rate limiting not available');
|
||||
} else {
|
||||
console.log('Rate window: ' + rate.window); // 60
|
||||
console.log('Rate limit: ' + rate.limit); // 100
|
||||
console.log('Rate current: ' + rate.current); // 74
|
||||
if (rate.over) {
|
||||
console.error('Over the limit!');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var middleware = rateLimiter.middleware({
|
||||
redis: redisClient,
|
||||
key: 'ip',
|
||||
rate: '100/minute'
|
||||
});
|
||||
|
||||
var app = express();
|
||||
app.use(middleware);
|
||||
44
redis-rate-limiter/redis-rate-limiter.d.ts
vendored
Normal file
44
redis-rate-limiter/redis-rate-limiter.d.ts
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// Type definitions for redis-rate-limiter 1.0.3
|
||||
// Project: https://github.com/TabDigital/redis-rate-limiter
|
||||
// Definitions by: Seth Westphal <https://github.com/westy92>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
|
||||
declare module "redis-rate-limiter" {
|
||||
|
||||
import * as express from 'express';
|
||||
import * as redis from 'redis';
|
||||
|
||||
class RedisRateLimiter {
|
||||
|
||||
public static create(options: RedisRateLimiter.Options):
|
||||
(req: express.Request, callback: (err: Error, res: RedisRateLimiter.Response) => void) => void;
|
||||
public static middleware(options: RedisRateLimiter.Options): express.RequestHandler;
|
||||
|
||||
}
|
||||
|
||||
namespace RedisRateLimiter {
|
||||
|
||||
export interface Options {
|
||||
redis: redis.RedisClient;
|
||||
key: 'ip' | ((req: express.Request) => string);
|
||||
window?: number;
|
||||
limit?: number;
|
||||
rate?: string;
|
||||
}
|
||||
|
||||
export interface Response {
|
||||
key: string;
|
||||
current: number;
|
||||
limit: number;
|
||||
window: number;
|
||||
over: boolean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export = RedisRateLimiter;
|
||||
|
||||
}
|
||||
37
redis-scripto/redis-scripto-tests.ts
Normal file
37
redis-scripto/redis-scripto-tests.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
/// <reference path="redis-scripto.d.ts" />
|
||||
|
||||
import * as redis from 'redis';
|
||||
import * as Scripto from 'redis-scripto';
|
||||
|
||||
var num: number;
|
||||
var str: string;
|
||||
var options: redis.ClientOpts;
|
||||
var redisClient = redis.createClient(num, str, options);
|
||||
|
||||
var scriptManager = new Scripto(redisClient);
|
||||
scriptManager.loadFromDir('/path/to/lua/scripts');
|
||||
|
||||
var keys = ['keyOne', 'keyTwo'];
|
||||
var values = [10, 20];
|
||||
scriptManager.run('your-script', keys, values, function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
scriptManager.eval('your-script', keys, values, function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
scriptManager.loadFromFile('script-one', '/path/to/the/file');
|
||||
scriptManager.run('script-one', [], [], function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
var scripts: Scripto.Scripts = {
|
||||
'script-two': 'return 1000'
|
||||
};
|
||||
|
||||
scriptManager.load(scripts);
|
||||
scriptManager.run('script-two', [], [], function(err, result) {
|
||||
|
||||
});
|
||||
39
redis-scripto/redis-scripto.d.ts
vendored
Normal file
39
redis-scripto/redis-scripto.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
// Type definitions for redis-scripto 0.1.3
|
||||
// Project: https://github.com/arunoda/node-redis-scripto
|
||||
// Definitions by: Seth Westphal <https://github.com/westy92>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
|
||||
declare module "redis-scripto" {
|
||||
|
||||
import * as redis from 'redis';
|
||||
|
||||
class Scripto {
|
||||
|
||||
constructor(redisClient: redis.RedisClient);
|
||||
|
||||
eval(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
evalSha(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
|
||||
load(scripts: Scripto.Scripts): void;
|
||||
loadFromDir(scriptsDir: string): void;
|
||||
loadFromFile(name: string, filepath: string): void;
|
||||
|
||||
run(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
|
||||
}
|
||||
|
||||
namespace Scripto {
|
||||
|
||||
export type Script = string;
|
||||
|
||||
export interface Scripts {
|
||||
[scriptName: string]: Script;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export = Scripto;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user