@elek-io/core 0.12.0 → 0.13.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.
- package/README.md +5 -6
- package/dist/browser/index.browser.d.ts +8363 -10091
- package/dist/browser/index.browser.js +8 -31
- package/dist/browser/index.browser.js.map +1 -1
- package/dist/node/index.node.d.ts +8054 -9782
- package/dist/node/index.node.js +569 -197
- package/dist/node/index.node.js.map +1 -1
- package/package.json +2 -2
package/dist/node/index.node.js
CHANGED
|
@@ -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.
|
|
11
|
+
var version = "0.13.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
|
|
16
|
+
import { OpenAPIHono as OpenAPIHono5 } from "@hono/zod-openapi";
|
|
17
17
|
import { cors } from "hono/cors";
|
|
18
18
|
|
|
19
|
-
// src/api/
|
|
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";
|
|
@@ -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()
|
|
903
|
-
|
|
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({
|
|
@@ -956,57 +961,480 @@ var userFileSchema = z12.union([localUserSchema, cloudUserSchema]);
|
|
|
956
961
|
var userSchema = userFileSchema;
|
|
957
962
|
var setUserSchema = userSchema;
|
|
958
963
|
|
|
959
|
-
// src/api/v1/
|
|
960
|
-
var
|
|
964
|
+
// src/api/v1/asset.ts
|
|
965
|
+
var AssetApiV1 = class {
|
|
961
966
|
api;
|
|
962
|
-
|
|
963
|
-
constructor(
|
|
964
|
-
this.
|
|
967
|
+
assetService;
|
|
968
|
+
constructor(assetService) {
|
|
969
|
+
this.assetService = assetService;
|
|
965
970
|
this.api = new OpenAPIHono();
|
|
966
971
|
this.registerRoutes();
|
|
967
972
|
}
|
|
968
973
|
registerRoutes() {
|
|
969
|
-
this.api.openapi(
|
|
970
|
-
const
|
|
974
|
+
this.api.openapi(listAssetsRoute, async (context) => {
|
|
975
|
+
const { projectId } = context.req.valid("param");
|
|
976
|
+
const { limit, offset } = context.req.valid("query");
|
|
977
|
+
const assets = await this.assetService.list({
|
|
978
|
+
projectId,
|
|
979
|
+
limit,
|
|
980
|
+
offset
|
|
981
|
+
});
|
|
982
|
+
return context.json(assets, 200);
|
|
983
|
+
});
|
|
984
|
+
this.api.openapi(countAssetsRoute, async (context) => {
|
|
985
|
+
const { projectId } = context.req.valid("param");
|
|
986
|
+
const count = await this.assetService.count({ projectId });
|
|
971
987
|
return context.json(count, 200);
|
|
972
988
|
});
|
|
973
|
-
this.api.openapi(
|
|
989
|
+
this.api.openapi(readAssetRoute, async (context) => {
|
|
990
|
+
const { projectId, assetId } = context.req.valid("param");
|
|
991
|
+
const asset = await this.assetService.read({
|
|
992
|
+
projectId,
|
|
993
|
+
id: assetId
|
|
994
|
+
});
|
|
995
|
+
return context.json(asset, 200);
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
var listAssetsRoute = createRoute({
|
|
1000
|
+
tags: ["Assets"],
|
|
1001
|
+
description: "Lists all Assets of the given Project",
|
|
1002
|
+
method: "get",
|
|
1003
|
+
path: "/projects/{projectId}/assets",
|
|
1004
|
+
operationId: "listAssets",
|
|
1005
|
+
request: {
|
|
1006
|
+
params: z13.object({
|
|
1007
|
+
projectId: uuidSchema.openapi({
|
|
1008
|
+
param: {
|
|
1009
|
+
name: "projectId",
|
|
1010
|
+
in: "path"
|
|
1011
|
+
}
|
|
1012
|
+
})
|
|
1013
|
+
}),
|
|
1014
|
+
query: z13.object({
|
|
1015
|
+
limit: z13.string().pipe(z13.coerce.number()).optional().openapi({
|
|
1016
|
+
default: "15",
|
|
1017
|
+
description: "The maximum number of items to return"
|
|
1018
|
+
}),
|
|
1019
|
+
offset: z13.string().pipe(z13.coerce.number()).optional().openapi({
|
|
1020
|
+
default: "0",
|
|
1021
|
+
description: "The number of items to skip before starting to collect the result set"
|
|
1022
|
+
})
|
|
1023
|
+
})
|
|
1024
|
+
},
|
|
1025
|
+
responses: {
|
|
1026
|
+
200: {
|
|
1027
|
+
content: {
|
|
1028
|
+
"application/json": {
|
|
1029
|
+
schema: paginatedListOf(assetSchema)
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
description: "A list of Assets of the given Project"
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1036
|
+
var countAssetsRoute = createRoute({
|
|
1037
|
+
tags: ["Assets"],
|
|
1038
|
+
description: "Counts all Assets of the given Project",
|
|
1039
|
+
method: "get",
|
|
1040
|
+
path: "/projects/{projectId}/assets/count",
|
|
1041
|
+
operationId: "countAssets",
|
|
1042
|
+
request: {
|
|
1043
|
+
params: z13.object({
|
|
1044
|
+
projectId: uuidSchema.openapi({
|
|
1045
|
+
param: {
|
|
1046
|
+
name: "projectId",
|
|
1047
|
+
in: "path"
|
|
1048
|
+
}
|
|
1049
|
+
})
|
|
1050
|
+
})
|
|
1051
|
+
},
|
|
1052
|
+
responses: {
|
|
1053
|
+
200: {
|
|
1054
|
+
content: {
|
|
1055
|
+
"application/json": {
|
|
1056
|
+
schema: z13.number()
|
|
1057
|
+
}
|
|
1058
|
+
},
|
|
1059
|
+
description: "The number of Assets of the given Project"
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
});
|
|
1063
|
+
var readAssetRoute = createRoute({
|
|
1064
|
+
tags: ["Assets"],
|
|
1065
|
+
description: "Retrieve an Asset by ID",
|
|
1066
|
+
method: "get",
|
|
1067
|
+
path: "/projects/{projectId}/assets/{assetId}",
|
|
1068
|
+
operationId: "readAsset",
|
|
1069
|
+
request: {
|
|
1070
|
+
params: z13.object({
|
|
1071
|
+
projectId: uuidSchema.openapi({
|
|
1072
|
+
param: {
|
|
1073
|
+
name: "projectId",
|
|
1074
|
+
in: "path"
|
|
1075
|
+
}
|
|
1076
|
+
}),
|
|
1077
|
+
assetId: uuidSchema.openapi({
|
|
1078
|
+
param: {
|
|
1079
|
+
name: "assetId",
|
|
1080
|
+
in: "path"
|
|
1081
|
+
}
|
|
1082
|
+
})
|
|
1083
|
+
})
|
|
1084
|
+
},
|
|
1085
|
+
responses: {
|
|
1086
|
+
200: {
|
|
1087
|
+
content: {
|
|
1088
|
+
"application/json": {
|
|
1089
|
+
schema: assetSchema
|
|
1090
|
+
}
|
|
1091
|
+
},
|
|
1092
|
+
description: "The requested Asset"
|
|
1093
|
+
},
|
|
1094
|
+
404: {
|
|
1095
|
+
description: "The requested Asset does not exist"
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
// src/api/v1/collection.ts
|
|
1101
|
+
import { createRoute as createRoute2, OpenAPIHono as OpenAPIHono2, z as z14 } from "@hono/zod-openapi";
|
|
1102
|
+
var CollectionApiV1 = class {
|
|
1103
|
+
api;
|
|
1104
|
+
collectionService;
|
|
1105
|
+
constructor(collectionService) {
|
|
1106
|
+
this.collectionService = collectionService;
|
|
1107
|
+
this.api = new OpenAPIHono2();
|
|
1108
|
+
this.registerRoutes();
|
|
1109
|
+
}
|
|
1110
|
+
registerRoutes() {
|
|
1111
|
+
this.api.openapi(listCollectionsRoute, async (context) => {
|
|
1112
|
+
const { projectId } = context.req.valid("param");
|
|
974
1113
|
const { limit, offset } = context.req.valid("query");
|
|
975
|
-
const
|
|
976
|
-
|
|
1114
|
+
const collections = await this.collectionService.list({
|
|
1115
|
+
projectId,
|
|
1116
|
+
limit,
|
|
1117
|
+
offset
|
|
1118
|
+
});
|
|
1119
|
+
return context.json(collections, 200);
|
|
977
1120
|
});
|
|
978
|
-
this.api.openapi(
|
|
979
|
-
const {
|
|
980
|
-
const
|
|
981
|
-
return context.json(
|
|
1121
|
+
this.api.openapi(countCollectionsRoute, async (context) => {
|
|
1122
|
+
const { projectId } = context.req.valid("param");
|
|
1123
|
+
const count = await this.collectionService.count({ projectId });
|
|
1124
|
+
return context.json(count, 200);
|
|
1125
|
+
});
|
|
1126
|
+
this.api.openapi(readCollectionRoute, async (context) => {
|
|
1127
|
+
const { projectId, collectionId } = context.req.valid("param");
|
|
1128
|
+
const collection = await this.collectionService.read({
|
|
1129
|
+
projectId,
|
|
1130
|
+
id: collectionId
|
|
1131
|
+
});
|
|
1132
|
+
return context.json(collection, 200);
|
|
982
1133
|
});
|
|
983
1134
|
}
|
|
984
1135
|
};
|
|
985
|
-
var
|
|
986
|
-
tags: ["
|
|
987
|
-
description: "
|
|
1136
|
+
var listCollectionsRoute = createRoute2({
|
|
1137
|
+
tags: ["Collections"],
|
|
1138
|
+
description: "Lists all Collections of the given Project",
|
|
988
1139
|
method: "get",
|
|
989
|
-
path: "/
|
|
990
|
-
operationId: "
|
|
1140
|
+
path: "/projects/{projectId}/collections",
|
|
1141
|
+
operationId: "listCollections",
|
|
1142
|
+
request: {
|
|
1143
|
+
params: z14.object({
|
|
1144
|
+
projectId: uuidSchema.openapi({
|
|
1145
|
+
param: {
|
|
1146
|
+
name: "projectId",
|
|
1147
|
+
in: "path"
|
|
1148
|
+
}
|
|
1149
|
+
})
|
|
1150
|
+
}),
|
|
1151
|
+
query: z14.object({
|
|
1152
|
+
limit: z14.string().pipe(z14.coerce.number()).optional().openapi({
|
|
1153
|
+
default: "15",
|
|
1154
|
+
description: "The maximum number of items to return"
|
|
1155
|
+
}),
|
|
1156
|
+
offset: z14.string().pipe(z14.coerce.number()).optional().openapi({
|
|
1157
|
+
default: "0",
|
|
1158
|
+
description: "The number of items to skip before starting to collect the result set"
|
|
1159
|
+
})
|
|
1160
|
+
})
|
|
1161
|
+
},
|
|
991
1162
|
responses: {
|
|
992
1163
|
200: {
|
|
993
1164
|
content: {
|
|
994
1165
|
"application/json": {
|
|
995
|
-
schema:
|
|
1166
|
+
schema: paginatedListOf(collectionSchema)
|
|
996
1167
|
}
|
|
997
1168
|
},
|
|
998
|
-
description: "
|
|
1169
|
+
description: "A list of Collections of the given Project"
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
var countCollectionsRoute = createRoute2({
|
|
1174
|
+
tags: ["Collections"],
|
|
1175
|
+
description: "Counts all Collections of the given Project",
|
|
1176
|
+
method: "get",
|
|
1177
|
+
path: "/projects/{projectId}/collections/count",
|
|
1178
|
+
operationId: "countCollections",
|
|
1179
|
+
request: {
|
|
1180
|
+
params: z14.object({
|
|
1181
|
+
projectId: uuidSchema.openapi({
|
|
1182
|
+
param: {
|
|
1183
|
+
name: "projectId",
|
|
1184
|
+
in: "path"
|
|
1185
|
+
}
|
|
1186
|
+
})
|
|
1187
|
+
})
|
|
1188
|
+
},
|
|
1189
|
+
responses: {
|
|
1190
|
+
200: {
|
|
1191
|
+
content: {
|
|
1192
|
+
"application/json": {
|
|
1193
|
+
schema: z14.number()
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
description: "The number of Collections of the given Project"
|
|
999
1197
|
}
|
|
1000
1198
|
}
|
|
1001
1199
|
});
|
|
1002
|
-
var
|
|
1200
|
+
var readCollectionRoute = createRoute2({
|
|
1201
|
+
tags: ["Collections"],
|
|
1202
|
+
description: "Retrieve a Project by ID",
|
|
1203
|
+
method: "get",
|
|
1204
|
+
path: "/projects/{projectId}/collections/{collectionId}",
|
|
1205
|
+
operationId: "readCollection",
|
|
1206
|
+
request: {
|
|
1207
|
+
params: z14.object({
|
|
1208
|
+
projectId: uuidSchema.openapi({
|
|
1209
|
+
param: {
|
|
1210
|
+
name: "projectId",
|
|
1211
|
+
in: "path"
|
|
1212
|
+
}
|
|
1213
|
+
}),
|
|
1214
|
+
collectionId: uuidSchema.openapi({
|
|
1215
|
+
param: {
|
|
1216
|
+
name: "collectionId",
|
|
1217
|
+
in: "path"
|
|
1218
|
+
}
|
|
1219
|
+
})
|
|
1220
|
+
})
|
|
1221
|
+
},
|
|
1222
|
+
responses: {
|
|
1223
|
+
200: {
|
|
1224
|
+
content: {
|
|
1225
|
+
"application/json": {
|
|
1226
|
+
schema: collectionSchema
|
|
1227
|
+
}
|
|
1228
|
+
},
|
|
1229
|
+
description: "The requested Collection"
|
|
1230
|
+
},
|
|
1231
|
+
404: {
|
|
1232
|
+
description: "The requested Collection does not exist"
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
// src/api/v1/entry.ts
|
|
1238
|
+
import { createRoute as createRoute3, OpenAPIHono as OpenAPIHono3, z as z15 } from "@hono/zod-openapi";
|
|
1239
|
+
var EntryApiV1 = class {
|
|
1240
|
+
api;
|
|
1241
|
+
entryService;
|
|
1242
|
+
constructor(entryService) {
|
|
1243
|
+
this.entryService = entryService;
|
|
1244
|
+
this.api = new OpenAPIHono3();
|
|
1245
|
+
this.registerRoutes();
|
|
1246
|
+
}
|
|
1247
|
+
registerRoutes() {
|
|
1248
|
+
this.api.openapi(listEntriesRoute, async (context) => {
|
|
1249
|
+
const { projectId, collectionId } = context.req.valid("param");
|
|
1250
|
+
const { limit, offset } = context.req.valid("query");
|
|
1251
|
+
const entries = await this.entryService.list({
|
|
1252
|
+
projectId,
|
|
1253
|
+
collectionId,
|
|
1254
|
+
limit,
|
|
1255
|
+
offset
|
|
1256
|
+
});
|
|
1257
|
+
return context.json(entries, 200);
|
|
1258
|
+
});
|
|
1259
|
+
this.api.openapi(countEntriesRoute, async (context) => {
|
|
1260
|
+
const { projectId, collectionId } = context.req.valid("param");
|
|
1261
|
+
const count = await this.entryService.count({ projectId, collectionId });
|
|
1262
|
+
return context.json(count, 200);
|
|
1263
|
+
});
|
|
1264
|
+
this.api.openapi(readEntryRoute, async (context) => {
|
|
1265
|
+
const { projectId, collectionId, entryId } = context.req.valid("param");
|
|
1266
|
+
const entry = await this.entryService.read({
|
|
1267
|
+
projectId,
|
|
1268
|
+
collectionId,
|
|
1269
|
+
id: entryId
|
|
1270
|
+
});
|
|
1271
|
+
return context.json(entry, 200);
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
var listEntriesRoute = createRoute3({
|
|
1276
|
+
tags: ["Entries"],
|
|
1277
|
+
description: "Lists all Entries of the given Project",
|
|
1278
|
+
method: "get",
|
|
1279
|
+
path: "/projects/{projectId}/collections/{collectionId}/entries",
|
|
1280
|
+
operationId: "listEntries",
|
|
1281
|
+
request: {
|
|
1282
|
+
params: z15.object({
|
|
1283
|
+
projectId: uuidSchema.openapi({
|
|
1284
|
+
param: {
|
|
1285
|
+
name: "projectId",
|
|
1286
|
+
in: "path"
|
|
1287
|
+
}
|
|
1288
|
+
}),
|
|
1289
|
+
collectionId: uuidSchema.openapi({
|
|
1290
|
+
param: {
|
|
1291
|
+
name: "collectionId",
|
|
1292
|
+
in: "path"
|
|
1293
|
+
}
|
|
1294
|
+
})
|
|
1295
|
+
}),
|
|
1296
|
+
query: z15.object({
|
|
1297
|
+
limit: z15.string().pipe(z15.coerce.number()).optional().openapi({
|
|
1298
|
+
default: "15",
|
|
1299
|
+
description: "The maximum number of items to return"
|
|
1300
|
+
}),
|
|
1301
|
+
offset: z15.string().pipe(z15.coerce.number()).optional().openapi({
|
|
1302
|
+
default: "0",
|
|
1303
|
+
description: "The number of items to skip before starting to collect the result set"
|
|
1304
|
+
})
|
|
1305
|
+
})
|
|
1306
|
+
},
|
|
1307
|
+
responses: {
|
|
1308
|
+
200: {
|
|
1309
|
+
content: {
|
|
1310
|
+
"application/json": {
|
|
1311
|
+
schema: paginatedListOf(entrySchema)
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
description: "A list of Entries of the given Project"
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
var countEntriesRoute = createRoute3({
|
|
1319
|
+
tags: ["Entries"],
|
|
1320
|
+
description: "Counts all Entries of the given Project",
|
|
1321
|
+
method: "get",
|
|
1322
|
+
path: "/projects/{projectId}/collections/{collectionId}/entries/count",
|
|
1323
|
+
operationId: "countEntries",
|
|
1324
|
+
request: {
|
|
1325
|
+
params: z15.object({
|
|
1326
|
+
projectId: uuidSchema.openapi({
|
|
1327
|
+
param: {
|
|
1328
|
+
name: "projectId",
|
|
1329
|
+
in: "path"
|
|
1330
|
+
}
|
|
1331
|
+
}),
|
|
1332
|
+
collectionId: uuidSchema.openapi({
|
|
1333
|
+
param: {
|
|
1334
|
+
name: "collectionId",
|
|
1335
|
+
in: "path"
|
|
1336
|
+
}
|
|
1337
|
+
})
|
|
1338
|
+
})
|
|
1339
|
+
},
|
|
1340
|
+
responses: {
|
|
1341
|
+
200: {
|
|
1342
|
+
content: {
|
|
1343
|
+
"application/json": {
|
|
1344
|
+
schema: z15.number()
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
description: "The number of Entries of the given Project"
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
var readEntryRoute = createRoute3({
|
|
1352
|
+
tags: ["Entries"],
|
|
1353
|
+
description: "Retrieve a Project by ID",
|
|
1354
|
+
method: "get",
|
|
1355
|
+
path: "/projects/{projectId}/collections/{collectionId}/entries/{entryId}",
|
|
1356
|
+
operationId: "readCollection",
|
|
1357
|
+
request: {
|
|
1358
|
+
params: z15.object({
|
|
1359
|
+
projectId: uuidSchema.openapi({
|
|
1360
|
+
param: {
|
|
1361
|
+
name: "projectId",
|
|
1362
|
+
in: "path"
|
|
1363
|
+
}
|
|
1364
|
+
}),
|
|
1365
|
+
collectionId: uuidSchema.openapi({
|
|
1366
|
+
param: {
|
|
1367
|
+
name: "collectionId",
|
|
1368
|
+
in: "path"
|
|
1369
|
+
}
|
|
1370
|
+
}),
|
|
1371
|
+
entryId: uuidSchema.openapi({
|
|
1372
|
+
param: {
|
|
1373
|
+
name: "entryId",
|
|
1374
|
+
in: "path"
|
|
1375
|
+
}
|
|
1376
|
+
})
|
|
1377
|
+
})
|
|
1378
|
+
},
|
|
1379
|
+
responses: {
|
|
1380
|
+
200: {
|
|
1381
|
+
content: {
|
|
1382
|
+
"application/json": {
|
|
1383
|
+
schema: entrySchema
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
description: "The requested Collection"
|
|
1387
|
+
},
|
|
1388
|
+
404: {
|
|
1389
|
+
description: "The requested Collection does not exist"
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
// src/api/v1/project.ts
|
|
1395
|
+
import { createRoute as createRoute4, OpenAPIHono as OpenAPIHono4, z as z16 } from "@hono/zod-openapi";
|
|
1396
|
+
var ProjectApiV1 = class {
|
|
1397
|
+
api;
|
|
1398
|
+
projectService;
|
|
1399
|
+
constructor(projectService) {
|
|
1400
|
+
this.projectService = projectService;
|
|
1401
|
+
this.api = new OpenAPIHono4();
|
|
1402
|
+
this.registerRoutes();
|
|
1403
|
+
}
|
|
1404
|
+
registerRoutes() {
|
|
1405
|
+
this.api.openapi(listProjectsRoute, async (context) => {
|
|
1406
|
+
const { limit, offset } = context.req.valid("query");
|
|
1407
|
+
const projects = await this.projectService.list({ limit, offset });
|
|
1408
|
+
return context.json(projects, 200);
|
|
1409
|
+
});
|
|
1410
|
+
this.api.openapi(countProjectsRoute, async (context) => {
|
|
1411
|
+
const count = await this.projectService.count();
|
|
1412
|
+
return context.json(count, 200);
|
|
1413
|
+
});
|
|
1414
|
+
this.api.openapi(readProjectRoute, async (context) => {
|
|
1415
|
+
const { projectId } = context.req.valid("param");
|
|
1416
|
+
const project = await this.projectService.read({ id: projectId });
|
|
1417
|
+
return context.json(project, 200);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
var listProjectsRoute = createRoute4({
|
|
1003
1422
|
tags: ["Projects"],
|
|
1004
1423
|
description: "Lists all Projects you currently have access to",
|
|
1005
1424
|
method: "get",
|
|
1006
|
-
path: "/",
|
|
1425
|
+
path: "/projects",
|
|
1007
1426
|
operationId: "listProjects",
|
|
1008
1427
|
request: {
|
|
1009
|
-
query:
|
|
1428
|
+
query: z16.object({
|
|
1429
|
+
limit: z16.string().pipe(z16.coerce.number()).optional().openapi({
|
|
1430
|
+
default: "15",
|
|
1431
|
+
description: "The maximum number of items to return"
|
|
1432
|
+
}),
|
|
1433
|
+
offset: z16.string().pipe(z16.coerce.number()).optional().openapi({
|
|
1434
|
+
default: "0",
|
|
1435
|
+
description: "The number of items to skip before starting to collect the result set"
|
|
1436
|
+
})
|
|
1437
|
+
})
|
|
1010
1438
|
},
|
|
1011
1439
|
responses: {
|
|
1012
1440
|
200: {
|
|
@@ -1019,17 +1447,34 @@ var listProjectsRoute = createRoute({
|
|
|
1019
1447
|
}
|
|
1020
1448
|
}
|
|
1021
1449
|
});
|
|
1022
|
-
var
|
|
1450
|
+
var countProjectsRoute = createRoute4({
|
|
1451
|
+
tags: ["Projects"],
|
|
1452
|
+
description: "Counts all Projects you currently have access to",
|
|
1453
|
+
method: "get",
|
|
1454
|
+
path: "/projects/count",
|
|
1455
|
+
operationId: "countProjects",
|
|
1456
|
+
responses: {
|
|
1457
|
+
200: {
|
|
1458
|
+
content: {
|
|
1459
|
+
"application/json": {
|
|
1460
|
+
schema: z16.number()
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
description: "The number of Projects you have acces to"
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
var readProjectRoute = createRoute4({
|
|
1023
1468
|
tags: ["Projects"],
|
|
1024
1469
|
description: "Retrieve a Project by ID",
|
|
1025
1470
|
method: "get",
|
|
1026
|
-
path: "/{
|
|
1471
|
+
path: "/projects/{projectId}",
|
|
1027
1472
|
operationId: "readProject",
|
|
1028
1473
|
request: {
|
|
1029
|
-
params:
|
|
1030
|
-
|
|
1474
|
+
params: z16.object({
|
|
1475
|
+
projectId: uuidSchema.openapi({
|
|
1031
1476
|
param: {
|
|
1032
|
-
name: "
|
|
1477
|
+
name: "projectId",
|
|
1033
1478
|
in: "path"
|
|
1034
1479
|
}
|
|
1035
1480
|
})
|
|
@@ -1054,20 +1499,64 @@ var readProjectRoute = createRoute({
|
|
|
1054
1499
|
var LocalApi = class {
|
|
1055
1500
|
logService;
|
|
1056
1501
|
projectService;
|
|
1502
|
+
collectionService;
|
|
1503
|
+
entryService;
|
|
1504
|
+
assetService;
|
|
1057
1505
|
api;
|
|
1058
1506
|
server = null;
|
|
1059
|
-
constructor(logService, projectService) {
|
|
1507
|
+
constructor(logService, projectService, collectionService, entryService, assetService) {
|
|
1060
1508
|
this.logService = logService;
|
|
1061
1509
|
this.projectService = projectService;
|
|
1062
|
-
this.
|
|
1510
|
+
this.collectionService = collectionService;
|
|
1511
|
+
this.entryService = entryService;
|
|
1512
|
+
this.assetService = assetService;
|
|
1513
|
+
this.api = new OpenAPIHono5();
|
|
1063
1514
|
this.api.use(
|
|
1064
1515
|
cors({
|
|
1065
1516
|
origin: ["http://localhost"]
|
|
1066
1517
|
})
|
|
1067
1518
|
);
|
|
1068
|
-
this.
|
|
1069
|
-
this.
|
|
1519
|
+
this.api.use(new LoggerMiddleware(logService).handler);
|
|
1520
|
+
this.registerRoutesV1();
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Starts the local API on given port
|
|
1524
|
+
*/
|
|
1525
|
+
start(port) {
|
|
1526
|
+
this.server = serve(
|
|
1527
|
+
{
|
|
1528
|
+
fetch: this.api.fetch,
|
|
1529
|
+
port
|
|
1530
|
+
},
|
|
1531
|
+
(info) => {
|
|
1532
|
+
this.logService.info(
|
|
1533
|
+
`Started local API on ${info.address}:${info.port} (${info.family})`
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
);
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Stops the local API
|
|
1540
|
+
*/
|
|
1541
|
+
stop() {
|
|
1542
|
+
this.server?.close(() => {
|
|
1543
|
+
this.logService.info("Stopped local API");
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
/**
|
|
1547
|
+
* Returns true if the local API is running
|
|
1548
|
+
*/
|
|
1549
|
+
isRunning() {
|
|
1550
|
+
if (this.server?.listening) {
|
|
1551
|
+
return true;
|
|
1552
|
+
}
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
registerRoutesV1() {
|
|
1556
|
+
const apiV1 = new OpenAPIHono5();
|
|
1557
|
+
apiV1.doc("/openapi.json", {
|
|
1070
1558
|
openapi: "3.0.0",
|
|
1559
|
+
externalDocs: { url: "https://elek.io/docs" },
|
|
1071
1560
|
info: {
|
|
1072
1561
|
version: "0.1.0",
|
|
1073
1562
|
title: "elek.io Project API",
|
|
@@ -1113,44 +1602,12 @@ var LocalApi = class {
|
|
|
1113
1602
|
}
|
|
1114
1603
|
]
|
|
1115
1604
|
});
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
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);
|
|
1605
|
+
apiV1.get("/ui", swaggerUI({ url: "/v1/openapi.json" }));
|
|
1606
|
+
apiV1.route("/", new ProjectApiV1(this.projectService).api);
|
|
1607
|
+
apiV1.route("/", new CollectionApiV1(this.collectionService).api);
|
|
1608
|
+
apiV1.route("/", new EntryApiV1(this.entryService).api);
|
|
1609
|
+
apiV1.route("/", new AssetApiV1(this.assetService).api);
|
|
1610
|
+
this.api.route("/v1", apiV1);
|
|
1154
1611
|
}
|
|
1155
1612
|
};
|
|
1156
1613
|
|
|
@@ -1869,15 +2326,13 @@ var EntryService = class extends AbstractCrudService {
|
|
|
1869
2326
|
jsonFileService;
|
|
1870
2327
|
gitService;
|
|
1871
2328
|
collectionService;
|
|
1872
|
-
assetService;
|
|
1873
2329
|
// private sharedValueService: SharedValueService;
|
|
1874
|
-
constructor(options, logService, jsonFileService, gitService, collectionService
|
|
2330
|
+
constructor(options, logService, jsonFileService, gitService, collectionService) {
|
|
1875
2331
|
super(serviceTypeSchema.Enum.Entry, options);
|
|
1876
2332
|
this.logService = logService;
|
|
1877
2333
|
this.jsonFileService = jsonFileService;
|
|
1878
2334
|
this.gitService = gitService;
|
|
1879
2335
|
this.collectionService = collectionService;
|
|
1880
|
-
this.assetService = assetService;
|
|
1881
2336
|
}
|
|
1882
2337
|
/**
|
|
1883
2338
|
* Creates a new Entry for given Collection
|
|
@@ -2114,74 +2569,6 @@ var EntryService = class extends AbstractCrudService {
|
|
|
2114
2569
|
}
|
|
2115
2570
|
});
|
|
2116
2571
|
}
|
|
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
2572
|
/**
|
|
2186
2573
|
* Creates an Entry from given EntryFile by resolving it's Values
|
|
2187
2574
|
*/
|
|
@@ -2191,24 +2578,7 @@ var EntryService = class extends AbstractCrudService {
|
|
|
2191
2578
|
});
|
|
2192
2579
|
return {
|
|
2193
2580
|
...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
|
-
)
|
|
2581
|
+
history
|
|
2212
2582
|
};
|
|
2213
2583
|
}
|
|
2214
2584
|
};
|
|
@@ -3744,8 +4114,7 @@ var ElekIoCore = class {
|
|
|
3744
4114
|
this.logService,
|
|
3745
4115
|
this.jsonFileService,
|
|
3746
4116
|
this.gitService,
|
|
3747
|
-
this.collectionService
|
|
3748
|
-
this.assetService
|
|
4117
|
+
this.collectionService
|
|
3749
4118
|
);
|
|
3750
4119
|
this.projectService = new ProjectService(
|
|
3751
4120
|
this.coreVersion,
|
|
@@ -3758,7 +4127,13 @@ var ElekIoCore = class {
|
|
|
3758
4127
|
this.collectionService,
|
|
3759
4128
|
this.entryService
|
|
3760
4129
|
);
|
|
3761
|
-
this.localApi = new LocalApi(
|
|
4130
|
+
this.localApi = new LocalApi(
|
|
4131
|
+
this.logService,
|
|
4132
|
+
this.projectService,
|
|
4133
|
+
this.collectionService,
|
|
4134
|
+
this.entryService,
|
|
4135
|
+
this.assetService
|
|
4136
|
+
);
|
|
3762
4137
|
this.logService.info(`Initializing elek.io Core ${this.coreVersion}`, {
|
|
3763
4138
|
options: this.options
|
|
3764
4139
|
});
|
|
@@ -3916,9 +4291,6 @@ export {
|
|
|
3916
4291
|
readGitTagSchema,
|
|
3917
4292
|
readProjectSchema,
|
|
3918
4293
|
referencedValueSchema,
|
|
3919
|
-
resolvedReferencedValueSchema,
|
|
3920
|
-
resolvedValueContentReferenceSchema,
|
|
3921
|
-
resolvedValueSchema,
|
|
3922
4294
|
saveAssetSchema,
|
|
3923
4295
|
searchProjectSchema,
|
|
3924
4296
|
serviceTypeSchema,
|