@zuplo/cli 6.72.2 → 6.72.7

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 (102) hide show
  1. package/node_modules/@fastify/reply-from/.github/dependabot.yml +42 -2
  2. package/node_modules/@fastify/reply-from/README.md +3 -3
  3. package/node_modules/@fastify/reply-from/index.js +6 -1
  4. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.gitattributes +2 -0
  5. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/dependabot.yml +53 -0
  6. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/workflows/ci.yml +33 -0
  7. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/.github/workflows/lock-threads.yml +19 -0
  8. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/LICENSE +21 -0
  9. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/README.md +188 -0
  10. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/eslint.config.js +6 -0
  11. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/index.js +67 -0
  12. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/lib/getPluginName.js +25 -0
  13. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/lib/toCamelCase.js +10 -0
  14. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/package.json +70 -0
  15. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/bundlers.test.js +110 -0
  16. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/checkVersion.test.js +67 -0
  17. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/composite.test.js +14 -0
  18. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/esm/esm.mjs +11 -0
  19. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/esm/index.test.js +11 -0
  20. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/extractPluginName.test.js +49 -0
  21. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/mu1tip1e.composite.test.js +15 -0
  22. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/test.js +396 -0
  23. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/test/toCamelCase.test.js +24 -0
  24. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/example-async.tst.ts +19 -0
  25. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/example-callback.tst.ts +19 -0
  26. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/index.d.ts +54 -0
  27. package/node_modules/@fastify/reply-from/node_modules/fastify-plugin/types/index.tst.ts +249 -0
  28. package/node_modules/@fastify/reply-from/package.json +6 -7
  29. package/node_modules/@fastify/reply-from/test/incomplete-request.test.js +142 -0
  30. package/node_modules/@fastify/reply-from/types/index.tst.ts +123 -0
  31. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +35 -2
  32. package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
  33. package/node_modules/@posthog/core/dist/posthog-core-stateless.js +68 -56
  34. package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +68 -56
  35. package/node_modules/@posthog/core/dist/posthog-core.d.ts +2 -1
  36. package/node_modules/@posthog/core/dist/posthog-core.d.ts.map +1 -1
  37. package/node_modules/@posthog/core/dist/posthog-core.js +1 -0
  38. package/node_modules/@posthog/core/dist/posthog-core.mjs +1 -0
  39. package/node_modules/@posthog/core/dist/types.d.ts +1 -0
  40. package/node_modules/@posthog/core/dist/types.d.ts.map +1 -1
  41. package/node_modules/@posthog/core/dist/types.js +1 -0
  42. package/node_modules/@posthog/core/dist/types.mjs +1 -0
  43. package/node_modules/@posthog/core/package.json +1 -1
  44. package/node_modules/@posthog/core/src/posthog-core-stateless.ts +135 -72
  45. package/node_modules/@posthog/core/src/posthog-core.ts +3 -1
  46. package/node_modules/@posthog/core/src/types.ts +5 -0
  47. package/node_modules/@zuplo/core/package.json +1 -1
  48. package/node_modules/@zuplo/graphql/package.json +1 -1
  49. package/node_modules/@zuplo/openapi-tools/dist/overlay.d.ts.map +1 -1
  50. package/node_modules/@zuplo/openapi-tools/dist/overlay.js +85 -1
  51. package/node_modules/@zuplo/openapi-tools/dist/overlay.js.map +1 -1
  52. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js +82 -0
  53. package/node_modules/@zuplo/openapi-tools/dist/overlay.spec.js.map +1 -1
  54. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  55. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js +26 -0
  56. package/node_modules/@zuplo/otel/out/esm/chunk-X7TLQJWO.js.map +1 -0
  57. package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
  58. package/node_modules/@zuplo/otel/package.json +1 -1
  59. package/node_modules/@zuplo/runtime/out/esm/chunk-423FXHUV.js +399 -0
  60. package/node_modules/@zuplo/runtime/out/esm/chunk-423FXHUV.js.map +1 -0
  61. package/node_modules/@zuplo/runtime/out/esm/chunk-GBIUQ4JJ.js +30 -0
  62. package/node_modules/@zuplo/runtime/out/esm/chunk-GBIUQ4JJ.js.map +1 -0
  63. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  64. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  65. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  66. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  67. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +26 -0
  68. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js.map +1 -0
  69. package/node_modules/@zuplo/runtime/out/types/index.d.ts +1576 -288
  70. package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +1374 -156
  71. package/node_modules/@zuplo/runtime/out/types/sdks/aws/index.d.ts +2281 -0
  72. package/node_modules/@zuplo/runtime/package.json +5 -1
  73. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -4
  74. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +12 -2
  75. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -4
  76. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +12 -2
  77. package/node_modules/hono/dist/cjs/client/client.js +10 -1
  78. package/node_modules/hono/dist/cjs/client/utils.js +1 -1
  79. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  80. package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -1
  81. package/node_modules/hono/dist/cjs/middleware/etag/index.js +2 -1
  82. package/node_modules/hono/dist/cjs/middleware/method-override/index.js +5 -3
  83. package/node_modules/hono/dist/cjs/router/trie-router/node.js +9 -0
  84. package/node_modules/hono/dist/client/client.js +10 -1
  85. package/node_modules/hono/dist/client/utils.js +1 -1
  86. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  87. package/node_modules/hono/dist/middleware/compress/index.js +2 -1
  88. package/node_modules/hono/dist/middleware/etag/index.js +2 -1
  89. package/node_modules/hono/dist/middleware/method-override/index.js +5 -3
  90. package/node_modules/hono/dist/router/trie-router/node.js +9 -0
  91. package/node_modules/hono/dist/types/adapter/lambda-edge/handler.d.ts +1 -1
  92. package/node_modules/hono/dist/types/helper/websocket/index.d.ts +1 -1
  93. package/node_modules/hono/dist/types/middleware/language/language.d.ts +18 -0
  94. package/node_modules/hono/dist/types/utils/types.d.ts +1 -1
  95. package/node_modules/hono/package.json +4 -4
  96. package/package.json +6 -6
  97. package/node_modules/@fastify/reply-from/types/index.test-d.ts +0 -194
  98. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js +0 -26
  99. package/node_modules/@zuplo/otel/out/esm/chunk-T25G5RDX.js.map +0 -1
  100. package/node_modules/@zuplo/runtime/out/esm/chunk-IC7XGD5C.js +0 -403
  101. package/node_modules/@zuplo/runtime/out/esm/chunk-IC7XGD5C.js.map +0 -1
  102. /package/node_modules/@zuplo/runtime/out/esm/{chunk-IC7XGD5C.js.LEGAL.txt → chunk-423FXHUV.js.LEGAL.txt} +0 -0
