@deessejs/collections 0.0.10 → 0.0.12

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.
@@ -1,2 +1,20 @@
1
1
  import { Collection } from "./types";
2
- export declare const collection: (config: Collection) => Collection;
2
+ export declare const collection: <const Slug extends string, const Fields extends Record<string, any>>(config: {
3
+ slug: Slug;
4
+ name?: string;
5
+ admin?: {
6
+ title?: string;
7
+ group?: string;
8
+ };
9
+ fields: Fields;
10
+ hooks?: Collection["hooks"];
11
+ }) => {
12
+ slug: Slug;
13
+ name?: string;
14
+ admin?: {
15
+ title?: string;
16
+ group?: string;
17
+ };
18
+ fields: Fields;
19
+ hooks?: Collection["hooks"];
20
+ };
@@ -11,15 +11,13 @@ export type CollectionHooks = {
11
11
  afterError?: (error: Error) => Promise<any>;
12
12
  afterSuccess?: (data: any) => Promise<any>;
13
13
  };
14
- export type Collection = {
15
- slug: string;
14
+ export type Collection<Slug extends string = string, Fields extends Record<string, Field> = Record<string, Field>> = {
15
+ slug: Slug;
16
16
  name?: string;
17
17
  admin?: {
18
18
  title?: string;
19
19
  group?: string;
20
20
  };
21
- fields: {
22
- [key: string]: Field;
23
- };
21
+ fields: Fields;
24
22
  hooks?: CollectionHooks;
25
23
  };
@@ -1,6 +1,9 @@
1
1
  import { Collection } from "../collections/types";
2
- import { CollectionsCrud } from "../database/types";
3
- import { UnionToIntersection } from "../utils/union-intersection";
4
2
  export declare const defineConfig: <const C extends {
5
3
  collections: readonly Collection[];
6
- }>(config: C) => UnionToIntersection<CollectionsCrud<C["collections"][number]>>;
4
+ }>(config: C) => { [K in C["collections"][number]["slug"]]: {
5
+ create: (data: C["collections"][number]["fields"]) => Promise<any>;
6
+ read: (id: string) => Promise<any>;
7
+ update: (id: string, data: Partial<C["collections"][number]["fields"]>) => Promise<any>;
8
+ delete: (id: string) => Promise<void>;
9
+ }; };
@@ -5,10 +5,10 @@ const defineConfig = (config) => {
5
5
  const db = {};
6
6
  for (const col of config.collections) {
7
7
  db[col.slug] = {
8
- create: (data) => ({ ...data }),
9
- read: (id) => ({ id }),
10
- update: (id, data) => ({ id, ...data }),
11
- delete: (id) => { },
8
+ create: async (data) => data,
9
+ read: async (id) => ({ id }),
10
+ update: async (id, data) => ({ id, ...data }),
11
+ delete: async (id) => { },
12
12
  };
13
13
  }
14
14
  return db;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/collections",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",