SQL Operations Studio Public Preview 1 (0.23) release source code

This commit is contained in:
Karl Burtram
2017-11-09 14:30:27 -08:00
parent b88ecb8d93
commit 3cdac41339
8829 changed files with 759707 additions and 286 deletions

View File

@@ -0,0 +1,83 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { ITask } from 'vs/base/common/async';
import { Promise, TPromise, ValueCallback } from 'vs/base/common/winjs.base';
/**
* Bases on vscode Delayer, however, it works by only running the task if it gets
* a specified number of requests in a specified time
*
* Ex. Useful encapsulation of handling double click from click listeners
*/
export class MultipleRequestDelayer<T> {
private timeout: number;
private completionPromise: Promise;
private onSuccess: ValueCallback;
private requests: number = 0;
private task: ITask<T>;
constructor(public delay: number, private maxRequests: number = 2) {
this.timeout = null;
this.completionPromise = null;
this.onSuccess = null;
}
trigger(task: ITask<T>): TPromise<T> {
this.cancelTimeout();
this.task = task;
if (++this.requests > this.maxRequests - 1) {
this.requests = 0;
this.onSuccess(null);
return this.completionPromise;
}
if (!this.completionPromise) {
this.completionPromise = new TPromise((c) => {
this.onSuccess = c;
}, () => {
// no-op
}).then(() => {
this.completionPromise = null;
this.onSuccess = null;
const task = this.task;
this.task = null;
return task();
});
}
this.timeout = setTimeout(() => {
this.timeout = null;
this.requests = 0;
}, this.delay);
return this.completionPromise;
}
isTriggered(): boolean {
return this.timeout !== null;
}
cancel(): void {
this.cancelTimeout();
if (this.completionPromise) {
this.completionPromise.cancel();
this.completionPromise = null;
}
}
private cancelTimeout(): void {
if (this.timeout !== null) {
clearTimeout(this.timeout);
this.timeout = null;
}
}
}

View File

@@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/**
* Alterable version of the vs memorize function; to unmemoize use unmemoize
*/
export function memoize(target: any, key: string, descriptor: any) {
let fnKey: string = null;
let fn: Function = null;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
}
if (!fn) {
throw new Error('not supported');
}
const memoizeKey = `$memoize$${key}`;
descriptor[fnKey] = function (...args: any[]) {
if (!this.hasOwnProperty(memoizeKey)) {
Object.defineProperty(this, memoizeKey, {
configurable: true,
enumerable: false,
writable: false,
value: fn.apply(this, args)
});
}
return this[memoizeKey];
};
}
export function unmemoize(target: Object, key: string) {
const memoizeKey = `$memoize$${key}`;
if (target.hasOwnProperty(memoizeKey)) {
delete target[memoizeKey];
}
}

View File

@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
export function log(...args: any[]): void {
console.log(`\x1b[90m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args);
}
export function warn(...args: any[]): void {
console.warn(`\x1b[93m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args);
}
export function error(...args: any[]) {
console.error(`\x1b[91m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args);
}

View File

@@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as Types from 'vs/base/common/types';
/**
* A copy of the vs mixin that accepts a custom behavior function
*/
export function mixin(destination: any, source: any, overwrite: boolean = true, fn?: (destination: any, source: any, overwrite?: boolean) => any): any {
if (!Types.isObject(destination)) {
return source;
}
if (Types.isObject(source)) {
Object.keys(source).forEach((key) => {
if (key in destination) {
if (overwrite) {
if (Types.isObject(destination[key]) && Types.isObject(source[key])) {
mixin(destination[key], source[key], overwrite, fn);
} else if(fn) {
fn(destination[key], source[key], overwrite);
} else {
destination[key] = source[key];
}
}
} else {
destination[key] = source[key];
}
});
}
return destination;
}

View File

@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/**
* Deferred promise
*/
export class Deferred<T> {
promise: Promise<T>;
resolve: (value?: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
constructor() {
this.promise = new Promise<T>((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}