@next-box/appsettings 0.0.7 → 0.0.8

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 (50) hide show
  1. package/README.md +59 -14
  2. package/dist/cjs/hooks/createUseAppSettings.cjs +2 -0
  3. package/dist/cjs/hooks/createUseAppSettings.cjs.map +1 -0
  4. package/dist/cjs/hooks/createUseSetting.cjs +2 -0
  5. package/dist/cjs/hooks/createUseSetting.cjs.map +1 -0
  6. package/dist/cjs/index.cjs +1 -1
  7. package/dist/esm/hooks/createUseAppSettings.mjs +2 -0
  8. package/dist/esm/hooks/createUseAppSettings.mjs.map +1 -0
  9. package/dist/esm/hooks/createUseSetting.mjs +2 -0
  10. package/dist/esm/hooks/createUseSetting.mjs.map +1 -0
  11. package/dist/esm/index.mjs +1 -1
  12. package/dist/production.analysis.txt +25 -25
  13. package/dist/types/cjs/hooks/createUseAppSettings.d.cts +4 -0
  14. package/dist/types/cjs/hooks/createUseAppSettings.d.cts.map +1 -0
  15. package/dist/types/cjs/hooks/createUseSetting.d.cts +4 -0
  16. package/dist/types/cjs/hooks/createUseSetting.d.cts.map +1 -0
  17. package/dist/types/cjs/index.d.cts +2 -4
  18. package/dist/types/cjs/index.d.cts.map +1 -1
  19. package/dist/types/esm/hooks/createUseAppSettings.d.ts +4 -0
  20. package/dist/types/esm/hooks/createUseAppSettings.d.ts.map +1 -0
  21. package/dist/types/esm/hooks/createUseSetting.d.ts +4 -0
  22. package/dist/types/esm/hooks/createUseSetting.d.ts.map +1 -0
  23. package/dist/types/esm/index.d.ts +2 -4
  24. package/dist/types/esm/index.d.ts.map +1 -1
  25. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/components/AppSettingsProvider.test.tsx +4 -1
  28. package/src/hooks/{useAppSetting.test.tsx → createUseAppSetting.test.tsx} +12 -6
  29. package/src/hooks/{useAppSettings.test.tsx → createUseAppSettings.test.tsx} +5 -3
  30. package/src/hooks/createUseAppSettings.ts +12 -0
  31. package/src/hooks/createUseSetting.ts +12 -0
  32. package/src/index.ts +2 -6
  33. package/dist/cjs/hooks/useAppSetting.cjs +0 -2
  34. package/dist/cjs/hooks/useAppSetting.cjs.map +0 -1
  35. package/dist/cjs/hooks/useAppSettings.cjs +0 -2
  36. package/dist/cjs/hooks/useAppSettings.cjs.map +0 -1
  37. package/dist/esm/hooks/useAppSetting.mjs +0 -2
  38. package/dist/esm/hooks/useAppSetting.mjs.map +0 -1
  39. package/dist/esm/hooks/useAppSettings.mjs +0 -2
  40. package/dist/esm/hooks/useAppSettings.mjs.map +0 -1
  41. package/dist/types/cjs/hooks/useAppSetting.d.cts +0 -6
  42. package/dist/types/cjs/hooks/useAppSetting.d.cts.map +0 -1
  43. package/dist/types/cjs/hooks/useAppSettings.d.cts +0 -6
  44. package/dist/types/cjs/hooks/useAppSettings.d.cts.map +0 -1
  45. package/dist/types/esm/hooks/useAppSetting.d.ts +0 -6
  46. package/dist/types/esm/hooks/useAppSetting.d.ts.map +0 -1
  47. package/dist/types/esm/hooks/useAppSettings.d.ts +0 -6
  48. package/dist/types/esm/hooks/useAppSettings.d.ts.map +0 -1
  49. package/src/hooks/useAppSetting.ts +0 -14
  50. package/src/hooks/useAppSettings.ts +0 -17
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@next-box/appsettings",
3
3
  "description": "A configuration management library for TypeScript applications, inspired by .NET’s appsettings.json.",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/next-box",
@@ -2,9 +2,12 @@
2
2
 
3
3
  import { describe, expect, it } from '@jest/globals';
4
4
  import { render, screen } from '@testing-library/react';
5
- import { useAppSetting } from '../hooks/useAppSetting.ts';
5
+ import { createUseSetting } from '../hooks/createUseSetting.ts';
6
6
  import { AppSettingsProvider } from './AppSettingsProvider.tsx';
7
7
 
