@modernpoacher/halacious 7.0.4 → 7.0.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernpoacher/halacious",
3
- "version": "7.0.4",
3
+ "version": "7.0.6",
4
4
  "description": "A HAL processor for Hapi",
5
5
  "keywords": [
6
6
  "HAL",
@@ -59,14 +59,14 @@
59
59
  "@hapi/vision": "^7.0.3",
60
60
  "@modernpoacher/hooks": "^1.0.457",
61
61
  "@sequencemedia/sinon-chai": "^0.0.6",
62
- "@typescript-eslint/eslint-plugin": "^6.19.0",
63
- "@typescript-eslint/parser": "^6.19.0",
62
+ "@typescript-eslint/eslint-plugin": "^6.19.1",
63
+ "@typescript-eslint/parser": "^6.19.1",
64
64
  "chai": "^5.0.0",
65
65
  "cross-env": "^7.0.3",
66
66
  "eslint": "^8.56.0",
67
67
  "eslint-config-standard": "^17.1.0",
68
68
  "eslint-config-standard-with-typescript": "^43.0.1",
69
- "husky": "^8.0.3",
69
+ "husky": "^9.0.1",
70
70
  "mocha": "^10.2.0",
71
71
  "sinon": "^17.0.1"
72
72
  },
package/src/plugin.mjs CHANGED
@@ -26,7 +26,7 @@ import URITemplate from 'urijs/src/URITemplate.js'
26
26
  import PKG from '#package' assert { type: 'json' }
27
27
  import IAM from '#where-am-i'
28
28
 
29
- import RepresentationFactory from './representation.mjs'
29
+ import RepresentationFactory from './representationFactory.mjs'
30
30
 
