@anteros/core 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.
@@ -85,7 +85,7 @@ async function initializeOnDatabase(collections: Collection[]) {
85
85
 
86
86
  if (field?.index) {
87
87
  let indexValue: Boolean | number = field.index;
88
- let includesStringType: Field['type'][] = ['string', 'email', 'enum', 'url', 'random'];
88
+ let includesStringType: Field['type'][] = ['string', 'email', 'enum', 'url', 'random', 'slug'];
89
89
  let includesDateType: Field['type'][] = ['date', 'datetime-local'];
90
90
  if (typeof indexValue == "boolean" && includesStringType.includes(field.type)) {
91
91
  indexValue = 1
@@ -69,6 +69,13 @@ function buildSchema(col: CollectionType, opts = {
69
69
  propertiesSchema[fieldName] = Joi.string().uri()
70
70
  }
71
71
 
72
+ if (f.type == 'slug') {
73
+ let schema = Joi.string().pattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
74
+ if (f.slugOptions?.min != null) schema = schema.min(f.slugOptions.min)
75
+ if (f.slugOptions?.max != null) schema = schema.max(f.slugOptions.max)
76
+ propertiesSchema[fieldName] = schema
77
+ }
78
+
72
79
  if (f.type == 'ipv4') {
73
80
  propertiesSchema[fieldName] = Joi.string().ip({ version: 'ipv4' })
74
81
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@anteros/core",
3
3
  "module": "index.ts",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "description": "Anteros Core",
7
7
  "private": false,
8
+ "packageManager": "bun",
8
9
  "engines": {
9
10
  "bun": ">=1.3.0"
10
11
  },
@@ -15,17 +16,17 @@
15
16
  "typescript": "6.0.3"
16
17
  },
17
18
  "dependencies": {
18
- "@colors/colors": "^1.6.0",
19
- "@socket.io/bun-engine": "^0.1.1",
20
- "bentocache": "^1.6.1",
19
+ "@colors/colors": "1.6.0",
20
+ "@socket.io/bun-engine": "0.1.1",
21
+ "bentocache": "1.6.1",
21
22
  "boxen": "^8.0.1",
22
- "dayjs": "^1.11.21",
23
- "hono": "^4.12.27",
24
- "ioredis": "^5.11.1",
25
- "joi": "^18.2.3",
26
- "jose": "^6.2.3",
27
- "mongodb": "6.21.0",
28
- "socket.io": "^4.8.3",
29
- "ufo": "^1.6.4"
23
+ "dayjs": "1.11.21",
24
+ "hono": "4.13.0",
25
+ "ioredis": "6.0.0",
26
+ "joi": "18.2.3",
27
+ "jose": "6.2.8",
28
+ "mongodb": "7.5.0",
29
+ "socket.io": "4.8.3",
30
+ "ufo": "1.6.4"
30
31
  }
31
32
  }
package/types/field.d.ts CHANGED
@@ -21,6 +21,7 @@ export type FieldType = "boolean"
21
21
  | "geojson.LineString"
22
22
  | "geojson.Polygon"
23
23
  | "uuid"
24
+ | "slug"
24
25
 
25
26
 
26
27
 
@@ -30,6 +31,11 @@ export type enumOptions = {
30
31
  items?: Array<string | number | boolean | object>;
31
32
  }
32
33
 
34
+ export type SlugOptions = {
35
+ min?: number;
36
+ max?: number;
37
+ }
38
+
33
39
 
34
40
  export type Field = {
35
41
  name: string;
@@ -45,6 +51,7 @@ export type Field = {
45
51
  },
46
52
  required?: boolean;
47
53
  enumOptions?: enumOptions;
54
+ slugOptions?: SlugOptions;
48
55
  unique?: boolean;
49
56
  nullable?: boolean;
50
57
  empty?: boolean;
package/utils/func.ts CHANGED
@@ -799,17 +799,22 @@ function clone<T>(data: T): T {
799
799
 
800
800
 
801
801
 
802
- //slugify function
803
- function slugify(text: string): string {
804
- return text
805
- .normalize('NFD')
806
- .replace(/[\u0300-\u036f]/g, '')
807
- .toLowerCase()
808
- .replace(/[^\w\s-]/g, '')
809
- .replace(/[\s_]+/g, '-')
810
- .replace(/-+/g, '-')
811
- .replace(/^-|-$/g, '');
812
- }
802
+ //slugify function
803
+ function slugify(text: string): string {
804
+ return text
805
+ .normalize('NFD')
806
+ .replace(/[\u0300-\u036f]/g, '')
807
+ .toLowerCase()
808
+ .replace(/[^\w\s-]/g, '')
809
+ .replace(/[\s_]+/g, '-')
810
+ .replace(/-+/g, '-')
811
+ .replace(/^-|-$/g, '');
812
+ }
813
+
814
+ /** Vérifie qu'une chaîne est un slug valide (lettres minuscules, chiffres, tirets simples) */
815
+ function isSlug(value: string): boolean {
816
+ return /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value);
817
+ }
813
818
 
814
819
 
815
820
  /**
@@ -1065,6 +1070,7 @@ export {
1065
1070
  jwt,
1066
1071
  isEmpty,
1067
1072
  slugify,
1073
+ isSlug,
1068
1074
  paginate,
1069
1075
  hasUnauthorizedKeys,
1070
1076
  protectFieldRenameOnProject,
package/utils/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { cleanDeep, clone, deepCopy, omit, pick,jwt } from './func';
1
+ import { cleanDeep, clone, deepCopy, omit, pick, jwt, isSlug } from './func';
2
2
  const jose = jwt
3
3
  const utils = {
4
4
  password: Bun.password,
@@ -11,6 +11,7 @@ const utils = {
11
11
  omit,
12
12
  pick,
13
13
  jose,
14
+ isSlug,
14
15
  }
15
16
 
16
17