core-services-sdk 1.3.74 → 1.3.75

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": "core-services-sdk",
3
- "version": "1.3.74",
3
+ "version": "1.3.75",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "types": "types/index.d.ts",
package/src/index.js CHANGED
@@ -11,3 +11,5 @@ export * from './templates/index.js'
11
11
  export * from './util/index.js'
12
12
  export * from './instant-messages/index.js'
13
13
  export * from './postgresql/index.js'
14
+ export * from './env/env-validation.js'
15
+ export * from './json/load-json.js'
@@ -0,0 +1,15 @@
1
+ import fs from 'node:fs'
2
+
3
+ /**
4
+ * Loads and parses a JSON file relative to a module URL.
5
+ *
6
+ * @param {string|URL} moduleUrl
7
+ * @param {string} relativePath
8
+ * @returns {any}
9
+ */
10
+ export function loadJson(moduleUrl, relativePath) {
11
+ const fileUrl = new URL(relativePath, moduleUrl)
12
+ const raw = fs.readFileSync(fileUrl, 'utf8')
13
+
14
+ return JSON.parse(raw)
15
+ }
@@ -0,0 +1,2 @@
1
+ {
2
+ "foo": "bar"
@@ -0,0 +1,4 @@
1
+ {
2
+ "foo": "bar",
3
+ "answer": 42
4
+ }
@@ -0,0 +1,37 @@
1
+ import path from 'node:path'
2
+ import { fileURLToPath } from 'node:url'
3
+ import { describe, it, expect } from 'vitest'
4
+
5
+ import { loadJson } from '../../src/json/load-json.js'
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = path.dirname(__filename)
9
+
10
+ describe('loadJson', () => {
11
+ it('loads and parses a JSON file relative to module URL', () => {
12
+ const moduleUrl = new URL(`file://${__dirname}/dummy.js`)
13
+
14
+ const result = loadJson(moduleUrl, './fixtures/valid.json')
15
+
16
+ expect(result).toEqual({
17
+ foo: 'bar',
18
+ answer: 42,
19
+ })
20
+ })
21
+
22
+ it('throws if file does not exist', () => {
23
+ const moduleUrl = new URL(`file://${__dirname}/dummy.js`)
24
+
25
+ expect(() => {
26
+ loadJson(moduleUrl, './fixtures/missing.json')
27
+ }).toThrow()
28
+ })
29
+
30
+ it('throws if JSON is invalid', () => {
31
+ const moduleUrl = new URL(`file://${__dirname}/dummy.js`)
32
+
33
+ expect(() => {
34
+ loadJson(moduleUrl, './fixtures/invalid.json')
35
+ }).toThrow(SyntaxError)
36
+ })
37
+ })
package/types/index.d.ts CHANGED
@@ -11,3 +11,5 @@ export * from './templates/index.js'
11
11
  export * from './util/index.js'
12
12
  export * from './instant-messages/index.js'
13
13
  export * from './postgresql/index.js'
14
+ export * from './env/env-validation.js'
15
+ export * from './json/load-json.js'
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Loads and parses a JSON file relative to a module URL.
3
+ *
4
+ * @param {string|URL} moduleUrl
5
+ * @param {string} relativePath
6
+ * @returns {any}
7
+ */
8
+ export function loadJson(moduleUrl: string | URL, relativePath: string): any