@deessejs/collections 0.0.40 → 0.0.41

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.
@@ -2,4 +2,4 @@ import { Config } from "./types";
2
2
  export declare const defineConfig: (config: Config) => import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>> & {
3
3
  $client: import("pg").Pool;
4
4
  };
5
- export declare const getConfig: () => Config;
5
+ export declare const waitConfig: () => Promise<Config>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = exports.defineConfig = void 0;
3
+ exports.waitConfig = exports.defineConfig = void 0;
4
4
  const node_postgres_1 = require("drizzle-orm/node-postgres");
5
5
  let _config;
6
6
  const defineConfig = (config) => {
@@ -9,9 +9,10 @@ const defineConfig = (config) => {
9
9
  return db;
10
10
  };
11
11
  exports.defineConfig = defineConfig;
12
- const getConfig = () => {
13
- if (!_config)
14
- throw new Error("Config not defined");
12
+ const waitConfig = async () => {
13
+ while (!_config) {
14
+ await new Promise((r) => setTimeout(r, 50));
15
+ }
15
16
  return _config;
16
17
  };
17
- exports.getConfig = getConfig;
18
+ exports.waitConfig = waitConfig;
@@ -1 +1,2 @@
1
- export {};
1
+ import { Collection } from "../collections/types";
2
+ export declare const loadCollections: () => Promise<Collection[]>;
@@ -1,37 +1,72 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const chokidar_1 = __importDefault(require("chokidar"));
39
+ exports.loadCollections = void 0;
40
+ const fs_1 = __importDefault(require("fs"));
7
41
  const path_1 = __importDefault(require("path"));
8
42
  const generate_1 = require("../drizzle/generate");
9
- const config_1 = require("../config");
43
+ // Dossier des collections
10
44
  const collectionsDir = path_1.default.join(process.cwd(), "src", "collections");
11
- console.log(`[worker] Watching collections folder: ${collectionsDir}`);
12
- const config = (0, config_1.getConfig)();
13
- (0, generate_1.generateShadowSchema)(config.collections);
14
- const watcher = chokidar_1.default.watch(collectionsDir, {
15
- persistent: true,
16
- ignoreInitial: false,
17
- depth: 2,
18
- awaitWriteFinish: {
19
- stabilityThreshold: 100,
20
- pollInterval: 50,
21
- },
22
- });
23
- watcher
24
- .on("add", (filePath) => {
25
- console.log(`[worker] File added: ${filePath}`);
26
- })
27
- .on("change", (filePath) => {
28
- console.log(`[worker] File changed: ${filePath}`);
29
- })
30
- .on("unlink", (filePath) => {
31
- console.log(`[worker] File removed: ${filePath}`);
32
- })
33
- .on("error", (err) => {
34
- const error = err instanceof Error ? err : new Error(String(err));
35
- console.error("[worker] Watcher error:", error);
36
- });
37
- console.log("[worker] Watcher started");
45
+ console.log(`[worker] Loading collections from ${collectionsDir}`);
46
+ // Fonction pour importer toutes les collections
47
+ const loadCollections = async () => {
48
+ const files = fs_1.default
49
+ .readdirSync(collectionsDir)
50
+ .filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
51
+ const collections = [];
52
+ for (const file of files) {
53
+ const fullPath = path_1.default.join(collectionsDir, file);
54
+ // Utilisation de import dynamique
55
+ const module = await Promise.resolve(`${fullPath}`).then(s => __importStar(require(s)));
56
+ // On suppose que la collection exporte toujours une const (ex: Posts)
57
+ for (const exported of Object.values(module)) {
58
+ const col = exported;
59
+ if (col?.slug && col?.fields) {
60
+ collections.push(col);
61
+ }
62
+ }
63
+ }
64
+ return collections;
65
+ };
66
+ exports.loadCollections = loadCollections;
67
+ // Exemple d'utilisation
68
+ (async () => {
69
+ const collections = await (0, exports.loadCollections)();
70
+ (0, generate_1.generateShadowSchema)(collections);
71
+ console.log(`[worker] Shadow schema generated for ${collections.length} collections.`);
72
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/collections",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",