@semiont/backend 0.3.4 → 0.3.6
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/dist/index.js +64 -71
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
import winston from 'winston';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import jwt from 'jsonwebtoken';
|
|
5
|
-
import {
|
|
5
|
+
import { email, userId, accessToken, googleCredential, annotationId, resourceId, EventBus, jobId, entityType, assembleAnnotation, userToAgent } from '@semiont/core';
|
|
6
6
|
import { cors } from 'hono/cors';
|
|
7
7
|
import { serve } from '@hono/node-server';
|
|
8
8
|
import { Hono } from 'hono';
|
|
9
9
|
import { swaggerUI } from '@hono/swagger-ui';
|
|
10
|
+
import { SemiontProject, loadEnvironmentConfig } from '@semiont/core/node';
|
|
10
11
|
import { exportBackup, importBackup, readEntityTypesProjection, exportLinkedData, importLinkedData, AnnotationContext, startMakeMeaning, ResourceContext, ResourceOperations } from '@semiont/make-meaning';
|
|
11
|
-
import * as fs from 'fs';
|
|
12
|
-
import * as path from 'path';
|
|
13
12
|
import { PrismaClient } from '@prisma/client';
|
|
14
13
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
15
14
|
import { HTTPException } from 'hono/http-exception';
|
|
@@ -20,6 +19,8 @@ import { Writable, Readable } from 'stream';
|
|
|
20
19
|
import { streamSSE } from 'hono/streaming';
|
|
21
20
|
import crypto2, { randomUUID } from 'crypto';
|
|
22
21
|
import { EventQuery } from '@semiont/event-sourcing';
|
|
22
|
+
import * as fs from 'fs';
|
|
23
|
+
import * as path from 'path';
|
|
23
24
|
import { fileURLToPath } from 'url';
|
|
24
25
|
|
|
25
26
|
var __create = Object.create;
|
|
@@ -1070,7 +1071,7 @@ var require_Observable = __commonJS({
|
|
|
1070
1071
|
Observable2.prototype.forEach = function(next, promiseCtor) {
|
|
1071
1072
|
var _this = this;
|
|
1072
1073
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
1073
|
-
return new promiseCtor(function(
|
|
1074
|
+
return new promiseCtor(function(resolve, reject) {
|
|
1074
1075
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
1075
1076
|
next: /* @__PURE__ */ __name(function(value) {
|
|
1076
1077
|
try {
|
|
@@ -1081,7 +1082,7 @@ var require_Observable = __commonJS({
|
|
|
1081
1082
|
}
|
|
1082
1083
|
}, "next"),
|
|
1083
1084
|
error: reject,
|
|
1084
|
-
complete:
|
|
1085
|
+
complete: resolve
|
|
1085
1086
|
});
|
|
1086
1087
|
_this.subscribe(subscriber);
|
|
1087
1088
|
});
|
|
@@ -1103,14 +1104,14 @@ var require_Observable = __commonJS({
|
|
|
1103
1104
|
Observable2.prototype.toPromise = function(promiseCtor) {
|
|
1104
1105
|
var _this = this;
|
|
1105
1106
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
1106
|
-
return new promiseCtor(function(
|
|
1107
|
+
return new promiseCtor(function(resolve, reject) {
|
|
1107
1108
|
var value;
|
|
1108
1109
|
_this.subscribe(function(x) {
|
|
1109
1110
|
return value = x;
|
|
1110
1111
|
}, function(err) {
|
|
1111
1112
|
return reject(err);
|
|
1112
1113
|
}, function() {
|
|
1113
|
-
return
|
|
1114
|
+
return resolve(value);
|
|
1114
1115
|
});
|
|
1115
1116
|
});
|
|
1116
1117
|
};
|
|
@@ -3394,12 +3395,12 @@ var require_innerFrom = __commonJS({
|
|
|
3394
3395
|
"../../node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js"(exports$1) {
|
|
3395
3396
|
var __awaiter = exports$1 && exports$1.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3396
3397
|
function adopt(value) {
|
|
3397
|
-
return value instanceof P ? value : new P(function(
|
|
3398
|
-
|
|
3398
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
3399
|
+
resolve(value);
|
|
3399
3400
|
});
|
|
3400
3401
|
}
|
|
3401
3402
|
__name(adopt, "adopt");
|
|
3402
|
-
return new (P || (P = Promise))(function(
|
|
3403
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
3403
3404
|
function fulfilled(value) {
|
|
3404
3405
|
try {
|
|
3405
3406
|
step(generator.next(value));
|
|
@@ -3417,7 +3418,7 @@ var require_innerFrom = __commonJS({
|
|
|
3417
3418
|
}
|
|
3418
3419
|
__name(rejected, "rejected");
|
|
3419
3420
|
function step(result) {
|
|
3420
|
-
result.done ?
|
|
3421
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
3421
3422
|
}
|
|
3422
3423
|
__name(step, "step");
|
|
3423
3424
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
@@ -3526,14 +3527,14 @@ var require_innerFrom = __commonJS({
|
|
|
3526
3527
|
}, i);
|
|
3527
3528
|
function verb(n) {
|
|
3528
3529
|
i[n] = o[n] && function(v) {
|
|
3529
|
-
return new Promise(function(
|
|
3530
|
-
v = o[n](v), settle(
|
|
3530
|
+
return new Promise(function(resolve, reject) {
|
|
3531
|
+
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
3531
3532
|
});
|
|
3532
3533
|
};
|
|
3533
3534
|
}
|
|
3534
|
-
function settle(
|
|
3535
|
+
function settle(resolve, reject, d, v) {
|
|
3535
3536
|
Promise.resolve(v).then(function(v2) {
|
|
3536
|
-
|
|
3537
|
+
resolve({
|
|
3537
3538
|
value: v2,
|
|
3538
3539
|
done: d
|
|
3539
3540
|
});
|
|
@@ -4246,7 +4247,7 @@ var require_lastValueFrom = __commonJS({
|
|
|
4246
4247
|
var EmptyError_1 = require_EmptyError();
|
|
4247
4248
|
function lastValueFrom(source, config2) {
|
|
4248
4249
|
var hasConfig = typeof config2 === "object";
|
|
4249
|
-
return new Promise(function(
|
|
4250
|
+
return new Promise(function(resolve, reject) {
|
|
4250
4251
|
var _hasValue = false;
|
|
4251
4252
|
var _value;
|
|
4252
4253
|
source.subscribe({
|
|
@@ -4257,9 +4258,9 @@ var require_lastValueFrom = __commonJS({
|
|
|
4257
4258
|
error: reject,
|
|
4258
4259
|
complete: /* @__PURE__ */ __name(function() {
|
|
4259
4260
|
if (_hasValue) {
|
|
4260
|
-
|
|
4261
|
+
resolve(_value);
|
|
4261
4262
|
} else if (hasConfig) {
|
|
4262
|
-
|
|
4263
|
+
resolve(config2.defaultValue);
|
|
4263
4264
|
} else {
|
|
4264
4265
|
reject(new EmptyError_1.EmptyError());
|
|
4265
4266
|
}
|
|
@@ -4283,16 +4284,16 @@ var require_firstValueFrom = __commonJS({
|
|
|
4283
4284
|
var Subscriber_1 = require_Subscriber();
|
|
4284
4285
|
function firstValueFrom4(source, config2) {
|
|
4285
4286
|
var hasConfig = typeof config2 === "object";
|
|
4286
|
-
return new Promise(function(
|
|
4287
|
+
return new Promise(function(resolve, reject) {
|
|
4287
4288
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
4288
4289
|
next: /* @__PURE__ */ __name(function(value) {
|
|
4289
|
-
|
|
4290
|
+
resolve(value);
|
|
4290
4291
|
subscriber.unsubscribe();
|
|
4291
4292
|
}, "next"),
|
|
4292
4293
|
error: reject,
|
|
4293
4294
|
complete: /* @__PURE__ */ __name(function() {
|
|
4294
4295
|
if (hasConfig) {
|
|
4295
|
-
|
|
4296
|
+
resolve(config2.defaultValue);
|
|
4296
4297
|
} else {
|
|
4297
4298
|
reject(new EmptyError_1.EmptyError());
|
|
4298
4299
|
}
|
|
@@ -11897,20 +11898,17 @@ var require_operators = __commonJS({
|
|
|
11897
11898
|
});
|
|
11898
11899
|
}
|
|
11899
11900
|
});
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11905
|
-
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
}, "readRequired")
|
|
11912
|
-
};
|
|
11913
|
-
var loadEnvironmentConfig = createConfigLoader(nodeFileReader);
|
|
11901
|
+
function makeMeaningConfigFrom(config2) {
|
|
11902
|
+
const meta = config2._metadata;
|
|
11903
|
+
return {
|
|
11904
|
+
services: {
|
|
11905
|
+
graph: config2.services?.graph
|
|
11906
|
+
},
|
|
11907
|
+
actors: meta?.actors,
|
|
11908
|
+
workers: meta?.workers
|
|
11909
|
+
};
|
|
11910
|
+
}
|
|
11911
|
+
__name(makeMeaningConfigFrom, "makeMeaningConfigFrom");
|
|
11914
11912
|
|
|
11915
11913
|
// src/index.ts
|
|
11916
11914
|
init_logger();
|
|
@@ -12085,9 +12083,9 @@ healthRouter.get("/api/health", async (c) => {
|
|
|
12085
12083
|
}
|
|
12086
12084
|
let startupFailed = false;
|
|
12087
12085
|
try {
|
|
12088
|
-
const
|
|
12089
|
-
if (
|
|
12090
|
-
const startupStatus =
|
|
12086
|
+
const fs2 = await import('fs');
|
|
12087
|
+
if (fs2.existsSync("/tmp/startup_status")) {
|
|
12088
|
+
const startupStatus = fs2.readFileSync("/tmp/startup_status", "utf-8").trim();
|
|
12091
12089
|
if (startupStatus.startsWith("FAILED")) {
|
|
12092
12090
|
startupFailed = true;
|
|
12093
12091
|
getRouteLogger().error("Startup script failure detected", {
|
|
@@ -15397,18 +15395,18 @@ __name(validateSchema, "validateSchema");
|
|
|
15397
15395
|
function formatValidationErrors(errors) {
|
|
15398
15396
|
if (errors.length === 0) return "Validation failed";
|
|
15399
15397
|
const messages = errors.map((err) => {
|
|
15400
|
-
const
|
|
15398
|
+
const path2 = err.instancePath || "root";
|
|
15401
15399
|
const message = err.message || "validation error";
|
|
15402
15400
|
if (err.keyword === "required" && "missingProperty" in err.params) {
|
|
15403
15401
|
return `Missing required property: ${err.params.missingProperty}`;
|
|
15404
15402
|
}
|
|
15405
15403
|
if (err.keyword === "type" && "type" in err.params) {
|
|
15406
|
-
return `${
|
|
15404
|
+
return `${path2}: ${message} (expected ${err.params.type})`;
|
|
15407
15405
|
}
|
|
15408
15406
|
if (err.keyword === "enum" && "allowedValues" in err.params) {
|
|
15409
|
-
return `${
|
|
15407
|
+
return `${path2}: must be one of [${err.params.allowedValues.join(", ")}]`;
|
|
15410
15408
|
}
|
|
15411
|
-
return `${
|
|
15409
|
+
return `${path2}: ${message}`;
|
|
15412
15410
|
});
|
|
15413
15411
|
return messages.join("; ");
|
|
15414
15412
|
}
|
|
@@ -16321,12 +16319,7 @@ exchangeRouter.post("/api/moderate/exchange/export", async (c) => {
|
|
|
16321
16319
|
const config2 = c.get("config");
|
|
16322
16320
|
const sourceUrl = config2.services?.backend?.publicURL ?? "http://localhost:4000";
|
|
16323
16321
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
16324
|
-
const entityTypes = await readEntityTypesProjection(
|
|
16325
|
-
services: {
|
|
16326
|
-
filesystem: config2.services?.filesystem
|
|
16327
|
-
},
|
|
16328
|
-
_metadata: config2._metadata
|
|
16329
|
-
});
|
|
16322
|
+
const entityTypes = await readEntityTypesProjection(new SemiontProject(config2._metadata.projectRoot));
|
|
16330
16323
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
16331
16324
|
const filename = `semiont-export-${timestamp}.tar.gz`;
|
|
16332
16325
|
let controller;
|
|
@@ -17014,8 +17007,8 @@ function registerAnnotateReferencesStream(router, jobQueue) {
|
|
|
17014
17007
|
const subscriptions = [];
|
|
17015
17008
|
let keepAliveInterval = null;
|
|
17016
17009
|
let closeStreamCallback = null;
|
|
17017
|
-
const streamPromise = new Promise((
|
|
17018
|
-
closeStreamCallback =
|
|
17010
|
+
const streamPromise = new Promise((resolve) => {
|
|
17011
|
+
closeStreamCallback = resolve;
|
|
17019
17012
|
});
|
|
17020
17013
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17021
17014
|
if (isStreamClosed) return;
|
|
@@ -17216,8 +17209,8 @@ function registerAnnotateHighlightsStream(router, jobQueue) {
|
|
|
17216
17209
|
const subscriptions = [];
|
|
17217
17210
|
let keepAliveInterval = null;
|
|
17218
17211
|
let closeStreamCallback = null;
|
|
17219
|
-
const streamPromise = new Promise((
|
|
17220
|
-
closeStreamCallback =
|
|
17212
|
+
const streamPromise = new Promise((resolve) => {
|
|
17213
|
+
closeStreamCallback = resolve;
|
|
17221
17214
|
});
|
|
17222
17215
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17223
17216
|
if (isStreamClosed) return;
|
|
@@ -17427,8 +17420,8 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17427
17420
|
const subscriptions = [];
|
|
17428
17421
|
let keepAliveInterval = null;
|
|
17429
17422
|
let closeStreamCallback = null;
|
|
17430
|
-
const streamPromise = new Promise((
|
|
17431
|
-
closeStreamCallback =
|
|
17423
|
+
const streamPromise = new Promise((resolve) => {
|
|
17424
|
+
closeStreamCallback = resolve;
|
|
17432
17425
|
});
|
|
17433
17426
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17434
17427
|
if (isStreamClosed) return;
|
|
@@ -17648,8 +17641,8 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17648
17641
|
const subscriptions = [];
|
|
17649
17642
|
let keepAliveInterval = null;
|
|
17650
17643
|
let closeStreamCallback = null;
|
|
17651
|
-
const streamPromise = new Promise((
|
|
17652
|
-
closeStreamCallback =
|
|
17644
|
+
const streamPromise = new Promise((resolve) => {
|
|
17645
|
+
closeStreamCallback = resolve;
|
|
17653
17646
|
});
|
|
17654
17647
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17655
17648
|
if (isStreamClosed) return;
|
|
@@ -18039,8 +18032,8 @@ function registerAnnotateTagsStream(router, jobQueue) {
|
|
|
18039
18032
|
const subscriptions = [];
|
|
18040
18033
|
let keepAliveInterval = null;
|
|
18041
18034
|
let closeStreamCallback = null;
|
|
18042
|
-
const streamPromise = new Promise((
|
|
18043
|
-
closeStreamCallback =
|
|
18035
|
+
const streamPromise = new Promise((resolve) => {
|
|
18036
|
+
closeStreamCallback = resolve;
|
|
18044
18037
|
});
|
|
18045
18038
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18046
18039
|
if (isStreamClosed) return;
|
|
@@ -18382,8 +18375,8 @@ function registerBindSearchStream(router) {
|
|
|
18382
18375
|
let isStreamClosed = false;
|
|
18383
18376
|
const subscriptions = [];
|
|
18384
18377
|
let closeStreamCallback = null;
|
|
18385
|
-
const streamPromise = new Promise((
|
|
18386
|
-
closeStreamCallback =
|
|
18378
|
+
const streamPromise = new Promise((resolve) => {
|
|
18379
|
+
closeStreamCallback = resolve;
|
|
18387
18380
|
});
|
|
18388
18381
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18389
18382
|
if (isStreamClosed) return;
|
|
@@ -18679,8 +18672,8 @@ function registerGetEventStream(router) {
|
|
|
18679
18672
|
let subscription = null;
|
|
18680
18673
|
let keepAliveInterval = null;
|
|
18681
18674
|
let closeStreamCallback = null;
|
|
18682
|
-
const streamPromise = new Promise((
|
|
18683
|
-
closeStreamCallback =
|
|
18675
|
+
const streamPromise = new Promise((resolve) => {
|
|
18676
|
+
closeStreamCallback = resolve;
|
|
18684
18677
|
});
|
|
18685
18678
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18686
18679
|
if (isStreamClosed) return;
|
|
@@ -18959,8 +18952,8 @@ function registerYieldResourceStream(router, jobQueue) {
|
|
|
18959
18952
|
const subscriptions = [];
|
|
18960
18953
|
let keepAliveInterval = null;
|
|
18961
18954
|
let closeStreamCallback = null;
|
|
18962
|
-
const streamPromise = new Promise((
|
|
18963
|
-
closeStreamCallback =
|
|
18955
|
+
const streamPromise = new Promise((resolve) => {
|
|
18956
|
+
closeStreamCallback = resolve;
|
|
18964
18957
|
});
|
|
18965
18958
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18966
18959
|
if (isStreamClosed) return;
|
|
@@ -19250,7 +19243,7 @@ operationsRouter.get("/api/annotations/:id/context", async (c) => {
|
|
|
19250
19243
|
operationsRouter.get("/api/annotations/:id/summary", async (c) => {
|
|
19251
19244
|
const { id } = c.req.param();
|
|
19252
19245
|
const query = c.req.query();
|
|
19253
|
-
const { kb, inferenceClient } = c.get("makeMeaning");
|
|
19246
|
+
const { kb, gathererInferenceClient: inferenceClient } = c.get("makeMeaning");
|
|
19254
19247
|
const resourceId20 = query.resourceId;
|
|
19255
19248
|
if (!resourceId20) {
|
|
19256
19249
|
throw new HTTPException(400, {
|
|
@@ -19351,8 +19344,8 @@ globalEventsRouter.get("/api/events/stream", async (c) => {
|
|
|
19351
19344
|
let isStreamClosed = false;
|
|
19352
19345
|
let keepAliveInterval = null;
|
|
19353
19346
|
let closeStreamCallback = null;
|
|
19354
|
-
const streamPromise = new Promise((
|
|
19355
|
-
closeStreamCallback =
|
|
19347
|
+
const streamPromise = new Promise((resolve) => {
|
|
19348
|
+
closeStreamCallback = resolve;
|
|
19356
19349
|
});
|
|
19357
19350
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
19358
19351
|
if (isStreamClosed) return;
|
|
@@ -19511,13 +19504,13 @@ var requestLoggerMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
|
19511
19504
|
const logger2 = c.get("logger");
|
|
19512
19505
|
const startTime = Date.now();
|
|
19513
19506
|
const method = c.req.method;
|
|
19514
|
-
const
|
|
19507
|
+
const path2 = c.req.path;
|
|
19515
19508
|
const query = c.req.query();
|
|
19516
19509
|
const userAgent = c.req.header("User-Agent") || "unknown";
|
|
19517
19510
|
logger2.http("Incoming request", {
|
|
19518
19511
|
type: "request_incoming",
|
|
19519
19512
|
method,
|
|
19520
|
-
path:
|
|
19513
|
+
path: path2,
|
|
19521
19514
|
query: Object.keys(query).length > 0 ? query : void 0,
|
|
19522
19515
|
userAgent
|
|
19523
19516
|
});
|
|
@@ -19527,7 +19520,7 @@ var requestLoggerMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
|
19527
19520
|
logger2.http("Outgoing response", {
|
|
19528
19521
|
type: "request_outgoing",
|
|
19529
19522
|
method,
|
|
19530
|
-
path:
|
|
19523
|
+
path: path2,
|
|
19531
19524
|
status,
|
|
19532
19525
|
duration,
|
|
19533
19526
|
durationMs: duration
|
|
@@ -19597,7 +19590,7 @@ if (databaseUrlConstructed) {
|
|
|
19597
19590
|
});
|
|
19598
19591
|
}
|
|
19599
19592
|
var eventBus = new EventBus();
|
|
19600
|
-
var makeMeaning = await startMakeMeaning(config, eventBus, logger);
|
|
19593
|
+
var makeMeaning = await startMakeMeaning(new SemiontProject(projectRoot), makeMeaningConfigFrom(config), eventBus, logger);
|
|
19601
19594
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
19602
19595
|
var __dirname$1 = path.dirname(__filename$1);
|
|
19603
19596
|
var app = new Hono();
|