ts-japi 1.5.1 → 1.6.2

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 (108) hide show
  1. package/.prettierrc +10 -0
  2. package/CHANGELOG.md +56 -16
  3. package/Makefile +19 -0
  4. package/README.md +235 -159
  5. package/api-extractor.json +14 -0
  6. package/benchmarks/playground.benchmark.ts +32 -32
  7. package/benchmarks/serializer.benchmark.ts +29 -29
  8. package/lib/classes/cache.d.ts +6 -6
  9. package/lib/classes/cache.d.ts.map +1 -1
  10. package/lib/classes/cache.js +26 -48
  11. package/lib/classes/cache.js.map +1 -1
  12. package/lib/classes/error-serializer.d.ts +9 -9
  13. package/lib/classes/error-serializer.d.ts.map +1 -1
  14. package/lib/classes/error-serializer.js +58 -125
  15. package/lib/classes/error-serializer.js.map +1 -1
  16. package/lib/classes/linker.d.ts +8 -8
  17. package/lib/classes/linker.d.ts.map +1 -1
  18. package/lib/classes/linker.js +15 -40
  19. package/lib/classes/linker.js.map +1 -1
  20. package/lib/classes/metaizer.d.ts +6 -6
  21. package/lib/classes/metaizer.d.ts.map +1 -1
  22. package/lib/classes/metaizer.js +12 -37
  23. package/lib/classes/metaizer.js.map +1 -1
  24. package/lib/classes/paginator.d.ts +6 -6
  25. package/lib/classes/paginator.d.ts.map +1 -1
  26. package/lib/classes/paginator.js +17 -16
  27. package/lib/classes/paginator.js.map +1 -1
  28. package/lib/classes/relator.d.ts +19 -18
  29. package/lib/classes/relator.d.ts.map +1 -1
  30. package/lib/classes/relator.js +70 -110
  31. package/lib/classes/relator.js.map +1 -1
  32. package/lib/classes/serializer.d.ts +20 -19
  33. package/lib/classes/serializer.d.ts.map +1 -1
  34. package/lib/classes/serializer.js +213 -311
  35. package/lib/classes/serializer.js.map +1 -1
  36. package/lib/index.d.ts +20 -20
  37. package/lib/index.js +17 -10
  38. package/lib/index.js.map +1 -1
  39. package/lib/interfaces/cache.interface.d.ts +3 -3
  40. package/lib/interfaces/cache.interface.d.ts.map +1 -1
  41. package/lib/interfaces/cache.interface.js +1 -1
  42. package/lib/interfaces/error-serializer.interface.d.ts +15 -15
  43. package/lib/interfaces/error-serializer.interface.d.ts.map +1 -1
  44. package/lib/interfaces/error-serializer.interface.js +1 -1
  45. package/lib/interfaces/error.interface.d.ts.map +1 -1
  46. package/lib/interfaces/error.interface.js +1 -1
  47. package/lib/interfaces/json-api.interface.d.ts +7 -7
  48. package/lib/interfaces/json-api.interface.d.ts.map +1 -1
  49. package/lib/interfaces/json-api.interface.js +1 -1
  50. package/lib/interfaces/linker.interface.d.ts +2 -2
  51. package/lib/interfaces/linker.interface.d.ts.map +1 -1
  52. package/lib/interfaces/linker.interface.js +1 -1
  53. package/lib/interfaces/paginator.interface.d.ts +1 -1
  54. package/lib/interfaces/paginator.interface.d.ts.map +1 -1
  55. package/lib/interfaces/paginator.interface.js +1 -1
  56. package/lib/interfaces/relator.interface.d.ts +7 -7
  57. package/lib/interfaces/relator.interface.d.ts.map +1 -1
  58. package/lib/interfaces/relator.interface.js +1 -1
  59. package/lib/interfaces/serializer.interface.d.ts +30 -30
  60. package/lib/interfaces/serializer.interface.d.ts.map +1 -1
  61. package/lib/interfaces/serializer.interface.js +1 -1
  62. package/lib/models/error.model.d.ts +5 -5
  63. package/lib/models/error.model.d.ts.map +1 -1
  64. package/lib/models/error.model.js +59 -22
  65. package/lib/models/error.model.js.map +1 -1
  66. package/lib/models/link.model.d.ts +2 -2
  67. package/lib/models/link.model.d.ts.map +1 -1
  68. package/lib/models/link.model.js +11 -10
  69. package/lib/models/link.model.js.map +1 -1
  70. package/lib/models/meta.model.d.ts.map +1 -1
  71. package/lib/models/meta.model.js +5 -6
  72. package/lib/models/meta.model.js.map +1 -1
  73. package/lib/models/relationship.model.d.ts +4 -4
  74. package/lib/models/relationship.model.d.ts.map +1 -1
  75. package/lib/models/relationship.model.js +11 -9
  76. package/lib/models/relationship.model.js.map +1 -1
  77. package/lib/models/resource-identifier.model.d.ts +1 -1
  78. package/lib/models/resource-identifier.model.d.ts.map +1 -1
  79. package/lib/models/resource-identifier.model.js +11 -9
  80. package/lib/models/resource-identifier.model.js.map +1 -1
  81. package/lib/models/resource.model.d.ts +4 -4
  82. package/lib/models/resource.model.d.ts.map +1 -1
  83. package/lib/models/resource.model.js +13 -26
  84. package/lib/models/resource.model.js.map +1 -1
  85. package/lib/tsdoc-metadata.json +11 -0
  86. package/lib/types/global.types.d.ts.map +1 -1
  87. package/lib/types/global.types.js +1 -1
  88. package/lib/utils/is-error-document.d.ts +2 -2
  89. package/lib/utils/is-error-document.js +7 -9
  90. package/lib/utils/is-error-document.js.map +1 -1
  91. package/lib/utils/is-object.js +2 -2
  92. package/lib/utils/is-object.js.map +1 -1
  93. package/lib/utils/is-plain-object.js +6 -6
  94. package/lib/utils/is-plain-object.js.map +1 -1
  95. package/lib/utils/merge.d.ts +3 -3
  96. package/lib/utils/merge.d.ts.map +1 -1
  97. package/lib/utils/merge.js +16 -62
  98. package/lib/utils/merge.js.map +1 -1
  99. package/lib/utils/serializer.utils.d.ts +5 -4
  100. package/lib/utils/serializer.utils.d.ts.map +1 -1
  101. package/lib/utils/serializer.utils.js +57 -168
  102. package/lib/utils/serializer.utils.js.map +1 -1
  103. package/package.json +94 -107
  104. package/tools/generate_docs.ts +33 -0
  105. package/tools/internal/custom_markdown_action.ts +32 -0
  106. package/tools/internal/custom_markdown_documenter.ts +1337 -0
  107. package/tsconfig.json +60 -83
  108. package/CONTRIBUTING.md +0 -127
