@deessejs/collections 0.0.36 → 0.0.38
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 +3 -7
- package/dist/config/index.js +24 -19
- package/dist/config/types.d.ts +1 -2
- package/dist/drizzle/generate.d.ts +2 -0
- package/dist/drizzle/generate.js +37 -0
- package/package.json +1 -1
package/dist/config/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { InferSchema } from "../fields/types";
|
|
2
1
|
import { Config } from "./types";
|
|
3
|
-
export declare const defineConfig:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
update: (id: string, data: Partial<InferSchema<Col["fields"]>>) => Promise<any>;
|
|
7
|
-
delete: (id: string) => Promise<void>;
|
|
8
|
-
}; };
|
|
2
|
+
export declare const defineConfig: (config: Config) => import("drizzle-orm/node-postgres").NodePgDatabase<Record<string, never>> & {
|
|
3
|
+
$client: import("pg").Pool;
|
|
4
|
+
};
|
package/dist/config/index.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.defineConfig = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return (0, orchestrator_1.runOperation)("delete", col, config.provider, { id });
|
|
21
|
-
},
|
|
22
|
-
};
|
|
7
|
+
const node_postgres_1 = require("drizzle-orm/node-postgres");
|
|
8
|
+
// Remarque : on importe depuis "fs" tout court, pas "fs/promises"
|
|
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
23
|
}
|
|
24
|
+
};
|
|
25
|
+
const defineConfig = (config) => {
|
|
26
|
+
const db = (0, node_postgres_1.drizzle)(config.databaseUrl);
|
|
27
|
+
// On peut l'appeler sans await
|
|
28
|
+
writeSchemaFileSync();
|
|
24
29
|
return db;
|
|
25
30
|
};
|
|
26
31
|
exports.defineConfig = defineConfig;
|
package/dist/config/types.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { Collection } from "../collections/types";
|
|
|
2
2
|
import { CollectionsCrud } from "../database/types";
|
|
3
3
|
import { Field, FieldTypeFinal } from "../fields";
|
|
4
4
|
import { Plugin } from "../plugins/types";
|
|
5
|
-
import { Provider } from "../providers/types";
|
|
6
5
|
import { UnionToIntersection } from "../utils/union-intersection";
|
|
7
6
|
export type Config = {
|
|
8
|
-
|
|
7
|
+
databaseUrl: string;
|
|
9
8
|
readonly collections: Collection[];
|
|
10
9
|
plugins?: Plugin[];
|
|
11
10
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateShadowSchema = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const _1 = require(".");
|
|
10
|
+
const SHADOW_DIR = path_1.default.join(process.cwd(), ".deesse", "shadow");
|
|
11
|
+
const SCHEMA_PATH = path_1.default.join(SHADOW_DIR, "schema.ts");
|
|
12
|
+
const generateShadowSchema = (collections) => {
|
|
13
|
+
fs_1.default.mkdirSync(SHADOW_DIR, { recursive: true });
|
|
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);
|
|
36
|
+
};
|
|
37
|
+
exports.generateShadowSchema = generateShadowSchema;
|