@fjell/registry 4.4.52 → 4.4.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +4 -4
  2. package/API.md +0 -62
  3. package/GETTING_STARTED.md +0 -69
  4. package/build.js +0 -38
  5. package/docs/README.md +0 -74
  6. package/docs/TIMING_NODE_OPTIMIZATION.md +0 -207
  7. package/docs/TIMING_README.md +0 -170
  8. package/docs/docs.config.ts +0 -114
  9. package/docs/index.html +0 -26
  10. package/docs/package-lock.json +0 -5129
  11. package/docs/package.json +0 -34
  12. package/docs/public/404.html +0 -53
  13. package/docs/public/GETTING_STARTED.md +0 -69
  14. package/docs/public/README.md +0 -623
  15. package/docs/public/TIMING_NODE_OPTIMIZATION.md +0 -207
  16. package/docs/public/api.md +0 -62
  17. package/docs/public/client-api-overview.md +0 -137
  18. package/docs/public/configuration.md +0 -759
  19. package/docs/public/error-handling/README.md +0 -356
  20. package/docs/public/error-handling/network-errors.md +0 -485
  21. package/docs/public/examples/coordinates-example.ts +0 -253
  22. package/docs/public/examples/multi-level-keys.ts +0 -374
  23. package/docs/public/examples/registry-hub-coordinates-example.ts +0 -370
  24. package/docs/public/examples/registry-hub-types.ts +0 -437
  25. package/docs/public/examples/simple-example.ts +0 -250
  26. package/docs/public/examples-README.md +0 -241
  27. package/docs/public/fjell-icon.svg +0 -1
  28. package/docs/public/icon.png +0 -0
  29. package/docs/public/icon2.png +0 -0
  30. package/docs/public/memory-overhead.svg +0 -120
  31. package/docs/public/memory.md +0 -430
  32. package/docs/public/operations/README.md +0 -121
  33. package/docs/public/operations/all.md +0 -325
  34. package/docs/public/operations/create.md +0 -415
  35. package/docs/public/operations/get.md +0 -389
  36. package/docs/public/package.json +0 -63
  37. package/docs/public/pano.png +0 -0
  38. package/docs/public/pano2.png +0 -0
  39. package/docs/public/timing-range.svg +0 -176
  40. package/docs/public/timing.md +0 -483
  41. package/docs/timing-range.svg +0 -174
  42. package/docs/vitest.config.ts +0 -14
  43. package/examples/README.md +0 -241
  44. package/examples/coordinates-example.ts +0 -253
  45. package/examples/multi-level-keys.ts +0 -382
  46. package/examples/registry-hub-coordinates-example.ts +0 -370
  47. package/examples/registry-hub-types.ts +0 -437
  48. package/examples/registry-statistics-example.ts +0 -264
  49. package/examples/simple-example.ts +0 -250
  50. package/tsconfig.docs.json +0 -28
  51. package/vitest.config.ts +0 -22
