@modernpoacher/halacious 6.2.9 → 6.3.0
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/examples/{api-root.js → api-root.cjs} +1 -1
- package/examples/{auto-namespace.js → auto-namespace.cjs} +1 -1
- package/index.mjs +1 -0
- package/package.json +8 -8
- package/{lib/index.d.ts → src/index.d.mts} +2 -2
- package/src/index.mjs +2 -0
- package/{lib/plugin.js → src/plugin.mjs} +33 -29
- package/{lib/representation.js → src/representation.mjs} +6 -6
- package/test/{plugin.spec.js → plugin.spec.mjs} +17 -15
- package/test/{representation.spec.js → representation.spec.mjs} +5 -6
- package/where-am-i.mjs +9 -0
- package/index.js +0 -3
- package/lib/index.js +0 -2
- /package/examples/{array-of-links.js → array-of-links.cjs} +0 -0
- /package/examples/{functional-href.js → functional-href.cjs} +0 -0
- /package/examples/{hello-world.js → hello-world.cjs} +0 -0
- /package/examples/{manual-namespace.js → manual-namespace.cjs} +0 -0
- /package/examples/{media-types.js → media-types.cjs} +0 -0
- /package/examples/{paging.js → paging.cjs} +0 -0
- /package/examples/{programmatic-entity.js → programmatic-entity.cjs} +0 -0
- /package/examples/{programmatic-route.js → programmatic-route.cjs} +0 -0
- /package/examples/{query-string.js → query-string.cjs} +0 -0
- /package/examples/{simple-embed.js → simple-embed.cjs} +0 -0
- /package/examples/{simple-link.js → simple-link.cjs} +0 -0
- /package/{index.d.ts → index.d.mts} +0 -0
|
@@ -2,7 +2,7 @@ const hapi = require('@hapi/hapi')
|
|
|
2
2
|
const vision = require('@hapi/vision')
|
|
3
3
|
const halacious = require('#halacious')
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const PLUGIN = '@modernpoacher/halacious'
|
|
6
6
|
|
|
7
7
|
async function init () {
|
|
8
8
|
const server = hapi.server({ port: 8080 })
|
|
@@ -4,7 +4,7 @@ const hapi = require('@hapi/hapi')
|
|
|
4
4
|
const vision = require('@hapi/vision')
|
|
5
5
|
const halacious = require('#halacious')
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const PLUGIN = '@modernpoacher/halacious'
|
|
8
8
|
|
|
9
9
|
async function init () {
|
|
10
10
|
const server = hapi.server({ port: 8080 })
|
package/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as default from './src/index.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modernpoacher/halacious",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "A HAL processor for Hapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"HAL",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"hypermedia",
|
|
9
9
|
"HATEOAS"
|
|
10
10
|
],
|
|
11
|
-
"
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./src/index.mjs",
|
|
12
13
|
"author": "Jonathan Perry <modernpoacher@modernpoacher.com> (Modern Poacher Limited)",
|
|
13
14
|
"contributors": [
|
|
14
15
|
"Brad Leupen"
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"url": "https://github.com/modernpoacher/halacious/issues"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
|
-
"lint": "eslint .",
|
|
30
|
+
"lint": "eslint . --ext .mjs --ext .cjs --ext .mts --ext .cts",
|
|
30
31
|
"lint:fix": "npm run lint -- --fix",
|
|
31
32
|
"test": "cross-env NODE_ENV=test mocha test",
|
|
32
33
|
"prepare": "husky install"
|
|
@@ -68,12 +69,11 @@
|
|
|
68
69
|
"sinon-chai": "^3.7.0"
|
|
69
70
|
},
|
|
70
71
|
"imports": {
|
|
71
|
-
"#halacious
|
|
72
|
-
"#halacious
|
|
73
|
-
"#
|
|
72
|
+
"#halacious/*": "./src/*.mjs",
|
|
73
|
+
"#halacious": "./src/index.mjs",
|
|
74
|
+
"#where-am-i": "./where-am-i.mjs"
|
|
74
75
|
},
|
|
75
76
|
"exports": {
|
|
76
|
-
"
|
|
77
|
-
".": "./lib/index.js"
|
|
77
|
+
".": "./src/index.mjs"
|
|
78
78
|
}
|
|
79
79
|
}
|
package/src/index.mjs
ADDED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import joi from '@hapi/joi'
|
|
2
|
+
import boom from '@hapi/boom'
|
|
3
|
+
import hoek from '@hapi/hoek'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import pug from 'pug'
|
|
8
|
+
import util from 'util'
|
|
9
|
+
import async from 'async'
|
|
10
|
+
import {
|
|
11
11
|
marked
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
} from 'marked'
|
|
13
|
+
import {
|
|
14
14
|
mangle
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
} from 'marked-mangle'
|
|
16
|
+
import {
|
|
17
17
|
gfmHeadingId
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
RepresentationFactory
|
|
27
|
-
} = require('./representation')
|
|
18
|
+
} from 'marked-gfm-heading-id'
|
|
19
|
+
import urlTemplate from 'url-template'
|
|
20
|
+
import Negotiator from 'negotiator'
|
|
21
|
+
import URITemplate from 'urijs/src/URITemplate.js'
|
|
22
|
+
import url from 'url'
|
|
23
|
+
import URI from 'urijs'
|
|
24
|
+
import IAM from '#where-am-i'
|
|
25
|
+
import RepresentationFactory from './representation.mjs'
|
|
28
26
|
|
|
29
27
|
const HAL_MIME_TYPE = 'application/hal+json'
|
|
30
28
|
|
|
31
|
-
const
|
|
29
|
+
const REG = /{([^{}]+)}|([^{}]+)/g
|
|
30
|
+
|
|
31
|
+
const PKG = JSON.parse(fs.readFileSync(path.join(IAM, './package.json')))
|
|
32
32
|
|
|
33
33
|
function reach (object, path) {
|
|
34
34
|
const parts = path ? path.split('.') : []
|
|
@@ -51,7 +51,7 @@ function flattenContext (template, ctx) {
|
|
|
51
51
|
let arr
|
|
52
52
|
const result = {}
|
|
53
53
|
|
|
54
|
-
while ((arr =
|
|
54
|
+
while ((arr = REG.exec(template)) !== null) {
|
|
55
55
|
if (arr[1]) {
|
|
56
56
|
const value = reach(ctx, arr[1])
|
|
57
57
|
result[arr[1]] = value && value.toString()
|
|
@@ -92,8 +92,8 @@ const optionsSchema = {
|
|
|
92
92
|
* @param opts
|
|
93
93
|
* @param next
|
|
94
94
|
*/
|
|
95
|
-
|
|
96
|
-
pkg:
|
|
95
|
+
const plugin = {
|
|
96
|
+
pkg: PKG,
|
|
97
97
|
|
|
98
98
|
async register (server, opts) {
|
|
99
99
|
let settings = opts
|
|
@@ -964,7 +964,7 @@ exports.plugin = {
|
|
|
964
964
|
engines: {
|
|
965
965
|
jade: pug
|
|
966
966
|
},
|
|
967
|
-
path: path.join(
|
|
967
|
+
path: path.join(IAM, './views'),
|
|
968
968
|
isCached: false
|
|
969
969
|
})
|
|
970
970
|
server.route({
|
|
@@ -983,3 +983,7 @@ exports.plugin = {
|
|
|
983
983
|
server.ext('onPreStart', internals.preStart)
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
|
+
|
|
987
|
+
export {
|
|
988
|
+
plugin
|
|
989
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import _ from 'lodash'
|
|
3
|
+
import hoek from '@hapi/hoek'
|
|
4
|
+
import URI from 'urijs'
|
|
4
5
|
|
|
5
|
-
const URI = require('urijs')
|
|
6
6
|
const templatedRE = /{*}/
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -15,7 +15,7 @@ const templatedRE = /{*}/
|
|
|
15
15
|
* @param root
|
|
16
16
|
* @constructor
|
|
17
17
|
*/
|
|
18
|
-
class Representation {
|
|
18
|
+
export class Representation {
|
|
19
19
|
constructor (factory, self, entity, root) {
|
|
20
20
|
this._halacious = factory._halacious
|
|
21
21
|
this.factory = factory
|
|
@@ -247,7 +247,7 @@ class Representation {
|
|
|
247
247
|
* @param request a hapi request object
|
|
248
248
|
* @constructor
|
|
249
249
|
*/
|
|
250
|
-
class RepresentationFactory {
|
|
250
|
+
export class RepresentationFactory {
|
|
251
251
|
constructor (halacious, request) {
|
|
252
252
|
this._halacious = halacious
|
|
253
253
|
this._request = request
|
|
@@ -269,4 +269,4 @@ class RepresentationFactory {
|
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
export default RepresentationFactory
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'path'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import chai from 'chai'
|
|
4
|
+
|
|
5
|
+
import hapi from '@hapi/hapi'
|
|
6
|
+
import vision from '@hapi/vision'
|
|
7
|
+
import sinon from 'sinon'
|
|
8
|
+
import sinonChai from 'sinon-chai'
|
|
9
|
+
import chaiString from 'chai-string'
|
|
10
|
+
import halacious from '#halacious'
|
|
11
|
+
import { plugin } from '#halacious/plugin'
|
|
12
|
+
import _ from 'lodash'
|
|
13
|
+
import url from 'url'
|
|
14
|
+
import IAM from '#where-am-i'
|
|
4
15
|
|
|
5
16
|
const should = chai.should()
|
|
6
|
-
const hapi = require('@hapi/hapi')
|
|
7
|
-
const vision = require('@hapi/vision')
|
|
8
|
-
const sinon = require('sinon')
|
|
9
|
-
const sinonChai = require('sinon-chai')
|
|
10
|
-
const chaiString = require('chai-string')
|
|
11
|
-
const halacious = require('#halacious')
|
|
12
|
-
const { plugin } = require('#halacious/lib/plugin')
|
|
13
|
-
const _ = require('lodash')
|
|
14
|
-
const url = require('url')
|
|
15
17
|
|
|
16
18
|
chai.use(sinonChai)
|
|
17
19
|
chai.use(chaiString)
|
|
18
20
|
|
|
19
|
-
const
|
|
21
|
+
const PLUGIN = '@modernpoacher/halacious'
|
|
20
22
|
|
|
21
23
|
describe('Halacious Plugin', () => {
|
|
22
24
|
let server
|
|
@@ -346,7 +348,7 @@ describe('Halacious Plugin', () => {
|
|
|
346
348
|
} = server
|
|
347
349
|
|
|
348
350
|
namespaces.add({
|
|
349
|
-
dir: path.
|
|
351
|
+
dir: path.join(IAM, './test/rels/mycompany'),
|
|
350
352
|
prefix: 'mco'
|
|
351
353
|
})
|
|
352
354
|
})
|
|
@@ -373,7 +375,7 @@ describe('Halacious Plugin', () => {
|
|
|
373
375
|
} = server
|
|
374
376
|
|
|
375
377
|
const namespace = plugin.namespaces.add({
|
|
376
|
-
dir: path.
|
|
378
|
+
dir: path.join(IAM, './test/rels/mycompany'),
|
|
377
379
|
prefix: 'mco'
|
|
378
380
|
})
|
|
379
381
|
|
|
@@ -402,7 +404,7 @@ describe('Halacious Plugin', () => {
|
|
|
402
404
|
} = server
|
|
403
405
|
|
|
404
406
|
plugin.namespaces.add({
|
|
405
|
-
dir: path.
|
|
407
|
+
dir: path.join(IAM, './test/rels/mycompany'),
|
|
406
408
|
prefix: 'mco'
|
|
407
409
|
})
|
|
408
410
|
})
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import chai from 'chai'
|
|
2
|
+
import hapi from '@hapi/hapi'
|
|
3
|
+
import halacious from '#halacious'
|
|
4
|
+
import RepresentationFactory from '#halacious/representation'
|
|
2
5
|
|
|
3
6
|
const should = chai.should()
|
|
4
|
-
const hapi = require('@hapi/hapi')
|
|
5
|
-
const halacious = require('#halacious')
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const { name: PLUGIN } = require('#halacious/package.json')
|
|
8
|
+
const PLUGIN = '@modernpoacher/halacious'
|
|
10
9
|
|
|
11
10
|
describe('Representation Factory', () => {
|
|
12
11
|
let server
|
package/where-am-i.mjs
ADDED
package/index.js
DELETED
package/lib/index.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|