diff --git a/docs/FIXTURES.MD b/docs/FIXTURES.MD index 8e88fcb..8ab8334 100644 --- a/docs/FIXTURES.MD +++ b/docs/FIXTURES.MD @@ -74,7 +74,7 @@ Here is an example of what a fixture can look like (taken from the `ranks.ts` fi // Import the necessary types with "import type..." import type { Fixture, Reference } from '../index'; import type { RanksRecord, RanksResponse } from '../../src/lib/types/pocketbase'; -import type { TierlistsDataKeys } from './tierlists'; +import type { TierlistsDataKeys } from './tier-lists'; // Export the data that is going to be inserted in a constant to be able to access it from other fixtures export const DATA = { @@ -106,8 +106,8 @@ export const DATA = { }, // ... other data // Use the right type to get full type-safety on your export, also makes it easier to add new data -// We omit the "tierlist" field because it is already represented by the key of the object -} as const satisfies Record>>; +// We omit the "tierList" field because it is already represented by the key of the object +} as const satisfies Record>>; // Export the keys of the data to be able to use them as types export type RanksDataKeys = keyof typeof DATA; @@ -116,17 +116,17 @@ export type RanksDataKeys = keyof typeof DATA; export default { // The name of our fixture, usually the name of the file and collection name: 'ranks', - // The order (ascendant) in which to load this fixture, useful to load this fixture after its dependencies (tierlists) + // The order (ascendant) in which to load this fixture, useful to load this fixture after its dependencies (tierLists) order: 2, // Our load function with PocketBase, records of other fixtures and Faker load: async (pb, references) => { // Prepare the records we will return const records: Reference = {}; - // Because we are loading after the "tierlists" fixture, all the tierlists inserted are available inside "references.tierlists" - const tierlistsReferences = references.tierlists || {}; + // Because we are loading after the "tierLists" fixture, all the tier lists inserted are available inside "references.tierLists" + const tierListsReferences = references.tierLists || {}; - // We loop over each tierlist - for (const [tierlist, ranks] of Object.entries(DATA)) { + // We loop over each tier list + for (const [tierList, ranks] of Object.entries(DATA)) { // We use the constant defined earlier to know how many ranks to add for (const [i, rank] of Object.entries(ranks)) { // We create a new record with fake data and add it to our "records" object @@ -135,8 +135,8 @@ export default { color: rank.color, description: rank.description, position: rank.position, - // We use the "references" object to reference the tierlist we want to link to - tierlist: tierlistsReferences[tierlist].id, + // We use the "references" object to reference the tier list we want to link to + tierList: tierListsReferences[tierList].id, } as RanksRecord); } } diff --git a/pocketbase/migrations/1711214542_updated_tierlists.go b/pocketbase/migrations/1711214542_updated_tierlists.go new file mode 100644 index 0000000..642db04 --- /dev/null +++ b/pocketbase/migrations/1711214542_updated_tierlists.go @@ -0,0 +1,37 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierlists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711214594_updated_tierlists.go b/pocketbase/migrations/1711214594_updated_tierlists.go new file mode 100644 index 0000000..1e2e26f --- /dev/null +++ b/pocketbase/migrations/1711214594_updated_tierlists.go @@ -0,0 +1,43 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.Name = "tier_lists" + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tier_lists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.Name = "tierlists" + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierlists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711215267_updated_tier_lists.go b/pocketbase/migrations/1711215267_updated_tier_lists.go new file mode 100644 index 0000000..0489e20 --- /dev/null +++ b/pocketbase/migrations/1711215267_updated_tier_lists.go @@ -0,0 +1,43 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.Name = "tierLists" + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierLists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.Name = "tier_lists" + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tier_lists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711215345_updated_ranks.go b/pocketbase/migrations/1711215345_updated_ranks.go new file mode 100644 index 0000000..2de70af --- /dev/null +++ b/pocketbase/migrations/1711215345_updated_ranks.go @@ -0,0 +1,70 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models/schema" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + // update + edit_tierList := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "ai8coksm", + "name": "tierList", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "0uxolnvwwz0sr78", + "cascadeDelete": true, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_tierList) + collection.Schema.AddField(edit_tierList) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + // update + edit_tierList := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "ai8coksm", + "name": "tierlist", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "0uxolnvwwz0sr78", + "cascadeDelete": true, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_tierList) + collection.Schema.AddField(edit_tierList) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711233247_updated_ranks.go b/pocketbase/migrations/1711233247_updated_ranks.go new file mode 100644 index 0000000..fe115a7 --- /dev/null +++ b/pocketbase/migrations/1711233247_updated_ranks.go @@ -0,0 +1,37 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_p0rclkv` + "`" + ` ON ` + "`" + `ranks` + "`" + ` (\n ` + "`" + `position` + "`" + `,\n ` + "`" + `tierList` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711270336_updated_items.go b/pocketbase/migrations/1711270336_updated_items.go new file mode 100644 index 0000000..6084c12 --- /dev/null +++ b/pocketbase/migrations/1711270336_updated_items.go @@ -0,0 +1,92 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models/schema" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + // add + new_tierList := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "tupaapcc", + "name": "tierList", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "0uxolnvwwz0sr78", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), new_tierList) + collection.Schema.AddField(new_tierList) + + // update + edit_rank := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "jlwvewrl", + "name": "rank", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "sf00q2lme3knpnc", + "cascadeDelete": true, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_rank) + collection.Schema.AddField(edit_rank) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + // remove + collection.Schema.RemoveField("tupaapcc") + + // update + edit_rank := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "jlwvewrl", + "name": "rank", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "sf00q2lme3knpnc", + "cascadeDelete": true, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_rank) + collection.Schema.AddField(edit_rank) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711280246_updated_items.go b/pocketbase/migrations/1711280246_updated_items.go new file mode 100644 index 0000000..c539edd --- /dev/null +++ b/pocketbase/migrations/1711280246_updated_items.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.CreateRule = types.Pointer("@request.data.rank:isset = false || @request.data.rank.tierList.id = @request.data.tierList.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.CreateRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711280391_updated_items.go b/pocketbase/migrations/1711280391_updated_items.go new file mode 100644 index 0000000..2e1a550 --- /dev/null +++ b/pocketbase/migrations/1711280391_updated_items.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("tierList.public = true || tierList.createdBy.id = @request.auth.id") + + collection.ViewRule = types.Pointer("tierList.public = true || tierList.createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.ListRule = nil + + collection.ViewRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711280638_updated_items.go b/pocketbase/migrations/1711280638_updated_items.go new file mode 100644 index 0000000..0dd8145 --- /dev/null +++ b/pocketbase/migrations/1711280638_updated_items.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = types.Pointer("") + + collection.DeleteRule = types.Pointer("@request.auth.id = tierList.createdBy.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = nil + + collection.DeleteRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711280791_updated_users.go b/pocketbase/migrations/1711280791_updated_users.go new file mode 100644 index 0000000..f2570ce --- /dev/null +++ b/pocketbase/migrations/1711280791_updated_users.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("") + + collection.ViewRule = types.Pointer("") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_") + if err != nil { + return err + } + + collection.ListRule = nil + + collection.ViewRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711280880_updated_items.go b/pocketbase/migrations/1711280880_updated_items.go new file mode 100644 index 0000000..3be7046 --- /dev/null +++ b/pocketbase/migrations/1711280880_updated_items.go @@ -0,0 +1,37 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[ + "CREATE INDEX ` + "`" + `idx_IIF4bdU` + "`" + ` ON ` + "`" + `items` + "`" + ` (\n ` + "`" + `position` + "`" + `,\n ` + "`" + `rank` + "`" + `,\n ` + "`" + `tierList` + "`" + `\n)" + ]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + json.Unmarshal([]byte(`[]`), &collection.Indexes) + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711291546_updated_items.go b/pocketbase/migrations/1711291546_updated_items.go new file mode 100644 index 0000000..12dab80 --- /dev/null +++ b/pocketbase/migrations/1711291546_updated_items.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = types.Pointer("tierList.createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711291940_updated_items.go b/pocketbase/migrations/1711291940_updated_items.go new file mode 100644 index 0000000..8623f06 --- /dev/null +++ b/pocketbase/migrations/1711291940_updated_items.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = types.Pointer("tierList.createdBy.id = @request.auth.id && (@request.data.rank:isset = false || (@request.data.rank.tierList.id = @request.data.tierList.id) || (@request.data.rank.tierList.id = tierList.id))") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.UpdateRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711292564_updated_items.go b/pocketbase/migrations/1711292564_updated_items.go new file mode 100644 index 0000000..2dc3df4 --- /dev/null +++ b/pocketbase/migrations/1711292564_updated_items.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.CreateRule = types.Pointer("tierList.createdBy.id = @request.auth.id && (@request.data.rank:isset = false || @request.data.rank.tierList.id = @request.data.tierList.id)") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl") + if err != nil { + return err + } + + collection.CreateRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711298240_updated_ranks.go b/pocketbase/migrations/1711298240_updated_ranks.go new file mode 100644 index 0000000..63a34cc --- /dev/null +++ b/pocketbase/migrations/1711298240_updated_ranks.go @@ -0,0 +1,34 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("tierList.public = true || tierList.createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + collection.ListRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711298405_updated_ranks.go b/pocketbase/migrations/1711298405_updated_ranks.go new file mode 100644 index 0000000..4cdefd1 --- /dev/null +++ b/pocketbase/migrations/1711298405_updated_ranks.go @@ -0,0 +1,46 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + collection.ViewRule = types.Pointer("tierList.public = true || tierList.createdBy.id = @request.auth.id") + + collection.CreateRule = types.Pointer("tierList.createdBy.id = @request.auth.id") + + collection.UpdateRule = types.Pointer("tierList.createdBy.id = @request.auth.id") + + collection.DeleteRule = types.Pointer("tierList.createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc") + if err != nil { + return err + } + + collection.ViewRule = nil + + collection.CreateRule = nil + + collection.UpdateRule = nil + + collection.DeleteRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711298491_updated_tierLists.go b/pocketbase/migrations/1711298491_updated_tierLists.go new file mode 100644 index 0000000..6a9a777 --- /dev/null +++ b/pocketbase/migrations/1711298491_updated_tierLists.go @@ -0,0 +1,38 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.ListRule = types.Pointer("public = true || createdBy.id = @request.auth.id") + + collection.ViewRule = types.Pointer("public = true || createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.ListRule = nil + + collection.ViewRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711298838_updated_tierLists.go b/pocketbase/migrations/1711298838_updated_tierLists.go new file mode 100644 index 0000000..1745ba4 --- /dev/null +++ b/pocketbase/migrations/1711298838_updated_tierLists.go @@ -0,0 +1,42 @@ +package migrations + +import ( + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/tools/types" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.CreateRule = types.Pointer("createdBy.id = @request.auth.id") + + collection.UpdateRule = types.Pointer("createdBy.id = @request.auth.id") + + collection.DeleteRule = types.Pointer("createdBy.id = @request.auth.id") + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + collection.CreateRule = nil + + collection.UpdateRule = nil + + collection.DeleteRule = nil + + return dao.SaveCollection(collection) + }) +} diff --git a/pocketbase/migrations/1711298895_updated_tierLists.go b/pocketbase/migrations/1711298895_updated_tierLists.go new file mode 100644 index 0000000..421c6be --- /dev/null +++ b/pocketbase/migrations/1711298895_updated_tierLists.go @@ -0,0 +1,70 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models/schema" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + // update + edit_createdBy := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "rqkfegky", + "name": "createdBy", + "type": "relation", + "required": true, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": true, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_createdBy) + collection.Schema.AddField(edit_createdBy) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78") + if err != nil { + return err + } + + // update + edit_createdBy := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "rqkfegky", + "name": "createdBy", + "type": "relation", + "required": false, + "unique": false, + "options": { + "collectionId": "_pb_users_auth_", + "cascadeDelete": false, + "minSelect": null, + "maxSelect": 1, + "displayFields": [] + } + }`), edit_createdBy) + collection.Schema.AddField(edit_createdBy) + + return dao.SaveCollection(collection) + }) +} diff --git a/svelte-kit/fixtures/data/items.ts b/svelte-kit/fixtures/data/items.ts index 9e6180c..0656075 100644 --- a/svelte-kit/fixtures/data/items.ts +++ b/svelte-kit/fixtures/data/items.ts @@ -1,14 +1,19 @@ import type { Fixture, Reference } from '..'; import type { ItemsRecord, ItemsResponse } from '../../src/lib/types/pocketbase'; import type { DATA as RANKS_DATA, RanksDataKeys } from './ranks'; +import type { TierListsDataKeys } from './tier-lists'; -export type RanksData = { - [tierlistKey in T]: { - [key in keyof (typeof RANKS_DATA)[tierlistKey]]: Reference>; +export type ItemReference = Reference>; + +export type RankedItemsData = { + [tierListKey in T]: { + [key in keyof (typeof RANKS_DATA)[tierListKey]]: ItemReference; }; }; -export const DATA = { +export type UnrankedItemsData = Record; + +export const RANKED_DATA = { cars: { veryFast: { teslaModelS: { @@ -124,7 +129,8 @@ export const DATA = { }, knockout: { name: 'Knockout', - description: 'Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.', + description: + 'Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.', position: 1, }, marionette: { @@ -137,7 +143,7 @@ export const DATA = { description: 'Polymer is a JavaScript library for building web applications using web components.', position: 3, }, - } + }, }, private: {}, template: { @@ -146,7 +152,42 @@ export const DATA = { b: {}, c: {}, }, -} as const satisfies RanksData; +} as const satisfies RankedItemsData; + +export const UNRANKED_DATA = { + cars: { + teslaModel3: { + name: 'Tesla Model 3', + description: 'The Tesla Model 3 is a compact electric car with a range of 263 miles.', + position: 0, + }, + porscheTaycan: { + name: 'Porsche Taycan', + description: 'The Porsche Taycan is an electric sports car with a range of 200 miles.', + position: 1, + }, + }, + frameworks: { + sapper: { + name: 'Sapper', + description: 'Sapper is a framework for building web applications of all sizes.', + position: 0, + }, + meteor: { + name: 'Meteor', + description: 'Meteor is a full-stack JavaScript platform for developing modern web and mobile applications.', + position: 1, + }, + }, + private: {}, + template: {}, +} as const satisfies UnrankedItemsData; + +export type RankedItemsDataKeys = keyof typeof RANKED_DATA; + +export type UnrankedItemsDataKeys = keyof typeof UNRANKED_DATA; + +export type ItemsDataKeys = RankedItemsDataKeys | UnrankedItemsDataKeys; export default { name: 'items', @@ -154,20 +195,35 @@ export default { load: async (pb, references) => { const records: Reference = {}; const ranksReferences = references.ranks || {}; + const tierListsReferences = references.tierLists || {}; - for (const ranks of Object.values(DATA)) { + // Ranked items + for (const ranks of Object.values(RANKED_DATA)) { for (const [rank, items] of Object.entries(ranks)) { - for (const [i, item] of Object.entries>(items)) { - records[i] = await pb.collection('items').create({ + for (const [i, item] of Object.entries>(items)) { + records[i] = await pb.collection('items').create({ name: item.name, description: item.description, position: item.position, rank: ranksReferences[rank].id, + tierList: ranksReferences[rank].tierList, } as ItemsRecord); } } } + // Unranked items + for (const [tierList, items] of Object.entries(UNRANKED_DATA)) { + for (const [i, item] of Object.entries>(items)) { + records[i] = await pb.collection('items').create({ + name: item.name, + description: item.description, + position: item.position, + tierList: tierListsReferences[tierList].id, + } as ItemsRecord); + } + } + return { records }; }, } satisfies Fixture; diff --git a/svelte-kit/fixtures/data/ranks.ts b/svelte-kit/fixtures/data/ranks.ts index 88c76cd..e88948d 100644 --- a/svelte-kit/fixtures/data/ranks.ts +++ b/svelte-kit/fixtures/data/ranks.ts @@ -1,6 +1,10 @@ import type { Fixture, Reference } from '../index'; import type { RanksRecord, RanksResponse } from '../../src/lib/types/pocketbase'; -import type { TierlistsDataKeys } from './tierlists'; +import type { TierListsDataKeys } from './tier-lists'; + +export type RankReference = Reference>; + +export type TierListRanksData = Record; export const DATA = { cars: { @@ -82,7 +86,7 @@ export const DATA = { position: 3, }, }, -} as const satisfies Record>>; +} as const satisfies TierListRanksData; export type RanksDataKeys = keyof typeof DATA; @@ -91,16 +95,16 @@ export default { order: 2, load: async (pb, references) => { const records: Reference = {}; - const tierlistsReferences = references.tierlists || {}; + const tierListsReferences = references.tierLists || {}; - for (const [tierlist, ranks] of Object.entries(DATA)) { + for (const [tierList, ranks] of Object.entries(DATA)) { for (const [i, rank] of Object.entries(ranks)) { - records[i] = await pb.collection('ranks').create({ + records[i] = await pb.collection('ranks').create({ name: rank.name, color: rank.color, description: rank.description, position: rank.position, - tierlist: tierlistsReferences[tierlist].id, + tierList: tierListsReferences[tierList].id, } as RanksRecord); } } diff --git a/svelte-kit/fixtures/data/tierlists.ts b/svelte-kit/fixtures/data/tier-lists.ts similarity index 55% rename from svelte-kit/fixtures/data/tierlists.ts rename to svelte-kit/fixtures/data/tier-lists.ts index b34f154..b501a73 100644 --- a/svelte-kit/fixtures/data/tierlists.ts +++ b/svelte-kit/fixtures/data/tier-lists.ts @@ -1,7 +1,9 @@ import type { Fixture, Reference } from '../index'; -import type { TierlistsRecord, TierlistsResponse } from '../../src/lib/types/pocketbase'; +import type { TierListsRecord, TierListsResponse } from '../../src/lib/types/pocketbase'; import type { DATA as USER_DATA } from './users'; +export type TierListReference = Reference; + export const DATA = { cars: { name: 'Cars', @@ -22,7 +24,7 @@ export const DATA = { private: { name: 'Private', slug: 'private', - description: 'Private tierlist (WIP)', + description: 'Private tier list (WIP)', public: false, canBeTemplate: false, createdBy: 'karl', @@ -35,32 +37,28 @@ export const DATA = { canBeTemplate: true, createdBy: 'quantumQuasar97', }, -} as const satisfies Reference< - TierlistsRecord & { - createdBy: keyof typeof USER_DATA; - } ->; +} as const satisfies TierListReference; -export type TierlistsDataKeys = keyof typeof DATA; +export type TierListsDataKeys = keyof typeof DATA; export default { - name: 'tierlists', + name: 'tierLists', order: 1, load: async (pb, references) => { - const records: Reference = {}; + const records: Reference = {}; const usersReferences = references.users || {}; - for (const [i, tierlist] of Object.entries(DATA)) { - records[i] = await pb.collection('tierlists').create({ - name: tierlist.name, - slug: tierlist.slug, - description: tierlist.description, - public: tierlist.public, - canBeTemplate: tierlist.canBeTemplate, - createdBy: usersReferences[tierlist.createdBy].id, - } as TierlistsRecord); + for (const [i, tierList] of Object.entries(DATA)) { + records[i] = await pb.collection('tierLists').create({ + name: tierList.name, + slug: tierList.slug, + description: tierList.description, + public: tierList.public, + canBeTemplate: tierList.canBeTemplate, + createdBy: usersReferences[tierList.createdBy].id, + } as TierListsRecord); } return { records }; }, -} satisfies Fixture; +} satisfies Fixture; diff --git a/svelte-kit/fixtures/data/users.ts b/svelte-kit/fixtures/data/users.ts index 28a163f..b4edd7f 100644 --- a/svelte-kit/fixtures/data/users.ts +++ b/svelte-kit/fixtures/data/users.ts @@ -39,9 +39,9 @@ export const DATA = { }, }, }, - tierlistCreator56: { - username: 'tierlistCreator56', - email: 'tierlistCreator56@ranky-list.com', + tierListCreator56: { + username: 'tierListCreator56', + email: 'tierListCreator56@ranky-list.com', emailVisibility: true, verified: true, websites: {}, diff --git a/svelte-kit/fixtures/index.ts b/svelte-kit/fixtures/index.ts index fe8a445..687f96d 100644 --- a/svelte-kit/fixtures/index.ts +++ b/svelte-kit/fixtures/index.ts @@ -6,7 +6,7 @@ import chalk from 'chalk'; import { createInterface } from 'readline/promises'; import type { Faker } from '@faker-js/faker'; -import type { BaseSystemFields, CollectionRecords, CollectionResponses } from '../src/lib/types/pocketbase'; +import type { BaseSystemFields, CollectionRecords, CollectionResponses, TypedPocketBase } from '../src/lib/types/pocketbase'; /** * A reference to a record in the fixture. @@ -58,7 +58,7 @@ export type Fixture = { * @param faker The faker instance. Try to use it as little as possible and only for irrelevant data, as fully random data can make your tests flaky. * @returns A promise that resolves to a reference holder containing the records that were loaded into the collection. */ - load(pb: PocketBase, references: ReferenceMap, faker: Faker): Promise>; + load(pb: TypedPocketBase, references: ReferenceMap, faker: Faker): Promise>; }; const prompt = createInterface({ input: process.stdin, output: process.stdout }); @@ -114,7 +114,7 @@ try { process.exit(1); } -let pb: PocketBase; +let pb: TypedPocketBase; let faker: Faker; if (process.env.SECRET_FIXTURES_LOCALE) { diff --git a/svelte-kit/src/app.d.ts b/svelte-kit/src/app.d.ts index aa448c1..622652e 100644 --- a/svelte-kit/src/app.d.ts +++ b/svelte-kit/src/app.d.ts @@ -1,8 +1,8 @@ // See https://kit.svelte.dev/docs/types#app // for information about these interfaces -import type { UsersResponse } from '$types/pocketbase'; -import type PocketBase, { RecordAuthResponse } from 'pocketbase'; +import type { TypedPocketBase, UsersResponse } from '$types/pocketbase'; +import type { RecordAuthResponse } from 'pocketbase'; import type { MetaTagsProps } from 'svelte-meta-tags'; import '@poppanator/sveltekit-svg/dist/svg'; @@ -11,7 +11,7 @@ import 'unplugin-icons/types/svelte'; declare global { declare namespace App { interface Locals { - pb: PocketBase; + pb: TypedPocketBase; user: RecordAuthResponse | null; } diff --git a/svelte-kit/src/hooks.server.ts b/svelte-kit/src/hooks.server.ts index 20648f5..a02788a 100644 --- a/svelte-kit/src/hooks.server.ts +++ b/svelte-kit/src/hooks.server.ts @@ -1,13 +1,13 @@ import { pb } from '$server/pocketbase'; import dayjs from '$utils/dayjs'; -import type { UsersResponse } from './lib/types/pocketbase'; import type { Handle, HandleServerError } from '@sveltejs/kit'; import { dev } from '$app/environment'; const ERROR_MAPPING = { 404: "The page you are looking for doesn't exist. Please check the URL and try again.", + 500: 'An unexpected error occurred. Please try again later.', } as Record; export const handle = (async ({ event, resolve }) => { @@ -16,7 +16,7 @@ export const handle = (async ({ event, resolve }) => { try { if (event.locals.pb.authStore.isValid) { - event.locals.user = await event.locals.pb.collection('users').authRefresh(); + event.locals.user = await event.locals.pb.collection('users').authRefresh(); } } catch (_) { event.locals.pb.authStore.clear(); diff --git a/svelte-kit/src/lib/schemas/item.ts b/svelte-kit/src/lib/schemas/item.ts new file mode 100644 index 0000000..abb209b --- /dev/null +++ b/svelte-kit/src/lib/schemas/item.ts @@ -0,0 +1,16 @@ +import { maxLength, minLength, minValue, number, object, string, toTrimmed, toTrimmedEnd, type Input } from 'valibot'; + +export const ItemSchema = object({ + name: string('Please enter a valid name.', [ + toTrimmed(), + minLength(1, 'The name of an item must contain at least 1 character.'), + maxLength(100, 'The name of an item must contain at most 100 characters.'), + ]), + description: string('Please enter a valid description.', [ + toTrimmedEnd(), + maxLength(2000, 'The description of an item must contain at most 2000 characters.'), + ]), + position: number("This rank's position is invalid.", [minValue(0, "This rank's position is invalid.")]), +}); + +export type ItemInput = Input; diff --git a/svelte-kit/src/lib/schemas/rank.ts b/svelte-kit/src/lib/schemas/rank.ts new file mode 100644 index 0000000..4c7ebad --- /dev/null +++ b/svelte-kit/src/lib/schemas/rank.ts @@ -0,0 +1,20 @@ +import { array, hexColor, maxLength, minLength, minValue, number, object, string, toTrimmed, toTrimmedEnd, type Input } from 'valibot'; + +import { ItemSchema } from './item'; + +export const RankSchema = object({ + name: string('Please enter a valid name.', [ + toTrimmed(), + minLength(1, 'The name of a rank must contain at least 1 character.'), + maxLength(100, 'The name of a rank must contain at most 100 characters.'), + ]), + color: string('Please enter a valid color.', [toTrimmed(), hexColor('The color of a rank must be a valid hex color code.')]), + description: string('Please enter a valid description.', [ + toTrimmedEnd(), + maxLength(2000, 'The description of a rank must contain at most 2000 characters.'), + ]), + position: number("This rank's position is invalid.", [minValue(0, "This rank's position is invalid.")]), + items: array(ItemSchema), +}); + +export type RankInput = Input; diff --git a/svelte-kit/src/lib/schemas/tier-list.ts b/svelte-kit/src/lib/schemas/tier-list.ts new file mode 100644 index 0000000..b740253 --- /dev/null +++ b/svelte-kit/src/lib/schemas/tier-list.ts @@ -0,0 +1,25 @@ +import { array, boolean, maxLength, minLength, object, string, toTrimmed, toTrimmedEnd, type Input } from 'valibot'; + +import { ItemSchema } from './item'; +import { RankSchema } from './rank'; + +export const TierListSchema = object({ + name: string('Please enter a valid name.', [ + toTrimmed(), + minLength(2, 'The name of your tier list must contain at least 2 characters.'), + maxLength(200, 'The name of your tier list must contain at most 200 characters.'), + ]), + description: string('Please enter a valid description.', [ + toTrimmedEnd(), + maxLength(2000, 'The description of your tier list must contain at most 2000 characters.'), + ]), + public: boolean('Please choose whether your tier list should be public or private.'), + canBeTemplate: boolean('Please choose whether your tier list can be used as a template.'), + ranks: array(RankSchema, [ + minLength(1, 'Your tier list must contain at least 1 rank.'), + maxLength(100, 'Your tier list cannot contain more than 100 ranks.'), + ]), + unrakedItems: array(ItemSchema), +}); + +export type TierListInput = Input; diff --git a/svelte-kit/src/lib/types/pocketbase.ts b/svelte-kit/src/lib/types/pocketbase.ts index f146f63..228e48c 100644 --- a/svelte-kit/src/lib/types/pocketbase.ts +++ b/svelte-kit/src/lib/types/pocketbase.ts @@ -8,7 +8,7 @@ import type { RecordService } from 'pocketbase'; export enum Collections { Items = 'items', Ranks = 'ranks', - Tierlists = 'tierlists', + TierLists = 'tierLists', Users = 'users', } @@ -40,7 +40,8 @@ export type ItemsRecord = { description?: string; name: string; position?: number; - rank: RecordIdString; + rank?: RecordIdString; + tierList: RecordIdString; }; export type RanksRecord = { @@ -48,12 +49,12 @@ export type RanksRecord = { description?: string; name: string; position?: number; - tierlist: RecordIdString; + tierList: RecordIdString; }; -export type TierlistsRecord = { +export type TierListsRecord = { canBeTemplate?: boolean; - createdBy?: RecordIdString; + createdBy: RecordIdString; description?: string; name: string; public?: boolean; @@ -68,7 +69,7 @@ export type UsersRecord = { // Response types include system fields and match responses from the PocketBase API export type ItemsResponse = Required & BaseSystemFields; export type RanksResponse = Required & BaseSystemFields; -export type TierlistsResponse = Required & BaseSystemFields; +export type TierListsResponse = Required & BaseSystemFields; export type UsersResponse = Required> & AuthSystemFields; // Types containing all Records and Responses, useful for creating typing helper functions @@ -76,14 +77,14 @@ export type UsersResponse = Required; collection(idOrName: 'ranks'): RecordService; - collection(idOrName: 'tierlists'): RecordService; + collection(idOrName: 'tierLists'): RecordService; collection(idOrName: 'users'): RecordService; }; diff --git a/svelte-kit/src/routes/+layout.svelte b/svelte-kit/src/routes/+layout.svelte index 083ceb1..3badace 100644 --- a/svelte-kit/src/routes/+layout.svelte +++ b/svelte-kit/src/routes/+layout.svelte @@ -189,8 +189,8 @@
- - + +
diff --git a/svelte-kit/src/routes/+page.server.ts b/svelte-kit/src/routes/+page.server.ts index 636304f..f283838 100644 --- a/svelte-kit/src/routes/+page.server.ts +++ b/svelte-kit/src/routes/+page.server.ts @@ -1,10 +1,9 @@ import { redirect } from '@sveltejs/kit'; -import type { TierlistsResponse } from '$types/pocketbase'; import type { Actions, PageServerLoad } from './$types'; export const load = (async ({ locals }) => { - const recentTierLists = await locals.pb.collection('tierlists').getList(1, 10, { + const recentTierLists = await locals.pb.collection('tierLists').getList(1, 10, { sort: '-created', }); diff --git a/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/+page.server.ts b/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/+page.server.ts similarity index 67% rename from svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/+page.server.ts rename to svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/+page.server.ts index 67caa5d..c1df1ff 100644 --- a/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/+page.server.ts +++ b/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/+page.server.ts @@ -1,18 +1,18 @@ import { error } from '@sveltejs/kit'; import { ClientResponseError } from 'pocketbase'; -import type { TierlistsResponse } from '$types/pocketbase'; +import type { TierListsResponse } from '$types/pocketbase'; import type { PageServerLoad } from './$types'; export const load = (async ({ params, locals }) => { - const { tierlistSlug } = params; - let tierList: TierlistsResponse; + const { tierListSlug } = params; + let tierList: TierListsResponse; try { - tierList = await locals.pb.collection('tierlists').getFirstListItem(`slug = "${tierlistSlug}"`); + tierList = await locals.pb.collection('tierLists').getFirstListItem(`slug = "${tierListSlug}"`); } catch (e) { if (e instanceof ClientResponseError && e.status === 404) { - error(404, `Tier list "${tierlistSlug}" not found`); + error(404, `Tier list "${tierListSlug}" not found`); } error(500, { message: 'Something went wrong while trying to retrieve the tier list.' }); diff --git a/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/+page.svelte b/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/+page.svelte similarity index 100% rename from svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/+page.svelte rename to svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/+page.svelte diff --git a/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/edit/+page.server.ts b/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/edit/+page.server.ts similarity index 100% rename from svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/edit/+page.server.ts rename to svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/edit/+page.server.ts diff --git a/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/edit/+page.svelte b/svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/edit/+page.svelte similarity index 100% rename from svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierlistSlug]/edit/+page.svelte rename to svelte-kit/src/routes/users/[userSlug]/tier-lists/[tierListSlug]/edit/+page.svelte