package/.prettierrc ADDED
@@ -0,0 +1,10 @@
1
+ printWidth: 100
2
+ tabWidth: 2
3
+ useTabs: false
4
+ semi: true
5
+ singleQuote: true
6
+ quoteProps: 'consistent'
7
+ trailingComma: 'es5'
8
+ bracketSpacing: true
9
+ arrowParens: 'always'
10
+ proseWrap: 'always'
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c5a8201: Add customisable relationship names
8
+
9
+ ## 1.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - d5cd4d1: Updated dependencies
14
+
15
+ ## 1.6.0
16
+
17
+ ### Minor Changes
18
+
19
+ - bd4c358: Add `relatorDataCache` in serialize method to avoid duplicate lookups during
20
+ `recurseRelators` call
21
+
3
22
  ## 1.5.1
4
23
 
5
24
  ### Patch Changes
@@ -11,7 +30,7 @@
11
30
 
12
31
  ### Minor Changes
13
32
 
14
- - Fixes https://github.com/mu-io/ts-japi/issues/23
33
+ - Fixes https://github.com/mathematic-inc/ts-japi/issues/23
15
34
 
16
35
  ## 1.4.0
17
36
 
@@ -23,8 +42,12 @@
23
42
 
24
43
  ### Added
25
44
 
26
- - 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).
27
- - 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).
45
+ - Added an `isErrorDocument` function to detect JSON:API Error documents. This function allows you
46
+ to treat the argument _as if it were an error document_ (there is obviously no way to know if it
47
+ really is a JSON:API error document at runtime).
48
+ - Added an `isLikeJapiError` function to detect JSON:API Error. This function allows you to treat
49
+ the argument _as if it were an JSON:API error_ (there is obviously no way to know if it really is
50
+ a JSON:API error at runtime).
28
51
 
29
52
  ### Changed
30
53
 
@@ -47,7 +70,8 @@
47
70
  ### Changed
48
71
 
49
72
  - Exported interfaces related to JSON:API.
50
- - The Error and Data document interfaces now require the "errors" and "data" properties respectively.
73
+ - The Error and Data document interfaces now require the "errors" and "data" properties
74
+ respectively.
51
75
  - The Base document interface has been abstracted further by removing the "meta" property.
52
76
  - A _new_ Meta document interface is now available for type-checking.
53
77
 
@@ -68,8 +92,10 @@
68
92
 
69
93
  ### Added
70
94
 
