@fjell/core 4.4.13 → 4.4.18

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 (73) hide show
  1. package/dist/AItemService.d.ts +1 -1
  2. package/dist/index.d.ts +5 -5
  3. package/dist/index.js +7911 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/item/IFactory.d.ts +2 -2
  6. package/dist/item/IQFactory.d.ts +1 -1
  7. package/dist/item/IQUtils.d.ts +3 -3
  8. package/dist/item/IUtils.d.ts +2 -2
  9. package/dist/item/ItemQuery.d.ts +1 -1
  10. package/dist/key/KUtils.d.ts +1 -1
  11. package/dist/logger.d.ts +1 -1
  12. package/package.json +15 -13
  13. package/dist/cjs/AItemService.js +0 -42
  14. package/dist/cjs/AItemService.js.map +0 -1
  15. package/dist/cjs/dictionary.js +0 -71
  16. package/dist/cjs/dictionary.js.map +0 -1
  17. package/dist/cjs/index.js +0 -62
  18. package/dist/cjs/index.js.map +0 -1
  19. package/dist/cjs/item/IFactory.js +0 -93
  20. package/dist/cjs/item/IFactory.js.map +0 -1
  21. package/dist/cjs/item/IQFactory.js +0 -154
  22. package/dist/cjs/item/IQFactory.js.map +0 -1
  23. package/dist/cjs/item/IQUtils.js +0 -335
  24. package/dist/cjs/item/IQUtils.js.map +0 -1
  25. package/dist/cjs/item/IUtils.js +0 -76
  26. package/dist/cjs/item/IUtils.js.map +0 -1
  27. package/dist/cjs/item/ItemQuery.js +0 -10
  28. package/dist/cjs/item/ItemQuery.js.map +0 -1
  29. package/dist/cjs/key/KUtils.js +0 -397
  30. package/dist/cjs/key/KUtils.js.map +0 -1
  31. package/dist/cjs/logger.js +0 -10
  32. package/dist/cjs/logger.js.map +0 -1
  33. package/dist/esm/AItemService.js +0 -38
  34. package/dist/esm/AItemService.js.map +0 -1
  35. package/dist/esm/dictionary.js +0 -67
  36. package/dist/esm/dictionary.js.map +0 -1
  37. package/dist/esm/index.js +0 -9
  38. package/dist/esm/index.js.map +0 -1
  39. package/dist/esm/item/IFactory.js +0 -89
  40. package/dist/esm/item/IFactory.js.map +0 -1
  41. package/dist/esm/item/IQFactory.js +0 -150
  42. package/dist/esm/item/IQFactory.js.map +0 -1
  43. package/dist/esm/item/IQUtils.js +0 -305
  44. package/dist/esm/item/IQUtils.js.map +0 -1
  45. package/dist/esm/item/IUtils.js +0 -69
  46. package/dist/esm/item/IUtils.js.map +0 -1
  47. package/dist/esm/item/ItemQuery.js +0 -6
  48. package/dist/esm/item/ItemQuery.js.map +0 -1
  49. package/dist/esm/key/KUtils.js +0 -365
  50. package/dist/esm/key/KUtils.js.map +0 -1
  51. package/dist/esm/logger.js +0 -6
  52. package/dist/esm/logger.js.map +0 -1
  53. package/dist/index.cjs +0 -1131
  54. package/dist/index.cjs.map +0 -1
  55. package/docs/README.md +0 -53
  56. package/docs/index.html +0 -18
  57. package/docs/package.json +0 -35
  58. package/docs/public/README.md +0 -227
  59. package/docs/public/api.md +0 -230
  60. package/docs/public/basic-usage.ts +0 -293
  61. package/docs/public/examples-README.md +0 -147
  62. package/docs/public/fjell-icon.svg +0 -1
  63. package/docs/public/package.json +0 -56
  64. package/docs/public/pano.png +0 -0
  65. package/docs/src/App.css +0 -1178
  66. package/docs/src/App.tsx +0 -683
  67. package/docs/src/index.css +0 -38
  68. package/docs/src/main.tsx +0 -10
  69. package/docs/tsconfig.node.json +0 -14
  70. package/docs/vitest.config.ts +0 -14
  71. package/examples/README.md +0 -147
  72. package/examples/basic-usage.ts +0 -293
  73. package/vitest.config.ts +0 -37