@@ -1,415 +0,0 @@
1
- # `create` Operation
2
-
3
- Create new items with validation, error handling, and automatic retry logic.
4
-
5
- ## Syntax
6
-
7
- ### Primary Items (PItemApi)
8
- ```typescript
9
- async create(item: Partial<Item<S>>): Promise<V>
10
- ```
11
-
12
- ### Contained Items (CItemApi)
13
- ```typescript
14
- async create(item: Partial<Item<S>>, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<V>
15
- ```
16
-
17
- ## Parameters
18
-
19
- | Parameter | Type | Required | Description |
20
- |-----------|------|----------|-------------|
21
- | `item` | `Partial<Item<S>>` | Yes | Item data to create (partial object) |
22
- | `locations` | `LocKeyArray` | No | Location context for contained items |
23
-
24
- ## Examples
25
-
26
- ### Basic Usage
27
-
28
- ```typescript
29
- // Create a new user
30
- const user = await userApi.create({
31
- name: 'John Doe',
32
- email: 'john@example.com',
33
- role: 'user'
34
- });
35
-
36
- console.log('Created user:', user.id);
37
- ```
38
-
39
- ### Contained Items
40
-
41
- ```typescript
42
- // Create a task for a specific user
43
- const task = await taskApi.create({
44
- title: 'Complete project proposal',
45
- description: 'Draft and review the Q1 project proposal',
46
- priority: 'high',
47
- dueDate: '2024-02-15'
48
- }, [userId]);
49
-
50
- // Create an order item for a specific order
51
- const orderItem = await orderItemApi.create({
52
- productId: 'prod-123',
53
- quantity: 2,
54
- price: 29.99
55
- }, [customerId, orderId]);
56
- ```
57
-
58
- ### Complex Data Structures
59
-
60
- ```typescript
61
- // Create user with nested data
62
- const user = await userApi.create({
63
- name: 'Alice Johnson',
64
- email: 'alice@example.com',
65
- profile: {
66
- bio: 'Software engineer with 5 years experience',
67
- avatar: 'https://example.com/avatars/alice.jpg',
68
- preferences: {
69
- theme: 'dark',
70
- notifications: true
71
- }
72
- },
73
- tags: ['developer', 'full-stack', 'react'],
74
- metadata: {
75
- source: 'registration-form',
76
- campaign: 'spring-2024'
77
- }
78
- });
79
- ```
80
-
81
- ### Batch Creation
82
-
83
- ```typescript
84
- // Create multiple users efficiently
85
- const userPromises = userData.map(data =>
86
- userApi.create(data).catch(error => ({ error, data }))
87
- );
88
-
89
- const results = await Promise.allSettled(userPromises);
90
-
91
- results.forEach((result, index) => {
92
- if (result.status === 'fulfilled') {
93
- console.log(`User ${index + 1} created:`, result.value.id);
94
- } else {
95
- console.error(`Failed to create user ${index + 1}:`, result.reason);
96
- }
97
- });
98
- ```
99
-
100
- ## Error Handling
101
-
102
- The `create` operation includes comprehensive error handling with automatic retry:
103
-
104
- ```typescript
105
- try {
106
- const user = await userApi.create({
107
- name: 'John Doe',
108
- email: 'john@example.com'
109
- });
110
-
111
- console.log('User created successfully:', user.id);
112
-
113
- } catch (error) {
114
- if (error.code === 'VALIDATION_ERROR') {
115
- console.error('Validation failed:', error.validationErrors);
116
- // Handle specific validation errors
117
- error.validationErrors.forEach(err => {
118
- console.log(`${err.field}: ${err.message}`);
119
- });
120
-
121
- } else if (error.code === 'CONFLICT_ERROR') {
122
- console.error('User already exists or conflict detected');
123
-
124
- } else if (error.code === 'NETWORK_ERROR') {
125
- console.error('Network issue - operation was automatically retried');
126
-
127
- } else {
128
- console.error('Unexpected error:', error.message);
129
- }
130
- }
131
- ```
132
-
133
- ### Automatic Retry Behavior
134
-
135
- Network and server errors are automatically retried with exponential backoff:
136
-
137
- ```typescript
138
- // Configuration affects retry behavior
139
- const config = {
140
- baseUrl: 'https://api.example.com',
141
- retryConfig: {
142
- maxRetries: 3,
143
- initialDelayMs: 1000,
144
- backoffMultiplier: 2
145
- }
146
- };
147
-
148
- const userApi = createPItemApi<User, 'user'>('user', ['users'], config);
149
-
150
- // This will automatically retry on transient failures
151
- const user = await userApi.create({ name: 'John', email: 'john@example.com' });
152
- ```
153
-
154
- ## Validation
155
-
156
- ### Client-side Validation
157
-
158
- ```typescript
159
- function validateUserData(userData: Partial<User>): string[] {
160
- const errors: string[] = [];
161
-
162
- if (!userData.name || userData.name.trim().length === 0) {
163
- errors.push('Name is required');
164
- }
165
-
166
- if (!userData.email || !isValidEmail(userData.email)) {
167
- errors.push('Valid email is required');
168
- }
169
-
170
- if (userData.age && (userData.age < 0 || userData.age > 150)) {
171
- errors.push('Age must be between 0 and 150');
172
- }
173
-
174
- return errors;
175
- }
176
-
177
- // Use validation before creating
178
- const userData = { name: 'John', email: 'invalid-email' };
179
- const validationErrors = validateUserData(userData);
180
-
181
- if (validationErrors.length > 0) {
182
- console.error('Validation errors:', validationErrors);
183
- return;
184
- }
185
-
186
- const user = await userApi.create(userData);
187
- ```
188
-
189
- ### Server-side Validation Handling
190
-
191
- ```typescript
192
- try {
193
- const user = await userApi.create({
194
- name: '', // Invalid: empty name
195
- email: 'not-an-email', // Invalid: bad email format
196
- age: -5 // Invalid: negative age
197
- });
198
- } catch (error) {
199
- if (error.code === 'VALIDATION_ERROR') {
200
- // Server returned detailed validation errors
201
- console.log('Server validation errors:');
202
- error.validationErrors.forEach(err => {
203
- console.log(`- ${err.field}: ${err.message}`);
204
- });
205
-
206
- // Example output:
207
- // - name: Name cannot be empty
208
- // - email: Email format is invalid
209
- // - age: Age must be a positive number
210
- }
211
- }
212
- ```
213
-
214
- ## Performance Considerations
215
-
216
- ### Efficient Creation Patterns
217
-
218
- ```typescript
219
- // Use batch operations when possible
220
- async function createUsersEfficiently(usersData: Partial<User>[]) {
221
- // Option 1: Parallel creation (faster but less control)
222
- const users = await Promise.all(
223
- usersData.map(data => userApi.create(data))
224
- );
225
-
226
- // Option 2: Sequential with error handling (more reliable)
227
- const results = [];
228
- for (const userData of usersData) {
229
- try {
230
- const user = await userApi.create(userData);
231
- results.push({ success: true, user });
232
- } catch (error) {
233
- results.push({ success: false, error, data: userData });
234
- }
235
- }
236
-
237
- return results;
238
- }
239
- ```
240
-
241
- ### Large Object Optimization
242
-
243
- ```typescript
244
- // For large objects, consider streaming or chunking
245
- async function createLargeDocument(documentData: LargeDocument) {
246
- try {
247
- // Option 1: Direct creation
248
- return await documentApi.create(documentData);
249
-
250
- } catch (error) {
251
- if (error.code === 'PAYLOAD_TOO_LARGE_ERROR') {
252
- // Option 2: Create with minimal data, then update
253
- const doc = await documentApi.create({
254
- title: documentData.title,
255
- type: documentData.type
256
- });
257
-
258
- // Update with full content
259
- return await documentApi.update(doc.id, documentData);
260
- }
261
- throw error;
262
- }
263
- }
264
- ```
265
-
266
- ## Return Value
267
-
268
- Returns a Promise that resolves to the created item with generated fields:
269
-
270
- ```typescript
271
- const user = await userApi.create({
272
- name: 'John Doe',
273
- email: 'john@example.com'
274
- });
275
-
276
- // Created user includes generated fields:
277
- console.log(user);
278
- // {
279
- // id: 'user-abc123', // Generated ID
280
- // name: 'John Doe', // Provided data
281
- // email: 'john@example.com', // Provided data
282
- // active: true, // Default value
283
- // createdAt: '2024-01-15T10:30:00Z', // Generated timestamp
284
- // updatedAt: '2024-01-15T10:30:00Z', // Generated timestamp
285
- // keyType: 'user' // Generated metadata
286
- // }
287
- ```
288
-
289
- ## Advanced Patterns
290
-
291
- ### Optimistic Creation
292
-
293
- ```typescript
294
- // Create locally first, then sync with server
295
- class OptimisticUserManager {
296
- private localUsers: User[] = [];
297
-
298
- async createUserOptimistically(userData: Partial<User>): Promise<User> {
299
- // Generate temporary ID
300
- const tempUser: User = {
301
- ...userData,
302
- id: `temp-${Date.now()}`,
303
- createdAt: new Date().toISOString(),
304
- updatedAt: new Date().toISOString(),
305
- keyType: 'user',
306
- pending: true
307
- };
308
-
309
- // Add to local state immediately
310
- this.localUsers.push(tempUser);
311
- this.notifyUI(tempUser);
312
-
313
- try {
314
- // Create on server
315
- const serverUser = await userApi.create(userData);
316
-
317
- // Replace temp user with server user
318
- const index = this.localUsers.findIndex(u => u.id === tempUser.id);
319
- if (index >= 0) {
320
- this.localUsers[index] = serverUser;
321
- this.notifyUI(serverUser);
322
- }
323
-
324
- return serverUser;
325
-
326
- } catch (error) {
327
- // Remove temp user on failure
328
- this.localUsers = this.localUsers.filter(u => u.id !== tempUser.id);
329
- this.notifyError(error);
330
- throw error;
331
- }
332
- }
333
- }
334
- ```
335
-
336
- ### Conditional Creation
337
-
338
- ```typescript
339
- // Create only if item doesn't exist
340
- async function createUserIfNotExists(userData: Partial<User>): Promise<User> {
341
- try {
342
- // Try to find existing user
343
- const existingUsers = await userApi.find('by-email', {
344
- email: userData.email
345
- });
346
-
347
- if (existingUsers.length > 0) {
348
- console.log('User already exists:', existingUsers[0].id);
349
- return existingUsers[0];
350
- }
351
-
352
- // Create new user
353
- return await userApi.create(userData);
354
-
355
- } catch (error) {
356
- if (error.code === 'CONFLICT_ERROR') {
357
- // Handle race condition - user was created between check and create
358
- console.log('User created by another process');
359
- const users = await userApi.find('by-email', { email: userData.email });
360
- return users[0];
361
- }
362
- throw error;
363
- }
364
- }
365
- ```
366
-
367
- ### Transaction-like Creation
368
-
369
- ```typescript
370
- // Create related items atomically
371
- async function createUserWithProfile(
372
- userData: Partial<User>,
373
- profileData: Partial<UserProfile>
374
- ): Promise<{ user: User; profile: UserProfile }> {
375
- try {
376
- // Create user first
377
- const user = await userApi.create(userData);
378
-
379
- try {
380
- // Create profile linked to user
381
- const profile = await profileApi.create({
382
- ...profileData,
383
- userId: user.id
384
- });
385
-
386
- return { user, profile };
387
-
388
- } catch (profileError) {
389
- // Cleanup user if profile creation fails
390
- try {
391
- await userApi.remove({ id: user.id, keyType: 'user' });
392
- } catch (cleanupError) {
393
- console.error('Failed to cleanup user after profile error:', cleanupError);
394
- }
395
- throw profileError;
396
- }
397
-
398
- } catch (userError) {
399
- throw userError;
400
- }
401
- }
402
- ```
403
-
404
- ## Related Operations
405
-
406
- - [`update`](./update.md) - Update existing items
407
- - [`get`](./get.md) - Retrieve created items
408
- - [`all`](./all.md) - List created items
409
- - [`remove`](./remove.md) - Delete items
410
-
411
- ## Next Steps
412
-
413
- - Learn about [Validation Patterns](../guides/validation.md)
414
- - Explore [Error Handling](../error-handling/README.md) for robust creation
415
- - Review [Performance Optimization](../guides/performance.md) for efficient creation