@bquery/bquery 1.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/LICENSE.md +21 -0
- package/README.md +266 -0
- package/dist/component/index.d.ts +155 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/component.es.mjs +128 -0
- package/dist/component.es.mjs.map +1 -0
- package/dist/core/collection.d.ts +198 -0
- package/dist/core/collection.d.ts.map +1 -0
- package/dist/core/element.d.ts +301 -0
- package/dist/core/element.d.ts.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/selector.d.ts +11 -0
- package/dist/core/selector.d.ts.map +1 -0
- package/dist/core/shared.d.ts +7 -0
- package/dist/core/shared.d.ts.map +1 -0
- package/dist/core/utils.d.ts +300 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core.es.mjs +1015 -0
- package/dist/core.es.mjs.map +1 -0
- package/dist/full.d.ts +48 -0
- package/dist/full.d.ts.map +1 -0
- package/dist/full.es.mjs +43 -0
- package/dist/full.es.mjs.map +1 -0
- package/dist/full.iife.js +2 -0
- package/dist/full.iife.js.map +1 -0
- package/dist/full.umd.js +2 -0
- package/dist/full.umd.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.mjs +43 -0
- package/dist/index.es.mjs.map +1 -0
- package/dist/motion/index.d.ts +145 -0
- package/dist/motion/index.d.ts.map +1 -0
- package/dist/motion.es.mjs +104 -0
- package/dist/motion.es.mjs.map +1 -0
- package/dist/platform/buckets.d.ts +44 -0
- package/dist/platform/buckets.d.ts.map +1 -0
- package/dist/platform/cache.d.ts +71 -0
- package/dist/platform/cache.d.ts.map +1 -0
- package/dist/platform/index.d.ts +15 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/notifications.d.ts +52 -0
- package/dist/platform/notifications.d.ts.map +1 -0
- package/dist/platform/storage.d.ts +69 -0
- package/dist/platform/storage.d.ts.map +1 -0
- package/dist/platform.es.mjs +245 -0
- package/dist/platform.es.mjs.map +1 -0
- package/dist/reactive/index.d.ts +8 -0
- package/dist/reactive/index.d.ts.map +1 -0
- package/dist/reactive/signal.d.ts +204 -0
- package/dist/reactive/signal.d.ts.map +1 -0
- package/dist/reactive.es.mjs +123 -0
- package/dist/reactive.es.mjs.map +1 -0
- package/dist/security/index.d.ts +8 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/sanitize.d.ts +99 -0
- package/dist/security/sanitize.d.ts.map +1 -0
- package/dist/security.es.mjs +194 -0
- package/dist/security.es.mjs.map +1 -0
- package/package.json +120 -0
- package/src/component/index.ts +360 -0
- package/src/core/collection.ts +339 -0
- package/src/core/element.ts +493 -0
- package/src/core/index.ts +4 -0
- package/src/core/selector.ts +29 -0
- package/src/core/shared.ts +13 -0
- package/src/core/utils.ts +425 -0
- package/src/full.ts +101 -0
- package/src/index.ts +27 -0
- package/src/motion/index.ts +365 -0
- package/src/platform/buckets.ts +115 -0
- package/src/platform/cache.ts +130 -0
- package/src/platform/index.ts +18 -0
- package/src/platform/notifications.ts +87 -0
- package/src/platform/storage.ts +208 -0
- package/src/reactive/index.ts +9 -0
- package/src/reactive/signal.ts +347 -0
- package/src/security/index.ts +18 -0
- package/src/security/sanitize.ts +446 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const $ = async (e) => {
|
|
2
|
+
const t = typeof e == "function" ? e : e.update, c = document;
|
|
3
|
+
if (c.startViewTransition) {
|
|
4
|
+
await c.startViewTransition(() => t()).finished;
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
t();
|
|
8
|
+
}, h = (e) => {
|
|
9
|
+
const t = e.getBoundingClientRect();
|
|
10
|
+
return {
|
|
11
|
+
top: t.top,
|
|
12
|
+
left: t.left,
|
|
13
|
+
width: t.width,
|
|
14
|
+
height: t.height
|
|
15
|
+
};
|
|
16
|
+
}, P = (e, t, c = {}) => {
|
|
17
|
+
const { duration: m = 300, easing: p = "ease-out", onComplete: i } = c, n = h(e);
|
|
18
|
+
if (n.width === 0 || n.height === 0)
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
const o = t.left - n.left, f = t.top - n.top, s = t.width / n.width, a = t.height / n.height;
|
|
21
|
+
if (o === 0 && f === 0 && s === 1 && a === 1)
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
const r = e;
|
|
24
|
+
return r.style.transform = `translate(${o}px, ${f}px) scale(${s}, ${a})`, r.style.transformOrigin = "top left", r.offsetHeight, new Promise((u) => {
|
|
25
|
+
const d = r.animate(
|
|
26
|
+
[
|
|
27
|
+
{
|
|
28
|
+
transform: `translate(${o}px, ${f}px) scale(${s}, ${a})`
|
|
29
|
+
},
|
|
30
|
+
{ transform: "translate(0, 0) scale(1, 1)" }
|
|
31
|
+
],
|
|
32
|
+
{ duration: m, easing: p, fill: "forwards" }
|
|
33
|
+
);
|
|
34
|
+
d.onfinish = () => {
|
|
35
|
+
r.style.transform = "", r.style.transformOrigin = "", i?.(), u();
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}, v = async (e, t, c = {}) => {
|
|
39
|
+
const m = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const i of e)
|
|
41
|
+
m.set(i, h(i));
|
|
42
|
+
t();
|
|
43
|
+
const p = e.map((i) => {
|
|
44
|
+
const n = m.get(i);
|
|
45
|
+
return n ? P(i, n, c) : Promise.resolve();
|
|
46
|
+
});
|
|
47
|
+
await Promise.all(p);
|
|
48
|
+
}, F = {
|
|
49
|
+
stiffness: 100,
|
|
50
|
+
damping: 10,
|
|
51
|
+
mass: 1,
|
|
52
|
+
precision: 0.01
|
|
53
|
+
}, x = (e, t = {}) => {
|
|
54
|
+
const { stiffness: c, damping: m, mass: p, precision: i } = {
|
|
55
|
+
...F,
|
|
56
|
+
...t
|
|
57
|
+
};
|
|
58
|
+
let n = e, o = 0, f = e, s = null, a = null;
|
|
59
|
+
const r = /* @__PURE__ */ new Set(), u = () => {
|
|
60
|
+
for (const l of r)
|
|
61
|
+
l(n);
|
|
62
|
+
}, d = () => {
|
|
63
|
+
const l = n - f, g = -c * l, w = -m * o, y = (g + w) / p;
|
|
64
|
+
if (o += y * (1 / 60), n += o * (1 / 60), u(), Math.abs(o) < i && Math.abs(l) < i) {
|
|
65
|
+
n = f, o = 0, s = null, u(), a?.(), a = null;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
s = requestAnimationFrame(d);
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
to(l) {
|
|
72
|
+
return f = l, s !== null && cancelAnimationFrame(s), new Promise((g) => {
|
|
73
|
+
a = g, s = requestAnimationFrame(d);
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
current() {
|
|
77
|
+
return n;
|
|
78
|
+
},
|
|
79
|
+
stop() {
|
|
80
|
+
s !== null && (cancelAnimationFrame(s), s = null), o = 0, a?.(), a = null;
|
|
81
|
+
},
|
|
82
|
+
onChange(l) {
|
|
83
|
+
return r.add(l), () => r.delete(l);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}, A = {
|
|
87
|
+
/** Gentle, slow-settling spring */
|
|
88
|
+
gentle: { stiffness: 80, damping: 15 },
|
|
89
|
+
/** Responsive, snappy spring */
|
|
90
|
+
snappy: { stiffness: 200, damping: 20 },
|
|
91
|
+
/** Bouncy, playful spring */
|
|
92
|
+
bouncy: { stiffness: 300, damping: 8 },
|
|
93
|
+
/** Stiff, quick spring with minimal overshoot */
|
|
94
|
+
stiff: { stiffness: 400, damping: 30 }
|
|
95
|
+
};
|
|
96
|
+
export {
|
|
97
|
+
h as capturePosition,
|
|
98
|
+
P as flip,
|
|
99
|
+
v as flipList,
|
|
100
|
+
x as spring,
|
|
101
|
+
A as springPresets,
|
|
102
|
+
$ as transition
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=motion.es.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motion.es.mjs","sources":["../src/motion/index.ts"],"sourcesContent":["/**\n * Motion module providing view transitions, FLIP animations, and spring physics.\n * Designed to work with modern browser APIs while providing smooth fallbacks.\n *\n * @module bquery/motion\n */\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Options for view transitions.\n */\nexport interface TransitionOptions {\n /** The DOM update function to execute during transition */\n update: () => void;\n}\n\n/**\n * Captured element bounds for FLIP animations.\n */\nexport interface ElementBounds {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\n/**\n * FLIP animation configuration options.\n */\nexport interface FlipOptions {\n /** Animation duration in milliseconds */\n duration?: number;\n /** CSS easing function */\n easing?: string;\n /** Callback when animation completes */\n onComplete?: () => void;\n}\n\n/**\n * Spring physics configuration.\n */\nexport interface SpringConfig {\n /** Spring stiffness (default: 100) */\n stiffness?: number;\n /** Damping coefficient (default: 10) */\n damping?: number;\n /** Mass of the object (default: 1) */\n mass?: number;\n /** Velocity threshold for completion (default: 0.01) */\n precision?: number;\n}\n\n/**\n * Spring instance for animating values.\n */\nexport interface Spring {\n /** Start animating to target value */\n to(target: number): Promise<void>;\n /** Get current animated value */\n current(): number;\n /** Stop the animation */\n stop(): void;\n /** Subscribe to value changes */\n onChange(callback: (value: number) => void): () => void;\n}\n\n// ============================================================================\n// View Transitions\n// ============================================================================\n\n/** Extended document type with View Transitions API */\ntype DocumentWithTransition = Document & {\n startViewTransition?: (callback: () => void) => {\n finished: Promise<void>;\n ready: Promise<void>;\n updateCallbackDone: Promise<void>;\n };\n};\n\n/**\n * Execute a DOM update with view transition animation.\n * Falls back to immediate update when View Transitions API is unavailable.\n *\n * @param updateOrOptions - Update function or options object\n * @returns Promise that resolves when transition completes\n *\n * @example\n * ```ts\n * await transition(() => {\n * $('#content').text('Updated');\n * });\n * ```\n */\nexport const transition = async (\n updateOrOptions: (() => void) | TransitionOptions\n): Promise<void> => {\n const update = typeof updateOrOptions === 'function' ? updateOrOptions : updateOrOptions.update;\n\n const doc = document as DocumentWithTransition;\n\n if (doc.startViewTransition) {\n await doc.startViewTransition(() => update()).finished;\n return;\n }\n\n update();\n};\n\n// ============================================================================\n// FLIP Animations\n// ============================================================================\n\n/**\n * Capture the current bounds of an element for FLIP animation.\n *\n * @param element - The DOM element to measure\n * @returns The element's current position and size\n */\nexport const capturePosition = (element: Element): ElementBounds => {\n const rect = element.getBoundingClientRect();\n return {\n top: rect.top,\n left: rect.left,\n width: rect.width,\n height: rect.height,\n };\n};\n\n/**\n * Perform a FLIP (First, Last, Invert, Play) animation.\n * Animates an element from its captured position to its current position.\n *\n * @param element - The element to animate\n * @param firstBounds - The previously captured bounds\n * @param options - Animation configuration\n * @returns Promise that resolves when animation completes\n *\n * @example\n * ```ts\n * const first = capturePosition(element);\n * // ... DOM changes that move the element ...\n * await flip(element, first, { duration: 300 });\n * ```\n */\nexport const flip = (\n element: Element,\n firstBounds: ElementBounds,\n options: FlipOptions = {}\n): Promise<void> => {\n const { duration = 300, easing = 'ease-out', onComplete } = options;\n\n // Last: Get current position\n const lastBounds = capturePosition(element);\n\n // Skip animation if element has zero dimensions (avoid division by zero)\n if (lastBounds.width === 0 || lastBounds.height === 0) {\n return Promise.resolve();\n }\n\n // Invert: Calculate the delta\n const deltaX = firstBounds.left - lastBounds.left;\n const deltaY = firstBounds.top - lastBounds.top;\n const deltaW = firstBounds.width / lastBounds.width;\n const deltaH = firstBounds.height / lastBounds.height;\n\n // Skip animation if no change\n if (deltaX === 0 && deltaY === 0 && deltaW === 1 && deltaH === 1) {\n return Promise.resolve();\n }\n\n const htmlElement = element as HTMLElement;\n\n // Apply inverted transform\n htmlElement.style.transform = `translate(${deltaX}px, ${deltaY}px) scale(${deltaW}, ${deltaH})`;\n htmlElement.style.transformOrigin = 'top left';\n\n // Force reflow\n void htmlElement.offsetHeight;\n\n // Play: Animate back to current position\n return new Promise((resolve) => {\n const animation = htmlElement.animate(\n [\n {\n transform: `translate(${deltaX}px, ${deltaY}px) scale(${deltaW}, ${deltaH})`,\n },\n { transform: 'translate(0, 0) scale(1, 1)' },\n ],\n { duration, easing, fill: 'forwards' }\n );\n\n animation.onfinish = () => {\n htmlElement.style.transform = '';\n htmlElement.style.transformOrigin = '';\n onComplete?.();\n resolve();\n };\n });\n};\n\n/**\n * FLIP helper for animating a list of elements.\n * Useful for reordering lists with smooth animations.\n *\n * @param elements - Array of elements to animate\n * @param performUpdate - Function that performs the DOM update\n * @param options - Animation configuration\n *\n * @example\n * ```ts\n * await flipList(listItems, () => {\n * container.appendChild(container.firstChild); // Move first to last\n * });\n * ```\n */\nexport const flipList = async (\n elements: Element[],\n performUpdate: () => void,\n options: FlipOptions = {}\n): Promise<void> => {\n // First: Capture all positions\n const positions = new Map<Element, ElementBounds>();\n for (const el of elements) {\n positions.set(el, capturePosition(el));\n }\n\n // Perform DOM update\n performUpdate();\n\n // Animate each element\n const animations = elements.map((el) => {\n const first = positions.get(el);\n if (!first) return Promise.resolve();\n return flip(el, first, options);\n });\n\n await Promise.all(animations);\n};\n\n// ============================================================================\n// Spring Physics\n// ============================================================================\n\n/**\n * Default spring configuration values.\n */\nconst DEFAULT_SPRING_CONFIG: Required<SpringConfig> = {\n stiffness: 100,\n damping: 10,\n mass: 1,\n precision: 0.01,\n};\n\n/**\n * Create a spring-based animation for smooth, physics-based motion.\n *\n * @param initialValue - Starting value for the spring\n * @param config - Spring physics configuration\n * @returns Spring instance for controlling the animation\n *\n * @example\n * ```ts\n * const x = spring(0, { stiffness: 120, damping: 14 });\n * x.onChange((value) => {\n * element.style.transform = `translateX(${value}px)`;\n * });\n * await x.to(100);\n * ```\n */\nexport const spring = (initialValue: number, config: SpringConfig = {}): Spring => {\n const { stiffness, damping, mass, precision } = {\n ...DEFAULT_SPRING_CONFIG,\n ...config,\n };\n\n let current = initialValue;\n let velocity = 0;\n let target = initialValue;\n let animationFrame: number | null = null;\n let resolvePromise: (() => void) | null = null;\n const listeners = new Set<(value: number) => void>();\n\n const notifyListeners = () => {\n for (const listener of listeners) {\n listener(current);\n }\n };\n\n const step = () => {\n // Spring physics calculation\n const displacement = current - target;\n const springForce = -stiffness * displacement;\n const dampingForce = -damping * velocity;\n const acceleration = (springForce + dampingForce) / mass;\n\n velocity += acceleration * (1 / 60); // Assuming 60fps\n current += velocity * (1 / 60);\n\n notifyListeners();\n\n // Check if spring has settled\n if (Math.abs(velocity) < precision && Math.abs(displacement) < precision) {\n current = target;\n velocity = 0;\n animationFrame = null;\n notifyListeners();\n resolvePromise?.();\n resolvePromise = null;\n return;\n }\n\n animationFrame = requestAnimationFrame(step);\n };\n\n return {\n to(newTarget: number): Promise<void> {\n target = newTarget;\n\n if (animationFrame !== null) {\n cancelAnimationFrame(animationFrame);\n }\n\n return new Promise((resolve) => {\n resolvePromise = resolve;\n animationFrame = requestAnimationFrame(step);\n });\n },\n\n current(): number {\n return current;\n },\n\n stop(): void {\n if (animationFrame !== null) {\n cancelAnimationFrame(animationFrame);\n animationFrame = null;\n }\n velocity = 0;\n resolvePromise?.();\n resolvePromise = null;\n },\n\n onChange(callback: (value: number) => void): () => void {\n listeners.add(callback);\n return () => listeners.delete(callback);\n },\n };\n};\n\n/**\n * Preset spring configurations for common use cases.\n */\nexport const springPresets = {\n /** Gentle, slow-settling spring */\n gentle: { stiffness: 80, damping: 15 } as SpringConfig,\n /** Responsive, snappy spring */\n snappy: { stiffness: 200, damping: 20 } as SpringConfig,\n /** Bouncy, playful spring */\n bouncy: { stiffness: 300, damping: 8 } as SpringConfig,\n /** Stiff, quick spring with minimal overshoot */\n stiff: { stiffness: 400, damping: 30 } as SpringConfig,\n};\n"],"names":["transition","updateOrOptions","update","doc","capturePosition","element","rect","flip","firstBounds","options","duration","easing","onComplete","lastBounds","deltaX","deltaY","deltaW","deltaH","htmlElement","resolve","animation","flipList","elements","performUpdate","positions","el","animations","first","DEFAULT_SPRING_CONFIG","spring","initialValue","config","stiffness","damping","mass","precision","current","velocity","target","animationFrame","resolvePromise","listeners","notifyListeners","listener","step","displacement","springForce","dampingForce","acceleration","newTarget","callback","springPresets"],"mappings":"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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Buckets API wrapper.
|
|
3
|
+
* Provides a simplified interface for storing blobs and binary data.
|
|
4
|
+
* Falls back to IndexedDB when Storage Buckets API is not available.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Bucket interface for blob storage operations.
|
|
8
|
+
*/
|
|
9
|
+
export interface Bucket {
|
|
10
|
+
/**
|
|
11
|
+
* Store a blob in the bucket.
|
|
12
|
+
* @param key - Unique identifier for the blob
|
|
13
|
+
* @param data - Blob data to store
|
|
14
|
+
*/
|
|
15
|
+
put(key: string, data: Blob): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve a blob from the bucket.
|
|
18
|
+
* @param key - Blob identifier
|
|
19
|
+
* @returns The stored blob or null if not found
|
|
20
|
+
*/
|
|
21
|
+
get(key: string): Promise<Blob | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Remove a blob from the bucket.
|
|
24
|
+
* @param key - Blob identifier
|
|
25
|
+
*/
|
|
26
|
+
remove(key: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* List all keys in the bucket.
|
|
29
|
+
* @returns Array of blob keys
|
|
30
|
+
*/
|
|
31
|
+
keys(): Promise<string[]>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Bucket manager for creating and accessing storage buckets.
|
|
35
|
+
*/
|
|
36
|
+
export declare const buckets: {
|
|
37
|
+
/**
|
|
38
|
+
* Open or create a storage bucket.
|
|
39
|
+
* @param name - Bucket name
|
|
40
|
+
* @returns Bucket instance for blob operations
|
|
41
|
+
*/
|
|
42
|
+
open(name: string): Promise<Bucket>;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=buckets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buckets.d.ts","sourceRoot":"","sources":["../../src/platform/buckets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC3B;AAkED;;GAEG;AACH,eAAO,MAAM,OAAO;IAClB;;;;OAIG;eACc,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAI1C,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Storage API wrapper.
|
|
3
|
+
* Provides a simplified interface for caching responses and assets.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Cache handle interface for managing cached resources.
|
|
7
|
+
*/
|
|
8
|
+
export interface CacheHandle {
|
|
9
|
+
/**
|
|
10
|
+
* Add a resource to the cache by URL.
|
|
11
|
+
* Fetches the resource and stores the response.
|
|
12
|
+
* @param url - URL to fetch and cache
|
|
13
|
+
*/
|
|
14
|
+
add(url: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Add multiple resources to the cache.
|
|
17
|
+
* @param urls - Array of URLs to fetch and cache
|
|
18
|
+
*/
|
|
19
|
+
addAll(urls: string[]): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Store a custom response in the cache.
|
|
22
|
+
* @param url - URL key for the cached response
|
|
23
|
+
* @param response - Response object to cache
|
|
24
|
+
*/
|
|
25
|
+
put(url: string, response: Response): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve a cached response.
|
|
28
|
+
* @param url - URL to look up
|
|
29
|
+
* @returns Cached Response or undefined if not found
|
|
30
|
+
*/
|
|
31
|
+
match(url: string): Promise<Response | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Remove a cached response.
|
|
34
|
+
* @param url - URL to remove from cache
|
|
35
|
+
* @returns True if the entry was deleted
|
|
36
|
+
*/
|
|
37
|
+
remove(url: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Get all cached request URLs.
|
|
40
|
+
* @returns Array of cached URLs
|
|
41
|
+
*/
|
|
42
|
+
keys(): Promise<string[]>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Cache manager for accessing the Cache Storage API.
|
|
46
|
+
*/
|
|
47
|
+
export declare const cache: {
|
|
48
|
+
/**
|
|
49
|
+
* Check if Cache Storage API is supported.
|
|
50
|
+
* @returns True if caches API is available
|
|
51
|
+
*/
|
|
52
|
+
isSupported(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Open or create a named cache.
|
|
55
|
+
* @param name - Cache name
|
|
56
|
+
* @returns CacheHandle for cache operations
|
|
57
|
+
*/
|
|
58
|
+
open(name: string): Promise<CacheHandle>;
|
|
59
|
+
/**
|
|
60
|
+
* Delete a named cache.
|
|
61
|
+
* @param name - Cache name to delete
|
|
62
|
+
* @returns True if the cache was deleted
|
|
63
|
+
*/
|
|
64
|
+
delete(name: string): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* List all cache names.
|
|
67
|
+
* @returns Array of cache names
|
|
68
|
+
*/
|
|
69
|
+
keys(): Promise<string[]>;
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/platform/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAElD;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtC;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC3B;AAkCD;;GAEG;AACH,eAAO,MAAM,KAAK;IAChB;;;OAGG;mBACY,OAAO;IAItB;;;;OAIG;eACc,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAQ9C;;;;OAIG;iBACgB,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAO5C;;;OAGG;YACW,OAAO,CAAC,MAAM,EAAE,CAAC;CAMhC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform module providing unified endpoints for web platform APIs.
|
|
3
|
+
* Offers consistent, promise-based interfaces with predictable errors.
|
|
4
|
+
*
|
|
5
|
+
* @module bquery/platform
|
|
6
|
+
*/
|
|
7
|
+
export { buckets } from './buckets';
|
|
8
|
+
export type { Bucket } from './buckets';
|
|
9
|
+
export { cache } from './cache';
|
|
10
|
+
export type { CacheHandle } from './cache';
|
|
11
|
+
export { notifications } from './notifications';
|
|
12
|
+
export type { NotificationOptions } from './notifications';
|
|
13
|
+
export { storage } from './storage';
|
|
14
|
+
export type { IndexedDBOptions, StorageAdapter } from './storage';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Notifications API wrapper.
|
|
3
|
+
* Provides a simplified interface for browser notifications.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Notification options matching the standard NotificationOptions interface.
|
|
7
|
+
*/
|
|
8
|
+
export interface NotificationOptions {
|
|
9
|
+
/** Body text of the notification */
|
|
10
|
+
body?: string;
|
|
11
|
+
/** Icon URL for the notification */
|
|
12
|
+
icon?: string;
|
|
13
|
+
/** Badge icon for mobile devices */
|
|
14
|
+
badge?: string;
|
|
15
|
+
/** Tag for grouping notifications */
|
|
16
|
+
tag?: string;
|
|
17
|
+
/** Whether to require user interaction */
|
|
18
|
+
requireInteraction?: boolean;
|
|
19
|
+
/** Vibration pattern for mobile devices */
|
|
20
|
+
vibrate?: number[];
|
|
21
|
+
/** Additional data attached to the notification */
|
|
22
|
+
data?: unknown;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Notifications manager providing a clean interface for web notifications.
|
|
26
|
+
*/
|
|
27
|
+
export declare const notifications: {
|
|
28
|
+
/**
|
|
29
|
+
* Check if notifications are supported.
|
|
30
|
+
* @returns True if Notification API is available
|
|
31
|
+
*/
|
|
32
|
+
isSupported(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get current permission status.
|
|
35
|
+
* @returns Current permission state
|
|
36
|
+
*/
|
|
37
|
+
getPermission(): NotificationPermission;
|
|
38
|
+
/**
|
|
39
|
+
* Request notification permission from the user.
|
|
40
|
+
* @returns Promise resolving to the permission result
|
|
41
|
+
*/
|
|
42
|
+
requestPermission(): Promise<NotificationPermission>;
|
|
43
|
+
/**
|
|
44
|
+
* Send a notification.
|
|
45
|
+
* Requires 'granted' permission.
|
|
46
|
+
* @param title - Notification title
|
|
47
|
+
* @param options - Optional notification settings
|
|
48
|
+
* @returns The Notification instance or null if not permitted
|
|
49
|
+
*/
|
|
50
|
+
send(title: string, options?: NotificationOptions): Notification | null;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=notifications.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifications.d.ts","sourceRoot":"","sources":["../../src/platform/notifications.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,mDAAmD;IACnD,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;IACxB;;;OAGG;mBACY,OAAO;IAItB;;;OAGG;qBACc,sBAAsB;IAKvC;;;OAGG;yBACwB,OAAO,CAAC,sBAAsB,CAAC;IAgB1D;;;;;;OAMG;gBACS,MAAM,YAAY,mBAAmB,GAAG,YAAY,GAAG,IAAI;CAaxE,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified storage adapters for web platform storage APIs.
|
|
3
|
+
* Provides a consistent, promise-based interface with predictable errors.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Common interface for all storage adapters.
|
|
7
|
+
* All methods return promises for a unified async API.
|
|
8
|
+
*/
|
|
9
|
+
export interface StorageAdapter {
|
|
10
|
+
/**
|
|
11
|
+
* Retrieve a value by key.
|
|
12
|
+
* @param key - The storage key
|
|
13
|
+
* @returns The stored value or null if not found
|
|
14
|
+
*/
|
|
15
|
+
get<T>(key: string): Promise<T | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Store a value by key.
|
|
18
|
+
* @param key - The storage key
|
|
19
|
+
* @param value - The value to store
|
|
20
|
+
*/
|
|
21
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Remove a value by key.
|
|
24
|
+
* @param key - The storage key
|
|
25
|
+
*/
|
|
26
|
+
remove(key: string): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Clear all stored values.
|
|
29
|
+
*/
|
|
30
|
+
clear(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all storage keys.
|
|
33
|
+
* @returns Array of all keys
|
|
34
|
+
*/
|
|
35
|
+
keys(): Promise<string[]>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* IndexedDB configuration options.
|
|
39
|
+
*/
|
|
40
|
+
export interface IndexedDBOptions {
|
|
41
|
+
/** Database name */
|
|
42
|
+
name: string;
|
|
43
|
+
/** Object store name */
|
|
44
|
+
store: string;
|
|
45
|
+
/** Database version (optional) */
|
|
46
|
+
version?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Storage factory providing access to different storage adapters.
|
|
50
|
+
*/
|
|
51
|
+
export declare const storage: {
|
|
52
|
+
/**
|
|
53
|
+
* Create a localStorage adapter.
|
|
54
|
+
* @returns StorageAdapter wrapping localStorage
|
|
55
|
+
*/
|
|
56
|
+
local(): StorageAdapter;
|
|
57
|
+
/**
|
|
58
|
+
* Create a sessionStorage adapter.
|
|
59
|
+
* @returns StorageAdapter wrapping sessionStorage
|
|
60
|
+
*/
|
|
61
|
+
session(): StorageAdapter;
|
|
62
|
+
/**
|
|
63
|
+
* Create an IndexedDB adapter with key-value interface.
|
|
64
|
+
* @param options - Database and store configuration
|
|
65
|
+
* @returns StorageAdapter wrapping IndexedDB
|
|
66
|
+
*/
|
|
67
|
+
indexedDB(options: IndexedDBOptions): StorageAdapter;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/platform/storage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAEvC;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7C;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC3B;AAuDD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA0ED;;GAEG;AACH,eAAO,MAAM,OAAO;IAClB;;;OAGG;aACM,cAAc;IAIvB;;;OAGG;eACQ,cAAc;IAIzB;;;;OAIG;uBACgB,gBAAgB,GAAG,cAAc;CAGrD,CAAC"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
class d {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
this.bucketName = e, this.dbPromise = null, this.storeName = "blobs";
|
|
4
|
+
}
|
|
5
|
+
openDB() {
|
|
6
|
+
if (this.dbPromise) return this.dbPromise;
|
|
7
|
+
const e = `bquery-bucket-${this.bucketName}`;
|
|
8
|
+
return this.dbPromise = new Promise((t, s) => {
|
|
9
|
+
const n = indexedDB.open(e, 1);
|
|
10
|
+
n.onupgradeneeded = () => {
|
|
11
|
+
const i = n.result;
|
|
12
|
+
i.objectStoreNames.contains(this.storeName) || i.createObjectStore(this.storeName);
|
|
13
|
+
}, n.onsuccess = () => t(n.result), n.onerror = () => s(n.error);
|
|
14
|
+
}), this.dbPromise;
|
|
15
|
+
}
|
|
16
|
+
async withStore(e, t) {
|
|
17
|
+
const s = await this.openDB();
|
|
18
|
+
return new Promise((n, i) => {
|
|
19
|
+
const a = s.transaction(this.storeName, e).objectStore(this.storeName), o = t(a);
|
|
20
|
+
o.onsuccess = () => n(o.result), o.onerror = () => i(o.error);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async put(e, t) {
|
|
24
|
+
await this.withStore("readwrite", (s) => s.put(t, e));
|
|
25
|
+
}
|
|
26
|
+
async get(e) {
|
|
27
|
+
return await this.withStore("readonly", (s) => s.get(e)) ?? null;
|
|
28
|
+
}
|
|
29
|
+
async remove(e) {
|
|
30
|
+
await this.withStore("readwrite", (t) => t.delete(e));
|
|
31
|
+
}
|
|
32
|
+
async keys() {
|
|
33
|
+
return (await this.withStore("readonly", (t) => t.getAllKeys())).map((t) => String(t));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const y = {
|
|
37
|
+
/**
|
|
38
|
+
* Open or create a storage bucket.
|
|
39
|
+
* @param name - Bucket name
|
|
40
|
+
* @returns Bucket instance for blob operations
|
|
41
|
+
*/
|
|
42
|
+
async open(r) {
|
|
43
|
+
return new d(r);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
class h {
|
|
47
|
+
constructor(e) {
|
|
48
|
+
this.cache = e;
|
|
49
|
+
}
|
|
50
|
+
async add(e) {
|
|
51
|
+
await this.cache.add(e);
|
|
52
|
+
}
|
|
53
|
+
async addAll(e) {
|
|
54
|
+
await this.cache.addAll(e);
|
|
55
|
+
}
|
|
56
|
+
async put(e, t) {
|
|
57
|
+
await this.cache.put(e, t);
|
|
58
|
+
}
|
|
59
|
+
async match(e) {
|
|
60
|
+
return this.cache.match(e);
|
|
61
|
+
}
|
|
62
|
+
async remove(e) {
|
|
63
|
+
return this.cache.delete(e);
|
|
64
|
+
}
|
|
65
|
+
async keys() {
|
|
66
|
+
return (await this.cache.keys()).map((t) => t.url);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const m = {
|
|
70
|
+
/**
|
|
71
|
+
* Check if Cache Storage API is supported.
|
|
72
|
+
* @returns True if caches API is available
|
|
73
|
+
*/
|
|
74
|
+
isSupported() {
|
|
75
|
+
return "caches" in window;
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Open or create a named cache.
|
|
79
|
+
* @param name - Cache name
|
|
80
|
+
* @returns CacheHandle for cache operations
|
|
81
|
+
*/
|
|
82
|
+
async open(r) {
|
|
83
|
+
if (!this.isSupported())
|
|
84
|
+
throw new Error("bQuery: Cache Storage API not supported");
|
|
85
|
+
const e = await caches.open(r);
|
|
86
|
+
return new h(e);
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Delete a named cache.
|
|
90
|
+
* @param name - Cache name to delete
|
|
91
|
+
* @returns True if the cache was deleted
|
|
92
|
+
*/
|
|
93
|
+
async delete(r) {
|
|
94
|
+
return this.isSupported() ? caches.delete(r) : !1;
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* List all cache names.
|
|
98
|
+
* @returns Array of cache names
|
|
99
|
+
*/
|
|
100
|
+
async keys() {
|
|
101
|
+
return this.isSupported() ? caches.keys() : [];
|
|
102
|
+
}
|
|
103
|
+
}, S = {
|
|
104
|
+
/**
|
|
105
|
+
* Check if notifications are supported.
|
|
106
|
+
* @returns True if Notification API is available
|
|
107
|
+
*/
|
|
108
|
+
isSupported() {
|
|
109
|
+
return "Notification" in window;
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Get current permission status.
|
|
113
|
+
* @returns Current permission state
|
|
114
|
+
*/
|
|
115
|
+
getPermission() {
|
|
116
|
+
return this.isSupported() ? Notification.permission : "denied";
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Request notification permission from the user.
|
|
120
|
+
* @returns Promise resolving to the permission result
|
|
121
|
+
*/
|
|
122
|
+
async requestPermission() {
|
|
123
|
+
return this.isSupported() ? Notification.permission === "granted" ? "granted" : Notification.permission === "denied" ? "denied" : Notification.requestPermission() : "denied";
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Send a notification.
|
|
127
|
+
* Requires 'granted' permission.
|
|
128
|
+
* @param title - Notification title
|
|
129
|
+
* @param options - Optional notification settings
|
|
130
|
+
* @returns The Notification instance or null if not permitted
|
|
131
|
+
*/
|
|
132
|
+
send(r, e) {
|
|
133
|
+
return this.isSupported() ? Notification.permission !== "granted" ? (console.warn("bQuery: Notification permission not granted"), null) : new Notification(r, e) : (console.warn("bQuery: Notifications not supported in this browser"), null);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
class c {
|
|
137
|
+
constructor(e) {
|
|
138
|
+
this.storage = e;
|
|
139
|
+
}
|
|
140
|
+
async get(e) {
|
|
141
|
+
const t = this.storage.getItem(e);
|
|
142
|
+
if (t === null) return null;
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(t);
|
|
145
|
+
} catch {
|
|
146
|
+
return t;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async set(e, t) {
|
|
150
|
+
const s = typeof t == "string" ? t : JSON.stringify(t);
|
|
151
|
+
this.storage.setItem(e, s);
|
|
152
|
+
}
|
|
153
|
+
async remove(e) {
|
|
154
|
+
this.storage.removeItem(e);
|
|
155
|
+
}
|
|
156
|
+
async clear() {
|
|
157
|
+
this.storage.clear();
|
|
158
|
+
}
|
|
159
|
+
async keys() {
|
|
160
|
+
return Object.keys(this.storage);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
class l extends c {
|
|
164
|
+
constructor() {
|
|
165
|
+
super(localStorage);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
class p extends c {
|
|
169
|
+
constructor() {
|
|
170
|
+
super(sessionStorage);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
class w {
|
|
174
|
+
constructor(e) {
|
|
175
|
+
this.options = e, this.dbPromise = null;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Opens or creates the IndexedDB database.
|
|
179
|
+
*/
|
|
180
|
+
openDB() {
|
|
181
|
+
return this.dbPromise ? this.dbPromise : (this.dbPromise = new Promise((e, t) => {
|
|
182
|
+
const s = indexedDB.open(this.options.name, this.options.version ?? 1);
|
|
183
|
+
s.onupgradeneeded = () => {
|
|
184
|
+
const n = s.result;
|
|
185
|
+
n.objectStoreNames.contains(this.options.store) || n.createObjectStore(this.options.store);
|
|
186
|
+
}, s.onsuccess = () => e(s.result), s.onerror = () => t(s.error);
|
|
187
|
+
}), this.dbPromise);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Executes a transaction on the object store.
|
|
191
|
+
*/
|
|
192
|
+
async withStore(e, t) {
|
|
193
|
+
const s = await this.openDB();
|
|
194
|
+
return new Promise((n, i) => {
|
|
195
|
+
const a = s.transaction(this.options.store, e).objectStore(this.options.store), o = t(a);
|
|
196
|
+
o.onsuccess = () => n(o.result), o.onerror = () => i(o.error);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async get(e) {
|
|
200
|
+
return await this.withStore("readonly", (s) => s.get(e)) ?? null;
|
|
201
|
+
}
|
|
202
|
+
async set(e, t) {
|
|
203
|
+
await this.withStore("readwrite", (s) => s.put(t, e));
|
|
204
|
+
}
|
|
205
|
+
async remove(e) {
|
|
206
|
+
await this.withStore("readwrite", (t) => t.delete(e));
|
|
207
|
+
}
|
|
208
|
+
async clear() {
|
|
209
|
+
await this.withStore("readwrite", (e) => e.clear());
|
|
210
|
+
}
|
|
211
|
+
async keys() {
|
|
212
|
+
return (await this.withStore("readonly", (t) => t.getAllKeys())).map((t) => String(t));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const b = {
|
|
216
|
+
/**
|
|
217
|
+
* Create a localStorage adapter.
|
|
218
|
+
* @returns StorageAdapter wrapping localStorage
|
|
219
|
+
*/
|
|
220
|
+
local() {
|
|
221
|
+
return new l();
|
|
222
|
+
},
|
|
223
|
+
/**
|
|
224
|
+
* Create a sessionStorage adapter.
|
|
225
|
+
* @returns StorageAdapter wrapping sessionStorage
|
|
226
|
+
*/
|
|
227
|
+
session() {
|
|
228
|
+
return new p();
|
|
229
|
+
},
|
|
230
|
+
/**
|
|
231
|
+
* Create an IndexedDB adapter with key-value interface.
|
|
232
|
+
* @param options - Database and store configuration
|
|
233
|
+
* @returns StorageAdapter wrapping IndexedDB
|
|
234
|
+
*/
|
|
235
|
+
indexedDB(r) {
|
|
236
|
+
return new w(r);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export {
|
|
240
|
+
y as buckets,
|
|
241
|
+
m as cache,
|
|
242
|
+
S as notifications,
|
|
243
|
+
b as storage
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=platform.es.mjs.map
|