@node-ctypes/comtypes 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +50 -624
  2. package/dist/automation/dispatch.js +10 -3
  3. package/dist/automation/record.js +3 -1
  4. package/dist/automation/variant.d.ts +4 -4
  5. package/dist/automation/variant.js +93 -28
  6. package/dist/client/dynamic.js +7 -8
  7. package/dist/client/events.js +18 -2
  8. package/dist/client/index.js +3 -1
  9. package/dist/commethod.d.ts +1 -1
  10. package/dist/commethod.js +151 -57
  11. package/dist/errorinfo.d.ts +10 -3
  12. package/dist/errorinfo.js +66 -18
  13. package/dist/errors.d.ts +7 -1
  14. package/dist/executor/apartment.d.ts +7 -3
  15. package/dist/executor/apartment.js +65 -29
  16. package/dist/executor/executor.d.ts +2 -0
  17. package/dist/executor/executor.js +65 -14
  18. package/dist/guid.d.ts +1 -1
  19. package/dist/guid.js +7 -9
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +4 -4
  22. package/dist/interfaces/agile.d.ts +52 -0
  23. package/dist/interfaces/agile.js +59 -0
  24. package/dist/interfaces/errorinfo.d.ts +8 -0
  25. package/dist/interfaces/errorinfo.js +10 -0
  26. package/dist/interfaces/index.d.ts +2 -1
  27. package/dist/interfaces/index.js +2 -1
  28. package/dist/low-level/iids.d.ts +14 -0
  29. package/dist/low-level/iids.js +14 -0
  30. package/dist/low-level/index.d.ts +2 -2
  31. package/dist/low-level/index.js +1 -1
  32. package/dist/low-level/native.d.ts +13 -0
  33. package/dist/low-level/native.js +33 -0
  34. package/dist/low-level/registry.js +4 -2
  35. package/dist/low-level/vtable.d.ts +10 -0
  36. package/dist/low-level/vtable.js +32 -5
  37. package/dist/pointer.d.ts +2 -0
  38. package/dist/pointer.js +154 -84
  39. package/dist/pump.d.ts +32 -8
  40. package/dist/pump.js +87 -15
  41. package/dist/runtime.d.ts +6 -0
  42. package/dist/runtime.js +15 -1
  43. package/dist/server/automation.js +3 -3
  44. package/dist/server/comobject.d.ts +53 -0
  45. package/dist/server/comobject.js +319 -27
  46. package/dist/server/index.d.ts +1 -1
  47. package/dist/server/index.js +1 -1
  48. package/dist/server/marshal.d.ts +1 -0
  49. package/dist/server/marshal.js +13 -7
  50. package/dist/server/register.js +8 -6
  51. package/dist/tracking.d.ts +2 -0
  52. package/dist/tracking.js +13 -0
  53. package/package.json +6 -2
@@ -1,11 +1,10 @@
1
1
  import * as ctypes from "node-ctypes";
2
- import { setTimeout as delay } from "node:timers/promises";
3
2
  import { CLSCTX_LOCAL_SERVER } from "../constants.js";
4
3
  import { checkHRESULT } from "../errors.js";
5
4
  import { toGUID } from "../guid.js";
6
5
  import { ole32 } from "../low-level/native.js";
7
6
  import { deleteTree, HKEY_CURRENT_USER, writeString } from "../low-level/registry.js";
8
- import { pumpMessages } from "../pump.js";
7
+ import { waitAndPumpMessages } from "../pump.js";
9
8
  import { CoInitializeEx, CoUninitialize } from "../runtime.js";
10
9
  import { ClassFactory, COMObject, classTypeLib, getLiveObjectCount, queryObject } from "./comobject.js";
11
10
  import { registerTypeLib, unregisterTypeLib } from "../typelib/load.js";
