Add types for backend response

This commit is contained in:
Ferdinand Thiessen 2021-11-26 23:04:15 +01:00
parent a21475a0d4
commit 471fb486d5
5 changed files with 26 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"license": "MIT",
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"name": "@flaschengeist/types",
"author": "Ferdinand Thiessen <rpm@fthiessen.de>",
"homepage": "https://flaschengeist.dev/",

14
types/PEP440.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
/* This is some sort of PEP440 subset */
type Join<T extends unknown[], D extends string> = T extends []
? ''
: T extends [string | number | boolean | bigint]
? `${T[0]}`
: T extends [string | number | boolean | bigint, ...infer U]
? `${T[0]}${D}${Join<U, D>}`
: string;
type BaseVersion = Join<[number, number], '.'> | Join<[number, number, number], '.'>;
type PreRelease = Join<[['a' | 'b' | 'rc'], number], '.'>;
type PRVersion = BaseVersion | `${BaseVersion}${PreRelease}`;
/** A PEP440 subset used to describe backend module versions */
declare type PEP440Version = PRVersion | `${PRVersion}.dev${number}`;

View File

@ -1,8 +1,17 @@
/// <reference path="PEP440.d.ts" />
/**
* Types used for communicating with the API
*/
declare namespace FG {
interface BackendPlugin {
permissions: string[];
version: PEP440Version;
}
interface Backend {
plugins: {[key: string]: BackendPlugin};
version: PEP440Version;
}
interface Notification {
id: number;
plugin: string;

1
types/index.d.ts vendored
View File

@ -1,3 +1,4 @@
/// <reference path="flaschengeist.d.ts" />
/// <reference path="PEP440.d.ts" />
export * from './plugin';

15
types/plugin.d.ts vendored
View File

@ -1,3 +1,4 @@
/// <reference path="PEP440.d.ts" />
import type { RouteLocationRaw, RouteRecordRaw, RouteRecordName } from 'vue-router';
import type { Component } from '@vue/runtime-core';
@ -6,20 +7,6 @@ import type { Component } from '@vue/runtime-core';
* + Additional types for plugin interaction with the core
*/
/* This is some sort of PEP440 subset */
type Join<T extends unknown[], D extends string> = T extends []
? ''
: T extends [string | number | boolean | bigint]
? `${T[0]}`
: T extends [string | number | boolean | bigint, ...infer U]
? `${T[0]}${D}${Join<U, D>}`
: string;
type BaseVersion = Join<[number, number], '.'> | Join<[number, number, number], '.'>;
type PreRelease = Join<[['a' | 'b' | 'rc'], number], '.'>;
type PRVersion = BaseVersion | `${BaseVersion}${PreRelease}`;
/** A PEP440 subset used to describe backend module versions */
export type PEP440Version = PRVersion | `${PRVersion}.dev${number}`;
export namespace FG_Plugin {
/**
* Interface defining a Flaschengeist plugin