@anteros/core 0.0.13 → 0.0.14
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.
- package/database/collection.ts +1 -1
- package/database/schema.ts +7 -0
- package/package.json +12 -12
- package/types/field.d.ts +7 -0
- package/utils/func.ts +17 -11
- package/utils/index.ts +2 -1
package/database/collection.ts
CHANGED
|
@@ -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
|
package/database/schema.ts
CHANGED
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anteros/core",
|
|
3
3
|
"module": "index.ts",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Anteros Core",
|
|
7
7
|
"private": false,
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
"typescript": "6.0.3"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@colors/colors": "
|
|
19
|
-
"@socket.io/bun-engine": "
|
|
20
|
-
"bentocache": "
|
|
18
|
+
"@colors/colors": "1.6.0",
|
|
19
|
+
"@socket.io/bun-engine": "0.1.1",
|
|
20
|
+
"bentocache": "1.6.1",
|
|
21
21
|
"boxen": "^8.0.1",
|
|
22
|
-
"dayjs": "
|
|
23
|
-
"hono": "
|
|
24
|
-
"ioredis": "
|
|
25
|
-
"joi": "
|
|
26
|
-
"jose": "
|
|
27
|
-
"mongodb": "
|
|
28
|
-
"socket.io": "
|
|
29
|
-
"ufo": "
|
|
22
|
+
"dayjs": "1.11.21",
|
|
23
|
+
"hono": "4.13.0",
|
|
24
|
+
"ioredis": "6.0.0",
|
|
25
|
+
"joi": "18.2.3",
|
|
26
|
+
"jose": "6.2.8",
|
|
27
|
+
"mongodb": "7.5.0",
|
|
28
|
+
"socket.io": "4.8.3",
|
|
29
|
+
"ufo": "1.6.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
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
|
|