8
+ type Settings = { Api: { Timeout: number } };
9
+
10
+ const useAppSetting = createUseSetting<Settings>();
8
11
  const SettingsOutput = () => <span>{String(useAppSetting('Api.Timeout'))}</span>;
9
12
 
10
13
  describe('AppSettingsProvider', () => {
@@ -2,23 +2,24 @@
2
2
 
3
3
  import { describe, expect, it } from '@jest/globals';
4
4
  import { renderHook } from '@testing-library/react';
5
- import { type ReactNode } from 'react';
5
+ import { type PropsWithChildren } from 'react';
6
6
  import { AppSettingsProvider } from '../components/AppSettingsProvider.tsx';
7
- import { useAppSetting } from './useAppSetting.ts';
7
+ import { createUseSetting } from './createUseSetting.ts';
8
8
 
9
9
  const settings = { Api: { Missing: undefined, Timeout: 5000 } };
10
+ const useSetting = createUseSetting<typeof settings>();
10
11
 
11
- const createWrapper = ({ children }: { children: ReactNode }) => (
12
+ const createWrapper = ({ children }: PropsWithChildren) => (
12
13
  <AppSettingsProvider settings={settings}>{children}</AppSettingsProvider>
13
14
  );
14
15
 
15
- describe('useAppSetting', () => {
16
+ describe('useSetting', () => {
16
17
  it('When used within a provider, then it returns the value at the requested leaf path', () => {
17
18
  // Arrange
18
19
  const path = 'Api.Timeout';
19
20
 
20
21
  // Act
21
- const { result } = renderHook(() => useAppSetting(path), { wrapper: createWrapper });
22
+ const { result } = renderHook(() => useSetting(path), { wrapper: createWrapper });
22
23
 
23
24
  // Assert
24
25
  expect(result.current).toBe(5000);
@@ -29,7 +30,12 @@ describe('useAppSetting', () => {
29
30
  const path = 'Api.Missing';
30
31
 
31
32
  // Act
32
- const { result } = renderHook(() => useAppSetting(path), { wrapper: createWrapper });
33
+ const { result } = renderHook(
34
+ () => {
35
+ useSetting(path);
36
+ },
37
+ { wrapper: createWrapper },
38
+ );
33
39
 
34
40
  // Assert
35
41
  expect(result.current).toBeUndefined();
@@ -2,13 +2,14 @@
2
2
 
3
3
  import { describe, expect, it } from '@jest/globals';
4
4
  import { renderHook } from '@testing-library/react';
5
- import { type ReactNode } from 'react';
5
+ import { type PropsWithChildren } from 'react';
6
6
  import { AppSettingsProvider } from '../components/AppSettingsProvider.tsx';
7
- import { useAppSettings } from './useAppSettings.ts';
7
+ import { createUseAppSettings } from './createUseAppSettings.ts';
8
8
 
9
9
  const settings = { Api: { Timeout: 5000 } };
10
+ const useAppSettings = createUseAppSettings<typeof settings>();
10
11
 
11
- const createWrapper = ({ children }: { children: ReactNode }) => (
12
+ const createWrapper = ({ children }: PropsWithChildren) => (
12
13
  <AppSettingsProvider settings={settings}>{children}</AppSettingsProvider>
13
14
  );
14
15
 
@@ -29,6 +30,7 @@ describe('useAppSettings', () => {
29
30
  const path = 'Missing';
30
31
 
31
32
  // Act
33
+ // @ts-expect-error Intended for test
32
34
  const { result } = renderHook(() => useAppSettings(path), { wrapper: createWrapper });
33
35
 
34
36
  // Assert
@@ -0,0 +1,12 @@
1
+ import { type Get } from 'type-fest';
2
+ import { type SettingSectionPath } from '#types/Config.types.ts';
3
+ import { useAppSettingsContext } from './useAppSettingsContext.ts';
4
+
5
+ export const createUseAppSettings = <T extends object>() => {
6
+ return <P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined => {
7
+ const settings = useAppSettingsContext();
8
+ // Assert the resolved settings type based on the caller-provided schema and path.
9
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
10
+ return settings.read(path) as Get<T, P> | undefined;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ import { type Get } from 'type-fest';
2
+ import { useAppSettingsContext } from '#hooks/useAppSettingsContext.ts';
3
+ import { type SettingPath } from '#types/Config.types.ts';
4
+
5
+ export const createUseSetting = <T extends object>() => {
6
+ return <P extends SettingPath<T>>(path: P): Get<T, P> | undefined => {
7
+ const settings = useAppSettingsContext();
8
+ // Assert the resolved setting type based on the caller-provided schema and path.
9
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
10
+ return settings.read(path) as Get<T, P> | undefined;
11
+ };
12
+ };
package/src/index.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  export { AppSettingsProvider } from '#components/AppSettingsProvider.tsx';
2
2
  export { Setting } from '#components/Setting.tsx';
3
- export { useAppSetting } from '#hooks/useAppSetting.ts';
4
- export { useAppSettings } from '#hooks/useAppSettings.ts';
3
+ export { createUseSetting } from '#hooks/createUseSetting.ts';
4
+ export { createUseAppSettings } from '#hooks/createUseAppSettings.ts';
5
5
  export { useAppSettingsContext } from '#hooks/useAppSettingsContext.ts';
6
6
  export type { AppSettings, ScopedSettings } from '#types/AppSettings.types.ts';
7
7
  export type { SettingPath, SettingSectionPath, SettingValue } from '#types/Config.types.ts';
8
-
9
- // Consumers can augment this interface through the package's public entry point.
10
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
11
- export interface AppSettingsSchema {}
@@ -1,2 +0,0 @@
1
- "use strict";var t=require("./useAppSettingsContext.cjs");exports.useAppSetting=function(e){return t.useAppSettingsContext().read(e)};
2
- //# sourceMappingURL=useAppSetting.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSetting.cjs","sources":["../../../src/hooks/useAppSetting.ts"],"sourcesContent":["import { type Get } from 'type-fest';\nimport { type AppSettingsSchema } from '../index.ts';\nimport { type SettingPath } from '../types/Config.types.ts';\nimport { useAppSettingsContext } from './useAppSettingsContext.ts';\n\nexport function useAppSetting<P extends SettingPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;\nexport function useAppSetting<T extends object, P extends SettingPath<T>>(path: P): Get<T, P> | undefined;\n\n// Required for overloads\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function useAppSetting(path: string): unknown {\n const settings = useAppSettingsContext();\n return settings.read(path);\n}\n"],"names":["path","useAppSettingsContext","read"],"mappings":"gFAUO,SAAuBA,GAE5B,OADiBC,EAAAA,wBACDC,KAAKF,EACvB"}
@@ -1,2 +0,0 @@
1
- "use strict";var t=require("./useAppSettingsContext.cjs");exports.useAppSettings=function(e){return t.useAppSettingsContext().read(e)};
2
- //# sourceMappingURL=useAppSettings.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSettings.cjs","sources":["../../../src/hooks/useAppSettings.ts"],"sourcesContent":["import { type Get } from 'type-fest';\nimport { type SettingSectionPath } from '#types/Config.types.ts';\nimport { type AppSettingsSchema } from '../index.ts';\nimport { useAppSettingsContext } from './useAppSettingsContext.ts';\n\nexport function useAppSettings<P extends SettingSectionPath<AppSettingsSchema>>(\n path: P,\n): Get<AppSettingsSchema, P> | undefined;\n\nexport function useAppSettings<T extends object, P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined;\n\n// Required for overloads\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function useAppSettings(path: string): unknown {\n const settings = useAppSettingsContext();\n return settings.read(path);\n}\n"],"names":["path","useAppSettingsContext","read"],"mappings":"iFAaO,SAAwBA,GAE7B,OADiBC,EAAAA,wBACDC,KAAKF,EACvB"}
@@ -1,2 +0,0 @@
1
- import{useAppSettingsContext as t}from"./useAppSettingsContext.mjs";function e(e){return t().read(e)}export{e as useAppSetting};
2
- //# sourceMappingURL=useAppSetting.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSetting.mjs","sources":["../../../src/hooks/useAppSetting.ts"],"sourcesContent":["import { type Get } from 'type-fest';\nimport { type AppSettingsSchema } from '../index.ts';\nimport { type SettingPath } from '../types/Config.types.ts';\nimport { useAppSettingsContext } from './useAppSettingsContext.ts';\n\nexport function useAppSetting<P extends SettingPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;\nexport function useAppSetting<T extends object, P extends SettingPath<T>>(path: P): Get<T, P> | undefined;\n\n// Required for overloads\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function useAppSetting(path: string): unknown {\n const settings = useAppSettingsContext();\n return settings.read(path);\n}\n"],"names":["useAppSetting","path","useAppSettingsContext","read"],"mappings":"oEAUO,SAASA,EAAcC,GAE5B,OADiBC,IACDC,KAAKF,EACvB"}
@@ -1,2 +0,0 @@
1
- import{useAppSettingsContext as t}from"./useAppSettingsContext.mjs";function e(e){return t().read(e)}export{e as useAppSettings};
2
- //# sourceMappingURL=useAppSettings.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSettings.mjs","sources":["../../../src/hooks/useAppSettings.ts"],"sourcesContent":["import { type Get } from 'type-fest';\nimport { type SettingSectionPath } from '#types/Config.types.ts';\nimport { type AppSettingsSchema } from '../index.ts';\nimport { useAppSettingsContext } from './useAppSettingsContext.ts';\n\nexport function useAppSettings<P extends SettingSectionPath<AppSettingsSchema>>(\n path: P,\n): Get<AppSettingsSchema, P> | undefined;\n\nexport function useAppSettings<T extends object, P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined;\n\n// Required for overloads\n// eslint-disable-next-line prefer-arrow/prefer-arrow-functions\nexport function useAppSettings(path: string): unknown {\n const settings = useAppSettingsContext();\n return settings.read(path);\n}\n"],"names":["useAppSettings","path","useAppSettingsContext","read"],"mappings":"oEAaO,SAASA,EAAeC,GAE7B,OADiBC,IACDC,KAAKF,EACvB"}
@@ -1,6 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type AppSettingsSchema } from '../index.cts';
3
- import { type SettingPath } from '../types/Config.types.cts';
4
- export declare function useAppSetting<P extends SettingPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;
5
- export declare function useAppSetting<T extends object, P extends SettingPath<T>>(path: P): Get<T, P> | undefined;
6
- //# sourceMappingURL=useAppSetting.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSetting.d.cts","sourceRoot":"","sources":["../../../../src/hooks/useAppSetting.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AACxH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type SettingSectionPath } from '#types/Config.types.cts';
3
- import { type AppSettingsSchema } from '../index.cts';
4
- export declare function useAppSettings<P extends SettingSectionPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;
5
- export declare function useAppSettings<T extends object, P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined;
6
- //# sourceMappingURL=useAppSettings.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSettings.d.cts","sourceRoot":"","sources":["../../../../src/hooks/useAppSettings.cts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,wBAAgB,cAAc,CAAC,CAAC,SAAS,kBAAkB,CAAC,iBAAiB,CAAC,EAC5E,IAAI,EAAE,CAAC,GACN,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AAEzC,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type AppSettingsSchema } from '../index.ts';
3
- import { type SettingPath } from '../types/Config.types.ts';
4
- export declare function useAppSetting<P extends SettingPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;
5
- export declare function useAppSetting<T extends object, P extends SettingPath<T>>(path: P): Get<T, P> | undefined;
6
- //# sourceMappingURL=useAppSetting.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSetting.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useAppSetting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AACxH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC"}
@@ -1,6 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type SettingSectionPath } from '#types/Config.types.ts';
3
- import { type AppSettingsSchema } from '../index.ts';
4
- export declare function useAppSettings<P extends SettingSectionPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;
5
- export declare function useAppSettings<T extends object, P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined;
6
- //# sourceMappingURL=useAppSettings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAppSettings.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useAppSettings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,wBAAgB,cAAc,CAAC,CAAC,SAAS,kBAAkB,CAAC,iBAAiB,CAAC,EAC5E,IAAI,EAAE,CAAC,GACN,GAAG,CAAC,iBAAiB,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AAEzC,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,kBAAkB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC"}
@@ -1,14 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type AppSettingsSchema } from '../index.ts';
3
- import { type SettingPath } from '../types/Config.types.ts';
4
- import { useAppSettingsContext } from './useAppSettingsContext.ts';
5
-
6
- export function useAppSetting<P extends SettingPath<AppSettingsSchema>>(path: P): Get<AppSettingsSchema, P> | undefined;
7
- export function useAppSetting<T extends object, P extends SettingPath<T>>(path: P): Get<T, P> | undefined;
8
-
9
- // Required for overloads
10
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
11
- export function useAppSetting(path: string): unknown {
12
- const settings = useAppSettingsContext();
13
- return settings.read(path);
14
- }
@@ -1,17 +0,0 @@
1
- import { type Get } from 'type-fest';
2
- import { type SettingSectionPath } from '#types/Config.types.ts';
3
- import { type AppSettingsSchema } from '../index.ts';
4
- import { useAppSettingsContext } from './useAppSettingsContext.ts';
5
-
6
- export function useAppSettings<P extends SettingSectionPath<AppSettingsSchema>>(
7
- path: P,
8
- ): Get<AppSettingsSchema, P> | undefined;
9
-
10
- export function useAppSettings<T extends object, P extends SettingSectionPath<T>>(path: P): Get<T, P> | undefined;
11
-
12
- // Required for overloads
13
- // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
14
- export function useAppSettings(path: string): unknown {
15
- const settings = useAppSettingsContext();
16
- return settings.read(path);
17
- }