@wp-typia/rest 0.3.3 → 0.3.5

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/dist/client.js CHANGED
@@ -1,4 +1,5 @@
1
- import { isFormDataLike, isPlainObject, toValidationResult, } from "./internal/runtime-primitives.js";
1
+ import { encodeGetLikeRequest, joinPathWithQuery, joinUrlWithQuery, mergeHeaderInputs, parseResponsePayload, } from "@wp-typia/api-client/client-utils";
2
+ import { isFormDataLike, toValidationResult, } from "./internal/runtime-primitives.js";
2
3
  export { isValidationResult, normalizeValidationError, toValidationResult } from "./internal/runtime-primitives.js";
3
4
  function getDefaultRestRoot() {
4
5
  if (typeof window !== "undefined") {
@@ -75,73 +76,6 @@ async function defaultFetch(options) {
75
76
  return text;
76
77
  }
77
78
  }
78
- async function parseResponsePayload(response) {
79
- if (response.status === 204) {
80
- return undefined;
81
- }
82
- const text = await response.text();
83
- if (!text) {
84
- return undefined;
85
- }
86
- try {
87
- return JSON.parse(text);
88
- }
89
- catch {
90
- return text;
91
- }
92
- }
93
- function encodeGetLikeRequest(request) {
94
- if (request === undefined || request === null) {
95
- return "";
96
- }
97
- if (request instanceof URLSearchParams) {
98
- return request.toString();
99
- }
100
- if (!isPlainObject(request)) {
101
- throw new Error("GET/DELETE endpoint requests must be plain objects or URLSearchParams.");
102
- }
103
- const params = new URLSearchParams();
104
- for (const [key, value] of Object.entries(request)) {
105
- if (value === undefined || value === null) {
106
- continue;
107
- }
108
- if (Array.isArray(value)) {
109
- for (const item of value) {
110
- params.append(key, String(item));
111
- }
112
- continue;
113
- }
114
- params.set(key, String(value));
115
- }
116
- return params.toString();
117
- }
118
- function joinPathWithQuery(path, query) {
119
- if (!query) {
120
- return path;
121
- }
122
- return path.includes("?") ? `${path}&${query}` : `${path}?${query}`;
123
- }
124
- function joinUrlWithQuery(url, query) {
125
- if (!query) {
126
- return url;
127
- }
128
- const nextUrl = new URL(url, typeof window !== "undefined" ? window.location.origin : "http://localhost");
129
- for (const [key, value] of new URLSearchParams(query)) {
130
- nextUrl.searchParams.append(key, value);
131
- }
132
- return nextUrl.toString();
133
- }
134
- function mergeHeaderInputs(baseHeaders, requestHeaders) {
135
- if (!baseHeaders && !requestHeaders) {
136
- return undefined;
137
- }
138
- const mergedHeaders = new Headers(baseHeaders);
139
- const nextHeaders = new Headers(requestHeaders);
140
- for (const [key, value] of nextHeaders.entries()) {
141
- mergedHeaders.set(key, value);
142
- }
143
- return Object.fromEntries(mergedHeaders.entries());
144
- }
145
79
  function buildEndpointFetchOptions(endpoint, request) {
146
80
  const baseOptions = endpoint.buildRequestOptions?.(request) ?? {};
147
81
  if (endpoint.method === "GET" || endpoint.method === "DELETE") {
@@ -1 +1 @@
1
- export { isFormDataLike, isPlainObject, isValidationResult, normalizeExpected, normalizePath, normalizeValidationError, toValidationResult, type RawValidationError, type ValidationError, type ValidationLike, type ValidationResult, } from "@wp-typia/api-client/internal/runtime-primitives";
1
+ export { isFormDataLike, isPlainObject, isValidationResult, normalizeExpected, normalizePath, normalizeValidationError, toValidationResult, type RawValidationError, type ValidationError, type ValidationLike, type ValidationResult, } from "@wp-typia/api-client/runtime-primitives";
@@ -1 +1 @@
1
- export { isFormDataLike, isPlainObject, isValidationResult, normalizeExpected, normalizePath, normalizeValidationError, toValidationResult, } from "@wp-typia/api-client/internal/runtime-primitives";
1
+ export { isFormDataLike, isPlainObject, isValidationResult, normalizeExpected, normalizePath, normalizeValidationError, toValidationResult, } from "@wp-typia/api-client/runtime-primitives";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-typia/rest",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Typed WordPress REST helpers powered by Typia validation",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -59,10 +59,10 @@
59
59
  "engines": {
60
60
  "node": ">=20.0.0",
61
61
  "npm": ">=10.0.0",
62
- "bun": ">=1.3.10"
62
+ "bun": ">=1.3.11"
63
63
  },
64
64
  "dependencies": {
65
- "@wp-typia/api-client": "^0.4.0",
65
+ "@wp-typia/api-client": "^0.4.2",
66
66
  "@typia/interface": "^12.0.1",
67
67
  "@wordpress/api-fetch": "^7.42.0"
68
68
  },