@elek-io/core 0.12.0 → 0.14.0

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.
@@ -8,19 +8,44 @@ var __export = (target, all) => {
8
8
  import Fs7 from "fs-extra";
9
9
 
10
10
  // package.json
11
- var version = "0.12.0";
11
+ var version = "0.14.0";
12
12
 
13
13
  // src/api/index.ts
14
14
  import { serve } from "@hono/node-server";
15
15
  import { swaggerUI } from "@hono/swagger-ui";
16
- import { OpenAPIHono as OpenAPIHono2 } from "@hono/zod-openapi";
16
+ import { OpenAPIHono as OpenAPIHono5 } from "@hono/zod-openapi";
17
17
  import { cors } from "hono/cors";
18
18
 
19
- // src/api/v1/projects.ts
19
+ // src/api/middleware/logger.ts
20
+ import { createMiddleware } from "hono/factory";
21
+ var LoggerMiddleware = class {
22
+ logService;
23
+ constructor(logService) {
24
+ this.logService = logService;
25
+ }
26
+ handler = createMiddleware(async (c, next) => {
27
+ const { method, url } = c.req;
28
+ this.logService.info(`Recieved API request "${method} ${url}"`);
29
+ const start = Date.now();
30
+ await next();
31
+ const durationMs = Date.now() - start;
32
+ const statusCode = c.res.status.toString();
33
+ const resultLog = `Response for API request "${method} ${url}" with status code ${statusCode} in ${durationMs}ms`;
34
+ if (statusCode.startsWith("2")) {
35
+ this.logService.info(resultLog);
36
+ } else if (statusCode.startsWith("3")) {
37
+ this.logService.warn(resultLog);
38
+ } else if (statusCode.startsWith("4") || statusCode.startsWith("5")) {
39
+ this.logService.error(resultLog);
40
+ }
41
+ });
42
+ };
43
+
44
+ // src/api/v1/asset.ts
20
45
  import { createRoute, OpenAPIHono, z as z13 } from "@hono/zod-openapi";
21
46
 
22
47
  // src/schema/assetSchema.ts
23
- import z4 from "zod";
48
+ import { z as z4 } from "@hono/zod-openapi";
24
49
 
25
50
  // src/schema/baseSchema.ts
26
51
  import z from "zod";
@@ -136,7 +161,7 @@ var fileReferenceSchema = z2.object({
136
161
  import { z as z3 } from "zod";
137
162
  var gitSignatureSchema = z3.object({
138
163
  name: z3.string(),
139
- email: z3.string()
164
+ email: z3.string().email()
140
165
  });
141
166
  var gitMessageSchema = z3.object({
142
167
  method: z3.enum(["create", "update", "delete", "upgrade"]),
@@ -271,7 +296,7 @@ var assetSchema = assetFileSchema.extend({
271
296
  * Commit history of this Asset
272
297
  */
273
298
  history: z4.array(gitCommitSchema)
274
- });
299
+ }).openapi("Asset");
275
300
  var assetExportSchema = assetSchema.extend({});
276
301
  var createAssetSchema = assetFileSchema.pick({
277
302
  name: true,
@@ -316,10 +341,10 @@ var deleteAssetSchema = assetFileSchema.pick({
316
341
  var countAssetsSchema = z4.object({ projectId: uuidSchema.readonly() });
317
342
 
318
343
  // src/schema/collectionSchema.ts
319
- import z8 from "zod";
344
+ import { z as z8 } from "@hono/zod-openapi";
320
345
 
321
346
  // src/schema/entrySchema.ts
322
- import z6 from "zod";
347
+ import { z as z6 } from "@hono/zod-openapi";
323
348
 
324
349
  // src/schema/valueSchema.ts
325
350
  import z5 from "zod";
@@ -347,12 +372,6 @@ var valueContentReferenceSchema = z5.union([
347
372
  valueContentReferenceToEntrySchema
348
373
  // valueContentReferenceToSharedValueSchema,
349
374
  ]);
350
- var resolvedValueContentReferenceSchema = z5.union([
351
- assetSchema,
352
- z5.lazy(() => entrySchema)
353
- // Circular dependency / recursive type @see https://github.com/colinhacks/zod?tab=readme-ov-file#recursive-types
354
- // resolvedValueContentReferenceToSharedValueSchema,
355
- ]);
356
375
  var directValueBaseSchema = z5.object({
357
376
  objectType: z5.literal(objectTypeSchema.Enum.value).readonly(),
358
377
  fieldDefinitionId: uuidSchema.readonly()
@@ -381,13 +400,6 @@ var referencedValueSchema = z5.object({
381
400
  content: translatableArrayOf(valueContentReferenceSchema)
382
401
  });
383
402
  var valueSchema = z5.union([directValueSchema, referencedValueSchema]);
384
- var resolvedReferencedValueSchema = referencedValueSchema.extend({
385
- content: translatableArrayOf(resolvedValueContentReferenceSchema)
386
- });
387
- var resolvedValueSchema = z5.union([
388
- directValueSchema,
389
- resolvedReferencedValueSchema
390
- ]);
391
403
 
392
404
  // src/schema/entrySchema.ts
393
405
  var entryFileSchema = baseFileSchema.extend({
@@ -395,12 +407,11 @@ var entryFileSchema = baseFileSchema.extend({
395
407
  values: z6.array(valueSchema)
396
408
  });
397
409
  var entrySchema = entryFileSchema.extend({
398
- values: z6.array(z6.lazy(() => resolvedValueSchema)),
399
410
  /**
400
411
  * Commit history of this Entry
401
412
  */
402
413
  history: z6.array(gitCommitSchema)
403
- });
414
+ }).openapi("Entry");
404
415
  var entryExportSchema = entrySchema.extend({});
405
416
  var createEntrySchema = entryFileSchema.omit({
406
417
  id: true,
@@ -694,7 +705,7 @@ var collectionSchema = collectionFileSchema.extend({
694
705
  * Commit history of this Collection
695
706
  */
696
707
  history: z8.array(gitCommitSchema)
697
- });
708
+ }).openapi("Collection");
698
709
  var collectionExportSchema = collectionSchema.extend({
699
710
  entries: z8.array(entryExportSchema)
700
711
  });
@@ -899,14 +910,8 @@ function paginatedListOf(schema) {
899
910
  }
900
911
  var listSchema = z11.object({
901
912
  projectId: uuidSchema,
902
- limit: z11.number().optional().openapi({
903
- default: 15,
904
- description: "The maximum number of items to return"
905
- }),
906
- offset: z11.number().optional().openapi({
907
- default: 0,
908
- description: "The number of items to skip before starting to collect the result set"
909
- })
913
+ limit: z11.number().optional(),
914
+ offset: z11.number().optional()
910
915
  });
911
916
  var listCollectionsSchema = listSchema;
912
917
  var listEntriesSchema = listSchema.extend({
@@ -935,15 +940,7 @@ var baseUserSchema = gitSignatureSchema.extend({
935
940
  * The port the local API uses
936
941
  */
937
942
  port: z12.number()
938
- }),
939
- window: z12.object({
940
- width: z12.number(),
941
- height: z12.number(),
942
- position: z12.object({
943
- x: z12.number(),
944
- y: z12.number()
945
- })
946
- }).nullable()
943
+ })
947
944
  });
948
945
  var localUserSchema = baseUserSchema.extend({
949
946
  userType: z12.literal(UserTypeSchema.Enum.local)
@@ -956,57 +953,480 @@ var userFileSchema = z12.union([localUserSchema, cloudUserSchema]);
956
953
  var userSchema = userFileSchema;
957
954
  var setUserSchema = userSchema;
958
955
 
959
- // src/api/v1/projects.ts
960
- var ProjectsApiV1 = class {
956
+ // src/api/v1/asset.ts
957
+ var AssetApiV1 = class {
961
958
  api;
962
- projectService;
963
- constructor(projectService) {
964
- this.projectService = projectService;
959
+ assetService;
960
+ constructor(assetService) {
961
+ this.assetService = assetService;
965
962
  this.api = new OpenAPIHono();
966
963
  this.registerRoutes();
967
964
  }
968
965
  registerRoutes() {
969
- this.api.openapi(countProjectsRoute, async (context) => {
970
- const count = await this.projectService.count();
966
+ this.api.openapi(listAssetsRoute, async (context) => {
967
+ const { projectId } = context.req.valid("param");
968
+ const { limit, offset } = context.req.valid("query");
969
+ const assets = await this.assetService.list({
970
+ projectId,
971
+ limit,
972
+ offset
973
+ });
974
+ return context.json(assets, 200);
975
+ });
976
+ this.api.openapi(countAssetsRoute, async (context) => {
977
+ const { projectId } = context.req.valid("param");
978
+ const count = await this.assetService.count({ projectId });
971
979
  return context.json(count, 200);
972
980
  });
973
- this.api.openapi(listProjectsRoute, async (context) => {
981
+ this.api.openapi(readAssetRoute, async (context) => {
982
+ const { projectId, assetId } = context.req.valid("param");
983
+ const asset = await this.assetService.read({
984
+ projectId,
985
+ id: assetId
986
+ });
987
+ return context.json(asset, 200);
988
+ });
989
+ }
990
+ };
991
+ var listAssetsRoute = createRoute({
992
+ tags: ["Assets"],
993
+ description: "Lists all Assets of the given Project",
994
+ method: "get",
995
+ path: "/projects/{projectId}/assets",
996
+ operationId: "listAssets",
997
+ request: {
998
+ params: z13.object({
999
+ projectId: uuidSchema.openapi({
1000
+ param: {
1001
+ name: "projectId",
1002
+ in: "path"
1003
+ }
1004
+ })
1005
+ }),
1006
+ query: z13.object({
1007
+ limit: z13.string().pipe(z13.coerce.number()).optional().openapi({
1008
+ default: "15",
1009
+ description: "The maximum number of items to return"
1010
+ }),
1011
+ offset: z13.string().pipe(z13.coerce.number()).optional().openapi({
1012
+ default: "0",
1013
+ description: "The number of items to skip before starting to collect the result set"
1014
+ })
1015
+ })
1016
+ },
1017
+ responses: {
1018
+ 200: {
1019
+ content: {
1020
+ "application/json": {
1021
+ schema: paginatedListOf(assetSchema)
1022
+ }
1023
+ },
1024
+ description: "A list of Assets of the given Project"
1025
+ }
1026
+ }
1027
+ });
1028
+ var countAssetsRoute = createRoute({
1029
+ tags: ["Assets"],
1030
+ description: "Counts all Assets of the given Project",
1031
+ method: "get",
1032
+ path: "/projects/{projectId}/assets/count",
1033
+ operationId: "countAssets",
1034
+ request: {
1035
+ params: z13.object({
1036
+ projectId: uuidSchema.openapi({
1037
+ param: {
1038
+ name: "projectId",
1039
+ in: "path"
1040
+ }
1041
+ })
1042
+ })
1043
+ },
1044
+ responses: {
1045
+ 200: {
1046
+ content: {
1047
+ "application/json": {
1048
+ schema: z13.number()
1049
+ }
1050
+ },
1051
+ description: "The number of Assets of the given Project"
1052
+ }
1053
+ }
1054
+ });
1055
+ var readAssetRoute = createRoute({
1056
+ tags: ["Assets"],
1057
+ description: "Retrieve an Asset by ID",
1058
+ method: "get",
1059
+ path: "/projects/{projectId}/assets/{assetId}",
1060
+ operationId: "readAsset",
1061
+ request: {
1062
+ params: z13.object({
1063
+ projectId: uuidSchema.openapi({
1064
+ param: {
1065
+ name: "projectId",
1066
+ in: "path"
1067
+ }
1068
+ }),
1069
+ assetId: uuidSchema.openapi({
1070
+ param: {
1071
+ name: "assetId",
1072
+ in: "path"
1073
+ }
1074
+ })
1075
+ })
1076
+ },
1077
+ responses: {
1078
+ 200: {
1079
+ content: {
1080
+ "application/json": {
1081
+ schema: assetSchema
1082
+ }
1083
+ },
1084
+ description: "The requested Asset"
1085
+ },
1086
+ 404: {
1087
+ description: "The requested Asset does not exist"
1088
+ }
1089
+ }
1090
+ });
1091
+
1092
+ // src/api/v1/collection.ts
1093
+ import { createRoute as createRoute2, OpenAPIHono as OpenAPIHono2, z as z14 } from "@hono/zod-openapi";
1094
+ var CollectionApiV1 = class {
1095
+ api;
1096
+ collectionService;
1097
+ constructor(collectionService) {
1098
+ this.collectionService = collectionService;
1099
+ this.api = new OpenAPIHono2();
1100
+ this.registerRoutes();
1101
+ }
1102
+ registerRoutes() {
1103
+ this.api.openapi(listCollectionsRoute, async (context) => {
1104
+ const { projectId } = context.req.valid("param");
974
1105
  const { limit, offset } = context.req.valid("query");
975
- const projects = await this.projectService.list({ limit, offset });
976
- return context.json(projects, 200);
1106
+ const collections = await this.collectionService.list({
1107
+ projectId,
1108
+ limit,
1109
+ offset
1110
+ });
1111
+ return context.json(collections, 200);
977
1112
  });
978
- this.api.openapi(readProjectRoute, async (context) => {
979
- const { id } = context.req.valid("param");
980
- const project = await this.projectService.read({ id });
981
- return context.json(project, 200);
1113
+ this.api.openapi(countCollectionsRoute, async (context) => {
1114
+ const { projectId } = context.req.valid("param");
1115
+ const count = await this.collectionService.count({ projectId });
1116
+ return context.json(count, 200);
1117
+ });
1118
+ this.api.openapi(readCollectionRoute, async (context) => {
1119
+ const { projectId, collectionId } = context.req.valid("param");
1120
+ const collection = await this.collectionService.read({
1121
+ projectId,
1122
+ id: collectionId
1123
+ });
1124
+ return context.json(collection, 200);
982
1125
  });
983
1126
  }
984
1127
  };
985
- var countProjectsRoute = createRoute({
986
- tags: ["Projects"],
987
- description: "Counts all Projects you currently have access to",
1128
+ var listCollectionsRoute = createRoute2({
1129
+ tags: ["Collections"],
1130
+ description: "Lists all Collections of the given Project",
988
1131
  method: "get",
989
- path: "/count",
990
- operationId: "countProjects",
1132
+ path: "/projects/{projectId}/collections",
1133
+ operationId: "listCollections",
1134
+ request: {
1135
+ params: z14.object({
1136
+ projectId: uuidSchema.openapi({
1137
+ param: {
1138
+ name: "projectId",
1139
+ in: "path"
1140
+ }
1141
+ })
1142
+ }),
1143
+ query: z14.object({
1144
+ limit: z14.string().pipe(z14.coerce.number()).optional().openapi({
1145
+ default: "15",
1146
+ description: "The maximum number of items to return"
1147
+ }),
1148
+ offset: z14.string().pipe(z14.coerce.number()).optional().openapi({
1149
+ default: "0",
1150
+ description: "The number of items to skip before starting to collect the result set"
1151
+ })
1152
+ })
1153
+ },
991
1154
  responses: {
992
1155
  200: {
993
1156
  content: {
994
1157
  "application/json": {
995
- schema: z13.number()
1158
+ schema: paginatedListOf(collectionSchema)
996
1159
  }
997
1160
  },
998
- description: "The number of Projects you have acces to"
1161
+ description: "A list of Collections of the given Project"
1162
+ }
1163
+ }
1164
+ });
1165
+ var countCollectionsRoute = createRoute2({
1166
+ tags: ["Collections"],
1167
+ description: "Counts all Collections of the given Project",
1168
+ method: "get",
1169
+ path: "/projects/{projectId}/collections/count",
1170
+ operationId: "countCollections",
1171
+ request: {
1172
+ params: z14.object({
1173
+ projectId: uuidSchema.openapi({
1174
+ param: {
1175
+ name: "projectId",
1176
+ in: "path"
1177
+ }
1178
+ })
1179
+ })
1180
+ },
1181
+ responses: {
1182
+ 200: {
1183
+ content: {
1184
+ "application/json": {
1185
+ schema: z14.number()
1186
+ }
1187
+ },
1188
+ description: "The number of Collections of the given Project"
1189
+ }
1190
+ }
1191
+ });
1192
+ var readCollectionRoute = createRoute2({
1193
+ tags: ["Collections"],
1194
+ description: "Retrieve a Project by ID",
1195
+ method: "get",
1196
+ path: "/projects/{projectId}/collections/{collectionId}",
1197
+ operationId: "readCollection",
1198
+ request: {
1199
+ params: z14.object({
1200
+ projectId: uuidSchema.openapi({
1201
+ param: {
1202
+ name: "projectId",
1203
+ in: "path"
1204
+ }
1205
+ }),
1206
+ collectionId: uuidSchema.openapi({
1207
+ param: {
1208
+ name: "collectionId",
1209
+ in: "path"
1210
+ }
1211
+ })
1212
+ })
1213
+ },
1214
+ responses: {
1215
+ 200: {
1216
+ content: {
1217
+ "application/json": {
1218
+ schema: collectionSchema
1219
+ }
1220
+ },
1221
+ description: "The requested Collection"
1222
+ },
1223
+ 404: {
1224
+ description: "The requested Collection does not exist"
1225
+ }
1226
+ }
1227
+ });
1228
+
1229
+ // src/api/v1/entry.ts
1230
+ import { createRoute as createRoute3, OpenAPIHono as OpenAPIHono3, z as z15 } from "@hono/zod-openapi";
1231
+ var EntryApiV1 = class {
1232
+ api;
1233
+ entryService;
1234
+ constructor(entryService) {
1235
+ this.entryService = entryService;
1236
+ this.api = new OpenAPIHono3();
1237
+ this.registerRoutes();
1238
+ }
1239
+ registerRoutes() {
1240
+ this.api.openapi(listEntriesRoute, async (context) => {
1241
+ const { projectId, collectionId } = context.req.valid("param");
1242
+ const { limit, offset } = context.req.valid("query");
1243
+ const entries = await this.entryService.list({
1244
+ projectId,
1245
+ collectionId,
1246
+ limit,
1247
+ offset
1248
+ });
1249
+ return context.json(entries, 200);
1250
+ });
1251
+ this.api.openapi(countEntriesRoute, async (context) => {
1252
+ const { projectId, collectionId } = context.req.valid("param");
1253
+ const count = await this.entryService.count({ projectId, collectionId });
1254
+ return context.json(count, 200);
1255
+ });
1256
+ this.api.openapi(readEntryRoute, async (context) => {
1257
+ const { projectId, collectionId, entryId } = context.req.valid("param");
1258
+ const entry = await this.entryService.read({
1259
+ projectId,
1260
+ collectionId,
1261
+ id: entryId
1262
+ });
1263
+ return context.json(entry, 200);
1264
+ });
1265
+ }
1266
+ };
1267
+ var listEntriesRoute = createRoute3({
1268
+ tags: ["Entries"],
1269
+ description: "Lists all Entries of the given Project",
1270
+ method: "get",
1271
+ path: "/projects/{projectId}/collections/{collectionId}/entries",
1272
+ operationId: "listEntries",
1273
+ request: {
1274
+ params: z15.object({
1275
+ projectId: uuidSchema.openapi({
1276
+ param: {
1277
+ name: "projectId",
1278
+ in: "path"
1279
+ }
1280
+ }),
1281
+ collectionId: uuidSchema.openapi({
1282
+ param: {
1283
+ name: "collectionId",
1284
+ in: "path"
1285
+ }
1286
+ })
1287
+ }),
1288
+ query: z15.object({
1289
+ limit: z15.string().pipe(z15.coerce.number()).optional().openapi({
1290
+ default: "15",
1291
+ description: "The maximum number of items to return"
1292
+ }),
1293
+ offset: z15.string().pipe(z15.coerce.number()).optional().openapi({
1294
+ default: "0",
1295
+ description: "The number of items to skip before starting to collect the result set"
1296
+ })
1297
+ })
1298
+ },
1299
+ responses: {
1300
+ 200: {
1301
+ content: {
1302
+ "application/json": {
1303
+ schema: paginatedListOf(entrySchema)
1304
+ }
1305
+ },
1306
+ description: "A list of Entries of the given Project"
1307
+ }
1308
+ }
1309
+ });
1310
+ var countEntriesRoute = createRoute3({
1311
+ tags: ["Entries"],
1312
+ description: "Counts all Entries of the given Project",
1313
+ method: "get",
1314
+ path: "/projects/{projectId}/collections/{collectionId}/entries/count",
1315
+ operationId: "countEntries",
1316
+ request: {
1317
+ params: z15.object({
1318
+ projectId: uuidSchema.openapi({
1319
+ param: {
1320
+ name: "projectId",
1321
+ in: "path"
1322
+ }
1323
+ }),
1324
+ collectionId: uuidSchema.openapi({
1325
+ param: {
1326
+ name: "collectionId",
1327
+ in: "path"
1328
+ }
1329
+ })
1330
+ })
1331
+ },
1332
+ responses: {
1333
+ 200: {
1334
+ content: {
1335
+ "application/json": {
1336
+ schema: z15.number()
1337
+ }
1338
+ },
1339
+ description: "The number of Entries of the given Project"
999
1340
  }
1000
1341
  }
1001
1342
  });
1002
- var listProjectsRoute = createRoute({
1343
+ var readEntryRoute = createRoute3({
1344
+ tags: ["Entries"],
1345
+ description: "Retrieve a Project by ID",
1346
+ method: "get",
1347
+ path: "/projects/{projectId}/collections/{collectionId}/entries/{entryId}",
1348
+ operationId: "readCollection",
1349
+ request: {
1350
+ params: z15.object({
1351
+ projectId: uuidSchema.openapi({
1352
+ param: {
1353
+ name: "projectId",
1354
+ in: "path"
1355
+ }
1356
+ }),
1357
+ collectionId: uuidSchema.openapi({
1358
+ param: {
1359
+ name: "collectionId",
1360
+ in: "path"
1361
+ }
1362
+ }),
1363
+ entryId: uuidSchema.openapi({
1364
+ param: {
1365
+ name: "entryId",
1366
+ in: "path"
1367
+ }
1368
+ })
1369
+ })
1370
+ },
1371
+ responses: {
1372
+ 200: {
1373
+ content: {
1374
+ "application/json": {
1375
+ schema: entrySchema
1376
+ }
1377
+ },
1378
+ description: "The requested Collection"
1379
+ },
1380
+ 404: {
1381
+ description: "The requested Collection does not exist"
1382
+ }
1383
+ }
1384
+ });
1385
+
1386
+ // src/api/v1/project.ts
1387
+ import { createRoute as createRoute4, OpenAPIHono as OpenAPIHono4, z as z16 } from "@hono/zod-openapi";
1388
+ var ProjectApiV1 = class {
1389
+ api;
1390
+ projectService;
1391
+ constructor(projectService) {
1392
+ this.projectService = projectService;
1393
+ this.api = new OpenAPIHono4();
1394
+ this.registerRoutes();
1395
+ }
1396
+ registerRoutes() {
1397
+ this.api.openapi(listProjectsRoute, async (context) => {
1398
+ const { limit, offset } = context.req.valid("query");
1399
+ const projects = await this.projectService.list({ limit, offset });
1400
+ return context.json(projects, 200);
1401
+ });
1402
+ this.api.openapi(countProjectsRoute, async (context) => {
1403
+ const count = await this.projectService.count();
1404
+ return context.json(count, 200);
1405
+ });
1406
+ this.api.openapi(readProjectRoute, async (context) => {
1407
+ const { projectId } = context.req.valid("param");
1408
+ const project = await this.projectService.read({ id: projectId });
1409
+ return context.json(project, 200);
1410
+ });
1411
+ }
1412
+ };
1413
+ var listProjectsRoute = createRoute4({
1003
1414
  tags: ["Projects"],
1004
1415
  description: "Lists all Projects you currently have access to",
1005
1416
  method: "get",
1006
- path: "/",
1417
+ path: "/projects",
1007
1418
  operationId: "listProjects",
1008
1419
  request: {
1009
- query: listProjectsSchema
1420
+ query: z16.object({
1421
+ limit: z16.string().pipe(z16.coerce.number()).optional().openapi({
1422
+ default: "15",
1423
+ description: "The maximum number of items to return"
1424
+ }),
1425
+ offset: z16.string().pipe(z16.coerce.number()).optional().openapi({
1426
+ default: "0",
1427
+ description: "The number of items to skip before starting to collect the result set"
1428
+ })
1429
+ })
1010
1430
  },
1011
1431
  responses: {
1012
1432
  200: {
@@ -1019,17 +1439,34 @@ var listProjectsRoute = createRoute({
1019
1439
  }
1020
1440
  }
1021
1441
  });
1022
- var readProjectRoute = createRoute({
1442
+ var countProjectsRoute = createRoute4({
1443
+ tags: ["Projects"],
1444
+ description: "Counts all Projects you currently have access to",
1445
+ method: "get",
1446
+ path: "/projects/count",
1447
+ operationId: "countProjects",
1448
+ responses: {
1449
+ 200: {
1450
+ content: {
1451
+ "application/json": {
1452
+ schema: z16.number()
1453
+ }
1454
+ },
1455
+ description: "The number of Projects you have acces to"
1456
+ }
1457
+ }
1458
+ });
1459
+ var readProjectRoute = createRoute4({
1023
1460
  tags: ["Projects"],
1024
1461
  description: "Retrieve a Project by ID",
1025
1462
  method: "get",
1026
- path: "/{id}",
1463
+ path: "/projects/{projectId}",
1027
1464
  operationId: "readProject",
1028
1465
  request: {
1029
- params: z13.object({
1030
- id: uuidSchema.openapi({
1466
+ params: z16.object({
1467
+ projectId: uuidSchema.openapi({
1031
1468
  param: {
1032
- name: "id",
1469
+ name: "projectId",
1033
1470
  in: "path"
1034
1471
  }
1035
1472
  })
@@ -1054,20 +1491,64 @@ var readProjectRoute = createRoute({
1054
1491
  var LocalApi = class {
1055
1492
  logService;
1056
1493
  projectService;
1494
+ collectionService;
1495
+ entryService;
1496
+ assetService;
1057
1497
  api;
1058
1498
  server = null;
1059
- constructor(logService, projectService) {
1499
+ constructor(logService, projectService, collectionService, entryService, assetService) {
1060
1500
  this.logService = logService;
1061
1501
  this.projectService = projectService;
1062
- this.api = new OpenAPIHono2();
1502
+ this.collectionService = collectionService;
1503
+ this.entryService = entryService;
1504
+ this.assetService = assetService;
1505
+ this.api = new OpenAPIHono5();
1063
1506
  this.api.use(
1064
1507
  cors({
1065
1508
  origin: ["http://localhost"]
1066
1509
  })
1067
1510
  );
1068
- this.registerRoutes();
1069
- this.api.doc("/openapi.json", {
1511
+ this.api.use(new LoggerMiddleware(logService).handler);
1512
+ this.registerRoutesV1();
1513
+ }
1514
+ /**
1515
+ * Starts the local API on given port
1516
+ */
1517
+ async start(port) {
1518
+ this.server = serve(
1519
+ {
1520
+ fetch: this.api.fetch,
1521
+ port
1522
+ },
1523
+ (info) => {
1524
+ this.logService.info(
1525
+ `Started local API on ${info.address}:${info.port} (${info.family})`
1526
+ );
1527
+ }
1528
+ );
1529
+ }
1530
+ /**
1531
+ * Stops the local API
1532
+ */
1533
+ async stop() {
1534
+ this.server?.close(() => {
1535
+ this.logService.info("Stopped local API");
1536
+ });
1537
+ }
1538
+ /**
1539
+ * Returns true if the local API is running
1540
+ */
1541
+ async isRunning() {
1542
+ if (this.server?.listening) {
1543
+ return true;
1544
+ }
1545
+ return false;
1546
+ }
1547
+ registerRoutesV1() {
1548
+ const apiV1 = new OpenAPIHono5();
1549
+ apiV1.doc("/openapi.json", {
1070
1550
  openapi: "3.0.0",
1551
+ externalDocs: { url: "https://elek.io/docs" },
1071
1552
  info: {
1072
1553
  version: "0.1.0",
1073
1554
  title: "elek.io Project API",
@@ -1113,44 +1594,12 @@ var LocalApi = class {
1113
1594
  }
1114
1595
  ]
1115
1596
  });
1116
- this.api.get("/ui", swaggerUI({ url: "/openapi.json" }));
1117
- }
1118
- /**
1119
- * Starts the local API on given port
1120
- */
1121
- start(port) {
1122
- this.server = serve(
1123
- {
1124
- fetch: this.api.fetch,
1125
- port
1126
- },
1127
- (info) => {
1128
- this.logService.info(
1129
- `Started local API on ${info.address}:${info.port} (${info.family})`
1130
- );
1131
- }
1132
- );
1133
- }
1134
- /**
1135
- * Stops the local API
1136
- */
1137
- stop() {
1138
- this.server?.close(() => {
1139
- this.logService.info("Stopped local API");
1140
- });
1141
- }
1142
- /**
1143
- * Returns true if the local API is running
1144
- */
1145
- isRunning() {
1146
- if (this.server?.listening) {
1147
- return true;
1148
- }
1149
- return false;
1150
- }
1151
- registerRoutes() {
1152
- const projectsV1 = new ProjectsApiV1(this.projectService);
1153
- this.api.route("/v1/projects", projectsV1.api);
1597
+ apiV1.get("/ui", swaggerUI({ url: "/v1/openapi.json" }));
1598
+ apiV1.route("/", new ProjectApiV1(this.projectService).api);
1599
+ apiV1.route("/", new CollectionApiV1(this.collectionService).api);
1600
+ apiV1.route("/", new EntryApiV1(this.entryService).api);
1601
+ apiV1.route("/", new AssetApiV1(this.assetService).api);
1602
+ this.api.route("/v1", apiV1);
1154
1603
  }
1155
1604
  };
1156
1605
 
@@ -1869,15 +2318,13 @@ var EntryService = class extends AbstractCrudService {
1869
2318
  jsonFileService;
1870
2319
  gitService;
1871
2320
  collectionService;
1872
- assetService;
1873
2321
  // private sharedValueService: SharedValueService;
1874
- constructor(options, logService, jsonFileService, gitService, collectionService, assetService) {
2322
+ constructor(options, logService, jsonFileService, gitService, collectionService) {
1875
2323
  super(serviceTypeSchema.Enum.Entry, options);
1876
2324
  this.logService = logService;
1877
2325
  this.jsonFileService = jsonFileService;
1878
2326
  this.gitService = gitService;
1879
2327
  this.collectionService = collectionService;
1880
- this.assetService = assetService;
1881
2328
  }
1882
2329
  /**
1883
2330
  * Creates a new Entry for given Collection
@@ -2114,74 +2561,6 @@ var EntryService = class extends AbstractCrudService {
2114
2561
  }
2115
2562
  });
2116
2563
  }
2117
- /**
2118
- * Validates given shared Value references against it's Collections definitions
2119
- */
2120
- // private validateResolvedSharedValues(props: {
2121
- // collectionId: string;
2122
- // valueDefinitions: ValueDefinition[];
2123
- // resolvedSharedValues: ResolvedSharedValueReference[];
2124
- // }) {
2125
- // props.resolvedSharedValues.map((value) => {
2126
- // const definition = this.getValueDefinitionById({
2127
- // collectionId: props.collectionId,
2128
- // valueDefinitions: props.valueDefinitions,
2129
- // id: value.definitionId,
2130
- // });
2131
- // const schema = getValueSchemaFromDefinition(definition);
2132
- // schema.parse(value.resolved.content);
2133
- // });
2134
- // }
2135
- async resolveValueContentReference(props) {
2136
- switch (props.valueContentReference.objectType) {
2137
- case objectTypeSchema.Enum.asset:
2138
- return await this.assetService.read({
2139
- projectId: props.projectId,
2140
- id: props.valueContentReference.id
2141
- });
2142
- case objectTypeSchema.Enum.entry:
2143
- return await this.read({
2144
- projectId: props.projectId,
2145
- collectionId: props.collectionId,
2146
- id: props.valueContentReference.id
2147
- });
2148
- // case objectTypeSchema.Enum.sharedValue:
2149
- // return this.resolveValueContentReferenceToSharedValue({
2150
- // projectId: props.projectId,
2151
- // valueContentReferenceToSharedValue: props.valueContentReference,
2152
- // });
2153
- default:
2154
- throw new Error(
2155
- // @ts-ignore
2156
- `Tried to resolve unsupported Value reference "${props.valueContentReference.referenceObjectType}"`
2157
- );
2158
- }
2159
- }
2160
- async resolveValueContentReferences(props) {
2161
- let resolvedContent = {};
2162
- for (const language in props.valueReference.content) {
2163
- const referencesOfLanguage = props.valueReference.content[language];
2164
- if (!referencesOfLanguage) {
2165
- throw new Error(
2166
- `Trying to access content references by language "${language}" failed`
2167
- );
2168
- }
2169
- const resolvedReferencesOfLanguage = await Promise.all(
2170
- referencesOfLanguage.map(async (reference) => {
2171
- return await this.resolveValueContentReference({
2172
- projectId: props.projectId,
2173
- collectionId: props.collectionId,
2174
- valueContentReference: reference
2175
- });
2176
- })
2177
- );
2178
- resolvedContent = {
2179
- ...resolvedContent,
2180
- [language]: resolvedReferencesOfLanguage
2181
- };
2182
- }
2183
- return resolvedContent;
2184
- }
2185
2564
  /**
2186
2565
  * Creates an Entry from given EntryFile by resolving it's Values
2187
2566
  */
@@ -2191,24 +2570,7 @@ var EntryService = class extends AbstractCrudService {
2191
2570
  });
2192
2571
  return {
2193
2572
  ...entryFile,
2194
- history,
2195
- // @ts-ignore @todo fixme - I have no idea why this happens. The types seem to be compatible to me and they work
2196
- values: await Promise.all(
2197
- entryFile.values.map(async (value) => {
2198
- if (value.valueType === ValueTypeSchema.Enum.reference) {
2199
- const resolvedContentReferences = await this.resolveValueContentReferences({
2200
- projectId,
2201
- collectionId,
2202
- valueReference: value
2203
- });
2204
- return {
2205
- ...value,
2206
- content: resolvedContentReferences
2207
- };
2208
- }
2209
- return value;
2210
- })
2211
- )
2573
+ history
2212
2574
  };
2213
2575
  }
2214
2576
  };
@@ -2306,6 +2668,10 @@ var GitTagService = class extends AbstractCrudService {
2306
2668
  });
2307
2669
  const lineObjArr = noEmptyLinesArr.map((line) => {
2308
2670
  const lineArray = line.split("|");
2671
+ if (lineArray[3]?.startsWith("<") && lineArray[3]?.endsWith(">")) {
2672
+ lineArray[3] = lineArray[3].slice(1, -1);
2673
+ lineArray[3] = lineArray[3].slice(0, -1);
2674
+ }
2309
2675
  return {
2310
2676
  id: lineArray[0],
2311
2677
  message: lineArray[1],
@@ -3369,6 +3735,8 @@ var ProjectService = class extends AbstractCrudService {
3369
3735
  };
3370
3736
  /**
3371
3737
  * Updates the remote origin URL of given Project
3738
+ *
3739
+ * @todo maybe add this logic to the update method
3372
3740
  */
3373
3741
  async setRemoteOriginUrl(props) {
3374
3742
  setRemoteOriginUrlProjectSchema.parse(props);
@@ -3744,8 +4112,7 @@ var ElekIoCore = class {
3744
4112
  this.logService,
3745
4113
  this.jsonFileService,
3746
4114
  this.gitService,
3747
- this.collectionService,
3748
- this.assetService
4115
+ this.collectionService
3749
4116
  );
3750
4117
  this.projectService = new ProjectService(
3751
4118
  this.coreVersion,
@@ -3758,7 +4125,13 @@ var ElekIoCore = class {
3758
4125
  this.collectionService,
3759
4126
  this.entryService
3760
4127
  );
3761
- this.localApi = new LocalApi(this.logService, this.projectService);
4128
+ this.localApi = new LocalApi(
4129
+ this.logService,
4130
+ this.projectService,
4131
+ this.collectionService,
4132
+ this.entryService,
4133
+ this.assetService
4134
+ );
3762
4135
  this.logService.info(`Initializing elek.io Core ${this.coreVersion}`, {
3763
4136
  options: this.options
3764
4137
  });
@@ -3916,9 +4289,6 @@ export {
3916
4289
  readGitTagSchema,
3917
4290
  readProjectSchema,
3918
4291
  referencedValueSchema,
3919
- resolvedReferencedValueSchema,
3920
- resolvedValueContentReferenceSchema,
3921
- resolvedValueSchema,
3922
4292
  saveAssetSchema,
3923
4293
  searchProjectSchema,
3924
4294
  serviceTypeSchema,