@jlnstack/cookies 0.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/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/defineProperty.cjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/defineProperty.mjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/objectSpread2.cjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/objectSpread2.mjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/toPrimitive.cjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/toPrimitive.mjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/toPropertyKey.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/toPropertyKey.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/typeof.cjs +18 -0
- package/dist/_virtual/_@oxc-project_runtime@0.106.0/helpers/typeof.mjs +12 -0
- package/dist/browser.cjs +37 -0
- package/dist/browser.d.cts +8 -0
- package/dist/browser.d.cts.map +1 -0
- package/dist/browser.d.mts +8 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +37 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.cjs +73 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +73 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next.cjs +25 -0
- package/dist/next.d.cts +8 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.mts +8 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +25 -0
- package/dist/next.mjs.map +1 -0
- package/dist/types.d.cts +44 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +44 -0
- package/dist/types.d.mts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const require_toPropertyKey = require('./toPropertyKey.cjs');
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/defineProperty.js
|
|
4
|
+
function _defineProperty(e, r, t) {
|
|
5
|
+
return (r = require_toPropertyKey.toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
6
|
+
value: t,
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
configurable: !0,
|
|
9
|
+
writable: !0
|
|
10
|
+
}) : e[r] = t, e;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports._defineProperty = _defineProperty;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { toPropertyKey } from "./toPropertyKey.mjs";
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/defineProperty.js
|
|
4
|
+
function _defineProperty(e, r, t) {
|
|
5
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
6
|
+
value: t,
|
|
7
|
+
enumerable: !0,
|
|
8
|
+
configurable: !0,
|
|
9
|
+
writable: !0
|
|
10
|
+
}) : e[r] = t, e;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { _defineProperty };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_defineProperty = require('./defineProperty.cjs');
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/objectSpread2.js
|
|
4
|
+
function ownKeys(e, r) {
|
|
5
|
+
var t = Object.keys(e);
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
8
|
+
r && (o = o.filter(function(r$1) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
10
|
+
})), t.push.apply(t, o);
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread2(e) {
|
|
15
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
16
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
17
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
18
|
+
require_defineProperty._defineProperty(e, r$1, t[r$1]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
20
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports._objectSpread2 = _objectSpread2;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { _defineProperty } from "./defineProperty.mjs";
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/objectSpread2.js
|
|
4
|
+
function ownKeys(e, r) {
|
|
5
|
+
var t = Object.keys(e);
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
8
|
+
r && (o = o.filter(function(r$1) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
10
|
+
})), t.push.apply(t, o);
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread2(e) {
|
|
15
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
16
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
17
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
18
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
20
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { _objectSpread2 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_typeof = require('./typeof.cjs');
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/toPrimitive.js
|
|
4
|
+
function toPrimitive(t, r) {
|
|
5
|
+
if ("object" != require_typeof._typeof(t) || !t) return t;
|
|
6
|
+
var e = t[Symbol.toPrimitive];
|
|
7
|
+
if (void 0 !== e) {
|
|
8
|
+
var i = e.call(t, r || "default");
|
|
9
|
+
if ("object" != require_typeof._typeof(i)) return i;
|
|
10
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
11
|
+
}
|
|
12
|
+
return ("string" === r ? String : Number)(t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.toPrimitive = toPrimitive;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { _typeof } from "./typeof.mjs";
|
|
2
|
+
|
|
3
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/toPrimitive.js
|
|
4
|
+
function toPrimitive(t, r) {
|
|
5
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
6
|
+
var e = t[Symbol.toPrimitive];
|
|
7
|
+
if (void 0 !== e) {
|
|
8
|
+
var i = e.call(t, r || "default");
|
|
9
|
+
if ("object" != _typeof(i)) return i;
|
|
10
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
11
|
+
}
|
|
12
|
+
return ("string" === r ? String : Number)(t);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { toPrimitive };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const require_typeof = require('./typeof.cjs');
|
|
2
|
+
const require_toPrimitive = require('./toPrimitive.cjs');
|
|
3
|
+
|
|
4
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/toPropertyKey.js
|
|
5
|
+
function toPropertyKey(t) {
|
|
6
|
+
var i = require_toPrimitive.toPrimitive(t, "string");
|
|
7
|
+
return "symbol" == require_typeof._typeof(i) ? i : i + "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.toPropertyKey = toPropertyKey;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { _typeof } from "./typeof.mjs";
|
|
2
|
+
import { toPrimitive } from "./toPrimitive.mjs";
|
|
3
|
+
|
|
4
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/toPropertyKey.js
|
|
5
|
+
function toPropertyKey(t) {
|
|
6
|
+
var i = toPrimitive(t, "string");
|
|
7
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { toPropertyKey };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/typeof.js
|
|
3
|
+
function _typeof(o) {
|
|
4
|
+
"@babel/helpers - typeof";
|
|
5
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
6
|
+
return typeof o$1;
|
|
7
|
+
} : function(o$1) {
|
|
8
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
9
|
+
}, _typeof(o);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
Object.defineProperty(exports, '_typeof', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _typeof;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.106.0/helpers/typeof.js
|
|
2
|
+
function _typeof(o) {
|
|
3
|
+
"@babel/helpers - typeof";
|
|
4
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
5
|
+
return typeof o$1;
|
|
6
|
+
} : function(o$1) {
|
|
7
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
8
|
+
}, _typeof(o);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { _typeof };
|
package/dist/browser.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const require_index = require('./index.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/browser.ts
|
|
4
|
+
function getCookie(name) {
|
|
5
|
+
const cookies = document.cookie.split("; ");
|
|
6
|
+
for (const cookie of cookies) {
|
|
7
|
+
const [key, ...valueParts] = cookie.split("=");
|
|
8
|
+
if (key === name) return decodeURIComponent(valueParts.join("="));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function setCookie(name, value, options) {
|
|
12
|
+
const parts = [`${encodeURIComponent(name)}=${encodeURIComponent(value)}`];
|
|
13
|
+
if ((options === null || options === void 0 ? void 0 : options.maxAge) !== void 0) parts.push(`max-age=${options.maxAge}`);
|
|
14
|
+
if (options === null || options === void 0 ? void 0 : options.expires) parts.push(`expires=${options.expires.toUTCString()}`);
|
|
15
|
+
if (options === null || options === void 0 ? void 0 : options.path) parts.push(`path=${options.path}`);
|
|
16
|
+
if (options === null || options === void 0 ? void 0 : options.domain) parts.push(`domain=${options.domain}`);
|
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.secure) parts.push("secure");
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.sameSite) parts.push(`samesite=${options.sameSite}`);
|
|
19
|
+
document.cookie = parts.join("; ");
|
|
20
|
+
}
|
|
21
|
+
function deleteCookie(name) {
|
|
22
|
+
document.cookie = `${encodeURIComponent(name)}=; max-age=0`;
|
|
23
|
+
}
|
|
24
|
+
function createCookie(name, options) {
|
|
25
|
+
return require_index.createCookie({
|
|
26
|
+
name,
|
|
27
|
+
schema: options === null || options === void 0 ? void 0 : options.schema,
|
|
28
|
+
serializer: options === null || options === void 0 ? void 0 : options.serializer,
|
|
29
|
+
get: () => getCookie(name),
|
|
30
|
+
set: (value, opts) => setCookie(name, value, opts),
|
|
31
|
+
delete: () => deleteCookie(name)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.createCookie = createCookie;
|
|
37
|
+
exports.createCookieGroup = require_index.createCookieGroup;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieGroup, CookieOptions, CreateCookieOptions, Serializer } from "./types.cjs";
|
|
2
|
+
import { createCookieGroup } from "./index.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/browser.d.ts
|
|
5
|
+
declare function createCookie<T>(name: string, options?: CreateCookieOptions<T>): Cookie<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=browser.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.cts","names":[],"sources":["../src/browser.ts"],"sourcesContent":[],"mappings":";;;;iBA8CgB,wCAEJ,oBAAoB,KAC7B,OAAO"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieGroup, CookieOptions, CreateCookieOptions, Serializer } from "./types.mjs";
|
|
2
|
+
import { createCookieGroup } from "./index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/browser.d.ts
|
|
5
|
+
declare function createCookie<T>(name: string, options?: CreateCookieOptions<T>): Cookie<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=browser.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.mts","names":[],"sources":["../src/browser.ts"],"sourcesContent":[],"mappings":";;;;iBA8CgB,wCAEJ,oBAAoB,KAC7B,OAAO"}
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createCookie as createCookie$1, createCookieGroup } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/browser.ts
|
|
4
|
+
function getCookie(name) {
|
|
5
|
+
const cookies = document.cookie.split("; ");
|
|
6
|
+
for (const cookie of cookies) {
|
|
7
|
+
const [key, ...valueParts] = cookie.split("=");
|
|
8
|
+
if (key === name) return decodeURIComponent(valueParts.join("="));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function setCookie(name, value, options) {
|
|
12
|
+
const parts = [`${encodeURIComponent(name)}=${encodeURIComponent(value)}`];
|
|
13
|
+
if ((options === null || options === void 0 ? void 0 : options.maxAge) !== void 0) parts.push(`max-age=${options.maxAge}`);
|
|
14
|
+
if (options === null || options === void 0 ? void 0 : options.expires) parts.push(`expires=${options.expires.toUTCString()}`);
|
|
15
|
+
if (options === null || options === void 0 ? void 0 : options.path) parts.push(`path=${options.path}`);
|
|
16
|
+
if (options === null || options === void 0 ? void 0 : options.domain) parts.push(`domain=${options.domain}`);
|
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.secure) parts.push("secure");
|
|
18
|
+
if (options === null || options === void 0 ? void 0 : options.sameSite) parts.push(`samesite=${options.sameSite}`);
|
|
19
|
+
document.cookie = parts.join("; ");
|
|
20
|
+
}
|
|
21
|
+
function deleteCookie(name) {
|
|
22
|
+
document.cookie = `${encodeURIComponent(name)}=; max-age=0`;
|
|
23
|
+
}
|
|
24
|
+
function createCookie(name, options) {
|
|
25
|
+
return createCookie$1({
|
|
26
|
+
name,
|
|
27
|
+
schema: options === null || options === void 0 ? void 0 : options.schema,
|
|
28
|
+
serializer: options === null || options === void 0 ? void 0 : options.serializer,
|
|
29
|
+
get: () => getCookie(name),
|
|
30
|
+
set: (value, opts) => setCookie(name, value, opts),
|
|
31
|
+
delete: () => deleteCookie(name)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createCookie, createCookieGroup };
|
|
37
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","names":["createCookieCore"],"sources":["../src/browser.ts"],"sourcesContent":["import { createCookie as createCookieCore } from \"./index\";\nimport type { Cookie, CookieOptions, CreateCookieOptions } from \"./types\";\n\nexport { createCookieGroup } from \"./index\";\nexport type { Cookie, CookieGroup, CookieOptions, Serializer } from \"./types\";\n\nfunction getCookie(name: string): string | undefined {\n const cookies = document.cookie.split(\"; \");\n for (const cookie of cookies) {\n const [key, ...valueParts] = cookie.split(\"=\");\n if (key === name) {\n return decodeURIComponent(valueParts.join(\"=\"));\n }\n }\n return undefined;\n}\n\nfunction setCookie(name: string, value: string, options?: CookieOptions): void {\n const parts = [`${encodeURIComponent(name)}=${encodeURIComponent(value)}`];\n\n if (options?.maxAge !== undefined) {\n parts.push(`max-age=${options.maxAge}`);\n }\n if (options?.expires) {\n parts.push(`expires=${options.expires.toUTCString()}`);\n }\n if (options?.path) {\n parts.push(`path=${options.path}`);\n }\n if (options?.domain) {\n parts.push(`domain=${options.domain}`);\n }\n if (options?.secure) {\n parts.push(\"secure\");\n }\n if (options?.sameSite) {\n parts.push(`samesite=${options.sameSite}`);\n }\n\n document.cookie = parts.join(\"; \");\n}\n\nfunction deleteCookie(name: string): void {\n document.cookie = `${encodeURIComponent(name)}=; max-age=0`;\n}\n\nexport function createCookie<T>(\n name: string,\n options?: CreateCookieOptions<T>,\n): Cookie<T> {\n return createCookieCore({\n name,\n schema: options?.schema,\n serializer: options?.serializer,\n get: () => getCookie(name),\n set: (value, opts) => setCookie(name, value, opts),\n delete: () => deleteCookie(name),\n });\n}\n"],"mappings":";;;AAMA,SAAS,UAAU,MAAkC;CACnD,MAAM,UAAU,SAAS,OAAO,MAAM,KAAK;AAC3C,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,CAAC,KAAK,GAAG,cAAc,OAAO,MAAM,IAAI;AAC9C,MAAI,QAAQ,KACV,QAAO,mBAAmB,WAAW,KAAK,IAAI,CAAC;;;AAMrD,SAAS,UAAU,MAAc,OAAe,SAA+B;CAC7E,MAAM,QAAQ,CAAC,GAAG,mBAAmB,KAAK,CAAC,GAAG,mBAAmB,MAAM,GAAG;AAE1E,wDAAI,QAAS,YAAW,OACtB,OAAM,KAAK,WAAW,QAAQ,SAAS;AAEzC,uDAAI,QAAS,QACX,OAAM,KAAK,WAAW,QAAQ,QAAQ,aAAa,GAAG;AAExD,uDAAI,QAAS,KACX,OAAM,KAAK,QAAQ,QAAQ,OAAO;AAEpC,uDAAI,QAAS,OACX,OAAM,KAAK,UAAU,QAAQ,SAAS;AAExC,uDAAI,QAAS,OACX,OAAM,KAAK,SAAS;AAEtB,uDAAI,QAAS,SACX,OAAM,KAAK,YAAY,QAAQ,WAAW;AAG5C,UAAS,SAAS,MAAM,KAAK,KAAK;;AAGpC,SAAS,aAAa,MAAoB;AACxC,UAAS,SAAS,GAAG,mBAAmB,KAAK,CAAC;;AAGhD,SAAgB,aACd,MACA,SACW;AACX,QAAOA,eAAiB;EACtB;EACA,0DAAQ,QAAS;EACjB,8DAAY,QAAS;EACrB,WAAW,UAAU,KAAK;EAC1B,MAAM,OAAO,SAAS,UAAU,MAAM,OAAO,KAAK;EAClD,cAAc,aAAa,KAAK;EACjC,CAAC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const require_objectSpread2 = require('./_virtual/_@oxc-project_runtime@0.106.0/helpers/objectSpread2.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const jsonSerializer = {
|
|
5
|
+
serialize: (value) => {
|
|
6
|
+
if (typeof value === "string") return value;
|
|
7
|
+
return JSON.stringify(value);
|
|
8
|
+
},
|
|
9
|
+
deserialize: (raw) => {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
} catch (_unused) {
|
|
13
|
+
return raw;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
async function validateSchema(schema, value) {
|
|
18
|
+
const result = await schema["~standard"].validate(value);
|
|
19
|
+
if ("issues" in result && result.issues) return { success: false };
|
|
20
|
+
return {
|
|
21
|
+
success: true,
|
|
22
|
+
value: result.value
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createCookie(config) {
|
|
26
|
+
const { name, schema, serializer = jsonSerializer, get, set, delete: deleteFn } = config;
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
async get() {
|
|
30
|
+
const raw = await get();
|
|
31
|
+
if (raw === void 0) return void 0;
|
|
32
|
+
const parsed = serializer.deserialize(raw);
|
|
33
|
+
if (schema) {
|
|
34
|
+
const result = await validateSchema(schema, parsed);
|
|
35
|
+
if (!result.success) return void 0;
|
|
36
|
+
return result.value;
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
},
|
|
40
|
+
async set(value, options) {
|
|
41
|
+
if (schema) {
|
|
42
|
+
if (!(await validateSchema(schema, value)).success) throw new Error("Invalid cookie value");
|
|
43
|
+
}
|
|
44
|
+
await set(serializer.serialize(value), options);
|
|
45
|
+
},
|
|
46
|
+
async delete() {
|
|
47
|
+
await deleteFn();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function createCookieGroup(cookies) {
|
|
52
|
+
return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, cookies), {}, {
|
|
53
|
+
async get() {
|
|
54
|
+
const entries = await Promise.all(Object.entries(cookies).map(async ([key, cookie]) => [key, await cookie.get()]));
|
|
55
|
+
return Object.fromEntries(entries);
|
|
56
|
+
},
|
|
57
|
+
async set(values, options) {
|
|
58
|
+
const promises = [];
|
|
59
|
+
for (const [key, value] of Object.entries(values)) {
|
|
60
|
+
const cookie = cookies[key];
|
|
61
|
+
if (cookie && value !== void 0) promises.push(cookie.set(value, options));
|
|
62
|
+
}
|
|
63
|
+
await Promise.all(promises);
|
|
64
|
+
},
|
|
65
|
+
async deleteAll() {
|
|
66
|
+
await Promise.all(Object.values(cookies).map((c) => c.delete()));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
exports.createCookie = createCookie;
|
|
73
|
+
exports.createCookieGroup = createCookieGroup;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieConfig, CookieGroup, CookieOptions, Serializer } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare function createCookie<T>(config: CookieConfig<T>): Cookie<T>;
|
|
5
|
+
declare function createCookieGroup<T extends Record<string, Cookie<unknown>>>(cookies: T): CookieGroup<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;iBAuCgB,wBAAwB,aAAa,KAAK,OAAO;AAAjD,iBA0CA,iBA1CY,CAAA,UA0CgB,MA1ChB,CAAA,MAAA,EA0C+B,MA1C/B,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EA2CjB,CA3CiB,CAAA,EA4CzB,WA5CyB,CA4Cb,CA5Ca,CAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieConfig, CookieGroup, CookieOptions, Serializer } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare function createCookie<T>(config: CookieConfig<T>): Cookie<T>;
|
|
5
|
+
declare function createCookieGroup<T extends Record<string, Cookie<unknown>>>(cookies: T): CookieGroup<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;iBAuCgB,wBAAwB,aAAa,KAAK,OAAO;AAAjD,iBA0CA,iBA1CY,CAAA,UA0CgB,MA1ChB,CAAA,MAAA,EA0C+B,MA1C/B,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EA2CjB,CA3CiB,CAAA,EA4CzB,WA5CyB,CA4Cb,CA5Ca,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.106.0/helpers/objectSpread2.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
const jsonSerializer = {
|
|
5
|
+
serialize: (value) => {
|
|
6
|
+
if (typeof value === "string") return value;
|
|
7
|
+
return JSON.stringify(value);
|
|
8
|
+
},
|
|
9
|
+
deserialize: (raw) => {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(raw);
|
|
12
|
+
} catch (_unused) {
|
|
13
|
+
return raw;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
async function validateSchema(schema, value) {
|
|
18
|
+
const result = await schema["~standard"].validate(value);
|
|
19
|
+
if ("issues" in result && result.issues) return { success: false };
|
|
20
|
+
return {
|
|
21
|
+
success: true,
|
|
22
|
+
value: result.value
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createCookie(config) {
|
|
26
|
+
const { name, schema, serializer = jsonSerializer, get, set, delete: deleteFn } = config;
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
async get() {
|
|
30
|
+
const raw = await get();
|
|
31
|
+
if (raw === void 0) return void 0;
|
|
32
|
+
const parsed = serializer.deserialize(raw);
|
|
33
|
+
if (schema) {
|
|
34
|
+
const result = await validateSchema(schema, parsed);
|
|
35
|
+
if (!result.success) return void 0;
|
|
36
|
+
return result.value;
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
},
|
|
40
|
+
async set(value, options) {
|
|
41
|
+
if (schema) {
|
|
42
|
+
if (!(await validateSchema(schema, value)).success) throw new Error("Invalid cookie value");
|
|
43
|
+
}
|
|
44
|
+
await set(serializer.serialize(value), options);
|
|
45
|
+
},
|
|
46
|
+
async delete() {
|
|
47
|
+
await deleteFn();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function createCookieGroup(cookies) {
|
|
52
|
+
return _objectSpread2(_objectSpread2({}, cookies), {}, {
|
|
53
|
+
async get() {
|
|
54
|
+
const entries = await Promise.all(Object.entries(cookies).map(async ([key, cookie]) => [key, await cookie.get()]));
|
|
55
|
+
return Object.fromEntries(entries);
|
|
56
|
+
},
|
|
57
|
+
async set(values, options) {
|
|
58
|
+
const promises = [];
|
|
59
|
+
for (const [key, value] of Object.entries(values)) {
|
|
60
|
+
const cookie = cookies[key];
|
|
61
|
+
if (cookie && value !== void 0) promises.push(cookie.set(value, options));
|
|
62
|
+
}
|
|
63
|
+
await Promise.all(promises);
|
|
64
|
+
},
|
|
65
|
+
async deleteAll() {
|
|
66
|
+
await Promise.all(Object.values(cookies).map((c) => c.delete()));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { createCookie, createCookieGroup };
|
|
73
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type {\n Cookie,\n CookieConfig,\n CookieGroup,\n CookieOptions,\n CookieValues,\n Serializer,\n} from \"./types\";\n\nexport type { Cookie, CookieGroup, CookieOptions, Serializer } from \"./types\";\n\nconst jsonSerializer: Serializer<unknown> = {\n serialize: (value) => {\n if (typeof value === \"string\") return value;\n return JSON.stringify(value);\n },\n deserialize: (raw) => {\n try {\n return JSON.parse(raw);\n } catch {\n return raw;\n }\n },\n};\n\nasync function validateSchema<T>(\n schema: StandardSchemaV1<T>,\n value: unknown,\n): Promise<{ success: true; value: T } | { success: false }> {\n const result = await schema[\"~standard\"].validate(value);\n\n if (\"issues\" in result && result.issues) {\n return { success: false };\n }\n\n return { success: true, value: result.value as T };\n}\n\nexport function createCookie<T>(config: CookieConfig<T>): Cookie<T> {\n const {\n name,\n schema,\n serializer = jsonSerializer as Serializer<T>,\n get,\n set,\n delete: deleteFn,\n } = config;\n\n return {\n name,\n async get() {\n const raw = await get();\n if (raw === undefined) return undefined;\n\n const parsed = serializer.deserialize(raw);\n\n if (schema) {\n const result = await validateSchema(schema, parsed);\n if (!result.success) return undefined;\n return result.value;\n }\n\n return parsed;\n },\n async set(value: T, options?: CookieOptions) {\n if (schema) {\n const result = await validateSchema(schema, value);\n if (!result.success) {\n throw new Error(\"Invalid cookie value\");\n }\n }\n\n await set(serializer.serialize(value), options);\n },\n async delete() {\n await deleteFn();\n },\n };\n}\n\nexport function createCookieGroup<T extends Record<string, Cookie<unknown>>>(\n cookies: T,\n): CookieGroup<T> {\n return {\n ...cookies,\n async get() {\n const entries = await Promise.all(\n Object.entries(cookies).map(async ([key, cookie]) => [\n key,\n await cookie.get(),\n ]),\n );\n return Object.fromEntries(entries) as {\n [K in keyof T]: Awaited<ReturnType<T[K][\"get\"]>>;\n };\n },\n async set(values: Partial<CookieValues<T>>, options?: CookieOptions) {\n const promises: Promise<void>[] = [];\n for (const [key, value] of Object.entries(values)) {\n const cookie = cookies[key as keyof T];\n if (cookie && value !== undefined) {\n promises.push(cookie.set(value, options));\n }\n }\n await Promise.all(promises);\n },\n async deleteAll() {\n await Promise.all(Object.values(cookies).map((c) => c.delete()));\n },\n };\n}\n"],"mappings":";;;AAYA,MAAM,iBAAsC;CAC1C,YAAY,UAAU;AACpB,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,KAAK,UAAU,MAAM;;CAE9B,cAAc,QAAQ;AACpB,MAAI;AACF,UAAO,KAAK,MAAM,IAAI;oBAChB;AACN,UAAO;;;CAGZ;AAED,eAAe,eACb,QACA,OAC2D;CAC3D,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,MAAM;AAExD,KAAI,YAAY,UAAU,OAAO,OAC/B,QAAO,EAAE,SAAS,OAAO;AAG3B,QAAO;EAAE,SAAS;EAAM,OAAO,OAAO;EAAY;;AAGpD,SAAgB,aAAgB,QAAoC;CAClE,MAAM,EACJ,MACA,QACA,aAAa,gBACb,KACA,KACA,QAAQ,aACN;AAEJ,QAAO;EACL;EACA,MAAM,MAAM;GACV,MAAM,MAAM,MAAM,KAAK;AACvB,OAAI,QAAQ,OAAW,QAAO;GAE9B,MAAM,SAAS,WAAW,YAAY,IAAI;AAE1C,OAAI,QAAQ;IACV,MAAM,SAAS,MAAM,eAAe,QAAQ,OAAO;AACnD,QAAI,CAAC,OAAO,QAAS,QAAO;AAC5B,WAAO,OAAO;;AAGhB,UAAO;;EAET,MAAM,IAAI,OAAU,SAAyB;AAC3C,OAAI,QAEF;QAAI,EADW,MAAM,eAAe,QAAQ,MAAM,EACtC,QACV,OAAM,IAAI,MAAM,uBAAuB;;AAI3C,SAAM,IAAI,WAAW,UAAU,MAAM,EAAE,QAAQ;;EAEjD,MAAM,SAAS;AACb,SAAM,UAAU;;EAEnB;;AAGH,SAAgB,kBACd,SACgB;AAChB,0CACK;EACH,MAAM,MAAM;GACV,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,QAAQ,QAAQ,CAAC,IAAI,OAAO,CAAC,KAAK,YAAY,CACnD,KACA,MAAM,OAAO,KAAK,CACnB,CAAC,CACH;AACD,UAAO,OAAO,YAAY,QAAQ;;EAIpC,MAAM,IAAI,QAAkC,SAAyB;GACnE,MAAM,WAA4B,EAAE;AACpC,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,EAAE;IACjD,MAAM,SAAS,QAAQ;AACvB,QAAI,UAAU,UAAU,OACtB,UAAS,KAAK,OAAO,IAAI,OAAO,QAAQ,CAAC;;AAG7C,SAAM,QAAQ,IAAI,SAAS;;EAE7B,MAAM,YAAY;AAChB,SAAM,QAAQ,IAAI,OAAO,OAAO,QAAQ,CAAC,KAAK,MAAM,EAAE,QAAQ,CAAC,CAAC"}
|
package/dist/next.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_index = require('./index.cjs');
|
|
2
|
+
let next_headers = require("next/headers");
|
|
3
|
+
|
|
4
|
+
//#region src/next.ts
|
|
5
|
+
function createCookie(name, options) {
|
|
6
|
+
return require_index.createCookie({
|
|
7
|
+
name,
|
|
8
|
+
schema: options === null || options === void 0 ? void 0 : options.schema,
|
|
9
|
+
serializer: options === null || options === void 0 ? void 0 : options.serializer,
|
|
10
|
+
get: async () => {
|
|
11
|
+
var _await$cookies$get;
|
|
12
|
+
return (_await$cookies$get = (await (0, next_headers.cookies)()).get(name)) === null || _await$cookies$get === void 0 ? void 0 : _await$cookies$get.value;
|
|
13
|
+
},
|
|
14
|
+
set: async (value, opts) => {
|
|
15
|
+
(await (0, next_headers.cookies)()).set(name, value, opts);
|
|
16
|
+
},
|
|
17
|
+
delete: async () => {
|
|
18
|
+
(await (0, next_headers.cookies)()).delete(name);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.createCookie = createCookie;
|
|
25
|
+
exports.createCookieGroup = require_index.createCookieGroup;
|
package/dist/next.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieGroup, CookieOptions, CreateCookieOptions, Serializer } from "./types.cjs";
|
|
2
|
+
import { createCookieGroup } from "./index.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/next.d.ts
|
|
5
|
+
declare function createCookie<T>(name: string, options?: CreateCookieOptions<T>): Cookie<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=next.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.cts","names":[],"sources":["../src/next.ts"],"sourcesContent":[],"mappings":";;;;iBAOgB,wCAEJ,oBAAoB,KAC7B,OAAO"}
|
package/dist/next.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cookie, CookieGroup, CookieOptions, CreateCookieOptions, Serializer } from "./types.mjs";
|
|
2
|
+
import { createCookieGroup } from "./index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/next.d.ts
|
|
5
|
+
declare function createCookie<T>(name: string, options?: CreateCookieOptions<T>): Cookie<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { type Cookie, type CookieGroup, type CookieOptions, type Serializer, createCookie, createCookieGroup };
|
|
8
|
+
//# sourceMappingURL=next.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.mts","names":[],"sources":["../src/next.ts"],"sourcesContent":[],"mappings":";;;;iBAOgB,wCAEJ,oBAAoB,KAC7B,OAAO"}
|
package/dist/next.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createCookie as createCookie$1, createCookieGroup } from "./index.mjs";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
|
|
4
|
+
//#region src/next.ts
|
|
5
|
+
function createCookie(name, options) {
|
|
6
|
+
return createCookie$1({
|
|
7
|
+
name,
|
|
8
|
+
schema: options === null || options === void 0 ? void 0 : options.schema,
|
|
9
|
+
serializer: options === null || options === void 0 ? void 0 : options.serializer,
|
|
10
|
+
get: async () => {
|
|
11
|
+
var _await$cookies$get;
|
|
12
|
+
return (_await$cookies$get = (await cookies()).get(name)) === null || _await$cookies$get === void 0 ? void 0 : _await$cookies$get.value;
|
|
13
|
+
},
|
|
14
|
+
set: async (value, opts) => {
|
|
15
|
+
(await cookies()).set(name, value, opts);
|
|
16
|
+
},
|
|
17
|
+
delete: async () => {
|
|
18
|
+
(await cookies()).delete(name);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createCookie, createCookieGroup };
|
|
25
|
+
//# sourceMappingURL=next.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.mjs","names":["createCookieCore"],"sources":["../src/next.ts"],"sourcesContent":["import { cookies } from \"next/headers\";\nimport { createCookie as createCookieCore } from \"./index\";\nimport type { Cookie, CreateCookieOptions } from \"./types\";\n\nexport { createCookieGroup } from \"./index\";\nexport type { Cookie, CookieGroup, CookieOptions, Serializer } from \"./types\";\n\nexport function createCookie<T>(\n name: string,\n options?: CreateCookieOptions<T>,\n): Cookie<T> {\n return createCookieCore({\n name,\n schema: options?.schema,\n serializer: options?.serializer,\n get: async () => (await cookies()).get(name)?.value,\n set: async (value, opts) => {\n (await cookies()).set(name, value, opts);\n },\n delete: async () => {\n (await cookies()).delete(name);\n },\n });\n}\n"],"mappings":";;;;AAOA,SAAgB,aACd,MACA,SACW;AACX,QAAOA,eAAiB;EACtB;EACA,0DAAQ,QAAS;EACjB,8DAAY,QAAS;EACrB,KAAK,YAAY;;iCAAC,MAAM,SAAS,EAAE,IAAI,KAAK,0EAAE;;EAC9C,KAAK,OAAO,OAAO,SAAS;AAC1B,IAAC,MAAM,SAAS,EAAE,IAAI,MAAM,OAAO,KAAK;;EAE1C,QAAQ,YAAY;AAClB,IAAC,MAAM,SAAS,EAAE,OAAO,KAAK;;EAEjC,CAAC"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
interface CookieOptions {
|
|
5
|
+
maxAge?: number;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
path?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
sameSite?: "strict" | "lax" | "none";
|
|
12
|
+
}
|
|
13
|
+
interface Serializer<T> {
|
|
14
|
+
serialize: (value: T) => string;
|
|
15
|
+
deserialize: (raw: string) => T;
|
|
16
|
+
}
|
|
17
|
+
interface Cookie<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
get(): Promise<T | undefined>;
|
|
20
|
+
set(value: T, options?: CookieOptions): Promise<void>;
|
|
21
|
+
delete(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface CookieConfig<T> {
|
|
24
|
+
name: string;
|
|
25
|
+
schema?: StandardSchemaV1<T>;
|
|
26
|
+
serializer?: Serializer<T>;
|
|
27
|
+
get: () => Promise<string | undefined> | string | undefined;
|
|
28
|
+
set: (value: string, options?: CookieOptions) => Promise<void> | void;
|
|
29
|
+
delete: () => Promise<void> | void;
|
|
30
|
+
}
|
|
31
|
+
interface CreateCookieOptions<T> {
|
|
32
|
+
schema?: StandardSchemaV1<T>;
|
|
33
|
+
serializer?: Serializer<T>;
|
|
34
|
+
}
|
|
35
|
+
type CookieValues<T extends Record<string, Cookie<unknown>>> = { [K in keyof T]: Parameters<T[K]["set"]>[0] };
|
|
36
|
+
interface _CookieGroup<T extends Record<string, Cookie<unknown>>> {
|
|
37
|
+
get(): Promise<{ [K in keyof T]: Awaited<ReturnType<T[K]["get"]>> }>;
|
|
38
|
+
set(values: Partial<CookieValues<T>>, options?: CookieOptions): Promise<void>;
|
|
39
|
+
deleteAll(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
type CookieGroup<T extends Record<string, Cookie<unknown>>> = _CookieGroup<T> & T;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Cookie, CookieConfig, CookieGroup, CookieOptions, CreateCookieOptions, Serializer };
|
|
44
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;UAEiB,aAAA;;EAAA,OAAA,CAAA,EAEL,IAFK;EAUA,IAAA,CAAA,EAAA,MAAU;EAAA,MAAA,CAAA,EAAA,MAAA;QACN,CAAA,EAAA,OAAA;UACW,CAAA,EAAA,OAAA;EAAC,QAAA,CAAA,EAAA,QAAA,GAAA,KAAA,GAAA,MAAA;AAGjC;AAAuB,UALN,UAKM,CAAA,CAAA,CAAA,CAAA;WAEN,EAAA,CAAA,KAAA,EANI,CAMJ,EAAA,GAAA,MAAA;aAAR,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GALuB,CAKvB;;AACiB,UAHT,MAGS,CAAA,CAAA,CAAA,CAAA;MAAgB,EAAA,MAAA;KAC9B,EAAA,EAFH,OAEG,CAFK,CAEL,GAAA,SAAA,CAAA;EAAO,GAAA,CAAA,KAAA,EADN,CACM,EAAA,OAAA,CAAA,EADO,aACP,CAAA,EADuB,OACvB,CAAA,IAAA,CAAA;EAGF,MAAA,EAAA,EAHL,OAGiB,CAAA,IAAA,CAAA;;AAED,UAFX,YAEW,CAAA,CAAA,CAAA,CAAA;MAAjB,EAAA,MAAA;QACe,CAAA,EADf,gBACe,CADE,CACF,CAAA;YAAX,CAAA,EAAA,UAAA,CAAW,CAAX,CAAA;KACF,EAAA,GAAA,GAAA,OAAA,CAAA,MAAA,GAAA,SAAA,CAAA,GAAA,MAAA,GAAA,SAAA;KACoB,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,aAAA,EAAA,GAAkB,OAAlB,CAAA,IAAA,CAAA,GAAA,IAAA;QAAkB,EAAA,GAAA,GACnC,OADmC,CAAA,IAAA,CAAA,GAAA,IAAA;;AAC5B,UAGN,mBAHM,CAAA,CAAA,CAAA,CAAA;EAGN,MAAA,CAAA,EACN,gBADyB,CACR,CADQ,CAAA;EAAA,UAAA,CAAA,EAErB,UAFqB,CAEV,CAFU,CAAA;;AAEV,KASd,YATc,CAAA,UASS,MATT,CAAA,MAAA,EASwB,MATxB,CAAA,OAAA,CAAA,CAAA,CAAA,GAAA,QAAX,MAUD,CAVC,GAUG,UAVH,CAUc,CAVd,CAUgB,CAVhB,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAU;AASb,UAIK,YAJO,CAAA,UAIgB,MAJhB,CAAA,MAAA,EAI+B,MAJ/B,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA;EAAA,GAAA,EAAA,EAKf,OALe,CAAA,QAA0B,MAKnB,CALmB,GAKf,OALe,CAKP,UALO,CAKI,CALJ,CAKM,CALN,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA;KACpC,CAAA,MAAA,EAKA,OALA,CAKQ,YALR,CAKqB,CALrB,CAAA,CAAA,EAAA,OAAA,CAAA,EAKoC,aALpC,CAAA,EAKoD,OALpD,CAAA,IAAA,CAAA;WAAe,EAAA,EAMd,OANc,CAAA,IAAA,CAAA;;AAAX,KASN,WATM,CAAA,UASgB,MAThB,CAAA,MAAA,EAS+B,MAT/B,CAAA,OAAA,CAAA,CAAA,CAAA,GAUhB,YAVgB,CAUH,CAVG,CAAA,GAUE,CAVF"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
interface CookieOptions {
|
|
5
|
+
maxAge?: number;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
path?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
sameSite?: "strict" | "lax" | "none";
|
|
12
|
+
}
|
|
13
|
+
interface Serializer<T> {
|
|
14
|
+
serialize: (value: T) => string;
|
|
15
|
+
deserialize: (raw: string) => T;
|
|
16
|
+
}
|
|
17
|
+
interface Cookie<T> {
|
|
18
|
+
name: string;
|
|
19
|
+
get(): Promise<T | undefined>;
|
|
20
|
+
set(value: T, options?: CookieOptions): Promise<void>;
|
|
21
|
+
delete(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
interface CookieConfig<T> {
|
|
24
|
+
name: string;
|
|
25
|
+
schema?: StandardSchemaV1<T>;
|
|
26
|
+
serializer?: Serializer<T>;
|
|
27
|
+
get: () => Promise<string | undefined> | string | undefined;
|
|
28
|
+
set: (value: string, options?: CookieOptions) => Promise<void> | void;
|
|
29
|
+
delete: () => Promise<void> | void;
|
|
30
|
+
}
|
|
31
|
+
interface CreateCookieOptions<T> {
|
|
32
|
+
schema?: StandardSchemaV1<T>;
|
|
33
|
+
serializer?: Serializer<T>;
|
|
34
|
+
}
|
|
35
|
+
type CookieValues<T extends Record<string, Cookie<unknown>>> = { [K in keyof T]: Parameters<T[K]["set"]>[0] };
|
|
36
|
+
interface _CookieGroup<T extends Record<string, Cookie<unknown>>> {
|
|
37
|
+
get(): Promise<{ [K in keyof T]: Awaited<ReturnType<T[K]["get"]>> }>;
|
|
38
|
+
set(values: Partial<CookieValues<T>>, options?: CookieOptions): Promise<void>;
|
|
39
|
+
deleteAll(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
type CookieGroup<T extends Record<string, Cookie<unknown>>> = _CookieGroup<T> & T;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { Cookie, CookieConfig, CookieGroup, CookieOptions, CreateCookieOptions, Serializer };
|
|
44
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;UAEiB,aAAA;;EAAA,OAAA,CAAA,EAEL,IAFK;EAUA,IAAA,CAAA,EAAA,MAAU;EAAA,MAAA,CAAA,EAAA,MAAA;QACN,CAAA,EAAA,OAAA;UACW,CAAA,EAAA,OAAA;EAAC,QAAA,CAAA,EAAA,QAAA,GAAA,KAAA,GAAA,MAAA;AAGjC;AAAuB,UALN,UAKM,CAAA,CAAA,CAAA,CAAA;WAEN,EAAA,CAAA,KAAA,EANI,CAMJ,EAAA,GAAA,MAAA;aAAR,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GALuB,CAKvB;;AACiB,UAHT,MAGS,CAAA,CAAA,CAAA,CAAA;MAAgB,EAAA,MAAA;KAC9B,EAAA,EAFH,OAEG,CAFK,CAEL,GAAA,SAAA,CAAA;EAAO,GAAA,CAAA,KAAA,EADN,CACM,EAAA,OAAA,CAAA,EADO,aACP,CAAA,EADuB,OACvB,CAAA,IAAA,CAAA;EAGF,MAAA,EAAA,EAHL,OAGiB,CAAA,IAAA,CAAA;;AAED,UAFX,YAEW,CAAA,CAAA,CAAA,CAAA;MAAjB,EAAA,MAAA;QACe,CAAA,EADf,gBACe,CADE,CACF,CAAA;YAAX,CAAA,EAAA,UAAA,CAAW,CAAX,CAAA;KACF,EAAA,GAAA,GAAA,OAAA,CAAA,MAAA,GAAA,SAAA,CAAA,GAAA,MAAA,GAAA,SAAA;KACoB,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,aAAA,EAAA,GAAkB,OAAlB,CAAA,IAAA,CAAA,GAAA,IAAA;QAAkB,EAAA,GAAA,GACnC,OADmC,CAAA,IAAA,CAAA,GAAA,IAAA;;AAC5B,UAGN,mBAHM,CAAA,CAAA,CAAA,CAAA;EAGN,MAAA,CAAA,EACN,gBADyB,CACR,CADQ,CAAA;EAAA,UAAA,CAAA,EAErB,UAFqB,CAEV,CAFU,CAAA;;AAEV,KASd,YATc,CAAA,UASS,MATT,CAAA,MAAA,EASwB,MATxB,CAAA,OAAA,CAAA,CAAA,CAAA,GAAA,QAAX,MAUD,CAVC,GAUG,UAVH,CAUc,CAVd,CAUgB,CAVhB,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAU;AASb,UAIK,YAJO,CAAA,UAIgB,MAJhB,CAAA,MAAA,EAI+B,MAJ/B,CAAA,OAAA,CAAA,CAAA,CAAA,CAAA;EAAA,GAAA,EAAA,EAKf,OALe,CAAA,QAA0B,MAKnB,CALmB,GAKf,OALe,CAKP,UALO,CAKI,CALJ,CAKM,CALN,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA;KACpC,CAAA,MAAA,EAKA,OALA,CAKQ,YALR,CAKqB,CALrB,CAAA,CAAA,EAAA,OAAA,CAAA,EAKoC,aALpC,CAAA,EAKoD,OALpD,CAAA,IAAA,CAAA;WAAe,EAAA,EAMd,OANc,CAAA,IAAA,CAAA;;AAAX,KASN,WATM,CAAA,UASgB,MAThB,CAAA,MAAA,EAS+B,MAT/B,CAAA,OAAA,CAAA,CAAA,CAAA,GAUhB,YAVgB,CAUH,CAVG,CAAA,GAUE,CAVF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jlnstack/cookies",
|
|
3
|
+
"description": "Type-safe cookie management",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "jln13x",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/jln13x/jlnstack"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"package.json"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsdown",
|
|
20
|
+
"dev": "tsdown --watch",
|
|
21
|
+
"lint": "tsc --noEmit",
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"test:run": "vitest run",
|
|
24
|
+
"test:ui": "vitest --ui"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"next": ">=16"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@standard-schema/spec": "^1.1.0",
|
|
31
|
+
"@vitest/ui": "^2.1.8",
|
|
32
|
+
"tsdown": "^0.15.4",
|
|
33
|
+
"typescript": "^5.9.3",
|
|
34
|
+
"vitest": "^2.1.8"
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/index.d.mts",
|
|
41
|
+
"default": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/index.d.cts",
|
|
45
|
+
"default": "./dist/index.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./next": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/next.d.mts",
|
|
51
|
+
"default": "./dist/next.mjs"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/next.d.cts",
|
|
55
|
+
"default": "./dist/next.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./browser": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/browser.d.mts",
|
|
61
|
+
"default": "./dist/browser.mjs"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/browser.d.cts",
|
|
65
|
+
"default": "./dist/browser.cjs"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|