@ooneex/seeds 1.2.4 → 1.3.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.
package/dist/index.d.ts CHANGED
@@ -11,7 +11,11 @@ declare const decorator: {
11
11
  declare const getSeeds: () => ISeed[];
12
12
  declare const seedCreate: (config: {
13
13
  name: string;
14
- dir?: string;
15
- }) => Promise<string>;
14
+ seedsDir?: string;
15
+ testsDir?: string;
16
+ }) => Promise<{
17
+ seedPath: string;
18
+ testPath: string;
19
+ }>;
16
20
  declare const seedRun: () => Promise<void>;
17
21
  export { seedRun, seedCreate, getSeeds, decorator, SeedClassType, ISeed };
package/dist/index.js CHANGED
@@ -27,6 +27,32 @@ import { join } from "path";
27
27
  import { toPascalCase } from "@ooneex/utils";
28
28
  var {Glob } = globalThis.Bun;
29
29
 
30
+ // src/seed.test.txt
31
+ var seed_test_default = `import { describe, expect, test } from "bun:test";
32
+ import { {{NAME}}Seed } from "@/seeds/{{NAME}}Seed";
33
+
34
+ describe("{{NAME}}Seed", () => {
35
+ test("should have class name ending with 'Seed'", () => {
36
+ expect({{NAME}}Seed.name.endsWith("Seed")).toBe(true);
37
+ });
38
+
39
+ test("should have 'run' method", () => {
40
+ expect({{NAME}}Seed.prototype.run).toBeDefined();
41
+ expect(typeof {{NAME}}Seed.prototype.run).toBe("function");
42
+ });
43
+
44
+ test("should have 'isActive' method", () => {
45
+ expect({{NAME}}Seed.prototype.isActive).toBeDefined();
46
+ expect(typeof {{NAME}}Seed.prototype.isActive).toBe("function");
47
+ });
48
+
49
+ test("should have 'getDependencies' method", () => {
50
+ expect({{NAME}}Seed.prototype.getDependencies).toBeDefined();
51
+ expect(typeof {{NAME}}Seed.prototype.getDependencies).toBe("function");
52
+ });
53
+ });
54
+ `;
55
+
30
56
  // src/seed.txt
31
57
  var seed_default = `import { decorator, type ISeed, type SeedClassType } from "@ooneex/seeds";
32
58
 
@@ -51,19 +77,26 @@ export class {{ name }} implements ISeed {
51
77
 
52
78
  // src/seedCreate.ts
53
79
  var seedCreate = async (config) => {
54
- const name = `${toPascalCase(config.name)}Seed`;
55
- const seedsDir = config.dir || "seeds";
56
- await Bun.write(join(process.cwd(), seedsDir, `${name}.ts`), seed_default.replaceAll("{{ name }}", name));
80
+ const name = toPascalCase(config.name).replace(/Seed$/, "");
81
+ const seedName = `${name}Seed`;
82
+ const seedsDir = config.seedsDir || "seeds";
83
+ const testsDir = config.testsDir || join("tests", "seeds");
84
+ await Bun.write(join(process.cwd(), seedsDir, `${seedName}.ts`), seed_default.replaceAll("{{ name }}", seedName));
85
+ const testContent = seed_test_default.replace(/\{\{NAME\}\}/g, name);
86
+ await Bun.write(join(process.cwd(), testsDir, `${seedName}.spec.ts`), testContent);
57
87
  const imports = [];
58
88
  const glob = new Glob("**/*Seed.ts");
59
- for await (const file of glob.scan(seedsDir)) {
60
- const name2 = file.replace(/\.ts$/, "");
61
- imports.push(`export { ${name2} } from './${name2}';`);
89
+ for await (const file of glob.scan(join(process.cwd(), seedsDir))) {
90
+ const seedClassName = file.replace(/\.ts$/, "");
91
+ imports.push(`export { ${seedClassName} } from './${seedClassName}';`);
62
92
  }
63
93
  await Bun.write(join(process.cwd(), seedsDir, "seeds.ts"), `${imports.sort().join(`
64
94
  `)}