@@ -127,21 +126,24 @@ export async function runLocalServer(types, options = {}) {
127
126
  const locked = () => registrations.some((registration) => registration.factory.locks > 0);
128
127
  try {
129
128
  const started = performance.now();
129
+ const sliceMs = options.interval ?? 8;
130
+ const idleTimeout = options.idleTimeout ?? 2000;
131
+ const startupTimeout = options.startupTimeout ?? 60_000;
130
132
  let served = false;
131
133
  let idleSince = performance.now();
132
134
  for (;;) {
133
- pumpMessages();
135
+ waitAndPumpMessages(sliceMs);
134
136
  const busy = live() > 0 || locked();
135
137
  if (busy) {
136
138
  served = true;
137
139
  idleSince = performance.now();
138
140
  }
139
141
  const now = performance.now();
140
- if (served && !busy && now - idleSince >= (options.idleTimeout ?? 2000))
142
+ if (served && !busy && now - idleSince >= idleTimeout)
141
143
  break;
142
- if (!served && now - started >= (options.startupTimeout ?? 60_000))
144
+ if (!served && now - started >= startupTimeout)
143
145
  break;
144
- await delay(options.interval ?? 5);
146
+ await new Promise((resolve) => setImmediate(resolve));
145
147
  }
146
148
  }
147
149
  finally {
@@ -15,5 +15,7 @@ export declare function apartmentGeneration(): number;
15
15
  export declare function liveCount(): number;
16
16
  export declare function initCount(): number;
17
17
  export declare function initialized(): void;
18
+ /** Register a cleanup hook invoked right before the apartment is uninitialized. */
19
+ export declare function onApartmentTeardown(hook: () => void): void;
18
20
  /** Account for one CoUninitialize; on the last one, release everything and start a new generation. */
19
21
  export declare function uninitializing(): void;
package/dist/tracking.js CHANGED
@@ -59,11 +59,24 @@ export function initCount() {
59
59
  export function initialized() {
60
60
  state.initCount++;
61
61
  }
62
+ const teardownHooks = new Set();
63
+ /** Register a cleanup hook invoked right before the apartment is uninitialized. */
64
+ export function onApartmentTeardown(hook) {
65
+ teardownHooks.add(hook);
66
+ }
62
67
  /** Account for one CoUninitialize; on the last one, release everything and start a new generation. */
63
68
  export function uninitializing() {
64
69
  if (state.initCount === 0)
65
70
  return;
66
71
  if (state.initCount === 1) {
72
+ for (const hook of teardownHooks) {
73
+ try {
74
+ hook();
75
+ }
76
+ catch {
77
+ // Keep tearing down.
78
+ }
79
+ }
67
80
  releaseAll();
68
81
  state.generation++;
69
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-ctypes/comtypes",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Typed Windows COM client and server support for Node.js powered by node-ctypes, inspired by Python comtypes",
5
5
  "author": "Damiano Mazzella",
6
6
  "license": "MIT",
@@ -76,15 +76,19 @@
76
76
  "build": "npm run clean && tsc -p tsconfig.build.json",
77
77
  "test:types": "tsc -p tests/tsconfig.json && tsc -p tests/types/tsconfig.json",
78
78
  "test": "npm run build && npm run test:types && node --test --test-concurrency=1 \"tests/checks/*.test.ts\" \"tests/src/*.test.ts\"",
79
+ "test:mirror": "npm run build && node -e \"const { spawnSync } = require('node:child_process'); const r = spawnSync(process.execPath, ['--test', '--test-concurrency=1', 'tests/checks/*.test.ts', 'tests/src/*.test.ts'], { stdio: 'inherit', env: { ...process.env, NODE_CTYPES_NO_EXTERNAL_BUFFERS: '1' } }); process.exit(r.status ?? 1);\"",
79
80
  "test:unit": "npm run build && node --test \"tests/checks/unit.*.test.ts\"",
81
+ "docs": "typedoc",
82
+ "docs:serve": "typedoc && npx serve docs",
80
83
  "prepack": "npm run build",
81
84
  "prepublishOnly": "npm test"
82
85
  },
83
86
  "dependencies": {
84
- "node-ctypes": "^2.15.2"
87
+ "node-ctypes": "^2.16.0"
85
88
  },
86
89
  "devDependencies": {
87
90
  "@types/node": "^26.6.6",
91
+ "typedoc": "^0.28.20",
88
92
  "typescript": "~6.0.3"
89
93
  }
90
94
  }