enlace 0.0.1-beta.4 → 0.0.1-beta.6
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 +111 -17
- package/dist/{next/hook → hook}/index.d.mts +49 -10
- package/dist/{next/hook → hook}/index.d.ts +49 -10
- package/dist/{next/hook → hook}/index.js +158 -138
- package/dist/{next/hook → hook}/index.mjs +159 -158
- package/dist/index.d.mts +46 -77
- package/dist/index.d.ts +46 -77
- package/dist/index.js +48 -385
- package/dist/index.mjs +50 -385
- package/package.json +6 -11
- package/dist/next/index.d.mts +0 -82
- package/dist/next/index.d.ts +0 -82
- package/dist/next/index.js +0 -111
- package/dist/next/index.mjs +0 -95
package/dist/next/index.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/next/index.ts
|
|
22
|
-
var next_exports = {};
|
|
23
|
-
__export(next_exports, {
|
|
24
|
-
createEnlace: () => createEnlace
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(next_exports);
|
|
27
|
-
var import_enlace_core2 = require("enlace-core");
|
|
28
|
-
|
|
29
|
-
// src/next/fetch.ts
|
|
30
|
-
var import_enlace_core = require("enlace-core");
|
|
31
|
-
|
|
32
|
-
// src/utils/generateTags.ts
|
|
33
|
-
function generateTags(path) {
|
|
34
|
-
return path.map((_, i) => path.slice(0, i + 1).join("/"));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/next/fetch.ts
|
|
38
|
-
async function executeNextFetch(baseUrl, path, method, combinedOptions, requestOptions) {
|
|
39
|
-
const {
|
|
40
|
-
autoGenerateTags = true,
|
|
41
|
-
autoRevalidateTags = true,
|
|
42
|
-
revalidator,
|
|
43
|
-
headers: defaultHeaders,
|
|
44
|
-
...restOptions
|
|
45
|
-
} = combinedOptions;
|
|
46
|
-
const url = (0, import_enlace_core.buildUrl)(baseUrl, path, requestOptions?.query);
|
|
47
|
-
let headers = (0, import_enlace_core.mergeHeaders)(defaultHeaders, requestOptions?.headers);
|
|
48
|
-
const isGet = method === "GET";
|
|
49
|
-
const autoTags = generateTags(path);
|
|
50
|
-
const fetchOptions = {
|
|
51
|
-
...restOptions,
|
|
52
|
-
method
|
|
53
|
-
};
|
|
54
|
-
if (requestOptions?.cache) {
|
|
55
|
-
fetchOptions.cache = requestOptions.cache;
|
|
56
|
-
}
|
|
57
|
-
if (isGet) {
|
|
58
|
-
const tags = requestOptions?.tags ?? (autoGenerateTags ? autoTags : void 0);
|
|
59
|
-
const nextFetchOptions = {};
|
|
60
|
-
if (tags) {
|
|
61
|
-
nextFetchOptions.tags = tags;
|
|
62
|
-
}
|
|
63
|
-
if (requestOptions?.revalidate !== void 0) {
|
|
64
|
-
nextFetchOptions.revalidate = requestOptions.revalidate;
|
|
65
|
-
}
|
|
66
|
-
fetchOptions.next = nextFetchOptions;
|
|
67
|
-
}
|
|
68
|
-
if (headers) {
|
|
69
|
-
fetchOptions.headers = headers;
|
|
70
|
-
}
|
|
71
|
-
if (requestOptions?.body !== void 0) {
|
|
72
|
-
if ((0, import_enlace_core.isJsonBody)(requestOptions.body)) {
|
|
73
|
-
fetchOptions.body = JSON.stringify(requestOptions.body);
|
|
74
|
-
headers = (0, import_enlace_core.mergeHeaders)(headers, { "Content-Type": "application/json" });
|
|
75
|
-
if (headers) {
|
|
76
|
-
fetchOptions.headers = headers;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
fetchOptions.body = requestOptions.body;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const response = await fetch(url, fetchOptions);
|
|
83
|
-
const contentType = response.headers.get("content-type");
|
|
84
|
-
const isJson = contentType?.includes("application/json");
|
|
85
|
-
if (response.ok) {
|
|
86
|
-
if (!isGet && !requestOptions?.skipRevalidator) {
|
|
87
|
-
const revalidateTags = requestOptions?.revalidateTags ?? (autoRevalidateTags ? autoTags : []);
|
|
88
|
-
const revalidatePaths = requestOptions?.revalidatePaths ?? [];
|
|
89
|
-
if (revalidateTags.length || revalidatePaths.length) {
|
|
90
|
-
revalidator?.(revalidateTags, revalidatePaths);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
ok: true,
|
|
95
|
-
status: response.status,
|
|
96
|
-
data: isJson ? await response.json() : response
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
ok: false,
|
|
101
|
-
status: response.status,
|
|
102
|
-
error: isJson ? await response.json() : response
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/next/index.ts
|
|
107
|
-
__reExport(next_exports, require("enlace-core"), module.exports);
|
|
108
|
-
function createEnlace(baseUrl, defaultOptions = {}, nextOptions = {}) {
|
|
109
|
-
const combinedOptions = { ...defaultOptions, ...nextOptions };
|
|
110
|
-
return (0, import_enlace_core2.createProxyHandler)(baseUrl, combinedOptions, [], executeNextFetch);
|
|
111
|
-
}
|
package/dist/next/index.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// src/next/index.ts
|
|
2
|
-
import {
|
|
3
|
-
createProxyHandler
|
|
4
|
-
} from "enlace-core";
|
|
5
|
-
|
|
6
|
-
// src/next/fetch.ts
|
|
7
|
-
import {
|
|
8
|
-
buildUrl,
|
|
9
|
-
isJsonBody,
|
|
10
|
-
mergeHeaders
|
|
11
|
-
} from "enlace-core";
|
|
12
|
-
|
|
13
|
-
// src/utils/generateTags.ts
|
|
14
|
-
function generateTags(path) {
|
|
15
|
-
return path.map((_, i) => path.slice(0, i + 1).join("/"));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/next/fetch.ts
|
|
19
|
-
async function executeNextFetch(baseUrl, path, method, combinedOptions, requestOptions) {
|
|
20
|
-
const {
|
|
21
|
-
autoGenerateTags = true,
|
|
22
|
-
autoRevalidateTags = true,
|
|
23
|
-
revalidator,
|
|
24
|
-
headers: defaultHeaders,
|
|
25
|
-
...restOptions
|
|
26
|
-
} = combinedOptions;
|
|
27
|
-
const url = buildUrl(baseUrl, path, requestOptions?.query);
|
|
28
|
-
let headers = mergeHeaders(defaultHeaders, requestOptions?.headers);
|
|
29
|
-
const isGet = method === "GET";
|
|
30
|
-
const autoTags = generateTags(path);
|
|
31
|
-
const fetchOptions = {
|
|
32
|
-
...restOptions,
|
|
33
|
-
method
|
|
34
|
-
};
|
|
35
|
-
if (requestOptions?.cache) {
|
|
36
|
-
fetchOptions.cache = requestOptions.cache;
|
|
37
|
-
}
|
|
38
|
-
if (isGet) {
|
|
39
|
-
const tags = requestOptions?.tags ?? (autoGenerateTags ? autoTags : void 0);
|
|
40
|
-
const nextFetchOptions = {};
|
|
41
|
-
if (tags) {
|
|
42
|
-
nextFetchOptions.tags = tags;
|
|
43
|
-
}
|
|
44
|
-
if (requestOptions?.revalidate !== void 0) {
|
|
45
|
-
nextFetchOptions.revalidate = requestOptions.revalidate;
|
|
46
|
-
}
|
|
47
|
-
fetchOptions.next = nextFetchOptions;
|
|
48
|
-
}
|
|
49
|
-
if (headers) {
|
|
50
|
-
fetchOptions.headers = headers;
|
|
51
|
-
}
|
|
52
|
-
if (requestOptions?.body !== void 0) {
|
|
53
|
-
if (isJsonBody(requestOptions.body)) {
|
|
54
|
-
fetchOptions.body = JSON.stringify(requestOptions.body);
|
|
55
|
-
headers = mergeHeaders(headers, { "Content-Type": "application/json" });
|
|
56
|
-
if (headers) {
|
|
57
|
-
fetchOptions.headers = headers;
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
fetchOptions.body = requestOptions.body;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const response = await fetch(url, fetchOptions);
|
|
64
|
-
const contentType = response.headers.get("content-type");
|
|
65
|
-
const isJson = contentType?.includes("application/json");
|
|
66
|
-
if (response.ok) {
|
|
67
|
-
if (!isGet && !requestOptions?.skipRevalidator) {
|
|
68
|
-
const revalidateTags = requestOptions?.revalidateTags ?? (autoRevalidateTags ? autoTags : []);
|
|
69
|
-
const revalidatePaths = requestOptions?.revalidatePaths ?? [];
|
|
70
|
-
if (revalidateTags.length || revalidatePaths.length) {
|
|
71
|
-
revalidator?.(revalidateTags, revalidatePaths);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
ok: true,
|
|
76
|
-
status: response.status,
|
|
77
|
-
data: isJson ? await response.json() : response
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
ok: false,
|
|
82
|
-
status: response.status,
|
|
83
|
-
error: isJson ? await response.json() : response
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// src/next/index.ts
|
|
88
|
-
export * from "enlace-core";
|
|
89
|
-
function createEnlace(baseUrl, defaultOptions = {}, nextOptions = {}) {
|
|
90
|
-
const combinedOptions = { ...defaultOptions, ...nextOptions };
|
|
91
|
-
return createProxyHandler(baseUrl, combinedOptions, [], executeNextFetch);
|
|
92
|
-
}
|
|
93
|
-
export {
|
|
94
|
-
createEnlace
|
|
95
|
-
};
|