65
95
  `);
66
- return join(seedsDir, `${name}.ts`);
96
+ return {
97
+ seedPath: join(seedsDir, `${seedName}.ts`),
98
+ testPath: join(testsDir, `${seedName}.spec.ts`)
99
+ };
67
100
  };
68
101
  // src/seedRun.ts
69
102
  import { container as container3 } from "@ooneex/container";
@@ -140,4 +173,4 @@ export {
140
173
  decorator
141
174
  };
142
175
 
143
- //# debugId=EA5EA9D6BDBCF90664756E2164756E21
176
+ //# debugId=13D2C1D163E1472064756E2164756E21
package/dist/index.js.map CHANGED
@@ -5,10 +5,10 @@
5
5
  "import { container, EContainerScope } from \"@ooneex/container\";\nimport { SEEDS_CONTAINER } from \"./container\";\nimport type { SeedClassType } from \"./types\";\n\nexport const decorator = {\n seed: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: SeedClassType): void => {\n container.add(target, scope);\n SEEDS_CONTAINER.push(target);\n };\n },\n};\n",
6
6
  "import type { SeedClassType } from \"./types\";\n\nexport const SEEDS_CONTAINER: SeedClassType[] = [];\n",
7
7
  "import { container } from \"@ooneex/container\";\nimport { SEEDS_CONTAINER } from \"./container\";\nimport type { ISeed } from \"./types\";\n\nexport const getSeeds = (): ISeed[] => {\n const seedInstances = SEEDS_CONTAINER.map((SeedClass) => {\n return container.get(SeedClass);\n });\n\n return seedInstances.filter((seed) => seed.isActive());\n};\n",
8
- "import { join } from \"node:path\";\nimport { toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport content from \"./seed.txt\";\n\nexport const seedCreate = async (config: { name: string; dir?: string }): Promise<string> => {\n const name = `${toPascalCase(config.name)}Seed`;\n const seedsDir = config.dir || \"seeds\";\n\n await Bun.write(join(process.cwd(), seedsDir, `${name}.ts`), content.replaceAll(\"{{ name }}\", name));\n\n const imports: string[] = [];\n const glob = new Glob(\"**/*Seed.ts\");\n for await (const file of glob.scan(seedsDir)) {\n const name = file.replace(/\\.ts$/, \"\");\n imports.push(`export { ${name} } from './${name}';`);\n }\n\n await Bun.write(join(process.cwd(), seedsDir, \"seeds.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n return join(seedsDir, `${name}.ts`);\n};\n",
8
+ "import { join } from \"node:path\";\nimport { toPascalCase } from \"@ooneex/utils\";\nimport { Glob } from \"bun\";\nimport testTemplate from \"./seed.test.txt\";\nimport template from \"./seed.txt\";\n\nexport const seedCreate = async (config: {\n name: string;\n seedsDir?: string;\n testsDir?: string;\n}): Promise<{ seedPath: string; testPath: string }> => {\n const name = toPascalCase(config.name).replace(/Seed$/, \"\");\n const seedName = `${name}Seed`;\n const seedsDir = config.seedsDir || \"seeds\";\n const testsDir = config.testsDir || join(\"tests\", \"seeds\");\n\n await Bun.write(join(process.cwd(), seedsDir, `${seedName}.ts`), template.replaceAll(\"{{ name }}\", seedName));\n\n const testContent = testTemplate.replace(/\\{\\{NAME\\}\\}/g, name);\n await Bun.write(join(process.cwd(), testsDir, `${seedName}.spec.ts`), testContent);\n\n const imports: string[] = [];\n const glob = new Glob(\"**/*Seed.ts\");\n for await (const file of glob.scan(join(process.cwd(), seedsDir))) {\n const seedClassName = file.replace(/\\.ts$/, \"\");\n imports.push(`export { ${seedClassName} } from './${seedClassName}';`);\n }\n\n await Bun.write(join(process.cwd(), seedsDir, \"seeds.ts\"), `${imports.sort().join(\"\\n\")}\\n`);\n\n return {\n seedPath: join(seedsDir, `${seedName}.ts`),\n testPath: join(testsDir, `${seedName}.spec.ts`),\n };\n};\n",
9
9
  "import { container } from \"@ooneex/container\";\nimport type { IException } from \"@ooneex/exception\";\nimport { TerminalLogger } from \"@ooneex/logger\";\nimport { getSeeds } from \"./getSeeds\";\nimport type { ISeed } from \"./types\";\n\nconst run = async (seed: ISeed): Promise<void> => {\n const data = [];\n\n const dependencies = await seed.getDependencies();\n\n for (const dependency of dependencies) {\n const dep = container.get(dependency);\n data.push(await run(dep));\n }\n\n await seed.run(data);\n};\n\nexport const seedRun = async (): Promise<void> => {\n const seeds = getSeeds();\n const logger = new TerminalLogger();\n\n if (seeds.length === 0) {\n logger.info(\"No seeds found\\n\", undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n return;\n }\n\n logger.info(`Running ${seeds.length} seed(s)...\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n\n for (const seed of seeds) {\n const seedName = seed.constructor.name;\n\n if (!seed.isActive()) {\n logger.warn(`Seed ${seedName} is inactive\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n continue;\n }\n\n try {\n await run(seed);\n logger.success(`Seed ${seedName} completed\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n } catch (error) {\n logger.error(`Seed ${seedName} failed\\n`, undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n logger.error(error as IException);\n process.exit(1);\n }\n }\n\n logger.success(\"\\nAll seeds completed successfully\\n\", undefined, {\n showTimestamp: false,\n showArrow: false,\n useSymbol: true,\n });\n};\n"
10
10
  ],
11
- "mappings": ";;AAAA;;;ACEO,IAAM,kBAAmC,CAAC;;;ADE1C,IAAM,YAAY;AAAA,EACvB,MAAM,CAAC,QAAyB,gBAAgB,cAAc;AAAA,IAC5D,OAAO,CAAC,WAAgC;AAAA,MACtC,UAAU,IAAI,QAAQ,KAAK;AAAA,MAC3B,gBAAgB,KAAK,MAAM;AAAA;AAAA;AAGjC;;AEXA,sBAAS;AAIF,IAAM,WAAW,MAAe;AAAA,EACrC,MAAM,gBAAgB,gBAAgB,IAAI,CAAC,cAAc;AAAA,IACvD,OAAO,WAAU,IAAI,SAAS;AAAA,GAC/B;AAAA,EAED,OAAO,cAAc,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC;AAAA;;ACTvD;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,aAAa,OAAO,WAA4D;AAAA,EAC3F,MAAM,OAAO,GAAG,aAAa,OAAO,IAAI;AAAA,EACxC,MAAM,WAAW,OAAO,OAAO;AAAA,EAE/B,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GAAG,UAAU,GAAG,SAAS,GAAG,aAAQ,WAAW,cAAc,IAAI,CAAC;AAAA,EAEnG,MAAM,UAAoB,CAAC;AAAA,EAC3B,MAAM,OAAO,IAAI,KAAK,aAAa;AAAA,EACnC,iBAAiB,QAAQ,KAAK,KAAK,QAAQ,GAAG;AAAA,IAC5C,MAAM,QAAO,KAAK,QAAQ,SAAS,EAAE;AAAA,IACrC,QAAQ,KAAK,YAAY,mBAAkB,SAAQ;AAAA,EACrD;AAAA,EAEA,MAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,GAAG,UAAU,UAAU,GAAG,GAAG,QAAQ,KAAK,EAAE,K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AuB,WAAW;AAAA,IAC7D,eAAe;AAAA,IACf,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AAAA,EAED,WAAW,QAAQ,OAAO;AAAA,IACxB,MAAM,WAAW,KAAK,YAAY;AAAA,IAElC,IAAI,CAAC,KAAK,SAAS,GAAG;AAAA,MACpB,OAAO,KAAK,QAAQ;AAAA,GAA0B,WAAW;AAAA,QACvD,eAAe;AAAA,QACf,WAAW;AAAA,QACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD;AAAA,IACF;AAAA,IAEA,IAAI;AAAA,MACF,MAAM,IAAI,IAAI;AAAA,MACd,OAAO,QAAQ,QAAQ;AAAA,GAAwB,WAAW;AAAA,QACxD,eAAe;AAAA,QACf,WAAW;AAAA,QACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD,OAAO,OAAO;AAAA,MACd,OAAO,MAAM,QAAQ;AAAA,GAAqB,WAAW;AAAA,QACnD,eAAe;AAAA,QACf,WAAW;AAAA,QACX,WAAW;AAAA,MACb,CAAC;AAAA,MACD,OAAO,MAAM,KAAmB;AAAA,MAChC,QAAQ,KAAK,CAAC;AAAA;AAAA,EAElB;AAAA,EAEA,OAAO,QAAQ;AAAA;AAAA,GAAwC,WAAW;AAAA,IAChE,eAAe;AAAA,IACf,WAAW;AAAA,IACX,WAAW;AAAA,EACb,CAAC;AAAA;",
12
+ "debugId": "13D2C1D163E1472064756E2164756E21",
13
13
  "names": []
14
14
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ooneex/seeds",
3
3
  "description": "Database seeding framework for populating initial data, fixtures, and test datasets with execution logging and idempotent operations",
4
- "version": "1.2.4",
4
+ "version": "1.3.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -28,12 +28,12 @@
28
28
  "npm:publish": "bun publish --tolerate-republish --force --production --access public"
29
29
  },
30
30
  "dependencies": {
31
- "@ooneex/container": "1.1.2",
32
- "@ooneex/logger": "1.2.3",
33
- "@ooneex/utils": "0.4.0"
31
+ "@ooneex/container": "1.2.3",
32
+ "@ooneex/logger": "1.2.7",
33
+ "@ooneex/utils": "0.4.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@ooneex/exception": "1.1.2"
36
+ "@ooneex/exception": "1.2.1"
37
37
  },
38
38
  "keywords": [
39
39
  "bun",