bluebird: Make Thenable an alias to the builtin PromiseLike.

This commit is contained in:
Andy Hanson
2017-06-16 09:02:18 -07:00
parent 04221e07e2
commit c15e214e5a
38 changed files with 186 additions and 219 deletions
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/squaremo/amqp.node
// Definitions by: Michael Nahkies <https://github.com/mnahkies>, Ab Reitsma <https://github.com/abreits>, Nicolás Fantone <https://github.com/nfantone>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/spion/anydb-sql-migrations
// Definitions by: Gorgi Kosev <https://github.com/spion>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import Promise = require('bluebird');
import { Column, Table, Transaction, AnydbSql } from 'anydb-sql';
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/Asana/node-asana
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="bluebird" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/auth0/node-auth0
// Definitions by: Wilson Hobbs <https://github.com/wbhob>, Seth Westphal <https://github.com/westy92>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as Promise from 'bluebird';
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/spion/blue-tape
// Definitions by: Haoqun Jiang <https://github.com/sodatea>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/petkaantonov/bluebird
// Definitions by: d-ph <https://github.com/d-ph>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/*
* 1. Why use `bluebird-global` instead of `bluebird`?
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/jut-io/bluebird-retry
// Definitions by: Pascal Vomhoff <https://github.com/pvomhoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="bluebird" />
+5 -8
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/petkaantonov/bluebird
// Definitions by: Leonard Hecker <https://github.com/lhecker>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/*!
* The code following this comment originates from:
@@ -44,10 +45,8 @@ declare class Bluebird<R> implements Bluebird.Thenable<R>, Bluebird.Inspection<R
/**
* Promises/A+ `.then()`. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise.
*/
then<U1, U2>(onFulfill: (value: R) => U1 | Bluebird.Thenable<U1>, onReject: (error: any) => U2 | Bluebird.Thenable<U2>): Bluebird<U1 | U2>;
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>, onReject: (error: any) => U | Bluebird.Thenable<U>): Bluebird<U>;
then<U>(onFulfill: (value: R) => U | Bluebird.Thenable<U>): Bluebird<U>;
then(): Bluebird<R>;
// Based on PromiseLike.then, but returns a Bluebird instance.
then<TResult1 = R, TResult2 = never>(onfulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Bluebird<TResult1 | TResult2>;
/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
@@ -951,10 +950,8 @@ declare namespace Bluebird {
export class Disposer<R> {
}
export interface Thenable<R> {
then<U>(onFulfilled: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
then<U>(onFulfilled: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void | Thenable<void>): Thenable<U>;
}
/** @deprecated Use PromiseLike<T> directly. */
export type Thenable<T> = PromiseLike<T>;
export interface Resolver<R> {
/**
+1 -1
View File
@@ -2,7 +2,7 @@
// Project: http://bookshelfjs.org/
// Definitions by: Andrew Schurman <http://github.com/arcticwaters>, Vesa Poikajärvi <https://github.com/vesse>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import Knex = require('knex');
import knex = require('knex');
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/visionmedia/consolidate.js
// Definitions by: Carlos Ballesteros Velasco <https://github.com/soywiz>, Theo Sherry <https://github.com/theosherry>, Nicolas Henry <https://github.com/nicolashenry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// Imported from: https://github.com/soywiz/typescript-node-definitions/consolidate.d.ts
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/db-migrate/db-migrate-base
// Definitions by: nickiannone <https://github.com/nickiannone>
// Definitions: https://github.com/nickiannone/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node"/>
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/db-migrate/pg
// Definitions by: nickiannone <http://github.com/nickiannone>
// Definitions: https://github.com/nickiannone/DefinitelyTyped
// TypeScript Version: 2.3
import * as pg from "pg";
import * as DbMigrateBase from "db-migrate-base";
+1 -3
View File
@@ -2,11 +2,9 @@
// Project: https://github.com/overlookmotel/fs-extra-promise
// Definitions by: midknight41 <https://github.com/midknight41>, Jason Swearingen <https://github.com/jasonswearingen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
/// <reference types="node" />
/// <reference types="bluebird" />
/// <reference types="fs-extra" />
import * as stream from 'stream';
import { Stats } from 'fs';
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/jonkemp/inline-css
// Definitions by: Philip Spain <https://github.com/philipisapain>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="bluebird" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/joeferner/node-java
// Definitions by: Jim Lloyd <https://github.com/jimlloyd>, Kentaro Teramoto <https://github.com/hrl7>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
+1 -3
View File
@@ -1,5 +1,3 @@
///<reference types="bluebird"/>
import java = require('java');
import BluePromise = require('bluebird');
@@ -9,7 +7,7 @@ java.asyncOptions = {
promiseSuffix: 'P',
promisify: BluePromise.promisify
};
// todo: figure out why promise doesn't work here
// todo: figure out why promise doesn't work here
/* java.registerClientP((): Promise<void> => {
return BluePromise.resolve();
}); */
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/karma-runner/karma-coverage
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as karma from 'karma';
import * as istanbul from 'istanbul';
+2 -2
View File
@@ -2,8 +2,8 @@
// Project: https://github.com/karma-runner/karma
// Definitions by: Tanguy Krotoff <https://github.com/tkrotoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="bluebird" />
/// <reference types="node" />
// See Karma public API https://karma-runner.github.io/0.13/dev/public-api.html
@@ -54,7 +54,7 @@ declare namespace karma {
};
EXIT_CODE: string;
}
interface LauncherStatic {
generateId(): string;
//TODO: injector should be of type `di.Injector`
+1 -2
View File
@@ -2,9 +2,8 @@
// Project: https://github.com/tgriesser/knex
// Definitions by: Qubo <https://github.com/tkQubo>, Baronfel <https://github.com/baronfel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
/// <reference types="bluebird" />
/// <reference types="node" />
import events = require("events");
+25 -24
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/nodets/node-mysql-wrapper
// Definitions by: Makis Maropoulos <https://github.com/kataras>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
///<reference path="./my-meteor.d.ts" />
@@ -49,20 +50,20 @@ interface IQueryConstructor<T> {
declare class Helper {
/**
/**
* Callback like forEach
* @name valueCallback
* @function
* @param {T} the value of the object's key
* @param {T} the value of the object's key
* @returnTye {U}
* @return {U}
*/
/**
* CallbaforEach
* @name keyCallback
* @function
* @param {string} the name of the object's key
* @param {string} the name of the object's key
* @returnTye {U}
* @return {U}
*/
@@ -158,7 +159,7 @@ declare class CriteriaParts implements ICriteriaParts {
noDatabaseProperties: string[];
/**
* The converted/exported where clause.
* The converted/exported where clause.
*/
whereClause: string;
@@ -472,7 +473,7 @@ declare class Connection extends EventEmitter {
eventTypes: string[];
/**
* Force to fetch ONLY these Database table names {array of string}.
* Force to fetch ONLY these Database table names {array of string}.
*/
tableNamesToUseOnly: any[];
@@ -495,7 +496,7 @@ declare class Connection extends EventEmitter {
* Attach a real connection.
* @param {Mysql.IConnection} connection the real connection object.
* @returnType {nothing}
* @return {nothing}
* @return {nothing}
*/
attach(connection: Mysql.IConnection): void;
@@ -503,13 +504,13 @@ declare class Connection extends EventEmitter {
* Close the entire real connection and remove all event's listeners (if exist).
* @param {function} callback If error occurs when closing the connection, this callback has the responsibility to catch it.
* @returnType {nothing}
* @return {nothing}
* @return {nothing}
*/
end(callback?: (error: any) => void): void;
/**
* Close the entire real connection and remove all event's listeners (if exist).
* the difference from the 'end' is that this method doesn't care about errors so no callback passing here.
* the difference from the 'end' is that this method doesn't care about errors so no callback passing here.
*/
destroy(): void;
@@ -545,7 +546,7 @@ declare class Connection extends EventEmitter {
/**
* Escape the query column's value and return it.
* @param {string} val the value which will be escaped.
* @param {string} val the value which will be escaped.
* @returnType {string}
* @return {string}
*/
@@ -565,7 +566,7 @@ declare class Connection extends EventEmitter {
* Adds an event listener/watcher on a table for a 'database event'.
* @param {string} tableName the table name which you want to add the event listener.
* @param {string or string[]} evtType the event(s) type you want to watch, one of these(string) or an array of them(string[]): ["INSERT", "UPDATE", "REMOVE", "SAVE"].
* @param {function} callback Callback which has one parameter(typeof any[]) which filled by the rawRows (results after query executed and before parsed to object(s)).
* @param {function} callback Callback which has one parameter(typeof any[]) which filled by the rawRows (results after query executed and before parsed to object(s)).
* @returnType {nothing}
* @return {nothing}
*/
@@ -573,7 +574,7 @@ declare class Connection extends EventEmitter {
/**
* Removes an event listener/watcher from a table for a specific event type.
* @param {string} tableName the table name which you want to remove the event listener.
* @param {string} tableName the table name which you want to remove the event listener.
* @param {string} evtType the Event type you want to remove, one of these: "INSERT", "UPDATE", "REMOVE", "SAVE".
* @param {function} callbackToRemove the callback that you were used for watch this event type.
* @returnType {nothing}
@@ -587,13 +588,13 @@ declare class Connection extends EventEmitter {
* @param {function} callback the function will be called and fill the one and only parameter when an errors occurs.
* @param {any[]} queryArguments (optional) the query arguments you want to pass into query. ['arg1','arg2']...
* @returnType {nothing}
* @return {nothing}
* @return {nothing}
*/
query(queryStr: string, callback: (err: Mysql.IError, results: any) => any, queryArguments?: any[]): void;
/**
* Returns a MysqlTable object from the database factory. (Note: this method doesn't create anything, just finds and returns the correct table, you don't have to create anything at all. Tables are fetched by the library itself.)
* If you are using typescript you can pass a class (generic<T>) in order to use the auto completion assistance on table's results methods(find,findById,findAll,save,remove,safeRemove).
* If you are using typescript you can pass a class (generic<T>) in order to use the auto completion assistance on table's results methods(find,findById,findAll,save,remove,safeRemove).
* @param {string} tableName the table name which you want to get, on the form of: 'anyDatabaseTable' OR 'any_database_table' (possible your real table name into your database).
* @returnType {MysqlTable}
* @return {MysqlTable}
@@ -602,7 +603,7 @@ declare class Connection extends EventEmitter {
}
declare class Table<T> {
/** Private keywords here are useless but I put them.
/** Private keywords here are useless but I put them.
* If the developer wants to see the properties of the Table class, he/she just comes here.
*/
@@ -630,17 +631,17 @@ declare class Table<T> {
primaryKey: string;
/**
* The MysqlConnection object which this MysqlTable belongs.
* The MysqlConnection object which this MysqlTable belongs.
*/
connection: Connection;
/**
* The real database name of the table. Autofilled by library.
* The real database name of the table. Autofilled by library.
*/
name: string;
/**
* Set of the query rules that will be applied after the 'where clause' on each select query executed by this table.
* Set of the query rules that will be applied after the 'where clause' on each select query executed by this table.
* @return {SelectQueryRules}
*/
rules: SelectQueryRules;
@@ -661,7 +662,7 @@ declare class Table<T> {
/**
* Adds or turn on an event listener/watcher on a table for a 'database event'.
* @param {string} evtType the event type you want to watch, one of these: ["INSERT", "UPDATE", "REMOVE", "SAVE"].
* @param {function} callback Callback which has one parameter(typeof any[]) which filled by the rawResults (results after query executed and before exports to object(s)).
* @param {function} callback Callback which has one parameter(typeof any[]) which filled by the rawResults (results after query executed and before exports to object(s)).
* @returnType {nothing}
* @return {nothing}
*/
@@ -689,7 +690,7 @@ declare class Table<T> {
* @param {string} functionName the function name you want to use, this is used when you want to call this function later.
* @param {function} theFunction the function with any optional parameters you want to pass along.
* @returnType {nothing}
* @return {nothing}
* @return {nothing}
*/
extend(functionName: string, theFunction: (...args: any[]) => any): void;
@@ -726,9 +727,9 @@ declare class Table<T> {
getPrimaryKeyValue(jsObject: any): number | string;
/**
*
*
*/
find(criteriaRawJsObject: any): Promise<T[]>; // only criteria
find(criteriaRawJsObject: any): Promise<T[]>; // only criteria
find(criteriaRawJsObject: any, callback: ((_results: T[]) => any)): Promise<T[]>; // criteria and callback
find(criteriaRawJsObject: any, callback?: (_results: T[]) => any): Promise<T[]>;
@@ -792,7 +793,7 @@ declare class Database {
/**
* Close the entire real connection and remove all event's listeners (if exist).
* the difference from the 'end' is that this method doesn't care about errors so no callback passing here.
* the difference from the 'end' is that this method doesn't care about errors so no callback passing here.
*/
destroy(): void;
@@ -800,7 +801,7 @@ declare class Database {
* Close the entire real connection and remove all event's listeners (if exist).
* @param {function} maybeAcallbackError If error occurs when closing the connection, this callback has the responsibility to catch it.
* @returnType {nothing}
* @return {nothing}
* @return {nothing}
*/
end(maybeAcallbackError: (err: any) => void): void;
+4 -4
View File
@@ -24,16 +24,16 @@ declare namespace smtpTransport {
/** is the registered client secret of the application */
clientSecret?: string;
/** is an optional refresh token. If it is provided then Nodemailer tries to generate a new access token if existing one expires or fails */
refreshToken?: string;
/** is the access token for the user. Required only if refreshToken is not available and there is no token refresh callback specified */
accessToken?: string;
/** is an optional expiration time for the current accessToken */
expires?: number;
/** is an optional HTTP endpoint for requesting new access tokens. This value defaults to Gmail */
accessUrl?: string;
+2 -4
View File
@@ -4,11 +4,9 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
/// <reference types="bluebird" />
import directTransport = require("nodemailer-direct-transport");
import smtpTransport = require("nodemailer-smtp-transport");
import * as Promise from 'bluebird';
/**
* Transporter plugin
@@ -36,7 +34,7 @@ export interface Transporter {
* Send mail using a template.
*/
templateSender(template?: any, defaults?: any): (mailData: any, context: any) => Promise<SentMessageInfo>;
/**
* Send mail using a template with a callback.
*/
@@ -50,7 +48,7 @@ export interface Transporter {
* @param pluginFunc is a function that takes two arguments: the mail object and a callback function
*/
use(step: string, plugin: Plugin): void;
/**
* Verifies connection with server
*/
+2
View File
@@ -2,6 +2,8 @@
// Project: https://github.com/orientechnologies/orientjs
// Definitions by: Saeed Tabrizi <https://github.com/saeedtabrizi>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// TypeScript Version: 2.3
// Developed with love in www.nowcando.com
/// <reference types="node" />
+1 -3
View File
@@ -1,6 +1,4 @@
import * as pg from "pg";
import * as bluebird from "bluebird";
var conString = "postgres://username:password@localhost/database";
@@ -55,7 +53,7 @@ var config = {
port: 5432, //env var: PGPORT
max: 10, // max number of clients in the pool
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
Promise: bluebird
Promise,
};
var pool = new pg.Pool(config);
+1 -5
View File
@@ -1,8 +1,4 @@
/// <reference types="bluebird" />
import * as pify from 'pify';
import * as Bluebird from 'bluebird';
function assert(actual: string, expected: string): void {
if (actual !== expected) {
@@ -28,4 +24,4 @@ const fsP = pify(fs);
fsP.readFile('foo.txt').then((result: string) => assert(result, 'foo'));
pify(fs.readFile)('foo.txt').then((result: string) => assert(result, 'foo'));
pify(fs.readFile, Bluebird)('bar.txt').then((result: string) => assert(result, 'bar'));
pify(fs.readFile, Promise)('bar.txt').then((result: string) => assert(result, 'bar'));
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/felixrieseberg/project-oxford
// Definitions by: Scott Southwood <https://github.com/scsouthw/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/mike-marcacci/node-redlock
// Definitions by: Ilya Mochalov <https://github.com/chrootsu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as redis from 'redis';
import * as Promise from 'bluebird';
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/request/request-promise
// Definitions by: Christopher Glantschnig <https://github.com/cglantschnig/>, Joe Skeen <http://github.com/joeskeen>, Aya Morisawa <https://github.com/AyaMorisawa>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import request = require('request');
import http = require('http');
+1 -3
View File
@@ -2,9 +2,7 @@
// Project: https://github.com/domasx2/sequelize-fixtures
// Definitions by: Christian Schwarz <https://github.com/cschwarz/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="sequelize" />
// TypeScript Version: 2.3
import * as Sequelize from "sequelize";
+1 -2
View File
@@ -2,12 +2,11 @@
// Project: http://sequelizejs.com
// Definitions by: samuelneff <https://github.com/samuelneff>, Peter Harris <https://github.com/codeanimal>, Ivan Drinchev <https://github.com/drinchev>, Brendan Abolivier <https://github.com/babolivier>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
// Based on original work by: samuelneff <https://github.com/samuelneff/sequelize-auto-ts/blob/master/lib/sequelize.d.ts>
/// <reference types="lodash" />
/// <reference types="bluebird" />
/// <reference types="validator" />
-1
View File
@@ -7,7 +7,6 @@
// Based on original work by: samuelneff <https://github.com/samuelneff/sequelize-auto-ts/blob/master/lib/sequelize.d.ts>
/// <reference types="lodash" />
/// <reference types="bluebird" />
/// <reference types="validator" />
+4 -7
View File
@@ -1,7 +1,7 @@
/// <reference types="mocha"/>
import Simple = require('simple-mock');
import Bluebird = require('bluebird');
declare function describe(desc: string, action: () => void): void;
declare function beforeEach(action: () => void): void;
declare function it(desc: string, action: (done: () => void) => void): void;
declare var assert: {
(cond: any, message?: string): void;
equal<T>(a: T, b: T): void;
@@ -908,9 +908,6 @@ describe('Simple', function() {
let obj: any
before(function() {
})
beforeEach(function() {
obj = new ProtoKlass()
})
@@ -1019,5 +1016,5 @@ describe('Simple', function() {
})
})
Simple.Promise = Bluebird;
Simple.Promise = Promise;
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/lelylan/simple-oauth2
// Definitions by: [Michael Müller] <https://github.com/mad-mike>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import Bluebird = require("bluebird");
-1
View File
@@ -3,7 +3,6 @@
// Definitions by: William Johnston <https://github.com/wjohnsto>, Peter Harris <https://github.com/codeanimal/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="bluebird" />
/// <reference types="node" />
declare module 'stripe' {
-3
View File
@@ -4,9 +4,6 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/// <reference types="bluebird" />
/// <reference types="sequelize" />
import Sequelize = require("sequelize");
declare namespace umzug {
+1
View File
@@ -2,6 +2,7 @@
// Project: https://github.com/balderdashy/waterline
// Definitions by: Alexandro Libertino <https://github.com/arvitaly>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
+1
View File
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6",
"dom"
+115 -143
View File
@@ -15,7 +15,6 @@
*/
const MetaDataStr = "";
import Promise = require("bluebird");
import PluginBase = require("plugin/PluginBase");
import * as fs from "fs";
@@ -286,36 +285,29 @@ function test_client_using_a_blob() {
return { stateMachine: { name: "dm", initialState: null, finalStates: [], states: [] } };
}
public main(mainHandler: Core.ResultCallback): void {
async main(mainHandler: Core.ResultCallback): Promise<string[]> {
let artifact: Core.Artifact;
Promise
.try(() => {
return this.extractDataModel();
})
.then((dataModel) => {
var dataModelStr = JSON.stringify(dataModel, null, 4);
this.dataModel = dataModel;
const dataModel = this.extractDataModel();
var dataModelStr = JSON.stringify(dataModel, null, 4);
this.dataModel = dataModel;
this.logger.info('Extracted dataModel', dataModelStr);
this.logger.info('Extracted dataModel', dataModelStr);
return self.blobClient.putFile('dataModel.json', dataModelStr);
})
.then((jsonFileHash) => {
// Add link from result to this file.
self.result.addArtifact(jsonFileHash);
const jsonFileHash = await self.blobClient.putFile('dataModel.json', dataModelStr);
// Add link from result to this file.
self.result.addArtifact(jsonFileHash);
// Create a complex artifact, with links to multiple files.
artifact = self.blobClient.createArtifact('simulator');
// Create a complex artifact, with links to multiple files.
artifact = self.blobClient.createArtifact('simulator');
let programJS = "some javascript file";
self.logger.info('program.js', programJS);
let programJS = "some javascript file";
self.logger.info('program.js', programJS);
return artifact.addFilesAsSoftLinks({
'program.js': programJS,
'index.html': this.pluginMetadata
});
})
return artifact.addFilesAsSoftLinks({
'program.js': programJS,
'index.html': this.pluginMetadata
});
}
}
}
@@ -336,7 +328,7 @@ type DictionaryAny = { [key: string]: any };
* Related example using traverse.
* https://github.com/webgme/xmi-tools/blob/master/src/plugins/XMIExporter/XMIExporter.js#L430
*/
function test_core_containment_traversal_complete() {
async function test_core_containment_traversal_complete() {
const BLANK = "";
const NULL_OBJECT = "_OBJECT"
const NULL_GUID = "00000000-0000-0000-0000-000000000000";
@@ -389,7 +381,7 @@ function test_core_containment_traversal_complete() {
* The traverse function follows the containment tree.
* @type {[type]}
*/
let visitFn = (node: Node, done: Common.VoidFn): void => {
let visitFn = async (node: Node, done: Common.VoidFn): Promise<void> => {
try {
let core = sponsor.core;
let nodePath: string = core.getPath(node);
@@ -486,133 +478,113 @@ function test_core_containment_traversal_complete() {
});
// get pointers & inv_pointers
Promise
.try(() => {
return core.getPointerNames(node);
})
.map((ptrName: string) => {
let targetPathRaw = core.getPointerPath(node, ptrName);
if (typeof targetPathRaw !== "string") { return; }
const ptrNames = await core.getPointerNames(node);
Promise.all(ptrNames.map(async ptrName => {
let targetPathRaw = core.getPointerPath(node, ptrName);
if (typeof targetPathRaw !== "string") { return; }
let targetPath: string = targetPathRaw;
Promise
.try(() => {
return core.loadByPath(sponsor.rootNode, targetPath);
})
.then((targetNode: Node) => {
let targetGuid = core.getGuid(targetNode);
if (ptrName === "base") {
let targetPath: string = targetPathRaw;
const targetNode = core.loadByPath(sponsor.rootNode, targetPath);
let targetGuid = core.getGuid(targetNode);
if (ptrName === "base") {
} else {
let pointers: DictionaryAny = sourceEntry.pointers;
let targetMetaNode = core.getBaseType(targetNode);
let targetMetaName = core.getAttribute(targetMetaNode, "name");
if (typeof targetMetaName === "string") {
pointers[ptrName] = {
name: targetMetaName,
guid: targetGuid
};
}
let targetEntry = nodeGuidMap[targetGuid];
if (targetEntry === undefined) {
targetEntry = {
"name": {},
"guid": targetGuid,
"pointers": {}, "inv_pointers": {},
"sets": {}, "inv_sets": {}
};
nodeGuidMap[targetGuid] = targetEntry;
}
targetEntry.inv_pointers[ptrName] = {
name: targetMetaName,
guid: sourceGuid
};
}
});
});
} else {
let pointers: DictionaryAny = sourceEntry.pointers;
let targetMetaNode = core.getBaseType(targetNode);
let targetMetaName = core.getAttribute(targetMetaNode, "name");
if (typeof targetMetaName === "string") {
pointers[ptrName] = {
name: targetMetaName,
guid: targetGuid
};
}
let targetEntry = nodeGuidMap[targetGuid];
if (targetEntry === undefined) {
targetEntry = {
"name": {},
"guid": targetGuid,
"pointers": {}, "inv_pointers": {},
"sets": {}, "inv_sets": {}
};
nodeGuidMap[targetGuid] = targetEntry;
}
targetEntry.inv_pointers[ptrName] = {
name: targetMetaName,
guid: sourceGuid
};
}
}));
// get sets & inv_set
Promise
.try(() => {
return core.getValidSetNames(node);
})
.map((setName: string) => {
let targetMemberPathsRaw = core.getMemberPaths(node, setName);
for (let targetMemberPath of targetMemberPathsRaw) {
if (typeof targetMemberPath !== "string") { return; }
let targetPath: string = targetMemberPath;
const setNames = await core.getValidSetNames(node);
Promise.all(setNames.map(setName => {
let targetMemberPathsRaw = core.getMemberPaths(node, setName);
for (let targetMemberPath of targetMemberPathsRaw) {
if (typeof targetMemberPath !== "string") { return; }
let targetPath: string = targetMemberPath;
Promise
.try(() => {
return core.loadByPath(sponsor.rootNode, targetPath);
})
.then((targetNode: Node) => {
let targetGuid = core.getGuid(targetNode);
let sets: DictionaryAny = sourceEntry.sets;
let targetMetaNode = core.getBaseType(targetNode);
let targetMetaName = core.getAttribute(targetMetaNode, "name");
if (typeof targetMetaName === "string") {
let load = {
name: targetMetaName,
guid: targetGuid
};
let sourceSet = sets[setName];
if (sourceSet === undefined) {
sets[setName] = [load];
} else {
sourceSet.push(load);
}
}
let targetEntry = nodeGuidMap[targetGuid];
if (targetEntry === undefined) {
targetEntry = {
"name": {},
"guid": targetGuid,
"pointers": {}, "inv_pointers": {},
"sets": {}, "inv_sets": {}
};
nodeGuidMap[targetGuid] = targetEntry;
}
let invSets = targetEntry.inv_sets;
let targetSet = invSets[setName];
let invLoad = {
name: targetMetaName,
guid: sourceGuid
};
if (targetSet === undefined) {
invSets[setName] = [invLoad];
} else {
targetSet.push(invLoad);
};
})
.catch((err: Error) => {
console.log(`difficulty loading target path: ${targetPath} with err: ${err.message}`);
let load = {
"fault": `could not load member path: ${targetPath}`
};
let sets: DictionaryAny = sourceEntry.sets;
let sourceSet = sets[setName];
if (sourceSet === undefined) {
sets[setName] = [load];
} else {
sourceSet.push(load);
}
});
try {
const targetNode = core.loadByPath(sponsor.rootNode, targetPath);
let targetGuid = core.getGuid(targetNode);
let sets: DictionaryAny = sourceEntry.sets;
let targetMetaNode = core.getBaseType(targetNode);
let targetMetaName = core.getAttribute(targetMetaNode, "name");
if (typeof targetMetaName === "string") {
let load = {
name: targetMetaName,
guid: targetGuid
};
let sourceSet = sets[setName];
if (sourceSet === undefined) {
sets[setName] = [load];
} else {
sourceSet.push(load);
}
}
let targetEntry = nodeGuidMap[targetGuid];
if (targetEntry === undefined) {
targetEntry = {
"name": {},
"guid": targetGuid,
"pointers": {}, "inv_pointers": {},
"sets": {}, "inv_sets": {}
};
nodeGuidMap[targetGuid] = targetEntry;
}
let invSets = targetEntry.inv_sets;
let targetSet = invSets[setName];
let invLoad = {
name: targetMetaName,
guid: sourceGuid
};
if (targetSet === undefined) {
invSets[setName] = [invLoad];
} else {
targetSet.push(invLoad);
};
}
});
catch (err) {
console.log(`difficulty loading target path: ${targetPath} with err: ${err.message}`);
let load = {
"fault": `could not load member path: ${targetPath}`
};
let sets: DictionaryAny = sourceEntry.sets;
let sourceSet = sets[setName];
if (sourceSet === undefined) {
sets[setName] = [load];
} else {
sourceSet.push(load);
}
}
}
}));
} finally {
done();
}
};
return Promise
.try<void>(() => {
return core.traverse(sponsor.rootNode,
{ excludeRoot: false },
visitFn);
})
.then(() => {
return nodeGuidMap;
});
await core.traverse(sponsor.rootNode, { excludeRoot: false }, visitFn);
return nodeGuidMap;
}
}