Skip to content

Commit 1a4ce6b

Browse files
authored
Improve subscription and logger output. (#456)
feat(logger): add standardized log output Standardize information printed by logger and places where it is printed. feat(logger): add configuration options to set loggers Add `logLevel` and `loggers` configuration parameters to specify minimum log level and list of custom `Logger` interface implementations (when own logger needed). feat(subscription): add subscription / subscription set `cloneEmpty` function Add the `cloneEmpty` function, which will let you make a “bare” copy of a subscription / subscription set object, which will have shared state with the original but clear list of event handlers. feat(subscription): add `filter` subscription configuration Add a parameter for subscription where closure can be provided and filter events which should be delivered with listener. feat(subscription): add old messages filtering When a new subscription object is created, it won't notify about messages from the past (edge case with active and inactive channel subscriptions).
1 parent b8e1af9 commit 1a4ce6b

File tree

170 files changed

+19706
-8778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+19706
-8778
lines changed

.pubnub.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
---
22
changelog:
3+
- date: 2025-06-04
4+
version: v9.6.0
5+
changes:
6+
- type: feature
7+
text: "Standardize information printed by logger and places where it is printed."
8+
- type: feature
9+
text: "Add `logLevel` and `loggers` configuration parameters to specify minimum log level and list of custom `Logger` interface implementations (when own logger needed)."
10+
- type: feature
11+
text: "Add the `cloneEmpty` function, which will let you make a “bare” copy of a subscription / subscription set object, which will have shared state with the original but clear list of event handlers."
12+
- type: feature
13+
text: "Add a parameter for subscription where closure can be provided and filter events which should be delivered with listener."
14+
- type: feature
15+
text: "When a new subscription object is created, it won't notify about messages from the past (edge case with active and inactive channel subscriptions)."
316
- date: 2025-04-22
417
version: v9.5.2
518
changes:
@@ -1236,7 +1249,7 @@ supported-platforms:
12361249
- 'Ubuntu 14.04 and up'
12371250
- 'Windows 7 and up'
12381251
version: 'Pubnub Javascript for Node'
1239-
version: '9.5.2'
1252+
version: '9.6.0'
12401253
sdks:
12411254
- full-name: PubNub Javascript SDK
12421255
short-name: Javascript
@@ -1252,7 +1265,7 @@ sdks:
12521265
- distribution-type: source
12531266
distribution-repository: GitHub release
12541267
package-name: pubnub.js
1255-
location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.2.zip
1268+
location: https://github.com/pubnub/javascript/archive/refs/tags/v9.6.0.zip
12561269
requires:
12571270
- name: 'agentkeepalive'
12581271
min-version: '3.5.2'
@@ -1923,7 +1936,7 @@ sdks:
19231936
- distribution-type: library
19241937
distribution-repository: GitHub release
19251938
package-name: pubnub.js
1926-
location: https://github.com/pubnub/javascript/releases/download/v9.5.2/pubnub.9.5.2.js
1939+
location: https://github.com/pubnub/javascript/releases/download/v9.6.0/pubnub.9.6.0.js
19271940
requires:
19281941
- name: 'agentkeepalive'
19291942
min-version: '3.5.2'

.scripts/types-aggregate.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class Package {
169169
const internalModuleMatch = fileContent.match(/^\/\*\*[\s\S]*?@internal[\s\S]*?\*\//);
170170
if (internalModuleMatch && internalModuleMatch.index !== undefined && internalModuleMatch.index === 0) return;
171171

172-
this.files.push(new SourceFile(resourcePath, this.workingDirectory, this.tsConfiguration.options));
172+
this.files.push(new SourceFile(resourcePath, this.workingDirectory, this.tsConfiguration.options, this));
173173
}
174174
});
175175

