noxium 1.0.14 → 1.0.16

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.
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ var k=Object.create;var{getPrototypeOf:q,defineProperty:p,getOwnPropertyNames:N,getOwnPropertyDescriptor:S}=Object,g=Object.prototype.hasOwnProperty;function y(e){return this[e]}var I,D,M=(e,i,r)=>{var o=e!=null&&typeof e==="object";if(o){var l=i?I??=new WeakMap:D??=new WeakMap,u=l.get(e);if(u)return u}r=e!=null?k(q(e)):{};let m=i||!e||!e.__esModule||!g.call(e,"default")?p(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let d of N(e))if(!g.call(m,d))p(m,d,{get:y.bind(e,d),enumerable:!0})}if(o)l.set(e,m);return m},P=(e)=>{var i=(v??=new WeakMap).get(e),r;if(i)return i;if(i=p({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var o of N(e))if(!g.call(i,o))p(i,o,{get:y.bind(e,o),enumerable:!(r=S(e,o))||r.enumerable})}return v.set(e,i),i},v;var T=(e)=>e;function _(e,i){this[e]=T.bind(null,i)}var A=(e,i)=>{for(var r in i)p(e,r,{get:i[r],enumerable:!0,configurable:!0,set:_.bind(i,r)})};var C={};A(C,{renderDatabaseIndex:()=>h,renderNoxiumConfig:()=>f});var c=require("node:fs"),s=require("node:path");function f(e){return`import type { NoxiumConfig, SchemasMap } from "noxium";
3
+
4
+ const schemas = {
5
+ users: {
6
+ fields: {
7
+ name: { type: String, required: true, trim: true },
8
+ email: {
9
+ type: String,
10
+ required: true,
11
+ unique: true,
12
+ lowercase: true,
13
+ trim: true,
14
+ },
15
+ role: { type: String, default: "member" },
16
+ },
17
+ },
18
+ } as const satisfies SchemasMap;
19
+
20
+ export type AppSchemas = typeof schemas;
21
+
22
+ export default function getConfig(): NoxiumConfig<AppSchemas> {
23
+ return {
24
+ ${e.driver==="mongo"?` database: {
25
+ type: "mongo",
26
+ mongo: {
27
+ uri: process.env.MONGO_URI || "${e.mongoUri}",
28
+ dbName: "${e.dbName}",
29
+ },
30
+ },`:` database: {
31
+ type: "sqlite",
32
+ sqlite: {
33
+ path: process.env.SQLITE_PATH || "${e.sqlitePath}",
34
+ },
35
+ },`}
36
+ schemas,
37
+ };
38
+ }
39
+ `}function h(e=["users"],i="../../noxium.config"){let r=e.map((o)=>`export const ${o}Model = noxium.model("${o}");`).join(`
40
+ `);return`import { Noxium } from "noxium";
41
+ import getConfig, { type AppSchemas } from "${i}";
42
+
43
+ declare global {
44
+ // eslint-disable-next-line no-var
45
+ var __noxiumInstance: Noxium<AppSchemas> | undefined;
46
+ }
47
+
48
+ function createNoxiumInstance(): Noxium<AppSchemas> {
49
+ return new Noxium<AppSchemas>(getConfig());
50
+ }
51
+
52
+ // Hanya 1 instance Noxium di seluruh aplikasi/proses
53
+ export const noxium: Noxium<AppSchemas> =
54
+ globalThis.__noxiumInstance ??
55
+ (globalThis.__noxiumInstance = createNoxiumInstance());
56
+
57
+ ${r}
58
+ `}function E(e){let i=e.slice(2),r=i[0],o="sqlite",l="app_db",u="./app.db",m="mongodb://localhost:27017/?retryWrites=true&w=majority",d="src/lib",b=!1,x=!1;for(let a=1;a<i.length;a++){let n=i[a];if(n==="--help"||n==="-h")x=!0;else if(n==="--force"||n==="-f")b=!0;else if(n==="--driver"){let t=i[++a];if(!t||t!=="sqlite"&&t!=="mongo")throw Error(`Driver tidak valid: "${t??""}". Gunakan "sqlite" atau "mongo".`);o=t}else if(n==="--db-name"){let t=i[++a];if(!t)throw Error("Nilai --db-name tidak boleh kosong.");l=t}else if(n==="--sqlite-path"){let t=i[++a];if(!t)throw Error("Nilai --sqlite-path tidak boleh kosong.");u=t}else if(n==="--mongo-uri"){let t=i[++a];if(!t)throw Error("Nilai --mongo-uri tidak boleh kosong.");m=t}else if(n==="--dir"){let t=i[++a];if(!t)throw Error("Nilai --dir tidak boleh kosong.");d=t}else throw Error(`Opsi tidak dikenal: ${n}`)}return{command:r,driver:o,dbName:l,sqlitePath:u,mongoUri:m,dbDir:d,force:b,help:x}}function U(){console.log(`Noxium CLI
59
+
60
+ Penggunaan:
61
+ noxium init [opsi]
62
+
63
+ Opsi:
64
+ --driver <sqlite|mongo> Pilih driver database (default: sqlite)
65
+ --db-name <nama_db> Nama database untuk driver mongo (default: app_db)
66
+ --sqlite-path <path> Path file SQLite default (default: ./app.db)
67
+ --mongo-uri <uri> URI cluster MongoDB default (default: mongodb://localhost:27017/?retryWrites=true&w=majority)
68
+ --dir <folder_db> Folder output file index instance (default: src/lib)
69
+ -f, --force Timpa file jika sudah ada
70
+ -h, --help Tampilkan bantuan ini`)}function w(e,i,r){if(c.existsSync(e)&&!r){console.log(`Lewati (sudah ada): ${e}`);return}c.mkdirSync(s.dirname(e),{recursive:!0}),c.writeFileSync(e,i,"utf8"),console.log(`Dibuat: ${e}`)}function O(e,i){let r=s.relative(s.dirname(e),i).replace(/\\/g,"/");return r=r.replace(/\.ts$/,""),r.startsWith(".")?r:`./${r}`}async function j(){let e=E(process.argv);if(e.help||!e.command)U(),process.exit(0);if(e.command!=="init")throw Error(`Perintah tidak dikenal: "${e.command}".`);let i=process.cwd(),r=s.join(i,"noxium.config.ts"),o=s.join(i,e.dbDir,"noxium.ts"),l=O(o,r);w(r,f({driver:e.driver,dbName:e.dbName,sqlitePath:e.sqlitePath,mongoUri:e.mongoUri}),e.force),w(o,h(["users"],l),e.force)}j().catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});
71
+
72
+ //# debugId=007806DD42F5C50A64756E2164756E21
73
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli/index.ts", "../src/cli/templates.ts"],
4
+ "sourcesContent": [
5
+ "#!/usr/bin/env node\n\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport {\n renderDatabaseIndex,\n renderNoxiumConfig,\n type DriverType,\n} from \"./templates\";\n\ninterface ParsedCliArgs {\n command: string | undefined;\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n dbDir: string;\n force: boolean;\n help: boolean;\n}\n\nfunction parseArgs(argv: string[]): ParsedCliArgs {\n const args = argv.slice(2);\n const command = args[0];\n\n let driver: DriverType = \"sqlite\";\n let dbName = \"app_db\";\n let sqlitePath = \"./app.db\";\n let mongoUri = \"mongodb://localhost:27017/?retryWrites=true&w=majority\";\n let dbDir = \"src/lib\";\n let force = false;\n let help = false;\n\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n\n if (arg === \"--help\" || arg === \"-h\") {\n help = true;\n } else if (arg === \"--force\" || arg === \"-f\") {\n force = true;\n } else if (arg === \"--driver\") {\n const value = args[++i];\n if (!value || (value !== \"sqlite\" && value !== \"mongo\")) {\n throw new Error(\n `Driver tidak valid: \"${value ?? \"\"}\". Gunakan \"sqlite\" atau \"mongo\".`,\n );\n }\n driver = value;\n } else if (arg === \"--db-name\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --db-name tidak boleh kosong.\");\n }\n dbName = value;\n } else if (arg === \"--sqlite-path\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --sqlite-path tidak boleh kosong.\");\n }\n sqlitePath = value;\n } else if (arg === \"--mongo-uri\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --mongo-uri tidak boleh kosong.\");\n }\n mongoUri = value;\n } else if (arg === \"--dir\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --dir tidak boleh kosong.\");\n }\n dbDir = value;\n } else {\n throw new Error(`Opsi tidak dikenal: ${arg}`);\n }\n }\n\n return {\n command,\n driver,\n dbName,\n sqlitePath,\n mongoUri,\n dbDir,\n force,\n help,\n };\n}\n\nfunction printHelp(): void {\n console.log(`Noxium CLI\n\nPenggunaan:\n noxium init [opsi]\n\nOpsi:\n --driver <sqlite|mongo> Pilih driver database (default: sqlite)\n --db-name <nama_db> Nama database untuk driver mongo (default: app_db)\n --sqlite-path <path> Path file SQLite default (default: ./app.db)\n --mongo-uri <uri> URI cluster MongoDB default (default: mongodb://localhost:27017/?retryWrites=true&w=majority)\n --dir <folder_db> Folder output file index instance (default: src/lib)\n -f, --force Timpa file jika sudah ada\n -h, --help Tampilkan bantuan ini`);\n}\n\nfunction writeFileSafe(\n filePath: string,\n content: string,\n force: boolean,\n): void {\n if (existsSync(filePath) && !force) {\n console.log(`Lewati (sudah ada): ${filePath}`);\n return;\n }\n\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf8\");\n console.log(`Dibuat: ${filePath}`);\n}\n\nfunction resolveRelativeImport(fromFile: string, targetFile: string): string {\n let rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n rel = rel.replace(/\\.ts$/, \"\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv);\n\n if (parsed.help || !parsed.command) {\n printHelp();\n process.exit(0);\n }\n\n if (parsed.command !== \"init\") {\n throw new Error(`Perintah tidak dikenal: \"${parsed.command}\".`);\n }\n\n const cwd = process.cwd();\n const configPath = join(cwd, \"noxium.config.ts\");\n const indexPath = join(cwd, parsed.dbDir, \"noxium.ts\");\n const configImportPath = resolveRelativeImport(indexPath, configPath);\n\n writeFileSafe(\n configPath,\n renderNoxiumConfig({\n driver: parsed.driver,\n dbName: parsed.dbName,\n sqlitePath: parsed.sqlitePath,\n mongoUri: parsed.mongoUri,\n }),\n parsed.force,\n );\n\n writeFileSafe(\n indexPath,\n renderDatabaseIndex([\"users\"], configImportPath),\n parsed.force,\n );\n}\n\nmain().catch((err) => {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n});\n",
6
+ "export type DriverType = \"sqlite\" | \"mongo\";\n\nexport interface InitTemplateOptions {\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n}\n\nexport function renderNoxiumConfig(options: InitTemplateOptions): string {\n const databaseBlock =\n options.driver === \"mongo\"\n ? ` database: {\n type: \"mongo\",\n mongo: {\n uri: process.env.MONGO_URI || \"${options.mongoUri}\",\n dbName: \"${options.dbName}\",\n },\n },`\n : ` database: {\n type: \"sqlite\",\n sqlite: {\n path: process.env.SQLITE_PATH || \"${options.sqlitePath}\",\n },\n },`;\n\n return `import type { NoxiumConfig, SchemasMap } from \"noxium\";\n\nconst schemas = {\n users: {\n fields: {\n name: { type: String, required: true, trim: true },\n email: {\n type: String,\n required: true,\n unique: true,\n lowercase: true,\n trim: true,\n },\n role: { type: String, default: \"member\" },\n },\n },\n} as const satisfies SchemasMap;\n\nexport type AppSchemas = typeof schemas;\n\nexport default function getConfig(): NoxiumConfig<AppSchemas> {\n return {\n${databaseBlock}\n schemas,\n };\n}\n`;\n}\n\nexport function renderDatabaseIndex(\n modelNames: string[] = [\"users\"],\n configImportPath = \"../../noxium.config\",\n): string {\n const modelExports = modelNames\n .map((name) => `export const ${name}Model = noxium.model(\"${name}\");`)\n .join(\"\\n\");\n\n return `import { Noxium } from \"noxium\";\nimport getConfig, { type AppSchemas } from \"${configImportPath}\";\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __noxiumInstance: Noxium<AppSchemas> | undefined;\n}\n\nfunction createNoxiumInstance(): Noxium<AppSchemas> {\n return new Noxium<AppSchemas>(getConfig());\n}\n\n// Hanya 1 instance Noxium di seluruh aplikasi/proses\nexport const noxium: Noxium<AppSchemas> =\n globalThis.__noxiumInstance ??\n (globalThis.__noxiumInstance = createNoxiumInstance());\n\n${modelExports}\n`;\n}\n"
7
+ ],
8
+ "mappings": ";ygCAEqD,IAArD,qBACA,uBCMO,SAAS,CAAkB,CAAC,EAAsC,CAiBvE,MAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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EpE,EACE,EACA,EAAmB,CACjB,OAAQ,EAAO,OACf,OAAQ,EAAO,OACf,WAAY,EAAO,WACnB,SAAU,EAAO,QACnB,CAAC,EACD,EAAO,KACT,EAEA,EACE,EACA,EAAoB,CAAC,OAAO,EAAG,CAAgB,EAC/C,EAAO,KACT,EAGF,EAAK,EAAE,MAAM,CAAC,IAAQ,CACpB,QAAQ,MAAM,aAAe,MAAQ,EAAI,QAAU,OAAO,CAAG,CAAC,EAC9D,QAAQ,KAAK,CAAC,EACf",
9
+ "debugId": "007806DD42F5C50A64756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ import{existsSync as x,mkdirSync as v,writeFileSync as N}from"node:fs";import{dirname as b,join as f,relative as y}from"node:path";function p(e){return`import type { NoxiumConfig, SchemasMap } from "noxium";
3
+
4
+ const schemas = {
5
+ users: {
6
+ fields: {
7
+ name: { type: String, required: true, trim: true },
8
+ email: {
9
+ type: String,
10
+ required: true,
11
+ unique: true,
12
+ lowercase: true,
13
+ trim: true,
14
+ },
15
+ role: { type: String, default: "member" },
16
+ },
17
+ },
18
+ } as const satisfies SchemasMap;
19
+
20
+ export type AppSchemas = typeof schemas;
21
+
22
+ export default function getConfig(): NoxiumConfig<AppSchemas> {
23
+ return {
24
+ ${e.driver==="mongo"?` database: {
25
+ type: "mongo",
26
+ mongo: {
27
+ uri: process.env.MONGO_URI || "${e.mongoUri}",
28
+ dbName: "${e.dbName}",
29
+ },
30
+ },`:` database: {
31
+ type: "sqlite",
32
+ sqlite: {
33
+ path: process.env.SQLITE_PATH || "${e.sqlitePath}",
34
+ },
35
+ },`}
36
+ schemas,
37
+ };
38
+ }
39
+ `}function g(e=["users"],i="../../noxium.config"){let t=e.map((n)=>`export const ${n}Model = noxium.model("${n}");`).join(`
40
+ `);return`import { Noxium } from "noxium";
41
+ import getConfig, { type AppSchemas } from "${i}";
42
+
43
+ declare global {
44
+ // eslint-disable-next-line no-var
45
+ var __noxiumInstance: Noxium<AppSchemas> | undefined;
46
+ }
47
+
48
+ function createNoxiumInstance(): Noxium<AppSchemas> {
49
+ return new Noxium<AppSchemas>(getConfig());
50
+ }
51
+
52
+ // Hanya 1 instance Noxium di seluruh aplikasi/proses
53
+ export const noxium: Noxium<AppSchemas> =
54
+ globalThis.__noxiumInstance ??
55
+ (globalThis.__noxiumInstance = createNoxiumInstance());
56
+
57
+ ${t}
58
+ `}function w(e){let i=e.slice(2),t=i[0],n="sqlite",s="app_db",l="./app.db",m="mongodb://localhost:27017/?retryWrites=true&w=majority",d="src/lib",c=!1,u=!1;for(let a=1;a<i.length;a++){let o=i[a];if(o==="--help"||o==="-h")u=!0;else if(o==="--force"||o==="-f")c=!0;else if(o==="--driver"){let r=i[++a];if(!r||r!=="sqlite"&&r!=="mongo")throw Error(`Driver tidak valid: "${r??""}". Gunakan "sqlite" atau "mongo".`);n=r}else if(o==="--db-name"){let r=i[++a];if(!r)throw Error("Nilai --db-name tidak boleh kosong.");s=r}else if(o==="--sqlite-path"){let r=i[++a];if(!r)throw Error("Nilai --sqlite-path tidak boleh kosong.");l=r}else if(o==="--mongo-uri"){let r=i[++a];if(!r)throw Error("Nilai --mongo-uri tidak boleh kosong.");m=r}else if(o==="--dir"){let r=i[++a];if(!r)throw Error("Nilai --dir tidak boleh kosong.");d=r}else throw Error(`Opsi tidak dikenal: ${o}`)}return{command:t,driver:n,dbName:s,sqlitePath:l,mongoUri:m,dbDir:d,force:c,help:u}}function k(){console.log(`Noxium CLI
59
+
60
+ Penggunaan:
61
+ noxium init [opsi]
62
+
63
+ Opsi:
64
+ --driver <sqlite|mongo> Pilih driver database (default: sqlite)
65
+ --db-name <nama_db> Nama database untuk driver mongo (default: app_db)
66
+ --sqlite-path <path> Path file SQLite default (default: ./app.db)
67
+ --mongo-uri <uri> URI cluster MongoDB default (default: mongodb://localhost:27017/?retryWrites=true&w=majority)
68
+ --dir <folder_db> Folder output file index instance (default: src/lib)
69
+ -f, --force Timpa file jika sudah ada
70
+ -h, --help Tampilkan bantuan ini`)}function h(e,i,t){if(x(e)&&!t){console.log(`Lewati (sudah ada): ${e}`);return}v(b(e),{recursive:!0}),N(e,i,"utf8"),console.log(`Dibuat: ${e}`)}function q(e,i){let t=y(b(e),i).replace(/\\/g,"/");return t=t.replace(/\.ts$/,""),t.startsWith(".")?t:`./${t}`}async function S(){let e=w(process.argv);if(e.help||!e.command)k(),process.exit(0);if(e.command!=="init")throw Error(`Perintah tidak dikenal: "${e.command}".`);let i=process.cwd(),t=f(i,"noxium.config.ts"),n=f(i,e.dbDir,"noxium.ts"),s=q(n,t);h(t,p({driver:e.driver,dbName:e.dbName,sqlitePath:e.sqlitePath,mongoUri:e.mongoUri}),e.force),h(n,g(["users"],s),e.force)}S().catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});
71
+
72
+ //# debugId=CB9E518B0983C3F764756E2164756E21
73
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli/index.ts", "../src/cli/templates.ts"],
4
+ "sourcesContent": [
5
+ "#!/usr/bin/env node\n\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative } from \"node:path\";\nimport {\n renderDatabaseIndex,\n renderNoxiumConfig,\n type DriverType,\n} from \"./templates\";\n\ninterface ParsedCliArgs {\n command: string | undefined;\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n dbDir: string;\n force: boolean;\n help: boolean;\n}\n\nfunction parseArgs(argv: string[]): ParsedCliArgs {\n const args = argv.slice(2);\n const command = args[0];\n\n let driver: DriverType = \"sqlite\";\n let dbName = \"app_db\";\n let sqlitePath = \"./app.db\";\n let mongoUri = \"mongodb://localhost:27017/?retryWrites=true&w=majority\";\n let dbDir = \"src/lib\";\n let force = false;\n let help = false;\n\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n\n if (arg === \"--help\" || arg === \"-h\") {\n help = true;\n } else if (arg === \"--force\" || arg === \"-f\") {\n force = true;\n } else if (arg === \"--driver\") {\n const value = args[++i];\n if (!value || (value !== \"sqlite\" && value !== \"mongo\")) {\n throw new Error(\n `Driver tidak valid: \"${value ?? \"\"}\". Gunakan \"sqlite\" atau \"mongo\".`,\n );\n }\n driver = value;\n } else if (arg === \"--db-name\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --db-name tidak boleh kosong.\");\n }\n dbName = value;\n } else if (arg === \"--sqlite-path\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --sqlite-path tidak boleh kosong.\");\n }\n sqlitePath = value;\n } else if (arg === \"--mongo-uri\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --mongo-uri tidak boleh kosong.\");\n }\n mongoUri = value;\n } else if (arg === \"--dir\") {\n const value = args[++i];\n if (!value) {\n throw new Error(\"Nilai --dir tidak boleh kosong.\");\n }\n dbDir = value;\n } else {\n throw new Error(`Opsi tidak dikenal: ${arg}`);\n }\n }\n\n return {\n command,\n driver,\n dbName,\n sqlitePath,\n mongoUri,\n dbDir,\n force,\n help,\n };\n}\n\nfunction printHelp(): void {\n console.log(`Noxium CLI\n\nPenggunaan:\n noxium init [opsi]\n\nOpsi:\n --driver <sqlite|mongo> Pilih driver database (default: sqlite)\n --db-name <nama_db> Nama database untuk driver mongo (default: app_db)\n --sqlite-path <path> Path file SQLite default (default: ./app.db)\n --mongo-uri <uri> URI cluster MongoDB default (default: mongodb://localhost:27017/?retryWrites=true&w=majority)\n --dir <folder_db> Folder output file index instance (default: src/lib)\n -f, --force Timpa file jika sudah ada\n -h, --help Tampilkan bantuan ini`);\n}\n\nfunction writeFileSafe(\n filePath: string,\n content: string,\n force: boolean,\n): void {\n if (existsSync(filePath) && !force) {\n console.log(`Lewati (sudah ada): ${filePath}`);\n return;\n }\n\n mkdirSync(dirname(filePath), { recursive: true });\n writeFileSync(filePath, content, \"utf8\");\n console.log(`Dibuat: ${filePath}`);\n}\n\nfunction resolveRelativeImport(fromFile: string, targetFile: string): string {\n let rel = relative(dirname(fromFile), targetFile).replace(/\\\\/g, \"/\");\n rel = rel.replace(/\\.ts$/, \"\");\n return rel.startsWith(\".\") ? rel : `./${rel}`;\n}\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv);\n\n if (parsed.help || !parsed.command) {\n printHelp();\n process.exit(0);\n }\n\n if (parsed.command !== \"init\") {\n throw new Error(`Perintah tidak dikenal: \"${parsed.command}\".`);\n }\n\n const cwd = process.cwd();\n const configPath = join(cwd, \"noxium.config.ts\");\n const indexPath = join(cwd, parsed.dbDir, \"noxium.ts\");\n const configImportPath = resolveRelativeImport(indexPath, configPath);\n\n writeFileSafe(\n configPath,\n renderNoxiumConfig({\n driver: parsed.driver,\n dbName: parsed.dbName,\n sqlitePath: parsed.sqlitePath,\n mongoUri: parsed.mongoUri,\n }),\n parsed.force,\n );\n\n writeFileSafe(\n indexPath,\n renderDatabaseIndex([\"users\"], configImportPath),\n parsed.force,\n );\n}\n\nmain().catch((err) => {\n console.error(err instanceof Error ? err.message : String(err));\n process.exit(1);\n});\n",
6
+ "export type DriverType = \"sqlite\" | \"mongo\";\n\nexport interface InitTemplateOptions {\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n}\n\nexport function renderNoxiumConfig(options: InitTemplateOptions): string {\n const databaseBlock =\n options.driver === \"mongo\"\n ? ` database: {\n type: \"mongo\",\n mongo: {\n uri: process.env.MONGO_URI || \"${options.mongoUri}\",\n dbName: \"${options.dbName}\",\n },\n },`\n : ` database: {\n type: \"sqlite\",\n sqlite: {\n path: process.env.SQLITE_PATH || \"${options.sqlitePath}\",\n },\n },`;\n\n return `import type { NoxiumConfig, SchemasMap } from \"noxium\";\n\nconst schemas = {\n users: {\n fields: {\n name: { type: String, required: true, trim: true },\n email: {\n type: String,\n required: true,\n unique: true,\n lowercase: true,\n trim: true,\n },\n role: { type: String, default: \"member\" },\n },\n },\n} as const satisfies SchemasMap;\n\nexport type AppSchemas = typeof schemas;\n\nexport default function getConfig(): NoxiumConfig<AppSchemas> {\n return {\n${databaseBlock}\n schemas,\n };\n}\n`;\n}\n\nexport function renderDatabaseIndex(\n modelNames: string[] = [\"users\"],\n configImportPath = \"../../noxium.config\",\n): string {\n const modelExports = modelNames\n .map((name) => `export const ${name}Model = noxium.model(\"${name}\");`)\n .join(\"\\n\");\n\n return `import { Noxium } from \"noxium\";\nimport getConfig, { type AppSchemas } from \"${configImportPath}\";\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __noxiumInstance: Noxium<AppSchemas> | undefined;\n}\n\nfunction createNoxiumInstance(): Noxium<AppSchemas> {\n return new Noxium<AppSchemas>(getConfig());\n}\n\n// Hanya 1 instance Noxium di seluruh aplikasi/proses\nexport const noxium: Noxium<AppSchemas> =\n globalThis.__noxiumInstance ??\n (globalThis.__noxiumInstance = createNoxiumInstance());\n\n${modelExports}\n`;\n}\n"
7
+ ],
8
+ "mappings": ";AAEA,qBAAS,eAAY,mBAAW,gBAChC,kBAAS,UAAS,cAAM,kBCMjB,SAAS,CAAkB,CAAC,EAAsC,CAiBvE,MAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAfL,EAAQ,SAAW,QACf;AAAA;AAAA;AAAA,yCAGiC,EAAQ;AAAA,mBAC9B,EAAQ;AAAA;AAAA,QAGnB;AAAA;AAAA;AAAA,4CAGoC,EAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiC7C,SAAS,CAAmB,CACjC,EAAuB,CAAC,OAAO,EAC/B,E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AQ,EAAI,QAAU,OAAO,CAAG,CAAC,EAC9D,QAAQ,KAAK,CAAC,EACf",
9
+ "debugId": "CB9E518B0983C3F764756E2164756E21",
10
+ "names": []
11
+ }
@@ -0,0 +1,60 @@
1
+ var x=Object.create;var{getPrototypeOf:g,defineProperty:o,getOwnPropertyNames:c,getOwnPropertyDescriptor:d}=Object,a=Object.prototype.hasOwnProperty;function l(e){return this[e]}var f,h,A=(e,t,n)=>{var i=e!=null&&typeof e==="object";if(i){var m=t?f??=new WeakMap:h??=new WeakMap,p=m.get(e);if(p)return p}n=e!=null?x(g(e)):{};let r=t||!e||!e.__esModule||!a.call(e,"default")?o(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let s of c(e))if(!a.call(r,s))o(r,s,{get:l.bind(e,s),enumerable:!0})}if(i)m.set(e,r);return r},N=(e)=>{var t=(u??=new WeakMap).get(e),n;if(t)return t;if(t=o({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var i of c(e))if(!a.call(t,i))o(t,i,{get:l.bind(e,i),enumerable:!(n=d(e,i))||n.enumerable})}return u.set(e,t),t},u;var b=(e)=>e;function y(e,t){this[e]=b.bind(null,t)}var S=(e,t)=>{for(var n in t)o(e,n,{get:t[n],enumerable:!0,configurable:!0,set:y.bind(t,n)})};var v={};S(v,{renderDatabaseIndex:()=>q,renderNoxiumConfig:()=>I});module.exports=N(v);function I(e){return`import type { NoxiumConfig, SchemasMap } from "noxium";
2
+
3
+ const schemas = {
4
+ users: {
5
+ fields: {
6
+ name: { type: String, required: true, trim: true },
7
+ email: {
8
+ type: String,
9
+ required: true,
10
+ unique: true,
11
+ lowercase: true,
12
+ trim: true,
13
+ },
14
+ role: { type: String, default: "member" },
15
+ },
16
+ },
17
+ } as const satisfies SchemasMap;
18
+
19
+ export type AppSchemas = typeof schemas;
20
+
21
+ export default function getConfig(): NoxiumConfig<AppSchemas> {
22
+ return {
23
+ ${e.driver==="mongo"?` database: {
24
+ type: "mongo",
25
+ mongo: {
26
+ uri: process.env.MONGO_URI || "${e.mongoUri}",
27
+ dbName: "${e.dbName}",
28
+ },
29
+ },`:` database: {
30
+ type: "sqlite",
31
+ sqlite: {
32
+ path: process.env.SQLITE_PATH || "${e.sqlitePath}",
33
+ },
34
+ },`}
35
+ schemas,
36
+ };
37
+ }
38
+ `}function q(e=["users"],t="../../noxium.config"){let n=e.map((i)=>`export const ${i}Model = noxium.model("${i}");`).join(`
39
+ `);return`import { Noxium } from "noxium";
40
+ import getConfig, { type AppSchemas } from "${t}";
41
+
42
+ declare global {
43
+ // eslint-disable-next-line no-var
44
+ var __noxiumInstance: Noxium<AppSchemas> | undefined;
45
+ }
46
+
47
+ function createNoxiumInstance(): Noxium<AppSchemas> {
48
+ return new Noxium<AppSchemas>(getConfig());
49
+ }
50
+
51
+ // Hanya 1 instance Noxium di seluruh aplikasi/proses
52
+ export const noxium: Noxium<AppSchemas> =
53
+ globalThis.__noxiumInstance ??
54
+ (globalThis.__noxiumInstance = createNoxiumInstance());
55
+
56
+ ${n}
57
+ `}
58
+
59
+ //# debugId=72905212E0CD55E064756E2164756E21
60
+ //# sourceMappingURL=templates.cjs.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli/templates.ts"],
4
+ "sourcesContent": [
5
+ "export type DriverType = \"sqlite\" | \"mongo\";\n\nexport interface InitTemplateOptions {\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n}\n\nexport function renderNoxiumConfig(options: InitTemplateOptions): string {\n const databaseBlock =\n options.driver === \"mongo\"\n ? ` database: {\n type: \"mongo\",\n mongo: {\n uri: process.env.MONGO_URI || \"${options.mongoUri}\",\n dbName: \"${options.dbName}\",\n },\n },`\n : ` database: {\n type: \"sqlite\",\n sqlite: {\n path: process.env.SQLITE_PATH || \"${options.sqlitePath}\",\n },\n },`;\n\n return `import type { NoxiumConfig, SchemasMap } from \"noxium\";\n\nconst schemas = {\n users: {\n fields: {\n name: { type: String, required: true, trim: true },\n email: {\n type: String,\n required: true,\n unique: true,\n lowercase: true,\n trim: true,\n },\n role: { type: String, default: \"member\" },\n },\n },\n} as const satisfies SchemasMap;\n\nexport type AppSchemas = typeof schemas;\n\nexport default function getConfig(): NoxiumConfig<AppSchemas> {\n return {\n${databaseBlock}\n schemas,\n };\n}\n`;\n}\n\nexport function renderDatabaseIndex(\n modelNames: string[] = [\"users\"],\n configImportPath = \"../../noxium.config\",\n): string {\n const modelExports = modelNames\n .map((name) => `export const ${name}Model = noxium.model(\"${name}\");`)\n .join(\"\\n\");\n\n return `import { Noxium } from \"noxium\";\nimport getConfig, { type AppSchemas } from \"${configImportPath}\";\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __noxiumInstance: Noxium<AppSchemas> | undefined;\n}\n\nfunction createNoxiumInstance(): Noxium<AppSchemas> {\n return new Noxium<AppSchemas>(getConfig());\n}\n\n// Hanya 1 instance Noxium di seluruh aplikasi/proses\nexport const noxium: Noxium<AppSchemas> =\n globalThis.__noxiumInstance ??\n (globalThis.__noxiumInstance = createNoxiumInstance());\n\n${modelExports}\n`;\n}\n"
6
+ ],
7
+ "mappings": "6hCASO,SAAS,CAAkB,CAAC,EAAsC,CAiBvE,MAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAfL,EAAQ,SAAW,QACf;AAAA;AAAA;AAAA,yCAGiC,EAAQ;AAAA,mBAC9B,EAAQ;AAAA;AAAA,QAGnB;AAAA;AAAA;AAAA,4CAGoC,EAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiC7C,SAAS,CAAmB,CACjC,EAAuB,CAAC,OAAO,EAC/B,EAAmB,sBACX,CACR,IAAM,EAAe,EAClB,IAAI,CAAC,IAAS,gBAAgB,0BAA6B,MAAS,EACpE,KAAK;AAAA,CAAI,EAEZ,MAAO;AAAA,8CACqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB5C;",
8
+ "debugId": "72905212E0CD55E064756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,10 @@
1
+ export type DriverType = "sqlite" | "mongo";
2
+ export interface InitTemplateOptions {
3
+ driver: DriverType;
4
+ dbName: string;
5
+ sqlitePath: string;
6
+ mongoUri: string;
7
+ }
8
+ export declare function renderNoxiumConfig(options: InitTemplateOptions): string;
9
+ export declare function renderDatabaseIndex(modelNames?: string[], configImportPath?: string): string;
10
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/cli/templates.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA4CvE;AAED,wBAAgB,mBAAmB,CACjC,UAAU,GAAE,MAAM,EAAc,EAChC,gBAAgB,SAAwB,GACvC,MAAM,CAwBR"}
@@ -0,0 +1,60 @@
1
+ function o(e){return`import type { NoxiumConfig, SchemasMap } from "noxium";
2
+
3
+ const schemas = {
4
+ users: {
5
+ fields: {
6
+ name: { type: String, required: true, trim: true },
7
+ email: {
8
+ type: String,
9
+ required: true,
10
+ unique: true,
11
+ lowercase: true,
12
+ trim: true,
13
+ },
14
+ role: { type: String, default: "member" },
15
+ },
16
+ },
17
+ } as const satisfies SchemasMap;
18
+
19
+ export type AppSchemas = typeof schemas;
20
+
21
+ export default function getConfig(): NoxiumConfig<AppSchemas> {
22
+ return {
23
+ ${e.driver==="mongo"?` database: {
24
+ type: "mongo",
25
+ mongo: {
26
+ uri: process.env.MONGO_URI || "${e.mongoUri}",
27
+ dbName: "${e.dbName}",
28
+ },
29
+ },`:` database: {
30
+ type: "sqlite",
31
+ sqlite: {
32
+ path: process.env.SQLITE_PATH || "${e.sqlitePath}",
33
+ },
34
+ },`}
35
+ schemas,
36
+ };
37
+ }
38
+ `}function r(e=["users"],t="../../noxium.config"){let i=e.map((n)=>`export const ${n}Model = noxium.model("${n}");`).join(`
39
+ `);return`import { Noxium } from "noxium";
40
+ import getConfig, { type AppSchemas } from "${t}";
41
+
42
+ declare global {
43
+ // eslint-disable-next-line no-var
44
+ var __noxiumInstance: Noxium<AppSchemas> | undefined;
45
+ }
46
+
47
+ function createNoxiumInstance(): Noxium<AppSchemas> {
48
+ return new Noxium<AppSchemas>(getConfig());
49
+ }
50
+
51
+ // Hanya 1 instance Noxium di seluruh aplikasi/proses
52
+ export const noxium: Noxium<AppSchemas> =
53
+ globalThis.__noxiumInstance ??
54
+ (globalThis.__noxiumInstance = createNoxiumInstance());
55
+
56
+ ${i}
57
+ `}export{r as renderDatabaseIndex,o as renderNoxiumConfig};
58
+
59
+ //# debugId=D8439331BC3C721864756E2164756E21
60
+ //# sourceMappingURL=templates.mjs.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli/templates.ts"],
4
+ "sourcesContent": [
5
+ "export type DriverType = \"sqlite\" | \"mongo\";\n\nexport interface InitTemplateOptions {\n driver: DriverType;\n dbName: string;\n sqlitePath: string;\n mongoUri: string;\n}\n\nexport function renderNoxiumConfig(options: InitTemplateOptions): string {\n const databaseBlock =\n options.driver === \"mongo\"\n ? ` database: {\n type: \"mongo\",\n mongo: {\n uri: process.env.MONGO_URI || \"${options.mongoUri}\",\n dbName: \"${options.dbName}\",\n },\n },`\n : ` database: {\n type: \"sqlite\",\n sqlite: {\n path: process.env.SQLITE_PATH || \"${options.sqlitePath}\",\n },\n },`;\n\n return `import type { NoxiumConfig, SchemasMap } from \"noxium\";\n\nconst schemas = {\n users: {\n fields: {\n name: { type: String, required: true, trim: true },\n email: {\n type: String,\n required: true,\n unique: true,\n lowercase: true,\n trim: true,\n },\n role: { type: String, default: \"member\" },\n },\n },\n} as const satisfies SchemasMap;\n\nexport type AppSchemas = typeof schemas;\n\nexport default function getConfig(): NoxiumConfig<AppSchemas> {\n return {\n${databaseBlock}\n schemas,\n };\n}\n`;\n}\n\nexport function renderDatabaseIndex(\n modelNames: string[] = [\"users\"],\n configImportPath = \"../../noxium.config\",\n): string {\n const modelExports = modelNames\n .map((name) => `export const ${name}Model = noxium.model(\"${name}\");`)\n .join(\"\\n\");\n\n return `import { Noxium } from \"noxium\";\nimport getConfig, { type AppSchemas } from \"${configImportPath}\";\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __noxiumInstance: Noxium<AppSchemas> | undefined;\n}\n\nfunction createNoxiumInstance(): Noxium<AppSchemas> {\n return new Noxium<AppSchemas>(getConfig());\n}\n\n// Hanya 1 instance Noxium di seluruh aplikasi/proses\nexport const noxium: Noxium<AppSchemas> =\n globalThis.__noxiumInstance ??\n (globalThis.__noxiumInstance = createNoxiumInstance());\n\n${modelExports}\n`;\n}\n"
6
+ ],
7
+ "mappings": "AASO,SAAS,CAAkB,CAAC,EAAsC,CAiBvE,MAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAfL,EAAQ,SAAW,QACf;AAAA;AAAA;AAAA,yCAGiC,EAAQ;AAAA,mBAC9B,EAAQ;AAAA;AAAA,QAGnB;AAAA;AAAA;AAAA,4CAGoC,EAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiC7C,SAAS,CAAmB,CACjC,EAAuB,CAAC,OAAO,EAC/B,EAAmB,sBACX,CACR,IAAM,EAAe,EAClB,IAAI,CAAC,IAAS,gBAAgB,0BAA6B,MAAS,EACpE,KAAK;AAAA,CAAI,EAEZ,MAAO;AAAA,8CACqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB5C;",
8
+ "debugId": "D8439331BC3C721864756E2164756E21",
9
+ "names": []
10
+ }
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "noxium",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Unified ORM for SQLite and MongoDB with TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/noxium.cjs",
7
7
  "module": "./dist/noxium.mjs",
8
8
  "types": "./dist/noxium.d.ts",
9
+ "bin": {
10
+ "noxium": "./dist/cli/index.mjs"
11
+ },
9
12
  "files": [
10
13
  "dist"
11
14
  ],
@@ -59,7 +62,6 @@
59
62
  },
60
63
  "dependencies": {
61
64
  "better-sqlite3": "^13.0.3",
62
- "glob": "^13.0.6",
63
65
  "mongoose": "^9.9.4"
64
66
  }
65
67
  }