@ooneex/seeds 0.0.1 → 0.4.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 +6 -3
- package/dist/index.js +12 -14
- package/dist/index.js.map +5 -5
- package/package.json +13 -7
- package/dist/ooneex-seeds-0.0.1.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ interface ISeed {
|
|
|
5
5
|
isActive: () => Promise<boolean> | boolean;
|
|
6
6
|
getDependencies: () => Promise<SeedClassType[]> | SeedClassType[];
|
|
7
7
|
}
|
|
8
|
-
declare const
|
|
8
|
+
declare const decorator: {
|
|
9
|
+
seed: (scope?: EContainerScope) => (target: SeedClassType) => void;
|
|
10
|
+
};
|
|
9
11
|
declare const getSeeds: () => ISeed[];
|
|
10
12
|
declare const seedCreate: (config: {
|
|
13
|
+
name: string;
|
|
11
14
|
dir?: string;
|
|
12
|
-
}) => Promise<
|
|
15
|
+
}) => Promise<string>;
|
|
13
16
|
declare const seedRun: () => Promise<void>;
|
|
14
|
-
export { seedRun, seedCreate,
|
|
17
|
+
export { seedRun, seedCreate, getSeeds, decorator, SeedClassType, ISeed };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{container as l,EContainerScope as f}from"@ooneex/container";var n=[];var u={seed:(o=f.Singleton)=>{return(e)=>{l.add(e,o),n.push(e)}}};import{container as S}from"@ooneex/container";var i=()=>{return n.map((e)=>{return S.get(e)}).filter((e)=>e.isActive())};import{join as a}from"path";import{toPascalCase as w}from"@ooneex/utils";var{Glob:T}=globalThis.Bun;var d=`import { decorator, type ISeed, type SeedClassType } from "@ooneex/seeds";
|
|
3
3
|
|
|
4
|
-
@seed()
|
|
4
|
+
@decorator.seed()
|
|
5
5
|
export class {{ name }} implements ISeed {
|
|
6
|
-
public async run<T>(data?:
|
|
6
|
+
public async run<T>(data?: unknown[]): Promise<T> {
|
|
7
7
|
// Your seed logic here
|
|
8
8
|
// console.log('{{ name }}!');
|
|
9
9
|
|
|
@@ -18,17 +18,15 @@ export class {{ name }} implements ISeed {
|
|
|
18
18
|
return [];
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
`;var
|
|
22
|
-
`),process.exit(1);let s=`${E(e.name)}Seed`,t=o?.dir||"seeds";await Bun.write(m(t,`${s}.ts`),c.replaceAll("{{ name }}",s));let a=[],l=new I("**/*Seed.ts");for await(let u of l.scan(t)){let p=u.replace(/\.ts$/,"");a.push(`export { ${p} } from './${p}';`)}await Bun.write(m(t,"index.ts"),`${a.sort().join(`
|
|
21
|
+
`;var g=async(o)=>{let e=`${w(o.name)}Seed`,s=o.dir||"seeds";await Bun.write(a(process.cwd(),s,`${e}.ts`),d.replaceAll("{{ name }}",e));let r=[],t=new T("**/*Seed.ts");for await(let c of t.scan(s)){let p=c.replace(/\.ts$/,"");r.push(`export { ${p} } from './${p}';`)}return await Bun.write(a(process.cwd(),s,"seeds.ts"),`${r.sort().join(`
|
|
23
22
|
`)}
|
|
24
|
-
`),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
`),e.error(t),process.exit(1)}}e.success(`
|
|
23
|
+
`),a(s,`${e}.ts`)};import{container as x}from"@ooneex/container";import{TerminalLogger as h}from"@ooneex/logger";var m=async(o)=>{let e=[],s=await o.getDependencies();for(let r of s){let t=x.get(r);e.push(await m(t))}await o.run(e)},C=async()=>{let o=i(),e=new h;if(o.length===0){e.info(`No seeds found
|
|
24
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0});return}e.info(`Running ${o.length} seed(s)...
|
|
25
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0});for(let s of o){let r=s.constructor.name;if(!s.isActive()){e.warn(`Seed ${r} is inactive
|
|
26
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0});continue}try{await m(s),e.success(`Seed ${r} completed
|
|
27
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0})}catch(t){e.error(`Seed ${r} failed
|
|
28
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0}),e.error(t),process.exit(1)}}e.success(`
|
|
31
29
|
All seeds completed successfully
|
|
32
|
-
|
|
30
|
+
`,void 0,{showTimestamp:!1,showArrow:!1,useSymbol:!0})};export{C as seedRun,g as seedCreate,i as getSeeds,u as decorator};
|
|
33
31
|
|
|
34
|
-
//# debugId=
|
|
32
|
+
//# debugId=37A71979F4BD9CF264756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/decorators.ts", "src/container.ts", "src/getSeeds.ts", "src/seedCreate.ts", "src/seedRun.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import {
|
|
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 {
|
|
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\");\n return;\n }\n\n logger.info(`Running ${seeds.length} seed(s)...\\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",
|
|
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,
|
|
12
|
-
"debugId": "
|
|
11
|
+
"mappings": ";AAAA,oBAAS,qBAAW,0BCEb,IAAM,EAAmC,CAAC,EDE1C,IAAM,EAAY,CACvB,KAAM,CAAC,EAAyB,EAAgB,YAAc,CAC5D,MAAO,CAAC,IAAgC,CACtC,EAAU,IAAI,EAAQ,CAAK,EAC3B,EAAgB,KAAK,CAAM,GAGjC,EEXA,oBAAS,0BAIF,IAAM,EAAW,IAAe,CAKrC,OAJsB,EAAgB,IAAI,CAAC,IAAc,CACvD,OAAO,EAAU,IAAI,CAAS,EAC/B,EAEoB,OAAO,CAAC,IAAS,EAAK,SAAS,CAAC,GCTvD,eAAS,aACT,uBAAS,sBACT;;;;;;;;;;;;;;;;;;;EAGO,IAAM,EAAa,MAAO,IAA4D,CAC3F,IAAM,EAAO,GAAG,EAAa,EAAO,IAAI,QAClC,EAAW,EAAO,KAAO,QAE/B,MAAM,IAAI,MAAM,EAAK,QAAQ,IAAI,EAAG,EAAU,GAAG,MAAS,EAAG,EAAQ,WAAW,aAAc,CAAI,CAAC,E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qB,OAAW,CACnD,cAAe,GACf,UAAW,GACX,UAAW,EACb,CAAC,EACD,EAAO,MAAM,CAAmB,EAChC,QAAQ,KAAK,CAAC,GAIlB,EAAO,QAAQ;AAAA;AAAA,EAAwC,OAAW,CAChE,cAAe,GACf,UAAW,GACX,UAAW,EACb,CAAC",
|
|
12
|
+
"debugId": "37A71979F4BD9CF264756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ooneex/seeds",
|
|
3
|
-
"description": "",
|
|
4
|
-
"version": "0.0
|
|
3
|
+
"description": "Database seeding utilities for populating initial and test data with logging support",
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -25,17 +25,23 @@
|
|
|
25
25
|
"test": "bun test tests",
|
|
26
26
|
"build": "bunup",
|
|
27
27
|
"lint": "tsgo --noEmit && bunx biome lint",
|
|
28
|
-
"publish
|
|
29
|
-
"publish:pack": "bun pm pack --destination ./dist",
|
|
30
|
-
"publish:dry": "bun publish --dry-run"
|
|
28
|
+
"npm:publish": "bun publish --tolerate-republish --access public"
|
|
31
29
|
},
|
|
32
30
|
"dependencies": {
|
|
33
|
-
"@ooneex/container": "0.0.
|
|
31
|
+
"@ooneex/container": "0.0.2",
|
|
34
32
|
"@ooneex/logger": "0.0.1",
|
|
35
33
|
"@ooneex/utils": "0.0.8"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@ooneex/exception": "0.0.1"
|
|
39
37
|
},
|
|
40
|
-
"
|
|
38
|
+
"keywords": [
|
|
39
|
+
"bun",
|
|
40
|
+
"database",
|
|
41
|
+
"fixtures",
|
|
42
|
+
"ooneex",
|
|
43
|
+
"seeding",
|
|
44
|
+
"seeds",
|
|
45
|
+
"typescript"
|
|
46
|
+
]
|
|
41
47
|
}
|
|
Binary file
|