71
- - 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).
72
- - 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.
95
+ - A new `Cache` class is now available to use for caching. You can set this in the `cache` option
96
+ for a `Serializer` (use `true` if you want the built in cache).
97
+ - With caching, there is a ~586% speed improvement (412,768 ops/sec over the previous 70,435
98
+ ops/sec). Without-caching rates have stayed the same.
73
99
 
74
100
  ## [1.2.1] - 2020-05-27
75
101
 
@@ -79,11 +105,15 @@
79
105
 
80
106
  ## [1.2.0] - 2020-05-26
81
107
 
82
- So, `ts-japi` has only been released a few days, but after some significant use in my APIs, I have realized a few things:
108
+ So, `ts-japi` has only been released a few days, but after some significant use in my APIs, I have
109
+ realized a few things:
83
110
 
84
- 1. Linkers and certain classes should be allowed to parse `nullish` data (`nullish` meaning `undefined` or `null`).
85
- 2. The `relationships object` should be allowed to have custom keys, not dependent on the `relators` options
86
- - `Relator`s should always have a `Serializer`; otherwise, they wouldn't relate to any `resource` per se.
111
+ 1. Linkers and certain classes should be allowed to parse `nullish` data (`nullish` meaning
112
+ `undefined` or `null`).
113
+ 2. The `relationships object` should be allowed to have custom keys, not dependent on the `relators`
114
+ options
115
+ - `Relator`s should always have a `Serializer`; otherwise, they wouldn't relate to any `resource`
116
+ per se.
87
117
  3. Projections should be "choose included" or "choose excluded" similar to MongoDB's.
88
118
  4. The code can be faster.
89
119
 
@@ -91,15 +121,22 @@ With this in mind, here are the changes.
91
121
 
92
122
  ### Changed
93
123
 
94
- - **[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.
95
- - 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.
96
- - 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.
124
+ - **[Breaking Change]** Every relator must define a `Serializer` as the second argument in its
125
+ constructor (as opposed to the relator's options. Options can go in the third argument.
126
+ - It may be subtle, but the reason for this lies in the fact `relationships object` must be keyed
127
+ by the related object. If the relator has no serializer, then the relator has no related name,
128
+ hence there is no canonical way to key the relationship.
129
+ - We will now allow objects of relators to be defined as an option for `relators` on
130
+ `Serializer`s. By using objects, the key for the relationship generated by the relator will
131
+ correspond to the same key for that of the relator's.
97
132
  - Several functional options now allow for `nullish` (`null` or `undefined`) arguments:
98
133
  - Resource Linkers can now type-safely use `nullish` arguments.
99
134
  - Resource Metaizers can now type-safely use `nullish` arguments.
100
135
  - Several plain options now allow for `nullish` (`null` or `undefined`):
101
- - Serializer `projection` option has changed significantly (see the option itself) with `nullish` values.
102
- - There is a ~33% speed improvement. (70,435 ops/sec over 52,843 ops/sec on a low-end Macbook Pro 15")
136
+ - Serializer `projection` option has changed significantly (see the option itself) with `nullish`
137
+ values.
138
+ - There is a ~33% speed improvement. (70,435 ops/sec over 52,843 ops/sec on a low-end Macbook Pro
139
+ 15")
103
140
 
104
141
  ### Added
105
142
 
@@ -107,4 +144,7 @@ With this in mind, here are the changes.
107
144
 
108
145
  #### Important Note
109
146
 
110
- I want to say this IS unusual to have a breaking change without depreciation, but given the fact this package is only a few days old, I want to apologize if you are bothered by the above break. However, I will guarantee that API changes will go through depreciation before removal, so happy coding :)
147
+ I want to say this IS unusual to have a breaking change without depreciation, but given the fact
148
+ this package is only a few days old, I want to apologize if you are bothered by the above break.
149
+ However, I will guarantee that API changes will go through depreciation before removal, so happy
150
+ coding :)
package/Makefile ADDED
@@ -0,0 +1,19 @@
1
+ PATH:=$(PATH):$(PWD)/node_modules/.bin
2
+ SHELL:=env PATH=$(PATH) /bin/bash
3
+
4
+ clean: clean-build clean-coverage
5
+
6
+ clean-lib:
7
+ @echo 'Cleaning build artifacts...'
8
+ @rm -rf ./lib
9
+
10
+ clean-coverage:
11
+ @echo 'Cleaning test coverage...'
12
+ @rm -rf ./coverage
13
+
14
+ .PHONY: all
15
+ .PHONY: clean
16
+ .PHONY: clean-docs
17
+ .PHONY: clean-readme
18
+ .PHONY: clean-lib
19
+ .PHONY: clean-coverage