Skip to content

Commit

Permalink
yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Feb 7, 2024
1 parent e8ddd24 commit 31b8c75
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
extends: [
"eslint:recommended",
"plugin:vue/vue3-recommended",
"prettier",
"@vue/eslint-config-typescript",
"prettier",
],
};
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
38 changes: 17 additions & 21 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class MinkApi {
/** Sets a JWT token which is then used to authenticate API requests. */
setJwt(jwt?: string) {
this.jwt = jwt;
this.axios.defaults.headers["Authorization"] = jwt
? `Bearer ${jwt}`
: null;
this.axios.defaults.headers["Authorization"] = jwt ? `Bearer ${jwt}` : null;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Documentation/operation/APIinfo */
Expand All @@ -45,17 +43,15 @@ class MinkApi {

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Corpora/operation/listcorpora */
async listCorpora() {
const response = await this.axios.get<MinkResponse<ListCorporaData>>(
"list-corpora"
);
const response =
await this.axios.get<MinkResponse<ListCorporaData>>("list-corpora");
return response.data.corpora;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Manage-Corpora/operation/createcorpus */
async createCorpus() {
const response = await this.axios.post<MinkResponse<CreateCorpusData>>(
"create-corpus"
);
const response =
await this.axios.post<MinkResponse<CreateCorpusData>>("create-corpus");
return response.data.corpus_id;
}

Expand All @@ -75,7 +71,7 @@ class MinkApi {
const response = await this.axios.put<MinkResponse>(
"upload-config",
formData,
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data;
}
Expand Down Expand Up @@ -104,7 +100,7 @@ class MinkApi {
const response = await this.axios.put<MinkResponse>(
"upload-sources",
formData,
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data;
}
Expand All @@ -127,17 +123,16 @@ class MinkApi {

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Process-Corpus/operation/resourceinfo */
async resourceInfoAll() {
const response = await this.axios.get<MinkResponse<ResourceInfoAllData>>(
"resource-info"
);
const response =
await this.axios.get<MinkResponse<ResourceInfoAllData>>("resource-info");
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Process-Corpus/operation/resourceinfo */
async resourceInfoOne(corpusId: string) {
const response = await this.axios.get<MinkResponse<ResourceInfoOneData>>(
"resource-info",
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data;
}
Expand Down Expand Up @@ -167,7 +162,7 @@ class MinkApi {
async listExports(corpusId: string) {
const response = await this.axios.get<MinkResponse<ListExportsData>>(
"list-exports",
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data.contents;
}
Expand Down Expand Up @@ -195,7 +190,7 @@ class MinkApi {
const response = await this.axios.put<MinkResponse<ResourceInfoOneData>>(
"install-korp",
null,
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data;
}
Expand All @@ -205,16 +200,17 @@ class MinkApi {
const response = await this.axios.put<MinkResponse<ResourceInfoOneData>>(
"install-strix",
null,
{ params: { corpus_id: corpusId } }
{ params: { corpus_id: corpusId } },
);
return response.data;
}

/** @see https://ws.spraakbanken.gu.se/ws/mink/api-doc#tag/Admin-Mode/operation/adminmodestatus */
async adminModeStatus() {
const response = await this.axios.get<MinkResponse<AdminModeStatusData>>(
"admin-mode-status"
);
const response =
await this.axios.get<MinkResponse<AdminModeStatusData>>(
"admin-mode-status",
);
return response.data.admin_mode_status;
}

Expand Down
26 changes: 13 additions & 13 deletions src/api/backend.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,49 @@ export default function useMinkBackend() {
spin(
api.removeCorpus(corpusId),
t("corpus.deleting"),
`corpus/${corpusId}`
`corpus/${corpusId}`,
);

const loadConfig = (corpusId: string) =>
spin(
api.downloadConfig(corpusId),
t("config.loading"),
`corpus/${corpusId}/config`
`corpus/${corpusId}/config`,
);

const saveConfig = (corpusId: string, configYaml: string) =>
spin(
api.uploadConfig(corpusId, configYaml),
t("corpus.configuring"),
`corpus/${corpusId}/config`
`corpus/${corpusId}/config`,
);

const downloadSource = (corpusId: string, filename: string, binary = false) =>
spin(
api.downloadSources(corpusId, filename, binary),
t("source.downloading"),
`corpus/${corpusId}/sources/${filename}`
`corpus/${corpusId}/sources/${filename}`,
);

const downloadPlaintext = (corpusId: string, filename: string) =>
spin(
api.downloadSourceText(corpusId, filename),
t("source.downloading_plain"),
`corpus/${corpusId}/sources/${filename}`
`corpus/${corpusId}/sources/${filename}`,
);

const uploadSources = (corpusId: string, files: FileList) =>
spin(
api.uploadSources(corpusId, files),
t("source.uploading", files.length),
`corpus/${corpusId}/sources`
`corpus/${corpusId}/sources`,
);

const deleteSource = (corpusId: string, filename: string) =>
spin(
api.removeSource(corpusId, filename),
t("source.deleting"),
`corpus/${corpusId}/sources`
`corpus/${corpusId}/sources`,
);

const resourceInfoAll = () =>
Expand All @@ -69,7 +69,7 @@ export default function useMinkBackend() {
spin(
api.resourceInfoOne(corpusId),
t("resource.loading"),
`corpus/${corpusId}/job`
`corpus/${corpusId}/job`,
);

const runJob = (corpusId: string) =>
Expand All @@ -79,14 +79,14 @@ export default function useMinkBackend() {
spin(
api.installKorp(corpusId),
t("job.installing"),
`corpus/${corpusId}/job`
`corpus/${corpusId}/job`,
);

const installStrix = (corpusId: string) =>
spin(
api.installStrix(corpusId),
t("job.installing"),
`corpus/${corpusId}/job`
`corpus/${corpusId}/job`,
);

const abortJob = (corpusId: string) =>
Expand All @@ -96,21 +96,21 @@ export default function useMinkBackend() {
spin(
api.listExports(corpusId),
t("exports.loading"),
`corpus/${corpusId}/exports`
`corpus/${corpusId}/exports`,
);

const downloadExports = (corpusId: string) =>
spin(
api.downloadExports(corpusId),
t("exports.downloading"),
`corpus/${corpusId}/exports`
`corpus/${corpusId}/exports`,
);

const downloadExportFiles = (corpusId: string, filename: string) =>
spin(
api.downloadExportFile(corpusId, filename),
t("exports.downloading"),
`corpus/${corpusId}/exports`
`corpus/${corpusId}/exports`,
);

const checkAdminMode = () => spin(api.adminModeStatus(), null, "admin-mode");
Expand Down
6 changes: 3 additions & 3 deletions src/api/backendInfo.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ api.getInfo().then((original: InfoData) => {
const status_codes = objsToDict(
original.status_codes.data,
"name",
"description"
"description",
);
const importer_modules = objsToDict(
original.importer_modules.data,
"file_extension",
"importer"
"importer",
);
const file_size_limits = keyBy(original.file_size_limits.data, "name");
const recommended_file_size = keyBy(
original.recommended_file_size.data,
"name"
"name",
);
info.value = {
status_codes,
Expand Down
32 changes: 18 additions & 14 deletions src/api/corpusConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function makeConfig(id: string, options: ConfigOptions) {
"<text>:dateformat.datefrom",
"<text>:dateformat.dateto",
"<text>:dateformat.timefrom",
"<text>:dateformat.timeto"
"<text>:dateformat.timeto",
);
}

Expand All @@ -143,7 +143,7 @@ export async function makeConfig(id: string, options: ConfigOptions) {
"swener.ne:swener.name",
"swener.ne:swener.ex",
"swener.ne:swener.type",
"swener.ne:swener.subtype"
"swener.ne:swener.subtype",
);
}

Expand All @@ -160,23 +160,27 @@ export function emptyConfig(): ConfigOptions {

/**
* Parse a Sparv config YAML string.
*
*
* May throw all kinds of errors, the sky is the limit.
*/
export async function parseConfig(configYaml: string): Promise<ConfigOptions> {
const config = (await yaml).load(configYaml) as any

if (!config) throw new TypeError(`Parsing config failed, returned "${config}"`)
const config = (await yaml).load(configYaml) as any;

if (!config)
throw new TypeError(`Parsing config failed, returned "${config}"`);

// Throw specific errors if required parts are missing.
const format = (Object.keys(FORMATS) as FileFormat[]).find(
(ext) => FORMATS[ext as FileFormat] == config.import.importer
)
if (!format) throw new TypeError(`Unrecognized importer: "${config.import.importer}"`)
(ext) => FORMATS[ext as FileFormat] == config.import.importer,
);
if (!format)
throw new TypeError(`Unrecognized importer: "${config.import.importer}"`);

const name = config.metadata.name
if (!name) throw new TypeError(`Name missing in metadata: ${config.metadata}`)
if (!name.swe || !name.eng) throw new TypeError(`Name must contain swe and eng: ${name}`)
const name = config.metadata.name;
if (!name)
throw new TypeError(`Name missing in metadata: ${config.metadata}`);
if (!name.swe || !name.eng)
throw new TypeError(`Name must contain swe and eng: ${name}`);

return {
format,
Expand All @@ -185,10 +189,10 @@ export async function parseConfig(configYaml: string): Promise<ConfigOptions> {
textAnnotation: config.import?.text_annotation,
sentenceSegmenter: config.segment?.sentence_segmenter,
datetimeFrom: config.custom_annotations?.find(
(a: any) => a.params.out == "<text>:misc.datefrom"
(a: any) => a.params.out == "<text>:misc.datefrom",
)?.params.value,
datetimeTo: config.custom_annotations?.find(
(a: any) => a.params.out == "<text>:misc.dateto"
(a: any) => a.params.out == "<text>:misc.dateto",
)?.params.value,
enableNer: config.export?.annotations?.includes("swener.ne"),
};
Expand Down
4 changes: 2 additions & 2 deletions src/auth/auth.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export function useAuth() {

const isAuthenticated = computed<boolean>(() => !!jwt.value);
const payload = computed<JwtSbPayload | undefined>(() =>
jwt.value ? decodeJwt(jwt.value)?.payload : undefined
jwt.value ? decodeJwt(jwt.value)?.payload : undefined,
);
const canUserAdmin = computed<boolean>(
() => !!payload.value && canAdmin(payload.value, "other", "mink-app")
() => !!payload.value && canAdmin(payload.value, "other", "mink-app"),
);
const canUserWrite = computed(() => isAuthenticated.value);
/** Indicates whether a jwt request is currently loading. */
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function getLoginUrl(redirectLocation = "") {
redirectLocation = pathJoin(
window.location.origin,
import.meta.env.BASE_URL,
redirectLocation
redirectLocation,
);
return AUTH_BASE + `login?redirect=${redirectLocation}`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/auth/jwtSb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function assertValidPayload(payload: any): payload is JwtSbPayload {
export function canAdmin(
payload: JwtSbPayload,
resourceType: string,
resourceName: string
resourceName: string,
) {
assertValidPayload(payload);
return payload.scope[resourceType]?.[resourceName] >= payload.levels.ADMIN;
Expand All @@ -63,7 +63,7 @@ export function canAdmin(
export function canWrite(
payload: JwtSbPayload,
resourceType: string,
resourceName: string
resourceName: string,
) {
assertValidPayload(payload);
return payload.scope[resourceType]?.[resourceName] >= payload.levels.WRITE;
Expand All @@ -72,7 +72,7 @@ export function canWrite(
export function canRead(
payload: JwtSbPayload,
resourceType: string,
resourceName: string
resourceName: string,
) {
assertValidPayload(payload);
return payload.scope[resourceType]?.[resourceName] >= payload.levels.READ;
Expand Down
6 changes: 3 additions & 3 deletions src/corpora/CreateCorpus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const formatOptions = computed(() =>
...options,
[ext]: `${t(ext)} (.${ext})`,
}),
{}
)
{},
),
);
requireAuthentication();
Expand All @@ -39,7 +39,7 @@ async function submit(fields: Form) {
fields.name,
fields.description,
fields.format,
fields.textAnnotation
fields.textAnnotation,
);
await spin(createPromise, null, "create");
}
Expand Down
Loading

0 comments on commit 31b8c75

Please sign in to comment.