4.0.0
4.0.0 (2020-07-19)
Bug Fixes
- add a package.json with the type 'module' on the ESM directory (9e1521b)
- node/logger: use provider creators (c2197a3)
- make all class properties private/protected with public getters (f78a7e6), closes #68
- node/errorhandler: use a provider creator (b53b71e)
- migrate from ESDoc to JSDoc (65ab6cd)
- remove 'main' from package.json (515165a)
- use 'named' exports on the folders' indexes (1ce2f2c)
- node: remove the providers that no longer exist (544c9e8)
- node: use provider creators (7f54d4e), closes #67
- node/appconfiguration: make all the class properties private/protected (eab4cab)
- node/appconfiguration: use a provider creator (ece3f9d)
- node/errorhandler: make the properties private/protected (82c7aa2)
- node/pathutils: use a provider creator (100fb44)
- shared/apiclient: make the properties private/protected (da216d3)
- shared/deepAssign: use spread instead of .freeze (bb8503c)
Features
- add ESM version (aebdab6), closes #61
- add the deepAssign module (d766a49), closes #63
- add the deepAssign module (1e9247b)
- add the new Jimple wrappers (67a8e6e), closes #66
- add the new Jimple wrappers (0afc6a3)
- add warn alias for warning on the Logger (38cf90c)
- fix the the types for the APIClient and validate with ts-check (346449b)
- node/environmentutils: use a provider creator (c6821f9)
- node/packageInfo: use a provider creator (fe66556)
- node/rootRequire: use a provider creator (9da0d2f)
BREAKING CHANGES
- shared/apiclient: The method
flattenEndpointswas removed; it was just a wrapper for a call to
ObjectUtils. - node/errorhandler: The properties for
.appLoggerand.eventNamesare not longer accesible. - node/appconfiguration: The properties for
.environmentUtilsandrootRequireare not longer accessible. - node/logger: The providers
loggerWithOptionsandappLoggerWithOptionswere removed. - node/pathutils: The provider
pathUtilsWithHomedoesn't exist anymore. - node/errorhandler: The provider
errorHandlerWithOptionsdoesn't exist anymore. - node/appconfiguration: The
appConfigurationfunction is now a provider creator and its signature changed - node/apiclient: The error method now adds the status to the returned error message
Migration guide
APIClient error message with status
The APIClient.error method used to return a new Error with the response's error property, but now it includes the status code as a prefix:
- new Error('Invalid data');
+ new Error('[400]: Invalid data');If you need for to get rid of the status, you have two alternatives:
- You can extend
APIClientand overwriteerrorwith your own method. - You could use the following snippet:
/**
* Takes the message from the error and removes any numeric prefix between
* brackets it may have.
*/
const message = error.message.replace(/^\[\d+\]:\s+/, '');APIClient.flattenEndpoints was removed
When I added ObjectUtils and made APIClient use it, I replaced the implementation of flattenEndpoints with ObjectUtils.flat, making the method just a "proxy"; when I was reviewing what should be of public access and what shouldn't, I decided that flattenEndpoints shouldn't be a public method and that it didn't make sense for it to be private/protected either.
I removed the proxy: instead of calling the method, I just added the call to ObjectUtils.flat directly.
If you were using the method, you can replace it with this snippet:
const ObjectUtils = require('wootils/shared/objectUtils');
// ...
const flat = ObjectUtils.flat(
theObjectYouWanToFlatten,
'.',
'',
(ignore, value) => typeof value.path === 'undefined',
);The appConfiguration provider generator
While the change is that now appConfiguration is a provider creator, which means that it's still a function, the signature has changed and you can't use the same parameters it had before:
- appConfiguration(appName, defaultConfiguration, options);
+ appConfiguration({ appName, defaultConfiguration, options });Usually, provider creators receive a single options object, with all its properties optionals.
Making your code compatible is really easy, if you were using custom parameters, put them inside an object; if you were calling it without parameters, use it as a variable:
- app.register(appConfiguration());
+ app.register(appConfiguration);Providers generators
This affects all the *withOptions providers that existed so we could generate a modified version of an existing provider:
errorHandlerWithOptions.loggerWithOptions.appLoggerWithOptions.pathUtilsWithHome.
All the providers that those function used were transformed into providers creators, so they became unnecessary and were removed.
errorHandlerWithOptions
- app.register(errorHandlerWithOptions(exitOnError));
+ app.register(errorHandler({ exitOnError }));loggerWithOptions
- app.register(loggerWithOptions(messagesPrefix, showTime));
+ app.register(logger({ messagesPrefix, showTime }));appLoggerWithOptions
- app.register(appLoggerWithOptions(showTime));
+ app.register(appLogger({ showTime }));pathUtilsWithHome
- app.register(pathUtilsWithHome(home));
+ app.register(pathUtils({ home }));Everything is private/protected
It was a long overdue, probably because this is one of my oldest packages, but it was time to properly scope the classes resources and stop exposing everything.
One one side, you have the OOP reasons for using getters and setters instead of exposing the members, on the other... if everything is public, whenever I make a change, I have to be extremely careful so it won't be breaking.
So, all class properties have become private/protected with public getters so they can still be accessed... except for properties that hold references for injected values, they don't get public getters as, if you need to use those services, you shouldn't do it by using another service as a proxy.
There's no "migration" for accessing the dependencies of a services through its properties, it dependes on the use case, but... extend the class, overwrite the provider, create your own service. There are a few alternatives you could consider.
A special note, ErrorHandler#eventsNames didn't get a public getter either; it didn't make sense to expose that property.
Now, I know the difference between protected and private, but I documented it as "private/protected" because the JSDoc tag says @access protected, but the only convention we have to not expose things as public is prefixing it with _... which makes them "private".
Probably, on a year or so, when Node 12 becomes the oldest LTS and Firefox adds support for them, these properties will become private class fields.