From a36c55be2ced48e3d3ddba15e543ad2e2308ab63 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Thu, 16 Aug 2018 11:29:23 +0530 Subject: [PATCH] Add ref-struct-di module --- types/ref-struct-di/index.d.ts | 60 ++++++++++++++++ types/ref-struct-di/ref-struct-di-tests.ts | 12 ++++ types/ref-struct-di/tsconfig.json | 23 +++++++ types/ref-struct-di/tslint.json | 79 ++++++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 types/ref-struct-di/index.d.ts create mode 100644 types/ref-struct-di/ref-struct-di-tests.ts create mode 100644 types/ref-struct-di/tsconfig.json create mode 100644 types/ref-struct-di/tslint.json diff --git a/types/ref-struct-di/index.d.ts b/types/ref-struct-di/index.d.ts new file mode 100644 index 0000000000..dd3d878fc1 --- /dev/null +++ b/types/ref-struct-di/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for ref-struct-di 1.1 +// Project: https://github.com/node-ffi-napi/ref-struct-di +// Definitions by: Keerthi Niranjan , Kiran Niranjan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import ref = require('ref-napi'); + +/** + * This is the `constructor` of the Struct type that gets returned. + * + * Invoke it with `new` to create a new Buffer instance backing the struct. + * Pass it an existing Buffer instance to use that as the backing buffer. + * Pass in an Object containing the struct fields to auto-populate the + * struct with the data. + * + * @constructor + */ +interface StructType extends ref.Type { + /** Pass it an existing Buffer instance to use that as the backing buffer. */ + new (arg: Buffer, data?: {}): any; + new (data?: {}): any; + /** Pass it an existing Buffer instance to use that as the backing buffer. */ + (arg: Buffer, data?: {}): any; + (data?: {}): any; + + fields: { [key: string]: { type: ref.Type } }; + + /** + * Adds a new field to the struct instance with the given name and type. + * Note that this function will throw an Error if any instances of the struct + * type have already been created, therefore this function must be called at the + * beginning, before any instances are created. + */ + defineProperty(name: string, type: ref.Type): void; + + /** + * Adds a new field to the struct instance with the given name and type. + * Note that this function will throw an Error if any instances of the struct + * type have already been created, therefore this function must be called at the + * beginning, before any instances are created. + */ + defineProperty(name: string, type: string): void; + + /** + * Custom for struct type instances. + * @override + */ + toString(): string; +} + +/** The struct type meta-constructor. */ +declare var StructType: { + new (fields?: object, opt?: object): StructType; + new (fields?: any[]): StructType; + (fields?: object, opt?: object): StructType; + (fields?: any[]): StructType; +} + +export = StructType; diff --git a/types/ref-struct-di/ref-struct-di-tests.ts b/types/ref-struct-di/ref-struct-di-tests.ts new file mode 100644 index 0000000000..60b03e0cd5 --- /dev/null +++ b/types/ref-struct-di/ref-struct-di-tests.ts @@ -0,0 +1,12 @@ +import ref = require("ref-napi"); +import StructType = require("ref-struct-di"); + +const normalStruct = StructType({ + t: ref.types.uint8, + v: ref.types.long, +}); + +const packedStruct = StructType({ + t: ref.types.uint8, + v: ref.types.long, +}, {packed: true}); diff --git a/types/ref-struct-di/tsconfig.json b/types/ref-struct-di/tsconfig.json new file mode 100644 index 0000000000..fef426ba7a --- /dev/null +++ b/types/ref-struct-di/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ref-struct-di-tests.ts" + ] +} diff --git a/types/ref-struct-di/tslint.json b/types/ref-struct-di/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/ref-struct-di/tslint.json @@ -0,0 +1,79 @@ +{ + "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 + } +}