universe-code 0.0.64 โ†’ 0.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@ An opinionated npm package that enforces coding discipline by standardizing stru
3
3
  ## Documentation
4
4
 
5
5
  ๐Ÿ“ฆ IndexedDB Angular
6
- ๐Ÿ‘‰ [View Docs](https://github.com/connectwithfalco/universe-code/tree/main/doc/angular/indexdb)
6
+ ๐Ÿ‘‰ [View Docs](https://github.com/connectwithfalco/universe-code/tree/main/dist/guide/angular/indexdb)
7
7
 
8
8
  ๐Ÿ“ฆ IndexedDB React
9
- ๐Ÿ‘‰ [View Docs](https://github.com/connectwithfalco/universe-code/tree/main/doc/react/indexdb)
9
+ ๐Ÿ‘‰ [View Docs](https://github.com/connectwithfalco/universe-code/tree/main/dist/guide/react/indexdb)
@@ -0,0 +1,190 @@
1
+ # ๐ŸŒŒ universe-code (Angular)
2
+
3
+ A lightweight and powerful **IndexedDB utility for Angular** that helps you cache API responses, manage offline storage, and reduce unnecessary network calls โ€” with a **clean, service-based API**.
4
+
5
+ Designed for **modern Angular (standalone + DI)** and production-ready applications.
6
+
7
+ ---
8
+
9
+ ## โœจ Features
10
+
11
+ * โšก Easy IndexedDB configuration
12
+ * ๐Ÿง  Built-in API caching with expiry
13
+ * ๐Ÿ“ฆ Simple CRUD helpers
14
+ * ๐Ÿ” Auto refresh when cache expires
15
+ * ๐Ÿงฉ Angular Dependency Injection support
16
+ * ๐Ÿ›  Clean & professional service-based API
17
+
18
+ ---
19
+
20
+ ## ๐Ÿ“ฆ Installation
21
+
22
+ Install the latest version using npm:
23
+
24
+ ```bash
25
+ npm install universe-code@latest
26
+ ```
27
+
28
+ ---
29
+
30
+ ## โš™๏ธ IndexedDB Setup (One Time Only)
31
+
32
+ IndexedDB should be initialized **once at application bootstrap level**.
33
+
34
+ ---
35
+
36
+ ## 1๏ธโƒฃ Import Angular Compiler (Required)
37
+
38
+ `universe-code` internally uses Angular decorators and DI.
39
+ For JIT environments, Angular Compiler **must be available**.
40
+
41
+ ๐Ÿ“ `main.ts`
42
+
43
+ ```ts
44
+ import '@angular/compiler';
45
+ import { bootstrapApplication } from '@angular/platform-browser';
46
+ import { appConfig } from './app/app.config';
47
+ import { App } from './app/app';
48
+
49
+ bootstrapApplication(App, appConfig)
50
+ .catch(console.error);
51
+ ```
52
+
53
+ > โš ๏ธ **Note:**
54
+ > This avoids `JIT compilation failed for injectable class` errors.
55
+
56
+ ---
57
+
58
+ ## 2๏ธโƒฃ Import the IndexedDB Service
59
+
60
+ `IdbService` is provided via Angular DI and requires **no manual provider setup**.
61
+
62
+ ```ts
63
+ import { IdbService } from 'universe-code/angular';
64
+ ```
65
+
66
+ ---
67
+
68
+ ## ๐Ÿš€ Using IndexedDB in Angular Components
69
+
70
+ Inject the service inside any component or service.
71
+
72
+ ๐Ÿ“ `app.ts`
73
+
74
+ ```ts
75
+ import { Component, OnInit } from '@angular/core';
76
+ import { IdbService } from 'universe-code/angular';
77
+
78
+ @Component({
79
+ selector: 'app-root',
80
+ template: `<h1>Angular App</h1>`,
81
+ })
82
+ export class App implements OnInit {
83
+
84
+ constructor(private idb: IdbService) {}
85
+
86
+ async ngOnInit() {
87
+ const data = await this.idb.fetchWithCache(
88
+ 'example-key',
89
+ 60_000, // cache expiry in ms
90
+ async () => {
91
+ const res = await fetch('https://example.com/api/data');
92
+ return res.json();
93
+ }
94
+ );
95
+
96
+ console.log(data);
97
+ }
98
+ }
99
+ ```
100
+
101
+ ---
102
+
103
+ ## ๐Ÿ” Fetch API Data with Cache + Expiry
104
+
105
+ ```ts
106
+ const result = await idb.fetchWithCache(
107
+ 'users',
108
+ 5 * 60 * 1000,
109
+ async () => {
110
+ const res = await fetch('/api/users');
111
+ return res.json();
112
+ }
113
+ );
114
+ ```
115
+
116
+ ### ๐Ÿง  How it Works
117
+
118
+ * Checks IndexedDB for cached data
119
+ * Validates expiry timestamp
120
+ * Calls API only if cache is missing or expired
121
+ * Stores fresh data automatically
122
+ * Returns cached data instantly on next call
123
+
124
+ ---
125
+
126
+ ## ๐Ÿ“ฅ Get Cached Data Only
127
+
128
+ ```ts
129
+ const data = await idb.get('users');
130
+ ```
131
+
132
+ ---
133
+
134
+ ## โœ๏ธ Insert / Update Data Manually
135
+
136
+ ```ts
137
+ await idb.put({
138
+ id: 'profile',
139
+ data: {
140
+ name: 'John',
141
+ role: 'Admin',
142
+ },
143
+ timestamp: Date.now(),
144
+ });
145
+ ```
146
+
147
+ ---
148
+
149
+ ## ๐Ÿ—‘๏ธ Remove a Specific Record
150
+
151
+ ```ts
152
+ await idb.remove('profile');
153
+ ```
154
+
155
+ ---
156
+
157
+ ## ๐Ÿงน Clear Entire IndexedDB Store
158
+
159
+ ```ts
160
+ await idb.clear();
161
+ ```
162
+
163
+ ---
164
+
165
+ ## ๐Ÿ“š API Reference
166
+
167
+ | Method | Description |
168
+ | -------------------------------------- | ---------------------------- |
169
+ | `get(id)` | Retrieve data from IndexedDB |
170
+ | `put(payload)` | Insert or update data |
171
+ | `remove(id)` | Delete a specific record |
172
+ | `clear()` | Clear entire IndexedDB |
173
+ | `fetchWithCache(id, expiry, callback)` | Fetch + cache with expiry |
174
+
175
+ ---
176
+
177
+ ## โœ… Ideal Use Cases
178
+
179
+ * API response caching
180
+ * Offline-first Angular apps
181
+ * Performance optimization
182
+ * Reducing repeated network calls
183
+ * Storing session-level data
184
+
185
+ ---
186
+
187
+ ## ๐Ÿ›ก License
188
+
189
+ MIT License ยฉ universe-code
190
+
@@ -0,0 +1,198 @@
1
+ # ๐ŸŒŒ universe-code (React)
2
+
3
+ A lightweight and powerful **IndexedDB utility for React** that helps you cache API data, manage offline storage, and reduce unnecessary network calls โ€” all with a clean and simple API.
4
+
5
+ ---
6
+
7
+ ## โœจ Features
8
+
9
+ - โšก Easy IndexedDB setup
10
+ - ๐Ÿง  Built-in API caching with expiry
11
+ - ๐Ÿ“ฆ Simple CRUD operations
12
+ - ๐Ÿ” Auto re-fetch when cache expires
13
+ - ๐Ÿ’ป Works perfectly with React / Next.js
14
+ - ๐Ÿ›  Clean and developer-friendly API
15
+
16
+ ---
17
+
18
+ ## ๐Ÿ“ฆ Installation
19
+
20
+ Install the latest version using npm:
21
+
22
+ ```bash
23
+ npm install universe-code@latest
24
+ ```
25
+ ---
26
+
27
+ ## โš™๏ธ IndexedDB Setup (One Time Only)
28
+
29
+ You must configure IndexedDB once at the root level of your app.
30
+
31
+ ---
32
+
33
+ ## 1๏ธโƒฃ Create IndexedDB Provider
34
+
35
+ Create the following file:
36
+
37
+ ๐Ÿ“ lib/provider/idb-provider.tsx
38
+
39
+ ```bash
40
+ "use client";
41
+
42
+ import { configureIdb } from "universe-code/react";
43
+
44
+ export function IdbProvider() {
45
+ configureIdb({
46
+ dbName: "db",
47
+ dbVersion: 1,
48
+ storeName: "store",
49
+ });
50
+
51
+ return null;
52
+ }
53
+ ```
54
+
55
+ ---
56
+
57
+ ### 2๏ธโƒฃ Register Provider in Root Layout
58
+
59
+ Call the provider once so IndexedDB initializes globally.
60
+
61
+ ```bash
62
+ import { IdbProvider } from "@/lib/provider/idb-provider";
63
+
64
+ export default function RootLayout({
65
+ children,
66
+ }: {
67
+ children: React.ReactNode;
68
+ }) {
69
+ return (
70
+ <html lang="en">
71
+ <body>
72
+ <IdbProvider />
73
+ {children}
74
+ </body>
75
+ </html>
76
+ );
77
+ }
78
+ ```
79
+
80
+ ---
81
+
82
+ ## โœ… IndexedDB is now created and ready to use.
83
+
84
+ ๐Ÿš€ Using IndexedDB in Components
85
+ Import the Hook
86
+
87
+ ```bash
88
+ import { useIdbStore } from "universe-code/react";
89
+ ```
90
+
91
+ Initialize Store
92
+
93
+ ```bash
94
+ const idbStore = useIdbStore();
95
+ ```
96
+
97
+ All IndexedDB helper functions are now available inside idbStore.
98
+
99
+ ---
100
+
101
+ ## ๐Ÿ” API Fetch + Cache with Expiry
102
+
103
+ Fetch API data and automatically store it in IndexedDB with expiry control.
104
+
105
+ ```bash
106
+ idbStore
107
+ .getWithExpiry("users", minutesToMs(1), async () => {
108
+ const res = await fetch("https://example.com/api/user", {
109
+ method: "GET",
110
+ headers: {
111
+ "Content-Type": "application/json",
112
+ },
113
+ });
114
+
115
+ const data = await res.json();
116
+ return data.data;
117
+ })
118
+ .then(console.log);
119
+ ```
120
+ ### Note:
121
+
122
+ import minutesToMs() from universe-code/core
123
+
124
+ ```bash
125
+ import { minutesToMs } from "universe-code/core";
126
+ ```
127
+
128
+ ### ๐Ÿง  How it works
129
+
130
+ - Calls API only if data is missing or expired
131
+ - Saves response in IndexedDB
132
+ - Returns cached data instantly on next call
133
+
134
+ ---
135
+
136
+ ## ๐Ÿ“ฅ Get Data from IndexedDB
137
+ ```bash
138
+ const data = await idbStore.get("users");
139
+ console.log(data);
140
+ ```
141
+
142
+ ---
143
+
144
+ ## โœ๏ธ Insert / Update Data
145
+ ```bash
146
+ idbStore.put({
147
+ id: "users",
148
+ data: {
149
+ name: "Mark",
150
+ country: "USA",
151
+ },
152
+ timestamp: Date.now(),
153
+ });
154
+ ```
155
+
156
+ ---
157
+
158
+ ### ๐Ÿ—‘๏ธ Delete a Specific Record
159
+
160
+ ```bash
161
+ idbStore.remove("users");
162
+ ```
163
+
164
+ ---
165
+
166
+ ## ๐Ÿงน Clear Entire IndexedDB Store
167
+
168
+ ```bash
169
+ idbStore.clear();
170
+ ```
171
+
172
+ ---
173
+
174
+ ### ๐Ÿ“š API Reference
175
+
176
+ | Function | Description |
177
+ |---------|------------|
178
+ | `get(id)` | Retrieve data from IndexedDB |
179
+ | `put(payload)` | Insert or update data |
180
+ | `remove(id)` | Delete a record |
181
+ | `clear()` | Clear all IndexedDB data |
182
+ | `getWithExpiry(id, expiry, callback)` | Fetch and cache data with expiry |
183
+
184
+ ---
185
+
186
+ ## โœ… Ideal Use Cases
187
+
188
+ - API response caching
189
+ - Offline-first applications
190
+ - Performance optimization
191
+ - Reducing repeated API calls
192
+ - Storing session or user data
193
+
194
+ ---
195
+
196
+ ## ๐Ÿ›ก License
197
+
198
+ MIT License ยฉ universe-code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universe-code",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "Universal utility functions for all JS frameworks",
5
5
  "license": "ISC",
6
6
  "type": "module",