@deessejs/collections 0.0.45 → 0.0.46
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 +0 -1
- package/dist/config/index.js +6 -10
- package/dist/next/index.js +21 -2
- package/dist/worker/index.js +48 -5
- package/package.json +2 -1
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defineConfig = void 0;
|
|
4
|
+
// src/core/index.ts (ou là où est défini defineConfig)
|
|
4
5
|
const node_postgres_1 = require("drizzle-orm/node-postgres");
|
|
5
|
-
let _config;
|
|
6
6
|
const defineConfig = (config) => {
|
|
7
|
-
_config = config;
|
|
8
7
|
const db = (0, node_postgres_1.drizzle)(config.databaseUrl);
|
|
8
|
+
// Astuce : on attache la config brute à l'objet retourné.
|
|
9
|
+
// Cela permet au worker de lire "db._config.collections" plus tard.
|
|
10
|
+
// On le type en "any" ou on étend le type de retour pour éviter les erreurs TS.
|
|
11
|
+
db._config = config;
|
|
9
12
|
return db;
|
|
10
13
|
};
|
|
11
14
|
exports.defineConfig = defineConfig;
|
|
12
|
-
const waitConfig = async () => {
|
|
13
|
-
while (!_config) {
|
|
14
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
15
|
-
}
|
|
16
|
-
return _config;
|
|
17
|
-
};
|
|
18
|
-
exports.waitConfig = waitConfig;
|
package/dist/next/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.withCollections = void 0;
|
|
7
|
+
// src/next/index.ts (votre withCollections)
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
8
9
|
const constants_1 = require("next/constants");
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
@@ -11,14 +12,32 @@ const withCollections = (phase, config) => {
|
|
|
11
12
|
const isDev = phase === constants_1.PHASE_DEVELOPMENT_SERVER;
|
|
12
13
|
if (isDev && !global.__collections_worker_started) {
|
|
13
14
|
global.__collections_worker_started = true;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
// Attention : Assurez-vous que ce chemin pointe vers le fichier JS compilé de votre lib
|
|
16
|
+
// Si vous êtes en monorepo/dev local sur la lib, pointez vers le TS avec ts-node ou bun
|
|
17
|
+
const workerPath = path_1.default.resolve(__dirname, "../worker/index.js");
|
|
18
|
+
console.log("[Deesse] Spawning background worker:", workerPath);
|
|
16
19
|
(0, child_process_1.spawn)("node", [workerPath], {
|
|
17
20
|
stdio: "inherit",
|
|
21
|
+
env: {
|
|
22
|
+
...process.env,
|
|
23
|
+
// Variables d'env utiles pour le worker
|
|
24
|
+
NODE_ENV: "development",
|
|
25
|
+
}
|
|
18
26
|
});
|
|
19
27
|
}
|
|
28
|
+
// On ajoute un alias webpack pour que l'utilisateur puisse importer
|
|
29
|
+
// le schéma généré facilement s'il en a besoin,
|
|
30
|
+
// ou pour que Drizzle trouve le fichier généré.
|
|
20
31
|
return {
|
|
21
32
|
...config,
|
|
33
|
+
webpack: (webpackConfig, options) => {
|
|
34
|
+
if (config.webpack) {
|
|
35
|
+
webpackConfig = config.webpack(webpackConfig, options);
|
|
36
|
+
}
|
|
37
|
+
// Exemple : alias pour accéder au dossier shadow facilement
|
|
38
|
+
webpackConfig.resolve.alias["@deesse/schema"] = path_1.default.join(process.cwd(), ".deesse/shadow/schema");
|
|
39
|
+
return webpackConfig;
|
|
40
|
+
}
|
|
22
41
|
};
|
|
23
42
|
};
|
|
24
43
|
exports.withCollections = withCollections;
|
package/dist/worker/index.js
CHANGED
|
@@ -3,9 +3,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// src/worker/index.ts
|
|
7
|
+
const jiti_1 = require("jiti");
|
|
6
8
|
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const chokidar_1 = __importDefault(require("chokidar"));
|
|
10
|
+
const generate_1 = require("../drizzle/generate"); // Votre fonction de génération existante
|
|
11
|
+
const PROJECT_ROOT = process.cwd();
|
|
12
|
+
const CONFIG_PATH = path_1.default.join(PROJECT_ROOT, "src", "api", "index.ts");
|
|
13
|
+
const COLLECTIONS_DIR = path_1.default.join(PROJECT_ROOT, "src", "collections");
|
|
14
|
+
// Initialiser Jiti pour lire du TS directement
|
|
15
|
+
const jiti = (0, jiti_1.createJiti)(PROJECT_ROOT, {
|
|
16
|
+
interopDefault: true,
|
|
17
|
+
requireCache: false, // Important pour recharger quand le fichier change
|
|
18
|
+
});
|
|
19
|
+
async function runGenerator() {
|
|
20
|
+
try {
|
|
21
|
+
console.log("[Deesse] 🛠️ Generating schema...");
|
|
22
|
+
// 1. On vide le cache de jiti pour être sûr d'avoir la dernière version
|
|
23
|
+
// jiti gère le cache automatiquement mais on peut forcer si besoin selon la version
|
|
24
|
+
// 2. On charge le fichier de config utilisateur
|
|
25
|
+
// Jiti va compiler le TS à la volée.
|
|
26
|
+
const mod = await jiti.import(CONFIG_PATH);
|
|
27
|
+
// 3. On récupère la config
|
|
28
|
+
// Note : Si l'utilisateur fait "export const db = ...", mod.db sera l'instance
|
|
29
|
+
// Si l'utilisateur fait "export default ...", ce sera mod.default
|
|
30
|
+
const dbInstance = mod.db || mod.default;
|
|
31
|
+
if (!dbInstance || !dbInstance._config) {
|
|
32
|
+
throw new Error("[Deesse] Could not find exported 'db' or '_config' in src/api/index.ts");
|
|
33
|
+
}
|
|
34
|
+
const collections = dbInstance._config.collections;
|
|
35
|
+
// 4. On appelle votre fonction existante
|
|
36
|
+
(0, generate_1.generateShadowSchema)(collections);
|
|
37
|
+
console.log("[Deesse] ✅ Schema updated");
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error("[Deesse] ❌ Error generating schema:", error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Lancement initial
|
|
44
|
+
runGenerator();
|
|
45
|
+
// Mode Watch
|
|
46
|
+
console.log(`[Deesse] 👀 Watching for changes in ${COLLECTIONS_DIR}...`);
|
|
47
|
+
const watcher = chokidar_1.default.watch([CONFIG_PATH, COLLECTIONS_DIR], {
|
|
48
|
+
ignoreInitial: true,
|
|
49
|
+
ignored: /(^|[\/\\])\../, // Ignorer les fichiers cachés (dotfiles)
|
|
50
|
+
});
|
|
51
|
+
watcher.on("all", (event, path) => {
|
|
52
|
+
// On debounce légèrement pour éviter de générer 2 fois si l'éditeur sauvegarde en plusieurs étapes
|
|
53
|
+
runGenerator();
|
|
54
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deessejs/collections",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"chokidar": "^5.0.0",
|
|
67
67
|
"dotenv": "^17.2.3",
|
|
68
68
|
"drizzle-orm": "^0.45.0",
|
|
69
|
+
"jiti": "^2.6.1",
|
|
69
70
|
"pg": "^8.16.3"
|
|
70
71
|
}
|
|
71
72
|
}
|