@deessejs/collections 0.0.13 → 0.0.15

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,9 +1,14 @@
1
1
  import { Collection } from "../collections/types";
2
+ import { Field, FieldTypeFinal } from "../fields/types";
3
+ type InferSchema<F extends Record<string, Field>> = {
4
+ [K in keyof F]: F[K] extends Field<infer FT> ? FT extends FieldTypeFinal<any, infer TVal> ? TVal : never : never;
5
+ };
2
6
  export declare const defineConfig: <const C extends {
3
7
  collections: readonly Collection[];
4
- }>(config: C) => { [K in C["collections"][number]["slug"]]: {
5
- create: (data: C["collections"][number]["fields"]) => Promise<any>;
8
+ }>(config: C) => { [Col in C["collections"][number] as Col["slug"]]: {
9
+ create: (data: InferSchema<Col["fields"]>) => Promise<any>;
6
10
  read: (id: string) => Promise<any>;
7
- update: (id: string, data: Partial<C["collections"][number]["fields"]>) => Promise<any>;
11
+ update: (id: string, data: Partial<InferSchema<Col["fields"]>>) => Promise<any>;
8
12
  delete: (id: string) => Promise<void>;
9
13
  }; };
14
+ export {};
@@ -1,9 +1,10 @@
1
1
  import { Collection } from "../collections/types";
2
+ import { InferSchema } from "../fields/types";
2
3
  export type CollectionsCrud<C extends Collection> = {
3
4
  [K in C["slug"]]: {
4
- create: (data: C["fields"]) => Promise<any>;
5
+ create: (data: InferSchema<C["fields"]>) => Promise<any>;
5
6
  read: (id: string) => Promise<any>;
6
- update: (id: string, data: Partial<C["fields"]>) => Promise<any>;
7
+ update: (id: string, data: Partial<InferSchema<C["fields"]>>) => Promise<any>;
7
8
  delete: (id: string) => Promise<void>;
8
9
  };
9
10
  };
@@ -5,11 +5,11 @@ export declare const number: (params: {
5
5
  }) => import("./types").FieldTypeFinal<z.ZodObject<{
6
6
  min: z.ZodOptional<z.ZodNumber>;
7
7
  max: z.ZodOptional<z.ZodNumber>;
8
- }, z.core.$strip>>;
8
+ }, z.core.$strip>, number>;
9
9
  export declare const text: (params: {
10
10
  min?: number | undefined;
11
11
  max?: number | undefined;
12
12
  }) => import("./types").FieldTypeFinal<z.ZodObject<{
13
13
  min: z.ZodOptional<z.ZodNumber>;
14
14
  max: z.ZodOptional<z.ZodNumber>;
15
- }, z.core.$strip>>;
15
+ }, z.core.$strip>, string>;
@@ -8,19 +8,11 @@ const zod_1 = __importDefault(require("zod"));
8
8
  const field_1 = require("./field");
9
9
  exports.number = (0, field_1.fieldType)({
10
10
  schema: zod_1.default.object({ min: zod_1.default.number().optional(), max: zod_1.default.number().optional() }),
11
- dsl: {
12
- kind: "number",
13
- },
14
- admin: {
15
- component: undefined,
16
- },
11
+ dsl: { kind: "number" },
12
+ admin: { component: undefined },
17
13
  });
18
14
  exports.text = (0, field_1.fieldType)({
19
15
  schema: zod_1.default.object({ min: zod_1.default.number().optional(), max: zod_1.default.number().optional() }),
20
- dsl: {
21
- kind: "text",
22
- },
23
- admin: {
24
- component: undefined,
25
- },
16
+ dsl: { kind: "text" },
17
+ admin: { component: undefined },
26
18
  });
@@ -1,4 +1,4 @@
1
1
  import z from "zod";
2
2
  import { Field, FieldConfig, FieldTypeConfig, FieldTypeFinal } from "./types";
3
- export declare const fieldType: <TParams extends z.ZodType>(config: FieldTypeConfig<TParams>) => (params: z.infer<TParams>) => FieldTypeFinal<TParams>;
3
+ export declare const fieldType: <TOutput, TParams extends z.ZodType>(config: FieldTypeConfig<TParams>) => (params: z.infer<TParams>) => FieldTypeFinal<TParams, TOutput>;
4
4
  export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => Field<TType>;
@@ -9,7 +9,7 @@ export type FieldTypeConfig<TParams extends z.ZodType = z.ZodType> = {
9
9
  component: any;
10
10
  };
11
11
  };
12
- export type FieldTypeFinal<TParams extends z.ZodType = z.ZodType> = {
12
+ export type FieldTypeFinal<TParams extends z.ZodType = z.ZodType, TOutput = any> = {
13
13
  kind: string;
14
14
  params: z.infer<TParams>;
15
15
  dsl: {
@@ -19,6 +19,7 @@ export type FieldTypeFinal<TParams extends z.ZodType = z.ZodType> = {
19
19
  admin: {
20
20
  component: any;
21
21
  };
22
+ _output?: TOutput;
22
23
  };
23
24
  export type FieldPermissions = {
24
25
  create: (ctx: any) => Promise<boolean>;
@@ -34,3 +35,6 @@ export type Field<TType extends FieldTypeFinal = FieldTypeFinal> = {
34
35
  type: TType;
35
36
  permissions: FieldPermissions;
36
37
  };
38
+ export type InferSchema<F extends Record<string, Field>> = {
39
+ [K in keyof F]: F[K] extends Field<infer FT> ? FT extends FieldTypeFinal<any, infer TVal> ? TVal : never : never;
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/collections",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",