miqro 8.0.1 → 8.0.2

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 (2) hide show
  1. package/build/lib.cjs +153 -64
  2. package/package.json +2 -2
package/build/lib.cjs CHANGED
@@ -34,12 +34,19 @@ var require_dist = __commonJS({
34
34
  "node_modules/cookie/dist/index.js"(exports2) {
35
35
  "use strict";
36
36
  Object.defineProperty(exports2, "__esModule", { value: true });
37
- exports2.parse = parse2;
38
- exports2.serialize = serialize2;
37
+ exports2.parseCookie = parseCookie;
38
+ exports2.parse = parseCookie;
39
+ exports2.stringifyCookie = stringifyCookie;
40
+ exports2.stringifySetCookie = stringifySetCookie;
41
+ exports2.serialize = stringifySetCookie;
42
+ exports2.parseSetCookie = parseSetCookie;
43
+ exports2.stringifySetCookie = stringifySetCookie;
44
+ exports2.serialize = stringifySetCookie;
39
45
  var cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
40
46
  var cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
41
47
  var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
42
48
  var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
49
+ var maxAgeRegExp = /^-?\d+$/;
43
50
  var __toString = Object.prototype.toString;
44
51
  var NullObject = /* @__PURE__ */ (() => {
45
52
  const C = function() {
@@ -47,7 +54,7 @@ var require_dist = __commonJS({
47
54
  C.prototype = /* @__PURE__ */ Object.create(null);
48
55
  return C;
49
56
  })();
50
- function parse2(str, options) {
57
+ function parseCookie(str, options) {
51
58
  const obj = new NullObject();
52
59
  const len = str.length;
53
60
  if (len < 2)
@@ -55,91 +62,87 @@ var require_dist = __commonJS({
55
62
  const dec = options?.decode || decode2;
56
63
  let index = 0;
57
64
  do {
58
- const eqIdx = str.indexOf("=", index);
65
+ const eqIdx = eqIndex(str, index, len);
59
66
  if (eqIdx === -1)
60
67
  break;
61
- const colonIdx = str.indexOf(";", index);
62
- const endIdx = colonIdx === -1 ? len : colonIdx;
68
+ const endIdx = endIndex(str, index, len);
63
69
  if (eqIdx > endIdx) {
64
70
  index = str.lastIndexOf(";", eqIdx - 1) + 1;
65
71
  continue;
66
72
  }
67
- const keyStartIdx = startIndex(str, index, eqIdx);
68
- const keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
69
- const key = str.slice(keyStartIdx, keyEndIdx);
73
+ const key = valueSlice(str, index, eqIdx);
70
74
  if (obj[key] === void 0) {
71
- let valStartIdx = startIndex(str, eqIdx + 1, endIdx);
72
- let valEndIdx = endIndex(str, endIdx, valStartIdx);
73
- const value = dec(str.slice(valStartIdx, valEndIdx));
74
- obj[key] = value;
75
+ obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
75
76
  }
76
77
  index = endIdx + 1;
77
78
  } while (index < len);
78
79
  return obj;
79
80
  }
80
- function startIndex(str, index, max) {
81
- do {
82
- const code = str.charCodeAt(index);
83
- if (code !== 32 && code !== 9)
84
- return index;
85
- } while (++index < max);
86
- return max;
87
- }
88
- function endIndex(str, index, min) {
89
- while (index > min) {
90
- const code = str.charCodeAt(--index);
91
- if (code !== 32 && code !== 9)
92
- return index + 1;
81
+ function stringifyCookie(cookie, options) {
82
+ const enc = options?.encode || encodeURIComponent;
83
+ const cookieStrings = [];
84
+ for (const name of Object.keys(cookie)) {
85
+ const val = cookie[name];
86
+ if (val === void 0)
87
+ continue;
88
+ if (!cookieNameRegExp.test(name)) {
89
+ throw new TypeError(`cookie name is invalid: ${name}`);
90
+ }
91
+ const value = enc(val);
92
+ if (!cookieValueRegExp.test(value)) {
93
+ throw new TypeError(`cookie val is invalid: ${val}`);
94
+ }
95
+ cookieStrings.push(`${name}=${value}`);
93
96
  }
94
- return min;
97
+ return cookieStrings.join("; ");
95
98
  }
96
- function serialize2(name, val, options) {
99
+ function stringifySetCookie(_name, _val, _opts) {
100
+ const cookie = typeof _name === "object" ? _name : { ..._opts, name: _name, value: String(_val) };
101
+ const options = typeof _val === "object" ? _val : _opts;
97
102
  const enc = options?.encode || encodeURIComponent;
98
- if (!cookieNameRegExp.test(name)) {
99
- throw new TypeError(`argument name is invalid: ${name}`);
103
+ if (!cookieNameRegExp.test(cookie.name)) {
104
+ throw new TypeError(`argument name is invalid: ${cookie.name}`);
100
105
  }
101
- const value = enc(val);
106
+ const value = cookie.value ? enc(cookie.value) : "";
102
107
  if (!cookieValueRegExp.test(value)) {
103
- throw new TypeError(`argument val is invalid: ${val}`);
108
+ throw new TypeError(`argument val is invalid: ${cookie.value}`);
104
109
  }
105
- let str = name + "=" + value;
106
- if (!options)
107
- return str;
108
- if (options.maxAge !== void 0) {
109
- if (!Number.isInteger(options.maxAge)) {
110
- throw new TypeError(`option maxAge is invalid: ${options.maxAge}`);
110
+ let str = cookie.name + "=" + value;
111
+ if (cookie.maxAge !== void 0) {
112
+ if (!Number.isInteger(cookie.maxAge)) {
113
+ throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
111
114
  }
112
- str += "; Max-Age=" + options.maxAge;
115
+ str += "; Max-Age=" + cookie.maxAge;
113
116
  }
114
- if (options.domain) {
115
- if (!domainValueRegExp.test(options.domain)) {
116
- throw new TypeError(`option domain is invalid: ${options.domain}`);
117
+ if (cookie.domain) {
118
+ if (!domainValueRegExp.test(cookie.domain)) {
119
+ throw new TypeError(`option domain is invalid: ${cookie.domain}`);
117
120
  }
118
- str += "; Domain=" + options.domain;
121
+ str += "; Domain=" + cookie.domain;
119
122
  }
120
- if (options.path) {
121
- if (!pathValueRegExp.test(options.path)) {
122
- throw new TypeError(`option path is invalid: ${options.path}`);
123
+ if (cookie.path) {
124
+ if (!pathValueRegExp.test(cookie.path)) {
125
+ throw new TypeError(`option path is invalid: ${cookie.path}`);
123
126
  }
124
- str += "; Path=" + options.path;
127
+ str += "; Path=" + cookie.path;
125
128
  }
126
- if (options.expires) {
127
- if (!isDate(options.expires) || !Number.isFinite(options.expires.valueOf())) {
128
- throw new TypeError(`option expires is invalid: ${options.expires}`);
129
+ if (cookie.expires) {
130
+ if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
131
+ throw new TypeError(`option expires is invalid: ${cookie.expires}`);
129
132
  }
130
- str += "; Expires=" + options.expires.toUTCString();
133
+ str += "; Expires=" + cookie.expires.toUTCString();
131
134
  }
132
- if (options.httpOnly) {
135
+ if (cookie.httpOnly) {
133
136
  str += "; HttpOnly";
134
137
  }
135
- if (options.secure) {
138
+ if (cookie.secure) {
136
139
  str += "; Secure";
137
140
  }
138
- if (options.partitioned) {
141
+ if (cookie.partitioned) {
139
142
  str += "; Partitioned";
140
143
  }
141
- if (options.priority) {
142
- const priority = typeof options.priority === "string" ? options.priority.toLowerCase() : void 0;
144
+ if (cookie.priority) {
145
+ const priority = typeof cookie.priority === "string" ? cookie.priority.toLowerCase() : void 0;
143
146
  switch (priority) {
144
147
  case "low":
145
148
  str += "; Priority=Low";
@@ -151,11 +154,11 @@ var require_dist = __commonJS({
151
154
  str += "; Priority=High";
152
155
  break;
153
156
  default:
154
- throw new TypeError(`option priority is invalid: ${options.priority}`);
157
+ throw new TypeError(`option priority is invalid: ${cookie.priority}`);
155
158
  }
156
159
  }
157
- if (options.sameSite) {
158
- const sameSite = typeof options.sameSite === "string" ? options.sameSite.toLowerCase() : options.sameSite;
160
+ if (cookie.sameSite) {
161
+ const sameSite = typeof cookie.sameSite === "string" ? cookie.sameSite.toLowerCase() : cookie.sameSite;
159
162
  switch (sameSite) {
160
163
  case true:
161
164
  case "strict":
@@ -168,11 +171,98 @@ var require_dist = __commonJS({
168
171
  str += "; SameSite=None";
169
172
  break;
170
173
  default:
171
- throw new TypeError(`option sameSite is invalid: ${options.sameSite}`);
174
+ throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
172
175
  }
173
176
  }
174
177
  return str;
175
178
  }
179
+ function parseSetCookie(str, options) {
180
+ const dec = options?.decode || decode2;
181
+ const len = str.length;
182
+ const endIdx = endIndex(str, 0, len);
183
+ const eqIdx = eqIndex(str, 0, endIdx);
184
+ const setCookie = eqIdx === -1 ? { name: "", value: dec(valueSlice(str, 0, endIdx)) } : {
185
+ name: valueSlice(str, 0, eqIdx),
186
+ value: dec(valueSlice(str, eqIdx + 1, endIdx))
187
+ };
188
+ let index = endIdx + 1;
189
+ while (index < len) {
190
+ const endIdx2 = endIndex(str, index, len);
191
+ const eqIdx2 = eqIndex(str, index, endIdx2);
192
+ const attr = eqIdx2 === -1 ? valueSlice(str, index, endIdx2) : valueSlice(str, index, eqIdx2);
193
+ const val = eqIdx2 === -1 ? void 0 : valueSlice(str, eqIdx2 + 1, endIdx2);
194
+ switch (attr.toLowerCase()) {
195
+ case "httponly":
196
+ setCookie.httpOnly = true;
197
+ break;
198
+ case "secure":
199
+ setCookie.secure = true;
200
+ break;
201
+ case "partitioned":
202
+ setCookie.partitioned = true;
203
+ break;
204
+ case "domain":
205
+ setCookie.domain = val;
206
+ break;
207
+ case "path":
208
+ setCookie.path = val;
209
+ break;
210
+ case "max-age":
211
+ if (val && maxAgeRegExp.test(val))
212
+ setCookie.maxAge = Number(val);
213
+ break;
214
+ case "expires":
215
+ if (!val)
216
+ break;
217
+ const date = new Date(val);
218
+ if (Number.isFinite(date.valueOf()))
219
+ setCookie.expires = date;
220
+ break;
221
+ case "priority":
222
+ if (!val)
223
+ break;
224
+ const priority = val.toLowerCase();
225
+ if (priority === "low" || priority === "medium" || priority === "high") {
226
+ setCookie.priority = priority;
227
+ }
228
+ break;
229
+ case "samesite":
230
+ if (!val)
231
+ break;
232
+ const sameSite = val.toLowerCase();
233
+ if (sameSite === "lax" || sameSite === "strict" || sameSite === "none") {
234
+ setCookie.sameSite = sameSite;
235
+ }
236
+ break;
237
+ }
238
+ index = endIdx2 + 1;
239
+ }
240
+ return setCookie;
241
+ }
242
+ function endIndex(str, min, len) {
243
+ const index = str.indexOf(";", min);
244
+ return index === -1 ? len : index;
245
+ }
246
+ function eqIndex(str, min, max) {
247
+ const index = str.indexOf("=", min);
248
+ return index < max ? index : -1;
249
+ }
250
+ function valueSlice(str, min, max) {
251
+ let start = min;
252
+ let end = max;
253
+ do {
254
+ const code = str.charCodeAt(start);
255
+ if (code !== 32 && code !== 9)
256
+ break;
257
+ } while (++start < end);
258
+ while (end > start) {
259
+ const code = str.charCodeAt(end - 1);
260
+ if (code !== 32 && code !== 9)
261
+ break;
262
+ end--;
263
+ }
264
+ return str.slice(start, end);
265
+ }
176
266
  function decode2(str) {
177
267
  if (str.indexOf("%") === -1)
178
268
  return str;
@@ -2588,7 +2678,7 @@ var import_node_fs = require("node:fs");
2588
2678
  var import_node_path = require("node:path");
2589
2679
 
2590
2680
  // node_modules/@miqro/core/build/types.js
2591
- var import_cookie2 = __toESM(require_dist(), 1);
2681
+ var import_cookie = __toESM(require_dist(), 1);
2592
2682
  var import_node_crypto = require("node:crypto");
2593
2683
  var import_node_http = require("node:http");
2594
2684
 
@@ -3050,7 +3140,6 @@ function parsePart(req, part, value, args, mode, parser4) {
3050
3140
  }
3051
3141
 
3052
3142
  // node_modules/@miqro/core/build/middleware/session.js
3053
- var import_cookie = __toESM(require_dist(), 1);
3054
3143
  var DEFAULT_TOKEN_LOCATION = "free";
3055
3144
  var DEFAULT_TOKEN_HEADER = "Authorization";
3056
3145
  var DEFAULT_TOKEN_QUERY = "token";
@@ -3438,7 +3527,7 @@ var Request = class extends import_node_http.IncomingMessage {
3438
3527
  set: (v2) => {
3439
3528
  vCookie = v2;
3440
3529
  this.cookies = /* @__PURE__ */ Object.create(null);
3441
- const cookies = (0, import_cookie2.parse)(vCookie || "");
3530
+ const cookies = (0, import_cookie.parse)(vCookie || "");
3442
3531
  const cookieList = Object.keys(cookies);
3443
3532
  for (const name of cookieList) {
3444
3533
  const value = cookies[name];
@@ -3522,7 +3611,7 @@ var Response = class _Response extends import_node_http.ServerResponse {
3522
3611
  });
3523
3612
  }
3524
3613
  setCookie(name, value, options) {
3525
- return this.setHeader("Set-Cookie", (0, import_cookie2.serialize)(name, String(value), options));
3614
+ return this.setHeader("Set-Cookie", (0, import_cookie.serialize)(name, String(value), options));
3526
3615
  }
3527
3616
  addVaryHeader(value) {
3528
3617
  const c = this.getHeader("Vary");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/esm/lib.js",
@@ -29,7 +29,7 @@
29
29
  "typescript": "^5.9.3"
30
30
  },
31
31
  "dependencies": {
32
- "@miqro/core": "^5.1.2",
32
+ "@miqro/core": "^5.1.3",
33
33
  "@miqro/jsx": "^1.0.2",
34
34
  "@miqro/jsx-dom": "^1.0.6",
35
35
  "@miqro/jsx-node": "^1.0.9",