@nimpl/getters 1.4.1 → 2.0.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/README.md CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  (Former [next-impl-getters](https://www.npmjs.com/package/next-impl-getters))
4
4
 
5
- Implementation of server getters in React Server Components without switching to SSR in next.js
5
+ Implementation of server getters in React Server Components without switching to SSR in Next.js
6
6
 
7
- Before using the library, read the [Possible Issues](https://nimpl.tech/getters/possible-issues)
7
+ Before using the library, read the [Possible Issues](https://nimpl.tech/docs/getters#possible-issues)
8
8
 
9
- Visit https://nimpl.tech/getters to view the full documentation.
9
+ Visit https://nimpl.tech/docs/getters to view the full documentation.
10
+
11
+ Use `@nimpl/getters 2.x` for Next.js v15. For earlier versions of Next.js use `@nimpl/getters 1.x`.
10
12
 
11
13
  ## Installation
12
14
 
@@ -24,12 +26,12 @@ yarn add @nimpl/getters
24
26
 
25
27
  ## Current Getters
26
28
 
27
- - [get-pathname](https://nimpl.tech/getters/current-getters/get-pathname)
28
- - [get-page-config](https://nimpl.tech/getters/current-getters/get-page-config)
29
- - [get-params](https://nimpl.tech/getters/current-getters/get-params)
30
- - [get-search-params](https://nimpl.tech/getters/current-getters/get-search-params) (_deprecated_)
29
+ - [get-pathname](https://nimpl.tech/docs/getters#get-pathname)
30
+ - [get-params](https://nimpl.tech/docs/getters#get-params)
31
+ - [get-page-config](https://nimpl.tech/docs/getters#get-page-config)
32
+ - [get-search-params](https://nimpl.tech/docs/getters#get-search-params) (_deprecated_)
31
33
 
32
- > _`create-server-context` and `get-server-context` were moved to a separate package - [@nimpl/context](https://nimpl.tech/context)_
34
+ > _`create-server-context` and `get-server-context` were moved to a separate package - [@nimpl/context](https://nimpl.tech/docs/context)_
33
35
 
34
36
  ## Stability
35
37
 
@@ -39,6 +41,6 @@ In this way, you can be sure not only of the stability of the code, but also tha
39
41
 
40
42
  ## Additional
41
43
 
42
- Please consider giving a star if you like it, it will help promote the implementation in the eyes of the next.js team.
44
+ Please consider giving a star if you like it, it will help promote the implementation in the eyes of the Next.js team. This also motivates the author to continue working on this and other solutions ❤️
43
45
 
44
- Create tasks for identified issues, desired getters, or various improvements.
46
+ Create issues for identified problems, desired getters, or various improvements.
@@ -1,11 +1,9 @@
1
1
  export declare const getPageConfig: () => {
2
2
  pagePath?: undefined;
3
3
  dynamic?: undefined;
4
- revalidate?: undefined;
5
4
  basePath?: undefined;
6
5
  } | {
7
- pagePath: string | undefined;
6
+ pagePath: string;
8
7
  dynamic: string;
9
- revalidate: import("next/dist/server/lib/revalidate").Revalidate | undefined;
10
8
  basePath: string;
11
9
  };
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPageConfig = void 0;
4
- const static_generation_async_storage_external_1 = require("next/dist/client/components/static-generation-async-storage.external");
4
+ const work_async_storage_external_1 = require("next/dist/server/app-render/work-async-storage.external");
5
5
  const server_getter_in_client_component_error_1 = require("./server-getter-in-client-component-error");
6
6
  const getPageConfig = () => {
7
7
  (0, server_getter_in_client_component_error_1.serverGetterInClientComponentError)("getPageConfig");
8
- const store = static_generation_async_storage_external_1.staticGenerationAsyncStorage.getStore();
8
+ const store = work_async_storage_external_1.workAsyncStorage.getStore();
9
9
  if (!store)
10
10
  return {};
11
11
  const basePath = process.env.__NEXT_ROUTER_BASEPATH || "";
12
- const { pagePath, forceDynamic, forceStatic, dynamicShouldError, revalidate } = store || {};
12
+ const { page, forceDynamic, forceStatic, dynamicShouldError } = store || {};
13
13
  let dynamic = "auto";
14
14
  if (forceDynamic) {
15
15
  dynamic = "force-dynamic";
@@ -20,6 +20,6 @@ const getPageConfig = () => {
20
20
  else if (dynamicShouldError) {
21
21
  dynamic = "error";
22
22
  }
23
- return { pagePath, dynamic, revalidate, basePath };
23
+ return { pagePath: page, dynamic, basePath };
24
24
  };
25
25
  exports.getPageConfig = getPageConfig;
package/get-params.d.ts CHANGED
@@ -12,5 +12,5 @@ type GetParamsOptions = {
12
12
  };
13
13
  export declare const getParams: (options?: GetParamsOptions) => {
14
14
  [key: string]: string | string[];
15
- } | null;
15
+ };
16
16
  export {};
package/get-params.js CHANGED
@@ -1,16 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getParams = void 0;
4
- const static_generation_async_storage_external_1 = require("next/dist/client/components/static-generation-async-storage.external");
4
+ const work_async_storage_external_1 = require("next/dist/server/app-render/work-async-storage.external");
5
+ const work_unit_async_storage_external_1 = require("next/dist/server/app-render/work-unit-async-storage.external");
5
6
  const server_getter_in_client_component_error_1 = require("./server-getter-in-client-component-error");
6
7
  const utils_1 = require("./utils");
7
8
  const getParams = (options = {}) => {
8
9
  (0, server_getter_in_client_component_error_1.serverGetterInClientComponentError)("getParams");
9
- const store = static_generation_async_storage_external_1.staticGenerationAsyncStorage.getStore();
10
+ const store = work_async_storage_external_1.workAsyncStorage.getStore();
10
11
  if (!store)
11
12
  return {};
12
13
  const { ignoreDifferenceError, pagePaths, pathname } = options;
13
- const { urlPathname, pagePath = "/" } = store;
14
+ const pageConfigurationStore = work_async_storage_external_1.workAsyncStorage.getStore();
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ const pageStore = work_unit_async_storage_external_1.workUnitAsyncStorage.getStore();
17
+ if (!pageConfigurationStore || !pageStore?.url?.pathname)
18
+ return {};
19
+ const { route } = pageConfigurationStore;
20
+ const pagePath = route;
21
+ const urlPathname = pageStore.url.pathname;
14
22
  const targetUrlPathname = pathname || urlPathname;
15
23
  let isInvalid = false;
16
24
  try {
@@ -21,7 +29,7 @@ const getParams = (options = {}) => {
21
29
  isInvalid ||= true;
22
30
  continue;
23
31
  }
24
- return params;
32
+ return params || {};
25
33
  }
26
34
  }
27
35
  else {
@@ -30,7 +38,7 @@ const getParams = (options = {}) => {
30
38
  isInvalid ||= true;
31
39
  }
32
40
  else {
33
- return params;
41
+ return params || {};
34
42
  }
35
43
  }
36
44
  }
@@ -44,6 +52,6 @@ const getParams = (options = {}) => {
44
52
  createIssueUrl.searchParams.append("labels", "bug");
45
53
  throw new Error(`Something went wrong. Please create an issue on Github: ${createIssueUrl}`);
46
54
  }
47
- return null;
55
+ return {};
48
56
  };
49
57
  exports.getParams = getParams;
package/get-pathname.js CHANGED
@@ -1,17 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPathname = void 0;
4
- const static_generation_async_storage_external_1 = require("next/dist/client/components/static-generation-async-storage.external");
4
+ const work_async_storage_external_1 = require("next/dist/server/app-render/work-async-storage.external");
5
+ const work_unit_async_storage_external_1 = require("next/dist/server/app-render/work-unit-async-storage.external");
5
6
  const has_base_path_1 = require("next/dist/client/has-base-path");
6
7
  const remove_base_path_1 = require("next/dist/client/remove-base-path");
7
8
  const server_getter_in_client_component_error_1 = require("./server-getter-in-client-component-error");
9
+ const utils_1 = require("./utils");
8
10
  function getPathname() {
9
11
  (0, server_getter_in_client_component_error_1.serverGetterInClientComponentError)("getPathname");
10
- const store = static_generation_async_storage_external_1.staticGenerationAsyncStorage.getStore();
11
- if (!store)
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ const pageStore = work_unit_async_storage_external_1.workUnitAsyncStorage.getStore();
14
+ let originalPathname = pageStore?.url?.pathname;
15
+ if (!originalPathname) {
16
+ const pageConfigurationStore = work_async_storage_external_1.workAsyncStorage.getStore();
17
+ originalPathname =
18
+ pageConfigurationStore?.route &&
19
+ (0, utils_1.normalizeInterceptingRoutes)(pageConfigurationStore.route.split("/")).join("/");
20
+ }
21
+ if (!originalPathname) {
12
22
  return null;
13
- const { urlPathname } = store;
14
- const url = new URL(urlPathname, "http://n");
23
+ }
24
+ const url = new URL(originalPathname, "http://n");
15
25
  const pathname = (0, has_base_path_1.hasBasePath)(url.pathname) ? (0, remove_base_path_1.removeBasePath)(url.pathname) : url.pathname;
16
26
  return pathname;
17
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimpl/getters",
3
- "version": "1.4.1",
3
+ "version": "2.0.0",
4
4
  "description": "Implementation of server getters in React Server Components without switching to SSR in next.js",
5
5
  "files": [
6
6
  "**/*.js",
@@ -35,7 +35,7 @@
35
35
  "@types/react": "18.3.2",
36
36
  "react": "18.3.1",
37
37
  "react-dom": "18.3.1",
38
- "next": "14.2.3",
38
+ "next": "15.0.0",
39
39
  "typescript": "5.4.5"
40
40
  },
41
41
  "peerDependencies": {
@@ -1,4 +0,0 @@
1
- /** @deprecated getSearchParams is deprecated. [Read more](https://nimpl.tech/getters/current-getters/get-search-params) */
2
- export declare function getSearchParams(opts?: {
3
- ignoreDynamicOptionErrors?: boolean;
4
- }): URLSearchParams;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSearchParams = void 0;
4
- const static_generation_async_storage_external_1 = require("next/dist/client/components/static-generation-async-storage.external");
5
- const server_getter_in_client_component_error_1 = require("./server-getter-in-client-component-error");
6
- const navigation_1 = require("next/navigation");
7
- const internal_utils_1 = require("next/dist/server/internal-utils");
8
- /** @deprecated getSearchParams is deprecated. [Read more](https://nimpl.tech/getters/current-getters/get-search-params) */
9
- function getSearchParams(opts) {
10
- (0, server_getter_in_client_component_error_1.serverGetterInClientComponentError)("getSearchParams");
11
- console.error("getSearchParams is deprecated. Read more - https://nimpl.tech/getters/current-getters/get-search-params");
12
- const store = static_generation_async_storage_external_1.staticGenerationAsyncStorage.getStore();
13
- if (!store)
14
- return new URLSearchParams();
15
- const { urlPathname, forceStatic, forceDynamic, dynamicShouldError } = store;
16
- if (!opts?.ignoreDynamicOptionErrors) {
17
- if (forceStatic) {
18
- throw new Error("Сannot get client search parameters with dynamic=force-static setting");
19
- }
20
- else if (dynamicShouldError) {
21
- throw new Error("Сannot get client search parameters with dynamic=error setting");
22
- }
23
- else if (!forceDynamic) {
24
- console.warn("Do not use getSearchParams with unselected dynamic setting, use force-dynamic instead");
25
- }
26
- }
27
- const url = new URL(urlPathname, "http://n");
28
- const strippedUrl = (0, internal_utils_1.stripInternalSearchParams)(url, true);
29
- const readonlySearchParams = new navigation_1.ReadonlyURLSearchParams(strippedUrl.searchParams);
30
- return readonlySearchParams;
31
- }
32
- exports.getSearchParams = getSearchParams;