@deessejs/collections 0.0.50 → 0.1.0
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/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/index.js +868 -22
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +821 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -72
- package/dist/collections/define.d.ts +0 -43
- package/dist/collections/define.js +0 -13
- package/dist/collections/extend-fields.d.ts +0 -3
- package/dist/collections/extend-fields.js +0 -13
- package/dist/collections/index.d.ts +0 -1
- package/dist/collections/index.js +0 -17
- package/dist/collections/types.d.ts +0 -29
- package/dist/collections/types.js +0 -2
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.js +0 -51
- package/dist/config/orchestrator.d.ts +0 -8
- package/dist/config/orchestrator.js +0 -70
- package/dist/config/types.d.ts +0 -14
- package/dist/config/types.js +0 -2
- package/dist/database/types.d.ts +0 -10
- package/dist/database/types.js +0 -2
- package/dist/drizzle/generate.d.ts +0 -2
- package/dist/drizzle/generate.js +0 -56
- package/dist/drizzle/index.d.ts +0 -31
- package/dist/drizzle/index.js +0 -24
- package/dist/drizzle/types.js +0 -1
- package/dist/dsl/collections.d.ts +0 -13
- package/dist/dsl/collections.js +0 -14
- package/dist/dsl/index.d.ts +0 -1
- package/dist/dsl/index.js +0 -17
- package/dist/dsl/types.d.ts +0 -1
- package/dist/dsl/types.js +0 -2
- package/dist/esm/collections/define.d.ts +0 -43
- package/dist/esm/collections/define.js +0 -9
- package/dist/esm/collections/extend-fields.d.ts +0 -3
- package/dist/esm/collections/extend-fields.js +0 -9
- package/dist/esm/collections/index.d.ts +0 -1
- package/dist/esm/collections/index.js +0 -1
- package/dist/esm/collections/types.d.ts +0 -29
- package/dist/esm/collections/types.js +0 -1
- package/dist/esm/config/index.d.ts +0 -5
- package/dist/esm/config/index.js +0 -13
- package/dist/esm/config/orchestrator.d.ts +0 -8
- package/dist/esm/config/orchestrator.js +0 -66
- package/dist/esm/config/types.d.ts +0 -14
- package/dist/esm/config/types.js +0 -1
- package/dist/esm/database/types.d.ts +0 -10
- package/dist/esm/database/types.js +0 -1
- package/dist/esm/drizzle/generate.d.ts +0 -2
- package/dist/esm/drizzle/generate.js +0 -30
- package/dist/esm/drizzle/index.d.ts +0 -31
- package/dist/esm/drizzle/index.js +0 -20
- package/dist/esm/drizzle/types.d.ts +0 -0
- package/dist/esm/drizzle/types.js +0 -1
- package/dist/esm/dsl/collections.d.ts +0 -13
- package/dist/esm/dsl/collections.js +0 -10
- package/dist/esm/dsl/index.d.ts +0 -1
- package/dist/esm/dsl/index.js +0 -1
- package/dist/esm/fields/constraints.d.ts +0 -6
- package/dist/esm/fields/constraints.js +0 -59
- package/dist/esm/fields/core.d.ts +0 -71
- package/dist/esm/fields/core.js +0 -27
- package/dist/esm/fields/field.d.ts +0 -24
- package/dist/esm/fields/field.js +0 -33
- package/dist/esm/fields/index.d.ts +0 -4
- package/dist/esm/fields/index.js +0 -4
- package/dist/esm/fields/types.d.ts +0 -48
- package/dist/esm/fields/types.js +0 -1
- package/dist/esm/index.d.ts +0 -8
- package/dist/esm/index.js +0 -8
- package/dist/esm/next/index.d.ts +0 -5
- package/dist/esm/next/index.js +0 -17
- package/dist/esm/plugins/index.d.ts +0 -2
- package/dist/esm/plugins/index.js +0 -3
- package/dist/esm/plugins/types.d.ts +0 -1
- package/dist/esm/plugins/types.js +0 -1
- package/dist/esm/providers/index.d.ts +0 -2
- package/dist/esm/providers/index.js +0 -53
- package/dist/esm/providers/types.d.ts +0 -8
- package/dist/esm/providers/types.js +0 -1
- package/dist/esm/utils/deep-partial.d.ts +0 -3
- package/dist/esm/utils/deep-partial.js +0 -1
- package/dist/esm/utils/exact.d.ts +0 -1
- package/dist/esm/utils/exact.js +0 -1
- package/dist/esm/utils/union-intersection.d.ts +0 -1
- package/dist/esm/utils/union-intersection.js +0 -1
- package/dist/esm/worker/index.d.ts +0 -2
- package/dist/esm/worker/index.js +0 -32
- package/dist/fields/constraints.d.ts +0 -6
- package/dist/fields/constraints.js +0 -67
- package/dist/fields/core.d.ts +0 -71
- package/dist/fields/core.js +0 -33
- package/dist/fields/field.d.ts +0 -24
- package/dist/fields/field.js +0 -38
- package/dist/fields/index.d.ts +0 -4
- package/dist/fields/index.js +0 -20
- package/dist/fields/types.d.ts +0 -48
- package/dist/fields/types.js +0 -2
- package/dist/index.d.ts +0 -8
- package/dist/next/index.d.ts +0 -5
- package/dist/next/index.js +0 -58
- package/dist/plugins/index.d.ts +0 -2
- package/dist/plugins/index.js +0 -7
- package/dist/plugins/types.d.ts +0 -1
- package/dist/plugins/types.js +0 -2
- package/dist/providers/index.d.ts +0 -2
- package/dist/providers/index.js +0 -57
- package/dist/providers/types.d.ts +0 -8
- package/dist/providers/types.js +0 -2
- package/dist/utils/deep-partial.d.ts +0 -3
- package/dist/utils/deep-partial.js +0 -2
- package/dist/utils/exact.d.ts +0 -1
- package/dist/utils/exact.js +0 -1
- package/dist/utils/union-intersection.d.ts +0 -1
- package/dist/utils/union-intersection.js +0 -2
- package/dist/worker/index.d.ts +0 -1
- package/dist/worker/index.js +0 -89
- /package/{dist/drizzle/types.d.ts → public/.gitkeep} +0 -0
package/dist/drizzle/generate.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
// 1. Générer le code des tables
|
|
15
|
-
const tablesCode = collections.map((col) => {
|
|
16
|
-
const columns = Object.entries(col.fields)
|
|
17
|
-
.map(([name, field]) => {
|
|
18
|
-
const kind = field.type.dsl.kind;
|
|
19
|
-
const drizzleType = Object.keys(_1.DrizzleTypes).includes(kind)
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
? `p.${kind}()` // TODO: gérer les params (varchar(255), etc.)
|
|
22
|
-
: `p.text()`;
|
|
23
|
-
return ` ${name}: ${drizzleType},`;
|
|
24
|
-
})
|
|
25
|
-
.join("\n");
|
|
26
|
-
return `
|
|
27
|
-
export const ${col.slug} = p.pgTable("${col.slug}", {
|
|
28
|
-
${columns}
|
|
29
|
-
});`;
|
|
30
|
-
});
|
|
31
|
-
// 2. Générer le code des relations (Pour l'instant vide ou basique)
|
|
32
|
-
// Drizzle a besoin de "relations" importé de "drizzle-orm"
|
|
33
|
-
const relationsCode = `
|
|
34
|
-
import { relations } from "drizzle-orm";
|
|
35
|
-
|
|
36
|
-
// Placeholder pour les relations futures
|
|
37
|
-
export const schemaRelations = relations(posts, ({ one, many }) => ({
|
|
38
|
-
// Logique à implémenter plus tard en lisant les champs "relationship" de vos collections
|
|
39
|
-
}));
|
|
40
|
-
`;
|
|
41
|
-
// 3. Assembler le fichier
|
|
42
|
-
const schemaFileContent = `
|
|
43
|
-
import * as p from "drizzle-orm/pg-core";
|
|
44
|
-
import { relations } from "drizzle-orm";
|
|
45
|
-
|
|
46
|
-
// --- Tables ---
|
|
47
|
-
${tablesCode.join("\n")}
|
|
48
|
-
|
|
49
|
-
// --- Relations ---
|
|
50
|
-
// (Note: Pour l'instant on ne génère pas de relations complexes automatiquement,
|
|
51
|
-
// mais on prépare le terrain)
|
|
52
|
-
`;
|
|
53
|
-
fs_1.default.writeFileSync(SCHEMA_PATH, schemaFileContent);
|
|
54
|
-
console.log("[Deesse] ✅ Shadow schema generated at", SCHEMA_PATH);
|
|
55
|
-
};
|
|
56
|
-
exports.generateShadowSchema = generateShadowSchema;
|
package/dist/drizzle/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
import { FieldKind } from "../fields";
|
|
3
|
-
export declare const DrizzleTypes: Record<FieldKind, () => any>;
|
|
4
|
-
export declare const toDrizzle: (collection: Collection) => import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
5
|
-
name: string;
|
|
6
|
-
schema: undefined;
|
|
7
|
-
columns: {
|
|
8
|
-
[x: string]: import("drizzle-orm/pg-core").PgColumn<{
|
|
9
|
-
name: any;
|
|
10
|
-
tableName: string;
|
|
11
|
-
dataType: any;
|
|
12
|
-
columnType: any;
|
|
13
|
-
data: any;
|
|
14
|
-
driverParam: any;
|
|
15
|
-
notNull: false;
|
|
16
|
-
hasDefault: false;
|
|
17
|
-
isPrimaryKey: false;
|
|
18
|
-
isAutoincrement: false;
|
|
19
|
-
hasRuntimeDefault: false;
|
|
20
|
-
enumValues: any;
|
|
21
|
-
baseColumn: never;
|
|
22
|
-
identity: undefined;
|
|
23
|
-
generated: undefined;
|
|
24
|
-
}, {}, {
|
|
25
|
-
[x: string]: any;
|
|
26
|
-
[x: number]: any;
|
|
27
|
-
[x: symbol]: any;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
|
-
dialect: "pg";
|
|
31
|
-
}>;
|
package/dist/drizzle/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toDrizzle = exports.DrizzleTypes = void 0;
|
|
4
|
-
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
5
|
-
exports.DrizzleTypes = {
|
|
6
|
-
boolean: () => (0, pg_core_1.boolean)(),
|
|
7
|
-
integer: () => (0, pg_core_1.integer)(),
|
|
8
|
-
serial: () => (0, pg_core_1.serial)(),
|
|
9
|
-
text: () => (0, pg_core_1.text)(),
|
|
10
|
-
varchar: () => (0, pg_core_1.varchar)(),
|
|
11
|
-
char: () => (0, pg_core_1.char)(),
|
|
12
|
-
numeric: () => (0, pg_core_1.numeric)(),
|
|
13
|
-
decimal: () => (0, pg_core_1.decimal)(),
|
|
14
|
-
json: () => (0, pg_core_1.json)(),
|
|
15
|
-
uuid: () => (0, pg_core_1.uuid)(),
|
|
16
|
-
timestamp: () => (0, pg_core_1.timestamp)(),
|
|
17
|
-
};
|
|
18
|
-
const toDrizzle = (collection) => {
|
|
19
|
-
return (0, pg_core_1.pgTable)(collection.slug, Object.fromEntries(Object.entries(collection.fields).map(([name, field]) => {
|
|
20
|
-
const kind = field.type.dsl.kind;
|
|
21
|
-
return [name, exports.DrizzleTypes[kind]()];
|
|
22
|
-
})));
|
|
23
|
-
};
|
|
24
|
-
exports.toDrizzle = toDrizzle;
|
package/dist/drizzle/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
export declare const dsl: (collection: Collection) => {
|
|
3
|
-
slug: string;
|
|
4
|
-
fields: {
|
|
5
|
-
name: string;
|
|
6
|
-
dsl: {
|
|
7
|
-
kind: string;
|
|
8
|
-
isPrimary: boolean;
|
|
9
|
-
isUnique: boolean;
|
|
10
|
-
canBeNull: boolean;
|
|
11
|
-
};
|
|
12
|
-
}[];
|
|
13
|
-
};
|
package/dist/dsl/collections.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dsl = void 0;
|
|
4
|
-
const dsl = (collection) => {
|
|
5
|
-
const { slug, fields } = collection;
|
|
6
|
-
return {
|
|
7
|
-
slug,
|
|
8
|
-
fields: Object.entries(fields).map(([name, field]) => ({
|
|
9
|
-
name,
|
|
10
|
-
dsl: field.type.dsl,
|
|
11
|
-
})),
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
exports.dsl = dsl;
|
package/dist/dsl/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './collections';
|
package/dist/dsl/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./collections"), exports);
|
package/dist/dsl/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type DataKind = 'integer' | 'smallint';
|
package/dist/dsl/types.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Field } from "../fields";
|
|
2
|
-
import { Collection } from "./types";
|
|
3
|
-
export declare const collection: <const Slug extends string, const Fields extends Record<string, Field>>(config: Collection<Slug, Fields>) => Collection<Slug, Fields & {
|
|
4
|
-
readonly id: Field<{
|
|
5
|
-
kind: import("../fields").FieldKind;
|
|
6
|
-
params: unknown;
|
|
7
|
-
dsl: {
|
|
8
|
-
kind: import("../fields").FieldKind;
|
|
9
|
-
isPrimary: boolean;
|
|
10
|
-
isUnique: boolean;
|
|
11
|
-
canBeNull: boolean;
|
|
12
|
-
};
|
|
13
|
-
admin: {
|
|
14
|
-
component: any;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
17
|
-
readonly createdAt: import("../fields").FieldChain<{
|
|
18
|
-
kind: import("../fields").FieldKind;
|
|
19
|
-
params: unknown;
|
|
20
|
-
dsl: {
|
|
21
|
-
kind: import("../fields").FieldKind;
|
|
22
|
-
isPrimary: boolean;
|
|
23
|
-
isUnique: boolean;
|
|
24
|
-
canBeNull: boolean;
|
|
25
|
-
};
|
|
26
|
-
admin: {
|
|
27
|
-
component: any;
|
|
28
|
-
};
|
|
29
|
-
}>;
|
|
30
|
-
readonly updatedAt: import("../fields").FieldChain<{
|
|
31
|
-
kind: import("../fields").FieldKind;
|
|
32
|
-
params: unknown;
|
|
33
|
-
dsl: {
|
|
34
|
-
kind: import("../fields").FieldKind;
|
|
35
|
-
isPrimary: boolean;
|
|
36
|
-
isUnique: boolean;
|
|
37
|
-
canBeNull: boolean;
|
|
38
|
-
};
|
|
39
|
-
admin: {
|
|
40
|
-
component: any;
|
|
41
|
-
};
|
|
42
|
-
}>;
|
|
43
|
-
}>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { field, primary, serial, timestamp } from "../fields";
|
|
2
|
-
import { extendFields } from "./extend-fields";
|
|
3
|
-
export const collection = (config) => {
|
|
4
|
-
return extendFields(config, {
|
|
5
|
-
id: primary(field({ type: serial() })),
|
|
6
|
-
createdAt: field({ type: timestamp() }),
|
|
7
|
-
updatedAt: field({ type: timestamp() }),
|
|
8
|
-
});
|
|
9
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Field } from "../fields";
|
|
2
|
-
import { Collection } from "./types";
|
|
3
|
-
export declare const extendFields: <const Slug extends string, const Fields extends Record<string, Field>, const NewFields extends Record<string, Field>>(base: Collection<Slug, Fields>, newFields: NewFields) => Collection<Slug, Fields & NewFields>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './define';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './define';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Field } from "../fields";
|
|
2
|
-
export type CollectionHooks = {
|
|
3
|
-
beforeCreate?: (data: any) => Promise<any>;
|
|
4
|
-
afterCreate?: (data: any) => Promise<any>;
|
|
5
|
-
beforeUpdate?: (data: any) => Promise<any>;
|
|
6
|
-
afterUpdate?: (data: any) => Promise<any>;
|
|
7
|
-
beforeDelete?: (data: any) => Promise<any>;
|
|
8
|
-
afterDelete?: (data: any) => Promise<any>;
|
|
9
|
-
beforeOperation?: (data: any) => Promise<any>;
|
|
10
|
-
afterOperation?: (data: any) => Promise<any>;
|
|
11
|
-
afterError?: (error: Error) => Promise<any>;
|
|
12
|
-
afterSuccess?: (data: any) => Promise<any>;
|
|
13
|
-
};
|
|
14
|
-
export type Collection<Slug extends string = string, Fields extends Record<string, Field> = Record<string, Field>> = {
|
|
15
|
-
slug: Slug;
|
|
16
|
-
name?: string;
|
|
17
|
-
admin?: {
|
|
18
|
-
title?: string;
|
|
19
|
-
group?: string;
|
|
20
|
-
};
|
|
21
|
-
fields: Fields;
|
|
22
|
-
hooks?: CollectionHooks;
|
|
23
|
-
permissions?: {
|
|
24
|
-
create?: (ctx: any) => Promise<boolean>;
|
|
25
|
-
read?: (ctx: any) => Promise<boolean>;
|
|
26
|
-
update?: (ctx: any) => Promise<boolean>;
|
|
27
|
-
delete?: (ctx: any) => Promise<boolean>;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/config/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { drizzle } from "drizzle-orm/node-postgres";
|
|
2
|
-
let _config;
|
|
3
|
-
export const defineConfig = (config) => {
|
|
4
|
-
_config = config;
|
|
5
|
-
const db = drizzle(config.databaseUrl);
|
|
6
|
-
return db;
|
|
7
|
-
};
|
|
8
|
-
export const waitConfig = async () => {
|
|
9
|
-
while (!_config) {
|
|
10
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
11
|
-
}
|
|
12
|
-
return _config;
|
|
13
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
import { Provider } from "../providers/types";
|
|
3
|
-
type Action = 'create' | 'read' | 'update' | 'delete';
|
|
4
|
-
export declare const runOperation: (action: Action, collection: Collection, provider: Provider, payload: {
|
|
5
|
-
id?: string;
|
|
6
|
-
data?: any;
|
|
7
|
-
}) => Promise<any>;
|
|
8
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export const runOperation = async (action, collection, provider, payload) => {
|
|
2
|
-
const { hooks } = collection;
|
|
3
|
-
let currentData = payload.data;
|
|
4
|
-
const id = payload.id;
|
|
5
|
-
try {
|
|
6
|
-
// 1. Hook Global: beforeOperation
|
|
7
|
-
if (hooks?.beforeOperation) {
|
|
8
|
-
await hooks.beforeOperation({ action, collection: collection.slug, data: currentData, id });
|
|
9
|
-
}
|
|
10
|
-
// 2. Hook Spécifique: before[Action]
|
|
11
|
-
// Note: TypeScript peut être strict ici, on simplifie pour la demo
|
|
12
|
-
if (action === 'create' && hooks?.beforeCreate)
|
|
13
|
-
currentData = await hooks.beforeCreate(currentData);
|
|
14
|
-
if (action === 'update' && hooks?.beforeUpdate)
|
|
15
|
-
currentData = await hooks.beforeUpdate(currentData);
|
|
16
|
-
if (action === 'delete' && hooks?.beforeDelete)
|
|
17
|
-
await hooks.beforeDelete({ id });
|
|
18
|
-
// 3. APPEL AU PROVIDER (Le vrai travail DB)
|
|
19
|
-
let result;
|
|
20
|
-
switch (action) {
|
|
21
|
-
case 'create':
|
|
22
|
-
result = await provider.create(collection.slug, currentData);
|
|
23
|
-
break;
|
|
24
|
-
case 'read':
|
|
25
|
-
if (!id)
|
|
26
|
-
throw new Error("ID required for read");
|
|
27
|
-
result = await provider.read(collection.slug, id);
|
|
28
|
-
break;
|
|
29
|
-
case 'update':
|
|
30
|
-
if (!id)
|
|
31
|
-
throw new Error("ID required for update");
|
|
32
|
-
result = await provider.update(collection.slug, id, currentData);
|
|
33
|
-
break;
|
|
34
|
-
case 'delete':
|
|
35
|
-
if (!id)
|
|
36
|
-
throw new Error("ID required for delete");
|
|
37
|
-
await provider.delete(collection.slug, id);
|
|
38
|
-
result = { success: true, id };
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
// 4. Hook Spécifique: after[Action]
|
|
42
|
-
if (action === 'create' && hooks?.afterCreate)
|
|
43
|
-
result = await hooks.afterCreate(result);
|
|
44
|
-
if (action === 'update' && hooks?.afterUpdate)
|
|
45
|
-
result = await hooks.afterUpdate(result);
|
|
46
|
-
if (action === 'delete' && hooks?.afterDelete)
|
|
47
|
-
result = await hooks.afterDelete(result);
|
|
48
|
-
// 5. Hook Global: afterOperation
|
|
49
|
-
if (hooks?.afterOperation) {
|
|
50
|
-
await hooks.afterOperation({ action, result });
|
|
51
|
-
}
|
|
52
|
-
// 6. Hook Global: afterSuccess (spécifique à ta liste)
|
|
53
|
-
if (hooks?.afterSuccess) {
|
|
54
|
-
await hooks.afterSuccess(result);
|
|
55
|
-
}
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
// Gestion des erreurs via les hooks
|
|
60
|
-
if (hooks?.afterError) {
|
|
61
|
-
// Le hook peut transformer l'erreur ou la logger
|
|
62
|
-
await hooks.afterError(error);
|
|
63
|
-
}
|
|
64
|
-
throw error; // On relance l'erreur pour que l'appelant sache que ça a échoué
|
|
65
|
-
}
|
|
66
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
import { CollectionsCrud } from "../database/types";
|
|
3
|
-
import { Field, FieldTypeFinal } from "../fields";
|
|
4
|
-
import { Plugin } from "../plugins/types";
|
|
5
|
-
import { UnionToIntersection } from "../utils/union-intersection";
|
|
6
|
-
export type Config = {
|
|
7
|
-
databaseUrl: string;
|
|
8
|
-
readonly collections: Collection[];
|
|
9
|
-
plugins?: Plugin[];
|
|
10
|
-
};
|
|
11
|
-
export type DbFromConfig<C extends Config> = UnionToIntersection<CollectionsCrud<C["collections"][number]>>;
|
|
12
|
-
export type InferSchema<F extends Record<string, Field>> = {
|
|
13
|
-
[K in keyof F]: F[K] extends Field<infer FT> ? FT extends FieldTypeFinal<any, infer TVal> ? TVal : never : never;
|
|
14
|
-
};
|
package/dist/esm/config/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
import { InferSchema } from "../fields/types";
|
|
3
|
-
export type CollectionsCrud<C extends Collection> = {
|
|
4
|
-
[K in C["slug"]]: {
|
|
5
|
-
create: (data: InferSchema<C["fields"]>) => Promise<any>;
|
|
6
|
-
read: (id: string) => Promise<any>;
|
|
7
|
-
update: (id: string, data: Partial<InferSchema<C["fields"]>>) => Promise<any>;
|
|
8
|
-
delete: (id: string) => Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { DrizzleTypes } from ".";
|
|
4
|
-
const SHADOW_DIR = path.join(process.cwd(), ".deesse", "shadow");
|
|
5
|
-
const SCHEMA_PATH = path.join(SHADOW_DIR, "schema.ts");
|
|
6
|
-
export const generateShadowSchema = (collections) => {
|
|
7
|
-
fs.mkdirSync(SHADOW_DIR, { recursive: true });
|
|
8
|
-
const tablesCode = collections.map((col) => {
|
|
9
|
-
const columns = Object.entries(col.fields)
|
|
10
|
-
.map(([name, field]) => {
|
|
11
|
-
const kind = field.type.dsl.kind;
|
|
12
|
-
const drizzleType = Object.keys(DrizzleTypes).includes(kind)
|
|
13
|
-
? `p.${kind}()`
|
|
14
|
-
: `p.text()`;
|
|
15
|
-
return ` ${name}: ${drizzleType},`;
|
|
16
|
-
})
|
|
17
|
-
.join("\n");
|
|
18
|
-
return `
|
|
19
|
-
export const ${col.slug} = p.pgTable("${col.slug}", {
|
|
20
|
-
${columns}
|
|
21
|
-
});`;
|
|
22
|
-
});
|
|
23
|
-
const schemaFileContent = `
|
|
24
|
-
import * as p from "drizzle-orm/pg-core";
|
|
25
|
-
|
|
26
|
-
${tablesCode.join("\n")}
|
|
27
|
-
`;
|
|
28
|
-
fs.writeFileSync(SCHEMA_PATH, schemaFileContent);
|
|
29
|
-
console.log("[Deesse] Shadow schema generated at", SCHEMA_PATH);
|
|
30
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
import { FieldKind } from "../fields";
|
|
3
|
-
export declare const DrizzleTypes: Record<FieldKind, () => any>;
|
|
4
|
-
export declare const toDrizzle: (collection: Collection) => import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
5
|
-
name: string;
|
|
6
|
-
schema: undefined;
|
|
7
|
-
columns: {
|
|
8
|
-
[x: string]: import("drizzle-orm/pg-core").PgColumn<{
|
|
9
|
-
name: any;
|
|
10
|
-
tableName: string;
|
|
11
|
-
dataType: any;
|
|
12
|
-
columnType: any;
|
|
13
|
-
data: any;
|
|
14
|
-
driverParam: any;
|
|
15
|
-
notNull: false;
|
|
16
|
-
hasDefault: false;
|
|
17
|
-
isPrimaryKey: false;
|
|
18
|
-
isAutoincrement: false;
|
|
19
|
-
hasRuntimeDefault: false;
|
|
20
|
-
enumValues: any;
|
|
21
|
-
baseColumn: never;
|
|
22
|
-
identity: undefined;
|
|
23
|
-
generated: undefined;
|
|
24
|
-
}, {}, {
|
|
25
|
-
[x: string]: any;
|
|
26
|
-
[x: number]: any;
|
|
27
|
-
[x: symbol]: any;
|
|
28
|
-
}>;
|
|
29
|
-
};
|
|
30
|
-
dialect: "pg";
|
|
31
|
-
}>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { boolean, integer, serial, text, varchar, char, numeric, decimal, json, uuid, timestamp, pgTable, } from "drizzle-orm/pg-core";
|
|
2
|
-
export const DrizzleTypes = {
|
|
3
|
-
boolean: () => boolean(),
|
|
4
|
-
integer: () => integer(),
|
|
5
|
-
serial: () => serial(),
|
|
6
|
-
text: () => text(),
|
|
7
|
-
varchar: () => varchar(),
|
|
8
|
-
char: () => char(),
|
|
9
|
-
numeric: () => numeric(),
|
|
10
|
-
decimal: () => decimal(),
|
|
11
|
-
json: () => json(),
|
|
12
|
-
uuid: () => uuid(),
|
|
13
|
-
timestamp: () => timestamp(),
|
|
14
|
-
};
|
|
15
|
-
export const toDrizzle = (collection) => {
|
|
16
|
-
return pgTable(collection.slug, Object.fromEntries(Object.entries(collection.fields).map(([name, field]) => {
|
|
17
|
-
const kind = field.type.dsl.kind;
|
|
18
|
-
return [name, DrizzleTypes[kind]()];
|
|
19
|
-
})));
|
|
20
|
-
};
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
export declare const dsl: (collection: Collection) => {
|
|
3
|
-
slug: string;
|
|
4
|
-
fields: {
|
|
5
|
-
name: string;
|
|
6
|
-
dsl: {
|
|
7
|
-
kind: string;
|
|
8
|
-
isPrimary: boolean;
|
|
9
|
-
isUnique: boolean;
|
|
10
|
-
canBeNull: boolean;
|
|
11
|
-
};
|
|
12
|
-
}[];
|
|
13
|
-
};
|
package/dist/esm/dsl/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './collections';
|
package/dist/esm/dsl/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './collections';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Field, FieldChain, FieldTypeFinal } from "./types";
|
|
2
|
-
export declare const unique: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
3
|
-
export declare const required: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
4
|
-
export declare const optional: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
5
|
-
export declare const primary: <TType extends FieldTypeFinal>(field: Field<TType>) => Field<TType>;
|
|
6
|
-
export declare const attachChain: <TType extends FieldTypeFinal>(f: Field<TType>) => FieldChain<TType>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export const unique = (field) => {
|
|
2
|
-
return {
|
|
3
|
-
...field,
|
|
4
|
-
type: {
|
|
5
|
-
...field.type,
|
|
6
|
-
dsl: {
|
|
7
|
-
...field.type.dsl,
|
|
8
|
-
isUnique: true,
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export const required = (field) => ({
|
|
14
|
-
...field,
|
|
15
|
-
type: {
|
|
16
|
-
...field.type,
|
|
17
|
-
dsl: {
|
|
18
|
-
...field.type.dsl,
|
|
19
|
-
canBeNull: false,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
export const optional = (field) => ({
|
|
24
|
-
...field,
|
|
25
|
-
type: {
|
|
26
|
-
...field.type,
|
|
27
|
-
dsl: {
|
|
28
|
-
...field.type.dsl,
|
|
29
|
-
canBeNull: true,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
export const primary = (field) => ({
|
|
34
|
-
...field,
|
|
35
|
-
type: {
|
|
36
|
-
...field.type,
|
|
37
|
-
dsl: {
|
|
38
|
-
...field.type.dsl,
|
|
39
|
-
isPrimary: true,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
export const attachChain = (f) => {
|
|
44
|
-
return {
|
|
45
|
-
...f,
|
|
46
|
-
unique() {
|
|
47
|
-
return attachChain(unique(f));
|
|
48
|
-
},
|
|
49
|
-
required() {
|
|
50
|
-
return attachChain(required(f));
|
|
51
|
-
},
|
|
52
|
-
optional() {
|
|
53
|
-
return attachChain(optional(f));
|
|
54
|
-
},
|
|
55
|
-
primary() {
|
|
56
|
-
return attachChain(primary(f));
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
};
|