From 86fe5077ca23998fca4ca12a504bd5fde2379f33 Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Sat, 19 Nov 2022 15:50:59 +0100 Subject: [PATCH] Update Pocketbase types --- package-lock.json | 80 +++++++++++++++++++------------- package.json | 10 ++-- src/@types/pocketbase-types.ts | 84 ++++++++++++++++++++++------------ src/components/TuneTag.tsx | 5 +- src/pages/Info.tsx | 11 +++-- src/pages/Upload.tsx | 19 ++++---- src/pages/auth/Profile.tsx | 7 ++- 7 files changed, 133 insertions(+), 83 deletions(-) diff --git a/package-lock.json b/package-lock.json index afec855..44408dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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" }, diff --git a/package.json b/package.json index 2eb31e6..f349b9a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/@types/pocketbase-types.ts b/src/@types/pocketbase-types.ts index a65d021..eabf50a 100644 --- a/src/@types/pocketbase-types.ts +++ b/src/@types/pocketbase-types.ts @@ -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 diff --git a/src/components/TuneTag.tsx b/src/components/TuneTag.tsx index fedd42f..f74c817 100644 --- a/src/components/TuneTag.tsx +++ b/src/components/TuneTag.tsx @@ -1,7 +1,8 @@ import { Tag } from 'antd'; +import { TunesTagsOptions } from '../@types/pocketbase-types'; -const TuneTag = ({ tag }: { tag: string }) => ( - tag ? +const TuneTag = ({ tag }: { tag: TunesTagsOptions | undefined }) => ( + tag ? {tag} : null ); diff --git a/src/pages/Info.tsx b/src/pages/Info.tsx index 9a9a794..f41465f 100644 --- a/src/pages/Info.tsx +++ b/src/pages/Info.tsx @@ -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 }) => { diff --git a/src/pages/Upload.tsx b/src/pages/Upload.tsx index 7d9da26..fb93520 100644 --- a/src/pages/Upload.tsx +++ b/src/pages/Upload.tsx @@ -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 = () => { @@ -670,8 +673,8 @@ const UploadPage = () => { style={{ width: '100%' }} options={[ { label: null, value: null }, - { label: base map, value: 'base map' }, - { label: help needed, value: 'help needed' }, + { label: base map, value: TunesTagsOptions.BaseMap }, + { label: help needed, value: TunesTagsOptions.HelpNeeded }, ]} /> @@ -717,9 +720,9 @@ const UploadPage = () => { @@ -907,7 +910,7 @@ const UploadPage = () => { initialValues={{ aspiration: 'na', readme, - visibility: 'public', + visibility: TunesVisibilityOptions.public, cylindersCount: 4, displacement: 1.6, year: thisYear, diff --git a/src/pages/auth/Profile.tsx b/src/pages/auth/Profile.tsx index 343ccdf..4d9c36a 100644 --- a/src/pages/auth/Profile.tsx +++ b/src/pages/auth/Profile.tsx @@ -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) => ( : , + tune.visibility === TunesVisibilityOptions.public ? : ,