From d87358c9a9f9e5d114a57c563c6e0def5be3eaf8 Mon Sep 17 00:00:00 2001 From: Pascal Knoth Date: Fri, 8 Mar 2024 10:20:26 +0100 Subject: [PATCH] run server as an esm module --- controllers/Default.js | 8 ++- docker/Dockerfile | 2 +- index.cjs => index.js | 8 ++- package-lock.json | 109 +++++++++++++++++++++++++------------- package.json | 10 ++-- service/DefaultService.js | 6 +-- utils/writer.js | 4 +- 7 files changed, 87 insertions(+), 60 deletions(-) rename index.cjs => index.js (76%) diff --git a/controllers/Default.js b/controllers/Default.js index 48dc3fa..c57fad3 100644 --- a/controllers/Default.js +++ b/controllers/Default.js @@ -1,9 +1,7 @@ -'use strict'; +import * as utils from '../utils/writer.js'; +import * as Service from '../service/DefaultService.js'; -const utils = require('../utils/writer.js'); -const Service = require('../service/DefaultService.js'); - -exports.resolve = function resolve (req, res) { +export const resolve = function resolve (req, res) { const identifier = req.params['identifier']; const accept = req.get('accept'); console.log('request: ' + identifier); diff --git a/docker/Dockerfile b/docker/Dockerfile index 6fea617..78e71b4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,4 +16,4 @@ RUN find ./ -name "*.ts" -type f -exec sed -i -e "s/'did:key:zUC7': typeof bls12 EXPOSE 8080 -CMD [ "node", "index.cjs" ] +CMD [ "npm", "start" ] diff --git a/index.cjs b/index.js similarity index 76% rename from index.cjs rename to index.js index 56718ee..86c3147 100644 --- a/index.cjs +++ b/index.js @@ -1,8 +1,6 @@ -'use strict'; - -const http = require('http'); -const express = require('express'); -const Controller = require('./controllers/Default.js'); +import http from 'http'; +import express from 'express'; +import * as Controller from './controllers/Default.js'; const serverPort = 8080; diff --git a/package-lock.json b/package-lock.json index 6191b51..8b54bb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.5.0", "license": "Unlicense", "dependencies": { - "@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.12", - "@malachit/did-key.js": "0.3.0-unstable.10", + "@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.15", + "@malachit/did-key.js": "0.3.0-unstable.14", "@transmute/did-key-bls12381": "0.3.0-unstable.10", "express": "4.18.2", "root": "github:malach-it/did-key.js" @@ -72,17 +72,17 @@ } }, "node_modules/@malachit/did-key-jwk-jcs-pub": { - "version": "0.3.0-unstable.12", - "resolved": "https://registry.npmjs.org/@malachit/did-key-jwk-jcs-pub/-/did-key-jwk-jcs-pub-0.3.0-unstable.12.tgz", - "integrity": "sha512-7X+1tN6noWYGoyJPSCKydepcSs5WbCcgvBFOKogrnBC39hStbtwLOr9hWyH3cqkt14t17+gjAfiDX7uDsCcQHQ==", + "version": "0.3.0-unstable.15", + "resolved": "https://registry.npmjs.org/@malachit/did-key-jwk-jcs-pub/-/did-key-jwk-jcs-pub-0.3.0-unstable.15.tgz", + "integrity": "sha512-bvR6a1JlG101DC8C6E8xSiAHU1xUQh0SFzAxxPi/emuRBKJ989DovHohbr15b2ypixw7LH4lNOdz4fBai9Cc6g==", "dependencies": { "@cef-ebsi/key-did-resolver": "^2.0.0" } }, "node_modules/@malachit/did-key.js": { - "version": "0.3.0-unstable.10", - "resolved": "https://registry.npmjs.org/@malachit/did-key.js/-/did-key.js-0.3.0-unstable.10.tgz", - "integrity": "sha512-RyDZBw6HA4qYjgE07SpWUWVz4Mi62e5xRBF/ducAbCpNylcv5K5+mFFyJCOKt1ME4Jhr9gDZXoqnC2UHZ/ze2g==", + "version": "0.3.0-unstable.14", + "resolved": "https://registry.npmjs.org/@malachit/did-key.js/-/did-key.js-0.3.0-unstable.14.tgz", + "integrity": "sha512-fxNDsMiTghlJguizWJPBQcTsJ9Ee8jtV3nGi4Qpb+Ya3bQMTzK1JjLEAc5t1xQdPcbw47ODmn8+Gnq/xFa1wDQ==", "dependencies": { "@malachit/did-key-jwk-jcs-pub": "^0.3.0-unstable.10", "@transmute/did-key-bls12381": "^0.3.0-unstable.10", @@ -724,13 +724,18 @@ } }, "node_modules/call-bind": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", - "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.1", - "set-function-length": "^1.1.1" + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1034,16 +1039,19 @@ } }, "node_modules/define-data-property": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", - "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "dependencies": { - "get-intrinsic": "^1.2.1", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" }, "engines": { "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/delegates": { @@ -1116,6 +1124,25 @@ "node": ">= 0.8" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", @@ -1353,15 +1380,19 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", - "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dependencies": { + "es-errors": "^1.3.0", "function-bind": "^1.1.2", "has-proto": "^1.0.1", "has-symbols": "^1.0.3", "hasown": "^2.0.0" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -1437,20 +1468,20 @@ } }, "node_modules/has-property-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", - "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dependencies": { - "get-intrinsic": "^1.2.2" + "es-define-property": "^1.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/has-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", - "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", "engines": { "node": ">= 0.4" }, @@ -1485,9 +1516,9 @@ } }, "node_modules/hasown": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", - "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.1.tgz", + "integrity": "sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==", "dependencies": { "function-bind": "^1.1.2" }, @@ -2408,14 +2439,16 @@ "optional": true }, "node_modules/set-function-length": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", - "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.1.tgz", + "integrity": "sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==", "dependencies": { - "define-data-property": "^1.1.1", - "get-intrinsic": "^1.2.1", + "define-data-property": "^1.1.2", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.3", "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.0" + "has-property-descriptors": "^1.0.1" }, "engines": { "node": ">= 0.4" diff --git a/package.json b/package.json index 16689d6..2faf8e6 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,21 @@ "name": "uni-resolver-driver-did-key", "version": "0.5.0", "description": "Universal Resolver Driver", - "main": "index.cjs", + "main": "index.js", "scripts": { "prestart": "npm install", - "start": "node index.cjs" + "start": "node index.js" }, "keywords": [ "swagger" ], + "type": "module", "license": "Unlicense", "private": true, - "type": "commonjs", "dependencies": { - "@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.12", + "@malachit/did-key-jwk-jcs-pub": "0.3.0-unstable.15", + "@malachit/did-key.js": "0.3.0-unstable.14", "@transmute/did-key-bls12381": "0.3.0-unstable.10", - "@malachit/did-key.js": "0.3.0-unstable.10", "express": "4.18.2", "root": "github:malach-it/did-key.js" } diff --git a/service/DefaultService.js b/service/DefaultService.js index 5cd6aeb..1f9cfa6 100644 --- a/service/DefaultService.js +++ b/service/DefaultService.js @@ -1,6 +1,4 @@ -'use strict'; - -const didKey = require('@malachit/did-key.js'); +import * as didKey from '@malachit/did-key.js'; /** * Resolve a DID or other identifier. @@ -9,7 +7,7 @@ const didKey = require('@malachit/did-key.js'); * accept String The requested MIME type of the DID document or DID resolution result. (optional) * returns Object **/ -exports.resolve = function(identifier,accept) { +export const resolve = function(identifier,accept) { return new Promise(function(resolve, reject) { didKey.resolve(identifier) .then(function(didResolutionResult) { diff --git a/utils/writer.js b/utils/writer.js index 3cee5c6..ea4c0cd 100644 --- a/utils/writer.js +++ b/utils/writer.js @@ -3,11 +3,11 @@ var ResponsePayload = function(code, payload) { this.payload = payload; } -exports.respondWithCode = function(code, payload) { +export const respondWithCode = function(code, payload) { return new ResponsePayload(code, payload); } -var writeJson = exports.writeJson = function(response, arg1, arg2) { +export const writeJson = function(response, arg1, arg2) { var code; var payload;