From 1d01e0998b0bd94728e969cf83c4b1db2119ddac Mon Sep 17 00:00:00 2001 From: Sebastien Dumetz Date: Mon, 23 Oct 2023 17:17:41 +0200 Subject: [PATCH] Node20 support (#43) Update server imports to nodeNext. Downgrade compile target to node 16 --- source/server/auth/User.test.ts | 2 +- source/server/auth/UserManager.test.ts | 10 +- source/server/auth/UserManager.ts | 8 +- source/server/index.ts | 4 +- source/server/integration.test.ts | 16 +- source/server/package.json | 5 +- source/server/routes/api/v1/index.ts | 42 ++-- source/server/routes/api/v1/login.test.ts | 6 +- source/server/routes/api/v1/login.ts | 10 +- .../server/routes/api/v1/scenes/get.test.ts | 10 +- source/server/routes/api/v1/scenes/get.ts | 10 +- .../server/routes/api/v1/scenes/post.test.ts | 6 +- source/server/routes/api/v1/scenes/post.ts | 12 +- .../routes/api/v1/scenes/scene/files/get.ts | 4 +- .../routes/api/v1/scenes/scene/get.test.ts | 10 +- .../server/routes/api/v1/scenes/scene/get.ts | 8 +- .../api/v1/scenes/scene/history/get.test.ts | 6 +- .../routes/api/v1/scenes/scene/history/get.ts | 2 +- .../api/v1/scenes/scene/history/post.test.ts | 6 +- .../api/v1/scenes/scene/history/post.ts | 6 +- .../routes/api/v1/scenes/scene/patch.test.ts | 4 +- .../routes/api/v1/scenes/scene/patch.ts | 4 +- .../api/v1/scenes/scene/permissions/get.ts | 4 +- .../api/v1/scenes/scene/permissions/patch.ts | 2 +- .../routes/api/v1/scenes/scene/post.test.ts | 11 +- .../server/routes/api/v1/scenes/scene/post.ts | 6 +- source/server/routes/api/v1/stats/index.ts | 2 +- source/server/routes/api/v1/users/post.ts | 8 +- .../server/routes/api/v1/users/uid/delete.ts | 8 +- .../server/routes/api/v1/users/uid/patch.ts | 6 +- .../server/routes/api/v1/users/users.test.ts | 8 +- source/server/routes/scenes/copy/copy.test.ts | 6 +- source/server/routes/scenes/copy/document.ts | 4 +- source/server/routes/scenes/copy/file.ts | 4 +- source/server/routes/scenes/delete/file.ts | 2 +- source/server/routes/scenes/delete/scene.ts | 2 +- source/server/routes/scenes/get/document.ts | 2 +- source/server/routes/scenes/get/file.test.ts | 6 +- source/server/routes/scenes/get/file.ts | 2 +- source/server/routes/scenes/index.ts | 24 +- source/server/routes/scenes/mkcol.test.ts | 6 +- source/server/routes/scenes/mkcol.ts | 2 +- source/server/routes/scenes/move/file.ts | 4 +- source/server/routes/scenes/move/move.test.ts | 6 +- source/server/routes/scenes/propfind.test.ts | 6 +- source/server/routes/scenes/propfind.ts | 4 +- source/server/routes/scenes/put/document.ts | 6 +- source/server/routes/scenes/put/file.test.ts | 8 +- source/server/routes/scenes/put/file.ts | 4 +- source/server/routes/scenes/put/index.ts | 4 +- source/server/server.ts | 20 +- source/server/tests-common.ts | 12 +- source/server/tsconfig.json | 13 +- source/server/utils/config.test.ts | 2 +- source/server/utils/errors.test.ts | 2 +- source/server/utils/glTF.test.ts | 11 +- source/server/utils/locals.ts | 8 +- source/server/utils/mails/send.ts | 4 +- source/server/utils/mails/templates.ts | 2 +- source/server/utils/schema/common.d.ts | 41 ++++ .../{documents => schema}/default.svx.json | 0 source/server/utils/schema/document.d.ts | 151 +++++++++++++ .../utils/{documents => schema}/edit.test.ts | 2 +- .../utils/{documents => schema}/edit.ts | 6 +- source/server/utils/schema/meta.d.ts | 87 ++++++++ source/server/utils/schema/model.d.ts | 147 +++++++++++++ source/server/utils/schema/setup.d.ts | 205 ++++++++++++++++++ .../{documents/types.ts => schema/types.d.ts} | 0 source/server/utils/uid.test.ts | 2 +- source/server/utils/wrapAsync.test.ts | 2 +- source/server/utils/zip/crc32.test.ts | 2 +- source/server/utils/zip/datetime.test.ts | 2 +- source/server/utils/zip/index.ts | 4 +- source/server/utils/zip/zip.test.ts | 4 +- source/server/vfs/Base.ts | 6 +- source/server/vfs/Clean.ts | 4 +- source/server/vfs/Docs.ts | 8 +- source/server/vfs/Files.ts | 10 +- source/server/vfs/Scenes.ts | 12 +- source/server/vfs/Stats.ts | 2 +- source/server/vfs/helpers/db.test.ts | 4 +- source/server/vfs/helpers/db.ts | 2 +- source/server/vfs/index.ts | 16 +- source/server/vfs/types.ts | 2 +- source/server/vfs/vfs.benchmark.ts | 4 +- source/server/vfs/vfs.test.ts | 10 +- 86 files changed, 894 insertions(+), 263 deletions(-) create mode 100644 source/server/utils/schema/common.d.ts rename source/server/utils/{documents => schema}/default.svx.json (100%) create mode 100644 source/server/utils/schema/document.d.ts rename source/server/utils/{documents => schema}/edit.test.ts (99%) rename source/server/utils/{documents => schema}/edit.ts (91%) create mode 100644 source/server/utils/schema/meta.d.ts create mode 100644 source/server/utils/schema/model.d.ts create mode 100644 source/server/utils/schema/setup.d.ts rename source/server/utils/{documents/types.ts => schema/types.d.ts} (100%) diff --git a/source/server/auth/User.test.ts b/source/server/auth/User.test.ts index b95a0d1c..6de09492 100644 --- a/source/server/auth/User.test.ts +++ b/source/server/auth/User.test.ts @@ -1,2 +1,2 @@ -import User from "./User"; +import User from "./User.js"; import {expect} from "chai"; diff --git a/source/server/auth/UserManager.test.ts b/source/server/auth/UserManager.test.ts index 1c3acc4d..b1d5ee89 100644 --- a/source/server/auth/UserManager.test.ts +++ b/source/server/auth/UserManager.test.ts @@ -1,13 +1,13 @@ -import UserManager, { AccessTypes } from "./UserManager"; +import UserManager, { AccessTypes } from "./UserManager.js"; import {tmpdir} from "os"; import fs from "fs/promises"; import path from "path"; import {expect} from "chai"; -import { BadRequestError, NotFoundError, UnauthorizedError } from "../utils/errors"; -import User from "./User"; -import openDatabase from "../vfs/helpers/db"; -import { Uid } from "../utils/uid"; +import { BadRequestError, NotFoundError, UnauthorizedError } from "../utils/errors.js"; +import User from "./User.js"; +import openDatabase from "../vfs/helpers/db.js"; +import { Uid } from "../utils/uid.js"; describe("UserManager static methods", function(){ describe("parsePassword()", function(){ diff --git a/source/server/auth/UserManager.ts b/source/server/auth/UserManager.ts index 8c667ee6..44beca3a 100644 --- a/source/server/auth/UserManager.ts +++ b/source/server/auth/UserManager.ts @@ -3,11 +3,11 @@ import crypto from "crypto"; import path from "path"; import {promisify, callbackify} from "util"; -import uid, { Uid } from "../utils/uid"; -import { BadRequestError, InternalError, NotFoundError, UnauthorizedError } from "../utils/errors"; -import User, {SafeUser, StoredUser} from "./User"; +import uid, { Uid } from "../utils/uid.js"; +import { BadRequestError, InternalError, NotFoundError, UnauthorizedError } from "../utils/errors.js"; +import User, {SafeUser, StoredUser} from "./User.js"; -import openDatabase, {Database, DbOptions} from "../vfs/helpers/db"; +import openDatabase, {Database, DbOptions} from "../vfs/helpers/db.js"; const scrypt :( diff --git a/source/server/index.ts b/source/server/index.ts index d58535af..7aa85f6d 100644 --- a/source/server/index.ts +++ b/source/server/index.ts @@ -16,8 +16,8 @@ */ import path from "path"; -import createServer from "./server"; -import config from "./utils/config"; +import createServer from "./server.js"; +import config from "./utils/config.js"; //@ts-ignore import("source-map-support").then((s)=>{ diff --git a/source/server/integration.test.ts b/source/server/integration.test.ts index b071a8a2..d03d06fe 100644 --- a/source/server/integration.test.ts +++ b/source/server/integration.test.ts @@ -1,15 +1,16 @@ import fs from "fs/promises"; import path from "path"; +import { fileURLToPath } from 'url'; import {tmpdir} from "os"; import request from "supertest"; -import createServer from "./server"; -import Vfs, { DocProps, WriteFileParams } from "./vfs"; -import User from "./auth/User"; +import createServer from "./server.js"; +import Vfs, { DocProps, WriteFileParams } from "./vfs/index.js"; +import User from "./auth/User.js"; import { Element, xml2js } from "xml-js"; -import UserManager from "./auth/UserManager"; - +import UserManager from "./auth/UserManager.js"; +const thisDir = path.dirname(fileURLToPath(import.meta.url)); describe("Web Server Integration", function(){ let vfs :Vfs, userManager :UserManager, user :User, admin :User; @@ -71,10 +72,11 @@ describe("Web Server Integration", function(){ }); it("can create a new scene", async function(){ - let content = await fs.readFile(path.join(__dirname, "__test_fixtures/cube.glb")); + let content = await fs.readFile(path.join(thisDir, "__test_fixtures/cube.glb")); let r = await this.agent.post("/api/v1/scenes/bar") .set("Content-Type", "application/octet-stream") .send(content) + .expect(201); let res = await this.agent.get("/scenes/bar/models/bar.glb").expect(200); expect(res.text.slice(0,4).toString()).to.equal("glTF"); expect(res.text.length).to.equal(content.length); @@ -84,7 +86,7 @@ describe("Web Server Integration", function(){ }); it("can upload a glb model in an existing scene", async function(){ - let content = await fs.readFile(path.join(__dirname, "__test_fixtures/cube.glb")); + let content = await fs.readFile(path.join(thisDir, "__test_fixtures/cube.glb")); await this.agent.put("/scenes/foo/models/baz.glb") .send(content) .expect(201); diff --git a/source/server/package.json b/source/server/package.json index 75c27841..4c2e3c76 100755 --- a/source/server/package.json +++ b/source/server/package.json @@ -3,9 +3,10 @@ "version": "0.0.1", "description": "eThesaurus application, based on Smithsonian DPO Voyager - 3D Explorer and Tool Suite", "public": false, + "type": "module", "scripts": { "start": "ROOT_DIR=\"$(pwd)/../..\" node ./dist/server/index.js", - "test": "mocha", + "test": "NODE_NO_WARNINGS=1 mocha", "build": "tsc -b ." }, "nodemonConfig": { @@ -65,7 +66,7 @@ "supertest": "^6.3.3", "webpack-dev-middleware": "^6.1.1" }, - "overrides":{ + "overrides": { "webpack-dev-middleware": { "webpack": "^5.88.1" } diff --git a/source/server/routes/api/v1/index.ts b/source/server/routes/api/v1/index.ts index 80a508d6..c0669908 100644 --- a/source/server/routes/api/v1/index.ts +++ b/source/server/routes/api/v1/index.ts @@ -1,29 +1,29 @@ import path from "path"; import { Router } from "express"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; -import { BadRequestError } from "../../../utils/errors"; -import { canAdmin, canRead, getUserManager, isAdministrator, isAdministratorOrOpen, isUser } from "../../../utils/locals"; -import wrap from "../../../utils/wrapAsync"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; +import { BadRequestError } from "../../../utils/errors.js"; +import { canAdmin, canRead, getUserManager, isAdministrator, isAdministratorOrOpen, isUser } from "../../../utils/locals.js"; +import wrap from "../../../utils/wrapAsync.js"; import bodyParser from "body-parser"; -import { getLogin, getLoginLink, sendLoginLink, postLogin } from "./login"; -import { postLogout } from "./logout"; -import postScene from "./scenes/scene/post"; -import getScenes from "./scenes/get"; -import getSceneHistory from "./scenes/scene/history/get"; -import getFiles from "./scenes/scene/files/get"; +import { getLogin, getLoginLink, sendLoginLink, postLogin } from "./login.js"; +import { postLogout } from "./logout.js"; +import postScene from "./scenes/scene/post.js"; +import getScenes from "./scenes/get.js"; +import getSceneHistory from "./scenes/scene/history/get.js"; +import getFiles from "./scenes/scene/files/get.js"; -import getScene from "./scenes/scene/get"; -import getPermissions from "./scenes/scene/permissions/get"; -import patchPermissions from "./scenes/scene/permissions/patch"; -import postUser from "./users/post"; -import handleDeleteUser from "./users/uid/delete"; -import { handlePatchUser } from "./users/uid/patch"; -import { postSceneHistory } from "./scenes/scene/history/post"; -import handleGetStats from "./stats"; -import postScenes from "./scenes/post"; -import patchScene from "./scenes/scene/patch"; +import getScene from "./scenes/scene/get.js"; +import getPermissions from "./scenes/scene/permissions/get.js"; +import patchPermissions from "./scenes/scene/permissions/patch.js"; +import postUser from "./users/post.js"; +import handleDeleteUser from "./users/uid/delete.js"; +import { handlePatchUser } from "./users/uid/patch.js"; +import { postSceneHistory } from "./scenes/scene/history/post.js"; +import handleGetStats from "./stats/index.js"; +import postScenes from "./scenes/post.js"; +import patchScene from "./scenes/scene/patch.js"; diff --git a/source/server/routes/api/v1/login.test.ts b/source/server/routes/api/v1/login.test.ts index e784380e..c0293dad 100644 --- a/source/server/routes/api/v1/login.test.ts +++ b/source/server/routes/api/v1/login.test.ts @@ -1,8 +1,8 @@ import request from "supertest"; -import Vfs from "../../../vfs"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; +import Vfs from "../../../vfs/index.js"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; diff --git a/source/server/routes/api/v1/login.ts b/source/server/routes/api/v1/login.ts index bb520490..06e67756 100644 --- a/source/server/routes/api/v1/login.ts +++ b/source/server/routes/api/v1/login.ts @@ -1,10 +1,10 @@ import { createHmac } from "crypto"; import { Request, RequestHandler, Response } from "express"; -import User, { SafeUser } from "../../../auth/User"; -import { BadRequestError, ForbiddenError, HTTPError } from "../../../utils/errors"; -import { getHost, getUser, getUserManager } from "../../../utils/locals"; -import sendmail from "../../../utils/mails/send"; -import { recoverAccount } from "../../../utils/mails/templates"; +import User, { SafeUser } from "../../../auth/User.js"; +import { BadRequestError, ForbiddenError, HTTPError } from "../../../utils/errors.js"; +import { getHost, getUser, getUserManager } from "../../../utils/locals.js"; +import sendmail from "../../../utils/mails/send.js"; +import { recoverAccount } from "../../../utils/mails/templates.js"; /** * * @type {RequestHandler} diff --git a/source/server/routes/api/v1/scenes/get.test.ts b/source/server/routes/api/v1/scenes/get.test.ts index 866f6363..5998887b 100644 --- a/source/server/routes/api/v1/scenes/get.test.ts +++ b/source/server/routes/api/v1/scenes/get.test.ts @@ -5,11 +5,11 @@ import {tmpdir} from "os"; import request from "supertest"; import { expect } from "chai"; -import Vfs from "../../../../vfs"; -import UserManager from "../../../../auth/UserManager"; -import User from "../../../../auth/User"; -import { HandleMock } from "../../../../utils/zip/zip.test"; -import { read_cdh } from "../../../../utils/zip"; +import Vfs from "../../../../vfs/index.js"; +import UserManager from "../../../../auth/UserManager.js"; +import User from "../../../../auth/User.js"; +import { HandleMock } from "../../../../utils/zip/zip.test.js"; +import { read_cdh } from "../../../../utils/zip/index.js"; diff --git a/source/server/routes/api/v1/scenes/get.ts b/source/server/routes/api/v1/scenes/get.ts index 4ca9c9c8..ed0fe7e9 100644 --- a/source/server/routes/api/v1/scenes/get.ts +++ b/source/server/routes/api/v1/scenes/get.ts @@ -2,11 +2,11 @@ import { createHash } from "crypto"; import { Request, Response } from "express"; import path from "path"; -import { AccessType } from "../../../../auth/UserManager"; -import { HTTPError } from "../../../../utils/errors"; -import { getHost, getUser, getVfs } from "../../../../utils/locals"; -import { wrapFormat } from "../../../../utils/wrapAsync"; -import { ZipEntry, zip } from "../../../../utils/zip"; +import { AccessType } from "../../../../auth/UserManager.js"; +import { HTTPError } from "../../../../utils/errors.js"; +import { getHost, getUser, getVfs } from "../../../../utils/locals.js"; +import { wrapFormat } from "../../../../utils/wrapAsync.js"; +import { ZipEntry, zip } from "../../../../utils/zip/index.js"; export default async function getScenes(req :Request, res :Response){ let vfs = getVfs(req); diff --git a/source/server/routes/api/v1/scenes/post.test.ts b/source/server/routes/api/v1/scenes/post.test.ts index b0499a86..953d65c6 100644 --- a/source/server/routes/api/v1/scenes/post.test.ts +++ b/source/server/routes/api/v1/scenes/post.test.ts @@ -2,9 +2,9 @@ import fs from "fs/promises"; import request from "supertest"; -import Vfs from "../../../../vfs"; -import UserManager from "../../../../auth/UserManager"; -import { NotFoundError } from "../../../../utils/errors"; +import Vfs from "../../../../vfs/index.js"; +import UserManager from "../../../../auth/UserManager.js"; +import { NotFoundError } from "../../../../utils/errors.js"; function binaryParser(res:request.Response, callback:(err:Error|null, data:Buffer)=>any) { res.setEncoding('binary'); diff --git a/source/server/routes/api/v1/scenes/post.ts b/source/server/routes/api/v1/scenes/post.ts index 608581d8..81c3f7db 100644 --- a/source/server/routes/api/v1/scenes/post.ts +++ b/source/server/routes/api/v1/scenes/post.ts @@ -3,14 +3,12 @@ import path from "path"; import {once} from "events"; import { Request, Response } from "express"; -import { getHost, getUser, getVfs } from "../../../../utils/locals"; -import { wrapFormat } from "../../../../utils/wrapAsync"; -import { zip } from "../../../../utils/zip"; -import { Uid } from "../../../../utils/uid"; -import { unzip } from "../../../../utils/zip"; -import { HTTPError } from "../../../../utils/errors"; +import { getHost, getUser, getVfs } from "../../../../utils/locals.js"; +import { Uid } from "../../../../utils/uid.js"; +import { unzip } from "../../../../utils/zip/index.js"; +import { HTTPError } from "../../../../utils/errors.js"; import { createReadStream } from "fs"; -import { getMimeType } from "../../../../utils/filetypes"; +import { getMimeType } from "../../../../utils/filetypes.js"; interface ImportResults { diff --git a/source/server/routes/api/v1/scenes/scene/files/get.ts b/source/server/routes/api/v1/scenes/scene/files/get.ts index 8dbb4532..725909ea 100644 --- a/source/server/routes/api/v1/scenes/scene/files/get.ts +++ b/source/server/routes/api/v1/scenes/scene/files/get.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; -import toCsv from "../../../../../../utils/csv"; -import { getVfs } from "../../../../../../utils/locals"; +import toCsv from "../../../../../../utils/csv.js"; +import { getVfs } from "../../../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/scenes/scene/get.test.ts b/source/server/routes/api/v1/scenes/scene/get.test.ts index a26e6a93..f0539289 100644 --- a/source/server/routes/api/v1/scenes/scene/get.test.ts +++ b/source/server/routes/api/v1/scenes/scene/get.test.ts @@ -6,12 +6,12 @@ import {Readable} from "stream"; import request from "supertest"; import { expect } from "chai"; -import Vfs from "../../../../../vfs"; -import UserManager from "../../../../../auth/UserManager"; -import User from "../../../../../auth/User"; -import { read_cdh } from "../../../../../utils/zip"; +import Vfs from "../../../../../vfs/index.js"; +import UserManager from "../../../../../auth/UserManager.js"; +import User from "../../../../../auth/User.js"; +import { read_cdh } from "../../../../../utils/zip/index.js"; -import { HandleMock } from "../../../../../utils/zip/zip.test"; +import { HandleMock } from "../../../../../utils/zip/zip.test.js"; describe("GET /api/v1/scenes/:scene", function(){ let vfs:Vfs, userManager:UserManager, ids :number[]; diff --git a/source/server/routes/api/v1/scenes/scene/get.ts b/source/server/routes/api/v1/scenes/scene/get.ts index 8b2aade6..dce4a0c1 100644 --- a/source/server/routes/api/v1/scenes/scene/get.ts +++ b/source/server/routes/api/v1/scenes/scene/get.ts @@ -1,10 +1,10 @@ import { Request, Response } from "express"; import path from "path"; -import { getUserId, getVfs } from "../../../../../utils/locals"; -import { wrapFormat } from "../../../../../utils/wrapAsync"; -import { ZipEntry, zip } from "../../../../../utils/zip"; -import { HTTPError } from "../../../../../utils/errors"; +import { getUserId, getVfs } from "../../../../../utils/locals.js"; +import { wrapFormat } from "../../../../../utils/wrapAsync.js"; +import { ZipEntry, zip } from "../../../../../utils/zip/index.js"; +import { HTTPError } from "../../../../../utils/errors.js"; diff --git a/source/server/routes/api/v1/scenes/scene/history/get.test.ts b/source/server/routes/api/v1/scenes/scene/history/get.test.ts index d217046d..e0c314ad 100644 --- a/source/server/routes/api/v1/scenes/scene/history/get.test.ts +++ b/source/server/routes/api/v1/scenes/scene/history/get.test.ts @@ -1,8 +1,8 @@ import request from "supertest"; -import Vfs from "../../../../../../vfs"; -import User from "../../../../../../auth/User"; -import UserManager from "../../../../../../auth/UserManager"; +import Vfs from "../../../../../../vfs/index.js"; +import User from "../../../../../../auth/User.js"; +import UserManager from "../../../../../../auth/UserManager.js"; diff --git a/source/server/routes/api/v1/scenes/scene/history/get.ts b/source/server/routes/api/v1/scenes/scene/history/get.ts index f5909826..31a45fa0 100644 --- a/source/server/routes/api/v1/scenes/scene/history/get.ts +++ b/source/server/routes/api/v1/scenes/scene/history/get.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; -import { getVfs } from "../../../../../../utils/locals"; +import { getVfs } from "../../../../../../utils/locals.js"; export default async function getSceneHistory(req :Request, res :Response){ diff --git a/source/server/routes/api/v1/scenes/scene/history/post.test.ts b/source/server/routes/api/v1/scenes/scene/history/post.test.ts index ae3a401d..27e83e83 100644 --- a/source/server/routes/api/v1/scenes/scene/history/post.test.ts +++ b/source/server/routes/api/v1/scenes/scene/history/post.test.ts @@ -1,8 +1,8 @@ import request from "supertest"; -import Vfs from "../../../../../../vfs"; -import User from "../../../../../../auth/User"; -import UserManager from "../../../../../../auth/UserManager"; +import Vfs from "../../../../../../vfs/index.js"; +import User from "../../../../../../auth/User.js"; +import UserManager from "../../../../../../auth/UserManager.js"; import { randomBytes } from "crypto"; diff --git a/source/server/routes/api/v1/scenes/scene/history/post.ts b/source/server/routes/api/v1/scenes/scene/history/post.ts index 49f6bceb..971d93c7 100644 --- a/source/server/routes/api/v1/scenes/scene/history/post.ts +++ b/source/server/routes/api/v1/scenes/scene/history/post.ts @@ -1,8 +1,8 @@ import { Request, Response } from "express"; import path from "path"; -import { BadRequestError } from "../../../../../../utils/errors"; -import { getUser, getVfs } from "../../../../../../utils/locals"; -import { ItemEntry } from "../../../../../../vfs"; +import { BadRequestError } from "../../../../../../utils/errors.js"; +import { getUser, getVfs } from "../../../../../../utils/locals.js"; +import { ItemEntry } from "../../../../../../vfs/index.js"; /** diff --git a/source/server/routes/api/v1/scenes/scene/patch.test.ts b/source/server/routes/api/v1/scenes/scene/patch.test.ts index d5a4f5e2..841b5dd8 100644 --- a/source/server/routes/api/v1/scenes/scene/patch.test.ts +++ b/source/server/routes/api/v1/scenes/scene/patch.test.ts @@ -2,8 +2,8 @@ import request from "supertest"; -import Vfs from "../../../../../vfs"; -import UserManager from "../../../../../auth/UserManager"; +import Vfs from "../../../../../vfs/index.js"; +import UserManager from "../../../../../auth/UserManager.js"; describe("PATCH /api/v1/scenes/:scene", function(){ let vfs:Vfs, userManager:UserManager, ids :number[]; diff --git a/source/server/routes/api/v1/scenes/scene/patch.ts b/source/server/routes/api/v1/scenes/scene/patch.ts index 75d68331..1d9b424d 100644 --- a/source/server/routes/api/v1/scenes/scene/patch.ts +++ b/source/server/routes/api/v1/scenes/scene/patch.ts @@ -1,6 +1,6 @@ -import { ConflictError } from "../../../../../utils/errors"; -import { getUserId, getVfs } from "../../../../../utils/locals"; +import { ConflictError } from "../../../../../utils/errors.js"; +import { getUserId, getVfs } from "../../../../../utils/locals.js"; import { Request, Response } from "express"; diff --git a/source/server/routes/api/v1/scenes/scene/permissions/get.ts b/source/server/routes/api/v1/scenes/scene/permissions/get.ts index db5b4090..3c96187e 100644 --- a/source/server/routes/api/v1/scenes/scene/permissions/get.ts +++ b/source/server/routes/api/v1/scenes/scene/permissions/get.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; -import { BadRequestError } from "../../../../../../utils/errors"; -import { getUserId, getUserManager } from "../../../../../../utils/locals"; +import { BadRequestError } from "../../../../../../utils/errors.js"; +import { getUserId, getUserManager } from "../../../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/scenes/scene/permissions/patch.ts b/source/server/routes/api/v1/scenes/scene/permissions/patch.ts index afad95db..053140c5 100644 --- a/source/server/routes/api/v1/scenes/scene/permissions/patch.ts +++ b/source/server/routes/api/v1/scenes/scene/permissions/patch.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; -import { getUserManager } from "../../../../../../utils/locals"; +import { getUserManager } from "../../../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/scenes/scene/post.test.ts b/source/server/routes/api/v1/scenes/scene/post.test.ts index 604cb5a2..64a41ffb 100644 --- a/source/server/routes/api/v1/scenes/scene/post.test.ts +++ b/source/server/routes/api/v1/scenes/scene/post.test.ts @@ -1,22 +1,23 @@ import fs from "fs/promises"; import path from "path"; +import { fileURLToPath } from 'url'; import {tmpdir} from "os"; import timers from 'timers/promises'; import request from "supertest"; import { expect } from "chai"; import { once } from "events"; -import postScene from "./post"; +import postScene from "./post.js"; import express, { Application } from "express"; -import wrap from "../../../../../utils/wrapAsync"; -import Vfs from "../../../../../vfs"; - +import wrap from "../../../../../utils/wrapAsync.js"; +import Vfs from "../../../../../vfs/index.js"; +const thisDir = path.dirname(fileURLToPath(import.meta.url)); describe("POST /api/v1/scenes/:scene", function(){ let vfs:Vfs, app: Application, data:Buffer; this.beforeEach(async function(){ - data = await fs.readFile(path.join(__dirname, "../../../../../__test_fixtures/cube.glb")); + data = await fs.readFile(path.join(thisDir, "../../../../../__test_fixtures/cube.glb")); this.dir = await fs.mkdtemp(path.join(tmpdir(), `scenes-integration`)); vfs = await Vfs.Open(this.dir,{createDirs: true}); app = express(); diff --git a/source/server/routes/api/v1/scenes/scene/post.ts b/source/server/routes/api/v1/scenes/scene/post.ts index 4f64961d..47f92fd1 100644 --- a/source/server/routes/api/v1/scenes/scene/post.ts +++ b/source/server/routes/api/v1/scenes/scene/post.ts @@ -1,7 +1,7 @@ -import { getUserId, getVfs } from "../../../../../utils/locals"; +import { getUserId, getVfs } from "../../../../../utils/locals.js"; import { Request, Response } from "express"; -import { parse_glb } from "../../../../../utils/glTF"; +import { parse_glb } from "../../../../../utils/glTF.js"; /** @@ -12,7 +12,7 @@ import { parse_glb } from "../../../../../utils/glTF"; * @returns */ async function getDocument(scene:string, filepath:string){ - let {default:orig} = await import("../../../../../utils/documents/default.svx.json"); + let {default:orig} = await import("../../../../../utils/schema/default.svx.json", {assert:{type:"json"}}); //dumb inefficient Deep copy because we want to mutate the doc in-place let document = JSON.parse(JSON.stringify(orig)); let meta = await parse_glb(filepath); diff --git a/source/server/routes/api/v1/stats/index.ts b/source/server/routes/api/v1/stats/index.ts index eb84971e..88778ae0 100644 --- a/source/server/routes/api/v1/stats/index.ts +++ b/source/server/routes/api/v1/stats/index.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { getVfs } from "../../../../utils/locals"; +import { getVfs } from "../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/users/post.ts b/source/server/routes/api/v1/users/post.ts index a4b92067..5f5b7f64 100644 --- a/source/server/routes/api/v1/users/post.ts +++ b/source/server/routes/api/v1/users/post.ts @@ -1,9 +1,9 @@ import { Request, Response } from "express"; -import User from "../../../../auth/User"; -import UserManager from "../../../../auth/UserManager"; -import { BadRequestError } from "../../../../utils/errors"; -import { getUserManager } from "../../../../utils/locals"; +import User from "../../../../auth/User.js"; +import UserManager from "../../../../auth/UserManager.js"; +import { BadRequestError } from "../../../../utils/errors.js"; +import { getUserManager } from "../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/users/uid/delete.ts b/source/server/routes/api/v1/users/uid/delete.ts index 8052febe..1b2ab145 100644 --- a/source/server/routes/api/v1/users/uid/delete.ts +++ b/source/server/routes/api/v1/users/uid/delete.ts @@ -1,9 +1,9 @@ import { Request, Response } from "express"; -import User from "../../../../../auth/User"; -import UserManager from "../../../../../auth/UserManager"; -import { BadRequestError } from "../../../../../utils/errors"; -import { getUserId, getUserManager } from "../../../../../utils/locals"; +import User from "../../../../../auth/User.js"; +import UserManager from "../../../../../auth/UserManager.js"; +import { BadRequestError } from "../../../../../utils/errors.js"; +import { getUserId, getUserManager } from "../../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/users/uid/patch.ts b/source/server/routes/api/v1/users/uid/patch.ts index 63258a16..9ccd18c8 100644 --- a/source/server/routes/api/v1/users/uid/patch.ts +++ b/source/server/routes/api/v1/users/uid/patch.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; -import User, { SafeUser } from "../../../../../auth/User"; -import { UnauthorizedError } from "../../../../../utils/errors"; -import { getUser, getUserManager } from "../../../../../utils/locals"; +import User, { SafeUser } from "../../../../../auth/User.js"; +import { UnauthorizedError } from "../../../../../utils/errors.js"; +import { getUser, getUserManager } from "../../../../../utils/locals.js"; diff --git a/source/server/routes/api/v1/users/users.test.ts b/source/server/routes/api/v1/users/users.test.ts index 42fcb2e6..8511e86b 100644 --- a/source/server/routes/api/v1/users/users.test.ts +++ b/source/server/routes/api/v1/users/users.test.ts @@ -1,9 +1,9 @@ import request from "supertest"; -import Vfs, { WriteFileParams } from "../../../../vfs"; -import User from "../../../../auth/User"; -import UserManager from "../../../../auth/UserManager"; -import { NotFoundError } from "../../../../utils/errors"; +import Vfs, { WriteFileParams } from "../../../../vfs/index.js"; +import User from "../../../../auth/User.js"; +import UserManager from "../../../../auth/UserManager.js"; +import { NotFoundError } from "../../../../utils/errors.js"; diff --git a/source/server/routes/scenes/copy/copy.test.ts b/source/server/routes/scenes/copy/copy.test.ts index aaa79996..9a147011 100644 --- a/source/server/routes/scenes/copy/copy.test.ts +++ b/source/server/routes/scenes/copy/copy.test.ts @@ -6,9 +6,9 @@ import request from "supertest"; import { expect } from "chai"; import express, { Application } from "express"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; -import Vfs, { WriteFileParams } from "../../../vfs"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; +import Vfs, { WriteFileParams } from "../../../vfs/index.js"; import { Element, xml2js } from "xml-js"; diff --git a/source/server/routes/scenes/copy/document.ts b/source/server/routes/scenes/copy/document.ts index f9c235ef..98f46995 100644 --- a/source/server/routes/scenes/copy/document.ts +++ b/source/server/routes/scenes/copy/document.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; import path from "path"; -import { BadRequestError, ConflictError, ForbiddenError, NotFoundError } from "../../../utils/errors"; -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { BadRequestError, ConflictError, ForbiddenError, NotFoundError } from "../../../utils/errors.js"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; diff --git a/source/server/routes/scenes/copy/file.ts b/source/server/routes/scenes/copy/file.ts index 1964feea..15690ae2 100644 --- a/source/server/routes/scenes/copy/file.ts +++ b/source/server/routes/scenes/copy/file.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; import path from "path"; -import { BadRequestError, ConflictError, ForbiddenError, NotFoundError } from "../../../utils/errors"; -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { BadRequestError, ConflictError, ForbiddenError, NotFoundError } from "../../../utils/errors.js"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; diff --git a/source/server/routes/scenes/delete/file.ts b/source/server/routes/scenes/delete/file.ts index 2cfa60dd..05c01cdc 100644 --- a/source/server/routes/scenes/delete/file.ts +++ b/source/server/routes/scenes/delete/file.ts @@ -1,5 +1,5 @@ -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; import { Request, Response } from "express"; /** diff --git a/source/server/routes/scenes/delete/scene.ts b/source/server/routes/scenes/delete/scene.ts index dfa6c6c3..01dbc5e1 100644 --- a/source/server/routes/scenes/delete/scene.ts +++ b/source/server/routes/scenes/delete/scene.ts @@ -1,5 +1,5 @@ -import { getFileParams, getUser, getUserId, getUserManager, getVfs } from "../../../utils/locals"; +import { getFileParams, getUser, getUserId, getUserManager, getVfs } from "../../../utils/locals.js"; import { Request, Response } from "express"; export default async function handleDeleteScene(req :Request, res :Response){ diff --git a/source/server/routes/scenes/get/document.ts b/source/server/routes/scenes/get/document.ts index 128785e9..b498d425 100644 --- a/source/server/routes/scenes/get/document.ts +++ b/source/server/routes/scenes/get/document.ts @@ -1,5 +1,5 @@ -import { getUserId, getVfs } from "../../../utils/locals"; +import { getUserId, getVfs } from "../../../utils/locals.js"; import { Request, Response } from "express"; import { createHash } from "crypto"; diff --git a/source/server/routes/scenes/get/file.test.ts b/source/server/routes/scenes/get/file.test.ts index 10bb4722..b20d6abd 100644 --- a/source/server/routes/scenes/get/file.test.ts +++ b/source/server/routes/scenes/get/file.test.ts @@ -4,9 +4,9 @@ import {Readable} from "stream"; import timers from "node:timers/promises"; import request from "supertest"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; -import Vfs from "../../../vfs"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; +import Vfs from "../../../vfs/index.js"; diff --git a/source/server/routes/scenes/get/file.ts b/source/server/routes/scenes/get/file.ts index 20f6e57d..047a9ce2 100644 --- a/source/server/routes/scenes/get/file.ts +++ b/source/server/routes/scenes/get/file.ts @@ -1,6 +1,6 @@ import {pipeline} from "node:stream/promises"; -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; import { Request, Response } from "express"; diff --git a/source/server/routes/scenes/index.ts b/source/server/routes/scenes/index.ts index bec93a3e..53fa8b75 100644 --- a/source/server/routes/scenes/index.ts +++ b/source/server/routes/scenes/index.ts @@ -1,19 +1,19 @@ import { NextFunction, Request, Response, Router } from "express"; -import {handlePropfind} from "./propfind"; -import {handlePutFile, handlePutDocument} from "./put"; -import { canRead, canWrite, isAdministrator, isUser } from "../../utils/locals"; -import wrap from "../../utils/wrapAsync"; +import {handlePropfind} from "./propfind.js"; +import {handlePutFile, handlePutDocument} from "./put/index.js"; +import { canRead, canWrite, isAdministrator, isUser } from "../../utils/locals.js"; +import wrap from "../../utils/wrapAsync.js"; import bodyParser from "body-parser"; -import handleGetDocument from "./get/document"; -import handleGetFile from "./get/file"; -import handleMoveFile from "./move/file"; -import handleDeleteFile from "./delete/file"; -import handleCopyFile from "./copy/file"; -import handleCopyDocument from "./copy/document"; -import handleDeleteScene from "./delete/scene"; -import handleMkcol from "./mkcol"; +import handleGetDocument from "./get/document.js"; +import handleGetFile from "./get/file.js"; +import handleMoveFile from "./move/file.js"; +import handleDeleteFile from "./delete/file.js"; +import handleCopyFile from "./copy/file.js"; +import handleCopyDocument from "./copy/document.js"; +import handleDeleteScene from "./delete/scene.js"; +import handleMkcol from "./mkcol.js"; const router = Router(); /** Configure cache behaviour for everything under `/scenes/**` diff --git a/source/server/routes/scenes/mkcol.test.ts b/source/server/routes/scenes/mkcol.test.ts index c6d30185..54975d61 100644 --- a/source/server/routes/scenes/mkcol.test.ts +++ b/source/server/routes/scenes/mkcol.test.ts @@ -2,9 +2,9 @@ import request from "supertest"; import { expect } from "chai"; -import User from "../../auth/User"; -import UserManager from "../../auth/UserManager"; -import Vfs from "../../vfs"; +import User from "../../auth/User.js"; +import UserManager from "../../auth/UserManager.js"; +import Vfs from "../../vfs/index.js"; import { Element, xml2js } from "xml-js"; diff --git a/source/server/routes/scenes/mkcol.ts b/source/server/routes/scenes/mkcol.ts index e29a1c68..ea2d8bed 100644 --- a/source/server/routes/scenes/mkcol.ts +++ b/source/server/routes/scenes/mkcol.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { getFileParams, getUser, getVfs } from "../../utils/locals"; +import { getFileParams, getUser, getVfs } from "../../utils/locals.js"; diff --git a/source/server/routes/scenes/move/file.ts b/source/server/routes/scenes/move/file.ts index 143ede32..b8698d6a 100644 --- a/source/server/routes/scenes/move/file.ts +++ b/source/server/routes/scenes/move/file.ts @@ -1,7 +1,7 @@ import { Request, Response } from "express"; import path from "path"; -import { BadRequestError, ForbiddenError } from "../../../utils/errors"; -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { BadRequestError, ForbiddenError } from "../../../utils/errors.js"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; /** diff --git a/source/server/routes/scenes/move/move.test.ts b/source/server/routes/scenes/move/move.test.ts index 271b334b..fc11c9bb 100644 --- a/source/server/routes/scenes/move/move.test.ts +++ b/source/server/routes/scenes/move/move.test.ts @@ -6,9 +6,9 @@ import request from "supertest"; import { expect } from "chai"; import express, { Application } from "express"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; -import Vfs, { WriteFileParams } from "../../../vfs"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; +import Vfs, { WriteFileParams } from "../../../vfs/index.js"; import { Element, xml2js } from "xml-js"; diff --git a/source/server/routes/scenes/propfind.test.ts b/source/server/routes/scenes/propfind.test.ts index eb20ece3..0cdc75dd 100644 --- a/source/server/routes/scenes/propfind.test.ts +++ b/source/server/routes/scenes/propfind.test.ts @@ -6,9 +6,9 @@ import request from "supertest"; import { expect } from "chai"; import express, { Application } from "express"; -import User from "../../auth/User"; -import UserManager from "../../auth/UserManager"; -import Vfs from "../../vfs"; +import User from "../../auth/User.js"; +import UserManager from "../../auth/UserManager.js"; +import Vfs from "../../vfs/index.js"; import { Element, xml2js } from "xml-js"; diff --git a/source/server/routes/scenes/propfind.ts b/source/server/routes/scenes/propfind.ts index e77a6169..407e806d 100644 --- a/source/server/routes/scenes/propfind.ts +++ b/source/server/routes/scenes/propfind.ts @@ -1,8 +1,8 @@ import { Request, RequestHandler, Response } from "express"; import xml from 'xml-js'; import path from "path"; -import { AppLocals, getHost, getUser } from "../../utils/locals"; -import Vfs, { FileProps, ItemProps } from "../../vfs"; +import { AppLocals, getHost, getUser } from "../../utils/locals.js"; +import Vfs, { FileProps, ItemProps } from "../../vfs/index.js"; interface ElementProps{ ctime:Date; diff --git a/source/server/routes/scenes/put/document.ts b/source/server/routes/scenes/put/document.ts index e3bdc193..5ab80c2f 100644 --- a/source/server/routes/scenes/put/document.ts +++ b/source/server/routes/scenes/put/document.ts @@ -1,10 +1,10 @@ import fs from "fs/promises"; import { constants } from "fs"; import path from "path"; -import { AppLocals, getUserId, getVfs } from "../../../utils/locals"; -import uid from "../../../utils/uid"; +import { AppLocals, getUserId, getVfs } from "../../../utils/locals.js"; +import uid from "../../../utils/uid.js"; import { Request, Response } from "express"; -import { BadRequestError } from "../../../utils/errors"; +import { BadRequestError } from "../../../utils/errors.js"; /** * Special handler for svx files to disallow the upload of invalid JSON. diff --git a/source/server/routes/scenes/put/file.test.ts b/source/server/routes/scenes/put/file.test.ts index e01ab251..26dfd862 100644 --- a/source/server/routes/scenes/put/file.test.ts +++ b/source/server/routes/scenes/put/file.test.ts @@ -1,9 +1,9 @@ import request from "supertest"; -import User from "../../../auth/User"; -import UserManager from "../../../auth/UserManager"; -import { NotFoundError } from "../../../utils/errors"; -import Vfs from "../../../vfs"; +import User from "../../../auth/User.js"; +import UserManager from "../../../auth/UserManager.js"; +import { NotFoundError } from "../../../utils/errors.js"; +import Vfs from "../../../vfs/index.js"; diff --git a/source/server/routes/scenes/put/file.ts b/source/server/routes/scenes/put/file.ts index 41429949..92ac2001 100644 --- a/source/server/routes/scenes/put/file.ts +++ b/source/server/routes/scenes/put/file.ts @@ -1,7 +1,7 @@ -import { getFileParams, getUserId, getVfs } from "../../../utils/locals"; +import { getFileParams, getUserId, getVfs } from "../../../utils/locals.js"; import { Request, Response } from "express"; -import { getContentType, getMimeType } from "../../../utils/filetypes"; +import { getContentType, getMimeType } from "../../../utils/filetypes.js"; export default async function handlePutFile(req :Request, res :Response){ diff --git a/source/server/routes/scenes/put/index.ts b/source/server/routes/scenes/put/index.ts index 330aa782..5b869cc2 100644 --- a/source/server/routes/scenes/put/index.ts +++ b/source/server/routes/scenes/put/index.ts @@ -1,3 +1,3 @@ -export {default as handlePutFile} from "./file"; -export {default as handlePutDocument} from "./document"; +export {default as handlePutFile} from "./file.js"; +export {default as handlePutDocument} from "./document.js"; diff --git a/source/server/server.ts b/source/server/server.ts index 5c7d3589..9c093b55 100644 --- a/source/server/server.ts +++ b/source/server/server.ts @@ -5,16 +5,16 @@ import cookieSession from "cookie-session"; import express from "express"; import { engine } from 'express-handlebars'; -import UserManager from "./auth/UserManager"; -import { BadRequestError, HTTPError } from "./utils/errors"; +import UserManager from "./auth/UserManager.js"; +import { BadRequestError, HTTPError } from "./utils/errors.js"; import { mkdir } from "fs/promises"; -import {AppLocals, getHost, getUserManager} from "./utils/locals"; +import {AppLocals, getHost, getUserManager} from "./utils/locals.js"; -import openDatabase from './vfs/helpers/db'; -import Vfs from "./vfs"; -import defaultConfig from "./utils/config"; -import User from "./auth/User"; +import openDatabase from "./vfs/helpers/db.js"; +import Vfs from "./vfs/index.js"; +import defaultConfig from "./utils/config.js"; +import User from "./auth/User.js"; export default async function createServer(config = defaultConfig) :Promise{ @@ -177,14 +177,14 @@ export default async function createServer(config = defaultConfig) :Promise =["foo", "\n"]){ } global.createIntegrationContext = async function(c :Mocha.Context){ - let {default:createServer} = await import("./server"); + let {default:createServer} = await import("./server.js"); let titleSlug = c.currentTest?.title.replace(/[^\w]/g, "_") ?? `eThesaurus_integration_test`; c.dir = await fs.mkdtemp(path.join(tmpdir(), titleSlug)); c.config = parse({ROOT_DIR: c.dir, CLEAN_DATABASE: "false", VERBOSE: "false", HOT_RELOAD: "false"}); diff --git a/source/server/tsconfig.json b/source/server/tsconfig.json index 257e1ce8..0d69489d 100644 --- a/source/server/tsconfig.json +++ b/source/server/tsconfig.json @@ -1,21 +1,16 @@ { "compilerOptions": { - "lib": ["es2022"], - "module": "node16", - "target": "es2022", + "lib": ["ES2021"], + "module": "NodeNext", + "target": "ES2021", "strict": true, "resolveJsonModule": true, - "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, - "moduleResolution": "node", "sourceMap": true, "types": ["mocha", "chai", "chai-as-promised"], "outDir": "./dist", - "rootDir": "..", - "paths": { - "@ff/core/types": [ "./utils/documents/types" ], - } + "rootDir": ".." }, "files": [ "index.ts", diff --git a/source/server/utils/config.test.ts b/source/server/utils/config.test.ts index 99140b1a..6f016e20 100644 --- a/source/server/utils/config.test.ts +++ b/source/server/utils/config.test.ts @@ -1,5 +1,5 @@ import {expect} from "chai"; -import config, {parse} from "./config"; +import config, {parse} from "./config.js"; describe("config", function(){ it("get a config option", function(){ diff --git a/source/server/utils/errors.test.ts b/source/server/utils/errors.test.ts index 62e44553..7f4fc507 100644 --- a/source/server/utils/errors.test.ts +++ b/source/server/utils/errors.test.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import * as errorConstructors from "./errors"; +import * as errorConstructors from "./errors.js"; describe("errors", function(){ let {HTTPError, ...defaultConstructors} = errorConstructors; Object.entries(defaultConstructors).forEach(([name, Constructor])=>{ diff --git a/source/server/utils/glTF.test.ts b/source/server/utils/glTF.test.ts index 5e47bd77..18bd64ef 100644 --- a/source/server/utils/glTF.test.ts +++ b/source/server/utils/glTF.test.ts @@ -1,12 +1,15 @@ import { expect } from "chai"; import fs from "fs/promises"; import path from "path"; -import { parse_glb, parse_glTF } from "./glTF"; +import { fileURLToPath } from 'url'; +import { parse_glb, parse_glTF } from "./glTF.js"; +const thisFile = fileURLToPath(import.meta.url); +const thisDir = path.dirname(thisFile); describe("parse_glb()", function(){ it("parse a glb file to extract data", async function(){ - let d = await parse_glb(path.resolve(__dirname, "../__test_fixtures/cube.glb" )); + let d = await parse_glb(path.resolve(thisDir, "../__test_fixtures/cube.glb" )); expect(d).to.deep.equal({ meshes:[{ numFaces: 6*2 /*it takes two triangles to make a square and 6 squares for a cube */, @@ -25,14 +28,14 @@ describe("parse_glb()", function(){ }) }); it("throw an error for invalid files", async function(){ - await expect(parse_glb( __filename)).to.be.rejectedWith("bad magic number"); + await expect(parse_glb( thisFile)).to.be.rejectedWith("bad magic number"); }) }); describe("parse_gltf()", function(){ it("handles morph targets", async function(){ - let data = await fs.readFile(path.resolve(__dirname, "../__test_fixtures/morph.gltf" ), {encoding: "utf8"}); + let data = await fs.readFile(path.resolve(thisDir, "../__test_fixtures/morph.gltf" ), {encoding: "utf8"}); let gltf = JSON.parse(data); let res = parse_glTF(gltf); expect(res).to.deep.equal({ diff --git a/source/server/utils/locals.ts b/source/server/utils/locals.ts index 0c199ec6..c48a9921 100644 --- a/source/server/utils/locals.ts +++ b/source/server/utils/locals.ts @@ -1,10 +1,10 @@ import { NextFunction, Request, RequestHandler, Response } from "express"; import {basename, dirname} from "path"; -import User, { SafeUser } from "../auth/User"; -import UserManager, { AccessType, AccessTypes } from "../auth/UserManager"; -import Vfs, { GetFileParams } from "../vfs"; -import { BadRequestError, ForbiddenError, HTTPError, InternalError, NotFoundError, UnauthorizedError } from "./errors"; +import User, { SafeUser } from "../auth/User.js"; +import UserManager, { AccessType, AccessTypes } from "../auth/UserManager.js"; +import Vfs, { GetFileParams } from "../vfs/index.js"; +import { BadRequestError, ForbiddenError, HTTPError, InternalError, NotFoundError, UnauthorizedError } from "./errors.js"; export interface AppLocals extends Record{ port :number; diff --git a/source/server/utils/mails/send.ts b/source/server/utils/mails/send.ts index 233d52d8..6900a7e1 100644 --- a/source/server/utils/mails/send.ts +++ b/source/server/utils/mails/send.ts @@ -1,8 +1,8 @@ import sendmail from "sendmail"; import { once } from "events"; -import config from "../config"; +import config from "../config.js"; -import { BOUNDARY, MailBody } from "./templates"; +import { BOUNDARY, MailBody } from "./templates.js"; import { promisify } from "util"; const _send = promisify(sendmail({ diff --git a/source/server/utils/mails/templates.ts b/source/server/utils/mails/templates.ts index 8d7327d7..6be41423 100644 --- a/source/server/utils/mails/templates.ts +++ b/source/server/utils/mails/templates.ts @@ -1,4 +1,4 @@ -import config from "../config"; +import config from "../config.js"; export type Mime = "text"|"html" diff --git a/source/server/utils/schema/common.d.ts b/source/server/utils/schema/common.d.ts new file mode 100644 index 00000000..8bf3692a --- /dev/null +++ b/source/server/utils/schema/common.d.ts @@ -0,0 +1,41 @@ +/** + * 3D Foundation Project + * Copyright 2019 Smithsonian Institution + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type TUnitType = "mm" | "cm" | "m" | "km" | "in" | "ft" | "yd" | "mi"; +export enum EUnitType { mm, cm, m, km, in, ft, yd, mi } + +export type Vector3 = number[]; +export type Vector4 = number[]; +export type Matrix4 = number[]; +export type Quaternion = Vector4; +export type ColorRGB = Vector3; +export type ColorRGBA = Vector4; + +export type TLanguageType = "EN" | "ES" | "DE" | "NL" | "JA" | "FR" | "HAW"; +export enum ELanguageType { EN, ES, DE, NL, JA, FR, HAW } +export enum ELanguageStringType { + EN = 'English', + ES = 'Spanish (Español)', + DE = 'German (Deutsche)', + NL = 'Dutch (Nederlands)', + JA = 'Japanese (日本語)', + FR = 'French (Français)', + HAW = 'Hawaiian (ʻŌlelo Hawaiʻi)', +} +export const DEFAULT_LANGUAGE = "EN"; + + diff --git a/source/server/utils/documents/default.svx.json b/source/server/utils/schema/default.svx.json similarity index 100% rename from source/server/utils/documents/default.svx.json rename to source/server/utils/schema/default.svx.json diff --git a/source/server/utils/schema/document.d.ts b/source/server/utils/schema/document.d.ts new file mode 100644 index 00000000..34be4051 --- /dev/null +++ b/source/server/utils/schema/document.d.ts @@ -0,0 +1,151 @@ +/** + * 3D Foundation Project + * Copyright 2019 Smithsonian Institution + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Index } from "./types.ts"; + +import { EUnitType, TUnitType, Vector3, Quaternion, Matrix4, ColorRGB } from "./common.ts"; +import { IMeta } from "./meta.ts"; +import { IModel } from "./model.ts"; +import { ISetup } from "./setup.ts"; + +//////////////////////////////////////////////////////////////////////////////// + +export { EUnitType, TUnitType, Vector3, Quaternion, Matrix4, ColorRGB }; + +export type TCameraType = "perspective" | "orthographic"; +export type TLightType = "ambient" | "directional" | "point" | "spot" | "hemisphere"; + +/** + * Encapsulates a node tree representing a renderable scene. + */ +export interface IDocument +{ + asset: IDocumentAsset; + scene?: Index; + scenes?: IScene[]; + nodes?: INode[]; + cameras?: ICamera[]; + lights?: ILight[]; + metas?: IMeta[]; + models?: IModel[]; + setups?: ISetup[]; +} + +/** + * Information about the document, such as its type, version, copyright and generator. + */ +export interface IDocumentAsset +{ + type: "application/si-dpo-3d.document+json"; + version: string; + copyright?: string; + generator?: string; +} + +export interface IScene +{ + name?: string; + nodes?: Index[]; + setup?: Index; + meta?: Index; + units: TUnitType; +} + +/** + * Node in scene hierarchy. + */ +export interface INode +{ + name?: string; + children?: Index[]; + + matrix?: Matrix4; + translation?: Vector3; + rotation?: Quaternion; + scale?: Vector3; + + camera?: Index; + light?: Index; + model?: Index; + meta?: Index; +} + +/** + * Properties shared by all camera types. + */ +export interface ICamera +{ + type: TCameraType; + perspective?: IPerspectiveCameraProps; + orthographic?: IOrthographicCameraProps; +} + +/** + * Properties for perspective cameras. + */ +export interface IPerspectiveCameraProps +{ + yfov: number; + znear?: number; + zfar?: number; +} + +/** + * Properties for orthographic cameras. + */ +export interface IOrthographicCameraProps +{ + ymag: number; + znear?: number; + zfar?: number; +} + +/** + * Properties shared by all light types. + */ +export interface ILight +{ + type: TLightType; + color?: ColorRGB; + intensity?: number; + + shadowEnabled?: boolean; + shadowSize?: number; + shadowResolution?: string; + shadowBlur?: number; + + point?: IPointLightProps; + spot?: ISpotLightProps; +} + +/** + * Properties for point lights. + */ +export interface IPointLightProps +{ + distance: number; + decay: number; +} + +/** + * Properties for spot lights. + */ +export interface ISpotLightProps extends IPointLightProps +{ + angle: number; + penumbra: number; +} diff --git a/source/server/utils/documents/edit.test.ts b/source/server/utils/schema/edit.test.ts similarity index 99% rename from source/server/utils/documents/edit.test.ts rename to source/server/utils/schema/edit.test.ts index ffb006a0..71497e06 100644 --- a/source/server/utils/documents/edit.test.ts +++ b/source/server/utils/schema/edit.test.ts @@ -1,5 +1,5 @@ import { expect } from "chai" -import { addDerivative, addModel, Asset, Document } from "./edit" +import { addDerivative, addModel, Asset, Document } from "./edit.js"; diff --git a/source/server/utils/documents/edit.ts b/source/server/utils/schema/edit.ts similarity index 91% rename from source/server/utils/documents/edit.ts rename to source/server/utils/schema/edit.ts index 29e3e4fb..8507580f 100644 --- a/source/server/utils/documents/edit.ts +++ b/source/server/utils/schema/edit.ts @@ -1,7 +1,7 @@ -import ref from "./default.svx.json"; +import ref from "./default.svx.json" assert { type: "json" }; -import {IDocument, INode, IScene} from "../../../client/schema/document" -import { IAsset, IBoundingBox, IDerivative, IModel, TDerivativeQuality, TDerivativeUsage } from "../../../client/schema/model"; +import {IDocument, INode, IScene} from "./document.js"; +import { IAsset, IBoundingBox, IDerivative, IModel, TDerivativeQuality, TDerivativeUsage } from "./model.js"; export interface Document extends IDocument{ scenes:IScene[]; diff --git a/source/server/utils/schema/meta.d.ts b/source/server/utils/schema/meta.d.ts new file mode 100644 index 00000000..216a7252 --- /dev/null +++ b/source/server/utils/schema/meta.d.ts @@ -0,0 +1,87 @@ +/** + * 3D Foundation Project + * Copyright 2019 Smithsonian Institution + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Index, Dictionary } from "./types.ts"; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Contains meta data (articles, collection record, processing information) + * about a scene item (scene root, model). + */ +export interface IMeta +{ + collection?: Dictionary; + process?: Dictionary; + images?: IImage[]; + articles?: IArticle[]; + audio?: IAudioClip[]; + leadArticle?: Index; +} + +export interface IImage +{ + quality: TImageQuality, + uri: string; + byteSize: number; + width: number; + height: number; +} + +export type TImageQuality = "Thumb" | "Low" | "Medium" | "High"; + +/** + * Refers to an external document or a media file (audio, video, image). + */ +export interface IArticle +{ + id: string; + uri: string; + uris?: Dictionary; + + title?: string; + titles?: Dictionary; + lead?: string; + leads?: Dictionary; + tags?: string[]; + taglist?: Dictionary; + + mimeType?: string; + thumbnailUri?: string; +} + +/** + * Notes taken during processing. Part of the process section of [[IMeta]]. + */ +export interface INote +{ + date: string; + user: string; + text: string; +} + +/** + * Audio files referenced by the scene [narrations, audio descriptions, etc.]. + */ +export interface IAudioClip +{ + id: string; + name: string; + uris: Dictionary; + captionUris: Dictionary; + durations: Dictionary; +} \ No newline at end of file diff --git a/source/server/utils/schema/model.d.ts b/source/server/utils/schema/model.d.ts new file mode 100644 index 00000000..96e5d60a --- /dev/null +++ b/source/server/utils/schema/model.d.ts @@ -0,0 +1,147 @@ +/** + * 3D Foundation Project + * Copyright 2019 Smithsonian Institution + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Dictionary } from "./types.js"; +import { ColorRGBA, EUnitType, TUnitType, Vector3, Vector4 } from "./common.js"; + +//////////////////////////////////////////////////////////////////////////////// + +export { EUnitType, TUnitType }; + +export type TNormalSpaceType = "Tangent" | "Object"; + +export enum EDerivativeUsage { Image2D, Web3D, App3D, iOSApp3D, Print3D, Editorial3D } +export type TDerivativeUsage = "Image2D" | "Web3D" | "App3D" | "iOSApp3D" | "Print3D" | "Editorial3D"; + +export enum EDerivativeQuality { Thumb, Low, Medium, High, Highest, AR } +export type TDerivativeQuality = "Thumb" | "Low" | "Medium" | "High" | "Highest" | "AR"; + +export enum EAssetType { Model, Geometry, Image, Texture, Points, Volume } +export type TAssetType = "Model" | "Geometry" | "Image" | "Texture" | "Points" | "Volume"; + +export enum EMapType { Color, Emissive, Occlusion, Normal, MetallicRoughness, Zone } +export type TMapType = "Color" | "Emissive" | "Occlusion" | "Normal" | "MetallicRoughness" | "Zone"; + +export enum ESideType { Front, Back, Double, Default } +export type TSideType = "Front" | "Back" | "Double"| "Default"; + + +export interface IModel +{ + units: TUnitType; + tags?: string; + derivatives: IDerivative[]; + + visible?: boolean; + renderOrder?: number; + overlayMap?: number; + castShadow?: boolean; + receiveShadow?: boolean; + shadowSide?: TSideType; + translation?: Vector3; + rotation?: Vector4; + boundingBox?: IBoundingBox; + material?: IPBRMaterialSettings; + annotations?: IAnnotation[]; +} + +/** + * Connects annotated information to a spatial location. + * Annotation targets are specific locations (spots) or areas (zones) on an item. + */ +export interface IAnnotation +{ + id: string; + + title?: string; + titles?: Dictionary; + lead?: string; + leads?: Dictionary; + marker?: string; + tags?: string[]; + taglist?: Dictionary; + articleId?: string; + imageUri?: string; + imageCredit?: Dictionary; + imageAltText?: Dictionary; + audioId?: string; + + style?: string; + visible?: boolean; + expanded?: boolean; + + position?: Vector3; + direction?: Vector3; + scale?: number; + offset?: number; + tilt?: number; + azimuth?: number; + color?: number[]; + + zoneIndex?: number; +} + +/** + * Axis-aligned bounding box. + */ +export interface IBoundingBox +{ + min: Vector3; + max: Vector3; +} + +/** + * Derivative representation of a collection item. + * Points to one or multiple assets (files/resources). + */ +export interface IDerivative +{ + usage: TDerivativeUsage; + quality: TDerivativeQuality; + assets: IAsset[]; +} + +/** + * Describes an asset, a resource containing a mesh, model, image, + * point cloud or volumetric representation. + */ +export interface IAsset +{ + uri: string; + type: TAssetType; + part?: string; + mimeType?: string; + byteSize?: number; + numFaces?: number; + imageSize?: number; + mapType?: TMapType; +} + +export interface IPBRMaterialSettings +{ + color?: ColorRGBA + opacity?: number; + hiddenOpacity?: number; + roughness?: number; + metalness?: number; + occlusion?: number; + //emissiveFactor?: ColorRGB; + //alphaMode?: any; // TODO + //alphaCutoff?: number; + doubleSided?: boolean; + normalSpace?: TNormalSpaceType; +} diff --git a/source/server/utils/schema/setup.d.ts b/source/server/utils/schema/setup.d.ts new file mode 100644 index 00000000..29d32424 --- /dev/null +++ b/source/server/utils/schema/setup.d.ts @@ -0,0 +1,205 @@ +import { Dictionary } from "./types.ts"; +import { ELanguageType, TLanguageType } from "./common.ts"; + +/** + * 3D Foundation Project + * Copyright 2019 Smithsonian Institution + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +export type TShaderMode = "Default" | "Clay" | "XRay" | "Normals" | "Wireframe"; +export enum EShaderMode { Default, Clay, XRay, Normals, Wireframe } + +export type TBackgroundStyle = "Solid" | "LinearGradient" | "RadialGradient"; +export enum EBackgroundStyle { Solid, LinearGradient, RadialGradient } + +export type TNavigationType = "Orbit" | "Walk"; +export enum ENavigationType { Orbit, Walk } + +export type TReaderPosition = "Overlay" | "Left" | "Right"; +export enum EReaderPosition { Overlay, Left, Right } + +export type TSliceAxis = "X" | "Y" | "Z"; +export enum ESliceAxis { X, Y, Z } + +export interface ISetup +{ + interface?: IInterface; + viewer?: IViewer; + reader?: IReader; + navigation?: INavigation; + background?: IBackground; + environment?: IEnvironment, + language?: ILanguage, + floor?: IFloor; + grid?: IGrid; + tape?: ITape; + slicer?: ISlicer; + tours?: ITours; + snapshots?: ISnapshots; +} + +export interface IInterface +{ + visible: boolean; + logo: boolean; + menu: boolean; + tools: boolean; +} + +export interface IViewer +{ + shader: TShaderMode; + exposure: number; + toneMapping: boolean; + gamma: number; + isWallMountAR: boolean; + arScale: number; + annotationsVisible?: boolean; + activeTags?: string; + sortedTags?: string; + radioTags?: boolean; +} + +export interface IReader +{ + enabled: boolean; + position: string; + articleId?: string; +} + +export interface INavigation +{ + type: TNavigationType; + enabled: boolean; + autoZoom: boolean; + autoRotation: boolean; + lightsFollowCamera: boolean; + orbit?: IOrbitNavigation; + walk?: IWalkNavigation; +} + +export interface IOrbitNavigation +{ + orbit: number[]; + offset: number[]; + minOrbit: number[]; + maxOrbit: number[]; + minOffset: number[]; + maxOffset: number[]; +} + +export interface IWalkNavigation +{ + position: number[]; + rotation: number[]; + minPosition: number[]; + maxPosition: number[]; +} + +export interface IBackground +{ + style: TBackgroundStyle; + color0: number[]; + color1: number[]; +} + +export interface IFloor +{ + visible: boolean; + position: number[]; + size: number; + color: number[]; + opacity: number; + receiveShadow: boolean; +} + +export interface IGrid +{ + visible: boolean; + color: number[]; +} + +export interface IEnvironment +{ + index: number; +} + +export interface ILanguage +{ + language: TLanguageType; +} + +export interface IAudio +{ + narrationId?: string; +} + +export interface ITape +{ + enabled: boolean; + /*startPosition: number[]; + startDirection: number[]; + endPosition: number[]; + endDirection: number[];*/ +} + +export interface ISlicer +{ + enabled: boolean; + axis: TSliceAxis; + inverted: boolean; + position: number; + color: number[]; +} + +export type ITours = ITour[]; + +export interface ISnapshots +{ + features: string[]; + targets: string[]; + states: { + id: string; + curve: string; + duration: number; + threshold: number; + values: any[]; + }[]; +} + +export interface ITour +{ + title: string; + titles?: Dictionary; + steps: ITourStep[]; + lead?: string; + leads?: Dictionary; + tags?: string[]; + taglist?: Dictionary; +} + +export interface ITourStep +{ + title: string; + titles?: Dictionary; + id: string; +} + +export interface ILanguageOption +{ + name: string; + id: ELanguageType; +} \ No newline at end of file diff --git a/source/server/utils/documents/types.ts b/source/server/utils/schema/types.d.ts similarity index 100% rename from source/server/utils/documents/types.ts rename to source/server/utils/schema/types.d.ts diff --git a/source/server/utils/uid.test.ts b/source/server/utils/uid.test.ts index 68461c10..27542fbc 100644 --- a/source/server/utils/uid.test.ts +++ b/source/server/utils/uid.test.ts @@ -4,7 +4,7 @@ import path from "path"; import {tmpdir} from "os"; import {expect} from "chai"; -import uid, { Uid } from "./uid" +import uid, { Uid } from "./uid.js"; describe("uid()", function(){ it("generates unique fixed-length names", function(){ for(let i=0; i <100; i++){ diff --git a/source/server/utils/wrapAsync.test.ts b/source/server/utils/wrapAsync.test.ts index 6781d51e..775766cd 100644 --- a/source/server/utils/wrapAsync.test.ts +++ b/source/server/utils/wrapAsync.test.ts @@ -3,7 +3,7 @@ import timers from "timers/promises" import express, { Express, NextFunction, Request, Response } from "express"; import request from "supertest"; -import wrap, { wrapFormat } from "./wrapAsync"; +import wrap, { wrapFormat } from "./wrapAsync.js"; describe("wrapAsync", function(){ diff --git a/source/server/utils/zip/crc32.test.ts b/source/server/utils/zip/crc32.test.ts index 087a82ab..aa1c2410 100644 --- a/source/server/utils/zip/crc32.test.ts +++ b/source/server/utils/zip/crc32.test.ts @@ -1,4 +1,4 @@ -import { crc32 } from "./crc32"; +import { crc32 } from "./crc32.js"; describe("crc32", function(){ diff --git a/source/server/utils/zip/datetime.test.ts b/source/server/utils/zip/datetime.test.ts index f9e5fa0d..4b37fc47 100644 --- a/source/server/utils/zip/datetime.test.ts +++ b/source/server/utils/zip/datetime.test.ts @@ -1,4 +1,4 @@ -import { DateTime } from "./datetime"; +import { DateTime } from "./datetime.js"; diff --git a/source/server/utils/zip/index.ts b/source/server/utils/zip/index.ts index 1575e699..ddf0ee98 100644 --- a/source/server/utils/zip/index.ts +++ b/source/server/utils/zip/index.ts @@ -3,8 +3,8 @@ import assert from "assert/strict"; import { Readable, Stream } from "stream"; -import { crc32 } from "./crc32"; -import {DateTime} from "./datetime"; +import { crc32 } from "./crc32.js"; +import {DateTime} from "./datetime.js"; import { ReadStream } from "fs"; diff --git a/source/server/utils/zip/zip.test.ts b/source/server/utils/zip/zip.test.ts index 59fb4ba4..4ba6353a 100644 --- a/source/server/utils/zip/zip.test.ts +++ b/source/server/utils/zip/zip.test.ts @@ -1,7 +1,7 @@ import fs, { FileHandle } from "fs/promises" import { expect } from "chai"; -import { GetFileResult } from "../../vfs"; -import { asyncMap, create_cd_header, flags, parse_cd_header, read_cdh, unzip, zip, } from "." +import { GetFileResult } from "../../vfs/index.js"; +import { asyncMap, create_cd_header, flags, parse_cd_header, read_cdh, unzip, zip, } from "./index.js"; import { Readable } from "stream"; import { createHash } from "crypto"; import path from "path"; diff --git a/source/server/vfs/Base.ts b/source/server/vfs/Base.ts index 008d6c87..515d7cc3 100644 --- a/source/server/vfs/Base.ts +++ b/source/server/vfs/Base.ts @@ -1,8 +1,8 @@ -import open, {Database} from "./helpers/db"; +import open, {Database} from "./helpers/db.js"; import path from "path"; -import { InternalError, NotFoundError } from "../utils/errors"; -import { FileProps } from "./types"; +import { InternalError, NotFoundError } from "../utils/errors.js"; +import { FileProps } from "./types.js"; export default abstract class BaseVfs{ diff --git a/source/server/vfs/Clean.ts b/source/server/vfs/Clean.ts index 25954c57..71cb5901 100644 --- a/source/server/vfs/Clean.ts +++ b/source/server/vfs/Clean.ts @@ -1,8 +1,8 @@ import fs from "fs/promises"; import timers from "timers/promises"; import {constants} from "fs"; -import BaseVfs from "./Base"; -import FilesVfs from "./Files"; +import BaseVfs from "./Base.js"; +import FilesVfs from "./Files.js"; diff --git a/source/server/vfs/Docs.ts b/source/server/vfs/Docs.ts index 92954fb0..2368b156 100644 --- a/source/server/vfs/Docs.ts +++ b/source/server/vfs/Docs.ts @@ -1,7 +1,7 @@ -import { NotFoundError } from "../utils/errors"; -import { Uid } from "../utils/uid"; -import BaseVfs from "./Base"; -import { DocProps } from "./types"; +import { NotFoundError } from "../utils/errors.js"; +import { Uid } from "../utils/uid.js"; +import BaseVfs from "./Base.js"; +import { DocProps } from "./types.js"; diff --git a/source/server/vfs/Files.ts b/source/server/vfs/Files.ts index de798db0..97f4831b 100644 --- a/source/server/vfs/Files.ts +++ b/source/server/vfs/Files.ts @@ -1,12 +1,12 @@ import { constants, promises as fs } from "fs"; import { createHash } from "crypto"; import path from "path"; -import { NotFoundError, InternalError, ConflictError, BadRequestError } from "../utils/errors"; -import { Uid } from "../utils/uid"; -import BaseVfs from "./Base"; -import { DataStream, FileProps, GetFileParams, GetFileResult, WriteDirParams, WriteFileParams } from "./types"; +import { NotFoundError, InternalError, ConflictError, BadRequestError } from "../utils/errors.js"; +import { Uid } from "../utils/uid.js"; +import BaseVfs from "./Base.js"; +import { DataStream, FileProps, GetFileParams, GetFileResult, WriteDirParams, WriteFileParams } from "./types.js"; -import { Transaction } from "./helpers/db"; +import { Transaction } from "./helpers/db.js"; import { FileHandle } from "fs/promises"; interface DiskFileParams{ diff --git a/source/server/vfs/Scenes.ts b/source/server/vfs/Scenes.ts index 421df8c1..97f40e0d 100644 --- a/source/server/vfs/Scenes.ts +++ b/source/server/vfs/Scenes.ts @@ -1,9 +1,9 @@ -import { AccessType, AccessTypes } from "../auth/UserManager"; -import config from "../utils/config"; -import { BadRequestError, ConflictError, NotFoundError } from "../utils/errors"; -import { Uid } from "../utils/uid"; -import BaseVfs from "./Base"; -import { ItemEntry, Scene, SceneQuery } from "./types"; +import { AccessType, AccessTypes } from "../auth/UserManager.js"; +import config from "../utils/config.js"; +import { BadRequestError, ConflictError, NotFoundError } from "../utils/errors.js"; +import { Uid } from "../utils/uid.js"; +import BaseVfs from "./Base.js"; +import { ItemEntry, Scene, SceneQuery } from "./types.js"; diff --git a/source/server/vfs/Stats.ts b/source/server/vfs/Stats.ts index dfce7deb..9c147d27 100644 --- a/source/server/vfs/Stats.ts +++ b/source/server/vfs/Stats.ts @@ -1,6 +1,6 @@ import os from "os"; -import BaseVfs from "./Base"; +import BaseVfs from "./Base.js"; interface ServerStats{ files: { diff --git a/source/server/vfs/helpers/db.test.ts b/source/server/vfs/helpers/db.test.ts index 82647799..9916c35a 100644 --- a/source/server/vfs/helpers/db.test.ts +++ b/source/server/vfs/helpers/db.test.ts @@ -2,9 +2,9 @@ import fs from "fs/promises"; import os from "os"; import timers from "timers/promises"; import { expect } from "chai"; -import open, { Database } from "./db" +import open, { Database } from "./db.js"; import path from "path"; -import uid from "../../utils/uid"; +import uid from "../../utils/uid.js"; describe("Database.beginTransaction()", function(){ diff --git a/source/server/vfs/helpers/db.ts b/source/server/vfs/helpers/db.ts index effb969b..dad8f0d4 100644 --- a/source/server/vfs/helpers/db.ts +++ b/source/server/vfs/helpers/db.ts @@ -1,7 +1,7 @@ import {open as openDatabase, ISqlite, Database as IDatabase } from "sqlite"; import sqlite from "sqlite3"; -import config from "../../utils/config"; +import config from "../../utils/config.js"; export interface DbOptions { filename:string; diff --git a/source/server/vfs/index.ts b/source/server/vfs/index.ts index 7e379e7f..8d01ef1a 100644 --- a/source/server/vfs/index.ts +++ b/source/server/vfs/index.ts @@ -1,16 +1,16 @@ import fs from "fs/promises"; import path from "path"; -import open, {Database} from "./helpers/db"; +import open, {Database} from "./helpers/db.js"; -import BaseVfs from "./Base"; -import FilesVfs from "./Files"; -import DocsVfs from "./Docs"; -import ScenesVfs from "./Scenes"; -import CleanVfs from "./Clean"; -import StatsVfs from "./Stats"; +import BaseVfs from "./Base.js"; +import FilesVfs from "./Files.js"; +import DocsVfs from "./Docs.js"; +import ScenesVfs from "./Scenes.js"; +import CleanVfs from "./Clean.js"; +import StatsVfs from "./Stats.js"; -export * from "./types"; +export * from "./types.js"; /** diff --git a/source/server/vfs/types.ts b/source/server/vfs/types.ts index ee3db48a..2b8c752a 100644 --- a/source/server/vfs/types.ts +++ b/source/server/vfs/types.ts @@ -1,7 +1,7 @@ import { Request } from "express"; import {ReadStream} from "fs"; import {Readable} from "stream"; -import { AccessType } from "../auth/UserManager"; +import { AccessType } from "../auth/UserManager.js"; export type DataStream = ReadStream|AsyncGenerator|Request; diff --git a/source/server/vfs/vfs.benchmark.ts b/source/server/vfs/vfs.benchmark.ts index 2b2fda09..aa53176b 100644 --- a/source/server/vfs/vfs.benchmark.ts +++ b/source/server/vfs/vfs.benchmark.ts @@ -1,8 +1,8 @@ import fs from "fs/promises"; import path from "path"; import {tmpdir} from "os"; -import Vfs from "."; -import UserManager from "../auth/UserManager"; +import Vfs from "./index.js"; +import UserManager from "../auth/UserManager.js"; import { performance } from "perf_hooks"; /* Test structures */ diff --git a/source/server/vfs/vfs.test.ts b/source/server/vfs/vfs.test.ts index 799dc7fc..adb1fcb3 100644 --- a/source/server/vfs/vfs.test.ts +++ b/source/server/vfs/vfs.test.ts @@ -2,11 +2,11 @@ import fs from "fs/promises"; import path from "path"; import {tmpdir} from "os"; import { expect } from "chai"; -import Vfs, { FileProps, GetFileParams, Scene, WriteFileParams } from "."; -import { Uid } from "../utils/uid"; -import UserManager from "../auth/UserManager"; -import User from "../auth/User"; -import { BadRequestError, ConflictError, NotFoundError } from "../utils/errors"; +import Vfs, { FileProps, GetFileParams, Scene, WriteFileParams } from "./index.js"; +import { Uid } from "../utils/uid.js"; +import UserManager from "../auth/UserManager.js"; +import User from "../auth/User.js"; +import { BadRequestError, ConflictError, NotFoundError } from "../utils/errors.js"; async function *dataStream(src :Array =["foo", "\n"]){ for(let d of src){