@deessejs/collections 0.0.38 → 0.0.40
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/config/index.d.ts +1 -0
- package/dist/config/index.js +9 -23
- package/dist/drizzle/generate.js +7 -7
- package/dist/worker/index.js +4 -0
- package/package.json +1 -1
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defineConfig = void 0;
|
|
3
|
+
exports.getConfig = exports.defineConfig = void 0;
|
|
7
4
|
const node_postgres_1 = require("drizzle-orm/node-postgres");
|
|
8
|
-
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
// Fonction utilitaire SYNCHRONE
|
|
12
|
-
const writeSchemaFileSync = () => {
|
|
13
|
-
try {
|
|
14
|
-
const targetPath = path_1.default.join(process.cwd(), ".deesse", "schema.ts");
|
|
15
|
-
const targetDir = path_1.default.dirname(targetPath);
|
|
16
|
-
// mkdirSync et writeFileSync bloquent l'exécution jusqu'à la fin de l'écriture
|
|
17
|
-
(0, fs_1.mkdirSync)(targetDir, { recursive: true });
|
|
18
|
-
(0, fs_1.writeFileSync)(targetPath, "hey", "utf-8");
|
|
19
|
-
console.log(`[config] Schema written to: ${targetPath}`);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
console.error("[config] Failed to write schema file:", error);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
5
|
+
let _config;
|
|
25
6
|
const defineConfig = (config) => {
|
|
7
|
+
_config = config;
|
|
26
8
|
const db = (0, node_postgres_1.drizzle)(config.databaseUrl);
|
|
27
|
-
// On peut l'appeler sans await
|
|
28
|
-
writeSchemaFileSync();
|
|
29
9
|
return db;
|
|
30
10
|
};
|
|
31
11
|
exports.defineConfig = defineConfig;
|
|
12
|
+
const getConfig = () => {
|
|
13
|
+
if (!_config)
|
|
14
|
+
throw new Error("Config not defined");
|
|
15
|
+
return _config;
|
|
16
|
+
};
|
|
17
|
+
exports.getConfig = getConfig;
|
package/dist/drizzle/generate.js
CHANGED
|
@@ -21,15 +21,15 @@ const generateShadowSchema = (collections) => {
|
|
|
21
21
|
return ` ${name}: ${drizzleType},`;
|
|
22
22
|
})
|
|
23
23
|
.join("\n");
|
|
24
|
-
return `
|
|
25
|
-
export const ${col.slug} = p.pgTable("${col.slug}", {
|
|
26
|
-
${columns}
|
|
24
|
+
return `
|
|
25
|
+
export const ${col.slug} = p.pgTable("${col.slug}", {
|
|
26
|
+
${columns}
|
|
27
27
|
});`;
|
|
28
28
|
});
|
|
29
|
-
const schemaFileContent = `
|
|
30
|
-
import * as p from "drizzle-orm/pg-core";
|
|
31
|
-
|
|
32
|
-
${tablesCode.join("\n")}
|
|
29
|
+
const schemaFileContent = `
|
|
30
|
+
import * as p from "drizzle-orm/pg-core";
|
|
31
|
+
|
|
32
|
+
${tablesCode.join("\n")}
|
|
33
33
|
`;
|
|
34
34
|
fs_1.default.writeFileSync(SCHEMA_PATH, schemaFileContent);
|
|
35
35
|
console.log("[Deesse] Shadow schema generated at", SCHEMA_PATH);
|
package/dist/worker/index.js
CHANGED
|
@@ -5,8 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const generate_1 = require("../drizzle/generate");
|
|
9
|
+
const config_1 = require("../config");
|
|
8
10
|
const collectionsDir = path_1.default.join(process.cwd(), "src", "collections");
|
|
9
11
|
console.log(`[worker] Watching collections folder: ${collectionsDir}`);
|
|
12
|
+
const config = (0, config_1.getConfig)();
|
|
13
|
+
(0, generate_1.generateShadowSchema)(config.collections);
|
|
10
14
|
const watcher = chokidar_1.default.watch(collectionsDir, {
|
|
11
15
|
persistent: true,
|
|
12
16
|
ignoreInitial: false,
|