@anteros/core 0.0.11 → 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 +2 -2
- package/database/file.ts +1 -1
- package/database/schema.ts +7 -0
- package/database/tenant.ts +1 -1
- package/package.json +12 -12
- package/server/boot.ts +1 -1
- package/server/routes.ts +18 -3
- package/types/field.d.ts +7 -0
- package/types/route.d.ts +2 -2
- package/utils/func.ts +17 -11
- package/utils/index.ts +2 -1
package/database/collection.ts
CHANGED
|
@@ -45,7 +45,7 @@ async function syncCollections() {
|
|
|
45
45
|
cfg.collections = collections
|
|
46
46
|
|
|
47
47
|
} catch (err: any) {
|
|
48
|
-
console.error(err?.message)
|
|
48
|
+
console.error(cfg.debug ? err : err?.message)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -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/file.ts
CHANGED
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/database/tenant.ts
CHANGED
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/server/boot.ts
CHANGED
|
@@ -91,7 +91,7 @@ async function bootApp(options: BootAppOptions = {} as BootAppOptions) {
|
|
|
91
91
|
|
|
92
92
|
return server;
|
|
93
93
|
} catch (err: any) {
|
|
94
|
-
console.error('Failed to boot server', err?.message);
|
|
94
|
+
console.error('Failed to boot server', cfg.debug ? err : err?.message);
|
|
95
95
|
process.exit(1);
|
|
96
96
|
}
|
|
97
97
|
}
|
package/server/routes.ts
CHANGED
|
@@ -9,8 +9,10 @@ import type { HonoVariables } from "./env";
|
|
|
9
9
|
function initializeRoutes(app: Hono<{ Variables: HonoVariables }>) {
|
|
10
10
|
for (let route of cfg.routes ?? []) {
|
|
11
11
|
if (route._prefix_) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let method = route.method.toLocaleLowerCase();
|
|
13
|
+
let routePath = path.posix.join(route._prefix_, route.path);
|
|
14
|
+
|
|
15
|
+
|
|
14
16
|
|
|
15
17
|
if (route.method == "GET") {
|
|
16
18
|
app.get(routePath, async (c) => { //
|
|
@@ -37,6 +39,19 @@ function initializeRoutes(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
37
39
|
});
|
|
38
40
|
});
|
|
39
41
|
}
|
|
42
|
+
|
|
43
|
+
if (route.method == "PUT") {
|
|
44
|
+
app.put(routePath, async (c) => { //
|
|
45
|
+
return route.handler({
|
|
46
|
+
c,
|
|
47
|
+
rest: new useRest({
|
|
48
|
+
tenant_id: route._tenant_,
|
|
49
|
+
}),
|
|
50
|
+
jwt: jwt,
|
|
51
|
+
io: io,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
56
|
}
|
|
42
57
|
|
|
@@ -45,4 +60,4 @@ function initializeRoutes(app: Hono<{ Variables: HonoVariables }>) {
|
|
|
45
60
|
|
|
46
61
|
export {
|
|
47
62
|
initializeRoutes
|
|
48
|
-
}
|
|
63
|
+
}
|
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/types/route.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ type routeContext = {
|
|
|
11
11
|
type Route = {
|
|
12
12
|
enabled?: boolean;
|
|
13
13
|
path: string;
|
|
14
|
-
method: 'GET' | 'POST';
|
|
14
|
+
method: 'GET' | 'POST'|'PUT';
|
|
15
15
|
handler: (ctx: routeContext) => void;
|
|
16
16
|
_tenant_?: string;
|
|
17
17
|
_isRoute_?: boolean;
|
|
18
18
|
_prefix_?: string;
|
|
19
|
-
}
|
|
19
|
+
}
|
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
|
|