Comparing version 2.8.1 to 3.0.0
@@ -5,6 +5,11 @@ # Change Log | ||
## [2.8.1](https://github.com/waitingsong/node-win32-def/compare/v2.8.0...v2.8.1) (2019-02-27) | ||
# [3.0.0](https://github.com/waitingsong/node-win32-def/compare/v2.8.1...v3.0.0) (2019-03-01) | ||
### Features | ||
* **types:** expand exported DllFuncsModel with async() method ([20f24b0](https://github.com/waitingsong/node-win32-def/commit/20f24b0)) | ||
<a name="2.4.3"></a> | ||
@@ -11,0 +16,0 @@ ## [2.4.3](https://github.com/waitingsong/node-win32-def/compare/v2.4.2...v2.4.3) (2019-02-21) |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 2.8.1 | ||
* @version 3.0.0 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 2.8.1 | ||
* @version 3.0.0 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* @version 2.8.1 | ||
* @version 3.0.0 | ||
* @author waiting | ||
@@ -8,0 +8,0 @@ * @license MIT |
/// <reference types="node" /> | ||
import { Push } from '@waiting/shared-core'; | ||
export declare type MacroParam<T> = T | [T, T, T]; | ||
@@ -97,3 +98,53 @@ export declare type MacroDef = [string, string, string]; | ||
export interface DllFuncsModel { | ||
[funcName: string]: (...args: any[]) => boolean | number | Buffer | void; | ||
[funcName: string]: SyncFnModel; | ||
} | ||
export declare type SyncFnModel = (...args: any[]) => boolean | number | Buffer | void; | ||
export interface AsyncSyncFuncModel { | ||
async: (...args: any[]) => void; | ||
[key: string]: SyncFnModel; | ||
} | ||
export interface AppendAsyncToSyncFnModel<T extends DllFuncsModel, K extends keyof T> { | ||
async(...args: Push<Parameters<T[K]>, (err: Error, result: ReturnType<T[K]>) => void>): void; | ||
} | ||
/** | ||
* Expand FnModel with async() | ||
* typeof arguments and typeof argument result of callback(err: Error, result) | ||
* will be retrieved from input method | ||
* | ||
* deps: typescript >= 3.1 | ||
* ref: | ||
* - https://github.com/microsoft/typescript/pull/24897 | ||
* - https://zhuanlan.zhihu.com/p/38687656 | ||
* | ||
* usage: | ||
* ```ts | ||
* export interface SDT extends DllFuncsModel { | ||
* foo: { | ||
* (msg: M.POINT): M.VOID, | ||
* async(msg: M.POINT, cb: (err: Error, result: M.VOINT)): void, | ||
* } | ||
* bar: BarFn | ||
* barz(port: M.INT): M.POINT | ||
* } | ||
* export interface BarFn extends AsyncSyncFuncModel { | ||
* (port: M.INT): M.INT | ||
* async( | ||
* port: M.INT | ||
* cb: (err: Error, code: M.INT) => void, | ||
* ): void | ||
* } | ||
* | ||
* // Will append async() method to barz() with correct parameter's types of the (last) callback parameter of barz() | ||
* export type SDTFnModel = ExpandFnModel<SDT> | ||
* // So we can calling async method | ||
* const api: SDTFnModel = .... | ||
* api.barz.async(port, (err, result) => { | ||
* // type of result will get correct typeof Buffer (according to ReresultType of api.barz) automatically | ||
* }) | ||
* ``` | ||
*/ | ||
export declare type ExpandFnModel<T extends DllFuncsModel> = { | ||
[K in keyof T]: 'async' extends keyof T[K] ? T[K] : T[K] extends AsyncSyncFuncModel ? T[K] : T[K] & { | ||
async(...args: Push<Parameters<T[K]>, (err: Error, result: ReturnType<T[K]>) => void>): void; | ||
}; | ||
}; |
{ | ||
"name": "win32-def", | ||
"author": "waiting", | ||
"version": "2.8.1", | ||
"version": "3.0.0", | ||
"description": "win32 definitions for node-ffi", | ||
@@ -50,3 +50,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@waiting/shared-core": "^1.3.3", | ||
"@waiting/shared-core": "^1.7.0", | ||
"rxjs": "^6.4.0" | ||
@@ -53,0 +53,0 @@ }, |
@@ -23,2 +23,3 @@ # win32-def | ||
### FFI | ||
```ts | ||
@@ -40,2 +41,34 @@ import * as ffi from 'ffi' | ||
```ts | ||
import * as ffi from 'ffi' | ||
import { DModel as M, DTypes as W, FModel as FM } from 'win32-def' | ||
export interface Win32Fns extends FM.DllFuncsModel { | ||
ClientToScreen(hWnd: M.HWND, lpPoint: M.LPPOINT): M.BOOL | ||
GetAncestor(hwnd: M.HWND, gaFlags: M.UINT): M.HWND | ||
} | ||
export const user32: FM.ExpandFnModel<Win32Fns> = ffi.Library('user32.dll', { | ||
ClientToScreen: [W.BOOL, [W.HWND, W.LPPOINT] ], | ||
GetAncestor: [W.HWND, [W.HWND, W.UINT] ], | ||
}) | ||
// You can calling with BOTH sync and async method | ||
const hWnd = user32.GetAncestor(hWnd, uint) | ||
user32.GetAncestor.async(handle, uint, (err, hWnd) => { | ||
// typeof hWnd will be the same of ReturnType of sync method | ||
if (err) { | ||
throw err | ||
} | ||
if (hWnd && !ref.isNull(hWnd) && ref.address(hWnd)) { | ||
// ... | ||
} | ||
else { | ||
throw new Error('hWnd invalid') | ||
} | ||
}) | ||
``` | ||
### [WIN32-API](https://www.npmjs.com/package/win32-api) | ||
```ts | ||
// struct usage by ref-struct | ||
@@ -42,0 +75,0 @@ import * as Struct from 'ref-struct' |
@@ -23,2 +23,3 @@ # win32-def | ||
### FFI | ||
```ts | ||
@@ -40,2 +41,34 @@ import * as ffi from 'ffi' | ||
```ts | ||
import * as ffi from 'ffi' | ||
import { DModel as M, DTypes as W, FModel as FM } from 'win32-def' | ||
export interface Win32Fns extends FM.DllFuncsModel { | ||
ClientToScreen(hWnd: M.HWND, lpPoint: M.LPPOINT): M.BOOL | ||
GetAncestor(hwnd: M.HWND, gaFlags: M.UINT): M.HWND | ||
} | ||
export const user32: FM.ExpandFnModel<Win32Fns> = ffi.Library('user32.dll', { | ||
ClientToScreen: [W.BOOL, [W.HWND, W.LPPOINT] ], | ||
GetAncestor: [W.HWND, [W.HWND, W.UINT] ], | ||
}) | ||
// You can calling with BOTH sync and async method | ||
const hWnd = user32.GetAncestor(hWnd, uint) | ||
user32.GetAncestor.async(handle, uint, (err, hWnd) => { | ||
// typeof hWnd will be the same of ReturnType of sync method | ||
if (err) { | ||
throw err | ||
} | ||
if (hWnd && !ref.isNull(hWnd) && ref.address(hWnd)) { | ||
// ... | ||
} | ||
else { | ||
throw new Error('hWnd invalid') | ||
} | ||
}) | ||
``` | ||
### [WIN32-API](https://www.npmjs.com/package/win32-api) | ||
```ts | ||
// struct usage by ref-struct | ||
@@ -100,4 +133,5 @@ import * as Struct from 'ref-struct' | ||
### Languages | ||
- [English](README.md) | ||
- [中文](README.zh-CN.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
150446
33
3188
134
Updated@waiting/shared-core@^1.7.0