@deessejs/collections 0.0.11 → 0.0.13

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,8 +1,15 @@
1
1
  import z from "zod";
2
2
  export declare const number: (params: {
3
- min: number;
4
- max: number;
3
+ min?: number | undefined;
4
+ max?: number | undefined;
5
5
  }) => import("./types").FieldTypeFinal<z.ZodObject<{
6
- min: z.ZodNumber;
7
- max: z.ZodNumber;
6
+ min: z.ZodOptional<z.ZodNumber>;
7
+ max: z.ZodOptional<z.ZodNumber>;
8
+ }, z.core.$strip>>;
9
+ export declare const text: (params: {
10
+ min?: number | undefined;
11
+ max?: number | undefined;
12
+ }) => import("./types").FieldTypeFinal<z.ZodObject<{
13
+ min: z.ZodOptional<z.ZodNumber>;
14
+ max: z.ZodOptional<z.ZodNumber>;
8
15
  }, z.core.$strip>>;
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.number = void 0;
6
+ exports.text = exports.number = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
8
  const field_1 = require("./field");
9
9
  exports.number = (0, field_1.fieldType)({
10
- schema: zod_1.default.object({ min: zod_1.default.number(), max: zod_1.default.number() }),
10
+ schema: zod_1.default.object({ min: zod_1.default.number().optional(), max: zod_1.default.number().optional() }),
11
11
  dsl: {
12
12
  kind: "number",
13
13
  },
@@ -15,3 +15,12 @@ exports.number = (0, field_1.fieldType)({
15
15
  component: undefined,
16
16
  },
17
17
  });
18
+ exports.text = (0, field_1.fieldType)({
19
+ 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
+ },
26
+ });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.field = exports.fieldType = void 0;
4
4
  const fieldType = (config) => (params) => {
5
- const validated = config.schema.parse(params);
5
+ const validated = config.schema ? config.schema.parse(params) : params;
6
6
  return {
7
7
  kind: config.dsl.kind,
8
8
  params: validated,
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  export type FieldTypeConfig<TParams extends z.ZodType = z.ZodType> = {
3
- schema: TParams;
3
+ schema?: TParams;
4
4
  dsl: {
5
5
  kind: string;
6
6
  config?: Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/collections",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",