Comparing version 1.3.1 to 1.4.0
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## 1.4.0 | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
### Minor Changes | ||
- 3dc7c4c: Allow null for empty to-one relationships | ||
## [1.3.0] - 2020-06-23 | ||
@@ -12,13 +13,13 @@ | ||
* Added an `isErrorDocument` function to detect JSON:API Error documents. This function allows you to treat the argument *as if it were an error document* (there is obviously no way to know if it really is a JSON:API error document at runtime). | ||
* Added an `isLikeJapiError` function to detect JSON:API Error. This function allows you to treat the argument *as if it were an JSON:API error* (there is obviously no way to know if it really is a JSON:API error at runtime). | ||
- Added an `isErrorDocument` function to detect JSON:API Error documents. This function allows you to treat the argument _as if it were an error document_ (there is obviously no way to know if it really is a JSON:API error document at runtime). | ||
- Added an `isLikeJapiError` function to detect JSON:API Error. This function allows you to treat the argument _as if it were an JSON:API error_ (there is obviously no way to know if it really is a JSON:API error at runtime). | ||
### Changed | ||
* Exported a `isPlainObject` and `isObjectObject` functions from internal. | ||
- Exported a `isPlainObject` and `isObjectObject` functions from internal. | ||
## [1.2.7] - 2020-06-22 | ||
* Fix for #10 | ||
* Fix for #11 | ||
- Fix for #10 | ||
- Fix for #11 | ||
@@ -29,4 +30,4 @@ ## [1.2.6] - 2020-06-19 | ||
* Changed user-level repo to org-level repo. | ||
* Links have been fixed in docs and README | ||
- Changed user-level repo to org-level repo. | ||
- Links have been fixed in docs and README | ||
@@ -37,6 +38,6 @@ ## [1.2.5] - 2020-06-19 | ||
* Exported interfaces related to JSON:API. | ||
* The Error and Data document interfaces now require the "errors" and "data" properties respectively. | ||
* The Base document interface has been abstracted further by removing the "meta" property. | ||
* A *new* Meta document interface is now available for type-checking. | ||
- Exported interfaces related to JSON:API. | ||
- The Error and Data document interfaces now require the "errors" and "data" properties respectively. | ||
- The Base document interface has been abstracted further by removing the "meta" property. | ||
- A _new_ Meta document interface is now available for type-checking. | ||
@@ -47,3 +48,3 @@ ## [1.2.4] - 2020-06-19 | ||
* Smaller packaging | ||
- Smaller packaging | ||
@@ -54,4 +55,4 @@ ## [1.2.3] - 2020-06-06 | ||
* Updated license to Apache 2.0 | ||
* Fixed some grammatical errors in README | ||
- Updated license to Apache 2.0 | ||
- Fixed some grammatical errors in README | ||
@@ -62,4 +63,4 @@ ## [1.2.2] - 2020-05-27 | ||
* A new `Cache` class is now available to use for caching. You can set this in the `cache` option for a `Serializer` (use `true` if you want the built in cache). | ||
* With caching, there is a ~586% speed improvement (412,768 ops/sec over the previous 70,435 ops/sec). Without-caching rates have stayed the same. | ||
- A new `Cache` class is now available to use for caching. You can set this in the `cache` option for a `Serializer` (use `true` if you want the built in cache). | ||
- With caching, there is a ~586% speed improvement (412,768 ops/sec over the previous 70,435 ops/sec). Without-caching rates have stayed the same. | ||
@@ -70,3 +71,3 @@ ## [1.2.1] - 2020-05-27 | ||
* More keywords to `package.json` to help user search for this package. | ||
- More keywords to `package.json` to help user search for this package. | ||
@@ -79,3 +80,3 @@ ## [1.2.0] - 2020-05-26 | ||
2. The `relationships object` should be allowed to have custom keys, not dependent on the `relators` options | ||
* `Relator`s should always have a `Serializer`; otherwise, they wouldn't relate to any `resource` per se. | ||
- `Relator`s should always have a `Serializer`; otherwise, they wouldn't relate to any `resource` per se. | ||
3. Projections should be "choose included" or "choose excluded" similar to MongoDB's. | ||
@@ -88,15 +89,15 @@ 4. The code can be faster. | ||
* **[Breaking Change]** Every relator must define a `Serializer` as the second argument in its constructor (as opposed to the relator's options. Options can go in the third argument. | ||
* It may be subtle, but the reason for this lies in the fact `relationships object` must be keyed by the related object. If the relator has no serializer, then the relator has no related name, hence there is no canonical way to key the relationship. | ||
* We will now allow objects of relators to be defined as an option for `relators` on `Serializer`s. By using objects, the key for the relationship generated by the relator will correspond to the same key for that of the relator's. | ||
* Several functional options now allow for `nullish` (`null` or `undefined`) arguments: | ||
* Resource Linkers can now type-safely use `nullish` arguments. | ||
* Resource Metaizers can now type-safely use `nullish` arguments. | ||
* Several plain options now allow for `nullish` (`null` or `undefined`): | ||
* Serializer `projection` option has changed significantly (see the option itself) with `nullish` values. | ||
* There is a ~33% speed improvement. (70,435 ops/sec over 52,843 ops/sec on a low-end Macbook Pro 15") | ||
- **[Breaking Change]** Every relator must define a `Serializer` as the second argument in its constructor (as opposed to the relator's options. Options can go in the third argument. | ||
- It may be subtle, but the reason for this lies in the fact `relationships object` must be keyed by the related object. If the relator has no serializer, then the relator has no related name, hence there is no canonical way to key the relationship. | ||
- We will now allow objects of relators to be defined as an option for `relators` on `Serializer`s. By using objects, the key for the relationship generated by the relator will correspond to the same key for that of the relator's. | ||
- Several functional options now allow for `nullish` (`null` or `undefined`) arguments: | ||
- Resource Linkers can now type-safely use `nullish` arguments. | ||
- Resource Metaizers can now type-safely use `nullish` arguments. | ||
- Several plain options now allow for `nullish` (`null` or `undefined`): | ||
- Serializer `projection` option has changed significantly (see the option itself) with `nullish` values. | ||
- There is a ~33% speed improvement. (70,435 ops/sec over 52,843 ops/sec on a low-end Macbook Pro 15") | ||
### Added | ||
* Started a CHANGELOG to keep users updated. | ||
- Started a CHANGELOG to keep users updated. | ||
@@ -103,0 +104,0 @@ #### Important Note |
@@ -10,5 +10,6 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
exports.__esModule = true; | ||
exports.Serializer = exports.ErrorSerializer = exports.JapiError = exports.Relator = exports.Paginator = exports.Metaizer = exports.Linker = exports.Cache = void 0; | ||
var cache_1 = require("./classes/cache"); | ||
@@ -15,0 +16,0 @@ __createBinding(exports, cache_1, "default", "Cache"); |
@@ -5,9 +5,10 @@ "use strict"; | ||
function Relationship(options) { | ||
// data can be explicitly set to null for empty to-one relationships | ||
if (typeof options.data !== "undefined") | ||
this.data = options.data; | ||
if (options.links) | ||
this.links = options.links; | ||
if (options.data) | ||
this.data = options.data; | ||
if (options.meta) | ||
this.meta = options.meta; | ||
if (!this.links && !this.data && !this.meta) { | ||
if (typeof options.data === "undefined" && !this.links && !this.meta) { | ||
throw new Error("Relationships must contain at least a link, data, or meta. See https://jsonapi.org/format/#document-resource-object-relationships for more information."); | ||
@@ -14,0 +15,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
@@ -9,0 +9,0 @@ }; |
@@ -103,3 +103,5 @@ "use strict"; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, relator.getRelatedResource(datum)]; | ||
case 0: | ||
if (!(datum !== null)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, relator.getRelatedResource(datum)]; | ||
case 1: | ||
@@ -112,3 +114,4 @@ resource = _a.sent(); | ||
} | ||
return [2 /*return*/]; | ||
_a.label = 2; | ||
case 2: return [2 /*return*/]; | ||
} | ||
@@ -115,0 +118,0 @@ }); |
{ | ||
"name": "ts-japi", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification", | ||
@@ -25,4 +25,4 @@ "main": "lib/index.js", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
@@ -48,33 +48,33 @@ "author": "mu.io <dev@mathematic.io>", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.5", | ||
"@babel/core": "^7.10.5", | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.10.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@types/benchmark": "^1.0.33", | ||
"@types/jest": "^26.0.4", | ||
"@types/lodash": "^4.14.157", | ||
"@types/uuid": "^8.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
"@typescript-eslint/parser": "^3.6.1", | ||
"babel-jest": "^26.1.0", | ||
"@babel/cli": "^7.12.17", | ||
"@babel/core": "^7.12.17", | ||
"@babel/plugin-proposal-class-properties": "^7.12.13", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.12.13", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.12.13", | ||
"@babel/preset-env": "^7.12.17", | ||
"@babel/preset-typescript": "^7.12.17", | ||
"@changesets/cli": "^2.14.1", | ||
"@types/benchmark": "^2.1.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/lodash": "^4.14.168", | ||
"@types/uuid": "^8.3.0", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"babel-jest": "^26.6.3", | ||
"benchmark": "^2.1.4", | ||
"core-js": "^3.6.5", | ||
"eslint": "^7.4.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"jest": "^26.1.0", | ||
"lodash": "^4.17.19", | ||
"prettier": "^2.0.5", | ||
"regenerator-runtime": "^0.13.5", | ||
"snyk": "^1.362.0", | ||
"ts-node": "^8.10.2", | ||
"typedoc": "^0.17.0-3", | ||
"typedoc-plugin-markdown": "^2.3.1", | ||
"typescript": "^3.9.6", | ||
"uuid": "^8.2.0" | ||
"core-js": "^3.9.0", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.6.3", | ||
"lodash": "^4.17.20", | ||
"prettier": "^2.2.1", | ||
"regenerator-runtime": "^0.13.7", | ||
"snyk": "^1.458.0", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.20.25", | ||
"typedoc-plugin-markdown": "^3.5.0", | ||
"typescript": "^4.1.5", | ||
"uuid": "^8.3.2" | ||
}, | ||
@@ -81,0 +81,0 @@ "snyk": true, |
@@ -5,4 +5,2 @@ <br /> | ||
[![Travis (.com)](https://img.shields.io/travis/com/mu-io/ts-japi)](https://travis-ci.com/github/mu-io/ts-japi) | ||
[![Codecov](https://img.shields.io/codecov/c/github/mu-io/ts-japi?token=NR90UY1SAF)](https://codecov.io/gh/mu-io/ts-japi) | ||
[![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/mu-io/ts-japi)](https://snyk.io/test/github/mu-io/ts-japi) | ||
@@ -14,19 +12,19 @@ ![node-current](https://img.shields.io/node/v/ts-japi) | ||
* [Features](#features) | ||
* [Documentation](#documentation) | ||
* [Installation](#installation) | ||
* [Getting Started](#getting-started) | ||
* [Examples](#examples) | ||
* [Serialization](#serialization) | ||
* [Links](#links) | ||
* [Pagination](#pagination) | ||
* [Relationships](#relationships) | ||
* [Metadata](#metadata) | ||
* [Serializing Errors](#serializing-errors) | ||
* [Caching](#caching) | ||
* [Deserialization](#deserialization) | ||
* [Remarks](#remarks) | ||
* [FAQ](#faq) | ||
* [Contributing](#contributing) | ||
* [License](#license) | ||
- [Features](#features) | ||
- [Documentation](#documentation) | ||
- [Installation](#installation) | ||
- [Getting Started](#getting-started) | ||
- [Examples](#examples) | ||
- [Serialization](#serialization) | ||
- [Links](#links) | ||
- [Pagination](#pagination) | ||
- [Relationships](#relationships) | ||
- [Metadata](#metadata) | ||
- [Serializing Errors](#serializing-errors) | ||
- [Caching](#caching) | ||
- [Deserialization](#deserialization) | ||
- [Remarks](#remarks) | ||
- [FAQ](#faq) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
@@ -289,8 +287,4 @@ ## Features | ||
We stress the following: There are many clients readily built to consume JSON:API endpoints (see [here](https://jsonapi.org/implementations/)). It is **highly recommended** to use them and only use this for serialization. It would be an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern) **not** to do so since the problem of serialization and deserialization generally have distinct solutions (think [P vs. NP](https://en.wikipedia.org/wiki/P_versus_NP_problem)). | ||
We stress the following: There are many clients readily built to consume JSON:API endpoints (see [here](https://jsonapi.org/implementations/)). It is **highly recommended** to use them and only use this for serialization. | ||
For inquisitive developers: To be precise, serialization is optimized by increasing runtime data storage and decreasing computation time (with e.g., caching and stored functions). Deserialization is somewhat dual to serialization; it is increasingly computational with storage proportional to the desired formatting. Perhaps an abstract directed binary tree (ADBT) could be helpful? It turns out the design of JSON:API is not very tree-like (think about the locations the relationships and identifiers can go), so by the time data gets transfigured into an ADBT, we would have finished serializing the data directly. | ||
tl;dr: Serialization and deserialization are different types of actions for different paradigms, therefore they **must** be in different packages. | ||
## Remarks | ||
@@ -314,6 +308,2 @@ | ||
> Is the "zero dependencies" a gimmick?<a id="zdg"></a> | ||
In general, some packages obtain "zero dependencies" by simply hardcoding packages into their libraries. This can sometimes lead to an undesirable bulk for final consumers of the package. For us, we just couldn't find a package that can do what we do faster. For example, even [`is-plain-object`](https://mu-io.github.io/ts-japi/https://www.npmjs.com/package/is-plain-object) (which is useful, e.g., for identifying classes over "plain" objects) has some unnecessary comparisons that we optimized upon. | ||
## Contributing | ||
@@ -320,0 +310,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
126
2450
193420
30
318