@nano-app/backend 0.8.2 → 0.9.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/README.md +17 -25
- package/build/Prisma-Dq-lYuz3.js +221 -0
- package/build/index.d.ts +136 -128
- package/build/index.js +314 -531
- package/build/nano-app.js +43 -38
- package/package.json +13 -13
package/build/nano-app.js
CHANGED
|
@@ -1,41 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
import { r as OFFICIAL_PLUGINS, t as Prisma } from "./Prisma-Dq-lYuz3.js";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
//#region bin/nano-app.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generates a Prisma client where nano-app reads it, as the startup does: for the build or the editor.
|
|
8
|
+
* nano-app generate the app's schema (src/prisma/schema.prisma)
|
|
9
|
+
* nano-app generate <name> an official plugin's, from the installed @nano-app/plugins
|
|
10
|
+
* nano-app generate <name> --schema <path>
|
|
11
|
+
*/
|
|
12
|
+
const [sCommand, ...aArgs] = process.argv.slice(2);
|
|
13
|
+
/** package.json of @nano-app/plugins: the project itself (its tests) or one in a node_modules */
|
|
14
|
+
function officialPackage() {
|
|
15
|
+
for (let sDir = process.cwd();; sDir = dirname(sDir)) {
|
|
16
|
+
const sOwn = join(sDir, "package.json");
|
|
17
|
+
if (existsSync(sOwn) && JSON.parse(readFileSync(sOwn, "utf-8")).name === "@nano-app/plugins") return sOwn;
|
|
18
|
+
const sInstalled = join(sDir, "node_modules", OFFICIAL_PLUGINS, "package.json");
|
|
19
|
+
if (existsSync(sInstalled)) return sInstalled;
|
|
20
|
+
if (dirname(sDir) === sDir) return void 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Schema of an official plugin: next to the entry @nano-app/plugins exports for it */
|
|
24
|
+
function pluginSchema(sName) {
|
|
25
|
+
const sPackage = officialPackage();
|
|
26
|
+
if (!sPackage) return `${OFFICIAL_PLUGINS} is not installed`;
|
|
27
|
+
const oExport = JSON.parse(readFileSync(sPackage, "utf-8")).exports["./*"];
|
|
28
|
+
const sTarget = oExport.import ?? oExport.default;
|
|
29
|
+
return join(dirname(sPackage), dirname(sTarget.replaceAll("*", sName)), "schema.prisma");
|
|
30
|
+
}
|
|
18
31
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
const dir = `${process.cwd()}/.nano-app/prisma-clients/${name}`;
|
|
33
|
-
mkdirSync(dir, { recursive: true });
|
|
34
|
-
writeFileSync(`${dir}/schema.prisma`, readFileSync(source, "utf-8").replace(/output\s*=\s*"[^"]*"/, 'output = "./generated"'));
|
|
35
|
-
prisma("generate", "--schema", `${dir}/schema.prisma`);
|
|
36
|
-
if (command === "push") prisma("db", "push", "--schema", `${dir}/schema.prisma`, "--url", process.env.DATABASE_URL ?? "", ...flags);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
process.exit(error?.status ?? 1);
|
|
32
|
+
if (sCommand !== "generate") throw new Error("[nano-app] [ERROR] Usage: nano-app generate [name] [--schema <path>]");
|
|
33
|
+
const iSchemaFlag = aArgs.indexOf("--schema");
|
|
34
|
+
const sSchemaFlag = iSchemaFlag >= 0 ? aArgs[iSchemaFlag + 1] : void 0;
|
|
35
|
+
const fnIsFlagPart = (iIndex) => iSchemaFlag >= 0 && (iIndex === iSchemaFlag || iIndex === iSchemaFlag + 1);
|
|
36
|
+
const sName = aArgs.find((_sArg, iIndex) => !fnIsFlagPart(iIndex));
|
|
37
|
+
const sDefault = sName ? pluginSchema(sName) : "src/prisma/schema.prisma";
|
|
38
|
+
const sSchema = sSchemaFlag ?? sDefault;
|
|
39
|
+
if (!existsSync(sSchema)) throw new Error(`[nano-app] [ERROR] "${sName ?? "app"}" has no schema: ${sSchema}`);
|
|
40
|
+
Prisma.generate(sName ?? "app", sSchema);
|
|
41
|
+
} catch (oError) {
|
|
42
|
+
console.error(oError.message);
|
|
43
|
+
process.exit(1);
|
|
41
44
|
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nano-app/backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Express server with file-convention routes, plugins and an optional PostgreSQL layer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"LICENSE"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"dev": "
|
|
19
|
+
"build": "tsdown",
|
|
20
|
+
"dev": "tsdown --watch",
|
|
21
21
|
"test": "tsx --env-file-if-exists=../.env --test tests/*.test.ts",
|
|
22
22
|
"prepublishOnly": "pnpm run build"
|
|
23
23
|
},
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">=
|
|
43
|
+
"node": ">=22"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"compression": "^1.8.
|
|
46
|
+
"compression": "^1.8.2",
|
|
47
47
|
"cors": "^2.8.6",
|
|
48
48
|
"dotenv": "^18.0.8",
|
|
49
49
|
"express": "^5.3.0",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"morgan": "^1.12.1"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@prisma/adapter-pg": "^7.
|
|
58
|
-
"@prisma/client": "^7.
|
|
57
|
+
"@prisma/adapter-pg": "^7.10.1",
|
|
58
|
+
"@prisma/client": "^7.10.1",
|
|
59
59
|
"pg": "^8.23.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependenciesMeta": {
|
|
@@ -70,19 +70,19 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@prisma/adapter-pg": "^7.
|
|
74
|
-
"@prisma/client": "^7.
|
|
73
|
+
"@prisma/adapter-pg": "^7.10.1",
|
|
74
|
+
"@prisma/client": "^7.10.1",
|
|
75
75
|
"@types/compression": "^1.8.1",
|
|
76
76
|
"@types/cors": "^2.8.19",
|
|
77
77
|
"@types/express": "^5.0.6",
|
|
78
78
|
"@types/morgan": "^1.9.10",
|
|
79
|
-
"@types/node": "^
|
|
79
|
+
"@types/node": "^26.6.5",
|
|
80
80
|
"@types/pg": "^8.20.0",
|
|
81
81
|
"pg": "^8.23.1",
|
|
82
|
-
"prisma": "^7.
|
|
83
|
-
"
|
|
82
|
+
"prisma": "^7.10.1",
|
|
83
|
+
"tsdown": "^0.23.1",
|
|
84
84
|
"tsx": "^4.23.15",
|
|
85
|
-
"typescript": "^
|
|
85
|
+
"typescript": "^7.0.2"
|
|
86
86
|
},
|
|
87
87
|
"bin": {
|
|
88
88
|
"nano-app": "build/nano-app.js"
|