Update Pocketbase types

This commit is contained in:
Piotr Rogowski 2022-11-19 15:50:59 +01:00
parent 11950e5d63
commit 86fe5077ca
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
7 changed files with 133 additions and 83 deletions

80
package-lock.json generated
View File

@ -20,7 +20,7 @@
"mlg-converter": "^0.9.0",
"nanoid": "^4.0.0",
"pako": "^2.1.0",
"pocketbase": "^0.8.0-rc4",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga4": "^1.4.1",
@ -29,7 +29,7 @@
"react-redux": "^8.0.5",
"react-router-dom": "^6.4.3",
"uplot": "^1.6.22",
"uplot-react": "^1.1.1",
"uplot-react": "^1.1.4",
"vite": "^3.2.4"
},
"devDependencies": {
@ -44,16 +44,16 @@
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@vitejs/plugin-react": "^2.2.0",
"eslint": "^8.27.0",
"eslint": "^8.28.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-modules-newline": "^0.0.6",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"less": "^4.1.3",
"pocketbase-typegen": "^1.0.13",
"pocketbase-typegen": "^1.1.0",
"prettier": "^2.7.1",
"rollup-plugin-visualizer": "^5.8.3",
"typescript": "^4.9.3",
@ -3426,6 +3426,19 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/array.prototype.tosorted": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array.prototype.tosorted/-/array.prototype.tosorted-1.1.1.tgz",
"integrity": "sha512-pZYPXPRl2PqWcsUs6LOMn+1f1532nEoPTYowBtqLwAW+W8vSVhkIGnmOX1t/UQjD6YGI0vcD2B1U7ZFGQH9jnQ==",
"dev": true,
"dependencies": {
"call-bind": "^1.0.2",
"define-properties": "^1.1.4",
"es-abstract": "^1.20.4",
"es-shim-unscopables": "^1.0.0",
"get-intrinsic": "^1.1.3"
}
},
"node_modules/ast-types-flow": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz",
@ -4808,9 +4821,9 @@
}
},
"node_modules/eslint": {
"version": "8.27.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.27.0.tgz",
"integrity": "sha512-0y1bfG2ho7mty+SiILVf9PfuRA49ek4Nc60Wmmu62QlobNR+CeXa4xXIJgcuwSQgZiWaPH+5BDsctpIW0PR/wQ==",
"version": "8.28.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.28.0.tgz",
"integrity": "sha512-S27Di+EVyMxcHiwDrFzk8dJYAaD+/5SoWKxL1ri/71CRHsnJnRDPNt2Kzj24+MT9FDupf4aqqyqPrvI8MvQ4VQ==",
"dev": true,
"dependencies": {
"@eslint/eslintrc": "^1.3.3",
@ -5145,25 +5158,26 @@
}
},
"node_modules/eslint-plugin-react": {
"version": "7.31.10",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.31.10.tgz",
"integrity": "sha512-e4N/nc6AAlg4UKW/mXeYWd3R++qUano5/o+t+wnWxIf+bLsOaH3a4q74kX3nDjYym3VBN4HyO9nEn1GcAqgQOA==",
"version": "7.31.11",
"resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.31.11.tgz",
"integrity": "sha512-TTvq5JsT5v56wPa9OYHzsrOlHzKZKjV+aLgS+55NJP/cuzdiQPC7PfYoUjMoxlffKtvijpk7vA/jmuqRb9nohw==",
"dev": true,
"dependencies": {
"array-includes": "^3.1.5",
"array.prototype.flatmap": "^1.3.0",
"array-includes": "^3.1.6",
"array.prototype.flatmap": "^1.3.1",
"array.prototype.tosorted": "^1.1.1",
"doctrine": "^2.1.0",
"estraverse": "^5.3.0",
"jsx-ast-utils": "^2.4.1 || ^3.0.0",
"minimatch": "^3.1.2",
"object.entries": "^1.1.5",
"object.fromentries": "^2.0.5",
"object.hasown": "^1.1.1",
"object.values": "^1.1.5",
"object.entries": "^1.1.6",
"object.fromentries": "^2.0.6",
"object.hasown": "^1.1.2",
"object.values": "^1.1.6",
"prop-types": "^15.8.1",
"resolve": "^2.0.0-next.3",
"semver": "^6.3.0",
"string.prototype.matchall": "^4.0.7"
"string.prototype.matchall": "^4.0.8"
},
"engines": {
"node": ">=4"
@ -8335,14 +8349,14 @@
}
},
"node_modules/pocketbase": {
"version": "0.8.0-rc4",
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.8.0-rc4.tgz",
"integrity": "sha512-4sepm1a9DLbvudkfNpOq6d5rfemVICMtbv8nngQJ7KFf6y0A1PE/R9oFJ9UMxotyUAgZeHmnwYEjIkRaR0SD/A=="
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.8.0.tgz",
"integrity": "sha512-LMuV46YcuG4bDZ1DNeUkvbaS5MWLZ1gpmccn6rYIg50n1bQ/BZJ9ip6SMJqo7xRGkPSL4kk1RP/zCkiG6g37Lg=="
},
"node_modules/pocketbase-typegen": {
"version": "1.0.13",
"resolved": "https://registry.npmjs.org/pocketbase-typegen/-/pocketbase-typegen-1.0.13.tgz",
"integrity": "sha512-IuKlwyAQ0T8gfxttDo7mDVqZCCO8QzDoGq+Nwu4UmOxI5Q3QUAV6CFHJYL+D48IQQpm7EyCf858rdKuNkCZmuQ==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pocketbase-typegen/-/pocketbase-typegen-1.1.0.tgz",
"integrity": "sha512-Pol2CRgyKmlzUPHLXbdA8o7sUehzceX/jrP7wKgQZPg8p7LfY2CB4u3DKxIinqdFVmRnEME8hryBviuCL/O8gw==",
"dev": true,
"dependencies": {
"commander": "^9.4.1",
@ -9011,9 +9025,9 @@
}
},
"node_modules/rc-tree": {
"version": "5.7.0",
"resolved": "https://registry.npmjs.org/rc-tree/-/rc-tree-5.7.0.tgz",
"integrity": "sha512-F+Ewkv/UcutshnVBMISP+lPdHDlcsL+YH/MQDVWbk+QdkfID7vXiwrHMEZn31+2Rbbm21z/HPceGS8PXGMmnQg==",
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/rc-tree/-/rc-tree-5.7.1.tgz",
"integrity": "sha512-fP04wmM5oyi9jT3DvmweLENswMHuNV5bDqT/1lWcmzAUqJ5/O/Bj7y8dMR5JlnnTojsRoJP6HlS+Az4Bc1h9jA==",
"dependencies": {
"@babel/runtime": "^7.10.1",
"classnames": "2.x",
@ -9079,9 +9093,9 @@
}
},
"node_modules/rc-util": {
"version": "5.24.4",
"resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.24.4.tgz",
"integrity": "sha512-2a4RQnycV9eV7lVZPEJ7QwJRPlZNc06J7CwcwZo4vIHr3PfUqtYgl1EkUV9ETAc6VRRi8XZOMFhYG63whlIC9Q==",
"version": "5.24.5",
"resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.24.5.tgz",
"integrity": "sha512-Y5b6qQ2/tZKRT8MvL0/ky++JOMAijZPvepTMbt20eRDDMqXUbmIR+lkjcTfzDu845ysEyq0YGdRsaae3hrpnQg==",
"dependencies": {
"@babel/runtime": "^7.18.3",
"react-is": "^16.12.0",
@ -10532,9 +10546,9 @@
"integrity": "sha512-2jtSb/YHUgtmIUn0+QJjf7ggcJicb5PKe7ijBiRDTPsG/f8F/MFayZ+g6/0kATNkDyF/qQsHJDmCp6cxncg1EQ=="
},
"node_modules/uplot-react": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/uplot-react/-/uplot-react-1.1.1.tgz",
"integrity": "sha512-zCvwyZVm4nfYDi+KjaK0FppqftGzga/x+u0h2baRWj1vXMB9/hfJ1qb9gXAdXMfp17C9Rk57HoZDE9MewNWLfg==",
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/uplot-react/-/uplot-react-1.1.4.tgz",
"integrity": "sha512-qO1UkQwjVKdj5vTm3O3yldvu1T6hwY4++rH4KznLhjqpnLdncq1zsRxq/zQz/HUHPVD0j7WBcEISbNM61JsuAQ==",
"engines": {
"node": ">=8.10"
},

View File

@ -31,7 +31,7 @@
"mlg-converter": "^0.9.0",
"nanoid": "^4.0.0",
"pako": "^2.1.0",
"pocketbase": "^0.8.0-rc4",
"pocketbase": "^0.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga4": "^1.4.1",
@ -40,7 +40,7 @@
"react-redux": "^8.0.5",
"react-router-dom": "^6.4.3",
"uplot": "^1.6.22",
"uplot-react": "^1.1.1",
"uplot-react": "^1.1.4",
"vite": "^3.2.4"
},
"devDependencies": {
@ -55,16 +55,16 @@
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@vitejs/plugin-react": "^2.2.0",
"eslint": "^8.27.0",
"eslint": "^8.28.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-modules-newline": "^0.0.6",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"less": "^4.1.3",
"pocketbase-typegen": "^1.0.13",
"pocketbase-typegen": "^1.1.0",
"prettier": "^2.7.1",
"rollup-plugin-visualizer": "^5.8.3",
"typescript": "^4.9.3",

View File

@ -1,19 +1,6 @@
// This file was @generated using pocketbase-typegen
export type IsoDateString = string
export type RecordIdString = string
export type UserIdString = string
export type BaseRecord = {
id: RecordIdString
created: IsoDateString
updated: IsoDateString
collectionId: string
collectionName: string
expand?: { [key: string]: any }
}
/**
* This file was @generated using pocketbase-typegen
*/
export enum Collections {
IniFiles = 'iniFiles',
@ -22,20 +9,60 @@ export enum Collections {
Users = 'users',
}
// Alias types for improved usability
export type IsoDateString = string
export type RecordIdString = string
// System fields
export type BaseSystemFields = {
id: RecordIdString
created: IsoDateString
updated: IsoDateString
collectionId: string
collectionName: Collections
expand?: { [key: string]: any }
}
export type AuthSystemFields = {
email: string
emailVisibility: boolean
username: string
verified: boolean
} & BaseSystemFields
// Record types for each collection
export enum IniFilesEcosystemOptions {
speeduino = 'speeduino',
rusefi = 'rusefi',
}
export type IniFilesRecord = {
signature: string
file: string
ecosystem: 'speeduino' | 'rusefi'
ecosystem: IniFilesEcosystemOptions
}
export type IniFilesResponse = IniFilesRecord & BaseRecord
export type StargazersRecord = {
user: RecordIdString
tune: RecordIdString
}
export type StargazersResponse = StargazersRecord & BaseRecord
export enum TunesAspirationOptions {
na = 'na',
turbocharged = 'turbocharged',
supercharged = 'supercharged',
}
export enum TunesTagsOptions {
BaseMap = 'base map',
HelpNeeded = 'help needed',
}
export enum TunesVisibilityOptions {
public = 'public',
unlisted = 'unlisted',
}
export type TunesRecord = {
author: RecordIdString
@ -47,7 +74,7 @@ export type TunesRecord = {
engineCode: string
displacement: number
cylindersCount: number
aspiration: 'na' | 'turbocharged' | 'supercharged'
aspiration: TunesAspirationOptions
compression?: number
fuel?: string
ignition?: string
@ -56,26 +83,25 @@ export type TunesRecord = {
hp?: number
stockHp?: number
readme: string
tags: 'base map' | 'help needed'
tags?: TunesTagsOptions
textSearch: string
visibility: 'public' | 'unlisted'
visibility: TunesVisibilityOptions
tuneFile: string
customIniFile?: string
logFiles?: string[]
toothLogFiles?: string[]
}
export type TunesResponse = TunesRecord & BaseRecord
export type UsersRecord = {
avatar?: string
username: string
email: string
verified: boolean
verifiedAuthor?: boolean
}
export type UsersResponse = UsersRecord & BaseRecord
// Response types include system fields and match responses from the PocketBase API
export type IniFilesResponse = IniFilesRecord & BaseSystemFields
export type StargazersResponse = StargazersRecord & BaseSystemFields
export type TunesResponse = TunesRecord & BaseSystemFields
export type UsersResponse = UsersRecord & AuthSystemFields
export type CollectionRecords = {
iniFiles: IniFilesRecord

View File

@ -1,7 +1,8 @@
import { Tag } from 'antd';
import { TunesTagsOptions } from '../@types/pocketbase-types';
const TuneTag = ({ tag }: { tag: string }) => (
tag ? <Tag color={tag === 'base map' ? 'green' : 'red'}>
const TuneTag = ({ tag }: { tag: TunesTagsOptions | undefined }) => (
tag ? <Tag color={tag === TunesTagsOptions.BaseMap ? 'green' : 'red'}>
{tag}
</Tag> : null
);

View File

@ -22,7 +22,10 @@ import Loader from '../components/Loader';
import { Routes } from '../routes';
import { useAuth } from '../contexts/AuthContext';
import { formatTime } from '../utils/time';
import { UsersResponse } from '../@types/pocketbase-types';
import {
TunesAspirationOptions,
UsersResponse,
} from '../@types/pocketbase-types';
import StarButton from '../components/StarButton';
const { Item } = Form;
@ -124,9 +127,9 @@ const Info = ({ tuneData }: { tuneData: TuneDataState }) => {
<Col {...colProps}>
<Item>
<Select placeholder="Aspiration" style={{ width: '100%' }} value={tuneData.aspiration}>
<Select.Option value="na">Naturally aspirated</Select.Option>
<Select.Option value="turbocharged">Turbocharged</Select.Option>
<Select.Option value="supercharged">Supercharged</Select.Option>
<Select.Option value={TunesAspirationOptions.na}>Naturally aspirated</Select.Option>
<Select.Option value={TunesAspirationOptions.turbocharged}>Turbocharged</Select.Option>
<Select.Option value={TunesAspirationOptions.supercharged}>Supercharged</Select.Option>
</Select>
</Item>
</Col>

View File

@ -68,8 +68,11 @@ import {
import { aspirationMapper } from '../utils/tune/mappers';
import { copyToClipboard } from '../utils/clipboard';
import {
TunesAspirationOptions,
TunesRecord,
TunesResponse,
TunesTagsOptions,
TunesVisibilityOptions,
} from '../@types/pocketbase-types';
import { removeFilenameSuffix } from '../pocketbase';
@ -580,10 +583,10 @@ const UploadPage = () => {
<Col {...colProps}>
<Item name="visibility">
<Select>
<Select.Option value="public">
<Select.Option value={TunesVisibilityOptions.public}>
<Space><GlobalOutlined />Public</Space>
</Select.Option>
<Select.Option value="unlisted">
<Select.Option value={TunesVisibilityOptions.unlisted}>
<Space><EyeOutlined />Unlisted</Space>
</Select.Option>
</Select>
@ -670,8 +673,8 @@ const UploadPage = () => {
style={{ width: '100%' }}
options={[
{ label: null, value: null },
{ label: <Tag color="green">base map</Tag>, value: 'base map' },
{ label: <Tag color="red">help needed</Tag>, value: 'help needed' },
{ label: <Tag color="green">base map</Tag>, value: TunesTagsOptions.BaseMap },
{ label: <Tag color="red">help needed</Tag>, value: TunesTagsOptions.HelpNeeded },
]}
/>
</Item>
@ -717,9 +720,9 @@ const UploadPage = () => {
<Col {...colProps}>
<Item name="aspiration">
<Select placeholder="Aspiration" style={{ width: '100%' }}>
<Select.Option value="na">Naturally aspirated</Select.Option>
<Select.Option value="turbocharged">Turbocharged</Select.Option>
<Select.Option value="supercharged">Supercharged</Select.Option>
<Select.Option value={TunesAspirationOptions.na}>Naturally aspirated</Select.Option>
<Select.Option value={TunesAspirationOptions.turbocharged}>Turbocharged</Select.Option>
<Select.Option value={TunesAspirationOptions.supercharged}>Supercharged</Select.Option>
</Select>
</Item>
</Col>
@ -907,7 +910,7 @@ const UploadPage = () => {
initialValues={{
aspiration: 'na',
readme,
visibility: 'public',
visibility: TunesVisibilityOptions.public,
cylindersCount: 4,
displacement: 1.6,
year: thisYear,

View File

@ -39,7 +39,10 @@ import { usernameRules } from '../../utils/form';
import { formatTime } from '../../utils/time';
import useDb from '../../hooks/useDb';
import { aspirationMapper } from '../../utils/tune/mappers';
import { TunesResponse } from '../../@types/pocketbase-types';
import {
TunesResponse,
TunesVisibilityOptions,
} from '../../@types/pocketbase-types';
import TuneTag from '../../components/TuneTag';
const { Item } = Form;
@ -208,7 +211,7 @@ const Profile = () => {
renderItem={(tune) => (
<List.Item
actions={[
tune.visibility === 'public' ? <GlobalOutlined /> : <EyeOutlined />,
tune.visibility === TunesVisibilityOptions.public ? <GlobalOutlined /> : <EyeOutlined />,
<Button icon={<EditOutlined />} onClick={() => goToEdit(tune.tuneId)} />,
<Button icon={<ArrowRightOutlined />} onClick={() => navigate(tunePath(tune.tuneId))} />,
]}