@semiont/backend 0.3.3 → 0.3.5
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 +69 -71
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/prisma/schema.prisma +0 -1
package/dist/index.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
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';
|
|
13
|
+
import { PrismaPg } from '@prisma/adapter-pg';
|
|
14
14
|
import { HTTPException } from 'hono/http-exception';
|
|
15
15
|
import Ajv from 'ajv';
|
|
16
16
|
import addFormats from 'ajv-formats';
|
|
@@ -19,6 +19,8 @@ import { Writable, Readable } from 'stream';
|
|
|
19
19
|
import { streamSSE } from 'hono/streaming';
|
|
20
20
|
import crypto2, { randomUUID } from 'crypto';
|
|
21
21
|
import { EventQuery } from '@semiont/event-sourcing';
|
|
22
|
+
import * as fs from 'fs';
|
|
23
|
+
import * as path from 'path';
|
|
22
24
|
import { fileURLToPath } from 'url';
|
|
23
25
|
|
|
24
26
|
var __create = Object.create;
|
|
@@ -1069,7 +1071,7 @@ var require_Observable = __commonJS({
|
|
|
1069
1071
|
Observable2.prototype.forEach = function(next, promiseCtor) {
|
|
1070
1072
|
var _this = this;
|
|
1071
1073
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
1072
|
-
return new promiseCtor(function(
|
|
1074
|
+
return new promiseCtor(function(resolve, reject) {
|
|
1073
1075
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
1074
1076
|
next: /* @__PURE__ */ __name(function(value) {
|
|
1075
1077
|
try {
|
|
@@ -1080,7 +1082,7 @@ var require_Observable = __commonJS({
|
|
|
1080
1082
|
}
|
|
1081
1083
|
}, "next"),
|
|
1082
1084
|
error: reject,
|
|
1083
|
-
complete:
|
|
1085
|
+
complete: resolve
|
|
1084
1086
|
});
|
|
1085
1087
|
_this.subscribe(subscriber);
|
|
1086
1088
|
});
|
|
@@ -1102,14 +1104,14 @@ var require_Observable = __commonJS({
|
|
|
1102
1104
|
Observable2.prototype.toPromise = function(promiseCtor) {
|
|
1103
1105
|
var _this = this;
|
|
1104
1106
|
promiseCtor = getPromiseCtor(promiseCtor);
|
|
1105
|
-
return new promiseCtor(function(
|
|
1107
|
+
return new promiseCtor(function(resolve, reject) {
|
|
1106
1108
|
var value;
|
|
1107
1109
|
_this.subscribe(function(x) {
|
|
1108
1110
|
return value = x;
|
|
1109
1111
|
}, function(err) {
|
|
1110
1112
|
return reject(err);
|
|
1111
1113
|
}, function() {
|
|
1112
|
-
return
|
|
1114
|
+
return resolve(value);
|
|
1113
1115
|
});
|
|
1114
1116
|
});
|
|
1115
1117
|
};
|
|
@@ -3393,12 +3395,12 @@ var require_innerFrom = __commonJS({
|
|
|
3393
3395
|
"../../node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js"(exports$1) {
|
|
3394
3396
|
var __awaiter = exports$1 && exports$1.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3395
3397
|
function adopt(value) {
|
|
3396
|
-
return value instanceof P ? value : new P(function(
|
|
3397
|
-
|
|
3398
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
3399
|
+
resolve(value);
|
|
3398
3400
|
});
|
|
3399
3401
|
}
|
|
3400
3402
|
__name(adopt, "adopt");
|
|
3401
|
-
return new (P || (P = Promise))(function(
|
|
3403
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
3402
3404
|
function fulfilled(value) {
|
|
3403
3405
|
try {
|
|
3404
3406
|
step(generator.next(value));
|
|
@@ -3416,7 +3418,7 @@ var require_innerFrom = __commonJS({
|
|
|
3416
3418
|
}
|
|
3417
3419
|
__name(rejected, "rejected");
|
|
3418
3420
|
function step(result) {
|
|
3419
|
-
result.done ?
|
|
3421
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
3420
3422
|
}
|
|
3421
3423
|
__name(step, "step");
|
|
3422
3424
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
@@ -3525,14 +3527,14 @@ var require_innerFrom = __commonJS({
|
|
|
3525
3527
|
}, i);
|
|
3526
3528
|
function verb(n) {
|
|
3527
3529
|
i[n] = o[n] && function(v) {
|
|
3528
|
-
return new Promise(function(
|
|
3529
|
-
v = o[n](v), settle(
|
|
3530
|
+
return new Promise(function(resolve, reject) {
|
|
3531
|
+
v = o[n](v), settle(resolve, reject, v.done, v.value);
|
|
3530
3532
|
});
|
|
3531
3533
|
};
|
|
3532
3534
|
}
|
|
3533
|
-
function settle(
|
|
3535
|
+
function settle(resolve, reject, d, v) {
|
|
3534
3536
|
Promise.resolve(v).then(function(v2) {
|
|
3535
|
-
|
|
3537
|
+
resolve({
|
|
3536
3538
|
value: v2,
|
|
3537
3539
|
done: d
|
|
3538
3540
|
});
|
|
@@ -4245,7 +4247,7 @@ var require_lastValueFrom = __commonJS({
|
|
|
4245
4247
|
var EmptyError_1 = require_EmptyError();
|
|
4246
4248
|
function lastValueFrom(source, config2) {
|
|
4247
4249
|
var hasConfig = typeof config2 === "object";
|
|
4248
|
-
return new Promise(function(
|
|
4250
|
+
return new Promise(function(resolve, reject) {
|
|
4249
4251
|
var _hasValue = false;
|
|
4250
4252
|
var _value;
|
|
4251
4253
|
source.subscribe({
|
|
@@ -4256,9 +4258,9 @@ var require_lastValueFrom = __commonJS({
|
|
|
4256
4258
|
error: reject,
|
|
4257
4259
|
complete: /* @__PURE__ */ __name(function() {
|
|
4258
4260
|
if (_hasValue) {
|
|
4259
|
-
|
|
4261
|
+
resolve(_value);
|
|
4260
4262
|
} else if (hasConfig) {
|
|
4261
|
-
|
|
4263
|
+
resolve(config2.defaultValue);
|
|
4262
4264
|
} else {
|
|
4263
4265
|
reject(new EmptyError_1.EmptyError());
|
|
4264
4266
|
}
|
|
@@ -4282,16 +4284,16 @@ var require_firstValueFrom = __commonJS({
|
|
|
4282
4284
|
var Subscriber_1 = require_Subscriber();
|
|
4283
4285
|
function firstValueFrom4(source, config2) {
|
|
4284
4286
|
var hasConfig = typeof config2 === "object";
|
|
4285
|
-
return new Promise(function(
|
|
4287
|
+
return new Promise(function(resolve, reject) {
|
|
4286
4288
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
4287
4289
|
next: /* @__PURE__ */ __name(function(value) {
|
|
4288
|
-
|
|
4290
|
+
resolve(value);
|
|
4289
4291
|
subscriber.unsubscribe();
|
|
4290
4292
|
}, "next"),
|
|
4291
4293
|
error: reject,
|
|
4292
4294
|
complete: /* @__PURE__ */ __name(function() {
|
|
4293
4295
|
if (hasConfig) {
|
|
4294
|
-
|
|
4296
|
+
resolve(config2.defaultValue);
|
|
4295
4297
|
} else {
|
|
4296
4298
|
reject(new EmptyError_1.EmptyError());
|
|
4297
4299
|
}
|
|
@@ -11896,20 +11898,17 @@ var require_operators = __commonJS({
|
|
|
11896
11898
|
});
|
|
11897
11899
|
}
|
|
11898
11900
|
});
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11905
|
-
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
}, "readRequired")
|
|
11911
|
-
};
|
|
11912
|
-
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");
|
|
11913
11912
|
|
|
11914
11913
|
// src/index.ts
|
|
11915
11914
|
init_logger();
|
|
@@ -11941,7 +11940,11 @@ var DatabaseConnection = class {
|
|
|
11941
11940
|
emit: "event",
|
|
11942
11941
|
level
|
|
11943
11942
|
}));
|
|
11943
|
+
const adapter = new PrismaPg({
|
|
11944
|
+
connectionString: process.env.DATABASE_URL
|
|
11945
|
+
});
|
|
11944
11946
|
this.instance = new PrismaClient({
|
|
11947
|
+
adapter,
|
|
11945
11948
|
log: logConfig
|
|
11946
11949
|
});
|
|
11947
11950
|
this.instance.$on("query", (e) => {
|
|
@@ -12080,9 +12083,9 @@ healthRouter.get("/api/health", async (c) => {
|
|
|
12080
12083
|
}
|
|
12081
12084
|
let startupFailed = false;
|
|
12082
12085
|
try {
|
|
12083
|
-
const
|
|
12084
|
-
if (
|
|
12085
|
-
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();
|
|
12086
12089
|
if (startupStatus.startsWith("FAILED")) {
|
|
12087
12090
|
startupFailed = true;
|
|
12088
12091
|
getRouteLogger().error("Startup script failure detected", {
|
|
@@ -15392,18 +15395,18 @@ __name(validateSchema, "validateSchema");
|
|
|
15392
15395
|
function formatValidationErrors(errors) {
|
|
15393
15396
|
if (errors.length === 0) return "Validation failed";
|
|
15394
15397
|
const messages = errors.map((err) => {
|
|
15395
|
-
const
|
|
15398
|
+
const path2 = err.instancePath || "root";
|
|
15396
15399
|
const message = err.message || "validation error";
|
|
15397
15400
|
if (err.keyword === "required" && "missingProperty" in err.params) {
|
|
15398
15401
|
return `Missing required property: ${err.params.missingProperty}`;
|
|
15399
15402
|
}
|
|
15400
15403
|
if (err.keyword === "type" && "type" in err.params) {
|
|
15401
|
-
return `${
|
|
15404
|
+
return `${path2}: ${message} (expected ${err.params.type})`;
|
|
15402
15405
|
}
|
|
15403
15406
|
if (err.keyword === "enum" && "allowedValues" in err.params) {
|
|
15404
|
-
return `${
|
|
15407
|
+
return `${path2}: must be one of [${err.params.allowedValues.join(", ")}]`;
|
|
15405
15408
|
}
|
|
15406
|
-
return `${
|
|
15409
|
+
return `${path2}: ${message}`;
|
|
15407
15410
|
});
|
|
15408
15411
|
return messages.join("; ");
|
|
15409
15412
|
}
|
|
@@ -16316,12 +16319,7 @@ exchangeRouter.post("/api/moderate/exchange/export", async (c) => {
|
|
|
16316
16319
|
const config2 = c.get("config");
|
|
16317
16320
|
const sourceUrl = config2.services?.backend?.publicURL ?? "http://localhost:4000";
|
|
16318
16321
|
const includeArchived = c.req.query("includeArchived") === "true";
|
|
16319
|
-
const entityTypes = await readEntityTypesProjection(
|
|
16320
|
-
services: {
|
|
16321
|
-
filesystem: config2.services?.filesystem
|
|
16322
|
-
},
|
|
16323
|
-
_metadata: config2._metadata
|
|
16324
|
-
});
|
|
16322
|
+
const entityTypes = await readEntityTypesProjection(new SemiontProject(config2._metadata.projectRoot));
|
|
16325
16323
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
16326
16324
|
const filename = `semiont-export-${timestamp}.tar.gz`;
|
|
16327
16325
|
let controller;
|
|
@@ -17009,8 +17007,8 @@ function registerAnnotateReferencesStream(router, jobQueue) {
|
|
|
17009
17007
|
const subscriptions = [];
|
|
17010
17008
|
let keepAliveInterval = null;
|
|
17011
17009
|
let closeStreamCallback = null;
|
|
17012
|
-
const streamPromise = new Promise((
|
|
17013
|
-
closeStreamCallback =
|
|
17010
|
+
const streamPromise = new Promise((resolve) => {
|
|
17011
|
+
closeStreamCallback = resolve;
|
|
17014
17012
|
});
|
|
17015
17013
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17016
17014
|
if (isStreamClosed) return;
|
|
@@ -17211,8 +17209,8 @@ function registerAnnotateHighlightsStream(router, jobQueue) {
|
|
|
17211
17209
|
const subscriptions = [];
|
|
17212
17210
|
let keepAliveInterval = null;
|
|
17213
17211
|
let closeStreamCallback = null;
|
|
17214
|
-
const streamPromise = new Promise((
|
|
17215
|
-
closeStreamCallback =
|
|
17212
|
+
const streamPromise = new Promise((resolve) => {
|
|
17213
|
+
closeStreamCallback = resolve;
|
|
17216
17214
|
});
|
|
17217
17215
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17218
17216
|
if (isStreamClosed) return;
|
|
@@ -17422,8 +17420,8 @@ function registerAnnotateAssessmentsStream(router, jobQueue) {
|
|
|
17422
17420
|
const subscriptions = [];
|
|
17423
17421
|
let keepAliveInterval = null;
|
|
17424
17422
|
let closeStreamCallback = null;
|
|
17425
|
-
const streamPromise = new Promise((
|
|
17426
|
-
closeStreamCallback =
|
|
17423
|
+
const streamPromise = new Promise((resolve) => {
|
|
17424
|
+
closeStreamCallback = resolve;
|
|
17427
17425
|
});
|
|
17428
17426
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17429
17427
|
if (isStreamClosed) return;
|
|
@@ -17643,8 +17641,8 @@ function registerAnnotateCommentsStream(router, jobQueue) {
|
|
|
17643
17641
|
const subscriptions = [];
|
|
17644
17642
|
let keepAliveInterval = null;
|
|
17645
17643
|
let closeStreamCallback = null;
|
|
17646
|
-
const streamPromise = new Promise((
|
|
17647
|
-
closeStreamCallback =
|
|
17644
|
+
const streamPromise = new Promise((resolve) => {
|
|
17645
|
+
closeStreamCallback = resolve;
|
|
17648
17646
|
});
|
|
17649
17647
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
17650
17648
|
if (isStreamClosed) return;
|
|
@@ -18034,8 +18032,8 @@ function registerAnnotateTagsStream(router, jobQueue) {
|
|
|
18034
18032
|
const subscriptions = [];
|
|
18035
18033
|
let keepAliveInterval = null;
|
|
18036
18034
|
let closeStreamCallback = null;
|
|
18037
|
-
const streamPromise = new Promise((
|
|
18038
|
-
closeStreamCallback =
|
|
18035
|
+
const streamPromise = new Promise((resolve) => {
|
|
18036
|
+
closeStreamCallback = resolve;
|
|
18039
18037
|
});
|
|
18040
18038
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18041
18039
|
if (isStreamClosed) return;
|
|
@@ -18377,8 +18375,8 @@ function registerBindSearchStream(router) {
|
|
|
18377
18375
|
let isStreamClosed = false;
|
|
18378
18376
|
const subscriptions = [];
|
|
18379
18377
|
let closeStreamCallback = null;
|
|
18380
|
-
const streamPromise = new Promise((
|
|
18381
|
-
closeStreamCallback =
|
|
18378
|
+
const streamPromise = new Promise((resolve) => {
|
|
18379
|
+
closeStreamCallback = resolve;
|
|
18382
18380
|
});
|
|
18383
18381
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18384
18382
|
if (isStreamClosed) return;
|
|
@@ -18674,8 +18672,8 @@ function registerGetEventStream(router) {
|
|
|
18674
18672
|
let subscription = null;
|
|
18675
18673
|
let keepAliveInterval = null;
|
|
18676
18674
|
let closeStreamCallback = null;
|
|
18677
|
-
const streamPromise = new Promise((
|
|
18678
|
-
closeStreamCallback =
|
|
18675
|
+
const streamPromise = new Promise((resolve) => {
|
|
18676
|
+
closeStreamCallback = resolve;
|
|
18679
18677
|
});
|
|
18680
18678
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18681
18679
|
if (isStreamClosed) return;
|
|
@@ -18954,8 +18952,8 @@ function registerYieldResourceStream(router, jobQueue) {
|
|
|
18954
18952
|
const subscriptions = [];
|
|
18955
18953
|
let keepAliveInterval = null;
|
|
18956
18954
|
let closeStreamCallback = null;
|
|
18957
|
-
const streamPromise = new Promise((
|
|
18958
|
-
closeStreamCallback =
|
|
18955
|
+
const streamPromise = new Promise((resolve) => {
|
|
18956
|
+
closeStreamCallback = resolve;
|
|
18959
18957
|
});
|
|
18960
18958
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
18961
18959
|
if (isStreamClosed) return;
|
|
@@ -19245,7 +19243,7 @@ operationsRouter.get("/api/annotations/:id/context", async (c) => {
|
|
|
19245
19243
|
operationsRouter.get("/api/annotations/:id/summary", async (c) => {
|
|
19246
19244
|
const { id } = c.req.param();
|
|
19247
19245
|
const query = c.req.query();
|
|
19248
|
-
const { kb, inferenceClient } = c.get("makeMeaning");
|
|
19246
|
+
const { kb, gathererInferenceClient: inferenceClient } = c.get("makeMeaning");
|
|
19249
19247
|
const resourceId20 = query.resourceId;
|
|
19250
19248
|
if (!resourceId20) {
|
|
19251
19249
|
throw new HTTPException(400, {
|
|
@@ -19346,8 +19344,8 @@ globalEventsRouter.get("/api/events/stream", async (c) => {
|
|
|
19346
19344
|
let isStreamClosed = false;
|
|
19347
19345
|
let keepAliveInterval = null;
|
|
19348
19346
|
let closeStreamCallback = null;
|
|
19349
|
-
const streamPromise = new Promise((
|
|
19350
|
-
closeStreamCallback =
|
|
19347
|
+
const streamPromise = new Promise((resolve) => {
|
|
19348
|
+
closeStreamCallback = resolve;
|
|
19351
19349
|
});
|
|
19352
19350
|
const cleanup = /* @__PURE__ */ __name(() => {
|
|
19353
19351
|
if (isStreamClosed) return;
|
|
@@ -19506,13 +19504,13 @@ var requestLoggerMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
|
19506
19504
|
const logger2 = c.get("logger");
|
|
19507
19505
|
const startTime = Date.now();
|
|
19508
19506
|
const method = c.req.method;
|
|
19509
|
-
const
|
|
19507
|
+
const path2 = c.req.path;
|
|
19510
19508
|
const query = c.req.query();
|
|
19511
19509
|
const userAgent = c.req.header("User-Agent") || "unknown";
|
|
19512
19510
|
logger2.http("Incoming request", {
|
|
19513
19511
|
type: "request_incoming",
|
|
19514
19512
|
method,
|
|
19515
|
-
path:
|
|
19513
|
+
path: path2,
|
|
19516
19514
|
query: Object.keys(query).length > 0 ? query : void 0,
|
|
19517
19515
|
userAgent
|
|
19518
19516
|
});
|
|
@@ -19522,7 +19520,7 @@ var requestLoggerMiddleware = /* @__PURE__ */ __name(async (c, next) => {
|
|
|
19522
19520
|
logger2.http("Outgoing response", {
|
|
19523
19521
|
type: "request_outgoing",
|
|
19524
19522
|
method,
|
|
19525
|
-
path:
|
|
19523
|
+
path: path2,
|
|
19526
19524
|
status,
|
|
19527
19525
|
duration,
|
|
19528
19526
|
durationMs: duration
|
|
@@ -19592,7 +19590,7 @@ if (databaseUrlConstructed) {
|
|
|
19592
19590
|
});
|
|
19593
19591
|
}
|
|
19594
19592
|
var eventBus = new EventBus();
|
|
19595
|
-
var makeMeaning = await startMakeMeaning(config, eventBus, logger);
|
|
19593
|
+
var makeMeaning = await startMakeMeaning(new SemiontProject(projectRoot), makeMeaningConfigFrom(config), eventBus, logger);
|
|
19596
19594
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
19597
19595
|
var __dirname$1 = path.dirname(__filename$1);
|
|
19598
19596
|
var app = new Hono();
|