@deessejs/collections 0.0.39 → 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.
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +10 -23
- package/dist/drizzle/generate.d.ts +2 -1
- package/dist/drizzle/generate.js +24 -4
- package/dist/worker/index.d.ts +2 -1
- package/dist/worker/index.js +64 -27
- package/package.json +1 -1
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
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.waitConfig = 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 waitConfig = async () => {
|
|
13
|
+
while (!_config) {
|
|
14
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
15
|
+
}
|
|
16
|
+
return _config;
|
|
17
|
+
};
|
|
18
|
+
exports.waitConfig = waitConfig;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Collection } from "../collections/types";
|
|
2
|
+
export declare const generateShadowSchema: (collections: Collection[]) => void;
|
package/dist/drizzle/generate.js
CHANGED
|
@@ -6,12 +6,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.generateShadowSchema = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const _1 = require(".");
|
|
9
10
|
const SHADOW_DIR = path_1.default.join(process.cwd(), ".deesse", "shadow");
|
|
10
11
|
const SCHEMA_PATH = path_1.default.join(SHADOW_DIR, "schema.ts");
|
|
11
|
-
const generateShadowSchema = () => {
|
|
12
|
+
const generateShadowSchema = (collections) => {
|
|
12
13
|
fs_1.default.mkdirSync(SHADOW_DIR, { recursive: true });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const tablesCode = collections.map((col) => {
|
|
15
|
+
const columns = Object.entries(col.fields)
|
|
16
|
+
.map(([name, field]) => {
|
|
17
|
+
const kind = field.type.dsl.kind;
|
|
18
|
+
const drizzleType = Object.keys(_1.DrizzleTypes).includes(kind)
|
|
19
|
+
? `p.${kind}()`
|
|
20
|
+
: `p.text()`;
|
|
21
|
+
return ` ${name}: ${drizzleType},`;
|
|
22
|
+
})
|
|
23
|
+
.join("\n");
|
|
24
|
+
return `
|
|
25
|
+
export const ${col.slug} = p.pgTable("${col.slug}", {
|
|
26
|
+
${columns}
|
|
27
|
+
});`;
|
|
28
|
+
});
|
|
29
|
+
const schemaFileContent = `
|
|
30
|
+
import * as p from "drizzle-orm/pg-core";
|
|
31
|
+
|
|
32
|
+
${tablesCode.join("\n")}
|
|
33
|
+
`;
|
|
34
|
+
fs_1.default.writeFileSync(SCHEMA_PATH, schemaFileContent);
|
|
35
|
+
console.log("[Deesse] Shadow schema generated at", SCHEMA_PATH);
|
|
16
36
|
};
|
|
17
37
|
exports.generateShadowSchema = generateShadowSchema;
|
package/dist/worker/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Collection } from "../collections/types";
|
|
2
|
+
export declare const loadCollections: () => Promise<Collection[]>;
|
package/dist/worker/index.js
CHANGED
|
@@ -1,35 +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
|
-
|
|
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");
|
|
43
|
+
// Dossier des collections
|
|
9
44
|
const collectionsDir = path_1.default.join(process.cwd(), "src", "collections");
|
|
10
|
-
console.log(`[worker]
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
})();
|