mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Merge branch 'master' into jest-type-inference
# Conflicts: # types/jest/index.d.ts
This commit is contained in:
@@ -11,8 +11,8 @@ Also see the [definitelytyped.org](http://definitelytyped.org) website, although
|
||||
This section tracks the health of the repository and publishing process.
|
||||
It may be helpful for contributors experiencing any issues with their PRs and packages.
|
||||
|
||||
* All packages are type-checking/linting cleanly: [](https://travis-ci.org/DefinitelyTyped/DefinitelyTyped)
|
||||
* All packages are being published to npm in under 10,000 seconds: [](https://typescript.visualstudio.com/TypeScript/_build/latest?definitionId=13)
|
||||
* All packages are [type-checking/linting](https://github.com/Microsoft/dtslint) cleanly: [](https://travis-ci.org/DefinitelyTyped/DefinitelyTyped)
|
||||
* All packages are being [published to npm](https://github.com/Microsoft/types-publisher) in under an hour: [](https://typescript.visualstudio.com/TypeScript/_build/latest?definitionId=13)
|
||||
* [typescript-bot](https://github.com/typescript-bot) has been active on DefinitelyTyped [](https://typescript.visualstudio.com/TypeScript/_build/latest?definitionId=14)
|
||||
|
||||
If anything here seems wrong, or any of the above are failing, please raise an issue in [the DefinitelyTyped Gitter channel](https://gitter.im/DefinitelyTyped/DefinitelyTyped).
|
||||
@@ -229,7 +229,7 @@ It depends, but most pull requests will be merged within a week. PRs that have b
|
||||
|
||||
#### My PR is merged; when will the `@types` NPM package be updated?
|
||||
|
||||
NPM packages should update within a few hours. If it's been more than 24 hours, ping @RyanCavanaugh and @andy-ms on the PR to investigate.
|
||||
NPM packages should update within a few minutes. If it's been more than an hour, mention the PR number on [the DefinitelyTyped Gitter channel](https://gitter.im/DefinitelyTyped/DefinitelyTyped) and the current maintainer will get the correct team member to investigate.
|
||||
|
||||
#### I'm writing a definition that depends on another definition. Should I use `<reference types="" />` or an import?
|
||||
|
||||
@@ -327,14 +327,60 @@ If the standard is still a draft, it belongs here.
|
||||
Use a name beginning with `dom-` and include a link to the standard as the "Project" link in the header.
|
||||
When it graduates draft mode, we may remove it from DefinitelyTyped and deprecate the associated `@types` package.
|
||||
|
||||
#### I want to update a package to a new major version
|
||||
#### How do DefinitelyTyped package versions relate to versions of the corresponding library?
|
||||
|
||||
If you intend to continue updating the older version of the package, you may create a new subfolder with the current version e.g. `v2`, and copy existing files to it. If so, you will need to:
|
||||
_NOTE: The discussion in this section assumes familiarity with [Semantic versioning](https://semver.org/)_
|
||||
|
||||
Each DefinitelyTyped package is versioned when published to NPM.
|
||||
The [types-publisher](https://github.com/Microsoft/types-publisher) (the tool that publishes `@types` packages to npm) will set the declaration package's version by using the `major.minor` version number listed in the first line of its `index.d.ts` file.
|
||||
For example, here are the first few lines of [Node's type declarations](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1253faabf5e0d2c5470db6ea87795d7f96fef7e2/types/node/index.d.ts) for version `10.12.x` at the time of writing:
|
||||
|
||||
```js
|
||||
// Type definitions for Node.js 10.12
|
||||
// Project: http://nodejs.org/
|
||||
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
|
||||
// DefinitelyTyped <https://github.com/DefinitelyTyped>
|
||||
// Alberto Schiabel <https://github.com/jkomyno>
|
||||
```
|
||||
|
||||
Because `10.12` is at the end the first line, the npm version of the `@types/node` package will also be `10.12.x`.
|
||||
Note that the first-line comment in the `index.d.ts` file should only contain the `major.minor` version (e.g. `10.12`) and should not contain a patch version (e.g. `10.12.4`).
|
||||
This is because only the major and minor release numbers are aligned between library packages and type declaration packages.
|
||||
The patch release number of the type declaration package (e.g. `.0` in `10.12.0`) is initialized to zero by DefinitelyTyped and is incremented each time a new `@types/node` package is published to NPM for the same major/minor version of the corresponding library.
|
||||
|
||||
Sometimes type declaration package versions and library package versions can get out of sync.
|
||||
Below are a few common reasons why, in order of how much they inconvenience users of a library.
|
||||
Only the last case is typically problematic.
|
||||
|
||||
* As noted above, the patch version of the type declaration package is unrelated to the library patch version.
|
||||
This allows DefinitelyTyped to safely update type declarations for the same major/minor version of a library.
|
||||
* If updating a package for new functionality, don't forget to update the version number to line up with that version of the library.
|
||||
If users make sure versions correspond between JavaScript packages and their respective `@types` packages, then `npm update` should typically just work.
|
||||
* It's common for type declaration package updates to lag behind library updates because it's often library users, not maintainers, who update DefinitelyTyped when new library features are released.
|
||||
So there may be a lag of days, weeks, or even months before a helpful community member sends a PR to update the type declaration package for a new library release.
|
||||
If you're impacted by this, you can be the change you want to see in the world and you can be that helpful community member!
|
||||
|
||||
:exclamation: If you're updating type declarations for a library, always set the `major.minor` version in the first line of `index.d.ts` to match the library version that you're documenting! :exclamation:
|
||||
|
||||
#### If a library is updated to a new major version with breaking changes, how should I update its type declaration package?
|
||||
|
||||
[Semantic versioning](https://semver.org/) requires that versions with breaking changes must increment the major version number.
|
||||
For example, a library that removes a publicly exported function after its `3.5.8` release must bump its version to `4.0.0` in its next release.
|
||||
Furthermore, when the library's `4.0.0` release is out, its DefinitelyTyped type declaration package should also be updated to `4.0.0`, including any breaking changes to the library's API.
|
||||
|
||||
Many libraries have a large installed base of developers (including maintainers of other packages using that library as a dependency) who won't move right away to a new version that has breaking changes, because it might be months until a maintainer has time to rewrite code to adapt to the new version.
|
||||
In the meantime, users of old library versions still may want to update type declarations for older versions.
|
||||
|
||||
If you intend to continue updating the older version of a library's type declarations, you may create a new subfolder (e.g. `/v2/`) named for the current (soon to be "old") version, and copy existing files from the current version to it.
|
||||
|
||||
Because the root folder should always contain the type declarations for the latest ("new") version, you'll need to make a few changes to the files in your old-version subdirectory to ensure that relative path references point to the subdirectory, not the root.
|
||||
|
||||
1. Update the relative paths in `tsconfig.json` as well as `tslint.json`.
|
||||
2. Add path mapping rules to ensure that tests are running against the intended version.
|
||||
|
||||
For example [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/history/v2/tsconfig.json) looks like:
|
||||
For example, the [`history`](https://github.com/ReactTraining/history/) library introduced breaking changes between version `2.x` and `3.x`.
|
||||
Because many users still consumed the older `2.x` version, a maintainer who wanted to update the type declarations for this library to `3.x` added a `v2` folder inside the history repository that contains type declarations for the older version.
|
||||
At the time of writing, the [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1253faabf5e0d2c5470db6ea87795d7f96fef7e2/types/history/v2/tsconfig.json) looks roughly like:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -352,10 +398,11 @@ For example [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/Defi
|
||||
}
|
||||
```
|
||||
|
||||
If there are other packages on DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version. You will also need to do this for packages depending on packages depending on the old version.
|
||||
If there are other packages in DefinitelyTyped that are incompatible with the new version, you will need to add path mappings to the old version.
|
||||
You will also need to do this recursively for packages depending on packages depending on the old version.
|
||||
|
||||
For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`;
|
||||
transitively `react-router-bootstrap` (which depends on `react-router`) also adds a path mapping in its [tsconfig.json](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router-bootstrap/tsconfig.json).
|
||||
For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-router/v2/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`.
|
||||
Transitively, `react-router-bootstrap` (which depends on `react-router`) also needed to add the same path mapping (`"history": [ "history/v2" ]`) in its `tsconfig.json` until its `react-router` dependency was updated to the latest version.
|
||||
|
||||
Also, `/// <reference types=".." />` will not work with path mapping, so dependencies must use `import`.
|
||||
|
||||
|
||||
@@ -564,12 +564,24 @@
|
||||
"sourceRepoURL": "https://www.npmjs.com/package/fast-simplex-noise",
|
||||
"asOfVersion": "3.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "fastify-cors",
|
||||
"typingsPackageName": "fastify-cors",
|
||||
"sourceRepoURL": "https://github.com/fastify/fastify-cors",
|
||||
"asOfVersion": "2.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "Fastify-JWT",
|
||||
"typingsPackageName": "fastify-jwt",
|
||||
"sourceRepoURL": "https://github.com/fastify/fastify-jwt",
|
||||
"asOfVersion": "0.8.1"
|
||||
},
|
||||
{
|
||||
"libraryName": "fastify-static",
|
||||
"typingsPackageName": "fastify-static",
|
||||
"sourceRepoURL": "https://github.com/fastify/fastify-static",
|
||||
"asOfVersion": "2.2.1"
|
||||
},
|
||||
{
|
||||
"libraryName": "fecha",
|
||||
"typingsPackageName": "fecha",
|
||||
|
||||
Vendored
+159
-130
@@ -1,150 +1,179 @@
|
||||
// Type definitions for node_acl 0.4.8
|
||||
// Type definitions for acl 0.4
|
||||
// Project: https://github.com/optimalbits/node_acl
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="node"/>
|
||||
/// <reference types="express"/>
|
||||
|
||||
import http = require('http');
|
||||
import Promise = require("bluebird");
|
||||
import express = require("express");
|
||||
import Promise = require('bluebird');
|
||||
import express = require('express');
|
||||
import redis = require('redis');
|
||||
import mongo = require('mongodb');
|
||||
|
||||
type strings = string|string[];
|
||||
type Value = string|number;
|
||||
type Values = Value|Value[];
|
||||
export = AclStatic;
|
||||
|
||||
declare const AclStatic: AclStatic;
|
||||
|
||||
type strings = string | string[];
|
||||
type Value = string | number;
|
||||
type Values = Value | Value[];
|
||||
type Action = () => any;
|
||||
type Callback = (err: Error) => any;
|
||||
type Callback = (err?: Error) => any;
|
||||
type AnyCallback = (err: Error, obj: any) => any;
|
||||
type AllowedCallback = (err: Error, allowed: boolean) => any;
|
||||
type GetUserId = (req: http.IncomingMessage, res: http.ServerResponse) => Value;
|
||||
|
||||
interface AclStatic {
|
||||
new (backend: Backend<any>, logger: Logger, options: Option): Acl;
|
||||
new (backend: Backend<any>, logger: Logger): Acl;
|
||||
new (backend: Backend<any>): Acl;
|
||||
memoryBackend: MemoryBackendStatic;
|
||||
new (
|
||||
backend: AclStatic.Backend<any>,
|
||||
logger?: AclStatic.Logger,
|
||||
options?: AclStatic.Option
|
||||
): AclStatic.Acl;
|
||||
readonly memoryBackend: AclStatic.MemoryBackendStatic;
|
||||
readonly mongodbBackend: AclStatic.MongodbBackendStatic;
|
||||
readonly redisBackend: AclStatic.RedisBackendStatic;
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug: (msg: string) => any;
|
||||
}
|
||||
|
||||
interface Acl {
|
||||
addUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
removeUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
userRoles: (userId: Value, cb?: (err: Error, roles: string[]) => any) => Promise<string[]>;
|
||||
roleUsers: (role: Value, cb?: (err: Error, users: Values) => any) => Promise<any>;
|
||||
hasRole: (userId: Value, role: string, cb?: (err: Error, isInRole: boolean) => any) => Promise<boolean>;
|
||||
addRoleParents: (role: string, parents: Values, cb?: Callback) => Promise<void>;
|
||||
removeRole: (role: string, cb?: Callback) => Promise<void>;
|
||||
removeResource: (resource: string, cb?: Callback) => Promise<void>;
|
||||
allow: {
|
||||
(roles: Values, resources: strings, permissions: strings, cb?: Callback): Promise<void>;
|
||||
(aclSets: AclSet | AclSet[]): Promise<void>;
|
||||
declare namespace AclStatic {
|
||||
interface Logger {
|
||||
debug: (msg: string) => any;
|
||||
}
|
||||
removeAllow: (role: string, resources: strings, permissions: strings, cb?: Callback) => Promise<void>;
|
||||
removePermissions: (role: string, resources: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
allowedPermissions: (userId: Value, resources: strings, cb?: AnyCallback) => Promise<void>;
|
||||
isAllowed: (userId: Value, resources: strings, permissions: strings, cb?: AllowedCallback) => Promise<boolean>;
|
||||
areAnyRolesAllowed: (roles: strings, resource: strings, permissions: strings, cb?: AllowedCallback) => Promise<any>;
|
||||
whatResources: {
|
||||
(roles: strings, cb?: AnyCallback): Promise<any>;
|
||||
(roles: strings, permissions: strings, cb?: AnyCallback): Promise<any>;
|
||||
|
||||
interface Acl {
|
||||
addUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
removeUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
userRoles: (userId: Value, cb?: (err: Error, roles: string[]) => any) => Promise<string[]>;
|
||||
roleUsers: (role: Value, cb?: (err: Error, users: Values) => any) => Promise<any>;
|
||||
hasRole: (
|
||||
userId: Value,
|
||||
role: string,
|
||||
cb?: (err: Error, isInRole: boolean) => any
|
||||
) => Promise<boolean>;
|
||||
addRoleParents: (role: string, parents: Values, cb?: Callback) => Promise<void>;
|
||||
removeRole: (role: string, cb?: Callback) => Promise<void>;
|
||||
removeResource: (resource: string, cb?: Callback) => Promise<void>;
|
||||
allow: {
|
||||
(roles: Values, resources: strings, permissions: strings, cb?: Callback): Promise<void>;
|
||||
(aclSets: AclSet | AclSet[]): Promise<void>;
|
||||
};
|
||||
removeAllow: (
|
||||
role: string,
|
||||
resources: strings,
|
||||
permissions: strings,
|
||||
cb?: Callback
|
||||
) => Promise<void>;
|
||||
removePermissions: (
|
||||
role: string,
|
||||
resources: strings,
|
||||
permissions: strings,
|
||||
cb?: Callback
|
||||
) => Promise<void>;
|
||||
allowedPermissions: (userId: Value, resources: strings, cb?: AnyCallback) => Promise<void>;
|
||||
isAllowed: (
|
||||
userId: Value,
|
||||
resources: strings,
|
||||
permissions: strings,
|
||||
cb?: AllowedCallback
|
||||
) => Promise<boolean>;
|
||||
areAnyRolesAllowed: (
|
||||
roles: strings,
|
||||
resource: strings,
|
||||
permissions: strings,
|
||||
cb?: AllowedCallback
|
||||
) => Promise<any>;
|
||||
whatResources: {
|
||||
(roles: strings, cb?: AnyCallback): Promise<any>;
|
||||
(roles: strings, permissions: strings, cb?: AnyCallback): Promise<any>;
|
||||
};
|
||||
permittedResources: (roles: strings, permissions: strings, cb?: Callback) => Promise<void>;
|
||||
middleware: (
|
||||
numPathComponents?: number,
|
||||
userId?: Value | GetUserId,
|
||||
actions?: strings
|
||||
) => express.RequestHandler;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
buckets?: BucketsOption;
|
||||
}
|
||||
|
||||
interface BucketsOption {
|
||||
meta?: string;
|
||||
parents?: string;
|
||||
permissions?: string;
|
||||
resources?: string;
|
||||
roles?: string;
|
||||
users?: string;
|
||||
}
|
||||
|
||||
interface AclSet {
|
||||
roles: strings;
|
||||
allows: AclAllow[];
|
||||
}
|
||||
|
||||
interface AclAllow {
|
||||
resources: strings;
|
||||
permissions: strings;
|
||||
}
|
||||
|
||||
interface MemoryBackend extends Backend<Action[]> {}
|
||||
interface MemoryBackendStatic {
|
||||
new (): MemoryBackend;
|
||||
}
|
||||
|
||||
//
|
||||
// For internal use
|
||||
//
|
||||
interface Backend<T> {
|
||||
begin: () => T;
|
||||
end: (transaction: T, cb?: Action) => void;
|
||||
clean: (cb?: Action) => void;
|
||||
get: (bucket: string, key: Value, cb?: Action) => void;
|
||||
union: (bucket: string, keys: Value[], cb?: Action) => void;
|
||||
add: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
del: (transaction: T, bucket: string, keys: Value[]) => void;
|
||||
remove: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
|
||||
endAsync: (transaction: T, cb?: (err: Error | null) => void) => Promise<void>;
|
||||
getAsync: (
|
||||
bucket: string,
|
||||
key: Value,
|
||||
cb?: (err: Error | null, value: any) => void
|
||||
) => Promise<any>;
|
||||
cleanAsync: (cb?: (error?: Error) => void) => Promise<void>;
|
||||
unionAsync: (
|
||||
bucket: string,
|
||||
keys: Value[],
|
||||
cb?: (error: Error | undefined, results: any[]) => void
|
||||
) => Promise<any[]>;
|
||||
}
|
||||
|
||||
interface Contract {
|
||||
(args: IArguments): Contract | NoOp;
|
||||
debug: boolean;
|
||||
fulfilled: boolean;
|
||||
args: any[];
|
||||
checkedParams: string[];
|
||||
params: (...types: string[]) => Contract | NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
interface NoOp {
|
||||
params: (...types: string[]) => NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
// for redis backend
|
||||
interface RedisBackend extends Backend<redis.RedisClient> {}
|
||||
interface RedisBackendStatic {
|
||||
new (redis: redis.RedisClient, prefix?: string): RedisBackend;
|
||||
}
|
||||
|
||||
// for mongodb backend
|
||||
interface MongodbBackend extends Backend<Callback> {}
|
||||
interface MongodbBackendStatic {
|
||||
new (db: mongo.Db, prefix?: string, useSingle?: boolean): MongodbBackend;
|
||||
}
|
||||
permittedResources: (roles: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
middleware: (numPathComponents?: number, userId?: Value | GetUserId, actions?: strings) => express.RequestHandler;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
buckets?: BucketsOption;
|
||||
}
|
||||
|
||||
interface BucketsOption {
|
||||
meta?: string;
|
||||
parents?: string;
|
||||
permissions?: string;
|
||||
resources?: string;
|
||||
roles?: string;
|
||||
users?: string;
|
||||
}
|
||||
|
||||
interface AclSet {
|
||||
roles: strings;
|
||||
allows: AclAllow[];
|
||||
}
|
||||
|
||||
interface AclAllow {
|
||||
resources: strings;
|
||||
permissions: strings;
|
||||
}
|
||||
|
||||
interface MemoryBackend extends Backend<Action[]> { }
|
||||
interface MemoryBackendStatic {
|
||||
new (): MemoryBackend;
|
||||
}
|
||||
|
||||
//
|
||||
// For internal use
|
||||
//
|
||||
interface Backend<T> {
|
||||
begin: () => T;
|
||||
end: (transaction: T, cb?: Action) => void;
|
||||
clean: (cb?: Action) => void;
|
||||
get: (bucket: string, key: Value, cb?: Action) => void;
|
||||
union: (bucket: string, keys: Value[], cb?: Action) => void;
|
||||
add: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
del: (transaction: T, bucket: string, keys: Value[]) => void;
|
||||
remove: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
|
||||
endAsync: Function; //TODO: Give more specific function signature
|
||||
getAsync: Function;
|
||||
cleanAsync: Function;
|
||||
unionAsync: Function;
|
||||
}
|
||||
|
||||
interface Contract {
|
||||
(args: IArguments): Contract | NoOp;
|
||||
debug: boolean;
|
||||
fulfilled: boolean;
|
||||
args: any[];
|
||||
checkedParams: string[];
|
||||
params: (...types: string[]) => Contract | NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
interface NoOp {
|
||||
params: (...types: string[]) => NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
// for redis backend
|
||||
import redis = require('redis');
|
||||
|
||||
interface AclStatic {
|
||||
redisBackend: RedisBackendStatic;
|
||||
}
|
||||
|
||||
interface RedisBackend extends Backend<redis.RedisClient> { }
|
||||
interface RedisBackendStatic {
|
||||
new (redis: redis.RedisClient, prefix: string): RedisBackend;
|
||||
new (redis: redis.RedisClient): RedisBackend;
|
||||
}
|
||||
|
||||
// for mongodb backend
|
||||
import mongo = require('mongodb');
|
||||
|
||||
interface AclStatic {
|
||||
mongodbBackend: MongodbBackendStatic;
|
||||
}
|
||||
|
||||
interface MongodbBackend extends Backend<Callback> { }
|
||||
interface MongodbBackendStatic {
|
||||
new (db: mongo.Db, prefix: string, useSingle: boolean): MongodbBackend;
|
||||
new (db: mongo.Db, prefix: string): MongodbBackend;
|
||||
new (db: mongo.Db): MongodbBackend;
|
||||
}
|
||||
|
||||
declare var _: AclStatic;
|
||||
export = _;
|
||||
|
||||
+35
-36
@@ -2,15 +2,15 @@
|
||||
// https://github.com/OptimalBits/node_acl/blob/master/Readme.md
|
||||
import Acl = require('acl');
|
||||
|
||||
var report = <T>(err: Error, value: T) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
console.info(value);
|
||||
const report = (err: Error, value: any) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
console.info(value);
|
||||
};
|
||||
|
||||
// Using the memory backend
|
||||
var acl = new Acl(new Acl.memoryBackend());
|
||||
const acl: Acl.Acl = new Acl(new Acl.memoryBackend());
|
||||
|
||||
// middleware with no optional parameters
|
||||
acl.middleware();
|
||||
@@ -18,11 +18,11 @@ acl.middleware();
|
||||
acl.middleware(1);
|
||||
|
||||
acl.middleware(1, () => {
|
||||
return "joed";
|
||||
return 'joed';
|
||||
});
|
||||
|
||||
acl.middleware(1, () => {
|
||||
return 2;
|
||||
return 2;
|
||||
});
|
||||
|
||||
acl.middleware(1, 'joed');
|
||||
@@ -33,36 +33,36 @@ acl.middleware(3, 'joed', 'post');
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
acl.allow('member', 'blogs', ['edit', 'view', 'delete']);
|
||||
|
||||
acl.addUserRoles('joed', 'guest');
|
||||
|
||||
acl.addRoleParents('baz', ['foo','bar']);
|
||||
acl.addRoleParents('baz', ['foo', 'bar']);
|
||||
|
||||
acl.allow('foo', ['blogs','forums','news'], ['view', 'delete']);
|
||||
acl.allow('foo', ['blogs', 'forums', 'news'], ['view', 'delete']);
|
||||
|
||||
acl.allow('admin', ['blogs','forums'], '*');
|
||||
acl.allow('admin', ['blogs', 'forums'], '*');
|
||||
|
||||
acl.allow([
|
||||
{
|
||||
roles:['guest','special-member'],
|
||||
allows:[
|
||||
{resources:'blogs', permissions:'get'},
|
||||
{resources:['forums','news'], permissions:['get','put','delete']}
|
||||
]
|
||||
roles: ['guest', 'special-member'],
|
||||
allows: [
|
||||
{ resources: 'blogs', permissions: 'get' },
|
||||
{ resources: ['forums', 'news'], permissions: ['get', 'put', 'delete'] },
|
||||
],
|
||||
},
|
||||
{
|
||||
roles:['gold','silver'],
|
||||
allows:[
|
||||
{resources:'cash', permissions:['sell','exchange']},
|
||||
{resources:['account','deposit'], permissions:['put','delete']}
|
||||
]
|
||||
}
|
||||
roles: ['gold', 'silver'],
|
||||
allows: [
|
||||
{ resources: 'cash', permissions: ['sell', 'exchange'] },
|
||||
{ resources: ['account', 'deposit'], permissions: ['put', 'delete'] },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
acl.isAllowed('joed', 'blogs', 'view', (err, res) => {
|
||||
if (res) {
|
||||
console.log("User joed is allowed to view blogs");
|
||||
console.log('User joed is allowed to view blogs');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -78,15 +78,14 @@ acl.whatResources('foo', 'view', (err, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
acl.isAllowed('jsmith', 'blogs', ['edit','view','delete'])
|
||||
.then((result) => {
|
||||
console.dir('jsmith is allowed blogs ' + result);
|
||||
acl.addUserRoles('jsmith', 'member');
|
||||
}).then(() =>
|
||||
acl.isAllowed('jsmith', 'blogs', ['edit','view','delete'])
|
||||
).then((result) =>
|
||||
console.dir('jsmith is allowed blogs ' + result)
|
||||
).then(() => {
|
||||
acl.allowedPermissions('james', ['blogs','forums'], report);
|
||||
acl.allowedPermissions('jsmith', ['blogs','forums'], report);
|
||||
});
|
||||
acl.isAllowed('jsmith', 'blogs', ['edit', 'view', 'delete'])
|
||||
.then(result => {
|
||||
console.dir('jsmith is allowed blogs ' + result);
|
||||
acl.addUserRoles('jsmith', 'member');
|
||||
})
|
||||
.then(() => acl.isAllowed('jsmith', 'blogs', ['edit', 'view', 'delete']))
|
||||
.then(result => console.dir('jsmith is allowed blogs ' + result))
|
||||
.then(() => {
|
||||
acl.allowedPermissions('james', ['blogs', 'forums'], report);
|
||||
acl.allowedPermissions('jsmith', ['blogs', 'forums'], report);
|
||||
});
|
||||
|
||||
@@ -5,10 +5,10 @@ import mongodb = require('mongodb');
|
||||
declare var db: mongodb.Db;
|
||||
|
||||
// Using the mongo db backend
|
||||
var acl = new Acl(new Acl.mongodbBackend(db, 'acl_', true));
|
||||
const acl = new Acl(new Acl.mongodbBackend(db, 'acl_', true));
|
||||
|
||||
// guest is allowed to view blogs
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
acl.allow('member', 'blogs', ['edit', 'view', 'delete']);
|
||||
|
||||
@@ -5,10 +5,10 @@ import redis = require('redis');
|
||||
declare var client: redis.RedisClient;
|
||||
|
||||
// Using the redis backend
|
||||
var acl = new Acl(new Acl.redisBackend(client, 'acl_'));
|
||||
const acl = new Acl(new Acl.redisBackend(client, 'acl_'));
|
||||
|
||||
// guest is allowed to view blogs
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
acl.allow('member', 'blogs', ['edit', 'view', 'delete']);
|
||||
|
||||
+1
-77
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1687,7 +1687,7 @@ declare namespace algoliasearch {
|
||||
* a list of language ISO codes (as a comma-separated string) for which stop words should be enable
|
||||
* https://github.com/algolia/algoliasearch-client-js#removestopwords
|
||||
*/
|
||||
removeStopWords?: string[];
|
||||
removeStopWords?: boolean | string[];
|
||||
/**
|
||||
* List of attributes on which you want to apply word-splitting ("decompounding") for
|
||||
* each of the languages supported (German, Dutch, and Finnish as of 05/2018)
|
||||
|
||||
@@ -294,6 +294,14 @@ foo.then((x) => {
|
||||
x.toFixed();
|
||||
});
|
||||
|
||||
namespace TestPromiseInterop {
|
||||
declare const promiseInterop: ng.IPromise<number>;
|
||||
const ngStringPromise: ng.IPromise<string> =
|
||||
promiseInterop.then((num) => Promise.resolve(String(num)));
|
||||
const caughtStringPromise: ng.IPromise<string|number> =
|
||||
promiseInterop.catch((reason) => Promise.resolve('oh noes'));
|
||||
}
|
||||
|
||||
// $q signature tests
|
||||
namespace TestQ {
|
||||
interface AbcObject {
|
||||
|
||||
Vendored
+14
@@ -1197,6 +1197,15 @@ declare namespace angular {
|
||||
* the `notifyCallback` method. The promise can not be resolved or rejected from the
|
||||
* `notifyCallback` method.
|
||||
*/
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
successCallback?:
|
||||
| ((value: T) => PromiseLike<never> | PromiseLike<TResult1> | TResult1)
|
||||
| null,
|
||||
errorCallback?:
|
||||
| ((reason: any) => PromiseLike<never> | PromiseLike<TResult2> | TResult2)
|
||||
| null,
|
||||
notifyCallback?: (state: any) => any
|
||||
): IPromise<TResult1 | TResult2>;
|
||||
then<TResult1 = T, TResult2 = never>(
|
||||
successCallback?:
|
||||
| ((value: T) => IPromise<never> | IPromise<TResult1> | TResult1)
|
||||
@@ -1210,6 +1219,11 @@ declare namespace angular {
|
||||
/**
|
||||
* Shorthand for promise.then(null, errorCallback)
|
||||
*/
|
||||
catch<TResult = never>(
|
||||
onRejected?:
|
||||
| ((reason: any) => PromiseLike<never> | PromiseLike<TResult> | TResult)
|
||||
| null
|
||||
): IPromise<T | TResult>;
|
||||
catch<TResult = never>(
|
||||
onRejected?:
|
||||
| ((reason: any) => IPromise<never> | IPromise<TResult> | TResult)
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.iterable"
|
||||
"es2015.iterable",
|
||||
"es2015.promise"
|
||||
],
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": false,
|
||||
@@ -25,4 +26,4 @@
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
declare let str: string;
|
||||
declare let strOrNull: string | null;
|
||||
declare let strOrUndefined: string | undefined;
|
||||
declare let strOrUndefinedOrNull: string | undefined | null;
|
||||
declare let date: Date;
|
||||
declare let anyObj: any;
|
||||
declare let num: number;
|
||||
declare let error: Error;
|
||||
declare let bool: boolean;
|
||||
declare let boolOrUndefined: boolean | undefined;
|
||||
declare let numOrUndefined: number | undefined;
|
||||
declare let apiGwEvtReqCtx: AWSLambda.APIGatewayEventRequestContext;
|
||||
declare let apiGwEvtReqCtxOpt: AWSLambda.APIGatewayEventRequestContext | null | undefined;
|
||||
declare let apiGwEvt: AWSLambda.APIGatewayEvent;
|
||||
@@ -80,6 +82,11 @@ declare const scheduledEvent: AWSLambda.ScheduledEvent;
|
||||
str = apiGwEvtReqCtx.accountId;
|
||||
str = apiGwEvtReqCtx.apiId;
|
||||
authResponseContextOpt = apiGwEvtReqCtx.authorizer;
|
||||
numOrUndefined = apiGwEvtReqCtx.connectedAt;
|
||||
strOrUndefined = apiGwEvtReqCtx.connectionId;
|
||||
strOrUndefined = apiGwEvtReqCtx.domainName;
|
||||
strOrUndefined = apiGwEvtReqCtx.eventType;
|
||||
strOrUndefined = apiGwEvtReqCtx.extendedRequestId;
|
||||
str = apiGwEvtReqCtx.httpMethod;
|
||||
strOrNull = apiGwEvtReqCtx.identity.accessKey;
|
||||
strOrNull = apiGwEvtReqCtx.identity.accountId;
|
||||
@@ -94,11 +101,15 @@ str = apiGwEvtReqCtx.identity.sourceIp;
|
||||
strOrNull = apiGwEvtReqCtx.identity.user;
|
||||
strOrNull = apiGwEvtReqCtx.identity.userAgent;
|
||||
strOrNull = apiGwEvtReqCtx.identity.userArn;
|
||||
strOrUndefined = apiGwEvtReqCtx.messageDirection;
|
||||
strOrUndefinedOrNull = apiGwEvtReqCtx.messageId;
|
||||
str = apiGwEvtReqCtx.path;
|
||||
str = apiGwEvtReqCtx.stage;
|
||||
str = apiGwEvtReqCtx.requestId;
|
||||
strOrUndefined = apiGwEvtReqCtx.requestTime;
|
||||
str = apiGwEvtReqCtx.resourceId;
|
||||
str = apiGwEvtReqCtx.resourcePath;
|
||||
strOrUndefined = apiGwEvtReqCtx.routeKey;
|
||||
|
||||
/* API Gateway Event */
|
||||
strOrNull = apiGwEvt.body;
|
||||
|
||||
Vendored
+10
@@ -25,6 +25,7 @@
|
||||
// Trevor Leach <https://github.com/trevor-leach>
|
||||
// James Gregory <https://github.com/jagregory>
|
||||
// Erik Dalén <https://github.com/dalen>
|
||||
// Loïk Gaonac'h <https://github.com/loikg>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -33,6 +34,11 @@ export interface APIGatewayEventRequestContext {
|
||||
accountId: string;
|
||||
apiId: string;
|
||||
authorizer?: AuthResponseContext | null;
|
||||
connectedAt: number;
|
||||
connectionId?: string;
|
||||
domainName?: string;
|
||||
eventType?: string;
|
||||
extendedRequestId?: string;
|
||||
httpMethod: string;
|
||||
identity: {
|
||||
accessKey: string | null;
|
||||
@@ -49,12 +55,16 @@ export interface APIGatewayEventRequestContext {
|
||||
userAgent: string | null;
|
||||
userArn: string | null;
|
||||
};
|
||||
messageDirection?: string;
|
||||
messageId?: string | null;
|
||||
path: string;
|
||||
stage: string;
|
||||
requestId: string;
|
||||
requestTime?: string;
|
||||
requestTimeEpoch: number;
|
||||
resourceId: string;
|
||||
resourcePath: string;
|
||||
routeKey?: string;
|
||||
}
|
||||
|
||||
// API Gateway "event"
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { SSM } from 'aws-sdk';
|
||||
import {
|
||||
ParameterQuery,
|
||||
parameterQuery,
|
||||
getParameter,
|
||||
getParameters,
|
||||
getParametersByPath,
|
||||
getParameterSync,
|
||||
getParametersSync,
|
||||
getParametersByPathSync,
|
||||
} from 'aws-param-store';
|
||||
|
||||
declare let bool: boolean;
|
||||
declare let query: ParameterQuery;
|
||||
declare let psName: SSM.Types.PSParameterName;
|
||||
declare let psNames: SSM.Types.ParameterNameList;
|
||||
declare let options: SSM.Types.ClientConfiguration;
|
||||
declare let paramResult: SSM.Types.Parameter;
|
||||
declare let paramsResult: SSM.Types.GetParametersResult;
|
||||
declare let paramsByPathResult: SSM.Types.ParameterList;
|
||||
declare let allParamResults: SSM.Types.Parameter | SSM.Types.GetParametersByPathResult | SSM.Types.ParameterList;
|
||||
declare let promiseParamResult: Promise<SSM.Types.Parameter>;
|
||||
declare let promiseParamsResult: Promise<SSM.Types.GetParametersResult>;
|
||||
declare let promiseParamsByPathResult: Promise<SSM.Types.ParameterList>;
|
||||
declare let promiseAllParamResults: Promise<typeof allParamResults>;
|
||||
|
||||
query = parameterQuery();
|
||||
|
||||
query.path(psName);
|
||||
query.named(psName);
|
||||
query.named(psNames);
|
||||
query.decryption(bool);
|
||||
query.recursive(bool);
|
||||
|
||||
promiseAllParamResults = query.execute();
|
||||
allParamResults = query.executeSync();
|
||||
|
||||
// test chaining
|
||||
query = query
|
||||
.path(psName)
|
||||
.named(psName)
|
||||
.named(psNames)
|
||||
.decryption(bool)
|
||||
.recursive(bool);
|
||||
|
||||
promiseAllParamResults = query
|
||||
.path(psName)
|
||||
.named(psName)
|
||||
.named(psNames)
|
||||
.decryption(bool)
|
||||
.recursive(bool)
|
||||
.execute();
|
||||
|
||||
allParamResults = query
|
||||
.path(psName)
|
||||
.named(psName)
|
||||
.named(psNames)
|
||||
.decryption(bool)
|
||||
.recursive(bool)
|
||||
.executeSync();
|
||||
|
||||
promiseParamResult = getParameter(psName);
|
||||
promiseParamResult = getParameter(psName, options);
|
||||
|
||||
promiseParamsResult = getParameters(psNames);
|
||||
promiseParamsResult = getParameters(psNames, options);
|
||||
|
||||
promiseParamsByPathResult = getParametersByPath(psNames);
|
||||
promiseParamsByPathResult = getParametersByPath(psNames, options);
|
||||
|
||||
paramResult = getParameterSync(psName);
|
||||
paramResult = getParameterSync(psName, options);
|
||||
|
||||
paramsResult = getParametersSync(psNames);
|
||||
paramsResult = getParametersSync(psNames, options);
|
||||
|
||||
paramsByPathResult = getParametersByPathSync(psNames);
|
||||
paramsByPathResult = getParametersByPathSync(psNames, options);
|
||||
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
// Type definitions for aws-param-store 2.1
|
||||
// Project: https://github.com/vandium-io/aws-param-store#readme
|
||||
// Definitions by: Jason Gray <https://github.com/jasonthomasgray>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import { SSM } from 'aws-sdk';
|
||||
|
||||
export function getParameter(
|
||||
name: SSM.Types.PSParameterName,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): Promise<SSM.Types.Parameter>;
|
||||
|
||||
export function getParameterSync(
|
||||
name: SSM.Types.PSParameterName,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): SSM.Types.Parameter;
|
||||
|
||||
export function getParameters(
|
||||
names: SSM.Types.ParameterNameList,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): Promise<SSM.Types.GetParametersResult>;
|
||||
|
||||
export function getParametersSync(
|
||||
names: SSM.Types.ParameterNameList,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): SSM.Types.GetParametersResult;
|
||||
|
||||
export function getParametersByPath(
|
||||
path: SSM.Types.ParameterNameList,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): Promise<SSM.Types.ParameterList>;
|
||||
|
||||
export function getParametersByPathSync(
|
||||
path: SSM.Types.ParameterNameList,
|
||||
options?: SSM.Types.ClientConfiguration
|
||||
): SSM.Types.ParameterList;
|
||||
|
||||
export interface ParameterQuery {
|
||||
path(path: SSM.Types.PSParameterName): ParameterQuery;
|
||||
named(nameOrNames: SSM.Types.PSParameterName | SSM.Types.ParameterNameList): ParameterQuery;
|
||||
decryption(enabled: boolean): ParameterQuery;
|
||||
recursive(enabled: boolean): ParameterQuery;
|
||||
execute(): Promise<SSM.Types.ParameterList | SSM.Types.Parameter | SSM.Types.GetParametersResult>;
|
||||
executeSync(): SSM.Types.ParameterList | SSM.Types.Parameter | SSM.Types.GetParametersResult;
|
||||
}
|
||||
|
||||
export function parameterQuery(options?: SSM.Types.ClientConfiguration): ParameterQuery;
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.325.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"aws-param-store-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import * as Backbone from 'backbone';
|
||||
import * as BackboneRel from 'backbone-relational';
|
||||
|
||||
class House extends Backbone.RelationalModel {
|
||||
class House extends BackboneRel.Model {
|
||||
// The 'relations' property, on the House's prototype. Initialized separately for each
|
||||
// instance of House. Each relation must define (as a minimum) the 'type', 'key' and
|
||||
// 'relatedModel'. Options include 'includeInJSON', 'createModels' and 'reverseRelation'.
|
||||
|
||||
relations = [
|
||||
{
|
||||
type: Backbone.HasMany, // Use the type, or the string 'HasOne' or 'HasMany'.
|
||||
type: BackboneRel.HasMany, // Use the type, or the string 'HasOne' or 'HasMany'.
|
||||
key: 'occupants',
|
||||
relatedModel: 'Person',
|
||||
includeInJSON: true,
|
||||
@@ -20,14 +20,14 @@ class House extends Backbone.RelationalModel {
|
||||
|
||||
}
|
||||
|
||||
class Person extends Backbone.RelationalModel {
|
||||
class Person extends BackboneRel.Model {
|
||||
relations = [
|
||||
{ // Create a (recursive) one-to-one relationship
|
||||
type: Backbone.HasOne,
|
||||
type: BackboneRel.HasOne,
|
||||
key: 'user',
|
||||
relatedModel: 'User',
|
||||
reverseRelation: {
|
||||
type: Backbone.HasOne,
|
||||
type: BackboneRel.HasOne,
|
||||
key: 'person'
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class Person extends Backbone.RelationalModel {
|
||||
}
|
||||
}
|
||||
|
||||
class User extends Backbone.RelationalModel {
|
||||
class User extends BackboneRel.Model {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vendored
+36
-35
@@ -1,15 +1,16 @@
|
||||
// Type definitions for Backbone-relational 0.8.5
|
||||
// Type definitions for Backbone-relational 0.10.0
|
||||
// Project: http://backbonerelational.org/
|
||||
// Definitions by: Eirik Hoem <https://github.com/eirikhm>
|
||||
// Julian Gonggrijp <https://github.com/jgonggrijp>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="jquery" />
|
||||
|
||||
import * as Backbone from 'backbone';
|
||||
import { Events, EventsHash, Model as BModel, Collection } from 'backbone';
|
||||
|
||||
declare module 'backbone' {
|
||||
class RelationalModel extends Model {
|
||||
declare module 'backbone-relational' {
|
||||
class Model extends BModel {
|
||||
/**
|
||||
* Do not use, prefer TypeScript's extend functionality.
|
||||
**/
|
||||
@@ -47,7 +48,7 @@ declare module 'backbone' {
|
||||
static findOrCreate(attributes:any, options?:any);
|
||||
}
|
||||
|
||||
export class Relation extends Model {
|
||||
export class Relation extends BModel {
|
||||
|
||||
options:any;
|
||||
instance:any;
|
||||
@@ -60,11 +61,11 @@ declare module 'backbone' {
|
||||
|
||||
checkPreconditions():boolean;
|
||||
|
||||
setRelated(related:Model):void;
|
||||
setRelated(related:BModel):void;
|
||||
|
||||
setRelated(related:Collection<Model>):void;
|
||||
setRelated(related:Collection<BModel>):void;
|
||||
|
||||
getReverseRelations(model:RelationalModel):Relation;
|
||||
getReverseRelations(model:Model):Relation;
|
||||
|
||||
destroy():void;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ declare module 'backbone' {
|
||||
export class HasOne extends Relation {
|
||||
collectionType:any;
|
||||
|
||||
findRelated(options:any):Model;
|
||||
findRelated(options:any):BModel;
|
||||
|
||||
setKeyContents(keyContents:string):void;
|
||||
|
||||
@@ -82,21 +83,21 @@ declare module 'backbone' {
|
||||
|
||||
setKeyContents(keyContents:number[]):void;
|
||||
|
||||
setKeyContents(keyContents:Collection<Model>):void;
|
||||
setKeyContents(keyContents:Collection<BModel>):void;
|
||||
|
||||
onChange(model:Model, attr:any, options:any):void;
|
||||
onChange(model:BModel, attr:any, options:any):void;
|
||||
|
||||
handleAddition(model:Model, coll:Collection<Model>, options:any):void;
|
||||
handleAddition(model:BModel, coll:Collection<BModel>, options:any):void;
|
||||
|
||||
handleRemoval(model:Model, coll:Collection<Model>, options:any):void;
|
||||
handleRemoval(model:BModel, coll:Collection<BModel>, options:any):void;
|
||||
|
||||
handleReset(coll:Collection<Model>, options:any):void;
|
||||
handleReset(coll:Collection<BModel>, options:any):void;
|
||||
|
||||
tryAddRelated(model:Model, coll:any, options:any):void;
|
||||
tryAddRelated(model:BModel, coll:any, options:any):void;
|
||||
|
||||
addRelated(model:Model, options:any):void;
|
||||
addRelated(model:BModel, options:any):void;
|
||||
|
||||
removeRelated(model:Model, coll:any, options:any):void;
|
||||
removeRelated(model:BModel, coll:any, options:any):void;
|
||||
|
||||
}
|
||||
|
||||
@@ -104,21 +105,21 @@ declare module 'backbone' {
|
||||
export class HasMany extends Relation {
|
||||
collectionType:any;
|
||||
|
||||
findRelated(options:any):Model;
|
||||
findRelated(options:any):BModel;
|
||||
|
||||
setKeyContents(keyContents:string):void;
|
||||
|
||||
setKeyContents(keyContents:number):void;
|
||||
|
||||
setKeyContents(keyContents:Model):void;
|
||||
setKeyContents(keyContents:BModel):void;
|
||||
|
||||
onChange(model:Model, attr:any, options:any):void;
|
||||
onChange(model:BModel, attr:any, options:any):void;
|
||||
|
||||
tryAddRelated(model:Model, coll:any, options:any):void;
|
||||
tryAddRelated(model:BModel, coll:any, options:any):void;
|
||||
|
||||
addRelated(model:Model, options:any):void;
|
||||
addRelated(model:BModel, options:any):void;
|
||||
|
||||
removeRelated(model:Model, coll:any, options:any):void;
|
||||
removeRelated(model:BModel, coll:any, options:any):void;
|
||||
|
||||
}
|
||||
|
||||
@@ -141,9 +142,9 @@ declare module 'backbone' {
|
||||
|
||||
removeModelScope(scope):void;
|
||||
|
||||
addSubModels(subModelTypes:RelationalModel, superModelType:RelationalModel):void;
|
||||
addSubModels(subModelTypes:Model, superModelType:Model):void;
|
||||
|
||||
setupSuperModel(modelType:RelationalModel):void;
|
||||
setupSuperModel(modelType:Model):void;
|
||||
|
||||
addReverseRelation(relation:any):void;
|
||||
|
||||
@@ -151,30 +152,30 @@ declare module 'backbone' {
|
||||
|
||||
processOrphanRelations():void;
|
||||
|
||||
retroFitRelation(relation:RelationalModel, create:boolean):Collection<Model>;
|
||||
retroFitRelation(relation:Model, create:boolean):Collection<BModel>;
|
||||
|
||||
getCollection(type:RelationalModel, create:boolean):Collection<Model>;
|
||||
getCollection(type:Model, create:boolean):Collection<BModel>;
|
||||
|
||||
getObjectByName(name:string):any;
|
||||
|
||||
|
||||
resolveIdForItem(type:any, item:any):any;
|
||||
|
||||
static find(type:any, item:string):RelationalModel;
|
||||
static find(type:any, item:string):Model;
|
||||
|
||||
static find(type:any, item:number):RelationalModel;
|
||||
static find(type:any, item:number):Model;
|
||||
|
||||
static find(type:any, item:RelationalModel):RelationalModel;
|
||||
static find(type:any, item:Model):Model;
|
||||
|
||||
static find(type:any, item:any):RelationalModel;
|
||||
static find(type:any, item:any):Model;
|
||||
|
||||
register(model:RelationalModel):void;
|
||||
register(model:Model):void;
|
||||
|
||||
checkId(model:RelationalModel, id:any):void;
|
||||
checkId(model:Model, id:any):void;
|
||||
|
||||
update(model:RelationalModel):void;
|
||||
update(model:Model):void;
|
||||
|
||||
unregister(model:RelationalModel, collection:Collection<Model>, options:any):void;
|
||||
unregister(model:Model, collection:Collection<BModel>, options:any):void;
|
||||
|
||||
reset():void;
|
||||
|
||||
|
||||
Vendored
+19
@@ -228,6 +228,25 @@ declare namespace Bull {
|
||||
* Takes a lock for this job so that no other queue worker can process it at the same time.
|
||||
*/
|
||||
takeLock(): Promise<number | false>;
|
||||
|
||||
/**
|
||||
* Get job properties as Json Object
|
||||
*/
|
||||
toJSON(): {
|
||||
id: JobId,
|
||||
name: string,
|
||||
data: T,
|
||||
opts: JobOptions,
|
||||
progress: number,
|
||||
delay: number,
|
||||
timestamp: number,
|
||||
attemptsMade: number,
|
||||
failedReason: any,
|
||||
stacktrace: string[] | null,
|
||||
returnvalue: any,
|
||||
finishedOn: number | null,
|
||||
processedOn: number | null
|
||||
};
|
||||
}
|
||||
|
||||
type JobStatus = 'completed' | 'waiting' | 'active' | 'delayed' | 'failed';
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
import bunyanSeq = require("bunyan-seq");
|
||||
bunyanSeq.createStream({name: 'LoggerComponent', serverUrl: 'http://seq.com'});
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// Type definitions for bunyan-blackhole 0.2
|
||||
// Project: https://github.com/datalust/bunyan-seq
|
||||
// Definitions by: Ray Booysen <https://github.com/raybooysen>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as Logger from "bunyan";
|
||||
export interface Configuration {
|
||||
apiKey?: string;
|
||||
batchSizeLimit?: number;
|
||||
eventSizeLimit?: number;
|
||||
level?: string;
|
||||
maxBatchingTime?: number;
|
||||
name?: string;
|
||||
onError?: (e: Error) => void;
|
||||
reemitErrorEvents?: boolean;
|
||||
serverUrl?: string;
|
||||
}
|
||||
|
||||
export function createStream(config: Configuration): Logger.Stream;
|
||||
@@ -18,6 +18,6 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"fastify-cors-tests.ts"
|
||||
"bunyan-seq-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { rgba } from "@carbon/colors";
|
||||
|
||||
rgba("TOTORO", 0.4); // $ExpectType string
|
||||
Vendored
+491
@@ -0,0 +1,491 @@
|
||||
// Type definitions for @carbon/colors 0.0
|
||||
// Project: https://github.com/IBM/carbon-elements/tree/master/packages/colors
|
||||
// Definitions by: Vince Picone <https://github.com/vpicone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export const black: string;
|
||||
|
||||
export const black100: string;
|
||||
|
||||
export const blue: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const blue10: string;
|
||||
|
||||
export const blue100: string;
|
||||
|
||||
export const blue20: string;
|
||||
|
||||
export const blue30: string;
|
||||
|
||||
export const blue40: string;
|
||||
|
||||
export const blue50: string;
|
||||
|
||||
export const blue60: string;
|
||||
|
||||
export const blue70: string;
|
||||
|
||||
export const blue80: string;
|
||||
|
||||
export const blue90: string;
|
||||
|
||||
export const colors: {
|
||||
black: {
|
||||
"100": string;
|
||||
};
|
||||
blue: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
coolGray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
cyan: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
gray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
green: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
magenta: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
orange: {
|
||||
"40": string;
|
||||
};
|
||||
purple: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
red: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
teal: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
warmGray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
white: {
|
||||
"0": string;
|
||||
};
|
||||
yellow: {
|
||||
"20": string;
|
||||
};
|
||||
};
|
||||
|
||||
export const coolGray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const coolGray10: string;
|
||||
|
||||
export const coolGray100: string;
|
||||
|
||||
export const coolGray20: string;
|
||||
|
||||
export const coolGray30: string;
|
||||
|
||||
export const coolGray40: string;
|
||||
|
||||
export const coolGray50: string;
|
||||
|
||||
export const coolGray60: string;
|
||||
|
||||
export const coolGray70: string;
|
||||
|
||||
export const coolGray80: string;
|
||||
|
||||
export const coolGray90: string;
|
||||
|
||||
export const cyan: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const cyan10: string;
|
||||
|
||||
export const cyan100: string;
|
||||
|
||||
export const cyan20: string;
|
||||
|
||||
export const cyan30: string;
|
||||
|
||||
export const cyan40: string;
|
||||
|
||||
export const cyan50: string;
|
||||
|
||||
export const cyan60: string;
|
||||
|
||||
export const cyan70: string;
|
||||
|
||||
export const cyan80: string;
|
||||
|
||||
export const cyan90: string;
|
||||
|
||||
export const gray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const gray10: string;
|
||||
|
||||
export const gray100: string;
|
||||
|
||||
export const gray20: string;
|
||||
|
||||
export const gray30: string;
|
||||
|
||||
export const gray40: string;
|
||||
|
||||
export const gray50: string;
|
||||
|
||||
export const gray60: string;
|
||||
|
||||
export const gray70: string;
|
||||
|
||||
export const gray80: string;
|
||||
|
||||
export const gray90: string;
|
||||
|
||||
export const green: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const green10: string;
|
||||
|
||||
export const green100: string;
|
||||
|
||||
export const green20: string;
|
||||
|
||||
export const green30: string;
|
||||
|
||||
export const green40: string;
|
||||
|
||||
export const green50: string;
|
||||
|
||||
export const green60: string;
|
||||
|
||||
export const green70: string;
|
||||
|
||||
export const green80: string;
|
||||
|
||||
export const green90: string;
|
||||
|
||||
export const magenta: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const magenta10: string;
|
||||
|
||||
export const magenta100: string;
|
||||
|
||||
export const magenta20: string;
|
||||
|
||||
export const magenta30: string;
|
||||
|
||||
export const magenta40: string;
|
||||
|
||||
export const magenta50: string;
|
||||
|
||||
export const magenta60: string;
|
||||
|
||||
export const magenta70: string;
|
||||
|
||||
export const magenta80: string;
|
||||
|
||||
export const magenta90: string;
|
||||
|
||||
export const orange: string;
|
||||
|
||||
export const orange40: string;
|
||||
|
||||
export const purple: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const purple10: string;
|
||||
|
||||
export const purple100: string;
|
||||
|
||||
export const purple20: string;
|
||||
|
||||
export const purple30: string;
|
||||
|
||||
export const purple40: string;
|
||||
|
||||
export const purple50: string;
|
||||
|
||||
export const purple60: string;
|
||||
|
||||
export const purple70: string;
|
||||
|
||||
export const purple80: string;
|
||||
|
||||
export const purple90: string;
|
||||
|
||||
export const red: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const red10: string;
|
||||
|
||||
export const red100: string;
|
||||
|
||||
export const red20: string;
|
||||
|
||||
export const red30: string;
|
||||
|
||||
export const red40: string;
|
||||
|
||||
export const red50: string;
|
||||
|
||||
export const red60: string;
|
||||
|
||||
export const red70: string;
|
||||
|
||||
export const red80: string;
|
||||
|
||||
export const red90: string;
|
||||
|
||||
export const teal: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const teal10: string;
|
||||
|
||||
export const teal100: string;
|
||||
|
||||
export const teal20: string;
|
||||
|
||||
export const teal30: string;
|
||||
|
||||
export const teal40: string;
|
||||
|
||||
export const teal50: string;
|
||||
|
||||
export const teal60: string;
|
||||
|
||||
export const teal70: string;
|
||||
|
||||
export const teal80: string;
|
||||
|
||||
export const teal90: string;
|
||||
|
||||
export const warmGray: {
|
||||
"10": string;
|
||||
"100": string;
|
||||
"20": string;
|
||||
"30": string;
|
||||
"40": string;
|
||||
"50": string;
|
||||
"60": string;
|
||||
"70": string;
|
||||
"80": string;
|
||||
"90": string;
|
||||
};
|
||||
|
||||
export const warmGray10: string;
|
||||
|
||||
export const warmGray100: string;
|
||||
|
||||
export const warmGray20: string;
|
||||
|
||||
export const warmGray30: string;
|
||||
|
||||
export const warmGray40: string;
|
||||
|
||||
export const warmGray50: string;
|
||||
|
||||
export const warmGray60: string;
|
||||
|
||||
export const warmGray70: string;
|
||||
|
||||
export const warmGray80: string;
|
||||
|
||||
export const warmGray90: string;
|
||||
|
||||
export const white: string;
|
||||
|
||||
export const white0: string;
|
||||
|
||||
export const yellow: string;
|
||||
|
||||
export const yellow20: string;
|
||||
|
||||
export function rgba(hexcode: string, opacity: number): string;
|
||||
|
||||
export namespace rgba {
|
||||
const prototype: {};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true,
|
||||
"paths": {
|
||||
"@carbon/colors": ["carbon__colors"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "carbon__colors-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
rem,
|
||||
em,
|
||||
px,
|
||||
breakpoint,
|
||||
breakpoints,
|
||||
breakpointDown,
|
||||
breakpointUp,
|
||||
baseFontSize
|
||||
} from "@carbon/layout";
|
||||
|
||||
const firstBreakpoint = Object.keys(breakpoints)[0];
|
||||
|
||||
rem(baseFontSize); // $ExpectType string
|
||||
em(baseFontSize); // $ExpectType string
|
||||
px(baseFontSize); // $ExpectType string
|
||||
|
||||
breakpoint(firstBreakpoint); // $ExpectType string
|
||||
breakpointUp(firstBreakpoint); // $ExpectType string
|
||||
breakpointDown(firstBreakpoint); // $ExpectType string
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
// Type definitions for @carbon/layout 0.0
|
||||
// Project: https://github.com/IBM/carbon-elements/tree/master/packages/layout
|
||||
// Definitions by: Vince Picone <https://github.com/vpicone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export const baseFontSize: number;
|
||||
|
||||
export const breakpoints: {
|
||||
lg: {
|
||||
columns: number;
|
||||
margin: string;
|
||||
width: string;
|
||||
};
|
||||
max: {
|
||||
columns: number;
|
||||
margin: string;
|
||||
width: string;
|
||||
};
|
||||
md: {
|
||||
columns: number;
|
||||
margin: string;
|
||||
width: string;
|
||||
};
|
||||
sm: {
|
||||
columns: number;
|
||||
margin: string;
|
||||
width: string;
|
||||
};
|
||||
xlg: {
|
||||
columns: number;
|
||||
margin: string;
|
||||
width: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const miniUnit: number;
|
||||
|
||||
export const spacing: number[];
|
||||
|
||||
export function breakpoint(...args: any[]): string;
|
||||
|
||||
export function breakpointDown(name: string): string;
|
||||
|
||||
export function breakpointUp(name: string): string;
|
||||
|
||||
export function em(px: number): string;
|
||||
|
||||
export function miniUnits(count: number): string;
|
||||
|
||||
export function px(value: number): string;
|
||||
|
||||
export function rem(px: number): string;
|
||||
|
||||
export namespace breakpoint {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace breakpointDown {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace breakpointUp {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace em {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace miniUnits {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace px {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace rem {
|
||||
const prototype: {};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@carbon/layout": ["carbon__layout"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "carbon__layout-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,8 @@
|
||||
import { easings, motion } from "@carbon/motion";
|
||||
|
||||
const easingNames = Object.keys(easings);
|
||||
|
||||
const firstEasing = easingNames[0];
|
||||
const firstMode = Object.keys(firstEasing)[0];
|
||||
|
||||
motion(firstEasing, firstMode);
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// Type definitions for @carbon/motion 0.0
|
||||
// Project: https://github.com/IBM/carbon-elements/tree/master/packages/motion
|
||||
// Definitions by: Vince Picone <https://github.com/vpicone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export const easings: {
|
||||
entrance: {
|
||||
expressive: string;
|
||||
productive: string;
|
||||
};
|
||||
exit: {
|
||||
expressive: string;
|
||||
productive: string;
|
||||
};
|
||||
standard: {
|
||||
expressive: string;
|
||||
productive: string;
|
||||
};
|
||||
};
|
||||
|
||||
export function motion(name: string, mode: string): string;
|
||||
|
||||
export namespace motion {
|
||||
const prototype: {};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@carbon/motion": ["carbon__motion"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "carbon__motion-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,59 @@
|
||||
import ThemePackage from "@carbon/themes";
|
||||
|
||||
interface Theme {
|
||||
active01: string;
|
||||
activeDanger: string;
|
||||
activePrimary: string;
|
||||
activeSecondary: string;
|
||||
activeTertiary: string;
|
||||
activeUI: string;
|
||||
brand01: string;
|
||||
brand02: string;
|
||||
brand03: string;
|
||||
disabled01: string;
|
||||
disabled02: string;
|
||||
disabled03: string;
|
||||
field01: string;
|
||||
field02: string;
|
||||
focus: string;
|
||||
highlight: string;
|
||||
hoverDanger: string;
|
||||
hoverField: string;
|
||||
hoverPrimary: string;
|
||||
hoverPrimaryText: string;
|
||||
hoverRow: string;
|
||||
hoverSecondary: string;
|
||||
hoverSelectedUI: string;
|
||||
hoverTertiary: string;
|
||||
hoverUI: string;
|
||||
icon01: string;
|
||||
icon02: string;
|
||||
interactive01: string;
|
||||
interactive02: string;
|
||||
interactive03: string;
|
||||
inverse01: string;
|
||||
inverse02: string;
|
||||
overlay01: string;
|
||||
selectedUI: string;
|
||||
support01: string;
|
||||
support02: string;
|
||||
support03: string;
|
||||
support04: string;
|
||||
text01: string;
|
||||
text02: string;
|
||||
text03: string;
|
||||
text04: string;
|
||||
ui01: string;
|
||||
ui02: string;
|
||||
ui03: string;
|
||||
ui04: string;
|
||||
ui05: string;
|
||||
uiBackground: string;
|
||||
visitedLink: string;
|
||||
}
|
||||
|
||||
const getDefaultTheme = (): Theme => {
|
||||
return ThemePackage.white;
|
||||
};
|
||||
|
||||
getDefaultTheme();
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
// Type definitions for @carbon/themes 0.0
|
||||
// Project: https://github.com/IBM/carbon-elements/tree/master/packages/themes
|
||||
// Definitions by: Vince Picone <https://github.com/vpicone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export default carbon__themes;
|
||||
|
||||
interface Theme {
|
||||
active01: string;
|
||||
activeDanger: string;
|
||||
activePrimary: string;
|
||||
activeSecondary: string;
|
||||
activeTertiary: string;
|
||||
activeUI: string;
|
||||
brand01: string;
|
||||
brand02: string;
|
||||
brand03: string;
|
||||
disabled01: string;
|
||||
disabled02: string;
|
||||
disabled03: string;
|
||||
field01: string;
|
||||
field02: string;
|
||||
focus: string;
|
||||
highlight: string;
|
||||
hoverDanger: string;
|
||||
hoverField: string;
|
||||
hoverPrimary: string;
|
||||
hoverPrimaryText: string;
|
||||
hoverRow: string;
|
||||
hoverSecondary: string;
|
||||
hoverSelectedUI: string;
|
||||
hoverTertiary: string;
|
||||
hoverUI: string;
|
||||
icon01: string;
|
||||
icon02: string;
|
||||
interactive01: string;
|
||||
interactive02: string;
|
||||
interactive03: string;
|
||||
inverse01: string;
|
||||
inverse02: string;
|
||||
overlay01: string;
|
||||
selectedUI: string;
|
||||
support01: string;
|
||||
support02: string;
|
||||
support03: string;
|
||||
support04: string;
|
||||
text01: string;
|
||||
text02: string;
|
||||
text03: string;
|
||||
text04: string;
|
||||
ui01: string;
|
||||
ui02: string;
|
||||
ui03: string;
|
||||
ui04: string;
|
||||
ui05: string;
|
||||
uiBackground: string;
|
||||
visitedLink: string;
|
||||
}
|
||||
|
||||
// The default theme is included as a top level export
|
||||
type ThemePackage = {
|
||||
white: Theme;
|
||||
g10: Theme;
|
||||
g100: Theme;
|
||||
g90: Theme;
|
||||
themes: {
|
||||
g10: Theme;
|
||||
g100: Theme;
|
||||
g90: Theme;
|
||||
white: Theme;
|
||||
};
|
||||
} & Theme;
|
||||
|
||||
declare const carbon__themes: ThemePackage;
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@carbon/themes": ["carbon__themes"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "carbon__themes-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,6 @@
|
||||
import { fontFamily, fontWeight, getTypeSize, print } from "@carbon/type";
|
||||
|
||||
fontFamily("mono"); // $ExpectType { fontFamily: string; }
|
||||
fontWeight("light"); // $ExpectType { fontWeight: number; }
|
||||
print(fontFamily("mono")); // $ExpectType string
|
||||
getTypeSize(2); // $ExpectType number
|
||||
Vendored
+726
@@ -0,0 +1,726 @@
|
||||
// Type definitions for @carbon/type 0.0
|
||||
// Project: https://github.com/IBM/carbon-elements/tree/master/packages/type
|
||||
// Definitions by: Vince Picone <https://github.com/vpicone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export const bodyLong01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const bodyLong02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const bodyShort01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const bodyShort02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const caption01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const code01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const code02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const display01: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const display02: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const display03: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const display04: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const expressiveHeading04: {
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const expressiveHeading05: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const expressiveParagraph01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lg: {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
lineHeight: string;
|
||||
max: {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const fontFamilies: {
|
||||
mono: string;
|
||||
sans: string;
|
||||
sansCondensed: string;
|
||||
sansHebrew: string;
|
||||
serif: string;
|
||||
};
|
||||
|
||||
export const fontWeights: {
|
||||
light: number;
|
||||
regular: number;
|
||||
semibold: number;
|
||||
};
|
||||
|
||||
export const heading01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const heading02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const heading03: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const helperText01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontStyle: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const label01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const productiveHeading04: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const productiveHeading05: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const quotation01: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const quotation02: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
|
||||
export const reset: {
|
||||
body: {
|
||||
"-moz-osx-font-smoothing": string;
|
||||
"-webkit-font-smoothing": string;
|
||||
fontFamily: string;
|
||||
fontWeight: number;
|
||||
textRendering: string;
|
||||
};
|
||||
html: {
|
||||
fontSize: string;
|
||||
};
|
||||
strong: {
|
||||
fontWeight: number;
|
||||
};
|
||||
};
|
||||
|
||||
export const scale: number[];
|
||||
|
||||
export const spacing: {
|
||||
layout01: string;
|
||||
layout02: string;
|
||||
layout03: string;
|
||||
margin01: string;
|
||||
margin02: string;
|
||||
margin03: string;
|
||||
};
|
||||
|
||||
export const styles: {
|
||||
bodyLong01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
bodyLong02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
bodyShort01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
bodyShort02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
caption01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
code01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
code02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
display01: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
display02: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
display03: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
display04: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
expressiveHeading04: {
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
expressiveHeading05: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
expressiveParagraph01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lg: {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
lineHeight: string;
|
||||
max: {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
};
|
||||
heading01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
heading02: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
heading03: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
helperText01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontStyle: string;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
label01: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
productiveHeading04: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
productiveHeading05: {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
quotation01: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
quotation02: {
|
||||
"@media (min-width: 42rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 66rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 82rem)": {
|
||||
fontSize: string;
|
||||
lineHeight: string;
|
||||
};
|
||||
"@media (min-width: 99rem)": {
|
||||
fontSize: string;
|
||||
};
|
||||
fontFamily: string;
|
||||
fontSize: string;
|
||||
fontWeight: number;
|
||||
letterSpacing: number;
|
||||
lineHeight: string;
|
||||
};
|
||||
};
|
||||
|
||||
export function fontFamily(
|
||||
name: string
|
||||
): {
|
||||
fontFamily: string;
|
||||
};
|
||||
|
||||
export function fontWeight(
|
||||
weight: string
|
||||
): {
|
||||
fontWeight: number;
|
||||
};
|
||||
|
||||
export function getTypeSize(step: number): number;
|
||||
|
||||
export function print(block: object): string;
|
||||
|
||||
export namespace fontFamily {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace fontWeight {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace getTypeSize {
|
||||
const prototype: {};
|
||||
}
|
||||
|
||||
export namespace print {
|
||||
const prototype: {};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@carbon/type": ["carbon__type"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "carbon__type-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -102,3 +102,35 @@ const mapper = new cassandra.mapping.Mapper(
|
||||
const videoMapper = mapper.forModel('Video');
|
||||
videoMapper.insert({ videoId: 'uuid', addedDate: new Date(), userId: 'uuid', name: 'My video', description: 'My desc' });
|
||||
videoMapper.find({ videoId: 'uuid' }).then(results => results.first());
|
||||
|
||||
console.log(cassandra.version);
|
||||
|
||||
const metadata = new cassandra.metadata.Metadata(cassandra.defaultOptions(), undefined);
|
||||
let refreshFinished: Promise<void> = metadata.refreshKeyspaces();
|
||||
refreshFinished = metadata.refreshKeyspaces(true);
|
||||
metadata.refreshKeyspaces(() => {});
|
||||
metadata.refreshKeyspaces(true, () => {});
|
||||
|
||||
const start: cassandra.token.Token = new cassandra.token.Token("x");
|
||||
const end: cassandra.token.Token = new cassandra.token.Token("z");
|
||||
|
||||
const tokenizer: cassandra.token.Tokenizer = {
|
||||
hash: (value: Buffer | number[]) => new cassandra.token.Token("x"),
|
||||
parse: (value: string) => new cassandra.token.Token("x"),
|
||||
minToken: () => new cassandra.token.Token("x"),
|
||||
split: (start: cassandra.token.Token, end: cassandra.token.Token, numberOfSplits: number) => [],
|
||||
splitBase: (start: number, end: number, ringEnd: number, ringLength: number, numberOfSplits: number): number[] => [1],
|
||||
stringify: (token: cassandra.token.Token): string => "asd"
|
||||
};
|
||||
|
||||
const range: cassandra.token.TokenRange = new cassandra.token.TokenRange(start, end, tokenizer);
|
||||
|
||||
class MyLoadBalancingPolicy extends cassandra.policies.loadBalancing.LoadBalancingPolicy {
|
||||
getDistance() {
|
||||
return cassandra.types.distance.ignored;
|
||||
}
|
||||
}
|
||||
|
||||
const myPolicy: cassandra.policies.loadBalancing.LoadBalancingPolicy = new MyLoadBalancingPolicy();
|
||||
let existingPolicy: cassandra.policies.loadBalancing.LoadBalancingPolicy = new cassandra.policies.loadBalancing.DCAwareRoundRobinPolicy();
|
||||
existingPolicy = new cassandra.policies.loadBalancing.DCAwareRoundRobinPolicy("dc");
|
||||
|
||||
Vendored
+91
-79
@@ -34,43 +34,29 @@ export namespace policies {
|
||||
}
|
||||
|
||||
namespace loadBalancing {
|
||||
let DCAwareRoundRobinPolicy: DCAwareRoundRobinPolicyStatic;
|
||||
let RoundRobinPolicy: RoundRobinPolicyStatic;
|
||||
let TokenAwarePolicy: TokenAwarePolicyStatic;
|
||||
let WhiteListPolicy: WhiteListPolicyStatic;
|
||||
|
||||
interface LoadBalancingPolicy {
|
||||
class LoadBalancingPolicy {
|
||||
init(client: Client, hosts: HostMap, callback: Callback): void;
|
||||
getDistance(host: Host): types.distance;
|
||||
newQueryPlan(keyspace: string, queryOptions: ExecutionOptions | null, callback: Callback): void;
|
||||
getOptions(): Map<string, any>;
|
||||
}
|
||||
|
||||
interface DCAwareRoundRobinPolicyStatic {
|
||||
new (localDc?: string): DCAwareRoundRobinPolicy;
|
||||
}
|
||||
|
||||
interface DCAwareRoundRobinPolicy extends LoadBalancingPolicy {
|
||||
class DCAwareRoundRobinPolicy extends LoadBalancingPolicy {
|
||||
localDc: string;
|
||||
localHostsArray: Host[];
|
||||
remoteHostsArray: Host[];
|
||||
|
||||
constructor(localDc?: string);
|
||||
}
|
||||
|
||||
interface RoundRobinPolicyStatic {
|
||||
new (): RoundRobinPolicy;
|
||||
class RoundRobinPolicy extends LoadBalancingPolicy {}
|
||||
|
||||
class TokenAwarePolicy extends LoadBalancingPolicy {
|
||||
constructor(childPolicy: LoadBalancingPolicy);
|
||||
}
|
||||
|
||||
interface RoundRobinPolicy extends LoadBalancingPolicy { }
|
||||
|
||||
interface TokenAwarePolicyStatic {
|
||||
new (childPolicy: LoadBalancingPolicy): TokenAwarePolicy;
|
||||
class WhiteListPolicy extends LoadBalancingPolicy {
|
||||
constructor(childPolicy: LoadBalancingPolicy, whiteList: string[]);
|
||||
}
|
||||
|
||||
interface TokenAwarePolicy extends LoadBalancingPolicy { }
|
||||
|
||||
interface WhiteListPolicyStatic {
|
||||
new (childPolicy: LoadBalancingPolicy, whiteList: string[]): WhiteListPolicy;
|
||||
}
|
||||
|
||||
interface WhiteListPolicy extends LoadBalancingPolicy { }
|
||||
}
|
||||
|
||||
namespace reconnection {
|
||||
@@ -499,8 +485,6 @@ export namespace types {
|
||||
}
|
||||
|
||||
export let Client: ClientStatic;
|
||||
export let Host: HostStatic;
|
||||
export let HostMap: HostMapStatic;
|
||||
export let Encoder: EncoderStatic;
|
||||
|
||||
export interface ClientOptions {
|
||||
@@ -611,14 +595,10 @@ export interface Client extends events.EventEmitter {
|
||||
stream(query: string, params?: any, options?: QueryOptions, callback?: Callback): NodeJS.ReadableStream;
|
||||
}
|
||||
|
||||
export interface HostStatic {
|
||||
new (address: string, protocolVersion: number, options: ClientOptions): Host;
|
||||
}
|
||||
|
||||
export interface Host extends events.EventEmitter {
|
||||
address: string;
|
||||
cassandraVersion: string;
|
||||
dataCenter: string;
|
||||
datacenter: string;
|
||||
rack: string;
|
||||
tokens: string[];
|
||||
|
||||
@@ -627,10 +607,6 @@ export interface Host extends events.EventEmitter {
|
||||
isUp(): boolean;
|
||||
}
|
||||
|
||||
export interface HostMapStatic {
|
||||
new (): HostMap;
|
||||
}
|
||||
|
||||
export interface HostMap extends events.EventEmitter {
|
||||
length: number;
|
||||
|
||||
@@ -742,19 +718,10 @@ export namespace errors {
|
||||
}
|
||||
|
||||
export namespace metadata {
|
||||
let Aggregate: AggregateStatic;
|
||||
let Index: IndexStatic;
|
||||
let MaterializedView: MaterializedViewStatic;
|
||||
let Metadata: MetadataStatic;
|
||||
let SchemaFunction: SchemaFunctionStatic;
|
||||
let TableMetadata: TableMetadataStatic;
|
||||
|
||||
type caching = "all" | "keys_only" | "rows_only" | "none";
|
||||
|
||||
interface AggregateStatic {
|
||||
new (): Aggregate;
|
||||
}
|
||||
|
||||
interface Aggregate {
|
||||
argumentTypes: Array<{ code: number, info: any }>;
|
||||
finalFunction: string;
|
||||
@@ -766,10 +733,6 @@ export namespace metadata {
|
||||
stateType: string;
|
||||
}
|
||||
|
||||
interface ClientStateStatic {
|
||||
new (): ClientState;
|
||||
}
|
||||
|
||||
interface ClientState {
|
||||
getConnectedHosts(): Host[];
|
||||
getInFlightQueries(host: Host): number;
|
||||
@@ -822,13 +785,6 @@ export namespace metadata {
|
||||
composites
|
||||
}
|
||||
|
||||
interface IndexStatic {
|
||||
new (name: string, target: string, kind: string | IndexType, options: object): Index;
|
||||
|
||||
fromRows(indexRows: types.Row[]): Index[];
|
||||
fromColumnRows(columnRows: types.Row[], columnsByName: { [key: string]: ColumnInfo }): Index[];
|
||||
}
|
||||
|
||||
interface Index {
|
||||
kind: IndexType;
|
||||
name: string;
|
||||
@@ -840,11 +796,19 @@ export namespace metadata {
|
||||
isKeysKind(): boolean;
|
||||
}
|
||||
|
||||
interface MaterializedViewStatic {
|
||||
new (name: string): MaterializedView;
|
||||
interface MaterializedView extends DataCollection { }
|
||||
|
||||
interface QueryTrace {
|
||||
requestType: any;
|
||||
coordinator: any;
|
||||
parameters: any;
|
||||
startedAt: any;
|
||||
duration: any;
|
||||
clientAddress: any;
|
||||
events: Array<{ id: any; activity: any; source: any; elapsed: any; thread: any }>;
|
||||
}
|
||||
|
||||
interface MaterializedView extends DataCollection { }
|
||||
type MetadataCallback<T> = (err: any, retVal: T) => void;
|
||||
|
||||
interface MetadataStatic {
|
||||
new (options: ClientOptions, controlConnection: any): Metadata;
|
||||
@@ -853,21 +817,34 @@ export namespace metadata {
|
||||
interface Metadata {
|
||||
clearPrepared(): void;
|
||||
|
||||
getAggregate(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: Callback): void;
|
||||
getAggregates(keyspaceName: string, name: string, callback: Callback): void;
|
||||
getFunction(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: Callback): void;
|
||||
getFunctions(keyspaceName: string, name: string, callback: Callback): void;
|
||||
getMaterializedView(keyspaceName: string, name: string, callback: Callback): void;
|
||||
getReplicas(keyspaceName: string, tokenBuffer: Buffer): any[];
|
||||
getTable(keyspaceName: string, name: string, callback: Callback): void;
|
||||
getTrace(traceId: types.Uuid, callback: Callback): void;
|
||||
getUdt(keyspaceName: string, name: string, callback: Callback): void;
|
||||
refreshKeyspace(name: string, callback?: Callback): void;
|
||||
refreshKeyspaces(callback?: Callback): void;
|
||||
}
|
||||
|
||||
interface SchemaFunctionStatic {
|
||||
new (): SchemaFunction;
|
||||
getAggregate(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: MetadataCallback<Aggregate>): void;
|
||||
getAggregate(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>): Promise<Aggregate>;
|
||||
getAggregates(keyspaceName: string, name: string, callback: MetadataCallback<Aggregate[]>): void;
|
||||
getAggregates(keyspaceName: string, name: string): Promise<Aggregate[]>;
|
||||
getFunction(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>, callback: MetadataCallback<SchemaFunction>): void;
|
||||
getFunction(keyspaceName: string, name: string, signature: string[] | Array<{ code: number, info: any }>): Promise<SchemaFunction>;
|
||||
getFunctions(keyspaceName: string, name: string, callback: MetadataCallback<SchemaFunction[]>): void;
|
||||
getFunctions(keyspaceName: string, name: string): Promise<SchemaFunction[]>;
|
||||
getMaterializedView(keyspaceName: string, name: string, callback: MetadataCallback<MaterializedView>): void;
|
||||
getMaterializedView(keyspaceName: string, name: string, callback: Callback): Promise<MaterializedView>;
|
||||
getReplicas(keyspaceName: string, token: Buffer | token.Token | token.TokenRange): any[]; // TODO
|
||||
getTable(keyspaceName: string, name: string, callback: MetadataCallback<TableMetadata>): void;
|
||||
getTable(keyspaceName: string, name: string): Promise<TableMetadata>;
|
||||
getTokenRanges(): Set<token.TokenRange>;
|
||||
getTokenRangesForHost(keyspaceName: string, host: Host): Set<token.TokenRange> | null;
|
||||
getTrace(traceId: types.Uuid, consistency: types.consistencies, callback: MetadataCallback<QueryTrace>): void;
|
||||
getTrace(traceId: types.Uuid, consistency: types.consistencies, callback: Callback): Promise<QueryTrace>;
|
||||
getTrace(traceId: types.Uuid, callback: MetadataCallback<QueryTrace>): void;
|
||||
getTrace(traceId: types.Uuid): Promise<QueryTrace>;
|
||||
getUdt(keyspaceName: string, name: string, callback: MetadataCallback<any>): void; // TODO
|
||||
getUdt(keyspaceName: string, name: string): Promise<any>; // TODO
|
||||
newToken(components: Buffer[] | Buffer | string): token.Token;
|
||||
newTokenRange(start: token.Token, end: token.Token): token.TokenRange;
|
||||
refreshKeyspace(name: string, callback: Callback): void;
|
||||
refreshKeyspace(name: string): Promise<void>;
|
||||
refreshKeyspaces(waitReconnect: boolean, callback: Callback): void;
|
||||
refreshKeyspaces(waitReconnect?: boolean): Promise<void>;
|
||||
refreshKeyspaces(callback: Callback): void;
|
||||
}
|
||||
|
||||
interface SchemaFunction {
|
||||
@@ -882,10 +859,6 @@ export namespace metadata {
|
||||
signature: string[];
|
||||
}
|
||||
|
||||
interface TableMetadataStatic {
|
||||
new (name: string): TableMetadata;
|
||||
}
|
||||
|
||||
interface TableMetadata extends DataCollection {
|
||||
indexes: Index[];
|
||||
indexInterval?: number;
|
||||
@@ -927,6 +900,7 @@ export interface ExecutionOptions {
|
||||
}
|
||||
|
||||
export let ExecutionOptions: ExecutionOptionsStatic;
|
||||
export let ExecutionProfile: ExecutionProfileStatic;
|
||||
|
||||
export namespace mapping {
|
||||
let Mapper: MapperStatic;
|
||||
@@ -1136,3 +1110,41 @@ export namespace metrics {
|
||||
}
|
||||
interface DefaultMetrics extends ClientMetrics {}
|
||||
}
|
||||
|
||||
export namespace token {
|
||||
interface Tokenizer {
|
||||
hash(value: Buffer | number[]): Token;
|
||||
parse(value: string): Token;
|
||||
minToken(): Token;
|
||||
split(start: Token, end: Token, numberOfSplits: number): TokenRange[];
|
||||
splitBase(start: number, end: number, ringEnd: number, ringLength: number, numberOfSplits: number): number[];
|
||||
stringify(token: Token): string;
|
||||
}
|
||||
|
||||
class Token {
|
||||
constructor(value: any);
|
||||
|
||||
getType(): { code: number, info: any };
|
||||
getValue(): any;
|
||||
compare(other: Token): number;
|
||||
equals(other: Token): boolean;
|
||||
}
|
||||
|
||||
class TokenRange {
|
||||
start: Token;
|
||||
end: Token;
|
||||
|
||||
constructor(start: Token, end: Token, tokenizer: Tokenizer);
|
||||
|
||||
splitEvenly(numberOfSplits: number): TokenRange[];
|
||||
isEmpty(): boolean;
|
||||
isWrappedAround(): boolean;
|
||||
unwrap(): TokenRange[];
|
||||
contains(token: Token): boolean;
|
||||
equals(other: TokenRange): boolean;
|
||||
compare(other: TokenRange): number;
|
||||
}
|
||||
}
|
||||
|
||||
export function defaultOptions(): ClientOptions;
|
||||
export const version: string;
|
||||
|
||||
Vendored
+1
@@ -417,6 +417,7 @@ declare namespace Chart {
|
||||
}
|
||||
|
||||
interface ChartLineOptions {
|
||||
cubicInterpolationMode?: 'default' | 'monotone';
|
||||
tension?: number;
|
||||
backgroundColor?: ChartColor;
|
||||
borderWidth?: number;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import colorSupport = require('color-support');
|
||||
|
||||
(() => {
|
||||
const result = colorSupport();
|
||||
if (!result) {
|
||||
console.log('color is not supported');
|
||||
} else if (result.has16m) {
|
||||
console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m');
|
||||
} else if (result.has256) {
|
||||
console.log('\x1b[38;5;119m256 colors\x1b[0m');
|
||||
} else if (result.hasBasic) {
|
||||
console.log('\x1b[31mbasic colors\x1b[0m');
|
||||
} else {
|
||||
console.log('Level: ', result.level);
|
||||
console.log('this is impossible, but colors are not supported');
|
||||
}
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const result = colorSupport({
|
||||
alwaysReturn: false,
|
||||
env: process.env,
|
||||
ignoreCI: true,
|
||||
ignoreDumb: true,
|
||||
ignoreTTY: true,
|
||||
level: 2,
|
||||
stream: process.stdout,
|
||||
term: process.env.TERM,
|
||||
}, {
|
||||
has16m: false,
|
||||
has256: false,
|
||||
hasBasic: false,
|
||||
level: 0,
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
console.log('color is not supported');
|
||||
} else if (result.has16m) {
|
||||
console.log('\x1b[38;2;102;194;255m16m colors\x1b[0m');
|
||||
} else if (result.has256) {
|
||||
console.log('\x1b[38;5;119m256 colors\x1b[0m');
|
||||
} else if (result.hasBasic) {
|
||||
console.log('\x1b[31mbasic colors\x1b[0m');
|
||||
} else {
|
||||
console.log('Level: ', result.level);
|
||||
console.log('this is impossible, but colors are not supported');
|
||||
}
|
||||
})();
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// Type definitions for color-support 1.1
|
||||
// Project: https://github.com/isaacs/color-support#readme
|
||||
// Definitions by: Guketlev Dmitry <https://github.com/Yavanosta>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
type ColorSupportLevel = 0 | 1 | 2 | 3;
|
||||
|
||||
interface ColorSupportOptions {
|
||||
alwaysReturn?: boolean;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
ignoreCI?: boolean;
|
||||
ignoreDumb?: boolean;
|
||||
ignoreTTY?: boolean;
|
||||
level?: ColorSupportLevel;
|
||||
stream?: NodeJS.WriteStream;
|
||||
term?: string;
|
||||
}
|
||||
|
||||
interface ColorSupportResult {
|
||||
level: ColorSupportLevel;
|
||||
hasBasic: boolean;
|
||||
has256: boolean;
|
||||
has16m: boolean;
|
||||
}
|
||||
|
||||
type ColorSupport = (options?: ColorSupportOptions,
|
||||
obj?: ColorSupportResult) => false | ColorSupportResult;
|
||||
|
||||
declare var colorSupport: ColorSupport;
|
||||
|
||||
export = colorSupport;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"color-support-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -685,6 +685,7 @@ nodeLinkSimulation = nodeLinkSimulation.stop();
|
||||
// tick() -----------------------------------------------------------------------------
|
||||
|
||||
nodeLinkSimulation.tick();
|
||||
nodeLinkSimulation.tick(10);
|
||||
|
||||
// find() -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
Vendored
+11
-5
@@ -1,9 +1,12 @@
|
||||
// Type definitions for D3JS d3-force module 1.1
|
||||
// Type definitions for D3JS d3-force module 1.2
|
||||
// Project: https://github.com/d3/d3-force/
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
|
||||
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
||||
// Alex Ford <https://github.com/gustavderdrache>
|
||||
// Boris Yankov <https://github.com/borisyankov>
|
||||
// denisname <https://github.com/denisname>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// Last module patch version validated against: 1.1.0
|
||||
// Last module patch version validated against: 1.2.0
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Force Simulation
|
||||
@@ -108,13 +111,16 @@ export interface Simulation<NodeDatum extends SimulationNodeDatum, LinkDatum ext
|
||||
stop(): this;
|
||||
|
||||
/**
|
||||
* Increments the current alpha by (alphaTarget - alpha) × alphaDecay; then invokes each registered force, passing the new alpha;
|
||||
* Manually steps the simulation by the specified number of *iterations*, and returns the simulation. If *iterations* is not specified, it defaults to 1 (single step).
|
||||
*
|
||||
* For each iteration, it increments the current alpha by (alphaTarget - alpha) × alphaDecay; then invokes each registered force, passing the new alpha;
|
||||
* then decrements each node’s velocity by velocity × velocityDecay; lastly increments each node’s position by velocity.
|
||||
*
|
||||
* This method does not dispatch events; events are only dispatched by the internal timer when the simulation is started automatically upon
|
||||
* creation or by calling simulation.restart. The natural number of ticks when the simulation is started is
|
||||
* ⌈log(alphaMin) / log(1 - alphaDecay)⌉; by default, this is 300.
|
||||
*/
|
||||
tick(): void;
|
||||
tick(iterations?: number): void;
|
||||
|
||||
/**
|
||||
* Returns the simulation’s array of nodes as specified to the constructor.
|
||||
|
||||
+16
-11
@@ -1,26 +1,31 @@
|
||||
import * as debug1 from "debug";
|
||||
/*tslint:disable-next-line:no-duplicate-imports*/
|
||||
import debug2 from 'debug';
|
||||
|
||||
const log2: debug1.Debugger = debug2("DefinitelyTyped:log");
|
||||
log2("Just text");
|
||||
log2("Formatted test (%d arg)", 1);
|
||||
log2("Formatted %s (%d args)", "test", 2);
|
||||
|
||||
import debug = require("debug");
|
||||
debug1.disable();
|
||||
debug1.enable("DefinitelyTyped:*");
|
||||
|
||||
debug.disable();
|
||||
debug.enable("DefinitelyTyped:*");
|
||||
|
||||
var log:debug.IDebugger = debug("DefinitelyTyped:log");
|
||||
const log: debug1.Debugger = debug1("DefinitelyTyped:log");
|
||||
|
||||
log("Just text");
|
||||
log("Formatted test (%d arg)", 1);
|
||||
log("Formatted %s (%d args)", "test", 2);
|
||||
|
||||
log("Enabled?: %s", debug.enabled("DefinitelyTyped:log"));
|
||||
log("Name Enabled: %s", debug.names.some(name => name.test("DefinitelyTyped:log")));
|
||||
log("Enabled?: %s", debug1.enabled("DefinitelyTyped:log"));
|
||||
log("Name Enabled: %s", debug1.names.some(name => name.test("DefinitelyTyped:log")));
|
||||
log("Namespace: %s", log.namespace);
|
||||
|
||||
var error:debug.IDebugger = debug("DefinitelyTyped:error");
|
||||
const error: debug1.Debugger = debug1("DefinitelyTyped:error");
|
||||
error.log = console.error.bind(console);
|
||||
error("This should be printed to stderr");
|
||||
|
||||
var extendedLog: debug.IDebugger = log.extend('extended');
|
||||
const extendedLog: debug1.Debugger = log.extend('extended');
|
||||
extendedLog("Testing this is also an IDebugger.");
|
||||
|
||||
var extendedWithCustomDelimiter: debug.IDebugger = log.extend('with-delim', '.');
|
||||
extendedWithCustomDelimiter("Testing this is an IDebugger, too.");
|
||||
const extendedWithCustomDelimiter: debug1.Debugger = log.extend('with-delim', '.');
|
||||
extendedWithCustomDelimiter("Testing this is an IDebugger, too.");
|
||||
|
||||
Vendored
+21
-16
@@ -1,40 +1,45 @@
|
||||
// Type definitions for debug
|
||||
// Type definitions for debug 4.1
|
||||
// Project: https://github.com/visionmedia/debug
|
||||
// Definitions by: Seon-Wook Park <https://github.com/swook>
|
||||
// Gal Talmor <https://github.com/galtalmor>
|
||||
// John McLaughlin <https://github.com/zamb3zi>
|
||||
// Brasten Sager <https://github.com/brasten>
|
||||
// Nicolas Penin <https://github.com/npenin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare var debug: debug.IDebug;
|
||||
declare var debug: debug.Debug & {debug: debug.Debug, default: debug.Debug};
|
||||
|
||||
export = debug;
|
||||
export as namespace debug;
|
||||
|
||||
declare namespace debug {
|
||||
export interface IDebug {
|
||||
(namespace: string): debug.IDebugger,
|
||||
coerce: (val: any) => any,
|
||||
disable: () => void,
|
||||
enable: (namespaces: string) => void,
|
||||
enabled: (namespaces: string) => boolean,
|
||||
interface Debug {
|
||||
(namespace: string): Debugger;
|
||||
coerce: (val: any) => any;
|
||||
disable: () => void;
|
||||
enable: (namespaces: string) => void;
|
||||
enabled: (namespaces: string) => boolean;
|
||||
|
||||
names: RegExp[],
|
||||
skips: RegExp[],
|
||||
names: RegExp[];
|
||||
skips: RegExp[];
|
||||
|
||||
formatters: IFormatters
|
||||
formatters: Formatters;
|
||||
}
|
||||
|
||||
export interface IFormatters {
|
||||
[formatter: string]: Function
|
||||
type IDebug = Debug;
|
||||
|
||||
interface Formatters {
|
||||
[formatter: string]: (v: any) => string;
|
||||
}
|
||||
|
||||
export interface IDebugger {
|
||||
type IDebugger = Debugger;
|
||||
|
||||
interface Debugger {
|
||||
(formatter: any, ...args: any[]): void;
|
||||
|
||||
enabled: boolean;
|
||||
log: Function;
|
||||
log: (v: any) => string;
|
||||
namespace: string;
|
||||
extend: (namespace: string, delimiter?: string) => debug.IDebugger;
|
||||
extend: (namespace: string, delimiter?: string) => Debugger;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-77
@@ -1,79 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -176,7 +176,7 @@ export class ec {
|
||||
|
||||
keyPair(options: ec.KeyPairOptions): ec.KeyPair;
|
||||
keyFromPrivate(priv: Buffer | string | ec.KeyPair, enc?: string): ec.KeyPair;
|
||||
keyFromPublic(pub: Buffer | string | ec.KeyPair, enc?: string): ec.KeyPair;
|
||||
keyFromPublic(pub: Buffer | string | {x: string, y: string} | ec.KeyPair, enc?: string): ec.KeyPair;
|
||||
genKeyPair(options?: ec.GenKeyPairOptions): ec.KeyPair;
|
||||
sign(msg: BNInput, key: Buffer | ec.KeyPair, enc: string, options?: ec.SignOptions): ec.Signature;
|
||||
sign(msg: BNInput, key: Buffer | ec.KeyPair, options?: ec.SignOptions): ec.Signature;
|
||||
@@ -201,7 +201,7 @@ export namespace ec {
|
||||
}
|
||||
|
||||
class KeyPair {
|
||||
static fromPublic(ec: ec, pub: Buffer | string | KeyPair, enc?: string): KeyPair;
|
||||
static fromPublic(ec: ec, pub: Buffer | string | {x: string, y: string} | KeyPair, enc?: string): KeyPair;
|
||||
static fromPrivate(ec: ec, priv: Buffer | string | KeyPair, enc?: string): KeyPair;
|
||||
|
||||
ec: ec;
|
||||
|
||||
Vendored
+1
-1
@@ -619,7 +619,7 @@ export class EnzymeAdapter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure enzyme to use the correct adapter for the react verstion
|
||||
* Configure enzyme to use the correct adapter for the react version
|
||||
* This is enabling the Enzyme configuration with adapters in TS
|
||||
*/
|
||||
export function configure(options: {
|
||||
|
||||
@@ -18,7 +18,7 @@ app.use(expressWinston.logger({
|
||||
meta: true,
|
||||
metaField: 'metaField',
|
||||
msg: 'msg',
|
||||
requestFilter: (req, prop) => true,
|
||||
requestFilter: (req, prop) => req[prop],
|
||||
requestWhitelist: ['foo', 'bar'],
|
||||
skip: (req, res) => false,
|
||||
statusLevels: ({ error: 'error', success: 'success', warn: 'warn' }),
|
||||
@@ -69,8 +69,8 @@ app.use(expressWinston.errorLogger({
|
||||
|
||||
expressWinston.bodyBlacklist.push('potato');
|
||||
expressWinston.bodyWhitelist.push('apple');
|
||||
expressWinston.defaultRequestFilter = (req: express.Request, prop: string) => true;
|
||||
expressWinston.defaultResponseFilter = (res: express.Response, prop: string) => true;
|
||||
expressWinston.defaultRequestFilter = (req: expressWinston.FilterRequest, prop: string) => req[prop];
|
||||
expressWinston.defaultResponseFilter = (res: expressWinston.FilterResponse, prop: string) => res[prop];
|
||||
expressWinston.defaultSkip = () => true;
|
||||
expressWinston.ignoredRoutes.push('/ignored');
|
||||
expressWinston.responseWhitelist.push('body');
|
||||
|
||||
Vendored
+10
-2
@@ -8,10 +8,18 @@ import { ErrorRequestHandler, Handler, Request, Response } from 'express';
|
||||
import * as winston from 'winston';
|
||||
import * as Transport from 'winston-transport';
|
||||
|
||||
export interface FilterRequest extends Request {
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
export interface FilterResponse extends Response {
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
export type DynamicMetaFunction = (req: Request, res: Response, err: Error) => object;
|
||||
export type DynamicLevelFunction = (req: Request, res: Response, err: Error) => string;
|
||||
export type RequestFilter = (req: Request, propName: string) => boolean;
|
||||
export type ResponseFilter = (res: Response, propName: string) => boolean;
|
||||
export type RequestFilter = (req: FilterRequest, propName: string) => any;
|
||||
export type ResponseFilter = (res: FilterResponse, propName: string) => any;
|
||||
export type RouteFilter = (req: Request, res: Response) => boolean;
|
||||
|
||||
export interface BaseLoggerOptions {
|
||||
|
||||
Vendored
+19
-1
@@ -3774,7 +3774,18 @@ interface IAllFilters {
|
||||
*/
|
||||
fromObject(object: any): IBrightnessFilter
|
||||
};
|
||||
Convolute: {
|
||||
ColorMatrix: {
|
||||
new(options?: {
|
||||
/** Filter matrix */
|
||||
matrix?: number[]
|
||||
}): IColorMatrix;
|
||||
/**
|
||||
* Returns filter instance from an object representation
|
||||
* @param object Object to create an instance from
|
||||
*/
|
||||
fromObject(object: any): IColorMatrix
|
||||
};
|
||||
Convolute: {
|
||||
new(options?: {
|
||||
opaque?: boolean,
|
||||
/** Filter matrix */
|
||||
@@ -3962,6 +3973,13 @@ interface IBrightnessFilter extends IBaseFilter {
|
||||
*/
|
||||
applyTo(canvasEl: HTMLCanvasElement): void;
|
||||
}
|
||||
interface IColorMatrix extends IBaseFilter {
|
||||
/**
|
||||
* Applies filter to canvas element
|
||||
* @param canvasEl Canvas element to apply filter to
|
||||
*/
|
||||
applyTo(canvasEl: HTMLCanvasElement): void;
|
||||
}
|
||||
interface IConvoluteFilter extends IBaseFilter {
|
||||
/**
|
||||
* Applies filter to canvas element
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import fastifyCors = require("fastify-cors");
|
||||
|
||||
fastifyCors();
|
||||
|
||||
const fastifyCorsOptions: fastifyCors.FastifyCorsOptions = {
|
||||
origin: true,
|
||||
allowedHeaders: "authorization,content-type",
|
||||
methods: "GET,POST,PUT,PATCH,DELETE,OPTIONS",
|
||||
credentials: true,
|
||||
exposedHeaders: "authorization",
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const fastifyCorsOptionsArray: fastifyCors.FastifyCorsOptions = {
|
||||
origin: true,
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const originString: fastifyCors.FastifyCorsOptions = {
|
||||
origin: "*",
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const originRegexp: fastifyCors.FastifyCorsOptions = {
|
||||
origin: /\*/,
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const originStringArray: fastifyCors.FastifyCorsOptions = {
|
||||
origin: ["*", "something"],
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const originRegexpArray: fastifyCors.FastifyCorsOptions = {
|
||||
origin: [/\*/, /something/],
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
|
||||
const originCallback: fastifyCors.FastifyCorsOptions = {
|
||||
origin: (err: Error, allow: boolean) => {
|
||||
throw err;
|
||||
},
|
||||
allowedHeaders: ["authorization", "content-type"],
|
||||
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
credentials: true,
|
||||
exposedHeaders: ["authorization"],
|
||||
maxAge: 13000,
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 200,
|
||||
preflight: false,
|
||||
};
|
||||
Vendored
-68
@@ -1,68 +0,0 @@
|
||||
// Type definitions for fastify-cors 0.1
|
||||
// Project: https://github.com/fastify/fastify-cors#readme
|
||||
// Definitions by: Jannik Keye <https://github.com/jannikkeye>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type originCallback = (err: Error, allow: boolean) => void;
|
||||
|
||||
/**
|
||||
* fastify-cors enables the use of CORS in a Fastify application.
|
||||
*/
|
||||
declare function fastifyCors(): void;
|
||||
|
||||
declare namespace fastifyCors {
|
||||
/**
|
||||
* Options for configuring the fastify-cors plugin.
|
||||
*/
|
||||
interface FastifyCorsOptions {
|
||||
/**
|
||||
* Configures the Access-Control-Allow-Origin CORS header.
|
||||
*/
|
||||
origin?: string | boolean | RegExp | string[] | RegExp[] | originCallback;
|
||||
/**
|
||||
* Configures the Access-Control-Allow-Credentials CORS header.
|
||||
* Set to true to pass the header, otherwise it is omitted.
|
||||
*/
|
||||
credentials?: boolean;
|
||||
/**
|
||||
* Configures the Access-Control-Expose-Headers CORS header.
|
||||
* Expects a comma-delimited string (ex: 'Content-Range,X-Content-Range')
|
||||
* or an array (ex: ['Content-Range', 'X-Content-Range']).
|
||||
* If not specified, no custom headers are exposed.
|
||||
*/
|
||||
exposedHeaders?: string | string[];
|
||||
/**
|
||||
* Configures the Access-Control-Allow-Headers CORS header.
|
||||
* Expects a comma-delimited string (ex: 'Content-Type,Authorization')
|
||||
* or an array (ex: ['Content-Type', 'Authorization']). If not
|
||||
* specified, defaults to reflecting the headers specified in the
|
||||
* request's Access-Control-Request-Headers header.
|
||||
*/
|
||||
allowedHeaders?: string | string[];
|
||||
/**
|
||||
* Configures the Access-Control-Allow-Methods CORS header.
|
||||
* Expects a comma-delimited string (ex: 'GET,PUT,POST') or an array (ex: ['GET', 'PUT', 'POST']).
|
||||
*/
|
||||
methods?: string | string[];
|
||||
/**
|
||||
* Configures the Access-Control-Max-Age CORS header.
|
||||
* Set to an integer to pass the header, otherwise it is omitted.
|
||||
*/
|
||||
maxAge?: number;
|
||||
/**
|
||||
* Pass the CORS preflight response to the route handler (default: false).
|
||||
*/
|
||||
preflightContinue?: boolean;
|
||||
/**
|
||||
* Provides a status code to use for successful OPTIONS requests,
|
||||
* since some legacy browsers (IE11, various SmartTVs) choke on 204.
|
||||
*/
|
||||
optionsSuccessStatus?: number;
|
||||
/**
|
||||
* Pass the CORS preflight response to the route handler (default: false).
|
||||
*/
|
||||
preflight?: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export = fastifyCors;
|
||||
@@ -1,16 +0,0 @@
|
||||
import path = require("path");
|
||||
import fastify = require("fastify");
|
||||
import fastifyStatic = require("fastify-static");
|
||||
|
||||
const app = fastify();
|
||||
|
||||
app.register<fastifyStatic.FastifyStaticOptions>(fastifyStatic, {
|
||||
root: path.join(__dirname, "public"),
|
||||
prefix: "/public/", // optional: default '/'
|
||||
immutable: true,
|
||||
maxAge: 42
|
||||
});
|
||||
|
||||
app.get("/another/path", (req, reply) => {
|
||||
reply.sendFile("myHtml.html"); // serving path.join(__dirname, 'public', 'myHtml.html') directly
|
||||
});
|
||||
Vendored
-41
@@ -1,41 +0,0 @@
|
||||
// Type definitions for fastify-static 0.14
|
||||
// Project: https://github.com/fastify/fastify-static
|
||||
// Definitions by: Leonhard Melzer <https://github.com/leomelzer>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import fastify = require("fastify");
|
||||
|
||||
import { Server, IncomingMessage, ServerResponse } from "http";
|
||||
|
||||
declare module "fastify" {
|
||||
interface FastifyReply<HttpResponse> {
|
||||
sendFile(filename: string): FastifyReply<HttpResponse>;
|
||||
}
|
||||
}
|
||||
|
||||
declare function fastifyStatic(): void;
|
||||
|
||||
declare namespace fastifyStatic {
|
||||
interface FastifyStaticOptions {
|
||||
root: string;
|
||||
prefix?: string;
|
||||
serve?: boolean;
|
||||
decorateReply?: boolean;
|
||||
schemaHide?: boolean;
|
||||
setHeaders?: () => void;
|
||||
|
||||
// Passed on to `send`
|
||||
acceptRanges?: boolean;
|
||||
cacheControl?: boolean;
|
||||
dotfiles?: boolean;
|
||||
etag?: boolean;
|
||||
extensions?: string[];
|
||||
immutable?: boolean;
|
||||
index?: string[];
|
||||
lastModified?: boolean;
|
||||
maxAge?: string | number;
|
||||
}
|
||||
}
|
||||
|
||||
export = fastifyStatic;
|
||||
Vendored
+17
-2
@@ -1,11 +1,26 @@
|
||||
// Type definitions for @feathersjs/errors 3.2
|
||||
// Type definitions for @feathersjs/errors 3.3
|
||||
// Project: http://feathersjs.com/
|
||||
// Definitions by: Jan Lohage <https://github.com/j2L4e>
|
||||
// RazzM13 <https://github.com/RazzM13>
|
||||
// Definitions: https://github.com/feathersjs-ecosystem/feathers-typescript
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export interface FeathersErrorJSON {
|
||||
readonly name: string;
|
||||
readonly message: string;
|
||||
readonly code: number;
|
||||
readonly className: string;
|
||||
readonly data: any;
|
||||
readonly errors: any;
|
||||
}
|
||||
|
||||
export class FeathersError extends Error {
|
||||
constructor(msg: string | Error, name: string, code: number, className: string, data: any)
|
||||
readonly code: number;
|
||||
readonly className: string;
|
||||
readonly data: any;
|
||||
readonly errors: any;
|
||||
constructor(msg: string | Error, name: string, code: number, className: string, data: any);
|
||||
toJSON(): FeathersErrorJSON;
|
||||
}
|
||||
|
||||
export class BadRequest extends FeathersError {
|
||||
|
||||
@@ -29,6 +29,7 @@ const opts = {
|
||||
min: 2,
|
||||
maxWaitingClients: 2,
|
||||
testOnBorrow: true,
|
||||
testOnReturn: true,
|
||||
acquireTimeoutMillis: 100,
|
||||
fifo: true,
|
||||
priorityRange: 5,
|
||||
|
||||
Vendored
+1
@@ -38,6 +38,7 @@ export interface Options {
|
||||
min?: number;
|
||||
maxWaitingClients?: number;
|
||||
testOnBorrow?: boolean;
|
||||
testOnReturn?: boolean;
|
||||
acquireTimeoutMillis?: number;
|
||||
fifo?: boolean;
|
||||
priorityRange?: number;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import giphyApi = require('giphy-api');
|
||||
|
||||
const cb = (err: Error, res: any) => {};
|
||||
|
||||
giphyApi('API KEY HERE');
|
||||
giphyApi({ https: true });
|
||||
giphyApi({ timeout: 60 });
|
||||
giphyApi({ apiKey: 'API KEY' });
|
||||
|
||||
const giphy = giphyApi();
|
||||
giphy.search('pokemon', cb);
|
||||
giphy.search('pokemon').then(res => {});
|
||||
giphy.search({ q: 'pokemon', rating: 'g' }, cb);
|
||||
giphy.search({ q: 'pokemon', rating: 'g' }).then(res => {});
|
||||
|
||||
giphy.id('feqkVgjJpYtjy', cb);
|
||||
giphy.id('feqkVgjJpYtjy').then(res => {});
|
||||
giphy.id(['feqkVgjJpYtjy'], cb);
|
||||
giphy.id(['feqkVgjJpYtjy']).then(res => {});
|
||||
|
||||
giphy.translate('superman', cb);
|
||||
giphy.translate('superman').then(res => {});
|
||||
giphy.translate({ s: 'superman', rating: 'g', fmt: 'html' }, cb);
|
||||
giphy.translate({ s: 'superman', rating: 'g' }).then(res => {});
|
||||
|
||||
giphy.random('superman', cb);
|
||||
giphy.random('superman').then(res => {});
|
||||
giphy.random({ tag: 'superman', rating: 'g' }, cb);
|
||||
giphy.random({ tag: 'superman', rating: 'g' }).then(res => {});
|
||||
|
||||
giphy.trending(cb);
|
||||
giphy.trending().then(res => {});
|
||||
giphy.trending({ limit: 2, rating: 'g' });
|
||||
giphy.trending({ limit: 2, rating: 'g' }).then(res => {});
|
||||
Vendored
+177
@@ -0,0 +1,177 @@
|
||||
// Type definitions for giphy-api 2.0
|
||||
// Project: https://github.com/austinkelleher/giphy-api
|
||||
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
type Rating = "y" | "g" | "pg" | "pg-13" | "r";
|
||||
type Format = "html" | "json";
|
||||
|
||||
interface GiphyOptions {
|
||||
https?: boolean;
|
||||
timeout?: number;
|
||||
apiKey?: string;
|
||||
}
|
||||
|
||||
interface BaseOptions {
|
||||
rating: Rating;
|
||||
fmt?: Format;
|
||||
}
|
||||
|
||||
interface SearchOptions extends BaseOptions {
|
||||
q: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}
|
||||
|
||||
interface TranslateOptions extends BaseOptions {
|
||||
s: string;
|
||||
}
|
||||
|
||||
interface RandomOptions extends BaseOptions {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
interface TrendingOptions extends BaseOptions {
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
interface BaseImage {
|
||||
url: string;
|
||||
width: string;
|
||||
height: string;
|
||||
}
|
||||
|
||||
interface Result {
|
||||
data: [
|
||||
{
|
||||
type: string;
|
||||
id: string;
|
||||
slug: string;
|
||||
url: string;
|
||||
bitly_url: string;
|
||||
embed_url: string;
|
||||
username: string;
|
||||
source: string;
|
||||
rating: Rating;
|
||||
content_url: string;
|
||||
user?: {
|
||||
avatar_url: string;
|
||||
banner_url: string;
|
||||
profile_url: string;
|
||||
username: string;
|
||||
display_name: string;
|
||||
twitter: string;
|
||||
},
|
||||
source_tld: string;
|
||||
source_post_url: string;
|
||||
update_datetime: string;
|
||||
create_datetime: string;
|
||||
import_datetime: string;
|
||||
trending_datetime: string;
|
||||
title: string;
|
||||
images: {
|
||||
fixed_height: BaseImage & {
|
||||
size: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
fixed_height_still: BaseImage;
|
||||
fixed_height_downsampled: BaseImage & {
|
||||
size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
fixed_width: BaseImage & {
|
||||
size: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
original_still: BaseImage;
|
||||
fixed_width_still: BaseImage;
|
||||
fixed_width_downsampled: BaseImage & {
|
||||
size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
fixed_height_small: BaseImage & {
|
||||
size: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
fixed_height_small_still: BaseImage;
|
||||
fixed_width_small: BaseImage & {
|
||||
size: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
fixed_width_small_still: BaseImage;
|
||||
downsized: BaseImage & {
|
||||
size: string;
|
||||
};
|
||||
downsized_still: BaseImage;
|
||||
downsized_large: BaseImage & {
|
||||
size: string;
|
||||
};
|
||||
downsized_medium: BaseImage & {
|
||||
size: string;
|
||||
};
|
||||
downsized_small: BaseImage & {
|
||||
size: string;
|
||||
};
|
||||
original: BaseImage & {
|
||||
size: string;
|
||||
frames: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
webp: string;
|
||||
webp_size: string;
|
||||
};
|
||||
looping: { mp4: string; };
|
||||
preview: {
|
||||
width: string;
|
||||
height: string;
|
||||
mp4: string;
|
||||
mp4_size: string;
|
||||
};
|
||||
preview_gif: BaseImage & {
|
||||
size: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
pagination: { total_count: number; count: number; offset: number };
|
||||
meta: {
|
||||
status: number;
|
||||
msg: string;
|
||||
response_id: string;
|
||||
};
|
||||
}
|
||||
|
||||
type Callback = (err: Error, res: Result) => void;
|
||||
|
||||
interface Giphy {
|
||||
search(queryOrOptions: string | SearchOptions, cb: Callback): void;
|
||||
search(queryOrOptions: string | SearchOptions): Promise<Result>;
|
||||
id(ids: string | string[], cb: Callback): void;
|
||||
id(ids: string | string[]): Promise<Result>;
|
||||
translate(termOrOptions: string | TranslateOptions, cb: Callback): void;
|
||||
translate(termOrOptions: string | TranslateOptions): Promise<Result>;
|
||||
random(tagOrOptions: string | RandomOptions, cb: Callback): void;
|
||||
random(tagOrOptions: string | RandomOptions): Promise<Result>;
|
||||
trending(options: TrendingOptions, cb: Callback): void;
|
||||
trending(cb: Callback): void;
|
||||
trending(options?: TrendingOptions): Promise<Result>;
|
||||
}
|
||||
|
||||
declare function giphyApi(apiKeyOrOptions?: string | GiphyOptions): Giphy;
|
||||
|
||||
export = giphyApi;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"giphy-api-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,462 @@
|
||||
import Hexo = require('hexo');
|
||||
import fs = require('fs');
|
||||
import Bunyan = require('bunyan');
|
||||
import { ParsedArgs } from 'minimist';
|
||||
import util = require('hexo-util');
|
||||
import http = require('http');
|
||||
|
||||
const config: Hexo.InstanceOptions = {};
|
||||
config.debug = false;
|
||||
config.safe = false;
|
||||
config.silent = false;
|
||||
config.config = '_config.yml';
|
||||
|
||||
let h: Hexo;
|
||||
h = hexo;
|
||||
h = new Hexo();
|
||||
h = new Hexo('./');
|
||||
h = new Hexo('./', config);
|
||||
|
||||
const logger: Bunyan = h.log;
|
||||
console.log(h.base_dir);
|
||||
console.log(h.public_dir);
|
||||
console.log(h.source_dir);
|
||||
console.log(h.plugin_dir);
|
||||
console.log(h.script_dir);
|
||||
console.log(h.scaffold_dir);
|
||||
console.log(h.theme_dir);
|
||||
console.log(h.theme_script_dir);
|
||||
console.log(h.config_path);
|
||||
console.log(h.env.args);
|
||||
console.log(h.env.debug);
|
||||
console.log(h.env.safe);
|
||||
console.log(h.env.silent);
|
||||
console.log(h.env.env);
|
||||
console.log(h.env.version);
|
||||
console.log(h.env.init);
|
||||
console.log(h.config.title);
|
||||
console.log(h.config.subtitle);
|
||||
console.log(h.config.description);
|
||||
console.log(h.config.author);
|
||||
console.log(h.config.language);
|
||||
console.log(h.config.timezone);
|
||||
console.log(h.config.url);
|
||||
console.log(h.config.root);
|
||||
console.log(h.config.permalink);
|
||||
console.log(h.config.permalink_defaults);
|
||||
console.log(h.config.source_dir);
|
||||
console.log(h.config.public_dir);
|
||||
console.log(h.config.tag_dir);
|
||||
console.log(h.config.archive_dir);
|
||||
console.log(h.config.category_dir);
|
||||
console.log(h.config.code_dir);
|
||||
console.log(h.config.i18n_dir);
|
||||
console.log(h.config.skip_render);
|
||||
console.log(h.config.new_post_name);
|
||||
console.log(h.config.default_layout);
|
||||
console.log(h.config.titlecase);
|
||||
console.log(h.config.external_link);
|
||||
console.log(h.config.filename_case);
|
||||
console.log(h.config.render_drafts);
|
||||
console.log(h.config.post_asset_folder);
|
||||
console.log(h.config.relative_link);
|
||||
console.log(h.config.future);
|
||||
console.log(h.config.highlight.enable);
|
||||
console.log(h.config.highlight.line_number);
|
||||
console.log(h.config.highlight.auto_detect);
|
||||
console.log(h.config.highlight.tab_replace);
|
||||
console.log(h.config.default_category);
|
||||
console.log(h.config.category_map);
|
||||
console.log(h.config.tag_map);
|
||||
console.log(h.config.time_format);
|
||||
console.log(h.config.per_page);
|
||||
console.log(h.config.pagination_dir);
|
||||
console.log(h.config.theme);
|
||||
console.log(h.config.theme_config);
|
||||
console.log(h.config.deploy);
|
||||
console.log(h.config.include);
|
||||
console.log(h.config.exclude);
|
||||
console.log(h.config.ignore);
|
||||
|
||||
h.init().then(async () => {
|
||||
await h.watch();
|
||||
h.unwatch();
|
||||
|
||||
await h.theme.watch();
|
||||
h.theme.unwatch();
|
||||
|
||||
await h.source.watch();
|
||||
h.source.unwatch();
|
||||
|
||||
await h.load();
|
||||
h.call('config', {_: ['arg1']}, (err, value) => {});
|
||||
|
||||
await h.exit();
|
||||
});
|
||||
|
||||
h.on('ready', () => {
|
||||
h.on('deployBefore', () => {});
|
||||
h.on('deployAfter', () => {});
|
||||
h.on('exit', err => {
|
||||
console.log(err);
|
||||
});
|
||||
h.on('generateBefore', () => {});
|
||||
h.on('generateAfter', () => {});
|
||||
h.on('new', param => {
|
||||
const path: string = param.path;
|
||||
const content: string = param.content;
|
||||
});
|
||||
h.on('processBefore', (type, path) => {
|
||||
const t: Hexo.Box.File['type'] = type;
|
||||
const p: string = path;
|
||||
});
|
||||
h.on('processAfter', (type, path) => {
|
||||
const t: Hexo.Box.File['type'] = type;
|
||||
const p: string = path;
|
||||
});
|
||||
h.on('ready', () => {});
|
||||
|
||||
{
|
||||
let local: Hexo.Locals.Post[] = [];
|
||||
const model = hexo.locals.get('posts');
|
||||
|
||||
local = model.toArray();
|
||||
const count: number = model.count();
|
||||
model.filter(v => true);
|
||||
model.forEach(v => {});
|
||||
model.map(v => v.name);
|
||||
}
|
||||
|
||||
{
|
||||
let local: Hexo.Locals.Page[] = [];
|
||||
const model = hexo.locals.get('pages');
|
||||
|
||||
local = model.toArray();
|
||||
const count: number = model.count();
|
||||
model.filter(v => true);
|
||||
model.forEach(v => {});
|
||||
model.map(v => v.name);
|
||||
}
|
||||
|
||||
{
|
||||
let local: Hexo.Locals.Category[] = [];
|
||||
const model = hexo.locals.get('categories');
|
||||
|
||||
local = model.toArray();
|
||||
const count: number = model.count();
|
||||
model.filter(v => true);
|
||||
model.forEach(v => {});
|
||||
model.map(v => v.name);
|
||||
}
|
||||
|
||||
{
|
||||
let local: Hexo.Locals.Tag[] = [];
|
||||
const model = hexo.locals.get('tags');
|
||||
|
||||
local = model.toArray();
|
||||
const count: number = model.count();
|
||||
model.filter(v => true);
|
||||
model.forEach(v => {});
|
||||
model.map(v => v.name);
|
||||
}
|
||||
|
||||
{
|
||||
h.locals.set('some-data', () => 'some vlue');
|
||||
h.locals.remove('some-data');
|
||||
h.locals.toObject();
|
||||
h.locals.invalidate();
|
||||
}
|
||||
|
||||
{
|
||||
const route = h.route.get('index.html');
|
||||
if (route) {
|
||||
console.log(route.modified);
|
||||
console.log(route.read());
|
||||
}
|
||||
|
||||
const data: Hexo.Router.Data = {
|
||||
data: 'some data',
|
||||
modified: true,
|
||||
};
|
||||
data.data = new Buffer([]);
|
||||
data.data = () => 'return';
|
||||
|
||||
let router: Hexo.Router;
|
||||
router = h.route;
|
||||
router = h.route.set('index.html', 'content');
|
||||
router = h.route.set('index.html', new Buffer([]));
|
||||
router = h.route.set('index.html', new util.Pattern(() => false));
|
||||
router = h.route.set('index.html', { data: 'index', modified: false });
|
||||
|
||||
router = h.route.remove('index.html');
|
||||
|
||||
const list: string[] = h.route.list();
|
||||
const format: string = h.route.format('/');
|
||||
}
|
||||
|
||||
{
|
||||
h.source.process(() => {});
|
||||
h.source.addProcessor('path', file => {
|
||||
console.log(file.source);
|
||||
console.log(file.path);
|
||||
console.log(file.type);
|
||||
console.log(file.params);
|
||||
|
||||
file.read((err, content) => {
|
||||
console.log(err, content.toString());
|
||||
console.log(content);
|
||||
});
|
||||
|
||||
file.read({encoding: 'utf8', flag: 'r'}, (err, content) => {
|
||||
console.log(err, content.toString());
|
||||
console.log(content);
|
||||
});
|
||||
|
||||
file.readSync({encoding: 'utf8', flag: 'r'});
|
||||
|
||||
file.stat((err, stat) => {
|
||||
console.log(err);
|
||||
console.log(stat.mtime);
|
||||
console.log(stat.ctime);
|
||||
console.log(stat.atime);
|
||||
});
|
||||
|
||||
file.stat().then(stat => {
|
||||
console.log(stat.mtime);
|
||||
console.log(stat.ctime);
|
||||
console.log(stat.atime);
|
||||
});
|
||||
|
||||
const stat: fs.Stats = file.statSync();
|
||||
|
||||
let render = '';
|
||||
file.render({}, (err, result) => {
|
||||
render = result;
|
||||
});
|
||||
file.render((err, result) => {
|
||||
render = result;
|
||||
});
|
||||
file.render().then(result => {
|
||||
render = result;
|
||||
});
|
||||
render = file.renderSync();
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let _bool = true;
|
||||
_bool = h.render.isRenderable('path');
|
||||
_bool = h.render.isRenderableSync('path');
|
||||
|
||||
const option: Hexo.Render.Data = {
|
||||
engine: 'ejs',
|
||||
text: 'test',
|
||||
path: __filename,
|
||||
};
|
||||
|
||||
let _string = '';
|
||||
h.render.render({text: 'example', engine: 'swig'}).then(result => {
|
||||
_string = result;
|
||||
});
|
||||
h.render.render({path: __filename}).then(result => {
|
||||
_string = result;
|
||||
});
|
||||
h.render.render({text: ''}, {foo: 'foo'}).then(result => {
|
||||
_string = result;
|
||||
});
|
||||
_string = h.render.renderSync({text: 'example'});
|
||||
|
||||
_string = h.render.getOutput('ejs');
|
||||
}
|
||||
|
||||
{
|
||||
const data: Hexo.Post.Data = {};
|
||||
data.title = 'Title';
|
||||
data.slug = 'URL';
|
||||
data.layout = 'layout_name';
|
||||
data.path = 'path';
|
||||
data.date = new Date();
|
||||
|
||||
h.post.create(data, false, () => {});
|
||||
h.post.create(data, () => {});
|
||||
|
||||
h.post.publish(data, false, () => {});
|
||||
h.post.publish(data, () => {});
|
||||
|
||||
const renderData: Hexo.Post.RenderData = {};
|
||||
renderData.content = 'content';
|
||||
renderData.engine = 'ejs';
|
||||
h.post.render(null, renderData, () => {});
|
||||
}
|
||||
|
||||
{
|
||||
h.scaffold.get('post').then(result => '');
|
||||
h.scaffold.set('post', '').then(() => {});
|
||||
h.scaffold.remove('post').then(() => {});
|
||||
}
|
||||
|
||||
{
|
||||
const themeConfig: Hexo['config'] = h.theme.config;
|
||||
let v: Hexo.View | undefined;
|
||||
h.theme.setView('path-name', {});
|
||||
v = h.theme.getView('post');
|
||||
if (v) {
|
||||
console.log(v.path);
|
||||
console.log(v.source);
|
||||
|
||||
v.render().then(result => {});
|
||||
v.renderSync();
|
||||
}
|
||||
|
||||
h.theme.removeView('path-name');
|
||||
h.theme.process(() => {});
|
||||
}
|
||||
|
||||
{
|
||||
const options: Hexo.extend.Console.Options = {};
|
||||
options.usage = '[layout] <title>';
|
||||
options.arguments = [
|
||||
{name: 'layout', desc: 'Post layout'},
|
||||
{name: 'title', desc: 'Post title'},
|
||||
];
|
||||
options.options = [
|
||||
{name: '-r, --replace', desc: 'Replace existing files'},
|
||||
];
|
||||
options.desc = 'desc';
|
||||
|
||||
h.extend.console.register('name', 'description', options, args => {
|
||||
const a: ParsedArgs = args;
|
||||
});
|
||||
h.extend.console.register('name', options, args => {});
|
||||
h.extend.console.register('name', 'description', args => {});
|
||||
h.extend.console.register('name', args => {});
|
||||
}
|
||||
|
||||
{
|
||||
h.extend.deployer.register('name', args => {
|
||||
console.log(args.type);
|
||||
console.log(args.someExtraArg);
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
h.extend.filter.register('before_post_render', data => data);
|
||||
h.extend.filter.register('before_post_render', data => undefined);
|
||||
h.extend.filter.register('before_post_render', data => undefined, 1);
|
||||
|
||||
h.extend.filter.register('after_post_render', data => data);
|
||||
h.extend.filter.register('after_post_render', data => undefined);
|
||||
h.extend.filter.register('after_post_render', data => undefined, 1);
|
||||
|
||||
h.extend.filter.register('before_exit', () => {});
|
||||
h.extend.filter.register('before_exit', () => {}, 1);
|
||||
|
||||
h.extend.filter.register('before_generate', data => data);
|
||||
h.extend.filter.register('before_generate', data => undefined);
|
||||
h.extend.filter.register('before_generate', data => undefined, 1);
|
||||
|
||||
h.extend.filter.register('after_generate', () => {});
|
||||
h.extend.filter.register('after_generate', () => {}, 1);
|
||||
|
||||
h.extend.filter.register('template_locals', locals => locals);
|
||||
h.extend.filter.register('template_locals', locals => undefined);
|
||||
h.extend.filter.register('template_locals', locals => undefined, 1);
|
||||
|
||||
h.extend.filter.register('after_init', () => {});
|
||||
h.extend.filter.register('after_init', () => {}, 1);
|
||||
|
||||
h.extend.filter.register('new_post_path', (data, replace) => undefined);
|
||||
h.extend.filter.register('new_post_path', (data, replace) => undefined, 1);
|
||||
|
||||
h.extend.filter.register('post_permalink', permalink => permalink);
|
||||
h.extend.filter.register('post_permalink', permalink => permalink, 1);
|
||||
|
||||
h.extend.filter.register('after_render:html', (result, data) => result);
|
||||
h.extend.filter.register('after_render:html', (result, data) => result, 1);
|
||||
|
||||
h.extend.filter.register('after_clean', () => {});
|
||||
h.extend.filter.register('after_clean', () => {}, 1);
|
||||
|
||||
h.extend.filter.register('server_middleware', app => {
|
||||
app.use((req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
res.setHeader('X-Powered-By', 'Hexo');
|
||||
});
|
||||
});
|
||||
|
||||
const filter = (data: any) => data;
|
||||
h.extend.filter.register('custom_filter', filter);
|
||||
h.extend.filter.unregister('custom_filter', filter);
|
||||
|
||||
const options: Hexo.extend.Filter.Options = {};
|
||||
options.args = ['foo', 'bar'];
|
||||
options.context = h;
|
||||
h.extend.filter.exec('custom_filter', options);
|
||||
h.extend.filter.exec('custom_filter');
|
||||
h.extend.filter.execSync('custom_filter', options);
|
||||
h.extend.filter.execSync('custom_filter');
|
||||
}
|
||||
|
||||
{
|
||||
const ret: Hexo.extend.Generator.Return = {
|
||||
data: {},
|
||||
layout: 'layout-name',
|
||||
path: '/',
|
||||
};
|
||||
h.extend.generator.register('name', local => ret);
|
||||
h.extend.generator.register('name', local => [ret]);
|
||||
h.extend.generator.register('name', local => {
|
||||
console.log(local.data);
|
||||
const categories: Hexo.Locals.Category[] = local.categories.toArray();
|
||||
const pages: Hexo.Locals.Page[] = local.pages.toArray();
|
||||
const posts: Hexo.Locals.Post[] = local.posts.toArray();
|
||||
const tags: Hexo.Locals.Tag[] = local.tags.toArray();
|
||||
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
h.extend.helper.register('name', (...args) => {
|
||||
return 'ret';
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
h.extend.migrator.register('name', args => {
|
||||
const a: ParsedArgs = args;
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
let f: Hexo.Box.File;
|
||||
h.extend.processor.register('pattern', file => f = file);
|
||||
h.extend.processor.register(/pattern/, file => f = file);
|
||||
h.extend.processor.register((str) => true , file => f = file);
|
||||
h.extend.processor.register(file => f = file);
|
||||
}
|
||||
|
||||
{
|
||||
h.extend.renderer.register('ts', 'js', (data, options) => {
|
||||
console.log(data.path);
|
||||
console.log(data.text);
|
||||
return 'result';
|
||||
}, true);
|
||||
|
||||
h.extend.renderer.register('ts', 'js', (data, options) => Promise.resolve('result'), false);
|
||||
h.extend.renderer.register('ts', 'js', (data, options) => Promise.resolve('result'));
|
||||
}
|
||||
|
||||
{
|
||||
const option: Hexo.extend.Tag.Options = {};
|
||||
option.async = true;
|
||||
option.ends = true;
|
||||
|
||||
h.extend.tag.register('name', (args, content) => {
|
||||
if (content) {
|
||||
const c: string = content;
|
||||
}
|
||||
const a: string[] = args;
|
||||
return 'content';
|
||||
});
|
||||
}
|
||||
});
|
||||
Vendored
+976
@@ -0,0 +1,976 @@
|
||||
// Type definitions for hexo 3.8
|
||||
// Project: https://hexo.io/
|
||||
// Definitions by: KentarouTakeda <https://github.com/kentarouTakeda>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import EventEmitter = require('events');
|
||||
import moment = require('moment');
|
||||
import { ParsedArgs } from 'minimist';
|
||||
import Logger = require('bunyan');
|
||||
import underscore = require('underscore');
|
||||
import connect = require('connect');
|
||||
import Stream = require('stream');
|
||||
import util = require('hexo-util');
|
||||
import fs = require('fs');
|
||||
|
||||
declare global {
|
||||
const hexo: Hexo;
|
||||
}
|
||||
|
||||
interface HexoConfig {
|
||||
[key: string]: any;
|
||||
/**
|
||||
* The title of your website
|
||||
*/
|
||||
readonly title: string;
|
||||
|
||||
/**
|
||||
* The subtitle of your website
|
||||
*/
|
||||
readonly subtitle: string;
|
||||
|
||||
/**
|
||||
* The description of your website
|
||||
*/
|
||||
readonly description: string;
|
||||
|
||||
/*
|
||||
* Your name
|
||||
*/
|
||||
readonly author: string;
|
||||
|
||||
/**
|
||||
* The language of your website. Use a 2-lettter ISO-639-1 code. Default is en.
|
||||
*/
|
||||
readonly language: string;
|
||||
|
||||
/**
|
||||
* The timezone of your website. Hexo uses the setting on your computer by default.
|
||||
* You can find the list of available timezones [here]{@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones} .
|
||||
* Some examples are `America/New_York` , `Japan` , and `UTC` .
|
||||
*/
|
||||
readonly timezone: string;
|
||||
|
||||
/*
|
||||
* The URL of your website
|
||||
*/
|
||||
readonly url: string;
|
||||
|
||||
/**
|
||||
* The root directory of your website
|
||||
*/
|
||||
readonly root: string;
|
||||
|
||||
/**
|
||||
* The permalink format of articles
|
||||
*/
|
||||
readonly permalink: string;
|
||||
|
||||
/**
|
||||
* Default values of each segment in permalink
|
||||
*/
|
||||
readonly permalink_defaults: string|null;
|
||||
|
||||
/**
|
||||
* Source folder. Where your content is stored
|
||||
*/
|
||||
readonly source_dir: string;
|
||||
|
||||
/**
|
||||
* Public folder. Where the static site will be generated
|
||||
*/
|
||||
readonly public_dir: string;
|
||||
|
||||
/**
|
||||
* Tag directory
|
||||
*/
|
||||
readonly tag_dir: string;
|
||||
|
||||
/**
|
||||
* Archive directory
|
||||
*/
|
||||
readonly archive_dir: string;
|
||||
|
||||
/**
|
||||
* Category directory
|
||||
*/
|
||||
readonly category_dir: string;
|
||||
|
||||
/**
|
||||
* Include code directory (subdirectory of source_dir)
|
||||
*/
|
||||
readonly code_dir: string;
|
||||
|
||||
/**
|
||||
* i18n directory
|
||||
*/
|
||||
readonly i18n_dir: string;
|
||||
|
||||
/**
|
||||
* Paths that will be copied to public raw, without being rendered. You can use glob expressions for path matching.
|
||||
*/
|
||||
readonly skip_render: string|string[]|null;
|
||||
|
||||
/**
|
||||
* The filename format for new posts
|
||||
*/
|
||||
readonly new_post_name: string;
|
||||
|
||||
/**
|
||||
* Default layout
|
||||
*/
|
||||
readonly default_layout: string;
|
||||
|
||||
/**
|
||||
* Transform titles into title case?
|
||||
*/
|
||||
readonly titlecase: boolean;
|
||||
|
||||
/**
|
||||
* Open external links in a new tab?
|
||||
*/
|
||||
readonly external_link: boolean;
|
||||
|
||||
/**
|
||||
* Transform filenames to 1 lower case; 2 upper case
|
||||
*/
|
||||
readonly filename_case: number;
|
||||
|
||||
/**
|
||||
* Display drafts?
|
||||
*/
|
||||
readonly render_drafts: boolean;
|
||||
|
||||
/**
|
||||
* Enable the Asset Folder?
|
||||
*/
|
||||
readonly post_asset_folder: boolean;
|
||||
|
||||
/**
|
||||
* Make links relative to the root folder?
|
||||
*/
|
||||
readonly relative_link: boolean;
|
||||
|
||||
/**
|
||||
* Display future posts?
|
||||
*/
|
||||
readonly future: boolean;
|
||||
|
||||
/**
|
||||
* Code block settings
|
||||
*/
|
||||
readonly highlight: {
|
||||
readonly enable: boolean;
|
||||
readonly line_number: boolean;
|
||||
readonly auto_detect: boolean;
|
||||
readonly tab_replace: string|null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default category
|
||||
*/
|
||||
readonly default_category: string;
|
||||
|
||||
/**
|
||||
* Category slugs
|
||||
*/
|
||||
readonly category_map: {[key: string]: string|number};
|
||||
|
||||
/**
|
||||
* Tag slugs
|
||||
*/
|
||||
readonly tag_map: {[key: string]: string|number};
|
||||
|
||||
/**
|
||||
* Date format
|
||||
* https://momentjs.com/
|
||||
*/
|
||||
readonly date_format: string;
|
||||
|
||||
/**
|
||||
* Time format
|
||||
* https://momentjs.com/
|
||||
*/
|
||||
readonly time_format: string;
|
||||
|
||||
/**
|
||||
* The amount of posts displayed on a single page. 0 disables pagination
|
||||
*/
|
||||
readonly per_page: number;
|
||||
|
||||
/**
|
||||
* Pagination directory
|
||||
*/
|
||||
readonly pagination_dir: string;
|
||||
|
||||
/**
|
||||
* Theme name. false disables theming
|
||||
*/
|
||||
readonly theme: string|false;
|
||||
|
||||
/**
|
||||
* Theme configuration. Include any custom theme settings under this key to override theme defaults.
|
||||
*/
|
||||
readonly theme_config: {[key: string]: string|number};
|
||||
|
||||
/**
|
||||
* Deployment settings
|
||||
*/
|
||||
readonly deploy: Hexo.extend.Deployer.Config | Hexo.extend.Deployer.Config | null;
|
||||
|
||||
/**
|
||||
* Hexo by default ignores hidden files and folders, but setting this field will make Hexo process them
|
||||
*/
|
||||
readonly include ?: string[];
|
||||
|
||||
/**
|
||||
* Hexo process will ignore files list under this field
|
||||
*/
|
||||
readonly exclude ?: string[];
|
||||
readonly ignore: string[];
|
||||
}
|
||||
|
||||
interface Model<T> {
|
||||
/**
|
||||
* Warehouse method
|
||||
* https://hexojs.github.io/warehouse/
|
||||
*/
|
||||
toArray(): T[];
|
||||
/**
|
||||
* Warehouse method
|
||||
* https://hexojs.github.io/warehouse/
|
||||
*/
|
||||
count(): number;
|
||||
/**
|
||||
* Warehouse method
|
||||
* https://hexojs.github.io/warehouse/
|
||||
*/
|
||||
forEach(fn: (v: T, i: number) => void): void;
|
||||
/**
|
||||
* Warehouse method
|
||||
* https://hexojs.github.io/warehouse/
|
||||
*/
|
||||
filter(fn: (v: T, i: number) => boolean): Model<T>;
|
||||
/**
|
||||
* Warehouse method
|
||||
* https://hexojs.github.io/warehouse/
|
||||
*/
|
||||
map<U>(fn: (v: T, i: number) => U): U[];
|
||||
}
|
||||
|
||||
interface Site {
|
||||
posts: Model<Hexo.Locals.Post>;
|
||||
pages: Model<Hexo.Locals.Page>;
|
||||
categories: Model<Hexo.Locals.Category>;
|
||||
tags: Model<Hexo.Locals.Tag>;
|
||||
data: {[key: string]: any};
|
||||
}
|
||||
|
||||
declare class Hexo extends EventEmitter {
|
||||
/**
|
||||
* Create a Hexo instance.
|
||||
* @param base the root directory of the website, `base_dir` .
|
||||
* @param args an object containing the initialization options.
|
||||
*/
|
||||
constructor(base?: string, args?: Hexo.InstanceOptions);
|
||||
|
||||
/**
|
||||
* Load configuration and plugins.
|
||||
*/
|
||||
init(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Loading all files in the `source` folder as well as the theme data.
|
||||
*/
|
||||
load(fn?: (err: any, value: any) => void): Promise<any>;
|
||||
|
||||
/**
|
||||
* The same things `load` does, but will also start watching for file changes continuously.
|
||||
*/
|
||||
watch(fn?: (err: any, value: any) => void): Promise<any>;
|
||||
|
||||
unwatch(): void;
|
||||
|
||||
/**
|
||||
* Any console command can be called explicitly using the call method on the Hexo instance.
|
||||
*/
|
||||
call(name: string, args?: any, fn?: (err: any, value: any) => void): Promise<any>;
|
||||
call(name: string, fn?: (err: any, value: any) => void): Promise<any>;
|
||||
|
||||
/**
|
||||
* You should call the `exit` method upon successful or unsuccessful completion of a console command.
|
||||
* This allows Hexo to exit gracefully and finish up important things such as saving the database.
|
||||
*/
|
||||
exit(err?: any): Promise<void>;
|
||||
|
||||
/**
|
||||
* Site settings in `_config.yml`
|
||||
*/
|
||||
readonly config: HexoConfig;
|
||||
|
||||
readonly theme: Hexo.Theme;
|
||||
readonly source: Hexo.Box;
|
||||
readonly post: Hexo.Post;
|
||||
readonly render: Hexo.Render;
|
||||
|
||||
/**
|
||||
* Local variables are used for template rendering, which is the `site` variable in templates.
|
||||
* https://hexo.io/api/locals
|
||||
*/
|
||||
readonly locals: Hexo.Locals;
|
||||
|
||||
readonly base_dir: string;
|
||||
|
||||
/**
|
||||
* Public folder. Where the static site will be generated
|
||||
*/
|
||||
readonly public_dir: string;
|
||||
|
||||
/**
|
||||
* Source folder. Where your content is stored
|
||||
*/
|
||||
readonly source_dir: string;
|
||||
|
||||
readonly plugin_dir: string;
|
||||
readonly script_dir: string;
|
||||
readonly scaffold_dir: string;
|
||||
readonly theme_dir: string;
|
||||
readonly theme_script_dir: string;
|
||||
readonly config_path: string;
|
||||
readonly env: {
|
||||
readonly args: ParsedArgs;
|
||||
readonly debug: boolean;
|
||||
readonly safe: boolean;
|
||||
readonly silent: boolean;
|
||||
readonly env: string;
|
||||
readonly version: string;
|
||||
readonly init: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logger object
|
||||
* https://www.npmjs.com/package/bunyan
|
||||
*/
|
||||
readonly log: Logger;
|
||||
|
||||
readonly extend: {
|
||||
/**
|
||||
* The console forms the bridge between Hexo and its users. It registers and describes the available console commands.
|
||||
*/
|
||||
readonly console: Hexo.extend.Console;
|
||||
/**
|
||||
* A deployer helps users quickly deploy their site to a remote server without complicated commands.
|
||||
*/
|
||||
readonly deployer: Hexo.extend.Deployer;
|
||||
/**
|
||||
* A filter is used to modify some specified data. Hexo passes data to filters in sequence and the filters then modify the data one after the other.
|
||||
*/
|
||||
readonly filter: Hexo.extend.Filter;
|
||||
/**
|
||||
* A generator builds routes based on processed files.
|
||||
*/
|
||||
readonly generator: Hexo.extend.Generator;
|
||||
/**
|
||||
* A helper makes it easy to quickly add snippets to your templates. We recommend using helpers instead of templates when you’re dealing with more complicated code.
|
||||
*/
|
||||
readonly helper: Hexo.extend.Helper;
|
||||
/**
|
||||
* A migrator helps users migrate from other systems to Hexo.
|
||||
*/
|
||||
readonly migrator: Hexo.extend.Migrator;
|
||||
/**
|
||||
* A processor is used to process source files in the source folder.
|
||||
*/
|
||||
readonly processor: Hexo.extend.Processor;
|
||||
/**
|
||||
* A renderer is used to render content.
|
||||
*/
|
||||
readonly renderer: Hexo.extend.Renderer;
|
||||
/**
|
||||
* A tag allows users to quickly and easily insert snippets into their posts.
|
||||
*/
|
||||
readonly tag: Hexo.extend.Tag;
|
||||
};
|
||||
|
||||
readonly route: Hexo.Router;
|
||||
readonly scaffold: Hexo.Scaffold;
|
||||
|
||||
/**
|
||||
* Emitted before deployment begins.
|
||||
*/
|
||||
on(ev: 'deployBefore', fn: () => void): this;
|
||||
|
||||
/**
|
||||
* Emitted after deployment finishes.
|
||||
*/
|
||||
on(ev: 'deployAfter', fn: () => void): this;
|
||||
|
||||
/**
|
||||
* Emitted before Hexo exits.
|
||||
*/
|
||||
on(ev: 'exit', fn: (err: any) => void): this;
|
||||
|
||||
/**
|
||||
* Emitted before generation begins.
|
||||
*/
|
||||
on(ev: 'generateBefore', fn: () => void): this;
|
||||
|
||||
/**
|
||||
* Emitted after generation finishes.
|
||||
*/
|
||||
on(ev: 'generateAfter', fn: () => void): this;
|
||||
|
||||
/**
|
||||
* Emitted after a new post has been created. This event returns the post data:
|
||||
*/
|
||||
on(ev: 'new', fn: (post: {path: string, content: string}) => void): this;
|
||||
|
||||
/**
|
||||
* Emitted before processing begins. This event returns a path representing the root directory of the box.
|
||||
*/
|
||||
on(ev: 'processBefore', fn: (type: Hexo.Box.File['type'], path: string) => void): this;
|
||||
|
||||
/**
|
||||
* Emitted after processing finishes. This event returns a path representing the root directory of the box.
|
||||
*/
|
||||
on(ev: 'processAfter', fn: (type: Hexo.Box.File['type'], path: string) => void): this;
|
||||
|
||||
/**
|
||||
* Emitted after initialization finishes.
|
||||
*/
|
||||
on(ev: 'ready', fn: () => void): this;
|
||||
}
|
||||
|
||||
declare namespace Hexo {
|
||||
interface InstanceOptions {
|
||||
debug?: boolean;
|
||||
safe?: boolean;
|
||||
silent?: boolean;
|
||||
config?: string;
|
||||
}
|
||||
|
||||
interface Locals {
|
||||
get(type: 'posts'): Model<Locals.Post>;
|
||||
get(type: 'pages'): Model<Locals.Page>;
|
||||
get(type: 'categories'): Model<Locals.Category>;
|
||||
get(type: 'tags'): Model<Locals.Tag>;
|
||||
/**
|
||||
* Get a Variable
|
||||
*/
|
||||
get(type: string): any;
|
||||
|
||||
/**
|
||||
* Set a Variable
|
||||
*/
|
||||
set(type: string, fn: () => any): this;
|
||||
|
||||
/**
|
||||
* Remove a Variable
|
||||
*/
|
||||
remove(type: string): this;
|
||||
|
||||
/**
|
||||
* Get All Variable
|
||||
*/
|
||||
toObject(): any;
|
||||
|
||||
/**
|
||||
* Invalidate the cache
|
||||
*/
|
||||
invalidate(): this;
|
||||
}
|
||||
namespace Locals {
|
||||
interface Page {
|
||||
title: string;
|
||||
date: moment.Moment;
|
||||
updated?: moment.Moment;
|
||||
comments: boolean;
|
||||
layout: string;
|
||||
content: string;
|
||||
excerpt?: string;
|
||||
more?: string;
|
||||
source: string;
|
||||
full_source: string;
|
||||
path: string;
|
||||
permalink: string;
|
||||
prev?: null|Page;
|
||||
next?: null|Page;
|
||||
raw?: string;
|
||||
photos?: string[];
|
||||
link?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface Post extends Page {
|
||||
published?: boolean;
|
||||
categories?: string[];
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
interface Tag {
|
||||
name: string;
|
||||
slug: string;
|
||||
path: string;
|
||||
permalink: string;
|
||||
posts: Model<Post>;
|
||||
length: number;
|
||||
}
|
||||
interface Category extends Tag {
|
||||
parent: string;
|
||||
}
|
||||
}
|
||||
|
||||
namespace extend {
|
||||
interface Console {
|
||||
register(name: string, desc: string, options: Console.Options, fn: (args: ParsedArgs) => void): void;
|
||||
register(name: string, options: Console.Options, fn: (args: ParsedArgs) => void): void;
|
||||
register(name: string, desc: string, fn: (args: ParsedArgs) => void): void;
|
||||
register(name: string, fn: (args: ParsedArgs) => void): void;
|
||||
}
|
||||
namespace Console {
|
||||
interface Options {
|
||||
/**
|
||||
* The usage of a console command.
|
||||
*/
|
||||
usage?: string;
|
||||
|
||||
/**
|
||||
* The description of each argument of a console command.
|
||||
*/
|
||||
arguments?: Array<{name: string, desc: string}>;
|
||||
|
||||
/**
|
||||
* The description of each option of a console command.
|
||||
*/
|
||||
options?: Array<{name: string, desc: string}>;
|
||||
|
||||
/**
|
||||
* More detailed information about a console command.
|
||||
*/
|
||||
desc?: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface Deployer {
|
||||
register(name: string, fn: (args: Deployer.Config) => void): void;
|
||||
}
|
||||
namespace Deployer {
|
||||
interface Config {
|
||||
readonly type: string|undefined;
|
||||
readonly [key: string]: any;
|
||||
}
|
||||
}
|
||||
|
||||
interface Filter {
|
||||
register(type: string, fn: (data: any, ...args: any[]) => any, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed before a post is rendered. Refer to post rendering to learn the execution steps.
|
||||
*/
|
||||
register(type: 'before_post_render', fn: (data: { content: string, [key: string]: any }) => { content: string, [key: string]: any }|void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed after a post is rendered. Refer to post rendering to learn the execution steps.
|
||||
*/
|
||||
register(type: 'after_post_render', fn: (data: { content: string, [key: string]: any }) => { content: string, [key: string]: any }|void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed before Hexo is about to exit – this will run right after `hexo.exit` is called.
|
||||
*/
|
||||
register(type: 'before_exit', fn: () => void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed before generation begins.
|
||||
*/
|
||||
register(type: 'before_generate', fn: (data: any) => any, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed after generation finishes.
|
||||
*/
|
||||
register(type: 'after_generate', fn: () => void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Modify [local variables](https://hexo.io/docs/variables) in templates.
|
||||
*/
|
||||
register(type: 'template_locals', fn: (locals: TemplateLocals) => TemplateLocals|void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed after Hexo is initialized – this will run right after `hexo.init` completes.
|
||||
*/
|
||||
register(type: 'after_init', fn: () => void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed when creating a post to determine the path of new posts.
|
||||
*/
|
||||
register(type: 'new_post_path', fn: (data: Post.Data, replace: boolean|undefined) => void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Used to determine the permalink of posts.
|
||||
*/
|
||||
register(type: 'post_permalink', fn: (permalink: string) => string, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed after rendering finishes. You can see rendering for more info.
|
||||
*/
|
||||
register(type: 'after_render:html', fn: (result: string, data: {path: string, text: string, [key: string]: any}) => string|void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Executed after generated files and cache are removed with hexo clean command.
|
||||
*/
|
||||
register(type: 'after_clean', fn: () => void, priority?: number): void;
|
||||
|
||||
/**
|
||||
* Add middleware to the server. app is a Connect instance.
|
||||
*/
|
||||
register(type: 'server_middleware', fn: (app: connect.Server) => connect.Server|void, priority?: number): void;
|
||||
|
||||
unregister(type: string, fn: (...args: any[]) => any): void;
|
||||
exec(type: string, data?: any, options?: Filter.Options): any;
|
||||
execSync(type: string, data?: any, options?: Filter.Options): any;
|
||||
}
|
||||
namespace Filter {
|
||||
interface Options {
|
||||
/**
|
||||
* `hexo` object.
|
||||
*/
|
||||
context?: Hexo;
|
||||
/**
|
||||
* Arguments. This must be an array.
|
||||
*/
|
||||
args?: any[];
|
||||
}
|
||||
}
|
||||
|
||||
interface Generator {
|
||||
register(name: string, fn: (locals: Site) => Generator.Return| Generator.Return[]): void;
|
||||
}
|
||||
namespace Generator {
|
||||
interface Return {
|
||||
/**
|
||||
* Path not including the prefixing `/` .
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* Layout. Specify the layouts for rendering. The value can be a string or an array. If it’s ignored then the route will return data directly.
|
||||
*/
|
||||
layout: string|string[];
|
||||
|
||||
data: any;
|
||||
}
|
||||
}
|
||||
|
||||
interface Helper {
|
||||
register(name: string, fn: (...args: any[]) => any): void;
|
||||
}
|
||||
|
||||
interface Migrator {
|
||||
register(name: string, fn: (args: ParsedArgs, fn: (err: any) => void) => void): void;
|
||||
}
|
||||
|
||||
interface Processor {
|
||||
register(pattern: RegExp | string | ((str: string) => any), fn: (file: Box.File) => void): void;
|
||||
register(fn: (file: Box.File) => void): void;
|
||||
}
|
||||
|
||||
interface Renderer {
|
||||
register(srcExt: string, outExt: string, fn: (data: HexoRendererData, options: any) => string, sync: true): void;
|
||||
register(srcExt: string, outExt: string, fn: (data: HexoRendererData, options: any) => Promise<string>, sync: false): void;
|
||||
register(srcExt: string, outExt: string, fn: (data: HexoRendererData, options: any) => Promise<string>): void;
|
||||
}
|
||||
|
||||
interface Tag {
|
||||
register(name: string, fn: (args: string[], content: string|undefined) => string, options?: Tag.Options): void;
|
||||
}
|
||||
namespace Tag {
|
||||
interface Options {
|
||||
ends?: boolean;
|
||||
async?: boolean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface Router {
|
||||
/**
|
||||
* The `get` method returns a `Stream`.
|
||||
*/
|
||||
get(path: string): Router.RouteStream|undefined;
|
||||
|
||||
/**
|
||||
* The `set` method takes a string, a `Buffer` or a function.
|
||||
*/
|
||||
set(path: string, data: string|Buffer|util.Pattern<boolean>|Router.Data): this;
|
||||
|
||||
/**
|
||||
* Remove a Path
|
||||
*/
|
||||
remove(path: string): this;
|
||||
|
||||
/**
|
||||
* Get the List of Routes
|
||||
*/
|
||||
list(): string[];
|
||||
|
||||
/**
|
||||
* The `format` method transforms a string to a valid path.
|
||||
*/
|
||||
format(path: string): string;
|
||||
}
|
||||
namespace Router {
|
||||
interface Data {
|
||||
data: string | Buffer | Callback;
|
||||
modified: boolean;
|
||||
}
|
||||
|
||||
interface RouteStream extends Stream.Readable {
|
||||
readonly modified: boolean;
|
||||
}
|
||||
|
||||
type Callback = ((err: any, result: string) => void) | (() => Promise<string>);
|
||||
}
|
||||
|
||||
interface Scaffold {
|
||||
/**
|
||||
* Get a Scaffold
|
||||
*/
|
||||
get(name: string, fn?: (err: any, result: string) => void): Promise<string>;
|
||||
/**
|
||||
* Set a Scaffold
|
||||
*/
|
||||
set(name: string, content: string, fn?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Remove a Scaffold
|
||||
*/
|
||||
remove(name: string, fn?: (err: any) => void): Promise<void>;
|
||||
}
|
||||
|
||||
interface Box extends EventEmitter {
|
||||
/**
|
||||
* Loads all files in the folder.
|
||||
*/
|
||||
process(fn: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Loads all files in the folder and start watching for file changes.
|
||||
*/
|
||||
watch(fn?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Stop watching.
|
||||
*/
|
||||
unwatch(): void;
|
||||
|
||||
/**
|
||||
* A processor is an essential element of `Box` and is used to process files.
|
||||
* You can use path matching as described above to restrict what exactly the processor should process.
|
||||
* Register a new processor with the `addProcessor` method.
|
||||
*/
|
||||
addProcessor(pattern: string|RegExp|util.Pattern<boolean>, fn: (file: Box.File) => void): void;
|
||||
}
|
||||
namespace Box {
|
||||
interface File {
|
||||
/**
|
||||
* Full path of the file
|
||||
*/
|
||||
readonly source: string;
|
||||
|
||||
/**
|
||||
* Relative path to the box of the file
|
||||
*/
|
||||
readonly path: string;
|
||||
|
||||
/**
|
||||
* File type. The value can be `create` , `update` , `skip`, `delete` .
|
||||
*/
|
||||
readonly type: 'create' | 'update' | 'skip' | 'delete';
|
||||
|
||||
/**
|
||||
* The information from path matching.
|
||||
*/
|
||||
readonly params: any;
|
||||
|
||||
/**
|
||||
* Read a file
|
||||
*/
|
||||
read(option?: {encoding?: string|null, flag?: string}, fn?: (err: any, result: string|Buffer) => void): Promise<string|Buffer>;
|
||||
read(fn?: (err: any, result: string|Buffer) => void): Promise<string|Buffer>;
|
||||
|
||||
/**
|
||||
* Read a file synchronously
|
||||
*/
|
||||
readSync(option?: {encoding?: string|null, flag?: string}): string|Buffer;
|
||||
|
||||
/**
|
||||
* Read the status of a file
|
||||
*/
|
||||
stat(fn?: (err: any, result: fs.Stats) => void): Promise<fs.Stats>;
|
||||
|
||||
/**
|
||||
* Read the status of a file synchronously
|
||||
*/
|
||||
statSync(): fs.Stats;
|
||||
|
||||
/**
|
||||
* Render a file
|
||||
*/
|
||||
render(fn?: (err: any, result: string) => void): Promise<string>;
|
||||
render(option?: any, fn?: (err: any, result: string) => void): Promise<string>;
|
||||
|
||||
/**
|
||||
* Render a file synchronously
|
||||
*/
|
||||
renderSync(option?: any): string;
|
||||
}
|
||||
}
|
||||
|
||||
interface Render {
|
||||
render(data: Render.Data, option?: any, fn?: (err: any, result: string) => void): Promise<string>;
|
||||
render(data: Render.Data, fn?: (err: any, result: string) => void): Promise<string>;
|
||||
renderSync(data: Render.Data, option?: any): string;
|
||||
|
||||
/**
|
||||
* Check whether a file is renderable synchronously.
|
||||
*/
|
||||
isRenderable(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Check whether a file is renderable.
|
||||
*/
|
||||
isRenderableSync(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Get the Output Extension
|
||||
*/
|
||||
getOutput(path: string): string;
|
||||
}
|
||||
namespace Render {
|
||||
interface Data {
|
||||
text?: string;
|
||||
engine?: string;
|
||||
path?: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface Post {
|
||||
/**
|
||||
* Create a Post
|
||||
*/
|
||||
create(data: Post.Data, replace?: boolean, fn?: (err: any) => void): Promise<void>;
|
||||
create(data: Post.Data, fn?: (err: any) => void): Promise<void>;
|
||||
|
||||
/**
|
||||
* Publish a Draft
|
||||
*/
|
||||
publish(data: Post.Data, replace?: boolean, fn?: (err: any) => void): Promise<void>;
|
||||
publish(data: Post.Data, fn?: (err: any) => void): Promise<void>;
|
||||
|
||||
render(source: string|null|undefined, data: Post.RenderData, fn: (err: any) => void): Promise<void>;
|
||||
}
|
||||
namespace Post {
|
||||
interface Data {
|
||||
title?: string;
|
||||
slug?: string;
|
||||
layout?: string;
|
||||
path?: string;
|
||||
date?: moment.MomentInput;
|
||||
}
|
||||
interface RenderData {
|
||||
engine?: string;
|
||||
content?: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface Theme extends Box {
|
||||
config: HexoConfig;
|
||||
|
||||
/**
|
||||
* Get a View
|
||||
*/
|
||||
getView(path: string): View|undefined;
|
||||
|
||||
/**
|
||||
* Set a View
|
||||
*/
|
||||
setView(path: string, data: any): void;
|
||||
|
||||
/**
|
||||
* Remove a View
|
||||
*/
|
||||
removeView(path: string): void;
|
||||
}
|
||||
|
||||
interface View {
|
||||
readonly path: string;
|
||||
readonly source: string;
|
||||
|
||||
/**
|
||||
* Remove a View
|
||||
*/
|
||||
render(options?: any, fn?: (err: any, result: string) => void): Promise<string>;
|
||||
render(fn: (err: any, result: string) => void): Promise<any>;
|
||||
|
||||
/**
|
||||
* Remove a View synchronously.
|
||||
*/
|
||||
renderSync(options?: any): string;
|
||||
}
|
||||
}
|
||||
|
||||
interface TemplateLocals {
|
||||
/**
|
||||
* Underscore object
|
||||
*/
|
||||
_: underscore.UnderscoreStatic;
|
||||
page: Hexo.Locals.Post | Hexo.Locals.Page | Hexo.Locals.Category | Hexo.Locals.Tag | IndexPage | ArchivePage | CategoryPage | TagPage;
|
||||
path: string;
|
||||
url: string;
|
||||
|
||||
/**
|
||||
* Site settings in `_config.yml`
|
||||
*/
|
||||
config: HexoConfig;
|
||||
theme: HexoConfig;
|
||||
env: Hexo['env'];
|
||||
layout: string;
|
||||
view_dir: string;
|
||||
site: any;
|
||||
}
|
||||
|
||||
interface IndexPage {
|
||||
per_page?: number;
|
||||
total?: number;
|
||||
current?: number;
|
||||
current_url?: string;
|
||||
posts?: object;
|
||||
prev?: number;
|
||||
prev_link?: string;
|
||||
next?: number;
|
||||
next_link?: string;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface ArchivePage extends IndexPage {
|
||||
archive?: boolean;
|
||||
year?: number;
|
||||
month?: number;
|
||||
}
|
||||
|
||||
interface CategoryPage extends IndexPage {
|
||||
category: string;
|
||||
}
|
||||
|
||||
interface TagPage extends IndexPage {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
interface HexoRendererData {
|
||||
/**
|
||||
* File content.
|
||||
*/
|
||||
readonly text: string;
|
||||
/**
|
||||
* File path.
|
||||
*/
|
||||
readonly path?: string;
|
||||
}
|
||||
|
||||
export = Hexo;
|
||||
@@ -1,16 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "fastify-static-tests.ts"]
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"hexo-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"unified-signatures": false
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+28
-10
@@ -2,7 +2,7 @@
|
||||
// Project: https://github.com/ioBroker/ioBroker
|
||||
// Definitions by: AlCalzone <https://github.com/AlCalzone>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
// TypeScript Version: 3.2
|
||||
|
||||
// Note: This is not the definition for the package `iobroker`,
|
||||
// which is just an installer, not a library.
|
||||
@@ -296,14 +296,28 @@ declare global {
|
||||
|
||||
/** attached history information */
|
||||
history?: any;
|
||||
|
||||
/** Custom settings for this state */
|
||||
custom?: Record<string, any>;
|
||||
}
|
||||
interface ChannelCommon extends ObjectCommon {
|
||||
/** description of this channel */
|
||||
desc?: string;
|
||||
|
||||
// Only states can have common.custom
|
||||
custom?: undefined;
|
||||
}
|
||||
type OtherCommon = ObjectCommon & {
|
||||
interface DeviceCommon extends ObjectCommon {
|
||||
// Only states can have common.custom
|
||||
custom?: undefined;
|
||||
// TODO: any other definition for device?
|
||||
}
|
||||
interface OtherCommon extends ObjectCommon {
|
||||
[propName: string]: any;
|
||||
};
|
||||
|
||||
// Only states can have common.custom
|
||||
custom?: undefined;
|
||||
}
|
||||
|
||||
interface BaseObject {
|
||||
/** The ID of this object */
|
||||
@@ -311,7 +325,7 @@ declare global {
|
||||
native: Record<string, any>;
|
||||
enums?: Record<string, string>;
|
||||
type: string; // specified in the derived interfaces
|
||||
common: ObjectCommon;
|
||||
common: StateCommon | ChannelCommon | DeviceCommon | OtherCommon;
|
||||
acl?: ObjectACL;
|
||||
}
|
||||
|
||||
@@ -335,10 +349,10 @@ declare global {
|
||||
|
||||
interface DeviceObject extends BaseObject {
|
||||
type: "device";
|
||||
common: ObjectCommon; // TODO: any definition for device?
|
||||
common: DeviceCommon;
|
||||
}
|
||||
interface PartialDeviceObject extends Partial<Pick<DeviceObject, "_id" | "native" | "enums" | "type" | "acl">> {
|
||||
common?: Partial<ObjectCommon>;
|
||||
common?: Partial<DeviceCommon>;
|
||||
}
|
||||
|
||||
interface OtherObject extends BaseObject {
|
||||
@@ -350,11 +364,15 @@ declare global {
|
||||
}
|
||||
|
||||
type Object = StateObject | ChannelObject | DeviceObject | OtherObject;
|
||||
|
||||
type SettableObjectWorker<T extends ioBroker.Object> =
|
||||
Pick<T, Exclude<keyof T, "_id" | "acl">> & {
|
||||
_id?: T["_id"];
|
||||
acl?: T["acl"];
|
||||
};
|
||||
|
||||
// In set[Foreign]Object[NotExists] methods, the ID and acl of the object is optional
|
||||
interface SettableObject extends Pick<ioBroker.Object, Exclude<keyof ioBroker.Object, "_id" | "acl">> {
|
||||
_id?: ioBroker.Object["_id"];
|
||||
acl?: ioBroker.Object["acl"];
|
||||
}
|
||||
type SettableObject = SettableObjectWorker<ioBroker.Object>;
|
||||
type PartialObject = PartialStateObject | PartialChannelObject | PartialDeviceObject | PartialOtherObject;
|
||||
|
||||
/** Defines access rights for a single file */
|
||||
|
||||
@@ -209,8 +209,8 @@ switch (adapter.log.level) {
|
||||
|
||||
adapter.sendTo("foo.0", "command", "message");
|
||||
adapter.sendTo("foo.0", "message");
|
||||
adapter.sendTo("foo.0", "command", {msg: "message"});
|
||||
adapter.sendTo("foo.0", {msg: "message"});
|
||||
adapter.sendTo("foo.0", "command", { msg: "message" });
|
||||
adapter.sendTo("foo.0", { msg: "message" });
|
||||
|
||||
function handleMessageResponse(response?: ioBroker.Message) {
|
||||
if (!response) return;
|
||||
@@ -226,28 +226,28 @@ function handleMessageResponse(response?: ioBroker.Message) {
|
||||
}
|
||||
adapter.sendTo("foo.0", "command", "message", handleMessageResponse);
|
||||
adapter.sendTo("foo.0", "message", handleMessageResponse);
|
||||
adapter.sendTo("foo.0", "command", {msg: "message"}, handleMessageResponse);
|
||||
adapter.sendTo("foo.0", {msg: "message"}, handleMessageResponse);
|
||||
adapter.sendTo("foo.0", "command", { msg: "message" }, handleMessageResponse);
|
||||
adapter.sendTo("foo.0", { msg: "message" }, handleMessageResponse);
|
||||
|
||||
adapter.sendToAsync("foo.0", "command", "message").then(handleMessageResponse);
|
||||
adapter.sendToAsync("foo.0", "message").then(handleMessageResponse);
|
||||
adapter.sendToAsync("foo.0", "command", {msg: "message"}).then(handleMessageResponse);
|
||||
adapter.sendToAsync("foo.0", {msg: "message"}).then(handleMessageResponse);
|
||||
adapter.sendToAsync("foo.0", "command", { msg: "message" }).then(handleMessageResponse);
|
||||
adapter.sendToAsync("foo.0", { msg: "message" }).then(handleMessageResponse);
|
||||
|
||||
adapter.sendToHost("host-foo", "command", "message");
|
||||
adapter.sendToHost("host-foo", "message");
|
||||
adapter.sendToHost("host-foo", "command", {msg: "message"});
|
||||
adapter.sendToHost("host-foo", {msg: "message"});
|
||||
adapter.sendToHost("host-foo", "command", { msg: "message" });
|
||||
adapter.sendToHost("host-foo", { msg: "message" });
|
||||
|
||||
adapter.sendToHost("host-foo", "command", "message", handleMessageResponse);
|
||||
adapter.sendToHost("host-foo", "message", handleMessageResponse);
|
||||
adapter.sendToHost("host-foo", "command", {msg: "message"}, handleMessageResponse);
|
||||
adapter.sendToHost("host-foo", {msg: "message"}, handleMessageResponse);
|
||||
adapter.sendToHost("host-foo", "command", { msg: "message" }, handleMessageResponse);
|
||||
adapter.sendToHost("host-foo", { msg: "message" }, handleMessageResponse);
|
||||
|
||||
adapter.sendToHostAsync("host-foo", "command", "message").then(handleMessageResponse);
|
||||
adapter.sendToHostAsync("host-foo", "message").then(handleMessageResponse);
|
||||
adapter.sendToHostAsync("host-foo", "command", {msg: "message"}).then(handleMessageResponse);
|
||||
adapter.sendToHostAsync("host-foo", {msg: "message"}).then(handleMessageResponse);
|
||||
adapter.sendToHostAsync("host-foo", "command", { msg: "message" }).then(handleMessageResponse);
|
||||
adapter.sendToHostAsync("host-foo", { msg: "message" }).then(handleMessageResponse);
|
||||
|
||||
function handleError(err?: string) { }
|
||||
adapter.subscribeStates("*", handleError);
|
||||
@@ -259,3 +259,30 @@ adapter.subscribeStatesAsync("*").catch(handleError);
|
||||
adapter.subscribeForeignStatesAsync("*").catch(handleError);
|
||||
adapter.unsubscribeStatesAsync("*").catch(handleError);
|
||||
adapter.unsubscribeForeignStatesAsync("*").catch(handleError);
|
||||
|
||||
// Repro from https://github.com/ioBroker/adapter-core/issues/3
|
||||
const repro1: ioBroker.ObjectChangeHandler = (id, obj) => {
|
||||
if (!obj || !obj.common) return;
|
||||
if (obj.common.custom) {
|
||||
const test1: ioBroker.StateCommon = obj.common;
|
||||
}
|
||||
obj
|
||||
&& obj.common
|
||||
&& obj.common.custom
|
||||
&& obj.common.custom["adapter.0"]
|
||||
&& obj.common.custom["adapter.0"].enabled
|
||||
;
|
||||
};
|
||||
|
||||
// Repro from https://github.com/ioBroker/adapter-core/issues/4
|
||||
function repro2() {
|
||||
// Prepare custom object
|
||||
const obj = {
|
||||
common: {
|
||||
custom: {
|
||||
"adapter.namespace": { start_day: null as any }
|
||||
}
|
||||
}
|
||||
};
|
||||
adapter.extendForeignObject("obj.id", obj, (err) => { });
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -8,8 +8,8 @@
|
||||
/** This library provides IRC client functionality. */
|
||||
|
||||
import events = require('events');
|
||||
import crypto = require('crypto');
|
||||
import net = require('net');
|
||||
import tls = require('tls');
|
||||
|
||||
/** This library provides IRC client functionality. */
|
||||
declare namespace NodeIRC {
|
||||
@@ -287,7 +287,7 @@ declare namespace NodeIRC {
|
||||
* Should SSL be used? Can either be true or crypto credentials.
|
||||
* @default false
|
||||
*/
|
||||
secure?: boolean | crypto.Credentials;
|
||||
secure?: boolean | tls.SecureContext;
|
||||
|
||||
/**
|
||||
* Should we accept self-signed certificates?
|
||||
|
||||
Vendored
+6
-3
@@ -213,9 +213,9 @@ declare namespace jest {
|
||||
* spy.mockRestore();
|
||||
* });
|
||||
*/
|
||||
function spyOn<T extends {}, M extends keyof T>(object: T, method: M, accessType: 'get'): SpyInstance<T[M], []>;
|
||||
function spyOn<T extends {}, M extends keyof T>(object: T, method: M, accessType: 'set'): SpyInstance<void, [T[M]]>;
|
||||
function spyOn<T extends {}, M extends keyof T>(object: T, method: M): T[M] extends (...args: any[]) => any ? SpyInstance<ReturnType<T[M]>, ArgsType<T[M]>> : never;
|
||||
function spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, method: M, accessType: 'get'): SpyInstance<T[M], []>;
|
||||
function spyOn<T extends {}, M extends NonFunctionPropertyNames<T>>(object: T, method: M, accessType: 'set'): SpyInstance<void, [T[M]]>;
|
||||
function spyOn<T extends {}, M extends FunctionPropertyNames<T>>(object: T, method: M): T[M] extends (...args: any[]) => any ? SpyInstance<ReturnType<T[M]>, ArgsType<T[M]>> : never;
|
||||
/**
|
||||
* Indicates that the module system should never return a mocked version of
|
||||
* the specified module from require() (e.g. that it should always return the real module).
|
||||
@@ -238,6 +238,9 @@ declare namespace jest {
|
||||
type ArgsType<T> = T extends (...args: infer A) => any ? A : never;
|
||||
type RejectedValue<T> = T extends PromiseLike<any> ? any : never;
|
||||
type ResolvedValue<T> = T extends PromiseLike<infer U> ? U | T : never;
|
||||
// see https://github.com/Microsoft/TypeScript/issues/25215
|
||||
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends (...args: any[]) => any ? never : K }[keyof T] & string;
|
||||
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never }[keyof T] & string;
|
||||
|
||||
interface DoneCallback {
|
||||
(...args: any[]): any;
|
||||
|
||||
@@ -360,24 +360,35 @@ const spiedTarget = {
|
||||
|
||||
class SpiedTargetClass {
|
||||
private _value = 3;
|
||||
private _value2 = '';
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
set value(value) {
|
||||
this._value = value;
|
||||
}
|
||||
get value2() {
|
||||
return this._value2;
|
||||
}
|
||||
set value2(value2) {
|
||||
this._value2 = value2;
|
||||
}
|
||||
}
|
||||
const spiedTarget2 = new SpiedTargetClass();
|
||||
|
||||
// $ExpectError
|
||||
jest.spyOn(spiedTarget, "setValue", "get");
|
||||
// $ExpectError
|
||||
jest.spyOn(spiedTarget2, "value");
|
||||
|
||||
const spy1 = jest.spyOn(spiedTarget, "returnsVoid");
|
||||
const spy2 = jest.spyOn(spiedTarget, "returnsVoid", "get");
|
||||
const spy3 = jest.spyOn(spiedTarget, "returnsString");
|
||||
const spy1Name: string = spy1.getMockName();
|
||||
|
||||
const spy2Calls: any[][] = spy2.mock.calls;
|
||||
const spy1Calls: Array<[]> = spy1.mock.calls;
|
||||
|
||||
spy2.mockClear();
|
||||
spy2.mockReset();
|
||||
spy1.mockClear();
|
||||
spy1.mockReset();
|
||||
|
||||
const spy3Mock = spy3
|
||||
.mockImplementation(() => "")
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// Type definitions for jscodeshift 0.6
|
||||
// Project: https://github.com/facebook/jscodeshift#readme
|
||||
// Definitions by: Brie Bunge <https://github.com/brieb>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
import core = require("./src/core");
|
||||
|
||||
export = core;
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"ast-types": "0.12.1",
|
||||
"recast": "0.17.2"
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import recast = require("recast");
|
||||
import JSXElement = require("./collections/JSXElement");
|
||||
import NodeCollection = require("./collections/Node");
|
||||
import VariableDeclarator = require("./collections/VariableDeclarator");
|
||||
|
||||
type ASTPath<N> = recast.NodePath<N, N>;
|
||||
|
||||
export interface Collection<N>
|
||||
extends NodeCollection.TraversalMethods,
|
||||
NodeCollection.MutationMethods<N>,
|
||||
VariableDeclarator.GlobalMethods,
|
||||
VariableDeclarator.TransformMethods<N>,
|
||||
JSXElement.GlobalMethods,
|
||||
JSXElement.TraversalMethods {
|
||||
/**
|
||||
* @param paths An array of AST paths
|
||||
* @param parent A parent collection
|
||||
* @param types An array of types all the paths in the collection
|
||||
* have in common. If not passed, it will be inferred from the paths.
|
||||
*/
|
||||
new (paths: Array<ASTPath<N>>, parent: Collection<any>, types?: Array<recast.Type<any>>): this;
|
||||
|
||||
/**
|
||||
* Returns a new collection containing the nodes for which the callback returns true.
|
||||
*/
|
||||
filter<S extends N>(
|
||||
callback: (path: ASTPath<N>, i: number, paths: Array<ASTPath<N>>) => path is ASTPath<S>
|
||||
): Collection<S>;
|
||||
filter(
|
||||
callback: (path: ASTPath<N>, i: number, paths: Array<ASTPath<N>>) => boolean
|
||||
): Collection<N>;
|
||||
|
||||
/**
|
||||
* Executes callback for each node/path in the collection.
|
||||
*/
|
||||
forEach(callback: (path: ASTPath<N>, i: number, paths: Array<ASTPath<N>>) => void): this;
|
||||
|
||||
/**
|
||||
* Tests whether at-least one path passes the test implemented by the provided callback.
|
||||
*/
|
||||
some(callback: (path: ASTPath<N>, i: number, paths: Array<ASTPath<N>>) => boolean): boolean;
|
||||
|
||||
/**
|
||||
* Tests whether all paths pass the test implemented by the provided callback.
|
||||
*/
|
||||
every(callback: (path: ASTPath<N>, i: number, paths: Array<ASTPath<N>>) => boolean): boolean;
|
||||
|
||||
/**
|
||||
* Executes the callback for every path in the collection and returns a new
|
||||
* collection from the return values (which must be paths).
|
||||
*
|
||||
* The callback can return null to indicate to exclude the element from the
|
||||
* new collection.
|
||||
*
|
||||
* If an array is returned, the array will be flattened into the result
|
||||
* collection.
|
||||
*
|
||||
* @param callback
|
||||
* @param type Force the new collection to be of a specific type
|
||||
*/
|
||||
map<T = recast.ASTNode>(
|
||||
callback: (
|
||||
path: ASTPath<N>,
|
||||
i: number,
|
||||
paths: Array<ASTPath<N>>
|
||||
) => ASTPath<T> | Array<ASTPath<T>> | null | undefined,
|
||||
type: recast.Type<any>
|
||||
): Collection<T>;
|
||||
|
||||
/** Returns the number of elements in this collection. */
|
||||
size(): number;
|
||||
|
||||
/** Returns the number of elements in this collection. */
|
||||
length: number;
|
||||
|
||||
/** Returns an array of AST nodes in this collection. */
|
||||
nodes(): N[];
|
||||
|
||||
/** Returns an array of ASTPaths in this this collection. */
|
||||
paths(): Array<ASTPath<N>>;
|
||||
|
||||
getAST(): Array<ASTPath<any>>;
|
||||
|
||||
/**
|
||||
* Converts the AST back to a string, using recast.
|
||||
* @param options directly passed to recast's printer
|
||||
*/
|
||||
toSource(options?: recast.Options): string;
|
||||
|
||||
/**
|
||||
* Returns a new collection containing only the element at position index.
|
||||
* In case of a negative index, the element is taken from the end:
|
||||
* .at(0) - first element
|
||||
* .at(-1) - last element
|
||||
*/
|
||||
at(index: number): Collection<N>;
|
||||
|
||||
/** Calls "get" on the first path (same as "collection.paths(0).get(...)"). */
|
||||
get(...fields: Array<string | number>): any;
|
||||
|
||||
/**
|
||||
* Returns the type(s) of the collection. This is only used for unit tests,
|
||||
* don't think other consumers would need it.
|
||||
*/
|
||||
getTypes(): string[];
|
||||
|
||||
/**
|
||||
* Returns true if this collection has the type 'type'.
|
||||
*/
|
||||
isOfType(type: recast.Type<any>): boolean;
|
||||
}
|
||||
|
||||
export function fromPaths(...args: any[]): any;
|
||||
|
||||
export function fromNodes(...args: any[]): any;
|
||||
|
||||
/**
|
||||
* This function adds the provided methods to the prototype of the corresponding
|
||||
* typed collection. If no type is passed, the methods are added to
|
||||
* Collection.prototype and are available for all collections.
|
||||
*
|
||||
* @param methods Methods to add to the prototype
|
||||
* @param type Optional type to add the methods to
|
||||
*/
|
||||
export function registerMethods(methods: object, type?: recast.Type<any>): void;
|
||||
|
||||
export function hasConflictingRegistration(...args: any[]): any;
|
||||
|
||||
export function setDefaultCollectionType(...args: any[]): any;
|
||||
|
||||
export {}; // shut off automatic exporting
|
||||
@@ -0,0 +1,71 @@
|
||||
import nodes = require("ast-types/gen/nodes");
|
||||
import recast = require("recast");
|
||||
import Collection = require("../Collection");
|
||||
|
||||
type ASTPath<N> = recast.NodePath<N, N>;
|
||||
type JSXElement = nodes.JSXElement;
|
||||
|
||||
export interface GlobalMethods {
|
||||
/**
|
||||
* Finds all JSXElements optionally filtered by name
|
||||
*/
|
||||
findJSXElements(name?: string): Collection.Collection<JSXElement>;
|
||||
|
||||
/**
|
||||
* Finds all JSXElements by module name. Given
|
||||
*
|
||||
* var Bar = require('Foo');
|
||||
* <Bar />
|
||||
*
|
||||
* findJSXElementsByModuleName('Foo') will find <Bar />, without having to
|
||||
* know the variable name.
|
||||
*/
|
||||
findJSXElementsByModuleName(moduleName: string): Collection.Collection<JSXElement>;
|
||||
}
|
||||
|
||||
type Defined<T> = T extends undefined ? never : T;
|
||||
type JSXElementChild = Defined<JSXElement["children"]>[0];
|
||||
|
||||
export interface TraversalMethods {
|
||||
/**
|
||||
* Returns all child nodes, including literals and expressions.
|
||||
* This method only applies to JSXElement typed collections.
|
||||
*/
|
||||
childNodes(): Collection.Collection<JSXElementChild>;
|
||||
|
||||
/**
|
||||
* Returns all children that are JSXElements.
|
||||
* This method only applies to JSXElement typed collections.
|
||||
*/
|
||||
childElements(): Collection.Collection<JSXElement>;
|
||||
}
|
||||
|
||||
interface Filter {
|
||||
(path: ASTPath<any>): boolean;
|
||||
}
|
||||
|
||||
export interface FilterMethods {
|
||||
/**
|
||||
* Filter method for attributes.
|
||||
*/
|
||||
hasAttributes(attributeFilter: { [attributeName: string]: any }): Filter;
|
||||
|
||||
/**
|
||||
* Filter elements which contain a specific child type
|
||||
*/
|
||||
hasChildren(name: string): Filter;
|
||||
}
|
||||
|
||||
export interface MappingMethods {
|
||||
/**
|
||||
* Given a JSXElement, returns its "root" name. E.g. it would return "Foo" for
|
||||
* both <Foo /> and <Foo.Bar />.
|
||||
*/
|
||||
getRootName(path: ASTPath<any>): string;
|
||||
}
|
||||
|
||||
export function register(): void;
|
||||
export const filters: FilterMethods;
|
||||
export const mappings: MappingMethods;
|
||||
|
||||
export {}; // shut off automatic exporting
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
import nodes = require("ast-types/gen/nodes");
|
||||
import recast = require("recast");
|
||||
import Collection = require("../Collection");
|
||||
|
||||
type ASTPath<N> = recast.NodePath<N, N>;
|
||||
|
||||
export interface TraversalMethods {
|
||||
/**
|
||||
* Find nodes of a specific type within the nodes of this collection.
|
||||
*/
|
||||
find<T>(type: recast.Type<T>, filter?: ((value: any) => boolean) | object): Collection.Collection<T>;
|
||||
|
||||
/**
|
||||
* Returns a collection containing the paths that create the scope of the
|
||||
* currently selected paths. Dedupes the paths.
|
||||
*/
|
||||
closestScope(): Collection.Collection<nodes.ASTNode>;
|
||||
|
||||
/**
|
||||
* Traverse the AST up and finds the closest node of the provided type.
|
||||
*/
|
||||
closest<T>(type: recast.Type<T>, filter?: any): Collection.Collection<T>;
|
||||
|
||||
/**
|
||||
* Finds the declaration for each selected path. Useful for member expressions
|
||||
* or JSXElements. Expects a callback function that maps each path to the name
|
||||
* to look for.
|
||||
*
|
||||
* If the callback returns a falsy value, the element is skipped.
|
||||
*/
|
||||
getVariableDeclarators(nameGetter: (...args: any[]) => any): Collection.Collection<nodes.VariableDeclarator>;
|
||||
}
|
||||
|
||||
export interface MutationMethods<N> {
|
||||
/**
|
||||
* Simply replaces the selected nodes with the provided node. If a function
|
||||
* is provided it is executed for every node and the node is replaced with the
|
||||
* functions return value.
|
||||
*/
|
||||
replaceWith<T>(nodes: T | T[] | ((path: ASTPath<N>, i: number) => T)): Collection.Collection<T>;
|
||||
|
||||
/**
|
||||
* Inserts a new node before the current one.
|
||||
*/
|
||||
insertBefore(insert: any): Collection.Collection<N>;
|
||||
|
||||
/**
|
||||
* Inserts a new node after the current one.
|
||||
*/
|
||||
insertAfter(insert: any): Collection.Collection<N>;
|
||||
|
||||
remove(): Collection.Collection<N>;
|
||||
}
|
||||
|
||||
export function register(): void;
|
||||
|
||||
export {}; // shut off automatic exporting
|
||||
@@ -0,0 +1,39 @@
|
||||
import nodes = require("ast-types/gen/nodes");
|
||||
import recast = require("recast");
|
||||
import Collection = require("../Collection");
|
||||
|
||||
type ASTPath<N> = recast.NodePath<N, N>;
|
||||
|
||||
export interface GlobalMethods {
|
||||
/**
|
||||
* Finds all variable declarators, optionally filtered by name.
|
||||
*/
|
||||
findVariableDeclarators(name?: string): Collection.Collection<nodes.VariableDeclarator>;
|
||||
}
|
||||
|
||||
export interface TransformMethods<N> {
|
||||
/**
|
||||
* Renames a variable and all its occurrences.
|
||||
* This method only applies to VariableDeclarator typed collections.
|
||||
*/
|
||||
renameTo(newName: string): Collection.Collection<N>;
|
||||
}
|
||||
|
||||
interface Filter {
|
||||
(path: ASTPath<any>): boolean;
|
||||
}
|
||||
|
||||
export interface FilterMethods {
|
||||
/**
|
||||
* Returns a function that returns true if the provided path is a variable
|
||||
* declarator and requires one of the specified module names.
|
||||
*
|
||||
* @param names A module name or an array of module names
|
||||
*/
|
||||
requiresModule(names: string | string[]): Filter;
|
||||
}
|
||||
|
||||
export function register(): void;
|
||||
export const filters: FilterMethods;
|
||||
|
||||
export {}; // shut off automatic exporting
|
||||
Vendored
+363
@@ -0,0 +1,363 @@
|
||||
import nodes = require("ast-types/gen/nodes");
|
||||
import recast = require("recast");
|
||||
import Collection = require("./Collection");
|
||||
import template = require("./template");
|
||||
import VariableDeclarator = require("./collections/VariableDeclarator");
|
||||
import JSXElement = require("./collections/JSXElement");
|
||||
|
||||
declare namespace core {
|
||||
type Parser = recast.Parser;
|
||||
|
||||
interface Filters {
|
||||
JSXElement: JSXElement.FilterMethods;
|
||||
VariableDeclarator: VariableDeclarator.FilterMethods;
|
||||
}
|
||||
|
||||
interface Mappings {
|
||||
JSXElement: JSXElement.MappingMethods;
|
||||
}
|
||||
|
||||
interface Plugin {
|
||||
(core: Core): void;
|
||||
}
|
||||
|
||||
interface FileInfo {
|
||||
/** The absolute path to the current file. */
|
||||
path: string;
|
||||
/** The source code of the current file. */
|
||||
source: string;
|
||||
}
|
||||
|
||||
interface Stats {
|
||||
/**
|
||||
* Helper function to collect data during --dry runs.
|
||||
* This function keeps a counter for how often it was called with a specific argument.
|
||||
* The result is shown in the console. Useful for finding out how many files match a criterion.
|
||||
*/
|
||||
(name: string, quantity?: number): void;
|
||||
}
|
||||
|
||||
type ASTPath<N = ASTNode> = recast.NodePath<N, N>;
|
||||
|
||||
interface Core {
|
||||
(source: string, options?: Options): Collection.Collection<any>;
|
||||
(source: ASTNode | ASTNode[] | ASTPath | ASTPath[]): Collection.Collection<any>;
|
||||
|
||||
registerMethods: typeof Collection.registerMethods;
|
||||
|
||||
types: typeof recast.default.types;
|
||||
|
||||
match(
|
||||
path: ASTNode | ASTPath,
|
||||
filter: ((path: ASTNode) => boolean) | ASTNode
|
||||
): boolean;
|
||||
|
||||
/** template, bound to default parser */
|
||||
template: template.Template;
|
||||
|
||||
filters: Filters;
|
||||
|
||||
mappings: Mappings;
|
||||
|
||||
/**
|
||||
* Utility function for registering plugins.
|
||||
*
|
||||
* Plugins are simple functions that are passed the core jscodeshift instance.
|
||||
* They should extend jscodeshift by calling `registerMethods`, etc.
|
||||
* This method guards against repeated registrations (the plugin callback will only be called once).
|
||||
*/
|
||||
use(plugin: Plugin): void;
|
||||
|
||||
/**
|
||||
* Returns a version of the core jscodeshift function "bound" to a specific
|
||||
* parser.
|
||||
*/
|
||||
withParser(parser: string | Parser): JSCodeshift;
|
||||
}
|
||||
|
||||
type JSCodeshift = Core & recast.NamedTypes & recast.Builders;
|
||||
|
||||
interface API {
|
||||
j: JSCodeshift;
|
||||
jscodeshift: JSCodeshift;
|
||||
stats: Stats;
|
||||
report: (msg: string) => void;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
[option: string]: any;
|
||||
}
|
||||
|
||||
interface Transform {
|
||||
/**
|
||||
* If a string is returned and it is different from passed source, the transform is considered to be successful.
|
||||
* If a string is returned but it's the same as the source, the transform is considered to be unsuccessful.
|
||||
* If nothing is returned, the file is not supposed to be transformed (which is ok).
|
||||
*/
|
||||
(file: FileInfo, api: API, options: Options): string | null | undefined | void;
|
||||
}
|
||||
|
||||
type ASTNode = nodes.ASTNode;
|
||||
|
||||
type AnyTypeAnnotation = nodes.AnyTypeAnnotation;
|
||||
type ArrayExpression = nodes.ArrayExpression;
|
||||
type ArrayPattern = nodes.ArrayPattern;
|
||||
type ArrayTypeAnnotation = nodes.ArrayTypeAnnotation;
|
||||
type ArrowFunctionExpression = nodes.ArrowFunctionExpression;
|
||||
type AssignmentExpression = nodes.AssignmentExpression;
|
||||
type AssignmentPattern = nodes.AssignmentPattern;
|
||||
type AwaitExpression = nodes.AwaitExpression;
|
||||
type BigIntLiteral = nodes.BigIntLiteral;
|
||||
type BinaryExpression = nodes.BinaryExpression;
|
||||
type BindExpression = nodes.BindExpression;
|
||||
type Block = nodes.Block;
|
||||
type BlockStatement = nodes.BlockStatement;
|
||||
type BooleanLiteral = nodes.BooleanLiteral;
|
||||
type BooleanLiteralTypeAnnotation = nodes.BooleanLiteralTypeAnnotation;
|
||||
type BooleanTypeAnnotation = nodes.BooleanTypeAnnotation;
|
||||
type BreakStatement = nodes.BreakStatement;
|
||||
type CallExpression = nodes.CallExpression;
|
||||
type CatchClause = nodes.CatchClause;
|
||||
type ClassBody = nodes.ClassBody;
|
||||
type ClassDeclaration = nodes.ClassDeclaration;
|
||||
type ClassExpression = nodes.ClassExpression;
|
||||
type ClassImplements = nodes.ClassImplements;
|
||||
type ClassMethod = nodes.ClassMethod;
|
||||
type ClassPrivateMethod = nodes.ClassPrivateMethod;
|
||||
type ClassPrivateProperty = nodes.ClassPrivateProperty;
|
||||
type ClassProperty = nodes.ClassProperty;
|
||||
type ClassPropertyDefinition = nodes.ClassPropertyDefinition;
|
||||
type Comment = nodes.Comment;
|
||||
type CommentBlock = nodes.CommentBlock;
|
||||
type CommentLine = nodes.CommentLine;
|
||||
type ComprehensionBlock = nodes.ComprehensionBlock;
|
||||
type ComprehensionExpression = nodes.ComprehensionExpression;
|
||||
type ConditionalExpression = nodes.ConditionalExpression;
|
||||
type ContinueStatement = nodes.ContinueStatement;
|
||||
type DebuggerStatement = nodes.DebuggerStatement;
|
||||
type Declaration = nodes.Declaration;
|
||||
type DeclareClass = nodes.DeclareClass;
|
||||
type DeclaredPredicate = nodes.DeclaredPredicate;
|
||||
type DeclareExportAllDeclaration = nodes.DeclareExportAllDeclaration;
|
||||
type DeclareExportDeclaration = nodes.DeclareExportDeclaration;
|
||||
type DeclareFunction = nodes.DeclareFunction;
|
||||
type DeclareInterface = nodes.DeclareInterface;
|
||||
type DeclareModule = nodes.DeclareModule;
|
||||
type DeclareModuleExports = nodes.DeclareModuleExports;
|
||||
type DeclareOpaqueType = nodes.DeclareOpaqueType;
|
||||
type DeclareTypeAlias = nodes.DeclareTypeAlias;
|
||||
type DeclareVariable = nodes.DeclareVariable;
|
||||
type Decorator = nodes.Decorator;
|
||||
type Directive = nodes.Directive;
|
||||
type DirectiveLiteral = nodes.DirectiveLiteral;
|
||||
type DoExpression = nodes.DoExpression;
|
||||
type DoWhileStatement = nodes.DoWhileStatement;
|
||||
type EmptyStatement = nodes.EmptyStatement;
|
||||
type EmptyTypeAnnotation = nodes.EmptyTypeAnnotation;
|
||||
type ExistentialTypeParam = nodes.ExistentialTypeParam;
|
||||
type ExistsTypeAnnotation = nodes.ExistsTypeAnnotation;
|
||||
type ExportAllDeclaration = nodes.ExportAllDeclaration;
|
||||
type ExportBatchSpecifier = nodes.ExportBatchSpecifier;
|
||||
type ExportDeclaration = nodes.ExportDeclaration;
|
||||
type ExportDefaultDeclaration = nodes.ExportDefaultDeclaration;
|
||||
type ExportDefaultSpecifier = nodes.ExportDefaultSpecifier;
|
||||
type ExportNamedDeclaration = nodes.ExportNamedDeclaration;
|
||||
type ExportNamespaceSpecifier = nodes.ExportNamespaceSpecifier;
|
||||
type ExportSpecifier = nodes.ExportSpecifier;
|
||||
type Expression = nodes.Expression;
|
||||
type ExpressionStatement = nodes.ExpressionStatement;
|
||||
type File = nodes.File;
|
||||
type Flow = nodes.Flow;
|
||||
type FlowPredicate = nodes.FlowPredicate;
|
||||
type FlowType = nodes.FlowType;
|
||||
type ForAwaitStatement = nodes.ForAwaitStatement;
|
||||
type ForInStatement = nodes.ForInStatement;
|
||||
type ForOfStatement = nodes.ForOfStatement;
|
||||
type ForStatement = nodes.ForStatement;
|
||||
type Function = nodes.Function;
|
||||
type FunctionDeclaration = nodes.FunctionDeclaration;
|
||||
type FunctionExpression = nodes.FunctionExpression;
|
||||
type FunctionTypeAnnotation = nodes.FunctionTypeAnnotation;
|
||||
type FunctionTypeParam = nodes.FunctionTypeParam;
|
||||
type GeneratorExpression = nodes.GeneratorExpression;
|
||||
type GenericTypeAnnotation = nodes.GenericTypeAnnotation;
|
||||
type Identifier = nodes.Identifier;
|
||||
type IfStatement = nodes.IfStatement;
|
||||
type Import = nodes.Import;
|
||||
type ImportDeclaration = nodes.ImportDeclaration;
|
||||
type ImportDefaultSpecifier = nodes.ImportDefaultSpecifier;
|
||||
type ImportNamespaceSpecifier = nodes.ImportNamespaceSpecifier;
|
||||
type ImportSpecifier = nodes.ImportSpecifier;
|
||||
type InferredPredicate = nodes.InferredPredicate;
|
||||
type InterfaceDeclaration = nodes.InterfaceDeclaration;
|
||||
type InterfaceExtends = nodes.InterfaceExtends;
|
||||
type InterfaceTypeAnnotation = nodes.InterfaceTypeAnnotation;
|
||||
type InterpreterDirective = nodes.InterpreterDirective;
|
||||
type IntersectionTypeAnnotation = nodes.IntersectionTypeAnnotation;
|
||||
type JSXAttribute = nodes.JSXAttribute;
|
||||
type JSXClosingElement = nodes.JSXClosingElement;
|
||||
type JSXClosingFragment = nodes.JSXClosingFragment;
|
||||
type JSXElement = nodes.JSXElement;
|
||||
type JSXEmptyExpression = nodes.JSXEmptyExpression;
|
||||
type JSXExpressionContainer = nodes.JSXExpressionContainer;
|
||||
type JSXFragment = nodes.JSXFragment;
|
||||
type JSXIdentifier = nodes.JSXIdentifier;
|
||||
type JSXMemberExpression = nodes.JSXMemberExpression;
|
||||
type JSXNamespacedName = nodes.JSXNamespacedName;
|
||||
type JSXOpeningElement = nodes.JSXOpeningElement;
|
||||
type JSXOpeningFragment = nodes.JSXOpeningFragment;
|
||||
type JSXSpreadAttribute = nodes.JSXSpreadAttribute;
|
||||
type JSXSpreadChild = nodes.JSXSpreadChild;
|
||||
type JSXText = nodes.JSXText;
|
||||
type LabeledStatement = nodes.LabeledStatement;
|
||||
type Line = nodes.Line;
|
||||
type Literal = nodes.Literal;
|
||||
type LogicalExpression = nodes.LogicalExpression;
|
||||
type MemberExpression = nodes.MemberExpression;
|
||||
type MemberTypeAnnotation = nodes.MemberTypeAnnotation;
|
||||
type MetaProperty = nodes.MetaProperty;
|
||||
type MethodDefinition = nodes.MethodDefinition;
|
||||
type MixedTypeAnnotation = nodes.MixedTypeAnnotation;
|
||||
type ModuleSpecifier = nodes.ModuleSpecifier;
|
||||
type NewExpression = nodes.NewExpression;
|
||||
type Node = nodes.Node;
|
||||
type Noop = nodes.Noop;
|
||||
type NullableTypeAnnotation = nodes.NullableTypeAnnotation;
|
||||
type NullLiteral = nodes.NullLiteral;
|
||||
type NullLiteralTypeAnnotation = nodes.NullLiteralTypeAnnotation;
|
||||
type NullTypeAnnotation = nodes.NullTypeAnnotation;
|
||||
type NumberLiteralTypeAnnotation = nodes.NumberLiteralTypeAnnotation;
|
||||
type NumberTypeAnnotation = nodes.NumberTypeAnnotation;
|
||||
type NumericLiteral = nodes.NumericLiteral;
|
||||
type NumericLiteralTypeAnnotation = nodes.NumericLiteralTypeAnnotation;
|
||||
type ObjectExpression = nodes.ObjectExpression;
|
||||
type ObjectMethod = nodes.ObjectMethod;
|
||||
type ObjectPattern = nodes.ObjectPattern;
|
||||
type ObjectProperty = nodes.ObjectProperty;
|
||||
type ObjectTypeAnnotation = nodes.ObjectTypeAnnotation;
|
||||
type ObjectTypeCallProperty = nodes.ObjectTypeCallProperty;
|
||||
type ObjectTypeIndexer = nodes.ObjectTypeIndexer;
|
||||
type ObjectTypeInternalSlot = nodes.ObjectTypeInternalSlot;
|
||||
type ObjectTypeProperty = nodes.ObjectTypeProperty;
|
||||
type ObjectTypeSpreadProperty = nodes.ObjectTypeSpreadProperty;
|
||||
type OpaqueType = nodes.OpaqueType;
|
||||
type OptionalCallExpression = nodes.OptionalCallExpression;
|
||||
type OptionalMemberExpression = nodes.OptionalMemberExpression;
|
||||
type ParenthesizedExpression = nodes.ParenthesizedExpression;
|
||||
type Pattern = nodes.Pattern;
|
||||
type Position = nodes.Position;
|
||||
type Printable = nodes.Printable;
|
||||
type PrivateName = nodes.PrivateName;
|
||||
type Program = nodes.Program;
|
||||
type Property = nodes.Property;
|
||||
type PropertyPattern = nodes.PropertyPattern;
|
||||
type QualifiedTypeIdentifier = nodes.QualifiedTypeIdentifier;
|
||||
type RegExpLiteral = nodes.RegExpLiteral;
|
||||
type RestElement = nodes.RestElement;
|
||||
type RestProperty = nodes.RestProperty;
|
||||
type ReturnStatement = nodes.ReturnStatement;
|
||||
type SequenceExpression = nodes.SequenceExpression;
|
||||
type SourceLocation = nodes.SourceLocation;
|
||||
type Specifier = nodes.Specifier;
|
||||
type SpreadElement = nodes.SpreadElement;
|
||||
type SpreadElementPattern = nodes.SpreadElementPattern;
|
||||
type SpreadProperty = nodes.SpreadProperty;
|
||||
type SpreadPropertyPattern = nodes.SpreadPropertyPattern;
|
||||
type Statement = nodes.Statement;
|
||||
type StringLiteral = nodes.StringLiteral;
|
||||
type StringLiteralTypeAnnotation = nodes.StringLiteralTypeAnnotation;
|
||||
type StringTypeAnnotation = nodes.StringTypeAnnotation;
|
||||
type Super = nodes.Super;
|
||||
type SwitchCase = nodes.SwitchCase;
|
||||
type SwitchStatement = nodes.SwitchStatement;
|
||||
type TaggedTemplateExpression = nodes.TaggedTemplateExpression;
|
||||
type TemplateElement = nodes.TemplateElement;
|
||||
type TemplateLiteral = nodes.TemplateLiteral;
|
||||
type ThisExpression = nodes.ThisExpression;
|
||||
type ThisTypeAnnotation = nodes.ThisTypeAnnotation;
|
||||
type ThrowStatement = nodes.ThrowStatement;
|
||||
type TryStatement = nodes.TryStatement;
|
||||
type TSAnyKeyword = nodes.TSAnyKeyword;
|
||||
type TSArrayType = nodes.TSArrayType;
|
||||
type TSAsExpression = nodes.TSAsExpression;
|
||||
type TSBooleanKeyword = nodes.TSBooleanKeyword;
|
||||
type TSCallSignatureDeclaration = nodes.TSCallSignatureDeclaration;
|
||||
type TSConditionalType = nodes.TSConditionalType;
|
||||
type TSConstructorType = nodes.TSConstructorType;
|
||||
type TSConstructSignatureDeclaration = nodes.TSConstructSignatureDeclaration;
|
||||
type TSDeclareFunction = nodes.TSDeclareFunction;
|
||||
type TSDeclareMethod = nodes.TSDeclareMethod;
|
||||
type TSEnumDeclaration = nodes.TSEnumDeclaration;
|
||||
type TSEnumMember = nodes.TSEnumMember;
|
||||
type TSExportAssignment = nodes.TSExportAssignment;
|
||||
type TSExpressionWithTypeArguments = nodes.TSExpressionWithTypeArguments;
|
||||
type TSExternalModuleReference = nodes.TSExternalModuleReference;
|
||||
type TSFunctionType = nodes.TSFunctionType;
|
||||
type TSHasOptionalTypeAnnotation = nodes.TSHasOptionalTypeAnnotation;
|
||||
type TSHasOptionalTypeParameters = nodes.TSHasOptionalTypeParameters;
|
||||
type TSImportEqualsDeclaration = nodes.TSImportEqualsDeclaration;
|
||||
type TSIndexedAccessType = nodes.TSIndexedAccessType;
|
||||
type TSIndexSignature = nodes.TSIndexSignature;
|
||||
type TSInferType = nodes.TSInferType;
|
||||
type TSInterfaceBody = nodes.TSInterfaceBody;
|
||||
type TSInterfaceDeclaration = nodes.TSInterfaceDeclaration;
|
||||
type TSIntersectionType = nodes.TSIntersectionType;
|
||||
type TSLiteralType = nodes.TSLiteralType;
|
||||
type TSMappedType = nodes.TSMappedType;
|
||||
type TSMethodSignature = nodes.TSMethodSignature;
|
||||
type TSModuleBlock = nodes.TSModuleBlock;
|
||||
type TSModuleDeclaration = nodes.TSModuleDeclaration;
|
||||
type TSNamespaceExportDeclaration = nodes.TSNamespaceExportDeclaration;
|
||||
type TSNeverKeyword = nodes.TSNeverKeyword;
|
||||
type TSNonNullExpression = nodes.TSNonNullExpression;
|
||||
type TSNullKeyword = nodes.TSNullKeyword;
|
||||
type TSNumberKeyword = nodes.TSNumberKeyword;
|
||||
type TSObjectKeyword = nodes.TSObjectKeyword;
|
||||
type TSOptionalType = nodes.TSOptionalType;
|
||||
type TSParameterProperty = nodes.TSParameterProperty;
|
||||
type TSParenthesizedType = nodes.TSParenthesizedType;
|
||||
type TSPropertySignature = nodes.TSPropertySignature;
|
||||
type TSQualifiedName = nodes.TSQualifiedName;
|
||||
type TSRestType = nodes.TSRestType;
|
||||
type TSStringKeyword = nodes.TSStringKeyword;
|
||||
type TSSymbolKeyword = nodes.TSSymbolKeyword;
|
||||
type TSThisType = nodes.TSThisType;
|
||||
type TSTupleType = nodes.TSTupleType;
|
||||
type TSType = nodes.TSType;
|
||||
type TSTypeAliasDeclaration = nodes.TSTypeAliasDeclaration;
|
||||
type TSTypeAnnotation = nodes.TSTypeAnnotation;
|
||||
type TSTypeAssertion = nodes.TSTypeAssertion;
|
||||
type TSTypeLiteral = nodes.TSTypeLiteral;
|
||||
type TSTypeOperator = nodes.TSTypeOperator;
|
||||
type TSTypeParameter = nodes.TSTypeParameter;
|
||||
type TSTypeParameterDeclaration = nodes.TSTypeParameterDeclaration;
|
||||
type TSTypeParameterInstantiation = nodes.TSTypeParameterInstantiation;
|
||||
type TSTypePredicate = nodes.TSTypePredicate;
|
||||
type TSTypeQuery = nodes.TSTypeQuery;
|
||||
type TSTypeReference = nodes.TSTypeReference;
|
||||
type TSUndefinedKeyword = nodes.TSUndefinedKeyword;
|
||||
type TSUnionType = nodes.TSUnionType;
|
||||
type TSUnknownKeyword = nodes.TSUnknownKeyword;
|
||||
type TSVoidKeyword = nodes.TSVoidKeyword;
|
||||
type TupleTypeAnnotation = nodes.TupleTypeAnnotation;
|
||||
type TypeAlias = nodes.TypeAlias;
|
||||
type TypeAnnotation = nodes.TypeAnnotation;
|
||||
type TypeCastExpression = nodes.TypeCastExpression;
|
||||
type TypeofTypeAnnotation = nodes.TypeofTypeAnnotation;
|
||||
type TypeParameter = nodes.TypeParameter;
|
||||
type TypeParameterDeclaration = nodes.TypeParameterDeclaration;
|
||||
type TypeParameterInstantiation = nodes.TypeParameterInstantiation;
|
||||
type UnaryExpression = nodes.UnaryExpression;
|
||||
type UnionTypeAnnotation = nodes.UnionTypeAnnotation;
|
||||
type UpdateExpression = nodes.UpdateExpression;
|
||||
type VariableDeclaration = nodes.VariableDeclaration;
|
||||
type VariableDeclarator = nodes.VariableDeclarator;
|
||||
type Variance = nodes.Variance;
|
||||
type VoidTypeAnnotation = nodes.VoidTypeAnnotation;
|
||||
type WhileStatement = nodes.WhileStatement;
|
||||
type WithStatement = nodes.WithStatement;
|
||||
type YieldExpression = nodes.YieldExpression;
|
||||
}
|
||||
|
||||
declare const core: core.JSCodeshift;
|
||||
export = core;
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import recast = require("recast");
|
||||
|
||||
export = template;
|
||||
|
||||
declare const template: typeof withParser;
|
||||
|
||||
declare function withParser(parser: recast.Parser): template.Template;
|
||||
|
||||
declare namespace template {
|
||||
interface Template {
|
||||
/** Tagged template function. Parses the string as source and returns an array of Statement AST nodes. */
|
||||
statements(...args: any[]): any;
|
||||
/** Tagged template function. Parses the string as source and returns an Statement AST node. */
|
||||
statement(...args: any[]): any;
|
||||
/** Tagged template function. Parses the string as source and returns an Expression AST node. */
|
||||
expression(...args: any[]): any;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Sample jscodeshift transforms taken from https://github.com/jhgg/js-transforms
|
||||
and converted to TypeScript, for use as real-world test cases.
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* This transform converts stuff like:
|
||||
*
|
||||
* let x = this.foo.bind(this);
|
||||
*
|
||||
* to
|
||||
*
|
||||
* let x = ::this.foo;
|
||||
*
|
||||
*/
|
||||
import j = require("jscodeshift");
|
||||
|
||||
const transform: j.Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
return j(file.source)
|
||||
// Find stuff that looks like this.xyz.bind(this)
|
||||
.find(j.CallExpression, {callee: {object: {object: j.ThisExpression}, property: {name: 'bind'}}})
|
||||
// Ensure that .bind() is being called with only one argument, and that argument is "this".
|
||||
.filter(p => p.value.arguments.length === 1 && p.value.arguments[0].type === "ThisExpression")
|
||||
// We can now replace it with ::this.xyz
|
||||
.replaceWith(p => j.bindExpression(null, (p.value.callee as j.MemberExpression).object))
|
||||
.toSource();
|
||||
};
|
||||
|
||||
export = transform;
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Converts
|
||||
* onClick(function(a, b) {
|
||||
* return a + b;
|
||||
* }.bind(this),
|
||||
* function(b, c) {
|
||||
* return 1;
|
||||
* }.bind(this));
|
||||
*
|
||||
* onClick(function(a) {
|
||||
* var a = 1;
|
||||
* return a;
|
||||
* }.bind(this));
|
||||
*
|
||||
* var a = function(c) { return c; }.bind(this);
|
||||
*
|
||||
* to
|
||||
* onClick((a, b) => a + b,
|
||||
* (b, c) => 1);
|
||||
*
|
||||
* onClick(a => {
|
||||
* var a = 1;
|
||||
* return a;
|
||||
* });
|
||||
*
|
||||
* var a = c => c;
|
||||
*
|
||||
*/
|
||||
import { Transform, MemberExpression, FunctionExpression, ArrowFunctionExpression } from "jscodeshift";
|
||||
|
||||
const transform: Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
|
||||
return j(file.source)
|
||||
// We're looking for a CallExpression that's calling .bind() onto a FunctionExpression.
|
||||
.find(j.CallExpression, {callee: {property: {name: 'bind'}, object: {type: 'FunctionExpression'}}})
|
||||
// Verify that .bind() is only being called with `this` as it's sole arguments.
|
||||
.filter(p => p.value.arguments.length === 1 && p.value.arguments[0].type === "ThisExpression")
|
||||
.replaceWith(p => {
|
||||
const callee = p.value.callee as MemberExpression;
|
||||
const object = callee.object as FunctionExpression;
|
||||
// Grab the function body. Since we looked for the CallExpression originally, the "callee.object" would refer
|
||||
// to the FunctionExpression that's being called .bind(this) on. We need the body of that function
|
||||
// to transform into an ArrowFunctionExpression.
|
||||
let body: ArrowFunctionExpression['body'] = object.body;
|
||||
// We can get a bit clever here. If we have a function that consists of a single return statement in it's body,
|
||||
// we can transform it to the more compact arrowFunctionExpression (a, b) => a + b, vs (a + b) => { return a + b }
|
||||
let useExpression = false;
|
||||
if (body.type === 'BlockStatement' && body.body.length === 1) {
|
||||
const first = body.body[0];
|
||||
if (first.type === "ReturnStatement") {
|
||||
useExpression = true;
|
||||
body = first.argument!;
|
||||
}
|
||||
}
|
||||
|
||||
return j.arrowFunctionExpression(object.params, body, useExpression);
|
||||
})
|
||||
.toSource();
|
||||
};
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Converts a FunctionExpression to an ArrowFunctionExpression when safe to do so.
|
||||
*
|
||||
* var a = function(a, b) {
|
||||
* return a + b;
|
||||
* }
|
||||
*
|
||||
* var b = function(a, b) {
|
||||
* var c = 0;
|
||||
* return a + b + c;
|
||||
* }
|
||||
*
|
||||
* var a = function(a, b) {
|
||||
* return a + b + this.c;
|
||||
* }
|
||||
*
|
||||
* var a = (a, b) => a + b
|
||||
*
|
||||
* var b = (a, b) => {
|
||||
* var c = 0;
|
||||
* return a + b + c;
|
||||
* }
|
||||
*
|
||||
* var a = function(a, b) {
|
||||
* return a + b + this.c;
|
||||
* }
|
||||
*/
|
||||
import { Transform, ArrowFunctionExpression } from "jscodeshift";
|
||||
|
||||
const transform: Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
|
||||
return j(file.source)
|
||||
.find(j.FunctionExpression)
|
||||
// We check for this expression, as if it's in a function expression, we don't want to re-bind "this" by
|
||||
// using the arrowFunctionExpression. As that could potentially have some unintended consequences.
|
||||
.filter(p => j(p).find(j.ThisExpression).size() === 0)
|
||||
.replaceWith(p => {
|
||||
let body: ArrowFunctionExpression['body'] = p.value.body;
|
||||
// We can get a bit clever here. If we have a function that consists of a single return statement in it's body,
|
||||
// we can transform it to the more compact arrowFunctionExpression (a, b) => a + b, vs (a + b) => { return a + b }
|
||||
let useExpression = false;
|
||||
if (body.type === 'BlockStatement' && body.body.length === 1) {
|
||||
const first = body.body[0];
|
||||
if (first.type === "ReturnStatement") {
|
||||
useExpression = true;
|
||||
body = first.argument!;
|
||||
}
|
||||
}
|
||||
return j.arrowFunctionExpression(p.value.params, body, useExpression);
|
||||
})
|
||||
.toSource();
|
||||
};
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Transforms:
|
||||
* class C extends React.Component() {
|
||||
* render() {
|
||||
* return <div foo={this.props.foo} bar={this.props.bar} />
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* To:
|
||||
*
|
||||
* class C extends React.Component() {
|
||||
* render() {
|
||||
* const {
|
||||
* foo,
|
||||
* bar
|
||||
* } = this.props;
|
||||
*
|
||||
* return <div foo={foo} bar={bar} />
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
import { Transform, VariableDeclarator, ObjectPattern, Identifier } from "jscodeshift";
|
||||
|
||||
// tslint:disable-next-line max-line-length
|
||||
const keywordsStr = 'this function if return var else for new in typeof while case break try catch delete throw switch continue default instanceof do void finally with debugger implements interface package private protected public static class enum export extends import super true false null abstract boolean byte char const double final float goto int long native short synchronized throws transient volatile';
|
||||
const keywords = keywordsStr.split(' ').reduce<{ [key: string]: boolean }>((f, k) => {
|
||||
f[k] = true;
|
||||
return f;
|
||||
}, {});
|
||||
const isKeyword = (k: string) => keywords.hasOwnProperty(k);
|
||||
|
||||
const transform: Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
const {statement} = j.template;
|
||||
|
||||
return j(file.source)
|
||||
.find(j.FunctionExpression)
|
||||
.replaceWith(p => {
|
||||
// console.log(p);
|
||||
const root = j(p.value);
|
||||
const variablesToReplace: { [name: string]: boolean } = {};
|
||||
|
||||
// Figure out if the variable was defined from props, so that we can re-use that definition.
|
||||
const isFromProps = (name: string, resolvedScope: any) => {
|
||||
return resolvedScope.getBindings()[name].every(
|
||||
(p: any) => {
|
||||
const decl = j(p).closest(j.VariableDeclarator);
|
||||
// What happens when our VariableDeclarator is too high up the parent AST?
|
||||
|
||||
if (!decl.size()) return false;
|
||||
const node: VariableDeclarator = decl.nodes()[0];
|
||||
|
||||
if (!(node.init != null &&
|
||||
node.init.type === 'MemberExpression' &&
|
||||
node.init.object.type === 'ThisExpression' &&
|
||||
node.init.property.type === 'Identifier' &&
|
||||
node.init.property.name === 'props'))
|
||||
return false;
|
||||
|
||||
// Check for the case where it could be aliased (i.e.) { baz: foo } = this.props;
|
||||
// In this case, we won't do a substitution.
|
||||
if (p.parentPath.value.type === 'Property' && p.parentPath.value.key.name !== name)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Transform "this.props.xyz" to "xyz", and record what we've transformed.
|
||||
// Transform as long as we don't have "xyz" already defined in the scope.
|
||||
root
|
||||
.find(j.MemberExpression, {
|
||||
object: {
|
||||
type: 'MemberExpression',
|
||||
object: {type: 'ThisExpression'},
|
||||
property: {name: 'props'}
|
||||
}
|
||||
})
|
||||
.filter(e => {
|
||||
const resolvedScope = e.scope.lookup((e.value.property as Identifier).name);
|
||||
// If the scope is null, that means that this property isn't defined in the scope yet,
|
||||
// and we can use it. Otherwise, if it is defined, we should see if it was defined from `this.props`
|
||||
// if none of these cases are true, we can't do substitution.
|
||||
return resolvedScope === null || isFromProps((e.value.property as Identifier).name, resolvedScope);
|
||||
})
|
||||
// Ensure that our substitution won't cause us to define a keyword, i.e. `this.props.while` won't
|
||||
// get converted into `while`.
|
||||
.filter(p => !isKeyword((p.value.property as Identifier).name))
|
||||
// Now, do the replacement, `this.props.xyz` => `xyz`.
|
||||
.replaceWith(p => p.value.property as Identifier)
|
||||
// Finally, mark the variable as something we will need to define earlier in the function,
|
||||
// if it's not already defined.
|
||||
.forEach(p => {
|
||||
// Is this prop already defined somewhere else.
|
||||
if (!p.scope.lookup(p.value.name))
|
||||
variablesToReplace[p.value.name] = true;
|
||||
});
|
||||
|
||||
// Create property definitions for variables that we've replaced.
|
||||
const properties = Object.keys(variablesToReplace)
|
||||
.sort()
|
||||
.map(k => {
|
||||
const prop = j.property('init', j.identifier(k), j.identifier(k));
|
||||
prop.shorthand = true;
|
||||
return prop;
|
||||
});
|
||||
|
||||
// We have no properties to inject, so we can bail here.
|
||||
if (!properties.length)
|
||||
return p.value;
|
||||
|
||||
// See if we already have a VariableDeclarator like { a, b, c } = this.props;
|
||||
const propDefinitions = root
|
||||
.find(j.VariableDeclarator, {
|
||||
id: {type: 'ObjectPattern'},
|
||||
init: {type: 'MemberExpression', object: {type: 'ThisExpression'}, property: {name: 'props'}}
|
||||
});
|
||||
|
||||
if (propDefinitions.size()) {
|
||||
const nodePath = propDefinitions.paths()[0];
|
||||
const node = nodePath.value;
|
||||
// TODO(brieb): support narrowing based on second argument to `find`
|
||||
const newPattern = j.objectPattern((node.id as ObjectPattern).properties.concat(properties));
|
||||
nodePath.replace(j.variableDeclarator(newPattern, node.init));
|
||||
return p.value;
|
||||
}
|
||||
|
||||
// Otherwise, we'll have to create our own, as none were suitable for use.
|
||||
// Create the variable definition `const { xyz } = this.props;`
|
||||
const decl = statement`const { ${properties} } = this.props;`;
|
||||
|
||||
// Add the variable definition to the top of the function expression body.
|
||||
return j.functionExpression(
|
||||
p.value.id,
|
||||
p.value.params,
|
||||
j.blockStatement([decl].concat(p.value.body.body))
|
||||
);
|
||||
}
|
||||
).toSource();
|
||||
};
|
||||
@@ -0,0 +1,64 @@
|
||||
/** For when you've gone too pure and want to go back. */
|
||||
/**
|
||||
* Converts
|
||||
* let HistoryItem = (props) => {
|
||||
* const {
|
||||
* item
|
||||
* } = props;
|
||||
* return <li>{item}</li>;
|
||||
* };
|
||||
*
|
||||
* let X = (props) => <div>foo</div>;
|
||||
*
|
||||
* to
|
||||
*
|
||||
* class HistoryItem extends Component {
|
||||
* render() {
|
||||
* const {
|
||||
* item
|
||||
* } = this.props;
|
||||
* return <li>{item}</li>;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class X extends Component {
|
||||
* render() {
|
||||
* return <div>foo</div>;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
import { Transform, ASTNode } from "jscodeshift";
|
||||
|
||||
const transform: Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
const {statement} = j.template;
|
||||
|
||||
function hasJSXElement(ast: ASTNode) {
|
||||
return j(ast).find(j.JSXElement).size() > 0;
|
||||
}
|
||||
|
||||
return j(file.source)
|
||||
.find(j.VariableDeclaration)
|
||||
.filter(p => p.value.declarations.length === 1)
|
||||
.replaceWith(p => {
|
||||
const decl = p.value.declarations[0];
|
||||
if (decl.type === "VariableDeclarator" && decl.init != null) {
|
||||
if (decl.init.type !== 'ArrowFunctionExpression' ||
|
||||
(!hasJSXElement(decl.init.body) && decl.init.body.type !== "JSXElement"))
|
||||
return p.value;
|
||||
|
||||
let body: any = decl.init.body;
|
||||
body = body.type === "JSXElement" ? j.returnStatement(body) : body = body.body;
|
||||
|
||||
j(body)
|
||||
.find(j.Identifier, {name: 'props'})
|
||||
.replaceWith(p => j.memberExpression(j.thisExpression(), j.identifier('props')));
|
||||
|
||||
return statement`class ${decl.id} extends Component {
|
||||
render() { ${body} }
|
||||
}`;
|
||||
}
|
||||
})
|
||||
.toSource();
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
import { ASTNode, FileInfo, API, Transform, Parser } from "jscodeshift";
|
||||
|
||||
// Can define transform with `function`.
|
||||
function replaceWithFooTransform(fileInfo: FileInfo, api: API) {
|
||||
return api
|
||||
.jscodeshift(fileInfo.source)
|
||||
.findVariableDeclarators("foo")
|
||||
.renameTo("bar")
|
||||
.toSource();
|
||||
}
|
||||
|
||||
// Can define transform with arrow function, using `Transform` type.
|
||||
const reverseIdentifiersTransform: Transform = (file, api) => {
|
||||
const j = api.jscodeshift;
|
||||
|
||||
return j(file.source)
|
||||
.find(j.Identifier)
|
||||
.forEach(path => {
|
||||
j(path).replaceWith(
|
||||
j.identifier(
|
||||
path.node.name
|
||||
.split("")
|
||||
.reverse()
|
||||
.join("")
|
||||
)
|
||||
);
|
||||
})
|
||||
.toSource();
|
||||
};
|
||||
|
||||
// Can define a custom parser.
|
||||
const parser: Parser = {
|
||||
parse(source, options) {
|
||||
// return estree compatible AST
|
||||
return { type: "root" };
|
||||
}
|
||||
};
|
||||
|
||||
// Can pass options to recast
|
||||
const transformWithRecastFormattingOptions: Transform = (file, { j }) => {
|
||||
return j(file.source).toSource({ quote: "single" });
|
||||
};
|
||||
|
||||
const transformWithRecastParseOptions: Transform = (file, { j }) => {
|
||||
return j(file.source, {
|
||||
/* ...passes options to recast's parse method... */
|
||||
}).toSource();
|
||||
};
|
||||
|
||||
// `ASTNode` supports type narrowing.
|
||||
{
|
||||
const node = ({} as any) as ASTNode;
|
||||
if (node.type === "CatchClause") {
|
||||
// $ExpectType CatchClause
|
||||
node;
|
||||
|
||||
if (node.param && node.param.type === "Identifier") {
|
||||
// $ExpectType Identifier
|
||||
node.param;
|
||||
|
||||
if (
|
||||
node.param.typeAnnotation &&
|
||||
node.param.typeAnnotation.type === "TSTypeAnnotation"
|
||||
) {
|
||||
// $ExpectType TSTypeAnnotation
|
||||
node.param.typeAnnotation;
|
||||
|
||||
if (node.param.typeAnnotation.typeAnnotation.type === "TSArrayType") {
|
||||
// $ExpectType TSArrayType
|
||||
node.param.typeAnnotation.typeAnnotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"src/core.d.ts",
|
||||
"src/Collection.d.ts",
|
||||
"src/collections/JSXElement.d.ts",
|
||||
"src/collections/Node.d.ts",
|
||||
"src/collections/VariableDeclarator.d.ts",
|
||||
"src/template.d.ts",
|
||||
"test/jscodeshift-tests.ts",
|
||||
"test/js-transforms/bind-this-to-bind-expression.ts",
|
||||
"test/js-transforms/call-expression-bind-this-to-arrow-function-expression.ts",
|
||||
"test/js-transforms/function-expression-to-arrow-function-expression.ts",
|
||||
"test/js-transforms/props-to-destructuring.ts",
|
||||
"test/js-transforms/pure-to-composite-component.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
declare module 'katex/dist/contrib/auto-render' {
|
||||
import { KatexOptions } from 'katex';
|
||||
|
||||
export interface RenderMathInElementSpecificOptionsDelimiters {
|
||||
/**
|
||||
* A string which starts the math expression (i.e. the left delimiter)
|
||||
*/
|
||||
left: string;
|
||||
/**
|
||||
* A string which ends the math expression (i.e. the right delimiter)
|
||||
*/
|
||||
right: string;
|
||||
/**
|
||||
* A boolean of whether the math in the expression should be rendered in display mode or not
|
||||
*/
|
||||
display: boolean
|
||||
}
|
||||
|
||||
export interface RenderMathInElementSpecificOptions {
|
||||
/**
|
||||
* A list of delimiters to look for math
|
||||
*
|
||||
* @default [
|
||||
* {left: "$$", right: "$$", display: true},
|
||||
* {left: "\\(", right: "\\)", display: false},
|
||||
* {left: "\\[", right: "\\]", display: true}
|
||||
* ]
|
||||
*/
|
||||
delimiters?: ReadonlyArray<RenderMathInElementSpecificOptionsDelimiters>;
|
||||
/**
|
||||
* A list of DOM node types to ignore when recursing through
|
||||
*
|
||||
* @default ["script", "noscript", "style", "textarea", "pre", "code"]
|
||||
*/
|
||||
ignoredTags?: ReadonlyArray<keyof HTMLElementTagNameMap>;
|
||||
/**
|
||||
* A list of DOM node class names to ignore when recursing through
|
||||
*
|
||||
* @default []
|
||||
*/
|
||||
ignoredClasses?: string[];
|
||||
/**
|
||||
* A callback method returning a message and an error stack in case of an critical error during rendering
|
||||
* @param msg Message generated by KaTeX
|
||||
* @param err Caught error
|
||||
*
|
||||
* @default console.error
|
||||
*/
|
||||
errorCallback?(msg: string, err: Error): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* renderMathInElement options contain KaTeX render options and renderMathInElement specific options
|
||||
*/
|
||||
export type RenderMathInElementOptions = KatexOptions & RenderMathInElementSpecificOptions;
|
||||
|
||||
/**
|
||||
* Auto-render TeX expressions in HTML element
|
||||
* @param elem HTML element to auto-render
|
||||
* @param options Render options
|
||||
*/
|
||||
function renderMathInElement(elem: HTMLElement, options?: RenderMathInElementOptions): void;
|
||||
export default renderMathInElement;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user