@maravilla-labs/platform 0.1.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.
@@ -0,0 +1,111 @@
1
+ # JSDoc Enhancement Summary
2
+
3
+ ## 📋 What Was Added
4
+
5
+ ### 1. Comprehensive Interface Documentation (`types.ts`)
6
+
7
+ **KvNamespace Interface:**
8
+ - ✅ Detailed method descriptions with parameter explanations
9
+ - ✅ Practical usage examples for each method
10
+ - ✅ Parameter options documentation
11
+ - ✅ Return type explanations
12
+
13
+ **Database Interface:**
14
+ - ✅ MongoDB-style API documentation
15
+ - ✅ Query filter examples
16
+ - ✅ Update operator documentation
17
+ - ✅ Error handling guidance
18
+
19
+ **Supporting Types:**
20
+ - ✅ KvListResult with pagination details
21
+ - ✅ DbFindOptions with sorting examples
22
+ - ✅ PlatformEnv usage patterns
23
+
24
+ ### 2. Enhanced Function Documentation (`index.ts`)
25
+
26
+ **getPlatform():**
27
+ - ✅ Environment detection explanation
28
+ - ✅ Configuration options documentation
29
+ - ✅ Complete usage examples
30
+ - ✅ Development vs production scenarios
31
+
32
+ **clearPlatformCache():**
33
+ - ✅ Testing utility documentation
34
+ - ✅ Use case explanations
35
+ - ✅ Practical examples
36
+
37
+ ### 3. Internal API Documentation (`remote-client.ts`)
38
+
39
+ **RemoteKvNamespace & RemoteDatabase:**
40
+ - ✅ Internal implementation details marked with @internal
41
+ - ✅ HTTP client documentation
42
+ - ✅ Error handling patterns
43
+
44
+ **createRemoteClient():**
45
+ - ✅ Development server integration docs
46
+ - ✅ Multi-tenancy support explanation
47
+
48
+ ### 4. Package Documentation
49
+
50
+ **File Header:**
51
+ - ✅ Comprehensive package overview
52
+ - ✅ Environment detection explanation
53
+ - ✅ Feature highlights
54
+ - ✅ Quick start examples
55
+
56
+ ### 5. Additional Resources
57
+
58
+ **JSDOC_GUIDE.md:**
59
+ - ✅ IDE integration instructions
60
+ - ✅ Feature explanations
61
+ - ✅ Usage patterns
62
+ - ✅ Documentation generation guide
63
+
64
+ **example-usage.ts:**
65
+ - ✅ Practical implementation examples
66
+ - ✅ JSDoc feature demonstrations
67
+ - ✅ Error handling patterns
68
+
69
+ **Updated README.md:**
70
+ - ✅ JSDoc feature highlights
71
+ - ✅ IDE integration information
72
+ - ✅ Enhanced developer experience section
73
+
74
+ ## 🎯 Developer Experience Improvements
75
+
76
+ ### IDE Features Now Available:
77
+ 1. **Hover Documentation**: Detailed explanations appear on hover
78
+ 2. **Parameter IntelliSense**: Parameter descriptions while typing
79
+ 3. **Auto-completion**: Enhanced suggestions with descriptions
80
+ 4. **Example Code**: Practical examples in documentation
81
+ 5. **Error Context**: Understanding of error scenarios
82
+ 6. **Type Safety**: Combined TypeScript + JSDoc validation
83
+
84
+ ### Supported IDEs:
85
+ - ✅ VS Code (full integration)
86
+ - ✅ WebStorm/IntelliJ (full integration)
87
+ - ✅ Any TypeScript-compatible editor
88
+
89
+ ### Real-world Examples Added:
90
+ - ✅ KV storage patterns (caching, sessions, configuration)
91
+ - ✅ Database operations (CRUD, queries, aggregation)
92
+ - ✅ Multi-tenancy usage
93
+ - ✅ Error handling patterns
94
+ - ✅ Testing scenarios
95
+
96
+ ## 🔧 Technical Fixes
97
+
98
+ - ✅ Fixed TypeScript type assertion issues in remote-client.ts
99
+ - ✅ Added proper return type annotations
100
+ - ✅ Improved error handling documentation
101
+ - ✅ Enhanced parameter validation docs
102
+
103
+ ## 🚀 Impact
104
+
105
+ Developers using this package will now get:
106
+ - **Better onboarding**: Clear examples and explanations
107
+ - **Fewer errors**: Understanding of proper usage patterns
108
+ - **Faster development**: IDE assistance while coding
109
+ - **Better maintenance**: Clear API contracts and examples
110
+
111
+ The JSDoc comments provide a complete reference without leaving the IDE, making the development experience much more streamlined and professional.
package/JSDOC_GUIDE.md ADDED
@@ -0,0 +1,98 @@
1
+ # JSDoc Documentation Guide
2
+
3
+ This package now includes comprehensive JSDoc comments for enhanced developer experience in IDEs.
4
+
5
+ ## IDE Integration
6
+
7
+ ### VS Code
8
+ The JSDoc comments will automatically provide:
9
+ - **Hover tooltips** with detailed descriptions
10
+ - **IntelliSense suggestions** with parameter descriptions
11
+ - **Type information** and examples
12
+ - **Parameter hints** while typing function calls
13
+
14
+ ### WebStorm/IntelliJ
15
+ - Full JSDoc integration with type hints
16
+ - Parameter documentation in completion popups
17
+ - Hover documentation
18
+
19
+ ### Other TypeScript-compatible IDEs
20
+ Most modern IDEs that support TypeScript will display the JSDoc information.
21
+
22
+ ## What's Included
23
+
24
+ ### Function Documentation
25
+ - **Purpose**: Clear description of what each function does
26
+ - **Parameters**: Detailed parameter descriptions with types
27
+ - **Return values**: What the function returns
28
+ - **Examples**: Practical usage examples
29
+ - **Error handling**: When functions might throw errors
30
+
31
+ ### Interface Documentation
32
+ - **Property descriptions**: What each property represents
33
+ - **Usage examples**: How to use the interfaces
34
+ - **Relationships**: How interfaces relate to each other
35
+
36
+ ### Examples in JSDoc
37
+ Each major function includes practical examples showing:
38
+ - Basic usage
39
+ - Advanced scenarios
40
+ - Error handling
41
+ - Best practices
42
+
43
+ ## Using the Documentation
44
+
45
+ ### Getting Platform Instance
46
+ ```typescript
47
+ import { getPlatform } from '@maravilla/platform';
48
+
49
+ // Hover over getPlatform to see full documentation
50
+ const platform = getPlatform({
51
+ devServerUrl: 'http://localhost:3001',
52
+ tenant: 'my-app'
53
+ });
54
+ ```
55
+
56
+ ### KV Operations
57
+ ```typescript
58
+ // Hover over any method to see documentation
59
+ await platform.env.KV.cache.put('key', 'value', {
60
+ expirationTtl: 3600 // See JSDoc for TTL details
61
+ });
62
+
63
+ const value = await platform.env.KV.cache.get('key');
64
+ ```
65
+
66
+ ### Database Operations
67
+ ```typescript
68
+ // Full documentation available in IDE
69
+ const result = await platform.env.DB.insertOne('users', {
70
+ name: 'John Doe',
71
+ email: 'john@example.com'
72
+ });
73
+
74
+ // See parameter documentation while typing
75
+ const users = await platform.env.DB.find('users',
76
+ { active: true },
77
+ { limit: 10, sort: { createdAt: -1 } }
78
+ );
79
+ ```
80
+
81
+ ## IDE Features Enabled
82
+
83
+ 1. **Parameter IntelliSense**: As you type function parameters, see descriptions
84
+ 2. **Hover Documentation**: Hover over any function/method for full docs
85
+ 3. **Auto-completion**: Better suggestions with descriptions
86
+ 4. **Type Safety**: Combined with TypeScript for full type checking
87
+ 5. **Examples**: See practical examples right in your IDE
88
+
89
+ ## Building Documentation
90
+
91
+ If you want to generate HTML documentation from the JSDoc comments:
92
+
93
+ ```bash
94
+ npm install -g typedoc
95
+ typedoc src/index.ts --out docs
96
+ ```
97
+
98
+ This will generate browsable HTML documentation from the JSDoc comments.
package/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # @maravilla/platform
2
+
3
+ Universal platform client for Maravilla Runtime that provides seamless access to KV, Database, and other platform services in both development and production environments.
4
+
5
+ ## 🎯 Enhanced Developer Experience
6
+
7
+ This package includes **comprehensive JSDoc documentation** for enhanced IDE support:
8
+ - **IntelliSense** with detailed parameter descriptions
9
+ - **Hover tooltips** with examples and usage guidance
10
+ - **Type hints** with real-world examples
11
+ - **Auto-completion** with contextual help
12
+
13
+ > 💡 **IDE Integration**: Works with VS Code, WebStorm, and any TypeScript-compatible editor
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @maravilla/platform
19
+ # or
20
+ pnpm add @maravilla/platform
21
+ # or
22
+ yarn add @maravilla/platform
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Basic Setup
28
+
29
+ ```typescript
30
+ import { getPlatform } from '@maravilla/platform';
31
+
32
+ // Auto-detects environment (dev/prod)
33
+ const platform = getPlatform();
34
+
35
+ // Access platform services
36
+ const { KV, DB } = platform.env;
37
+ ```
38
+
39
+ ### Development Mode
40
+
41
+ In development, the client automatically connects to the Maravilla dev server running on port 3001. Make sure to start the dev server first:
42
+
43
+ ```bash
44
+ # Start the dev server
45
+ maravilla dev --port 3001
46
+
47
+ # In another terminal, start your app
48
+ npm run dev
49
+ ```
50
+
51
+ ### Production Mode
52
+
53
+ In production, the platform client is injected by the Maravilla runtime automatically. No configuration needed.
54
+
55
+ ## API Reference
56
+
57
+ ### KV Store
58
+
59
+ Key-Value store for caching and simple data storage.
60
+
61
+ ```typescript
62
+ // Get a value
63
+ const value = await platform.env.KV.get('my-key');
64
+
65
+ // Set a value with optional TTL (in seconds)
66
+ await platform.env.KV.put('my-key', 'my-value', {
67
+ expirationTtl: 3600, // Expires in 1 hour
68
+ });
69
+
70
+ // Delete a value
71
+ await platform.env.KV.delete('my-key');
72
+
73
+ // List keys with optional prefix
74
+ const keys = await platform.env.KV.list({
75
+ prefix: 'user:',
76
+ limit: 100,
77
+ cursor: 'optional-cursor-for-pagination',
78
+ });
79
+ ```
80
+
81
+ ### Database (MongoDB-style API)
82
+
83
+ Document database with MongoDB-compatible query and update operators.
84
+
85
+ #### Query Operations
86
+
87
+ ```typescript
88
+ // Find multiple documents
89
+ const users = await platform.env.DB.find('users', {
90
+ active: true,
91
+ age: { $gte: 18 },
92
+ });
93
+
94
+ // Find single document
95
+ const user = await platform.env.DB.findOne('users', {
96
+ _id: 'user-123',
97
+ });
98
+
99
+ // With options (limit, skip, sort)
100
+ const posts = await platform.env.DB.find('posts',
101
+ { published: true },
102
+ {
103
+ limit: 10,
104
+ skip: 20,
105
+ sort: { createdAt: -1 },
106
+ }
107
+ );
108
+ ```
109
+
110
+ #### Insert Operations
111
+
112
+ ```typescript
113
+ // Insert single document
114
+ const result = await platform.env.DB.insertOne('users', {
115
+ name: 'John Doe',
116
+ email: 'john@example.com',
117
+ createdAt: new Date(),
118
+ });
119
+ console.log(result.insertedId); // Generated ID
120
+
121
+ // Insert multiple documents
122
+ const results = await platform.env.DB.insertMany('users', [
123
+ { name: 'Alice', email: 'alice@example.com' },
124
+ { name: 'Bob', email: 'bob@example.com' },
125
+ ]);
126
+ console.log(results.insertedIds); // Array of IDs
127
+ ```
128
+
129
+ #### Update Operations
130
+
131
+ ```typescript
132
+ // Update single document
133
+ await platform.env.DB.updateOne('users',
134
+ { _id: 'user-123' },
135
+ {
136
+ $set: { name: 'Updated Name' },
137
+ $inc: { loginCount: 1 },
138
+ $push: { tags: 'new-tag' },
139
+ }
140
+ );
141
+
142
+ // Update multiple documents
143
+ await platform.env.DB.updateMany('users',
144
+ { status: 'pending' },
145
+ { $set: { status: 'active' } }
146
+ );
147
+ ```
148
+
149
+ ##### Supported Update Operators
150
+
151
+ - `$set` - Set field values
152
+ - `$unset` - Remove fields
153
+ - `$inc` - Increment numeric values
154
+ - `$push` - Add to array
155
+ - `$pull` - Remove from array
156
+ - `$addToSet` - Add unique value to array
157
+
158
+ #### Delete Operations
159
+
160
+ ```typescript
161
+ // Delete single document
162
+ await platform.env.DB.deleteOne('users', {
163
+ _id: 'user-123',
164
+ });
165
+
166
+ // Delete multiple documents
167
+ const result = await platform.env.DB.deleteMany('users', {
168
+ inactive: true,
169
+ lastLogin: { $lt: thirtyDaysAgo },
170
+ });
171
+ console.log(result.deletedCount);
172
+ ```
173
+
174
+ ### Storage (Coming Soon)
175
+
176
+ Object storage for files and large data.
177
+
178
+ ```typescript
179
+ // Future API
180
+ await platform.env.STORAGE.put('file-key', buffer);
181
+ const file = await platform.env.STORAGE.get('file-key');
182
+ await platform.env.STORAGE.delete('file-key');
183
+ ```
184
+
185
+ ## Environment Detection
186
+
187
+ The client automatically detects the environment:
188
+
189
+ 1. **Development**: When `MARAVILLA_DEV_SERVER` env var is set (automatically set by vite-plugin)
190
+ 2. **Production**: When running inside Maravilla runtime (global `__MARAVILLA_PLATFORM__` is available)
191
+ 3. **Fallback**: Returns a mock platform for testing
192
+
193
+ ## TypeScript Support
194
+
195
+ Full TypeScript support with comprehensive JSDoc documentation:
196
+
197
+ ```typescript
198
+ import type { Platform, KVNamespace, Database } from '@maravilla/platform';
199
+
200
+ function myFunction(platform: Platform) {
201
+ const kv: KVNamespace = platform.env.KV;
202
+ const db: Database = platform.env.DB;
203
+
204
+ // Hover over any method to see detailed documentation
205
+ // Get parameter hints as you type
206
+ }
207
+ ```
208
+
209
+ ### IDE Features
210
+ - **Parameter IntelliSense**: See parameter descriptions while typing
211
+ - **Method Documentation**: Hover for detailed explanations and examples
212
+ - **Type Safety**: Full TypeScript integration with runtime type checking
213
+ - **Error Context**: Understand what errors might be thrown and when
214
+
215
+ > 📖 **See [JSDOC_GUIDE.md](./JSDOC_GUIDE.md) for detailed IDE integration information**
216
+
217
+ ## Framework Integration
218
+
219
+ ### SvelteKit
220
+
221
+ ```typescript
222
+ // src/routes/+page.server.ts
223
+ import { getPlatform } from '@maravilla/platform';
224
+
225
+ export async function load() {
226
+ const platform = getPlatform();
227
+ const data = await platform.env.KV.get('my-data');
228
+
229
+ return {
230
+ data: data ? JSON.parse(data) : null,
231
+ };
232
+ }
233
+ ```
234
+
235
+ ### Nuxt (Coming Soon)
236
+
237
+ ```typescript
238
+ // server/api/data.ts
239
+ export default defineEventHandler(async (event) => {
240
+ const platform = getPlatform();
241
+ const data = await platform.env.DB.find('items', {});
242
+ return data;
243
+ });
244
+ ```
245
+
246
+ ### Next.js (Coming Soon)
247
+
248
+ ```typescript
249
+ // app/api/route.ts
250
+ import { getPlatform } from '@maravilla/platform';
251
+
252
+ export async function GET() {
253
+ const platform = getPlatform();
254
+ const value = await platform.env.KV.get('key');
255
+ return Response.json({ value });
256
+ }
257
+ ```
258
+
259
+ ## Error Handling
260
+
261
+ All methods throw errors that should be handled:
262
+
263
+ ```typescript
264
+ try {
265
+ const data = await platform.env.KV.get('key');
266
+ } catch (error) {
267
+ console.error('Failed to get KV value:', error);
268
+ // Handle error appropriately
269
+ }
270
+ ```
271
+
272
+ ## Development Tips
273
+
274
+ 1. **Start Dev Server First**: Always start `maravilla dev` before your app dev server
275
+ 2. **Use Namespaces**: Prefix your KV keys to avoid collisions (e.g., `user:123`, `cache:api:...`)
276
+ 3. **Handle Missing Data**: Always check for null/undefined when getting values
277
+ 4. **Use TTL**: Set expiration for cache entries to avoid stale data
278
+ 5. **Batch Operations**: Use `insertMany`/`updateMany` for better performance
279
+
280
+ ## License
281
+
282
+ Proprietary. © 2025 SOLUTAS GmbH, Switzerland. All rights reserved.
283
+ Use is governed by the root LICENSE file or a separate written agreement
284
+ with SOLUTAS GmbH.