@mostajs/setup 2.1.3 → 2.1.4

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.
@@ -35,6 +35,11 @@ export interface SetupJsonSeed {
35
35
  hashField?: string;
36
36
  roleField?: string;
37
37
  defaults?: Record<string, unknown>;
38
+ lookupFields?: Record<string, {
39
+ collection: string;
40
+ match: string;
41
+ value: string;
42
+ }>;
38
43
  data: Record<string, unknown>[];
39
44
  }
40
45
  export interface SetupJson {
@@ -134,8 +134,18 @@ function buildSeedDefinition(seedDef, repoFactory) {
134
134
  run: async () => {
135
135
  const getRepo = repoFactory ?? defaultRepoFactory;
136
136
  const repo = await getRepo(seedDef.collection);
137
+ // Resolve lookupFields once (e.g. createdBy → user where email = admin@test.dz → userId)
138
+ const resolved = {};
139
+ if (seedDef.lookupFields) {
140
+ for (const [field, lookup] of Object.entries(seedDef.lookupFields)) {
141
+ const lookupRepo = await getRepo(lookup.collection);
142
+ const found = await lookupRepo.findOne({ [lookup.match]: lookup.value });
143
+ if (found)
144
+ resolved[field] = found.id;
145
+ }
146
+ }
137
147
  for (const rawItem of seedDef.data) {
138
- const item = { ...(seedDef.defaults ?? {}), ...rawItem };
148
+ const item = { ...(seedDef.defaults ?? {}), ...resolved, ...rawItem };
139
149
  // Hash field if configured (e.g. password)
140
150
  if (seedDef.hashField && item[seedDef.hashField]) {
141
151
  const bcryptModule = await import('bcryptjs');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/setup",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "Reusable setup wizard module — multi-dialect DB configuration, .env.local writer, seed runner",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "MIT",