feat: Enhance reference validation and add support for Handle URLs
Some checks failed
CI Pipeline / japa-tests (push) Failing after 51s

- Updated reference validation to handle various identifier types including DOI, ISBN, ISSN, URN, and Handle.
- Improved regex patterns for DOI and Handle validation to correctly extract and validate identifiers from URLs.
- Added asynchronous checks to verify the existence of DOI and Handle URLs.
- Added asynchronous checks to verify the existence of  ISBNs
- Included detailed comments explaining the regex patterns and validation logic.
- Adjusted the validation logic to handle any URL prefix for Handle identifiers.
- Ensured that the Handle format `handle/20.500.12854/36478` is correctly validated.
- Updated the CI workflow to trigger on push and pull request events.
This commit is contained in:
Kaimbacher 2025-01-24 17:11:10 +01:00
parent 537c6fd81a
commit 2c4f51be68
12 changed files with 538 additions and 162 deletions

View file

@ -95,3 +95,30 @@ jobs:
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
---
name: CI
on:
push:
branches:
- feat/checkReferenceType
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npx japa --group "ReferenceValidation"

View file

@ -33,7 +33,8 @@ export default defineConfig({
() => import('#start/rules/file_length'),
() => import('#start/rules/file_scan'),
() => import('#start/rules/allowed_extensions_mimetypes'),
() => import('#start/rules/dependent_array_min_length')
() => import('#start/rules/dependent_array_min_length'),
() => import('#start/rules/referenceValidation')
],
/*
|--------------------------------------------------------------------------

View file

@ -363,7 +363,8 @@ export default class DatasetController {
references: vine
.array(
vine.object({
value: vine.string().trim().minLength(3).maxLength(255),
// value: vine.string().trim().minLength(3).maxLength(255),
value: vine.string().trim().minLength(3).maxLength(255).validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
relation: vine.enum(Object.values(RelationTypes)),
label: vine.string().trim().minLength(2).maxLength(255),

View file

@ -1,6 +1,7 @@
import vine, { SimpleMessagesProvider } from '@vinejs/vine';
import { TitleTypes, DescriptionTypes, ContributorTypes, ReferenceIdentifierTypes, RelationTypes } from '#contracts/enums';
import dayjs from 'dayjs';
// import MimeType from '#models/mime_type';
// const enabledExtensions = await MimeType.query().select('file_extension').where('enabled', true).exec();
@ -125,7 +126,7 @@ export const createDatasetValidator = vine.compile(
references: vine
.array(
vine.object({
value: vine.string().trim().minLength(3).maxLength(255),
value: vine.string().trim().minLength(3).maxLength(255).validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
relation: vine.enum(Object.values(RelationTypes)),
label: vine.string().trim().minLength(2).maxLength(255),

297
package-lock.json generated
View file

@ -214,15 +214,15 @@
}
},
"node_modules/@adonisjs/assembler/node_modules/@adonisjs/env": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/@adonisjs/env/-/env-6.1.0.tgz",
"integrity": "sha512-CzK+njXTH3EK+d/UJPqckyqWocOItmLgHIUbvhpd6WvveBnfv1Dz5j9H3k+ogHqThDSJCXu1RkaRAC+HNym9gA==",
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/@adonisjs/env/-/env-6.1.1.tgz",
"integrity": "sha512-sYvcJMbLSqwFWH0WtTTLddxkyXzERZl+8TEkXlMiIFaAZveq9h5eC4SQ+L5ILe9FHHiHVfmHsYF6LlAfcsIG1w==",
"devOptional": true,
"license": "MIT",
"dependencies": {
"@poppinss/utils": "^6.7.3",
"@poppinss/validator-lite": "^1.0.3",
"dotenv": "^16.4.5",
"@poppinss/utils": "^6.9.2",
"@poppinss/validator-lite": "^2.0.1",
"dotenv": "^16.4.7",
"split-lines": "^3.0.0"
},
"engines": {
@ -450,14 +450,14 @@
}
},
"node_modules/@adonisjs/core/node_modules/@adonisjs/env": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/@adonisjs/env/-/env-6.1.0.tgz",
"integrity": "sha512-CzK+njXTH3EK+d/UJPqckyqWocOItmLgHIUbvhpd6WvveBnfv1Dz5j9H3k+ogHqThDSJCXu1RkaRAC+HNym9gA==",
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/@adonisjs/env/-/env-6.1.1.tgz",
"integrity": "sha512-sYvcJMbLSqwFWH0WtTTLddxkyXzERZl+8TEkXlMiIFaAZveq9h5eC4SQ+L5ILe9FHHiHVfmHsYF6LlAfcsIG1w==",
"license": "MIT",
"dependencies": {
"@poppinss/utils": "^6.7.3",
"@poppinss/validator-lite": "^1.0.3",
"dotenv": "^16.4.5",
"@poppinss/utils": "^6.9.2",
"@poppinss/validator-lite": "^2.0.1",
"dotenv": "^16.4.7",
"split-lines": "^3.0.0"
},
"engines": {
@ -1487,9 +1487,9 @@
}
},
"node_modules/@babel/compat-data": {
"version": "7.26.3",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.3.tgz",
"integrity": "sha512-nHIxvKPniQXpmQLb0vhY3VaFb3S0YrTAwpOWJZh1wn3oJPjJk9Asva204PsBdmAE8vpzfHudT8DB0scYvy9q0g==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.5.tgz",
"integrity": "sha512-XvcZi1KWf88RVbF9wn8MN6tYFloU5qX8KjuF3E1PVBmJ9eypXfs4GRiJwLuTZL0iSnJUKn1BFPa5BPZZJyFzPg==",
"dev": true,
"license": "MIT",
"engines": {
@ -1538,14 +1538,14 @@
}
},
"node_modules/@babel/generator": {
"version": "7.26.3",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.3.tgz",
"integrity": "sha512-6FF/urZvD0sTeO7k6/B15pMLC4CHUv1426lzr3N01aHJTl046uCAh9LXW/fzeXXjPNCJ6iABW5XaWOsIZB93aQ==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.5.tgz",
"integrity": "sha512-2caSP6fN9I7HOe6nqhtft7V4g7/V/gfDsC3Ag4W7kEzzvRGKqiv0pu0HogPiZ3KaVSoNDhUws6IJjDjpfmYIXw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.26.3",
"@babel/types": "^7.26.3",
"@babel/parser": "^7.26.5",
"@babel/types": "^7.26.5",
"@jridgewell/gen-mapping": "^0.3.5",
"@jridgewell/trace-mapping": "^0.3.25",
"jsesc": "^3.0.2"
@ -1568,13 +1568,13 @@
}
},
"node_modules/@babel/helper-compilation-targets": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.9.tgz",
"integrity": "sha512-j9Db8Suy6yV/VHa4qzrj9yZfZxhLWQdVnRlXxmKLYlhWUVB1sB2G5sxuWYXk/whHD9iW76PmNzxZ4UCnTQTVEQ==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.26.5.tgz",
"integrity": "sha512-IXuyn5EkouFJscIDuFF5EsiSolseme1s0CZB+QxVugqJLYmKdxI1VfIBOst0SUu4rnk2Z7kqTwmoO1lp3HIfnA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/compat-data": "^7.25.9",
"@babel/compat-data": "^7.26.5",
"@babel/helper-validator-option": "^7.25.9",
"browserslist": "^4.24.0",
"lru-cache": "^5.1.1",
@ -1731,9 +1731,9 @@
}
},
"node_modules/@babel/helper-plugin-utils": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.25.9.tgz",
"integrity": "sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.26.5.tgz",
"integrity": "sha512-RS+jZcRdZdRFzMyr+wcsaqOmld1/EqTghfaBGQQd/WnRdzdlvSZ//kF7U8VQTxf1ynZ4cjUcYgjVGx13ewNPMg==",
"dev": true,
"license": "MIT",
"engines": {
@ -1759,15 +1759,15 @@
}
},
"node_modules/@babel/helper-replace-supers": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.25.9.tgz",
"integrity": "sha512-IiDqTOTBQy0sWyeXyGSC5TBJpGFXBkRynjBeXsvbhQFKj2viwJC76Epz35YLU1fpe/Am6Vppb7W7zM4fPQzLsQ==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.26.5.tgz",
"integrity": "sha512-bJ6iIVdYX1YooY2X7w1q6VITt+LnUILtNk7zT78ykuwStx8BauCzxvFqFaHjOpW1bVnSUM1PN1f0p5P21wHxvg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/helper-member-expression-to-functions": "^7.25.9",
"@babel/helper-optimise-call-expression": "^7.25.9",
"@babel/traverse": "^7.25.9"
"@babel/traverse": "^7.26.5"
},
"engines": {
"node": ">=6.9.0"
@ -1848,12 +1848,12 @@
}
},
"node_modules/@babel/parser": {
"version": "7.26.3",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.3.tgz",
"integrity": "sha512-WJ/CvmY8Mea8iDXo6a7RK2wbmJITT5fN3BEkRuFlxVyNx8jOKIIhmC4fSkTcPcf8JyavbBwIe6OpiCOBXt/IcA==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.5.tgz",
"integrity": "sha512-SRJ4jYmXRqV1/Xc+TIVG84WjHBXKlxO9sHQnA2Pf12QQEAp1LOh6kDzNHXcUnbH1QI0FDoPPVOt+vyUDucxpaw==",
"license": "MIT",
"dependencies": {
"@babel/types": "^7.26.3"
"@babel/types": "^7.26.5"
},
"bin": {
"parser": "bin/babel-parser.js"
@ -2145,13 +2145,13 @@
}
},
"node_modules/@babel/plugin-transform-block-scoped-functions": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.25.9.tgz",
"integrity": "sha512-toHc9fzab0ZfenFpsyYinOX0J/5dgJVA2fm64xPewu7CoYHWEivIWKxkK2rMi4r3yQqLnVmheMXRdG+k239CgA==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.26.5.tgz",
"integrity": "sha512-chuTSY+hq09+/f5lMj8ZSYgCFpppV2CbYrhNFJ1BFoXpiWPnnAb7R0MqrafCpN8E1+YRrtM1MXZHJdIx8B6rMQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/helper-plugin-utils": "^7.25.9"
"@babel/helper-plugin-utils": "^7.26.5"
},
"engines": {
"node": ">=6.9.0"
@ -2565,13 +2565,13 @@
}
},
"node_modules/@babel/plugin-transform-nullish-coalescing-operator": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.25.9.tgz",
"integrity": "sha512-ENfftpLZw5EItALAD4WsY/KUWvhUlZndm5GC7G3evUsVeSJB6p0pBeLQUnRnBCBx7zV0RKQjR9kCuwrsIrjWog==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.26.5.tgz",
"integrity": "sha512-OHqczNm4NTQlW1ghrVY43FPoiRzbmzNVbcgVnMKZN/RQYezHUSdjACjaX50CD3B7UIAjv39+MlsrVDb3v741FA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/helper-plugin-utils": "^7.25.9"
"@babel/helper-plugin-utils": "^7.26.5"
},
"engines": {
"node": ">=6.9.0"
@ -2894,15 +2894,15 @@
}
},
"node_modules/@babel/plugin-transform-typescript": {
"version": "7.26.3",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.26.3.tgz",
"integrity": "sha512-6+5hpdr6mETwSKjmJUdYw0EIkATiQhnELWlE3kJFBwSg/BGIVwVaVbX+gOXBCdc7Ln1RXZxyWGecIXhUfnl7oA==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.26.5.tgz",
"integrity": "sha512-GJhPO0y8SD5EYVCy2Zr+9dSZcEgaSmq5BLR0Oc25TOEhC+ba49vUAGZFjy8v79z9E1mdldq4x9d1xgh4L1d5dQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/helper-annotate-as-pure": "^7.25.9",
"@babel/helper-create-class-features-plugin": "^7.25.9",
"@babel/helper-plugin-utils": "^7.25.9",
"@babel/helper-plugin-utils": "^7.26.5",
"@babel/helper-skip-transparent-expression-wrappers": "^7.25.9",
"@babel/plugin-syntax-typescript": "^7.25.9"
},
@ -3138,17 +3138,17 @@
}
},
"node_modules/@babel/traverse": {
"version": "7.26.4",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.4.tgz",
"integrity": "sha512-fH+b7Y4p3yqvApJALCPJcwb0/XaOSgtK4pzV6WVjPR5GLFQBRI7pfoX2V2iM48NXvX07NUxxm1Vw98YjqTcU5w==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.5.tgz",
"integrity": "sha512-rkOSPOw+AXbgtwUga3U4u8RpoK9FEFWBNAlTpcnkLFjL5CT+oyHNuUUC/xx6XefEJ16r38r8Bc/lfp6rYuHeJQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/code-frame": "^7.26.2",
"@babel/generator": "^7.26.3",
"@babel/parser": "^7.26.3",
"@babel/generator": "^7.26.5",
"@babel/parser": "^7.26.5",
"@babel/template": "^7.25.9",
"@babel/types": "^7.26.3",
"@babel/types": "^7.26.5",
"debug": "^4.3.1",
"globals": "^11.1.0"
},
@ -3157,9 +3157,9 @@
}
},
"node_modules/@babel/types": {
"version": "7.26.3",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.3.tgz",
"integrity": "sha512-vN5p+1kl59GVKMvTHt55NzzmYVxprfJD+ql7U9NFIfKCBkYE55LYtS+WtPlaYOyzydrKI8Nezd+aZextrd+FMA==",
"version": "7.26.5",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.5.tgz",
"integrity": "sha512-L6mZmwFDK6Cjh1nRCLXpa6no13ZIioJDz7mdkzHv399pThrTa/k0nUlNaenOeh2kWu/iaOQYElEpKPUswUa9Vg==",
"license": "MIT",
"dependencies": {
"@babel/helper-string-parser": "^7.25.9",
@ -4045,19 +4045,19 @@
}
},
"node_modules/@japa/plugin-adonisjs": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@japa/plugin-adonisjs/-/plugin-adonisjs-3.0.1.tgz",
"integrity": "sha512-xUZOzfBXSz2sWRoQT+qs+6LZBtWWE+cCBZ3j9ckz6+nPw3VI0nV6yLaX+oud3AY8Zb+BH+pErABBhaovZYv9dA==",
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@japa/plugin-adonisjs/-/plugin-adonisjs-3.0.2.tgz",
"integrity": "sha512-yrIif8YYcV4GPXygIm/ndULid/6gIJ/NcylDaAsCw/iKPooU+sgUcZjYWe9AO04xuUJ5nFCvzsM/7q1yP7lxNg==",
"devOptional": true,
"license": "MIT",
"engines": {
"node": ">=18.16.0"
},
"peerDependencies": {
"@adonisjs/core": "^6.5.0",
"@japa/api-client": "^2.0.3",
"@adonisjs/core": "^6.17.0",
"@japa/api-client": "^2.0.3 || ^3.0.0",
"@japa/browser-client": "^2.0.3",
"@japa/runner": "^3.1.2",
"@japa/runner": "^3.1.2 || ^4.0.0",
"playwright": "^1.42.1"
},
"peerDependenciesMeta": {
@ -4839,13 +4839,10 @@
"license": "BSD-3-Clause"
},
"node_modules/@poppinss/validator-lite": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/@poppinss/validator-lite/-/validator-lite-1.0.3.tgz",
"integrity": "sha512-u4dmT7PDHwNtxY3q1jHVp/u+hMEEcBlkzd37QwwM4tVt/0mLlEDttSfPQ+TT7sqPG4VEtWKwVSlMInwPUYyJpA==",
"license": "MIT",
"dependencies": {
"validator": "^13.9.0"
}
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@poppinss/validator-lite/-/validator-lite-2.0.1.tgz",
"integrity": "sha512-jdmx+7RsQL4iHscjEfC9TE6xGYUVug680VqwF8ICYdasxcTHODgQLv6ukCUTNVRFu/Xz70SLPNqXD0dA6MTMVQ==",
"license": "MIT"
},
"node_modules/@redis/bloom": {
"version": "1.2.0",
@ -5217,9 +5214,9 @@
}
},
"node_modules/@swc/core": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core/-/core-1.10.6.tgz",
"integrity": "sha512-zgXXsI6SAVwr6XsXyMnqlyLoa1lT+r09bAWI1xT3679ejWqI1Vnl14eJG0GjWYXCEMKHCNytfMq3OOQ62C39QQ==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core/-/core-1.10.7.tgz",
"integrity": "sha512-py91kjI1jV5D5W/Q+PurBdGsdU5TFbrzamP7zSCqLdMcHkKi3rQEM5jkQcZr0MXXSJTaayLxS3MWYTBIkzPDrg==",
"dev": true,
"hasInstallScript": true,
"license": "Apache-2.0",
@ -5235,16 +5232,16 @@
"url": "https://opencollective.com/swc"
},
"optionalDependencies": {
"@swc/core-darwin-arm64": "1.10.6",
"@swc/core-darwin-x64": "1.10.6",
"@swc/core-linux-arm-gnueabihf": "1.10.6",
"@swc/core-linux-arm64-gnu": "1.10.6",
"@swc/core-linux-arm64-musl": "1.10.6",
"@swc/core-linux-x64-gnu": "1.10.6",
"@swc/core-linux-x64-musl": "1.10.6",
"@swc/core-win32-arm64-msvc": "1.10.6",
"@swc/core-win32-ia32-msvc": "1.10.6",
"@swc/core-win32-x64-msvc": "1.10.6"
"@swc/core-darwin-arm64": "1.10.7",
"@swc/core-darwin-x64": "1.10.7",
"@swc/core-linux-arm-gnueabihf": "1.10.7",
"@swc/core-linux-arm64-gnu": "1.10.7",
"@swc/core-linux-arm64-musl": "1.10.7",
"@swc/core-linux-x64-gnu": "1.10.7",
"@swc/core-linux-x64-musl": "1.10.7",
"@swc/core-win32-arm64-msvc": "1.10.7",
"@swc/core-win32-ia32-msvc": "1.10.7",
"@swc/core-win32-x64-msvc": "1.10.7"
},
"peerDependencies": {
"@swc/helpers": "*"
@ -5256,9 +5253,9 @@
}
},
"node_modules/@swc/core-darwin-arm64": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.10.6.tgz",
"integrity": "sha512-USbMvT8Rw5PvIfF6HyTm+yW84J9c45emzmHBDIWY76vZHkFsS5MepNi+JLQyBzBBgE7ScwBRBNhRx6VNhkSoww==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.10.7.tgz",
"integrity": "sha512-SI0OFg987P6hcyT0Dbng3YRISPS9uhLX1dzW4qRrfqQdb0i75lPJ2YWe9CN47HBazrIA5COuTzrD2Dc0TcVsSQ==",
"cpu": [
"arm64"
],
@ -5273,9 +5270,9 @@
}
},
"node_modules/@swc/core-darwin-x64": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.10.6.tgz",
"integrity": "sha512-7t2IozcZN4r1p27ei+Kb8IjN4aLoBDn107fPi+aPLcVp2uFgJEUzhCDuZXBNW2057Mx1OHcjzrkaleRpECz3Xg==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.10.7.tgz",
"integrity": "sha512-RFIAmWVicD/l3RzxgHW0R/G1ya/6nyMspE2cAeDcTbjHi0I5qgdhBWd6ieXOaqwEwiCd0Mot1g2VZrLGoBLsjQ==",
"cpu": [
"x64"
],
@ -5290,9 +5287,9 @@
}
},
"node_modules/@swc/core-linux-arm-gnueabihf": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.10.6.tgz",
"integrity": "sha512-CPgWT+D0bDp/qhXsLkIJ54LmKU1/zvyGaf/yz8A4iR+YoF6R5CSXENXhNJY8cIrb6+uNWJZzHJ+gefB5V51bpA==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.10.7.tgz",
"integrity": "sha512-QP8vz7yELWfop5mM5foN6KkLylVO7ZUgWSF2cA0owwIaziactB2hCPZY5QU690coJouk9KmdFsPWDnaCFUP8tg==",
"cpu": [
"arm"
],
@ -5307,9 +5304,9 @@
}
},
"node_modules/@swc/core-linux-arm64-gnu": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.10.6.tgz",
"integrity": "sha512-5qZ6hVnqO/ShETXdGSzvdGUVx372qydlj1YWSYiaxQzTAepEBc8TC1NVUgYtOHOKVRkky1d7p6GQ9lymsd4bHw==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.10.7.tgz",
"integrity": "sha512-NgUDBGQcOeLNR+EOpmUvSDIP/F7i/OVOKxst4wOvT5FTxhnkWrW+StJGKj+DcUVSK5eWOYboSXr1y+Hlywwokw==",
"cpu": [
"arm64"
],
@ -5324,9 +5321,9 @@
}
},
"node_modules/@swc/core-linux-arm64-musl": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.10.6.tgz",
"integrity": "sha512-hB2xZFmXCKf2iJF5y2z01PSuLqEoUP3jIX/XlIHN+/AIP7PkSKsValE63LnjlnWPnSEI0IxUyRE3T3FzWE/fQQ==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.10.7.tgz",
"integrity": "sha512-gp5Un3EbeSThBIh6oac5ZArV/CsSmTKj5jNuuUAuEsML3VF9vqPO+25VuxCvsRf/z3py+xOWRaN2HY/rjMeZog==",
"cpu": [
"arm64"
],
@ -5341,9 +5338,9 @@
}
},
"node_modules/@swc/core-linux-x64-gnu": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.10.6.tgz",
"integrity": "sha512-PRGPp0I22+oJ8RMGg8M4hXYxEffH3ayu0WoSDPOjfol1F51Wj1tfTWN4wVa2RibzJjkBwMOT0KGLGb/hSEDDXQ==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.10.7.tgz",
"integrity": "sha512-k/OxLLMl/edYqbZyUNg6/bqEHTXJT15l9WGqsl/2QaIGwWGvles8YjruQYQ9d4h/thSXLT9gd8bExU2D0N+bUA==",
"cpu": [
"x64"
],
@ -5358,9 +5355,9 @@
}
},
"node_modules/@swc/core-linux-x64-musl": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.10.6.tgz",
"integrity": "sha512-SoNBxlA86lnoV9vIz/TCyakLkdRhFSHx6tFMKNH8wAhz1kKYbZfDmpYoIzeQqdTh0tpx8e/Zu1zdK4smovsZqQ==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.10.7.tgz",
"integrity": "sha512-XeDoURdWt/ybYmXLCEE8aSiTOzEn0o3Dx5l9hgt0IZEmTts7HgHHVeRgzGXbR4yDo0MfRuX5nE1dYpTmCz0uyA==",
"cpu": [
"x64"
],
@ -5375,9 +5372,9 @@
}
},
"node_modules/@swc/core-win32-arm64-msvc": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.10.6.tgz",
"integrity": "sha512-6L5Y2E+FVvM+BtoA+mJFjf/SjpFr73w2kHBxINxwH8/PkjAjkePDr5m0ibQhPXV61bTwX49+1otzTY85EsUW9Q==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.10.7.tgz",
"integrity": "sha512-nYAbi/uLS+CU0wFtBx8TquJw2uIMKBnl04LBmiVoFrsIhqSl+0MklaA9FVMGA35NcxSJfcm92Prl2W2LfSnTqQ==",
"cpu": [
"arm64"
],
@ -5392,9 +5389,9 @@
}
},
"node_modules/@swc/core-win32-ia32-msvc": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.10.6.tgz",
"integrity": "sha512-kxK3tW8DJwEkAkwy0vhwoBAShRebH1QTe0mvH9tlBQ21rToVZQn+GCV/I44dind80hYPw0Tw2JKFVfoEJyBszg==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.10.7.tgz",
"integrity": "sha512-+aGAbsDsIxeLxw0IzyQLtvtAcI1ctlXVvVcXZMNXIXtTURM876yNrufRo4ngoXB3jnb1MLjIIjgXfFs/eZTUSw==",
"cpu": [
"ia32"
],
@ -5409,9 +5406,9 @@
}
},
"node_modules/@swc/core-win32-x64-msvc": {
"version": "1.10.6",
"resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.10.6.tgz",
"integrity": "sha512-4pJka/+t8XcHee12G/R5VWcilkp5poT2EJhrybpuREkpQ7iC/4WOlOVrohbWQ4AhDQmojYQI/iS+gdF2JFLzTQ==",
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.10.7.tgz",
"integrity": "sha512-TBf4clpDBjF/UUnkKrT0/th76/zwvudk5wwobiTFqDywMApHip5O0VpBgZ+4raY2TM8k5+ujoy7bfHb22zu17Q==",
"cpu": [
"x64"
],
@ -7842,9 +7839,9 @@
}
},
"node_modules/browserslist": {
"version": "4.24.3",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.3.tgz",
"integrity": "sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA==",
"version": "4.24.4",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.4.tgz",
"integrity": "sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A==",
"dev": true,
"funding": [
{
@ -8079,9 +8076,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001690",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz",
"integrity": "sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==",
"version": "1.0.30001692",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001692.tgz",
"integrity": "sha512-A95VKan0kdtrsnMubMKxEKUKImOPSuCpYgxSQBo036P5YYgVIcOYJEgt/txJWqObiRQeISNCfef9nvlQ0vbV7A==",
"dev": true,
"funding": [
{
@ -10015,9 +10012,9 @@
"license": "MIT"
},
"node_modules/electron-to-chromium": {
"version": "1.5.79",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.79.tgz",
"integrity": "sha512-nYOxJNxQ9Om4EC88BE4pPoNI8xwSFf8pU/BAeOl4Hh/b/i6V4biTAzwV7pXi3ARKeoYO5JZKMIXTryXSVer5RA==",
"version": "1.5.80",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.80.tgz",
"integrity": "sha512-LTrKpW0AqIuHwmlVNV+cjFYTnXtM9K37OGhpe0ZI10ScPSxqVSryZHIY3WnCS5NSYbBODRTZyhRMS2h5FAEqAw==",
"dev": true,
"license": "ISC"
},
@ -11313,9 +11310,9 @@
}
},
"node_modules/focus-trap": {
"version": "7.6.2",
"resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.6.2.tgz",
"integrity": "sha512-9FhUxK1hVju2+AiQIDJ5Dd//9R2n2RAfJ0qfhF4IHGHgcoEUTMpbTeG/zbEuwaiYXfuAH6XE0/aCyxDdRM+W5w==",
"version": "7.6.4",
"resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.6.4.tgz",
"integrity": "sha512-xx560wGBk7seZ6y933idtjJQc1l+ck+pI3sKvhKozdBV1dRZoKhkW5xoCaFv9tQiX5RH1xfSxjuNu6g+lmN/gw==",
"license": "MIT",
"dependencies": {
"tabbable": "^6.2.0"
@ -12214,9 +12211,9 @@
}
},
"node_modules/http-parser-js": {
"version": "0.5.8",
"resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.8.tgz",
"integrity": "sha512-SGeBX54F94Wgu5RH3X5jsDtf4eHyRogWX1XGT3b4HuW3tQPM4AaBzoUji/4AAJNXCEOWZ5O0DgZmJw1947gD5Q==",
"version": "0.5.9",
"resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.9.tgz",
"integrity": "sha512-n1XsPy3rXVxlqxVioEWdC+0+M+SQw0DpJynwtOPo1X+ZlvdzTLtDBIJJlDQTnwZIFJrZSzSGmIOUdP8tu+SgLw==",
"dev": true,
"license": "MIT"
},
@ -13772,9 +13769,9 @@
"license": "MIT"
},
"node_modules/json11": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/json11/-/json11-2.0.0.tgz",
"integrity": "sha512-VuKJKUSPEJape+daTm70Nx7vdcdorf4S6LCyN2z0jUVH4UrQ4ftXo2kC0bnHpCREmxHuHqCNVPA75BjI3CB6Ag==",
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/json11/-/json11-2.0.2.tgz",
"integrity": "sha512-HIrd50UPYmP6sqLuLbFVm75g16o0oZrVfxrsY0EEys22klz8mRoWlX9KAEDOSOR9Q34rcxsyC8oDveGrCz5uLQ==",
"license": "MIT",
"bin": {
"json11": "dist/cli.mjs"
@ -16930,13 +16927,13 @@
}
},
"node_modules/readdirp": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.0.2.tgz",
"integrity": "sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==",
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.1.tgz",
"integrity": "sha512-h80JrZu/MHUZCyHu5ciuoI0+WxsCxzxJTILn6Fs8rxSnFPh+UVHYfeIxK1nVGugMqkfC4vJcBOYbkfkwYK0+gw==",
"devOptional": true,
"license": "MIT",
"engines": {
"node": ">= 14.16.0"
"node": ">= 14.18.0"
},
"funding": {
"type": "individual",
@ -19339,9 +19336,9 @@
"license": "Apache-2.0"
},
"node_modules/ts-loader": {
"version": "9.5.1",
"resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-9.5.1.tgz",
"integrity": "sha512-rNH3sK9kGZcH9dYzC7CewQm4NtxJTjSEVRJ2DyBZR7f8/wcta+iV44UPCXc5+nzDzivKtlzV6c9P4e+oFhDLYg==",
"version": "9.5.2",
"resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-9.5.2.tgz",
"integrity": "sha512-Qo4piXvOTWcMGIgRiuFa6nHNm+54HbYaZCKqc9eeZCLRy3XqafQgwX2F7mofrbJG3g7EEb+lkiR+z2Lic2s3Zw==",
"dev": true,
"license": "MIT",
"dependencies": {
@ -19549,9 +19546,9 @@
}
},
"node_modules/type-fest": {
"version": "4.31.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.31.0.tgz",
"integrity": "sha512-yCxltHW07Nkhv/1F6wWBr8kz+5BGMfP+RbRSYFnegVb0qV/UMT0G0ElBloPVerqn4M2ZV80Ir1FtCcYv1cT6vQ==",
"version": "4.32.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.32.0.tgz",
"integrity": "sha512-rfgpoi08xagF3JSdtJlCwMq9DGNDE0IMh3Mkpc1wUypg9vPi786AiqeBBKcqvIkq42azsBM85N490fyZjeUftw==",
"license": "(MIT OR CC0-1.0)",
"engines": {
"node": ">=16"
@ -19675,9 +19672,9 @@
}
},
"node_modules/typescript": {
"version": "5.7.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz",
"integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==",
"version": "5.7.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
"integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
"devOptional": true,
"license": "Apache-2.0",
"bin": {
@ -19813,9 +19810,9 @@
}
},
"node_modules/update-browserslist-db": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz",
"integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==",
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.2.tgz",
"integrity": "sha512-PPypAm5qvlD7XMZC3BujecnaOxwhrtoFR+Dqkk5Aa/6DssiH0ibKoketaj9w8LP7Bont1rYeoV5plxD7RTEPRg==",
"dev": true,
"funding": [
{
@ -19834,7 +19831,7 @@
"license": "MIT",
"dependencies": {
"escalade": "^3.2.0",
"picocolors": "^1.1.0"
"picocolors": "^1.1.1"
},
"bin": {
"update-browserslist-db": "cli.js"
@ -20353,9 +20350,9 @@
}
},
"node_modules/webpack-dev-middleware/node_modules/memfs": {
"version": "4.15.3",
"resolved": "https://registry.npmjs.org/memfs/-/memfs-4.15.3.tgz",
"integrity": "sha512-vR/g1SgqvKJgAyYla+06G4p/EOcEmwhYuVb1yc1ixcKf8o/sh7Zngv63957ZSNd1xrZJoinmNyDf2LzuP8WJXw==",
"version": "4.17.0",
"resolved": "https://registry.npmjs.org/memfs/-/memfs-4.17.0.tgz",
"integrity": "sha512-4eirfZ7thblFmqFjywlTmuWVSvccHAJbn1r8qQLzmTO11qcqpohOjmY2mFce6x7x7WtskzRqApPD0hv+Oa74jg==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {

View file

@ -63,6 +63,15 @@ export default class QueryBuilderProvider {
public register() {
// Register your own bindings
// const ModelQueryBuilder = this.app.container.bind('@adonisjs/lucid/orm/ModelQueryBuilder');
// ModelQueryBuilder.macro('whereTrue', function (columnName: string) {
// return this.where(columnName, true);
// });
// ModelQueryBuilder.macro('whereFalse', function (columnName: string) {
// return this.where(columnName, false);
// });
}
public async boot() {
@ -73,15 +82,14 @@ export default class QueryBuilderProvider {
// let rolesPluck = {};
let rolesPluck: { [key: number]: any } = {};
const result = await this.exec();
result.forEach((user, index) => {
let idc;
result.forEach((user: { [key: string]: any }, index: number) => {
let idc: number;
if (!id) {
idc = index;
} else {
idc = user[id];
}
const value = user[valueColumn];
// rolesPluck[idc] = user.name;
const value: any = user[valueColumn];
rolesPluck[idc] = value;
});
return rolesPluck;

View file

@ -98,6 +98,5 @@
"assets/images/marker-icon.png": "http://localhost:8080/assets/images/marker-icon.2b3e1faf.png",
"assets/images/layers-2x.png": "http://localhost:8080/assets/images/layers-2x.8f2c4d11.png",
"assets/images/layers.png": "http://localhost:8080/assets/images/layers.416d9136.png",
"assets/images/Close.svg": "http://localhost:8080/assets/images/Close.e4887675.svg",
"assets/vendors-node_modules_vue-facing-decorator_dist_esm_index_js-node_modules_vue-facing-decorator-818045.js": "http://localhost:8080/assets/vendors-node_modules_vue-facing-decorator_dist_esm_index_js-node_modules_vue-facing-decorator-818045.js"
"assets/images/Close.svg": "http://localhost:8080/assets/images/Close.e4887675.svg"
}

View file

@ -0,0 +1,114 @@
import { FieldContext } from '@vinejs/vine/types';
import vine from '@vinejs/vine';
import { VineString } from '@vinejs/vine';
import axios, { AxiosInstance } from 'axios';
import { ReferenceIdentifierTypes } from '#contracts/enums';
type Options = {
typeField: string;
};
// Function to check if DOI exists using the DOI API
async function checkDoiExists(doi: string): Promise<boolean> {
try {
const response = await axios.get(`${doi}`);
return response.status === 200; // If status is 200, DOI is valid
} catch (error) {
return false; // If request fails, DOI does not exist
}
}
// Function to check if ISBN exists using the Open Library API
async function checkIsbnExists(isbn: string): Promise<boolean> {
try {
const response = await axios.get(`https://isbnsearch.org/isbn/${isbn}`);
return response.data && response.status == 200; // If title is returned, ISBN is valid
} catch (error) {
return false; // If request fails, ISBN does not exist
}
}
async function validateReference(value: unknown, options: Options, field: FieldContext) {
if (typeof value !== 'string') {
return;
}
const type = field.parent[options.typeField];
if (type === ReferenceIdentifierTypes.URL) {
if (!/^https?:\/\/[^\s$.?#].[^\s]*$/.test(value)) {
field.report('The {{ field }} must be a valid URL', 'validateReference', field);
} else {
try {
const exists = await checkDoiExists(value);
if (!exists) {
field.report('The {{ field }} must be an existing DOI', 'validateReference', field);
}
} catch (error) {
field.report('Error checking DOI existence: ' + error.message, 'validateReference', field);
}
}
}
// Check if the value does not match the DOI pattern
// The regex pattern ^10.\d{4,9}\/[-._;()/:a-zA-Z0-9]+$ is designed to match valid DOI formats.
// - ^10. ensures that the string starts with "10."
// - \d{4,9} matches a sequence of 4 to 9 digits.
// - \/ matches the literal forward slash character.
// - [-._;()/:a-zA-Z0-9]+ matches one or more characters that can include uppercase and lowercase letters, digits, and a set of special characters.
// The i flag at the end of the regex makes the matching case-insensitive, meaning it will match both uppercase and lowercase letters.
// If the value does not match this pattern, the code inside the if block will execute.
else if (type === ReferenceIdentifierTypes.DOI) {
// Extract the DOI from the URL if it starts with 'https://doi.org/'
const doiPattern = /^https:\/\/doi\.org\/(10.\d{4,9}\/[-._;()/:a-zA-Z0-9]+)$/i;
const match = value.match(doiPattern);
const doi = match ? match[1] : value;
// Check if the extracted DOI or the value itself matches the DOI patter
if (!/^10.\d{4,9}\/[-._;()/:a-zA-Z0-9]+$/i.test(doi)) {
field.report('The {{ field }} must be a valid DOI', 'validateReference', field);
} else {
try {
const exists = await checkDoiExists(value);
if (!exists) {
field.report('The {{ field }} must be an existing DOI', 'validateReference', field);
}
} catch (error) {
field.report('Error checking DOI existence: ' + error.message, 'validateReference', field);
}
}
} else if (type === ReferenceIdentifierTypes.ISBN) {
if (!/^(?=(?:[^0-9]*[0-9]){10}(?:(?:[^0-9]*[0-9]){3})?$)[\d-]+$/.test(value)) {
field.report('The {{ field }} must be a valid ISBN', 'validateReference', field);
} else {
try {
const exists = await checkIsbnExists(value);
if (!exists) {
field.report('The {{ field }} must be an existing ISBN', 'validateReference', field);
}
} catch (error) {
field.report('Error checking ISBN existence: ' + error.message, 'validateReference', field);
}
}
} else if (type === ReferenceIdentifierTypes.Handle && !/^\d{2,}.\d{4,9}\/[-._;()/:a-zA-Z0-9]+$/.test(value)) {
/// Extract the Handle from the URL if it contains '/handle/'
field.report('The {{ field }} must be a valid Handle', 'validateReference', field);
} else if (
type === ReferenceIdentifierTypes.URN &&
!/^urn:[a-zA-Z0-9][a-zA-Z0-9-]{0,31}:[a-zA-Z0-9()+,\-.:=@;$_!*'%/?#]+$/.test(value)
) {
field.report('The {{ field }} must be a valid URN', 'validateReference', field);
} else if (type === ReferenceIdentifierTypes.ISSN && !/^\d{4}-\d{3}[\dxX]$/.test(value)) {
field.report('The {{ field }} must be a valid ISSN', 'validateReference', field);
}
}
export const validateReferenceRule = vine.createRule(validateReference);
declare module '@vinejs/vine' {
interface VineString {
validateReference(options: Options): this;
}
}
VineString.macro('validateReference', function (this: VineString, options: Options) {
return this.use(validateReferenceRule(options));
});

View file

@ -15,7 +15,7 @@ import { assert } from '@japa/assert';
import { apiClient } from '@japa/api-client';
import { pluginAdonisJS } from '@japa/plugin-adonisjs';
import app from '@adonisjs/core/services/app';
import env from '#start/env'
/*
|--------------------------------------------------------------------------
| Japa Plugins
@ -28,7 +28,13 @@ import app from '@adonisjs/core/services/app';
|
*/
// export const plugins: Required<Config>['plugins'] = [assert(), runFailedTests(), apiClient()];
export const plugins: Config['plugins'] = [assert(), apiClient(), pluginAdonisJS(app)];
export const plugins: Config['plugins'] = [
assert(),
apiClient({
baseURL: `http://${env.get('HOST')}:${env.get('PORT')}`,
}),
pluginAdonisJS(app),
];
/*
|--------------------------------------------------------------------------
@ -59,11 +65,18 @@ export const reporters: Required<Config>['reporters'] = {
*/
export const runnerHooks: Pick<Required<Config>, 'setup' | 'teardown'> = {
setup: [
() => {
console.log('running before all the tests');
},
// () => testUtils.ace().loadCommands(),
() => testUtils.db().migrate(),
// () => testUtils.httpServer().start(),
],
teardown: [],
teardown: [
() => {
console.log('running after all the tests');
},
],
};
/*

View file

@ -0,0 +1,215 @@
import { test } from '@japa/runner';
import { ReferenceIdentifierTypes } from '#contracts/enums';
import vine from '@vinejs/vine';
// node ace test functional --groups "ReferenceValidation"
test.group('ReferenceValidation', () => {
test('validate valid DOI', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
}),
);
const data = {
reference: 'https://doi.org/10.24341/tethys.236',
type: ReferenceIdentifierTypes.DOI,
};
try {
const payload = await validator.validate(data);
assert.deepEqual(payload, data);
} catch {
assert.isTrue(false);
}
});
test('validate invalid DOI', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
}),
);
const data = {
reference: 'https://doi.org/invalid-doi',
type: ReferenceIdentifierTypes.DOI,
};
let payload = {};
try {
payload = await validator.validate(data);
} catch {
assert.notDeepEqual(payload, data);
}
});
test('validate valid Handle', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: '20.5000/abc123',
type: ReferenceIdentifierTypes.Handle,
};
try {
const payload = await validator.validate(data);
assert.deepEqual(payload, data);
} catch {
assert.isTrue(false);
}
});
test('validate valid ISBN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
// reference: '978-3-85316-090-9',
// reference: '9783853160909',
// reference: '978-3-900312-64-0', // Geologische Karte der Republik Österreich 1 : 50.000
reference: '3900312648', // Geologische Karte der Republik Österreich 1 : 50.000
type: ReferenceIdentifierTypes.ISBN,
};
try {
const payload = await validator.validate(data);
assert.deepEqual(payload, data);
} catch {
assert.isTrue(false);
}
});
test('validate invalid ISBN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: 'invalid-isbn',
type: ReferenceIdentifierTypes.ISBN,
};
let payload = {};
try {
payload = await validator.validate(data);
} catch {
assert.notDeepEqual(payload, data);
}
});
test('validate valid URN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: 'urn:isbn:0451450523',
type: ReferenceIdentifierTypes.URN,
};
try {
const payload = await validator.validate(data);
assert.deepEqual(payload, data);
} catch {
assert.isTrue(false);
}
});
test('validate invalid URN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: 'invalid-urn',
type: ReferenceIdentifierTypes.URN,
};
let payload = {};
try {
payload = await validator.validate(data);
} catch {
assert.notDeepEqual(payload, data);
}
});
test('validate valid ISSN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: '1234-567X',
type: ReferenceIdentifierTypes.ISSN,
};
try {
const payload = await validator.validate(data);
assert.deepEqual(payload, data);
} catch {
assert.isTrue(false);
}
});
test('validate invalid ISSN', async ({ assert }) => {
const validator = vine.compile(
vine.object({
reference: vine.string().validateReference({ typeField: 'type' }),
type: vine.enum(Object.values(ReferenceIdentifierTypes)),
})
);
const data = {
reference: 'invalid-issn',
type: ReferenceIdentifierTypes.ISSN,
};
let payload = {};
try {
payload = await validator.validate(data);
} catch {
assert.notDeepEqual(payload, data);
}
});
// test('validate invalid Handle', async ({ assert }) => {
// const validator = vine.compile(
// vine.object({
// reference: vine.string().validateReference({ typeField: 'type' }),
// type: vine.enum(Object.values(ReferenceIdentifierTypes)),
// })
// );
// const data = {
// reference: 'invalid-handle',
// type: ReferenceIdentifierTypes.Handle,
// };
// const result = await validator.validate(data);
// assert.isFalse(result.valid);
// });
// Add more tests for other reference types as needed
});