31
31
  import {
32
32
  getRepresentationEntity,
@@ -14,13 +14,13 @@ const TEMPLATE = /{*}/
14
14
  * entities.
15
15
  *
16
16
  * @param factory
17
- * @param self
18
17
  * @param entity
18
+ * @param self
19
19
  * @param root
20
20
  * @constructor
21
21
  */
22
22
  export class Representation {
23
- constructor (factory, self, entity, root = this) {
23
+ constructor (factory, entity, link, root = this) {
24
24
  const {
25
25
  _halacious: halacious,
26
26
  _request: request
@@ -28,15 +28,15 @@ export class Representation {
28
28
 
29
29
  const {
30
30
  href
31
- } = self
31
+ } = link
32
32
 
33
33
  const links = {
34
- self
34
+ self: link
35
35
  }
36
36
 
37
37
  this.factory = factory
38
- this.self = href
39
38
  this.entity = entity
39
+ this.self = href
40
40
  this._root = root
41
41
  this._halacious = halacious
42
42
  this._request = request
@@ -179,7 +179,7 @@ export class Representation {
179
179
  * @return {{}}
180
180
  */
181
181
  toJSON () {
182
- // initialize the json entity
182
+ // initialize the entity
183
183
  const object = { _links: this.getLinks() }
184
184
 
185
185
  // copy all target properties in the entity using JSON.stringify(). if the entity has a .toJSON() implementation,
@@ -191,18 +191,11 @@ export class Representation {
191
191
  const ignore = this.getIgnore()
192
192
 
193
193
  JSON.stringify(entity, (key, value) => {
194
- if (!key) {
195
- return value
196
- }
194
+ if (!key) return value
197
195
 
198
196
  if (!ignore.has(key)) Reflect.set(object, key, value)
199
197
  })
200
198
 
201
- const props = this.getProps()
202
-
203
- // merge in any extra properties
204
- Object.assign(object, Object.fromEntries(Array.from(props.entries()).filter(([key]) => !ignore.has(key))))
205
-
206
199
  const embedded = this.getEmbedded()
207
200
 
208
201
  const entries = Object.entries(embedded)
@@ -221,9 +214,7 @@ export class Representation {
221
214
  }
222
215
 
223
216
  JSON.stringify(entryValue, (key, value) => {
224
- if (!key) {
225
- return value
226
- }
217
+ if (!key) return value
227
218
 
228
219
  if (!ignore.has(key)) Reflect.set(currentValue, key, value)
229
220
  })
@@ -235,7 +226,12 @@ export class Representation {
235
226
  )
236
227
  }
237
228
 
238
- return object
229
+ const props = this.getProps()
230
+
231
+ // merge in any extra properties
232
+ return (
233
+ Object.assign(object, Object.fromEntries(Array.from(props.entries()).filter(([key]) => !ignore.has(key))))
234
+ )
239
235
  }
240
236
 
241
237
  /**
@@ -386,60 +382,4 @@ export class Representation {
386
382
  }
387
383
  }
388
384
 
389
- /**
390
- * Responsible for creating all hal entities, top level or embedded, needed for a Hapi request
391
- *
392
- * @param halacious a reference to the plugin api
393
- * @param request a hapi request object
394
- * @constructor
395
- */
396
- export class RepresentationFactory {
397
- constructor (halacious, request) {
398
- this._halacious = halacious
399
- this._request = request
400
- }
401
-
402
- getHalacious () {
403
- return this._halacious
404
- }
405
-
406
- getRequest () {
407
- return this._request
408
- }
409
-
410
- getRequestPath () {
411
- return this.getRequest()?.path
412
- }
413
-
414
- get halacious () {
415
- return this._halacious
416
- }
417
-
418
- get request () {
419
- return this._request
420
- }
421
-
422
- get requestPath () {
423
- return this.request?.path
424
- }
425
-
426
- /**
427
- * Creates a new hal representation out of a javascript object
428
- * @param {{}=} entity the entity to wrap with a representation. an empty object is created by default
429
- * @param {String || {}=} self the self href or link object. The request's path is used by default
430
- * @param {Representation} root a pointer to the top level representation for adding curied links
431
- * should be expanded into absolute urls
432
- * @return {Representation}
433
- */
434
- create (entity = {}, self = this.getRequestPath(), root) {
435
- const halacious = this.getHalacious()
436
-
437
- const link = halacious.link(self)
438
-
439
- return (
440
- new Representation(this, link, entity, root)
441
- )
442
- }
443
- }
444
-
445
- export default RepresentationFactory
385
+ export default Representation
@@ -0,0 +1,60 @@
1
+ import Representation from './representation.mjs'
2
+
3
+ /**
4
+ * Responsible for creating all hal entities, top level or embedded, needed for a Hapi request
5
+ *
6
+ * @param halacious a reference to the plugin api
7
+ * @param request a hapi request object
8
+ * @constructor
9
+ */
10
+ export class RepresentationFactory {
11
+ constructor (halacious, request) {
12
+ this._halacious = halacious
13
+ this._request = request
14
+ }
15
+
16
+ getHalacious () {
17
+ return this._halacious
18
+ }
19
+
20
+ getRequest () {
21
+ return this._request
22
+ }
23
+
24
+ getRequestPath () {
25
+ console.log(this.getRequest()?.path)
26
+ return this.getRequest()?.path
27
+ }
28
+
29
+ get halacious () {
30
+ return this._halacious
31
+ }
32
+
33
+ get request () {
34
+ return this._request
35
+ }
36
+
37
+ get requestPath () {
38
+ return this.request?.path
39
+ }
40
+
41
+ /**
42
+ * Creates a new hal representation out of a javascript object
43
+ * @param {{}=} entity the entity to wrap with a representation. an empty object is created by default
44
+ * @param {String || {}=} self the self href or link object. The request's path is used by default
45
+ * @param {Representation} root a pointer to the top level representation for adding curied links
46
+ * should be expanded into absolute urls
47
+ * @return {Representation}
48
+ */
49
+ create (entity = {}, self = this.getRequestPath(), root) {
50
+ const halacious = this.getHalacious()
51
+
52
+ const link = halacious.link(self)
53
+
54
+ return (
55
+ new Representation(this, entity, link, root)
56
+ )
57
+ }
58
+ }
59
+
60
+ export default RepresentationFactory
package/babel.config.cjs DELETED
@@ -1,44 +0,0 @@
1
- const debug = require('debug')
2
-
3
- const log = debug('@modernpoacher/halacious')
4
-
5
- const {
6
- env: {
7
- NODE_ENV = 'development'
8
- }
9
- } = process
10
-
11
- log('`@modernpoacher/halacious` is awake')
12
-
13
- function env () {
14
- log({ NODE_ENV })
15
-
16
- return (
17
- NODE_ENV === 'production'
18
- )
19
- }
20
-
21
- const presets = [
22
- [
23
- '@babel/env', {
24
- targets: {
25
- node: 'current'
26
- },
27
- useBuiltIns: 'usage',
28
- corejs: 3
29
- }
30
- ]
31
- ]
32
-
33
- const plugins = [
34
- '@babel/syntax-import-assertions'
35
- ]
36
-
37
- module.exports = (api) => {
38
- if (api) api.cache.using(env)
39
-
40
- return {
41
- presets,
42
- plugins
43
- }
44
- }