Skip to content

Commit f3fe4db

Browse files
committed
patchedPryv: declaration merging for type+value exports, bump 0.1.15
1 parent f2d4171 commit f3fe4db

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hds-lib",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"description": "Health Data Safe - Library",
55
"type": "module",
66
"engines": {

ts/patchedPryv.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
/**
2-
* While developing this lib some functionalities should be
3-
* added to pryv js-lib in a second step
2+
* CJS→ESM interop for the pryv package with plugin patching.
43
*
5-
* CJS→ESM interop: default import gives the module.exports object directly
6-
* (Connection, Auth, etc.) instead of a frozen namespace wrapper.
7-
* Type errors from consumers using `pryv.Connection` as a namespace type
8-
* are suppressed via noEmitOnError: false — the JS output is correct.
4+
* Default import gives the module.exports object directly (Connection, Auth, etc.).
5+
* We re-export both the runtime value AND a merged type namespace so that consumers
6+
* can use `pryv.Connection` as both a constructor and a type annotation.
97
*/
10-
// @ts-ignore namespace usage in consumers requires `import *`, but runtime needs default
11-
import pryv from 'pryv';
8+
import _pryv from 'pryv';
9+
import type * as _PryvTypes from 'pryv';
1210
import monitor from '@pryv/monitor';
1311
import socketIo from '@pryv/socket.io';
1412
// @ts-expect-error CJS plugin pattern: module.exports = function(pryv) { ... }
15-
monitor(pryv);
13+
monitor(_pryv);
1614
// @ts-expect-error CJS plugin pattern: module.exports = function(pryv) { ... }
17-
socketIo(pryv);
15+
socketIo(_pryv);
1816

19-
export { pryv };
17+
// Declaration merging: the exported `pryv` const provides the runtime value,
18+
// and the namespace augments it with all the types from pryv's .d.ts.
19+
// This lets consumers write both `new pryv.Connection(...)` and `x: pryv.Connection`.
20+
21+
// eslint-disable-next-line import-x/export -- declaration merging: value + type namespace
22+
export const pryv = _pryv as unknown as typeof _PryvTypes;
23+
24+
// eslint-disable-next-line @typescript-eslint/no-namespace, import-x/export -- declaration merging
25+
export namespace pryv {
26+
export type Connection = _PryvTypes.Connection;
27+
export type Service = _PryvTypes.Service;
28+
export type Stream = _PryvTypes.Stream;
29+
export type Event = _PryvTypes.Event;
30+
export type APICall = _PryvTypes.APICall;
31+
export type AccessInfo = _PryvTypes.AccessInfo;
32+
export type Access = _PryvTypes.Access;
33+
export type Permission = _PryvTypes.Permission;
34+
export type ServiceInfo = _PryvTypes.ServiceInfo;
35+
export type ServiceAssets = _PryvTypes.ServiceAssets;
36+
export type AuthController = _PryvTypes.AuthController;
37+
export type AuthSettings = _PryvTypes.AuthSettings;
38+
export type ItemDeletion = _PryvTypes.ItemDeletion;
39+
export type PryvError = _PryvTypes.PryvError;
40+
export type KeyValue = _PryvTypes.KeyValue;
41+
}

0 commit comments

Comments
 (0)