@deessejs/collections 0.0.25 → 0.0.26

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,4 @@
1
+ import { Field } from "../fields";
1
2
  import { Collection } from "./types";
2
3
  export declare const collection: <const Slug extends string, const Fields extends Record<string, any>>(config: Collection<Slug, Fields>) => Collection<Slug, Fields>;
4
+ 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,7 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collection = void 0;
3
+ exports.extendFields = exports.collection = void 0;
4
+ const fields_1 = require("../fields");
4
5
  const collection = (config) => {
5
- return config;
6
+ return (0, exports.extendFields)(config, {
7
+ id: (0, fields_1.field)({ type: (0, fields_1.uuid)() }),
8
+ createdAt: (0, fields_1.field)({ type: (0, fields_1.timestamp)() }),
9
+ updatedAt: (0, fields_1.field)({ type: (0, fields_1.timestamp)() }),
10
+ });
6
11
  };
7
12
  exports.collection = collection;
13
+ const extendFields = (base, newFields) => {
14
+ return {
15
+ ...base,
16
+ fields: {
17
+ ...base.fields,
18
+ ...newFields,
19
+ },
20
+ };
21
+ };
22
+ exports.extendFields = extendFields;
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defineConfig = void 0;
4
4
  const orchestrator_1 = require("./orchestrator");
5
5
  const defineConfig = (config) => {
6
- // 1. Initialisation du Provider (Création tables, connexion DB...)
7
- // On passe les collections pour qu'il connaisse le schéma
8
6
  config.provider.init(config.collections);
9
7
  const db = {};
10
- // 2. Construction dynamique de l'objet DB
11
8
  for (const col of config.collections) {
12
9
  db[col.slug] = {
13
10
  create: async (data) => {
@@ -1,15 +1,58 @@
1
- import z from "zod";
2
- export declare const number: (params: {
1
+ export declare const number: (params?: {
3
2
  min?: number | undefined;
4
3
  max?: number | undefined;
5
- }) => import("./types").FieldTypeFinal<z.ZodObject<{
6
- min: z.ZodOptional<z.ZodNumber>;
7
- max: z.ZodOptional<z.ZodNumber>;
8
- }, z.core.$strip>, number>;
9
- export declare const text: (params: {
4
+ } | undefined) => {
5
+ kind: string;
6
+ params: unknown;
7
+ dsl: {
8
+ kind: string;
9
+ isPrimary: boolean;
10
+ isUnique: boolean;
11
+ canBeNull: boolean;
12
+ };
13
+ admin: {
14
+ component: any;
15
+ };
16
+ };
17
+ export declare const text: (params?: {
10
18
  min?: number | undefined;
11
19
  max?: number | undefined;
12
- }) => import("./types").FieldTypeFinal<z.ZodObject<{
13
- min: z.ZodOptional<z.ZodNumber>;
14
- max: z.ZodOptional<z.ZodNumber>;
15
- }, z.core.$strip>, string>;
20
+ } | undefined) => {
21
+ kind: string;
22
+ params: unknown;
23
+ dsl: {
24
+ kind: string;
25
+ isPrimary: boolean;
26
+ isUnique: boolean;
27
+ canBeNull: boolean;
28
+ };
29
+ admin: {
30
+ component: any;
31
+ };
32
+ };
33
+ export declare const uuid: (params?: void | undefined) => {
34
+ kind: string;
35
+ params: unknown;
36
+ dsl: {
37
+ kind: string;
38
+ isPrimary: boolean;
39
+ isUnique: boolean;
40
+ canBeNull: boolean;
41
+ };
42
+ admin: {
43
+ component: any;
44
+ };
45
+ };
46
+ export declare const timestamp: (params?: void | undefined) => {
47
+ kind: string;
48
+ params: unknown;
49
+ dsl: {
50
+ kind: string;
51
+ isPrimary: boolean;
52
+ isUnique: boolean;
53
+ canBeNull: boolean;
54
+ };
55
+ admin: {
56
+ component: any;
57
+ };
58
+ };
@@ -3,7 +3,7 @@ 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.text = exports.number = void 0;
6
+ exports.timestamp = exports.uuid = 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)({
@@ -16,3 +16,13 @@ exports.text = (0, field_1.fieldType)({
16
16
  dsl: { kind: "text" },
17
17
  admin: { component: undefined },
18
18
  });
19
+ exports.uuid = (0, field_1.fieldType)({
20
+ schema: zod_1.default.void(),
21
+ dsl: { kind: "uuid" },
22
+ admin: { component: undefined },
23
+ });
24
+ exports.timestamp = (0, field_1.fieldType)({
25
+ schema: zod_1.default.void(),
26
+ dsl: { kind: "timestamp" },
27
+ admin: { component: undefined },
28
+ });
@@ -1,4 +1,24 @@
1
1
  import z from "zod";
2
- import { FieldChain, FieldConfig, FieldTypeConfig, FieldTypeFinal } from "./types";
3
- export declare const fieldType: <TOutput, TParams extends z.ZodType>(config: FieldTypeConfig<TParams>) => (params: z.infer<TParams>) => FieldTypeFinal<TParams, TOutput>;
2
+ import { FieldChain, FieldConfig, FieldTypeFinal } from "./types";
3
+ export declare const fieldType: <TOutput, TParams extends z.ZodType | undefined>(config: {
4
+ schema?: TParams;
5
+ dsl: {
6
+ kind: string;
7
+ };
8
+ admin: {
9
+ component: any;
10
+ };
11
+ }) => (params?: TParams extends z.ZodType ? z.infer<TParams> : undefined) => {
12
+ kind: string;
13
+ params: unknown;
14
+ dsl: {
15
+ kind: string;
16
+ isPrimary: boolean;
17
+ isUnique: boolean;
18
+ canBeNull: boolean;
19
+ };
20
+ admin: {
21
+ component: any;
22
+ };
23
+ };
4
24
  export declare const field: <TType extends FieldTypeFinal>(config: FieldConfig<TType>) => FieldChain<TType>;
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.field = exports.fieldType = void 0;
4
4
  const constraints_1 = require("./constraints");
5
5
  const fieldType = (config) => (params) => {
6
- const validated = config.schema ? config.schema.parse(params) : params;
6
+ const validated = config.schema && params !== undefined
7
+ ? config.schema.parse(params)
8
+ : params;
7
9
  return {
8
10
  kind: config.dsl.kind,
9
11
  params: validated,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/collections",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",