@@ -202,16 +202,18 @@ class SourceFile {
202202
private readonly _types: TypeDefinition[] = [];
203203

204204
/**
205-
* Create source file from type definition file in the package.
205+
* Create a source file from type definition file in the package.
206206
*
207207
* @param filePath - Path to the type definition file which will be analyzed.
208208
* @param workingDirectory - Root folder with subfolders which represent project structure and contains types definition files.
209209
* @param tsCompileOptions - Package's TS parsed configuration object.
210+
* @param projectPackage - Project with processed files information.
210211
*/
211212
constructor(
212213
public readonly filePath: string,
213214
private readonly workingDirectory: string,
214215
private readonly tsCompileOptions: ts.CompilerOptions,
216+
readonly projectPackage: Package,
215217
) {
216218
const source = this.tsSourceFile();
217219
this.processImports(source);
@@ -343,6 +345,7 @@ class SourceFile {
343345
node.name.getText(sourceFile),
344346
type,
345347
this.tsSourceFile(`${documentation}\n${node.getText(sourceFile)}`),
348+
this,
346349
),
347350
);
348351
});
@@ -382,6 +385,7 @@ class TypeDefinition {
382385
public readonly name: string,
383386
public type: 'class' | 'interface' | 'type' | 'enum',
384387
private readonly sourceFile: ts.SourceFile,
388+
private readonly projectSourceFile: SourceFile,
385389
) {
386390
if (type === 'class') {
387391
const match = sourceFile.getText(this.sourceFile).match(/class PubNub extends ([a-zA-Z]+)[\s|<]/) ?? [];
@@ -412,6 +416,23 @@ class TypeDefinition {
412416
if (namespace) {
413417
const reference = ts.factory.createQualifiedName(ts.factory.createIdentifier(namespace), typeName);
414418

419+
replacement = ts.factory.createTypeReferenceNode(
420+
reference,
421+
node.typeArguments
422+
?.map((typeArg) => ts.visitNode(typeArg, visit))
423+
.filter((typeArg): typeArg is ts.TypeNode => typeArg !== undefined),
424+
);
425+
}
426+
} else if (!namespace && ts.isTypeReferenceNode(node)) {
427+
const typeName = node.typeName.getText(this.sourceFile);
428+
let typeNamespace = namespace;
429+
this.projectSourceFile.imports.forEach((importType) => {
430+
if (importType.type === 'alias' && importType.alias === typeName && !typeNamespace)
431+
typeNamespace = 'PubNub';
432+
});
433+
if (typeNamespace) {
434+
const reference = ts.factory.createQualifiedName(ts.factory.createIdentifier(typeNamespace), typeName);
435+
415436
replacement = ts.factory.createTypeReferenceNode(
416437
reference,
417438
node.typeArguments
@@ -458,7 +479,9 @@ class TypeDefinition {
458479

459480
const aliasedTypeStrings: string[] = [];
460481
if (this.aliases.length > 0) {
461-
const matches = this.sourceFile.getText(this.sourceFile).match(/^(\s*(export\s+)?(declare\s+)?(type|class)\s)/gm);
482+
const matches = this.sourceFile
483+
.getText(this.sourceFile)
484+
.match(/^(\s*(export\s+)?(declare\s+)?(type|class|enum)\s)/gm);
462485
if (!matches) throw new Error(`Unable to match prefix for '${this.name}' ${this.type}`);
463486

464487
this.aliases.forEach((alias) => {

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## v9.6.0
2+
June 04 2025
3+
4+
#### Added
5+
- Standardize information printed by logger and places where it is printed.
6+
- Add `logLevel` and `loggers` configuration parameters to specify minimum log level and list of custom `Logger` interface implementations (when own logger needed).
7+
- Add the `cloneEmpty` function, which will let you make a “bare” copy of a subscription / subscription set object, which will have shared state with the original but clear list of event handlers.
8+
- Add a parameter for subscription where closure can be provided and filter events which should be delivered with listener.
9+
- When a new subscription object is created, it won't notify about messages from the past (edge case with active and inactive channel subscriptions).
10+
111
## v9.5.2
212
April 22 2025
313

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2727
npm install pubnub
2828
```
2929
* or download one of our builds from our CDN:
30-
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.2.js
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.2.min.js
30+
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.6.0.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.9.6.0.min.js
3232
3333
2. Configure your keys:
3434

0 commit comments

Comments
 (0)