@nimpl/getters 1.4.1-canary.1 → 2.0.0-canary.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 +13 -7
- package/get-page-config.d.ts +1 -3
- package/get-page-config.js +4 -4
- package/get-params.d.ts +1 -1
- package/get-params.js +14 -6
- package/get-pathname.js +15 -5
- package/package.json +2 -2
- package/get-search-params.d.ts +0 -4
- package/get-search-params.js +0 -32
package/README.md
CHANGED
|
@@ -2,39 +2,45 @@
|
|
|
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
|
|
5
|
+
Implementation of server getters in React Server Components without switching to SSR in Next.js
|
|
6
6
|
|
|
7
7
|
Before using the library, read the [Possible Issues](https://nimpl.tech/getters/possible-issues)
|
|
8
8
|
|
|
9
9
|
Visit https://nimpl.tech/getters to view the full documentation.
|
|
10
10
|
|
|
11
|
+
Use `@nimpl/getters 2.x` for Next.js v15. For earlier versions of Next.js use `@nimpl/getters 1.x`.
|
|
12
|
+
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
13
15
|
**Using npm:**
|
|
16
|
+
|
|
14
17
|
```bash
|
|
15
18
|
npm i @nimpl/getters
|
|
16
19
|
```
|
|
17
20
|
|
|
18
21
|
**Using yarn:**
|
|
22
|
+
|
|
19
23
|
```bash
|
|
20
24
|
yarn add @nimpl/getters
|
|
21
25
|
```
|
|
22
26
|
|
|
23
27
|
## Current Getters
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
- [get-pathname](https://nimpl.tech/getters/current-getters/get-pathname)
|
|
30
|
+
- [get-page-config](https://nimpl.tech/getters/current-getters/get-page-config)
|
|
31
|
+
- [get-params](https://nimpl.tech/getters/current-getters/get-params)
|
|
32
|
+
- [get-search-params](https://nimpl.tech/getters/current-getters/get-search-params) (_deprecated_)
|
|
33
|
+
|
|
34
|
+
> _`create-server-context` and `get-server-context` were moved to a separate package - [@nimpl/context](https://nimpl.tech/context)_
|
|
29
35
|
|
|
30
36
|
## Stability
|
|
31
37
|
|
|
32
38
|
All getters are covered with tests. Tests are run on every release and every 6 hours on the latest **Canary** version of `Next.js`.
|
|
33
39
|
|
|
34
|
-
In this way, you can be sure not only of the stability of the code, but also that if there is a breaking change in `Next.js`, this will immediately become known.
|
|
40
|
+
In this way, you can be sure not only of the stability of the code, but also that if there is a breaking change in `Next.js`, this will immediately become known. _Even before the release of a stable version of `Next.js`._
|
|
35
41
|
|
|
36
42
|
## Additional
|
|
37
43
|
|
|
38
|
-
Please consider giving a star if you like it, it will help promote the implementation in the eyes of the
|
|
44
|
+
Please consider giving a star if you like it, it will help promote the implementation in the eyes of the Next.js team.
|
|
39
45
|
|
|
40
46
|
Create tasks for identified issues, desired getters, or various improvements.
|
package/get-page-config.d.ts
CHANGED
|
@@ -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
|
|
6
|
+
pagePath: string;
|
|
8
7
|
dynamic: string;
|
|
9
|
-
revalidate: import("next/dist/server/lib/revalidate").Revalidate | undefined;
|
|
10
8
|
basePath: string;
|
|
11
9
|
};
|
package/get-page-config.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPageConfig = void 0;
|
|
4
|
-
const
|
|
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 =
|
|
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 {
|
|
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,
|
|
23
|
+
return { pagePath: page, dynamic, basePath };
|
|
24
24
|
};
|
|
25
25
|
exports.getPageConfig = getPageConfig;
|
package/get-params.d.ts
CHANGED
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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
const url = new URL(
|
|
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": "
|
|
3
|
+
"version": "2.0.0-canary.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": "
|
|
38
|
+
"next": "15.0.0",
|
|
39
39
|
"typescript": "5.4.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
package/get-search-params.d.ts
DELETED
package/get-search-params.js
DELETED
|
@@ -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;
|