@@ -0,0 +1,110 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const fp = require('..')
5
+
6
+ test('webpack removes require.main.filename', t => {
7
+ const filename = require.main.filename
8
+ const info = console.info
9
+ t.after(() => {
10
+ require.main.filename = filename
11
+ console.info = info
12
+ })
13
+
14
+ require.main.filename = null
15
+
16
+ console.info = function (msg) {
17
+ t.assert.fail('logged: ' + msg)
18
+ }
19
+
20
+ fp((_fastify, _opts, next) => {
21
+ next()
22
+ }, {
23
+ fastify: '^5.0.0'
24
+ })
25
+ })
26
+
27
+ test('support faux modules', (t) => {
28
+ const plugin = fp((_fastify, _opts, next) => {
29
+ next()
30
+ })
31
+
32
+ t.assert.strictEqual(plugin.default, plugin)
33
+ })
34
+
35
+ test('support faux modules does not override existing default field in babel module', (t) => {
36
+ const module = {
37
+ default: (_fastify, _opts, next) => next()
38
+ }
39
+
40
+ module.default.default = 'Existing default field'
41
+
42
+ const plugin = fp(module)
43
+
44
+ t.assert.strictEqual(plugin.default, 'Existing default field')
45
+ })
46
+
47
+ test('support ts named imports', (t) => {
48
+ const plugin = fp((_fastify, _opts, next) => {
49
+ next()
50
+ }, {
51
+ name: 'hello'
52
+ })
53
+
54
+ t.assert.strictEqual(plugin.hello, plugin)
55
+ })
56
+
57
+ test('from kebab-case to camelCase', (t) => {
58
+ const plugin = fp((_fastify, _opts, next) => {
59
+ next()
60
+ }, {
61
+ name: 'hello-world'
62
+ })
63
+
64
+ t.assert.strictEqual(plugin.helloWorld, plugin)
65
+ })
66
+
67
+ test('from @-prefixed named imports', (t) => {
68
+ const plugin = fp((_fastify, _opts, next) => {
69
+ next()
70
+ }, {
71
+ name: '@hello/world'
72
+ })
73
+
74
+ t.assert.strictEqual(plugin.helloWorld, plugin)
75
+ })
76
+
77
+ test('from @-prefixed named kebab-case to camelCase', (t) => {
78
+ const plugin = fp((_fastify, _opts, next) => {
79
+ next()
80
+ }, {
81
+ name: '@hello/my-world'
82
+ })
83
+
84
+ t.assert.strictEqual(plugin.helloMyWorld, plugin)
85
+ })
86
+
87
+ test('from kebab-case to camelCase multiple words', (t) => {
88
+ const plugin = fp((_fastify, _opts, next) => {
89
+ next()
90
+ }, {
91
+ name: 'hello-long-world'
92
+ })
93
+
94
+ t.assert.strictEqual(plugin.helloLongWorld, plugin)
95
+ })
96
+
97
+ test('from kebab-case to camelCase multiple words does not override', (t) => {
98
+ const fn = (_fastify, _opts, next) => {
99
+ next()
100
+ }
101
+
102
+ const foobar = {}
103
+ fn.helloLongWorld = foobar
104
+
105
+ const plugin = fp(fn, {
106
+ name: 'hello-long-world'
107
+ })
108
+
109
+ t.assert.strictEqual(plugin.helloLongWorld, foobar)
110
+ })
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const fp = require('..')
5
+
6
+ test('checkVersion having require.main.filename', (t) => {
7
+ const info = console.info
8
+ t.assert.ok(require.main.filename)
9
+ t.after(() => {
10
+ console.info = info
11
+ })
12
+
13
+ console.info = function (msg) {
14
+ t.assert.fail('logged: ' + msg)
15
+ }
16
+
17
+ fp((_fastify, _opts, next) => {
18
+ next()
19
+ }, {
20
+ fastify: '^5.0.0'
21
+ })
22
+ })
23
+
24
+ test('checkVersion having no require.main.filename but process.argv[1]', (t) => {
25
+ const filename = require.main.filename
26
+ const info = console.info
27
+ t.after(() => {
28
+ require.main.filename = filename
29
+ console.info = info
30
+ })
31
+
32
+ require.main.filename = null
33
+
34
+ console.info = function (msg) {
35
+ t.assert.fail('logged: ' + msg)
36
+ }
37
+
38
+ fp((_fastify, _opts, next) => {
39
+ next()
40
+ }, {
41
+ fastify: '^5.0.0'
42
+ })
43
+ })
44
+
45
+ test('checkVersion having no require.main.filename and no process.argv[1]', (t) => {
46
+ const filename = require.main.filename
47
+ const argv = process.argv
48
+ const info = console.info
49
+ t.after(() => {
50
+ require.main.filename = filename
51
+ process.argv = argv
52
+ console.info = info
53
+ })
54
+
55
+ require.main.filename = null
56
+ process.argv[1] = null
57
+
58
+ console.info = function (msg) {
59
+ t.assert.fail('logged: ' + msg)
60
+ }
61
+
62
+ fp((_fastify, _opts, next) => {
63
+ next()
64
+ }, {
65
+ fastify: '^5.0.0'
66
+ })
67
+ })
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const fp = require('..')
5
+
6
+ test('anonymous function should be named composite.test0', (t) => {
7
+ t.plan(2)
8
+ const fn = fp((_fastify, _opts, next) => {
9
+ next()
10
+ })
11
+
12
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'composite.test-auto-0')
13
+ t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'composite.test-auto-0')
14
+ })
@@ -0,0 +1,11 @@
1
+ import { test } from 'node:test'
2
+ import fp from '../../index.js'
3
+
4
+ test('esm base support', (t) => {
5
+ fp((_fastify, _opts, next) => {
6
+ next()
7
+ }, {
8
+ fastify: '^5.0.0'
9
+ })
10
+ t.assert.ok(true, 'fp function called without throwing an error')
11
+ })
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ // Node v8 throw a `SyntaxError: Unexpected token import`
4
+ // even if this branch is never touch in the code,
5
+ // by using `eval` we can avoid this issue.
6
+ // eslint-disable-next-line
7
+ new Function('module', 'return import(module)')('./esm.mjs').catch((err) => {
8
+ process.nextTick(() => {
9
+ throw err
10
+ })
11
+ })
@@ -0,0 +1,49 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const extractPluginName = require('../lib/getPluginName').extractPluginName
5
+
6
+ const winStack = `Error: anonymous function
7
+ at checkName (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\index.js:43:11)
8
+ at plugin (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\index.js:24:20)
9
+ at Test.test (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\test\\hello.test.js:9:14)
10
+ at bound (domain.js:396:14)
11
+ at Test.runBound (domain.js:409:12)
12
+ at ret (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:278:21)
13
+ at Test.main (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:282:7)
14
+ at writeSubComment (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:371:13)
15
+ at TAP.writeSubComment (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:403:5)
16
+ at Test.runBeforeEach (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:370:14)
17
+ at loop (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\function-loop\\index.js:35:15)
18
+ at TAP.runBeforeEach (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:683:7)
19
+ at TAP.processSubtest (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:369:12)
20
+ at TAP.process (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:306:14)
21
+ at TAP.sub (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:185:10)
22
+ at TAP.test (C:\\Users\\leonardo.davinci\\Desktop\\fastify-plugin\\node_modules\\tap\\lib\\test.js:209:17)`
23
+
24
+ const nixStack = `Error: anonymous function
25
+ at checkName (/home/leonardo/desktop/fastify-plugin/index.js:43:11)
26
+ at plugin (/home/leonardo/desktop/fastify-plugin/index.js:24:20)
27
+ at Test.test (/home/leonardo/desktop/fastify-plugin/test/this.is.a.test.js:9:14)
28
+ at bound (domain.js:396:14)
29
+ at Test.runBound (domain.js:409:12)
30
+ at ret (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:278:21)
31
+ at Test.main (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:282:7)
32
+ at writeSubComment (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:371:13)
33
+ at TAP.writeSubComment (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:403:5)
34
+ at Test.runBeforeEach (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:370:14)
35
+ at loop (/home/leonardo/desktop/fastify-plugin/node_modules/function-loop/index.js:35:15)
36
+ at TAP.runBeforeEach (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:683:7)
37
+ at TAP.processSubtest (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:369:12)
38
+ at TAP.process (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:306:14)
39
+ at TAP.sub (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:185:10)
40
+ at TAP.test (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:209:17)`
41
+
42
+ const anonymousStack = 'Unable to parse this'
43
+
44
+ test('extractPluginName tests', (t) => {
45
+ t.plan(3)
46
+ t.assert.strictEqual(extractPluginName(winStack), 'hello.test')
47
+ t.assert.strictEqual(extractPluginName(nixStack), 'this.is.a.test')
48
+ t.assert.strictEqual(extractPluginName(anonymousStack), 'anonymous')
49
+ })
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const fp = require('..')
5
+
6
+ test('anonymous function should be named mu1tip1e.composite.test', (t) => {
7
+ t.plan(2)
8
+
9
+ const fn = fp((_fastify, _opts, next) => {
10
+ next()
11
+ })
12
+
13
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'mu1tip1e.composite.test-auto-0')
14
+ t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'mu1tip1e.composite.test-auto-0')
15
+ })
@@ -0,0 +1,396 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const proxyquire = require('proxyquire')
5
+ const fp = require('..')
6
+ const Fastify = require('fastify')
7
+
8
+ const pkg = require('../package.json')
9
+
10
+ test('fastify-plugin is a function', (t) => {
11
+ t.plan(1)
12
+ t.assert.ok(typeof fp === 'function')
13
+ })
14
+
15
+ test('should return the function with the skip-override Symbol', (t) => {
16
+ t.plan(1)
17
+
18
+ function plugin (_fastify, _opts, next) {
19
+ next()
20
+ }
21
+
22
+ fp(plugin)
23
+ t.assert.ok(plugin[Symbol.for('skip-override')])
24
+ })
25
+
26
+ test('should support "default" function from babel module', (t) => {
27
+ t.plan(1)
28
+
29
+ const plugin = {
30
+ default: () => { }
31
+ }
32
+
33
+ try {
34
+ fp(plugin)
35
+ t.assert.ok(true)
36
+ } catch (e) {
37
+ t.assert.strictEqual(e.message, 'fastify-plugin expects a function, instead got a \'object\'')
38
+ }
39
+ })
40
+
41
+ test('should throw if the plugin is not a function', (t) => {
42
+ t.plan(1)
43
+
44
+ try {
45
+ fp('plugin')
46
+ t.assert.fail()
47
+ } catch (e) {
48
+ t.assert.strictEqual(e.message, 'fastify-plugin expects a function, instead got a \'string\'')
49
+ }
50
+ })
51
+
52
+ test('should check the fastify version', (t) => {
53
+ t.plan(1)
54
+
55
+ function plugin (_fastify, _opts, next) {
56
+ next()
57
+ }
58
+
59
+ try {
60
+ fp(plugin, { fastify: '>=0.10.0' })
61
+ t.assert.ok(true)
62
+ } catch {
63
+ t.assert.fail()
64
+ }
65
+ })
66
+
67
+ test('should check the fastify version', (t) => {
68
+ t.plan(1)
69
+
70
+ function plugin (_fastify, _opts, next) {
71
+ next()
72
+ }
73
+
74
+ try {
75
+ fp(plugin, '>=0.10.0')
76
+ t.assert.ok(true)
77
+ } catch {
78
+ t.assert.fail()
79
+ }
80
+ })
81
+
82
+ test('the options object should be an object', (t) => {
83
+ t.plan(2)
84
+
85
+ try {
86
+ fp(() => { }, null)
87
+ t.assert.fail()
88
+ } catch (e) {
89
+ t.assert.strictEqual(e.message, 'The options object should be an object')
90
+ }
91
+
92
+ try {
93
+ fp(() => { }, [])
94
+ t.assert.fail()
95
+ } catch (e) {
96
+ t.assert.strictEqual(e.message, 'The options object should be an object')
97
+ }
98
+ })
99
+
100
+ test('should throw if the version number is not a string', (t) => {
101
+ t.plan(1)
102
+
103
+ try {
104
+ fp(() => { }, { fastify: 12 })
105
+ t.assert.fail()
106
+ } catch (e) {
107
+ t.assert.strictEqual(e.message, 'fastify-plugin expects a version string, instead got \'number\'')
108
+ }
109
+ })
110
+
111
+ test('Should accept an option object', (t) => {
112
+ t.plan(2)
113
+
114
+ const opts = { hello: 'world' }
115
+
116
+ function plugin (_fastify, _opts, next) {
117
+ next()
118
+ }
119
+
120
+ fp(plugin, opts)
121
+
122
+ t.assert.ok(plugin[Symbol.for('skip-override')], 'skip-override symbol should be present')
123
+ t.assert.deepStrictEqual(plugin[Symbol.for('plugin-meta')], opts, 'plugin-meta should match opts')
124
+ })
125
+
126
+ test('Should accept an option object and checks the version', (t) => {
127
+ t.plan(2)
128
+
129
+ const opts = { hello: 'world', fastify: '>=0.10.0' }
130
+
131
+ function plugin (_fastify, _opts, next) {
132
+ next()
133
+ }
134
+
135
+ fp(plugin, opts)
136
+ t.assert.ok(plugin[Symbol.for('skip-override')])
137
+ t.assert.deepStrictEqual(plugin[Symbol.for('plugin-meta')], opts)
138
+ })
139
+
140
+ test('should set anonymous function name to file it was called from with a counter', (t) => {
141
+ const fp = proxyquire('../index.js', { stubs: {} })
142
+
143
+ const fn = fp((_fastify, _opts, next) => {
144
+ next()
145
+ })
146
+
147
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'test-auto-0')
148
+ t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'test-auto-0')
149
+
150
+ const fn2 = fp((_fastify, _opts, next) => {
151
+ next()
152
+ })
153
+
154
+ t.assert.strictEqual(fn2[Symbol.for('plugin-meta')].name, 'test-auto-1')
155
+ t.assert.strictEqual(fn2[Symbol.for('fastify.display-name')], 'test-auto-1')
156
+ })
157
+
158
+ test('should set function name if Error.stackTraceLimit is set to 0', (t) => {
159
+ const stackTraceLimit = Error.stackTraceLimit = 0
160
+
161
+ const fp = proxyquire('../index.js', { stubs: {} })
162
+
163
+ const fn = fp((_fastify, _opts, next) => {
164
+ next()
165
+ })
166
+
167
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, 'test-auto-0')
168
+ t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], 'test-auto-0')
169
+
170
+ const fn2 = fp((_fastify, _opts, next) => {
171
+ next()
172
+ })
173
+
174
+ t.assert.strictEqual(fn2[Symbol.for('plugin-meta')].name, 'test-auto-1')
175
+ t.assert.strictEqual(fn2[Symbol.for('fastify.display-name')], 'test-auto-1')
176
+
177
+ Error.stackTraceLimit = stackTraceLimit
178
+ })
179
+
180
+ test('should set display-name to meta name', (t) => {
181
+ t.plan(2)
182
+
183
+ const functionName = 'superDuperSpecialFunction'
184
+
185
+ const fn = fp((_fastify, _opts, next) => next(), {
186
+ name: functionName
187
+ })
188
+
189
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].name, functionName)
190
+ t.assert.strictEqual(fn[Symbol.for('fastify.display-name')], functionName)
191
+ })
192
+
193
+ test('should preserve fastify version in meta', (t) => {
194
+ t.plan(1)
195
+
196
+ const opts = { hello: 'world', fastify: '>=0.10.0' }
197
+
198
+ const fn = fp((_fastify, _opts, next) => next(), opts)
199
+
200
+ t.assert.strictEqual(fn[Symbol.for('plugin-meta')].fastify, '>=0.10.0')
201
+ })
202
+
203
+ test('should check fastify dependency graph - plugin', async (t) => {
204
+ t.plan(1)
205
+ const fastify = Fastify()
206
+
207
+ fastify.register(fp((_fastify, _opts, next) => next(), {
208
+ fastify: '5.x',
209
+ name: 'plugin1-name'
210
+ }))
211
+
212
+ fastify.register(fp((_fastify, _opts, next) => next(), {
213
+ fastify: '5.x',
214
+ name: 'test',
215
+ dependencies: ['plugin1-name', 'plugin2-name']
216
+ }))
217
+
218
+ await t.assert.rejects(fastify.ready(), { message: "The dependency 'plugin2-name' of plugin 'test' is not registered" })
219
+ })
220
+
221
+ test('should check fastify dependency graph - decorate', async (t) => {
222
+ t.plan(1)
223
+ const fastify = Fastify()
224
+
225
+ fastify.decorate('plugin1', fp((_fastify, _opts, next) => next(), {
226
+ fastify: '5.x',
227
+ name: 'plugin1-name'
228
+ }))
229
+
230
+ fastify.register(fp((_fastify, _opts, next) => next(), {
231
+ fastify: '5.x',
232
+ name: 'test',
233
+ decorators: { fastify: ['plugin1', 'plugin2'] }
234
+ }))
235
+
236
+ await t.assert.rejects(fastify.ready(), { message: "The decorator 'plugin2' required by 'test' is not present in Fastify" })
237
+ })
238
+
239
+ test('should check fastify dependency graph - decorateReply', async (t) => {
240
+ t.plan(1)
241
+ const fastify = Fastify()
242
+
243
+ fastify.decorateReply('plugin1', fp((_fastify, _opts, next) => next(), {
244
+ fastify: '5.x',
245
+ name: 'plugin1-name'
246
+ }))
247
+
248
+ fastify.register(fp((_fastify, _opts, next) => next(), {
249
+ fastify: '5.x',
250
+ name: 'test',
251
+ decorators: { reply: ['plugin1', 'plugin2'] }
252
+ }))
253
+
254
+ await t.assert.rejects(fastify.ready(), { message: "The decorator 'plugin2' required by 'test' is not present in Reply" })
255
+ })
256
+
257
+ test('should accept an option to encapsulate', async (t) => {
258
+ t.plan(3)
259
+
260
+ const fastify = Fastify()
261
+
262
+ fastify.register(fp((fastify, _opts, next) => {
263
+ fastify.decorate('accessible', true)
264
+ next()
265
+ }, {
266
+ name: 'accessible-plugin'
267
+ }))
268
+
269
+ fastify.register(fp((fastify, _opts, next) => {
270
+ fastify.decorate('alsoAccessible', true)
271
+ next()
272
+ }, {
273
+ name: 'accessible-plugin2',
274
+ encapsulate: false
275
+ }))
276
+
277
+ fastify.register(fp((fastify, _opts, next) => {
278
+ fastify.decorate('encapsulated', true)
279
+ next()
280
+ }, {
281
+ name: 'encapsulated-plugin',
282
+ encapsulate: true
283
+ }))
284
+
285
+ await fastify.ready()
286
+
287
+ t.assert.ok(fastify.hasDecorator('accessible'))
288
+ t.assert.ok(fastify.hasDecorator('alsoAccessible'))
289
+ t.assert.ok(!fastify.hasDecorator('encapsulated'))
290
+ })
291
+
292
+ test('should check dependencies when encapsulated', async (t) => {
293
+ t.plan(1)
294
+ const fastify = Fastify()
295
+
296
+ fastify.register(fp((_fastify, _opts, next) => next(), {
297
+ name: 'test',
298
+ dependencies: ['missing-dependency-name'],
299
+ encapsulate: true
300
+ }))
301
+
302
+ await t.assert.rejects(fastify.ready(), { message: "The dependency 'missing-dependency-name' of plugin 'test' is not registered" })
303
+ })
304
+
305
+ test(
306
+ 'should check version when encapsulated',
307
+ { skip: /\d-.+/.test(pkg.devDependencies.fastify) },
308
+ async (t) => {
309
+ t.plan(1)
310
+ const fastify = Fastify()
311
+
312
+ fastify.register(fp((_fastify, _opts, next) => next(), {
313
+ name: 'test',
314
+ fastify: '<=2.10.0',
315
+ encapsulate: true
316
+ }))
317
+
318
+ await t.assert.rejects(fastify.ready(), { message: /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/ })
319
+ }
320
+ )
321
+
322
+ test('should check decorators when encapsulated', async (t) => {
323
+ t.plan(1)
324
+ const fastify = Fastify()
325
+
326
+ fastify.decorate('plugin1', 'foo')
327
+
328
+ fastify.register(fp((_fastify, _opts, next) => next(), {
329
+ fastify: '5.x',
330
+ name: 'test',
331
+ encapsulate: true,
332
+ decorators: { fastify: ['plugin1', 'plugin2'] }
333
+ }))
334
+
335
+ await t.assert.rejects(fastify.ready(), { message: "The decorator 'plugin2' required by 'test' is not present in Fastify" })
336
+ })
337
+
338
+ test('plugin name when encapsulated', async (t) => {
339
+ t.plan(6)
340
+ const fastify = Fastify()
341
+
342
+ fastify.register(function plugin (_instance, _opts, next) {
343
+ next()
344
+ })
345
+
346
+ fastify.register(fp(getFn('hello'), {
347
+ fastify: '5.x',
348
+ name: 'hello',
349
+ encapsulate: true
350
+ }))
351
+
352
+ fastify.register(function plugin (fastify, _opts, next) {
353
+ fastify.register(fp(getFn('deep'), {
354
+ fastify: '5.x',
355
+ name: 'deep',
356
+ encapsulate: true
357
+ }))
358
+
359
+ fastify.register(fp(function genericPlugin (fastify, _opts, next) {
360
+ t.assert.strictEqual(fastify.pluginName, 'deep-deep', 'should be deep-deep')
361
+
362
+ fastify.register(fp(getFn('deep-deep-deep'), {
363
+ fastify: '5.x',
364
+ name: 'deep-deep-deep',
365
+ encapsulate: true
366
+ }))
367
+
368
+ fastify.register(fp(getFn('deep-deep -> not-encapsulated-2'), {
369
+ fastify: '5.x',
370
+ name: 'not-encapsulated-2'
371
+ }))
372
+
373
+ next()
374
+ }, {
375
+ fastify: '5.x',
376
+ name: 'deep-deep',
377
+ encapsulate: true
378
+ }))
379
+
380
+ fastify.register(fp(getFn('plugin -> not-encapsulated'), {
381
+ fastify: '5.x',
382
+ name: 'not-encapsulated'
383
+ }))
384
+
385
+ next()
386
+ })
387
+
388
+ await fastify.ready()
389
+
390
+ function getFn (expectedName) {
391
+ return function genericPlugin (fastify, _opts, next) {
392
+ t.assert.strictEqual(fastify.pluginName, expectedName, `should be ${expectedName}`)
393
+ next()
394
+ }
395
+ }
396
+ })
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const toCamelCase = require('../lib/toCamelCase')
5
+
6
+ test('from kebab-case to camelCase', (t) => {
7
+ t.plan(1)
8
+ t.assert.strictEqual(toCamelCase('hello-world'), 'helloWorld')
9
+ })
10
+
11
+ test('from @-prefixed named imports', (t) => {
12
+ t.plan(1)
13
+ t.assert.strictEqual(toCamelCase('@hello/world'), 'helloWorld')
14
+ })
15
+
16
+ test('from @-prefixed named kebab-case to camelCase', (t) => {
17
+ t.plan(1)
18
+ t.assert.strictEqual(toCamelCase('@hello/my-world'), 'helloMyWorld')
19
+ })
20
+
21
+ test('from kebab-case to camelCase multiple words', (t) => {
22
+ t.plan(1)
23
+ t.assert.strictEqual(toCamelCase('hello-long-world'), 'helloLongWorld')
24
+ })