@deessejs/collections 0.0.51 → 0.2.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/dist/next/index.js +421 -51
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +377 -0
- package/dist/next/index.mjs.map +1 -0
- package/package.json +76 -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 -2
- package/dist/config/index.js +0 -45
- 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 -49
- 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/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 -101
- /package/{dist/drizzle/types.d.ts → public/.gitkeep} +0 -0
package/dist/fields/index.js
DELETED
|
@@ -1,20 +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("./field"), exports);
|
|
18
|
-
__exportStar(require("./types"), exports);
|
|
19
|
-
__exportStar(require("./core"), exports);
|
|
20
|
-
__exportStar(require("./constraints"), exports);
|
package/dist/fields/types.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export type FieldKind = "integer" | "serial" | "boolean" | "text" | "varchar" | "char" | "numeric" | "decimal" | "json" | "uuid" | "timestamp";
|
|
3
|
-
export type FieldTypeConfig<TParams extends z.ZodType = z.ZodType> = {
|
|
4
|
-
schema?: TParams;
|
|
5
|
-
dsl: {
|
|
6
|
-
kind: FieldKind;
|
|
7
|
-
};
|
|
8
|
-
admin: {
|
|
9
|
-
component: any;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export type FieldTypeFinal<TParams extends z.ZodType = z.ZodType, TOutput = any> = {
|
|
13
|
-
kind: string;
|
|
14
|
-
params: z.infer<TParams>;
|
|
15
|
-
dsl: {
|
|
16
|
-
kind: string;
|
|
17
|
-
isPrimary: boolean;
|
|
18
|
-
isUnique: boolean;
|
|
19
|
-
canBeNull: boolean;
|
|
20
|
-
};
|
|
21
|
-
admin: {
|
|
22
|
-
component: any;
|
|
23
|
-
};
|
|
24
|
-
_output?: TOutput;
|
|
25
|
-
};
|
|
26
|
-
export type FieldPermissions = {
|
|
27
|
-
create: (ctx: any) => Promise<boolean>;
|
|
28
|
-
read: (ctx: any) => Promise<boolean>;
|
|
29
|
-
update: (ctx: any) => Promise<boolean>;
|
|
30
|
-
delete: (ctx: any) => Promise<boolean>;
|
|
31
|
-
};
|
|
32
|
-
export type FieldConfig<TType extends FieldTypeFinal> = {
|
|
33
|
-
type: TType;
|
|
34
|
-
permissions?: Partial<FieldPermissions>;
|
|
35
|
-
};
|
|
36
|
-
export type Field<TType extends FieldTypeFinal = FieldTypeFinal> = {
|
|
37
|
-
type: TType;
|
|
38
|
-
permissions: FieldPermissions;
|
|
39
|
-
};
|
|
40
|
-
export type InferSchema<F extends Record<string, Field>> = {
|
|
41
|
-
[K in keyof F]: F[K] extends Field<infer FT> ? FT extends FieldTypeFinal<any, infer TVal> ? TVal : never : never;
|
|
42
|
-
};
|
|
43
|
-
export type FieldChain<TType extends FieldTypeFinal> = Field<TType> & {
|
|
44
|
-
unique(): FieldChain<TType>;
|
|
45
|
-
required(): FieldChain<TType>;
|
|
46
|
-
optional(): FieldChain<TType>;
|
|
47
|
-
primary(): FieldChain<TType>;
|
|
48
|
-
};
|
package/dist/fields/types.js
DELETED
package/dist/index.d.ts
DELETED
package/dist/next/index.d.ts
DELETED
package/dist/plugins/index.d.ts
DELETED
package/dist/plugins/index.js
DELETED
package/dist/plugins/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Plugin = {};
|
package/dist/plugins/types.js
DELETED
package/dist/providers/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inAppProvider = void 0;
|
|
4
|
-
const inAppProvider = () => {
|
|
5
|
-
// Stockage en mémoire : { "posts": { "id_1": { ...data }, "id_2": { ...data } } }
|
|
6
|
-
const storage = {};
|
|
7
|
-
return {
|
|
8
|
-
// L'init reçoit maintenant la liste des collections pour préparer le "schéma"
|
|
9
|
-
init: (collections) => {
|
|
10
|
-
console.log("Initializing in-app provider");
|
|
11
|
-
for (const col of collections) {
|
|
12
|
-
// On initialise un "bucket" vide pour chaque collection si pas déjà fait
|
|
13
|
-
if (!storage[col.slug]) {
|
|
14
|
-
storage[col.slug] = {};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
create: async (collectionSlug, data) => {
|
|
19
|
-
// Simulation d'un ID (dans une vraie DB, c'est géré par le moteur ou UUID)
|
|
20
|
-
const id = Math.random().toString(36).substring(2, 15);
|
|
21
|
-
const record = { ...data, id };
|
|
22
|
-
// Sécurité au cas où on écrit dans une collection non initialisée
|
|
23
|
-
if (!storage[collectionSlug])
|
|
24
|
-
storage[collectionSlug] = {};
|
|
25
|
-
storage[collectionSlug][id] = record;
|
|
26
|
-
return record;
|
|
27
|
-
},
|
|
28
|
-
read: async (collectionSlug, id) => {
|
|
29
|
-
const record = storage[collectionSlug]?.[id];
|
|
30
|
-
if (!record) {
|
|
31
|
-
throw new Error(`Record with ID "${id}" not found in "${collectionSlug}".`);
|
|
32
|
-
}
|
|
33
|
-
return record;
|
|
34
|
-
},
|
|
35
|
-
update: async (collectionSlug, id, data) => {
|
|
36
|
-
const existing = storage[collectionSlug]?.[id];
|
|
37
|
-
if (!existing) {
|
|
38
|
-
throw new Error(`Cannot update: Record with ID "${id}" not found in "${collectionSlug}".`);
|
|
39
|
-
}
|
|
40
|
-
// Fusion des données (Partial update)
|
|
41
|
-
const updated = { ...existing, ...data };
|
|
42
|
-
storage[collectionSlug][id] = updated;
|
|
43
|
-
return updated;
|
|
44
|
-
},
|
|
45
|
-
delete: async (collectionSlug, id) => {
|
|
46
|
-
if (storage[collectionSlug] && storage[collectionSlug][id]) {
|
|
47
|
-
delete storage[collectionSlug][id];
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Optionnel : Throw une erreur si l'item n'existe pas,
|
|
51
|
-
// ou juste ignorer comme le ferait une requête SQL "DELETE WHERE ID=..."
|
|
52
|
-
console.warn(`Attempted to delete non-existent record "${id}" in "${collectionSlug}"`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
exports.inAppProvider = inAppProvider;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Collection } from "../collections/types";
|
|
2
|
-
export type Provider = {
|
|
3
|
-
init: (collections: readonly Collection[]) => Promise<void> | void;
|
|
4
|
-
create: (collectionSlug: string, data: any) => Promise<any>;
|
|
5
|
-
read: (collectionSlug: string, id: string) => Promise<any>;
|
|
6
|
-
update: (collectionSlug: string, id: string, data: any) => Promise<any>;
|
|
7
|
-
delete: (collectionSlug: string, id: string) => Promise<void>;
|
|
8
|
-
};
|
package/dist/providers/types.js
DELETED
package/dist/utils/exact.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
type Exact<A, B> = A extends B ? Exclude<keyof A, keyof B> extends never ? A : never : never;
|
package/dist/utils/exact.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
package/dist/worker/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/worker/index.js
DELETED
|
@@ -1,101 +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
|
-
const jiti_1 = require("jiti");
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const chokidar_1 = __importDefault(require("chokidar"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const generate_1 = require("../drizzle/generate");
|
|
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
|
-
const DEESSE_DIR = path_1.default.join(PROJECT_ROOT, ".deesse");
|
|
15
|
-
const TYPES_PATH = path_1.default.join(DEESSE_DIR, "types.d.ts");
|
|
16
|
-
/**
|
|
17
|
-
* Charge les alias depuis tsconfig.json pour que jiti puisse résoudre "@/..."
|
|
18
|
-
*/
|
|
19
|
-
function getTsConfigAliases(root) {
|
|
20
|
-
const tsConfigPath = path_1.default.join(root, "tsconfig.json");
|
|
21
|
-
if (!fs_1.default.existsSync(tsConfigPath))
|
|
22
|
-
return {};
|
|
23
|
-
try {
|
|
24
|
-
const tempJiti = (0, jiti_1.createJiti)(root, { requireCache: false });
|
|
25
|
-
const loaded = tempJiti(tsConfigPath);
|
|
26
|
-
const tsConfig = loaded.default || loaded;
|
|
27
|
-
const paths = tsConfig?.compilerOptions?.paths;
|
|
28
|
-
if (!paths)
|
|
29
|
-
return {};
|
|
30
|
-
const aliases = {};
|
|
31
|
-
for (const [key, values] of Object.entries(paths)) {
|
|
32
|
-
const value = Array.isArray(values) ? values[0] : values;
|
|
33
|
-
const aliasKey = key.replace("/*", "");
|
|
34
|
-
const aliasValue = String(value).replace("/*", "");
|
|
35
|
-
aliases[aliasKey] = path_1.default.resolve(root, aliasValue);
|
|
36
|
-
}
|
|
37
|
-
return aliases;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.warn("[Deesse] ⚠️ Failed to load aliases from tsconfig.json", error);
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Génère le fichier de définition de types (.d.ts) pour surcharger defineConfig
|
|
46
|
-
*/
|
|
47
|
-
function generateTypeDefinitions() {
|
|
48
|
-
// On s'assure que le dossier existe
|
|
49
|
-
if (!fs_1.default.existsSync(DEESSE_DIR)) {
|
|
50
|
-
fs_1.default.mkdirSync(DEESSE_DIR, { recursive: true });
|
|
51
|
-
}
|
|
52
|
-
const typeDefContent = `
|
|
53
|
-
// Ce fichier est généré automatiquement par Deesse.
|
|
54
|
-
// Il permet d'avoir le typage strict sur db.query.*
|
|
55
|
-
|
|
56
|
-
import type * as Schema from "./shadow/schema";
|
|
57
|
-
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
58
|
-
import type { Config } from "@deessejs/collections";
|
|
59
|
-
|
|
60
|
-
declare module "@deessejs/collections" {
|
|
61
|
-
export function defineConfig(config: Config): NodePgDatabase<typeof Schema> & { _config: Config };
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
fs_1.default.writeFileSync(TYPES_PATH, typeDefContent);
|
|
65
|
-
}
|
|
66
|
-
// Initialisation Jiti
|
|
67
|
-
const aliases = getTsConfigAliases(PROJECT_ROOT);
|
|
68
|
-
const jiti = (0, jiti_1.createJiti)(PROJECT_ROOT, {
|
|
69
|
-
interopDefault: true,
|
|
70
|
-
requireCache: false,
|
|
71
|
-
alias: aliases,
|
|
72
|
-
});
|
|
73
|
-
async function runGenerator() {
|
|
74
|
-
try {
|
|
75
|
-
if (!fs_1.default.existsSync(CONFIG_PATH))
|
|
76
|
-
return;
|
|
77
|
-
// Charger la config utilisateur
|
|
78
|
-
const mod = await jiti.import(CONFIG_PATH);
|
|
79
|
-
const dbInstance = mod.db || mod.default;
|
|
80
|
-
if (!dbInstance || !dbInstance._config)
|
|
81
|
-
return;
|
|
82
|
-
const collections = dbInstance._config.collections;
|
|
83
|
-
// 1. Générer le schéma Drizzle (schema.ts)
|
|
84
|
-
(0, generate_1.generateShadowSchema)(collections);
|
|
85
|
-
// 2. Générer les définitions TypeScript (types.d.ts)
|
|
86
|
-
generateTypeDefinitions();
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
console.error("[Deesse] ❌ Worker Error:", error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// Lancement
|
|
93
|
-
runGenerator();
|
|
94
|
-
console.log(`[Deesse] 👀 Watching collections...`);
|
|
95
|
-
const watcher = chokidar_1.default.watch([CONFIG_PATH, COLLECTIONS_DIR], {
|
|
96
|
-
ignoreInitial: true,
|
|
97
|
-
ignored: /(^|[\/\\])\../,
|
|
98
|
-
});
|
|
99
|
-
watcher.on("all", () => {
|
|
100
|
-
runGenerator();
|
|
101
|
-
});
|
|
File without changes
|