Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript types creation #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@
"dependencies": {
"raven": "github:athombv/raven-node"
},
"contributors": [
{
"name": "Bence Palatin",
"url": "https://github.com/palatinb"
}
],
"devDependencies": {
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.0",
"@types/node": "^12.20.55",
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.5",
"@types/node": "^16.1.1",
"concurrently": "^5.1.0",
"eslint": "^7.2.0",
"eslint-config-athom": "^2.1.0",
"eslint": "^7.32.0",
"eslint-config-athom": "^3.1.3",
"homey": "^2.4.0",
"homey-jsdoc-template": "github:athombv/homey-jsdoc-template#1.4",
"jsdoc": "^3.6.6",
"jsdoc-ts-utils": "^1.1.2",
"npm-watch": "^0.6.0",
"serve": "^11.3.1",
"typescript": "^4.7.4",
"typescript": "^5.3.3",
"watch": "^1.0.2"
},
"types": "types/index.d.ts",
"types": "types/log.d.ts",
"watch": {
"jsdoc": {
"patterns": [
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Log = require('./log');

export { Log };
106 changes: 106 additions & 0 deletions types/log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use strict';

import Homey = require('homey');
import Raven = require('raven');

interface LogInstanceParams {
/**
* `this.homey` instance in
* your app (e.g. `App#homey`/`Driver#homey`/`Device#homey`).
*/
homey: Homey.App;

/**
* Additional options for Raven
*/
options?: any;
}

declare class Log {

/**
* Construct a new Log instance.
* @param args Parameters for creating the Log instance
*
* @example
* class MyApp extends Homey.App {
* onInit() {
* this.homeyLog = new Log({ homey: this.homey });
* }
* }
*/
constructor(args: LogInstanceParams);

/**
* Mimic SDK log method.
* @private
*/
private static _log(): void;

/**
* Mimic SDK error method.
* @private
*/
private static _error(): void;

/**
* Mimic SDK timestamp.
* @private
*/
private static _logTime(): string;

/**
* Raven.mergeContext covers only 1-level of the context (tags, extra, user)
* We need to merge a 2-level of the context
* see https://github.com/getsentry/raven-node/issues/228
* @param key The key where we can access the sent value
* @param value The logged value
* @private
*/
private static _mergeContext(key: string, value: object): void;

/**
* Set `tags` that will be sent as context with every message or error. See the raven-node
* documentation: https://docs.sentry.io/clients/node/usage/#raven-node-additional-context.
* @param tags
*/
setTags(tags: object): Log;

/**
* Set `extra` that will be sent as context with every message or error. See the raven-node
* documentation: https://docs.sentry.io/clients/node/usage/#raven-node-additional-context.
* @param extra
*/
setExtra(extra: object): Log;

/**
* Set `user` that will be sent as context with every message or error. See the raven-node
* documentation: https://docs.sentry.io/clients/node/usage/#raven-node-additional-context.
* @param user
*/
setUser(user: object): Log;

/**
* Create and send message event to Sentry. See the raven-node documentation:
* https://docs.sentry.io/clients/node/usage/#capturing-messages
* @param message Message to be sent
*/
captureMessage(message: string): Promise<string> | undefined;

/**
* Create and send exception event to Sentry. See the raven-node documentation:
* https://docs.sentry.io/clients/node/usage/#capturing-errors
* @param err Error instance to be sent
*/
captureException(err: Error): Promise<string | undefined>;

/**
* Init Raven, provide falsy value as `url` to prevent sending events upstream in debug mode.
* @param url falsy value as `url` to prevent sending events upstream in debug mode
* @param opts Raven constructor params
* @private
*/
private init(url: boolean | string, opts: Raven.ConstructorOptions): Log;
}

export = Log;