@@ -1,38 +0,0 @@
1
- :root {
2
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
-
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #242424;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- -webkit-text-size-adjust: 100%;
15
- }
16
-
17
- a {
18
- font-weight: 500;
19
- color: #646cff;
20
- text-decoration: inherit;
21
- }
22
-
23
- a:hover {
24
- color: #535bf2;
25
- }
26
-
27
- body {
28
- margin: 0;
29
- display: flex;
30
- place-items: center;
31
- min-width: 320px;
32
- min-height: 100vh;
33
- }
34
-
35
- h1 {
36
- font-size: 3.2em;
37
- line-height: 1.1;
38
- }
package/docs/src/main.tsx DELETED
@@ -1,10 +0,0 @@
1
- import React from 'react'
2
- import ReactDOM from 'react-dom/client'
3
- import App from './App.tsx'
4
- import './index.css'
5
-
6
- ReactDOM.createRoot(document.getElementById('root')!).render(
7
- <React.StrictMode>
8
- <App />
9
- </React.StrictMode>,
10
- )
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "allowSyntheticDefaultImports": true,
8
- "strict": true
9
- },
10
- "include": [
11
- "vite.config.ts",
12
- "vitest.config.ts"
13
- ]
14
- }
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
- import react from '@vitejs/plugin-react'
3
-
4
- export default defineConfig({
5
- plugins: [react()],
6
- test: {
7
- globals: true,
8
- environment: 'jsdom',
9
- setupFiles: ['./src/test/setup.ts'],
10
- coverage: {
11
- reporter: ['text', 'json', 'html']
12
- }
13
- }
14
- })
@@ -1,147 +0,0 @@
1
- # Fjell Core Examples
2
-
3
- This directory contains comprehensive examples demonstrating real-world usage patterns for Fjell Core.
4
-
5
- ## Available Examples
6
-
7
- ### Basic Examples
8
-
9
- #### [basic-usage.ts](./basic-usage.ts)
10
- Demonstrates fundamental Fjell Core operations:
11
- - Item creation with IFactory
12
- - Key generation and manipulation with KUtils
13
- - Basic service implementation with AItemService
14
-
15
- #### [service-patterns.ts](./service-patterns.ts)
16
- Shows common service implementation patterns:
17
- - Repository pattern implementation
18
- - Service composition
19
- - Error handling strategies
20
-
21
- #### [query-examples.ts](./query-examples.ts)
22
- Query building and execution examples:
23
- - Basic query construction
24
- - Complex filtering and sorting
25
- - Query optimization techniques
26
-
27
- ### Advanced Examples
28
-
29
- #### [enterprise-example.ts](./enterprise-example.ts)
30
- Production-ready enterprise patterns:
31
- - Multi-layered service architecture
32
- - Transaction management
33
- - Comprehensive error handling
34
- - Performance optimization
35
-
36
- #### [testing-example.ts](./testing-example.ts)
37
- Testing strategies and utilities:
38
- - Unit testing with Fjell Core
39
- - Mock creation and management
40
- - Integration testing patterns
41
-
42
- ## Running the Examples
43
-
44
- All examples are TypeScript files that can be run directly:
45
-
46
- ```bash
47
- # Using ts-node
48
- npx ts-node examples/basic-usage.ts
49
-
50
- # Using tsx
51
- npx tsx examples/basic-usage.ts
52
-
53
- # Compile and run
54
- tsc examples/basic-usage.ts && node examples/basic-usage.js
55
- ```
56
-
57
- ## Prerequisites
58
-
59
- Make sure you have Fjell Core installed:
60
-
61
- ```bash
62
- npm install @fjell/core
63
- ```
64
-
65
- For the examples that integrate with databases or external services, you may need additional dependencies as noted in each example.
66
-
67
- ## Example Structure
68
-
69
- Each example follows a consistent structure:
70
-
71
- 1. **Imports**: Required Fjell Core modules
72
- 2. **Type Definitions**: TypeScript interfaces and types
73
- 3. **Implementation**: Core logic demonstration
74
- 4. **Usage**: Practical usage examples
75
- 5. **Output**: Expected results and explanations
76
-
77
- ## Integration Examples
78
-
79
- Several examples show integration with popular libraries and frameworks:
80
-
81
- - Express.js web applications
82
- - Database ORMs (Sequelize, TypeORM)
83
- - Testing frameworks (Jest, Vitest)
84
- - React applications
85
- - GraphQL APIs
86
-
87
- ## Best Practices
88
-
89
- The examples demonstrate Fjell Core best practices:
90
-
91
- - **Type Safety**: Comprehensive TypeScript usage
92
- - **Error Handling**: Robust error management
93
- - **Performance**: Optimized patterns for production
94
- - **Testing**: Comprehensive test coverage
95
- - **Documentation**: Clear code documentation
96
-
97
- ## Contributing Examples
98
-
99
- We welcome new examples! Please follow these guidelines:
100
-
101
- 1. Create a new TypeScript file with a descriptive name
102
- 2. Include comprehensive comments explaining the concepts
103
- 3. Add proper type definitions
104
- 4. Include usage examples and expected output
105
- 5. Update this README with a description of your example
106
-
107
- ## Getting Help
108
-
109
- If you have questions about any example:
110
-
111
- 1. Check the inline comments for explanations
112
- 2. Review the main Fjell Core documentation
113
- 3. Open an issue on GitHub for specific questions
114
- 4. Join our community discussions
115
-
116
- ## Common Patterns Demonstrated
117
-
118
- ### Factory Pattern
119
- ```typescript
120
- const user = IFactory.create<User>('user', userData)
121
- ```
122
-
123
- ### Repository Pattern
124
- ```typescript
125
- class UserRepository extends AItemService {
126
- async save(user: User): Promise<User> { ... }
127
- async findById(id: string): Promise<User | null> { ... }
128
- }
129
- ```
130
-
131
- ### Service Layer
132
- ```typescript
133
- class UserService extends AItemService {
134
- constructor(private userRepo: UserRepository) { super() }
135
- async registerUser(data: UserData): Promise<User> { ... }
136
- }
137
- ```
138
-
139
- ### Query Building
140
- ```typescript
141
- const query = IQFactory.create('user')
142
- .where('status', 'active')
143
- .orderBy('createdAt', 'desc')
144
- .limit(10)
145
- ```
146
-
147
- These examples provide a solid foundation for building production applications with Fjell Core.
@@ -1,293 +0,0 @@
1
- /**
2
- * Basic Usage Example - Fjell Core
3
- *
4
- * This example demonstrates the fundamental operations available in Fjell Core:
5
- * - Item creation with IFactory
6
- * - Key generation and manipulation with KUtils
7
- * - Basic service implementation with AItemService
8
- */
9
-
10
- import { AItemService, IFactory, KUtils } from '@fjell/core'
11
-
12
- // Define our data types
13
- interface User {
14
- id: string
15
- name: string
16
- email: string
17
- createdAt: string
18
- status: 'active' | 'inactive'
19
- }
20
-
21
- interface Product {
22
- id: string
23
- name: string
24
- price: number
25
- category: string
26
- inStock: boolean
27
- }
28
-
29
- /**
30
- * 1. ITEM CREATION WITH IFACTORY
31
- *
32
- * IFactory provides type-safe item creation with validation and defaults.
33
- */
34
- console.log('=== Item Creation Examples ===')
35
-
36
- // Create a user item
37
- const user = IFactory.create<User>('user', {
38
- id: 'user-123',
39
- name: 'John Doe',
40
- email: 'john.doe@example.com',
41
- createdAt: new Date().toISOString(),
42
- status: 'active'
43
- })
44
-
45
- console.log('Created user:', user)
46
-
47
- // Create a product item
48
- const product = IFactory.create<Product>('product', {
49
- id: 'prod-456',
50
- name: 'Wireless Headphones',
51
- price: 199.99,
52
- category: 'Electronics',
53
- inStock: true
54
- })
55
-
56
- console.log('Created product:', product)
57
-
58
- /**
59
- * 2. KEY MANAGEMENT WITH KUTILS
60
- *
61
- * KUtils provides hierarchical key generation and manipulation utilities.
62
- */
63
- console.log('\n=== Key Management Examples ===')
64
-
65
- // Generate hierarchical keys
66
- const userKey = KUtils.generateKey(['users', user.id])
67
- const userProfileKey = KUtils.generateKey(['users', user.id, 'profile'])
68
- const userOrdersKey = KUtils.generateKey(['users', user.id, 'orders'])
69
-
70
- console.log('User key:', userKey)
71
- console.log('User profile key:', userProfileKey)
72
- console.log('User orders key:', userOrdersKey)
73
-
74
- // Parse keys back to components
75
- const userKeyComponents = KUtils.parseKey(userKey)
76
- const profileKeyComponents = KUtils.parseKey(userProfileKey)
77
-
78
- console.log('User key components:', userKeyComponents)
79
- console.log('Profile key components:', profileKeyComponents)
80
-
81
- // Validate keys
82
- const isValidUserKey = KUtils.isValidKey(userKey)
83
- const isValidInvalidKey = KUtils.isValidKey('invalid::key::format')
84
-
85
- console.log('User key is valid:', isValidUserKey)
86
- console.log('Invalid key is valid:', isValidInvalidKey)
87
-
88
- // Get parent keys
89
- const parentOfProfile = KUtils.getParentKey(userProfileKey)
90
- console.log('Parent of profile key:', parentOfProfile)
91
-
92
- /**
93
- * 3. SERVICE LAYER WITH AITEMSERVICE
94
- *
95
- * AItemService provides an abstract base for building domain services.
96
- */
97
- console.log('\n=== Service Layer Examples ===')
98
-
99
- class UserService extends AItemService {
100
- private users = new Map<string, User>()
101
-
102
- async create(userData: Partial<User>): Promise<User> {
103
- console.log('Creating user with data:', userData)
104
-
105
- // Create user with IFactory
106
- const user = IFactory.create<User>('user', {
107
- id: this.generateId(),
108
- createdAt: new Date().toISOString(),
109
- status: 'active',
110
- ...userData
111
- })
112
-
113
- // Validate the user
114
- await this.validate(user)
115
-
116
- // Save the user
117
- await this.save(user)
118
-
119
- console.log('User created successfully:', user.id)
120
- return user
121
- }
122
-
123
- async findById(id: string): Promise<User | null> {
124
- const key = KUtils.generateKey(['users', id])
125
- const user = this.users.get(key)
126
- console.log(`Finding user by ID ${id}:`, user ? 'found' : 'not found')
127
- return user || null
128
- }
129
-
130
- async updateStatus(id: string, status: User['status']): Promise<User | null> {
131
- const user = await this.findById(id)
132
- if (!user) {
133
- console.log(`User ${id} not found for status update`)
134
- return null
135
- }
136
-
137
- const updatedUser = { ...user, status }
138
- await this.save(updatedUser)
139
-
140
- console.log(`User ${id} status updated to ${status}`)
141
- return updatedUser
142
- }
143
-
144
- async listActiveUsers(): Promise<User[]> {
145
- const activeUsers = Array.from(this.users.values())
146
- .filter(user => user.status === 'active')
147
-
148
- console.log(`Found ${activeUsers.length} active users`)
149
- return activeUsers
150
- }
151
-
152
- protected async validate(user: User): Promise<void> {
153
- if (!user.email || !user.email.includes('@')) {
154
- throw new Error('Valid email is required')
155
- }
156
-
157
- if (!user.name || user.name.length < 2) {
158
- throw new Error('Name must be at least 2 characters')
159
- }
160
-
161
- console.log('User validation passed for:', user.email)
162
- }
163
-
164
- protected async save(user: User): Promise<User> {
165
- const key = KUtils.generateKey(['users', user.id])
166
- this.users.set(key, user)
167
- console.log('User saved with key:', key)
168
- return user
169
- }
170
-
171
- private generateId(): string {
172
- return `user-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
173
- }
174
- }
175
-
176
- // Demonstrate service usage
177
- async function demonstrateService() {
178
- const userService = new UserService()
179
-
180
- try {
181
- // Create users
182
- const user1 = await userService.create({
183
- name: 'Alice Smith',
184
- email: 'alice.smith@example.com'
185
- })
186
-
187
- const user2 = await userService.create({
188
- name: 'Bob Johnson',
189
- email: 'bob.johnson@example.com'
190
- })
191
-
192
- // Find users
193
- const foundUser = await userService.findById(user1.id)
194
- console.log('Found user:', foundUser?.name)
195
-
196
- // Update user status
197
- await userService.updateStatus(user2.id, 'inactive')
198
-
199
- // List active users
200
- const activeUsers = await userService.listActiveUsers()
201
- console.log('Active users:', activeUsers.map(u => u.name))
202
-
203
- } catch (error) {
204
- console.error('Service error:', error.message)
205
- }
206
- }
207
-
208
- /**
209
- * 4. PRACTICAL INTEGRATION EXAMPLE
210
- *
211
- * Combining all concepts in a realistic scenario.
212
- */
213
- console.log('\n=== Integration Example ===')
214
-
215
- class OrderService extends AItemService {
216
- private orders = new Map<string, any>()
217
-
218
- constructor(private userService: UserService) {
219
- super()
220
- }
221
-
222
- async createOrder(userId: string, items: any[]): Promise<any> {
223
- // Verify user exists
224
- const user = await this.userService.findById(userId)
225
- if (!user) {
226
- throw new Error(`User ${userId} not found`)
227
- }
228
-
229
- // Create order
230
- const order = IFactory.create('order', {
231
- id: this.generateOrderId(),
232
- userId,
233
- items,
234
- total: this.calculateTotal(items),
235
- status: 'pending',
236
- createdAt: new Date().toISOString()
237
- })
238
-
239
- // Save order
240
- const orderKey = KUtils.generateKey(['orders', order.id])
241
- this.orders.set(orderKey, order)
242
-
243
- console.log(`Order ${order.id} created for user ${user.name}`)
244
- return order
245
- }
246
-
247
- private generateOrderId(): string {
248
- return `order-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
249
- }
250
-
251
- private calculateTotal(items: any[]): number {
252
- return items.reduce((total, item) => total + (item.price * item.quantity), 0)
253
- }
254
- }
255
-
256
- async function demonstrateIntegration() {
257
- const userService = new UserService()
258
- const orderService = new OrderService(userService)
259
-
260
- try {
261
- // Create a user
262
- const user = await userService.create({
263
- name: 'Customer One',
264
- email: 'customer@example.com'
265
- })
266
-
267
- // Create an order for the user
268
- const order = await orderService.createOrder(user.id, [
269
- { name: 'Product A', price: 29.99, quantity: 2 },
270
- { name: 'Product B', price: 15.50, quantity: 1 }
271
- ])
272
-
273
- console.log('Integration completed successfully')
274
- console.log('Order total:', order.total)
275
-
276
- } catch (error) {
277
- console.error('Integration error:', error.message)
278
- }
279
- }
280
-
281
- // Run all demonstrations
282
- async function runExamples() {
283
- await demonstrateService()
284
- await demonstrateIntegration()
285
- console.log('\n=== All examples completed ===')
286
- }
287
-
288
- // Execute if running directly
289
- if (require.main === module) {
290
- runExamples().catch(console.error)
291
- }
292
-
293
- export { UserService, OrderService }
package/vitest.config.ts DELETED
@@ -1,37 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
- import * as path from 'path';
3
-
4
- export default defineConfig({
5
- resolve: {
6
- alias: {
7
- '@': path.resolve(__dirname, './src'),
8
- },
9
- },
10
- test: {
11
- globals: true,
12
- environment: 'node',
13
- include: ['tests/**/*.test.ts'],
14
- coverage: {
15
- provider: 'v8',
16
- all: true,
17
- include: ['src/**/*.{ts,tsx}'],
18
- exclude: [
19
- 'src/index.ts',
20
- 'tests/**',
21
- '**/*.d.ts',
22
- 'node_modules/**',
23
- 'dist/**',
24
- ],
25
- reportsDirectory: './coverage',
26
- reporter: ['text', 'html', 'clover', 'json'],
27
- thresholds: {
28
- global: {
29
- branches: 91,
30
- functions: 100,
31
- lines: 98,
32
- statements: 98,
33
- },
34
- },
35
- },
36
- },
37
- });