@ooneex/seeds 0.16.0 → 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.
Files changed (2) hide show
  1. package/README.md +184 -0
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1 +1,185 @@
1
1
  # @ooneex/seeds
2
+
3
+ Database seeding framework for populating initial data, fixtures, and test datasets with execution logging and idempotent operations.
4
+
5
+ ![Bun](https://img.shields.io/badge/Bun-Compatible-orange?style=flat-square&logo=bun)
6
+ ![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)
7
+ ![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)
8
+
9
+ ## Features
10
+
11
+ ✅ **Seed Decorator** - Register seed classes with the DI container using `@decorator.seed()`
12
+
13
+ ✅ **ISeed Interface** - Standard interface with `run()`, `isActive()`, and `getDependencies()` methods
14
+
15
+ ✅ **Dependency Resolution** - Define and automatically resolve seed dependencies before execution
16
+
17
+ ✅ **Active/Inactive Control** - Enable or disable individual seeds via the `isActive()` method
18
+
19
+ ✅ **Seed Runner** - Execute all active seeds in order with terminal logging via `seedRun()`
20
+
21
+ ✅ **Seed Scaffolding** - Generate new seed files from a template with `seedCreate()`
22
+
23
+ ✅ **Execution Logging** - Built-in terminal logging for seed progress, success, and failure
24
+
25
+ ✅ **Container Integration** - Automatic registration with `@ooneex/container` for dependency injection
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ bun add @ooneex/seeds
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Basic Seed
36
+
37
+ ```typescript
38
+ import { decorator, type ISeed, type SeedClassType } from '@ooneex/seeds';
39
+
40
+ @decorator.seed()
41
+ export class UserSeed implements ISeed {
42
+ public async run<T>(data?: unknown[]): Promise<T> {
43
+ // Insert initial users into the database
44
+ return data as T;
45
+ }
46
+
47
+ public isActive(): boolean {
48
+ return true;
49
+ }
50
+
51
+ public async getDependencies(): Promise<SeedClassType[]> {
52
+ return [];
53
+ }
54
+ }
55
+ ```
56
+
57
+ ### Seed with Dependencies
58
+
59
+ ```typescript
60
+ import { decorator, type ISeed, type SeedClassType } from '@ooneex/seeds';
61
+
62
+ @decorator.seed()
63
+ export class RoleSeed implements ISeed {
64
+ public async run<T>(data?: unknown[]): Promise<T> {
65
+ // Insert roles first
66
+ return data as T;
67
+ }
68
+
69
+ public isActive(): boolean {
70
+ return true;
71
+ }
72
+
73
+ public async getDependencies(): Promise<SeedClassType[]> {
74
+ return [];
75
+ }
76
+ }
77
+
78
+ @decorator.seed()
79
+ export class UserSeed implements ISeed {
80
+ public async run<T>(data?: unknown[]): Promise<T> {
81
+ // Roles are available in data from resolved dependencies
82
+ return data as T;
83
+ }
84
+
85
+ public isActive(): boolean {
86
+ return true;
87
+ }
88
+
89
+ public async getDependencies(): Promise<SeedClassType[]> {
90
+ return [RoleSeed];
91
+ }
92
+ }
93
+ ```
94
+
95
+ ### Running Seeds
96
+
97
+ ```typescript
98
+ import { seedRun } from '@ooneex/seeds';
99
+
100
+ await seedRun();
101
+ ```
102
+
103
+ ### Creating a New Seed
104
+
105
+ ```typescript
106
+ import { seedCreate } from '@ooneex/seeds';
107
+
108
+ const filePath = await seedCreate({ name: 'product', dir: 'seeds' });
109
+ // Creates seeds/ProductSeed.ts from the built-in template
110
+ ```
111
+
112
+ ## API Reference
113
+
114
+ ### Decorators
115
+
116
+ #### `@decorator.seed(scope?)`
117
+
118
+ Decorator to register a seed class with the DI container.
119
+
120
+ **Parameters:**
121
+ - `scope` - Container scope (default: `EContainerScope.Singleton`)
122
+
123
+ ### Interfaces
124
+
125
+ #### `ISeed`
126
+
127
+ Interface for seed implementations.
128
+
129
+ ```typescript
130
+ interface ISeed {
131
+ run: <T = unknown>(data?: unknown[]) => Promise<T> | T;
132
+ isActive: () => Promise<boolean> | boolean;
133
+ getDependencies: () => Promise<SeedClassType[]> | SeedClassType[];
134
+ }
135
+ ```
136
+
137
+ ### Functions
138
+
139
+ #### `seedRun(): Promise<void>`
140
+
141
+ Execute all active seeds with dependency resolution and terminal logging.
142
+
143
+ #### `seedCreate(config: { name: string; dir?: string }): Promise<string>`
144
+
145
+ Generate a new seed file from the built-in template. Returns the path of the created file.
146
+
147
+ #### `getSeeds(): ISeed[]`
148
+
149
+ Retrieve all registered and active seed instances from the container.
150
+
151
+ ### Types
152
+
153
+ #### `SeedClassType`
154
+
155
+ Type for seed class constructors.
156
+
157
+ ```typescript
158
+ type SeedClassType = new (...args: any[]) => ISeed;
159
+ ```
160
+
161
+ ## License
162
+
163
+ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
164
+
165
+ ## Contributing
166
+
167
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
168
+
169
+ ### Development Setup
170
+
171
+ 1. Clone the repository
172
+ 2. Install dependencies: `bun install`
173
+ 3. Run tests: `bun run test`
174
+ 4. Build the project: `bun run build`
175
+
176
+ ### Guidelines
177
+
178
+ - Write tests for new features
179
+ - Follow the existing code style
180
+ - Update documentation for API changes
181
+ - Ensure all tests pass before submitting PR
182
+
183
+ ---
184
+
185
+ Made with ❤️ by the Ooneex team
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ooneex/seeds",
3
- "description": "Database seeding utilities for populating initial and test data with logging support",
4
- "version": "0.16.0",
3
+ "description": "Database seeding framework for populating initial data, fixtures, and test datasets with execution logging and idempotent operations",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -28,12 +28,12 @@
28
28
  "npm:publish": "bun publish --tolerate-republish --access public"
29
29
  },
30
30
  "dependencies": {
31
- "@ooneex/container": "0.0.17",
32
- "@ooneex/logger": "0.15.0",
33
- "@ooneex/utils": "0.1.0"
31
+ "@ooneex/container": "0.0.19",
32
+ "@ooneex/logger": "0.17.2",
33
+ "@ooneex/utils": "0.1.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@ooneex/exception": "0.0.16"
36
+ "@ooneex/exception": "0.0.18"
37
37
  },
38
38
  "keywords": [
39
39
  "bun",