├── sdk ├── Example │ ├── Shared │ │ ├── RedirectTo.razor │ │ ├── Loading.razor │ │ ├── Loading.razor.cs │ │ ├── MainLayout.razor │ │ ├── RedirectTo.razor.cs │ │ └── MainLayout.razor.cs │ ├── wwwroot │ │ ├── favicon.ico │ │ ├── icon-192.png │ │ └── index.html │ ├── Models │ │ └── TodoModel.cs │ ├── Pages │ │ ├── Index.razor │ │ ├── Login.razor │ │ └── Components │ │ │ ├── TodoList.razor.cs │ │ │ └── TodoList.razor │ ├── _Imports.razor │ ├── App.razor │ ├── Program.cs │ ├── Example.csproj │ └── Properties │ │ └── launchSettings.json ├── pocketbase-csharp-sdk.Tests │ ├── Usings.cs │ ├── pocketbase-csharp-sdk.Tests.csproj │ └── PocketBaseTests.cs ├── pocketbase-csharp-sdk │ ├── Models │ │ ├── Auth │ │ │ ├── UserAuthModel.cs │ │ │ ├── AuthModel.cs │ │ │ ├── AdminAuthModel.cs │ │ │ └── RecordAuthModel.cs │ │ ├── UserModel.cs │ │ ├── ApiHealthModel.cs │ │ ├── PagedCollectionModel.cs │ │ ├── Files │ │ │ ├── BaseFile.cs │ │ │ ├── IFile.cs │ │ │ ├── StreamFile.cs │ │ │ └── FilepathFile.cs │ │ ├── Log │ │ │ ├── AuthMethodsList.cs │ │ │ ├── LogRequestStatistic.cs │ │ │ ├── AuthMethodProvider.cs │ │ │ └── LogRequestModel.cs │ │ ├── Collection │ │ │ ├── SchemaFieldModel.cs │ │ │ ├── CollectionOptionsModel.cs │ │ │ └── CollectionModel.cs │ │ ├── AdminModel.cs │ │ ├── IBaseAuthModel.cs │ │ ├── ResultList.cs │ │ ├── IBaseModel.cs │ │ ├── BaseAuthModel.cs │ │ ├── ExternalAuthModel.cs │ │ ├── Enum │ │ │ └── ThumbFormat.cs │ │ └── BaseModel.cs │ ├── Event │ │ ├── RequestEventArgs.cs │ │ └── ResponseEventArgs.cs │ ├── Services │ │ ├── AdminService.cs │ │ ├── HealthService.cs │ │ └── RecordService.cs │ ├── Helper │ │ ├── Extensions │ │ │ └── DictionaryExtensions.cs │ │ └── Convert │ │ │ └── SafeConvert.cs │ ├── AuthStoreEvent.cs │ ├── AssemblyInfo.cs │ ├── Json │ │ └── DateTimeConverter.cs │ ├── pocketbase-csharp-sdk.csproj │ ├── pocketbase-csharp-sdk - Backup.csproj │ └── ClientException.cs ├── .github │ └── workflows │ │ └── main.yml ├── LICENSE.txt ├── .vscode │ ├── launch.json │ └── tasks.json └── README.md ├── src ├── Test │ ├── PocketBaseClient.Test │ │ ├── Usings.cs │ │ └── PocketBaseClient.Test.csproj │ └── PocketBaseClient.DemoTest │ │ ├── PocketBaseClient.DemoTest.csproj │ │ ├── Models │ │ ├── Post.TagsList.cs │ │ ├── Tag.Sorts.cs │ │ ├── Category.Sorts.cs │ │ ├── Post.CategoriesList.cs │ │ ├── Tag.Filters.cs │ │ ├── Users2.Sorts.cs │ │ ├── Category.Filters.cs │ │ ├── Users2.Filters.cs │ │ ├── TestForType.SelectMultipleList.cs │ │ ├── TestForType.RelationMultipleLimitList.cs │ │ ├── TestForType.RelationMultipleNoLimitList.cs │ │ ├── User.AvatarFile.cs │ │ ├── Post.StatusEnum.cs │ │ ├── TestForType.FileMultipleRestrictionsList.cs │ │ ├── TestForType.FileMultipleNoRestrictionsList.cs │ │ ├── TestForType.FileSingleNoRestrictionFile.cs │ │ ├── TestForType.FileMultipleNoRestrictionsFile.cs │ │ ├── User.Sorts.cs │ │ ├── User.Filters.cs │ │ ├── TestForRelated.Sorts.cs │ │ ├── TestForType.FileSingleRestrictionFile.cs │ │ ├── Author.Sorts.cs │ │ ├── TestForType.FileMultipleRestrictionsFile.cs │ │ ├── TestForRelated.Filters.cs │ │ ├── TestForType.SelectSingleEnum.cs │ │ ├── TestForType.SelectMultipleEnum.cs │ │ ├── Author.Filters.cs │ │ ├── CollectionTags.cs │ │ ├── CollectionPosts.cs │ │ ├── CollectionUsers.cs │ │ ├── CollectionUsers2.cs │ │ ├── CollectionAuthors.cs │ │ ├── CollectionCategories.cs │ │ ├── CollectionTestForTypes.cs │ │ ├── CollectionTestForRelateds.cs │ │ └── Post.Sorts.cs │ │ ├── DemoTestApplication.cs │ │ └── Services │ │ └── DemoTestAuthService.cs ├── PocketBaseClient.CodeGenerator │ ├── PocketBaseClient.CodeGenerator.csproj.user │ ├── Properties │ │ └── PublishProfiles │ │ │ ├── FolderProfile-osx-x64.pubxml.user │ │ │ ├── FolderProfile-linux-x64.pubxml.user │ │ │ ├── FolderProfile-osx-x64.pubxml │ │ │ ├── FolderProfile-win-x64.pubxml │ │ │ ├── FolderProfile-linux-x64.pubxml │ │ │ └── FolderProfile-win-x64.pubxml.user │ ├── Interactive │ │ └── MainActions.cs │ ├── Models │ │ ├── PocketBaseFieldOptionsNumber.cs │ │ ├── PocketBaseApplicationModel.cs │ │ ├── PocketBaseFieldOptionsDateTime.cs │ │ ├── PocketBaseFieldOptionsText.cs │ │ ├── PocketBaseFieldOptionsSelect.cs │ │ ├── PocketBaseCredentials.cs │ │ ├── PocketBaseFieldOptionsRelation.cs │ │ └── PocketBaseFieldOptionsEmailUrl.cs │ ├── Generation │ │ ├── FieldInfoBool.cs │ │ ├── FieldInfoJson.cs │ │ ├── GeneratedCodeFile.cs │ │ ├── FieldInfoFileOne.cs │ │ ├── FieldInfoSelectOne.cs │ │ └── FieldInfoRelationOne.cs │ ├── Program.cs │ └── PocketBaseClient.CodeGenerator.csproj └── PocketBaseClient │ ├── Properties │ └── PublishProfiles │ │ └── FolderProfile.pubxml │ ├── Orm │ ├── Filters │ │ ├── FilterCommandComposeOptions.cs │ │ ├── FieldFilter.cs │ │ ├── ItemBaseSorts.cs │ │ ├── ItemBaseFilters.cs │ │ ├── FilterCommandComposed.cs │ │ ├── ItemAuthBaseSorts.cs │ │ ├── ItemAuthBaseFilters.cs │ │ ├── FieldFilterMailAddress.cs │ │ ├── FieldFilterEnum.cs │ │ ├── FieldFilterBool.cs │ │ └── FieldFilterUri.cs │ ├── Structures │ │ ├── FileOrigins.cs │ │ ├── IFieldItemList[T].cs │ │ ├── ILimitable.cs │ │ ├── IBasicCollection.cs │ │ ├── GetItemsFilter.cs │ │ ├── IOwnedByItem.cs │ │ ├── IFieldBasicList[T].cs │ │ ├── ListSaveDiscardModes.cs │ │ ├── Thumbnail.cs │ │ ├── IBasicList[T].cs │ │ └── IFieldFileList[T].cs │ ├── ItemSyncStatuses.cs │ ├── Json │ │ ├── UrlConverter.cs │ │ ├── EmailConverter.cs │ │ ├── FileConverter.cs │ │ ├── RelationConverter.cs │ │ ├── EnumConverter.cs │ │ ├── FileListConverter.cs │ │ ├── RelationListConverter.cs │ │ └── EnumListConverter.cs │ ├── CollectionAuthBase[T].cs │ ├── CollectionBase.ItemList.cs │ └── Validators │ │ ├── OnlyDomainsAttribute.cs │ │ └── ExceptDomainsAttribute.cs │ ├── Services │ ├── ServiceBase.cs │ └── AuthServiceBase.cs │ ├── Extensions │ ├── ObjectExtensions.cs │ ├── RandomExtensions.cs │ └── EnumExtensions.cs │ ├── PocketBaseClient.csproj │ └── PocketBaseClientApplication.cs ├── .github └── FUNDING.yml ├── pull_sdk.bat ├── doc ├── img │ ├── pbcodegen-generatefull.gif │ └── PocketBase_Collection_posts.png └── pbcodegen.md ├── .gitignore └── LICENSE /sdk/Example/Shared/RedirectTo.razor: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.Test/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ["https://www.buymeacoffee.com/iluvadev", Buy me a coffe] 2 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk.Tests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using Microsoft.VisualStudio.TestTools.UnitTesting; -------------------------------------------------------------------------------- /sdk/Example/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iluvadev/PocketBaseClient/HEAD/sdk/Example/wwwroot/favicon.ico -------------------------------------------------------------------------------- /pull_sdk.bat: -------------------------------------------------------------------------------- 1 | git subtree pull --prefix sdk https://github.com/iluvadev/pocketbase-csharp-sdk.git master --squash 2 | 3 | pause -------------------------------------------------------------------------------- /sdk/Example/wwwroot/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iluvadev/PocketBaseClient/HEAD/sdk/Example/wwwroot/icon-192.png -------------------------------------------------------------------------------- /doc/img/pbcodegen-generatefull.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iluvadev/PocketBaseClient/HEAD/doc/img/pbcodegen-generatefull.gif -------------------------------------------------------------------------------- /doc/img/PocketBase_Collection_posts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iluvadev/PocketBaseClient/HEAD/doc/img/PocketBase_Collection_posts.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | src/.vs/PocketClient/v17/.suo 3 | src/.vs/PocketClient/v17/.suo 4 | .vs 5 | bin 6 | obj 7 | *.user 8 | *.user 9 | *.user 10 | *.user 11 | -------------------------------------------------------------------------------- /sdk/Example/Shared/Loading.razor: -------------------------------------------------------------------------------- 1 | @if (!Visible ?? false) 2 | { 3 | 4 | } 5 | else 6 | { 7 | @ChildContent 8 | } -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Auth/UserAuthModel.cs: -------------------------------------------------------------------------------- 1 | namespace pocketbase_csharp_sdk.Models.Auth 2 | { 3 | public class UserAuthModel : RecordAuthModel 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /sdk/Example/Models/TodoModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Models; 2 | 3 | namespace Example.Models 4 | { 5 | public class TodoModel : BaseModel 6 | { 7 | public string? Name { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sdk/Example/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | ToDo-Example 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sdk/Example/Shared/Loading.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | 3 | namespace Example.Shared 4 | { 5 | public partial class Loading 6 | { 7 | [Parameter] 8 | public bool? Visible { get; set; } 9 | 10 | [Parameter] 11 | public RenderFragment? ChildContent { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Auth/AuthModel.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace pocketbase_csharp_sdk.Models.Auth 4 | { 5 | public abstract class AuthModel 6 | { 7 | public string? Token { get; set; } 8 | 9 | [JsonIgnore] 10 | public abstract IBaseModel? Model { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/UserModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models 8 | { 9 | public class UserModel : BaseAuthModel 10 | { 11 | public string? Avatar { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/ApiHealthModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models 8 | { 9 | public class ApiHealthModel 10 | { 11 | public int? Code { get; set; } 12 | public string? Message { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/PagedCollectionModel.cs: -------------------------------------------------------------------------------- 1 | namespace pocketbase_csharp_sdk.Models 2 | { 3 | public class PagedCollectionModel 4 | { 5 | public int Page { get; set; } 6 | public int PerPage { get; set; } 7 | public int TotalItems { get; set; } 8 | public int TotalPages { get; set; } 9 | public T[]? Items { get; set; } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Auth/AdminAuthModel.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace pocketbase_csharp_sdk.Models.Auth 4 | { 5 | public class AdminAuthModel : AuthModel 6 | { 7 | [JsonIgnore] 8 | public override IBaseModel? Model => Admin; 9 | 10 | 11 | [JsonPropertyName("admin")] 12 | public AdminModel? Admin { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Files/BaseFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Files 8 | { 9 | public abstract class BaseFile 10 | { 11 | public string? FieldName { get; set; } 12 | public string? FileName { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/PocketBaseClient.DemoTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/PocketBaseClient.CodeGenerator.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Dev\iluvadev\projects\PocketBaseClient-csharp\src\PocketBaseClient.CodeGenerator\Properties\PublishProfiles\FolderProfile-win-x64.pubxml 5 | 6 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\Release\net6.0\publish\ 10 | FileSystem 11 | <_TargetId>Folder 12 | 13 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Log/AuthMethodsList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Log 8 | { 9 | public class AuthMethodsList 10 | { 11 | public bool? UsernamePassword { get; set; } 12 | public bool? EmailPassword { get; set; } 13 | public IEnumerable? AuthProviders { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Auth/RecordAuthModel.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace pocketbase_csharp_sdk.Models.Auth 4 | { 5 | public class RecordAuthModel : AuthModel where T : IBaseAuthModel 6 | { 7 | [JsonIgnore] 8 | public override IBaseModel? Model => Record; 9 | 10 | [JsonPropertyName("record")] 11 | public T? Record { get; set; } 12 | 13 | public IDictionary? meta { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Collection/SchemaFieldModel.cs: -------------------------------------------------------------------------------- 1 | namespace pocketbase_csharp_sdk.Models.Collection 2 | { 3 | public class SchemaFieldModel 4 | { 5 | public string? Id { get; set; } 6 | public string? Name { get; set; } 7 | public string? Type { get; set; } 8 | public bool? System { get; set; } 9 | public bool? Required { get; set; } 10 | public bool? Unique { get; set; } 11 | public IDictionary? Options { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/AdminModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json.Serialization; 6 | using System.Threading.Tasks; 7 | 8 | namespace pocketbase_csharp_sdk.Models 9 | { 10 | public class AdminModel : BaseModel 11 | { 12 | [JsonPropertyName("email")] 13 | public string? Email { get; set; } 14 | 15 | [JsonPropertyName("avatar")] 16 | public int? Avatar { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/IBaseAuthModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json.Serialization; 6 | using System.Threading.Tasks; 7 | 8 | namespace pocketbase_csharp_sdk.Models 9 | { 10 | public interface IBaseAuthModel : IBaseModel 11 | { 12 | string? Email { get; } 13 | 14 | bool? EmailVisibility { get; } 15 | 16 | string? Username { get; } 17 | 18 | bool? Verified { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sdk/Example/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Authorization; 4 | @using Microsoft.AspNetCore.Components.Authorization 5 | @using Microsoft.AspNetCore.Components.Forms 6 | @using Microsoft.AspNetCore.Components.Routing 7 | @using Microsoft.AspNetCore.Components.Web 8 | @using Microsoft.AspNetCore.Components.Web.Virtualization 9 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 10 | @using Microsoft.JSInterop 11 | @using Example 12 | @using Example.Shared 13 | @using MudBlazor -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Log/LogRequestStatistic.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Models.Log 10 | { 11 | public class LogRequestStatistic 12 | { 13 | public int? Total { get; set; } 14 | 15 | [JsonConverter(typeof(DateTimeConverter))] 16 | public DateTime? Date { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/ResultList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models 8 | { 9 | public class ResultList where T : class 10 | { 11 | public int? Page { get; set; } 12 | public int? PerPage { get; set; } 13 | public int? TotalItems { get; set; } 14 | public int? TotalPages { get; set; } 15 | public IEnumerable? Items { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-osx-x64.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | True|2023-02-07T17:36:29.6710918Z;True|2023-01-15T14:23:53.8213289+01:00;True|2022-12-31T12:06:36.5486629+01:00;True|2022-12-18T21:24:07.4853077+01:00;True|2022-12-13T21:20:16.4813222+01:00;True|2022-12-11T20:48:46.5037967+01:00; 8 | 9 | 10 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Files/IFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Files 8 | { 9 | 10 | /// 11 | /// simple Interface needed for uploading files to PocketBase 12 | /// 13 | public interface IFile 14 | { 15 | public string? FieldName { get; set; } 16 | public string? FileName { get; set; } 17 | public Stream? GetStream(); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/IBaseModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Models 10 | { 11 | public interface IBaseModel 12 | { 13 | string? Id { get; } 14 | 15 | DateTime? Created { get; } 16 | 17 | DateTime? Updated { get; } 18 | 19 | string? CollectionId { get; } 20 | 21 | string? CollectionName { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Event/RequestEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Event 8 | { 9 | public class RequestEventArgs : EventArgs 10 | { 11 | 12 | public Uri Url { get; } 13 | public HttpRequestMessage HttpRequest { get; } 14 | 15 | public RequestEventArgs(Uri url, HttpRequestMessage httpRequest) 16 | { 17 | Url = url; 18 | HttpRequest = httpRequest; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Event/ResponseEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Event 8 | { 9 | public class ResponseEventArgs : EventArgs 10 | { 11 | 12 | public Uri Url { get; } 13 | public HttpResponseMessage? HttpResponse { get; } 14 | 15 | public ResponseEventArgs(Uri url, HttpResponseMessage? httpResponse) 16 | { 17 | Url = url; 18 | HttpResponse = httpResponse; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Services/AdminService.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Models; 2 | using pocketbase_csharp_sdk.Models.Auth; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Services 10 | { 11 | public class AdminService : BaseAuthService 12 | { 13 | 14 | protected override string BasePath(string? url = null) => "/api/admins"; 15 | 16 | public AdminService(PocketBase client) : base(client) 17 | { 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sdk/Example/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | 4 | 5 | Example-Todo-App 6 | 7 | 8 | 9 | 10 | 11 | @Body 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Log/AuthMethodProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Log 8 | { 9 | public class AuthMethodProvider 10 | { 11 | public string? Name { get; set; } 12 | public string? State { get; set; } 13 | public string? CodeVerifier { get; set; } 14 | public string? CodeChallenge { get; set; } 15 | public string? CodeChallengeMethod { get; set; } 16 | public string? AuthUrl { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-linux-x64.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | True|2023-02-07T17:34:47.7075835Z;True|2023-01-15T14:22:36.0717463+01:00;True|2022-12-31T12:07:50.2901693+01:00;True|2022-12-18T21:25:02.1023339+01:00;True|2022-12-13T21:22:06.3214098+01:00;True|2022-12-11T20:47:35.6586370+01:00;True|2022-12-11T20:36:53.9796310+01:00;True|2022-12-11T20:31:20.0881522+01:00; 8 | 9 | 10 | -------------------------------------------------------------------------------- /sdk/.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | deploy-to-github-pages: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v3.3.0 11 | 12 | - name: Setup .NET Core 13 | uses: actions/setup-dotnet@v3.0.3 14 | with: 15 | dotnet-version: 6.0.x 16 | 17 | - name: Install WASM Build Tools 18 | run: dotnet workload install wasm-tools 19 | 20 | - name: Publish .NET Core Project 21 | run: dotnet publish Example/Example.csproj -c:Release -o dist/Web --nologo 22 | -------------------------------------------------------------------------------- /sdk/Example/Shared/RedirectTo.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | 3 | namespace Example.Shared 4 | { 5 | public partial class RedirectTo 6 | { 7 | [Inject] 8 | public NavigationManager NavigationManager { get; set; } = null!; 9 | 10 | [Parameter] 11 | public string? To { get; set; } 12 | 13 | protected override void OnInitialized() 14 | { 15 | if (!string.IsNullOrWhiteSpace(To)) 16 | { 17 | NavigationManager.NavigateTo(To); 18 | } 19 | 20 | base.OnInitialized(); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Helper/Extensions/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Helper.Extensions 8 | { 9 | internal static class DictionaryExtensions 10 | { 11 | public static void AddIfNotNull(this IDictionary dictionary, TKey key, TValue? value) 12 | { 13 | if (value is null) 14 | { 15 | return; 16 | } 17 | dictionary[key] = value; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sdk/Example/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Not found 9 | 10 |

Sorry, there's nothing at this address.

11 |
12 |
13 |
14 |
-------------------------------------------------------------------------------- /sdk/Example/Shared/MainLayout.razor.cs: -------------------------------------------------------------------------------- 1 | using MudBlazor; 2 | 3 | namespace Example.Shared 4 | { 5 | public partial class MainLayout 6 | { 7 | 8 | public bool UseDarkmode { get; set; } = false; 9 | 10 | //fields 11 | protected MudThemeProvider? themeProvider = null!; 12 | 13 | protected override async Task OnAfterRenderAsync(bool firstRender) 14 | { 15 | if (firstRender) 16 | { 17 | UseDarkmode = await themeProvider!.GetSystemPreference(); 18 | StateHasChanged(); 19 | } 20 | await base.OnAfterRenderAsync(firstRender); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-osx-x64.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\publish\net6.0\osx-x64 10 | FileSystem 11 | <_TargetId>Folder 12 | net6.0 13 | osx-x64 14 | true 15 | true 16 | 17 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-win-x64.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\publish\net6.0\win-x64 10 | FileSystem 11 | <_TargetId>Folder 12 | net6.0 13 | win-x64 14 | true 15 | true 16 | 17 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-linux-x64.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\publish\net6.0\linux-x64 10 | FileSystem 11 | <_TargetId>Folder 12 | net6.0 13 | linux-x64 14 | true 15 | true 16 | 17 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FilterCommandComposeOptions.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | internal enum FilterCommandComposeOptions 14 | { 15 | And = 1, 16 | Or = 2, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Properties/PublishProfiles/FolderProfile-win-x64.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | True|2023-02-07T17:37:50.8257302Z;True|2023-01-15T14:24:59.1258723+01:00;True|2022-12-31T12:05:26.7859059+01:00;True|2022-12-31T12:02:31.1762835+01:00;True|2022-12-18T21:23:09.2727164+01:00;True|2022-12-18T21:21:07.5941836+01:00;True|2022-12-13T21:23:07.0110199+01:00;True|2022-12-11T20:46:22.2560915+01:00;True|2022-12-11T20:44:02.9733735+01:00;True|2022-12-11T20:40:15.9177442+01:00;True|2022-12-11T20:38:22.8023067+01:00; 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/FileOrigins.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | public enum FileOrigins 14 | { 15 | Unknown = 0, 16 | PocketBase = 1, 17 | LocalSystem = 2, 18 | MemoryStream = 3, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/AuthStoreEvent.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace pocketbase_csharp_sdk 9 | { 10 | public class AuthStoreEvent 11 | { 12 | 13 | public string? Token { get; private set; } 14 | public IBaseModel? Model { get; private set; } 15 | 16 | public AuthStoreEvent(string? token, IBaseModel? model) 17 | { 18 | Token = token; 19 | Model = model; 20 | } 21 | 22 | public override string ToString() 23 | { 24 | return $"token: {Token}{Environment.NewLine}model: {Model}"; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/BaseAuthModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json.Serialization; 6 | using System.Threading.Tasks; 7 | 8 | namespace pocketbase_csharp_sdk.Models 9 | { 10 | public class BaseAuthModel : BaseModel, IBaseAuthModel 11 | { 12 | [JsonPropertyName("email")] 13 | public string? Email { get; set; } 14 | 15 | [JsonPropertyName("emailVisibility")] 16 | public bool? EmailVisibility { get; set; } 17 | 18 | [JsonPropertyName("username")] 19 | public string? Username { get; set; } 20 | 21 | [JsonPropertyName("verified")] 22 | public bool? Verified { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Collection/CollectionOptionsModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Collection 8 | { 9 | public class CollectionOptionsModel 10 | { 11 | public bool? AllowEmailAuth { get; set; } 12 | public bool? AllowOAuth2Auth { get; set; } 13 | public bool? AllowUsernameAuth { get; set; } 14 | public bool? RequireEmail { get; set; } 15 | public int? MinPasswordLength { get; set; } 16 | 17 | public string? ExceptEmailDomains { get; set; } 18 | public string? OnlyEmailDomains { get; set; } 19 | 20 | public string? ManageRule { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Files/StreamFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Files 8 | { 9 | 10 | /// 11 | /// simple class for uploading files to PocketBase, accepting a Stream 12 | /// 13 | public class StreamFile : BaseFile, IFile 14 | { 15 | public Stream? Stream { get; set; } 16 | 17 | public Stream? GetStream() 18 | { 19 | return Stream; 20 | } 21 | 22 | public StreamFile() 23 | { 24 | 25 | } 26 | 27 | public StreamFile(Stream? stream) 28 | { 29 | this.Stream = stream; 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/Example/Pages/Login.razor: -------------------------------------------------------------------------------- 1 | @page "/login" 2 | 3 | 4 | 5 | 6 | Login 7 | Username: demo Password: demo1234 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Login 16 | 17 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IFieldItemList[T].cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | 14 | /// 15 | /// Definition for field types of Lists of Items 16 | /// 17 | public interface IFieldItemList : IFieldBasicList, IItemList 18 | where T : ItemBase, new() 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/ILimitable.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | /// 14 | /// Definition for types with Limit in size 15 | /// 16 | public interface ILimitable 17 | { 18 | /// 19 | /// The Max Size 20 | /// 21 | int? MaxSize { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/ExternalAuthModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Models 10 | { 11 | public class ExternalAuthModel 12 | { 13 | public string? Id { get; set; } 14 | 15 | [JsonConverter(typeof(DateTimeConverter))] 16 | public DateTime? Created { get; set; } 17 | 18 | [JsonConverter(typeof(DateTimeConverter))] 19 | public DateTime? Updated { get; set; } 20 | 21 | public string? RecordId { get; set; } 22 | public string? CollectionId { get; set; } 23 | public string? Provider { get; set; } 24 | public string? ProviderId { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /doc/pbcodegen.md: -------------------------------------------------------------------------------- 1 | # pbcodegen 2 | 3 | pbcodegen is the **PocketBaseClient.CodeGenerator**, the application that does all the magic: Creates an ORM for your PocketBase Application, your own PocketBaseClient. 4 | 5 | And all this, in less than 1 minunte. You can watch the entire process in the unedited recording below: 6 | 7 | ![](img/pbcodegen-generatefull.gif) 8 | 9 | As you can see, the process is simple: 10 | 11 | - It connects to the PocketBase Application with admin rigths 12 | 13 | - Downloads all schema and needed information 14 | 15 | - Generates a c# project for you, creating all needed classes and structures 16 | 17 | The project generated has the correct dependences to nuget packages: there is no need to modify it. 18 | 19 | 20 | 21 | 22 | 23 | Download the latest version from the [Releases section](https://github.com/iluvadev/PocketBaseClient-csharp/releases), and follow the process. 24 | -------------------------------------------------------------------------------- /sdk/Example/Program.cs: -------------------------------------------------------------------------------- 1 | using Blazored.LocalStorage; 2 | using Example; 3 | using Microsoft.AspNetCore.Components.Authorization; 4 | using Microsoft.AspNetCore.Components.Web; 5 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 6 | using MudBlazor.Services; 7 | using pocketbase_csharp_sdk; 8 | 9 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 10 | builder.RootComponents.Add("#app"); 11 | builder.RootComponents.Add("head::after"); 12 | 13 | builder.Services.AddSingleton(sp => 14 | { 15 | return new PocketBase("https://sdk-todo-example.pockethost.io/"); 16 | }); 17 | 18 | builder.Services.AddBlazoredLocalStorage(); 19 | builder.Services.AddMudServices(); 20 | 21 | //Authentication 22 | builder.Services.AddScoped(); 23 | builder.Services.AddAuthorizationCore(); 24 | 25 | await builder.Build().RunAsync(); 26 | -------------------------------------------------------------------------------- /sdk/Example/Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Interactive/MainActions.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.ComponentModel.DataAnnotations; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Interactive 14 | { 15 | /// 16 | /// Main actions to do in interactive mode 17 | /// 18 | internal enum MainActions 19 | { 20 | [Display(Name = "Generate code for first time")] 21 | GenerateNew, 22 | 23 | [Display(Name = "Regenerate code")] 24 | Regenerate, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Helper/Convert/SafeConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Helper.Convert 8 | { 9 | public static class SafeConvert 10 | { 11 | public static int ToInt(this object? obj, int defaultValue = 0) 12 | { 13 | if (obj is null) 14 | { 15 | return defaultValue; 16 | } 17 | 18 | if (int.TryParse(obj.ToString(), out var result)) 19 | { 20 | return result; 21 | } 22 | 23 | return defaultValue; 24 | } 25 | 26 | public static string ToString(this object? obj, string defaultValue = "") 27 | { 28 | if (obj is null) 29 | { 30 | return defaultValue; 31 | } 32 | 33 | return obj.ToString()!; 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sdk/Example/Pages/Components/TodoList.razor.cs: -------------------------------------------------------------------------------- 1 | using Example.Models; 2 | using Microsoft.AspNetCore.Components; 3 | using pocketbase_csharp_sdk; 4 | 5 | namespace Example.Pages.Components 6 | { 7 | public partial class TodoList 8 | { 9 | [Inject] 10 | public PocketBase PocketBase { get; set; } = null!; 11 | 12 | private bool isLoading = false; 13 | private IEnumerable? todos; 14 | 15 | protected override async Task OnInitializedAsync() 16 | { 17 | await LoadTodosFromPocketbase(); 18 | await base.OnInitializedAsync(); 19 | } 20 | 21 | protected async Task LoadTodosFromPocketbase() 22 | { 23 | isLoading = true; 24 | todos = await PocketBase.Records.GetFullListAsync("todos", batch: 1); 25 | isLoading = true; 26 | } 27 | 28 | protected void NavigateToTodoList(TodoModel model) 29 | { 30 | 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Enum/ThumbFormat.cs: -------------------------------------------------------------------------------- 1 | namespace pocketbase_csharp_sdk.Enum 2 | { 3 | public enum ThumbFormat 4 | { 5 | CropToWxHFromCenter, 6 | CropToWxHFromTop, 7 | CropToWxHFromBottom, 8 | FitInsideWxHViewbox, 9 | ResizeToHeight, 10 | ResizeToWidth 11 | } 12 | 13 | internal static class ThumbFormatHelper 14 | { 15 | 16 | public static string GetNameForQuery(ThumbFormat? thumbFormat) 17 | { 18 | return thumbFormat switch 19 | { 20 | ThumbFormat.CropToWxHFromCenter => "WxH", 21 | ThumbFormat.CropToWxHFromTop => "WxT", 22 | ThumbFormat.CropToWxHFromBottom => "WxB", 23 | ThumbFormat.FitInsideWxHViewbox => "WxHf", 24 | ThumbFormat.ResizeToHeight => "0xH", 25 | ThumbFormat.ResizeToWidth => "Wx0", 26 | _ => string.Empty 27 | }; 28 | } 29 | 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /sdk/Example/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Example 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
Loading...
18 | 19 |
20 | An unhandled error has occurred. 21 | Reload 22 | 🗙 23 |
24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Services/ServiceBase.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Services 12 | { 13 | /// 14 | /// Base class for a Service 15 | /// 16 | public abstract class ServiceBase 17 | { 18 | internal PocketBaseClientApplication App { get; } 19 | 20 | /// 21 | /// Ctor 22 | /// 23 | /// 24 | public ServiceBase(PocketBaseClientApplication app) 25 | { 26 | App = app; 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Example/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:44938", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "Example": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "http://localhost:5148", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "IIS Express": { 22 | "commandName": "IISExpress", 23 | "launchBrowser": true, 24 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Example/Pages/Components/TodoList.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | To-Do List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | @foreach (var item in todos!) 16 | { 17 | 18 | @item.Name 19 | 20 | } 21 | 22 | 23 | 24 | 25 | Learn More 26 | 27 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Post.TagsList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Post 17 | { 18 | public class TagsList : FieldItemList 19 | { 20 | public TagsList() : this(null) { } 21 | 22 | public TagsList(Post? post) : base(post, "Tags", "vqnnjaiq", null) { } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/BaseModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System.Text.Json; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace pocketbase_csharp_sdk.Models 6 | { 7 | public abstract class BaseModel : IBaseModel 8 | { 9 | [JsonPropertyName("id")] 10 | public virtual string? Id { get; set; } 11 | 12 | [JsonPropertyName("created")] 13 | [JsonConverter(typeof(DateTimeConverter))] 14 | public virtual DateTime? Created { get; set; } 15 | 16 | [JsonPropertyName("updated")] 17 | [JsonConverter(typeof(DateTimeConverter))] 18 | public virtual DateTime? Updated { get; set; } 19 | 20 | [JsonPropertyName("collectionId")] 21 | public virtual string? CollectionId { get; set; } 22 | 23 | [JsonPropertyName("collectionName")] 24 | public virtual string? CollectionName { get; set; } 25 | 26 | public override string ToString() 27 | { 28 | return JsonSerializer.Serialize(this); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IBasicCollection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PocketBaseClient.Orm.Structures 8 | { 9 | public interface IBasicCollection : IBasicList 10 | { 11 | /// 12 | /// Save Changes in the list (async) 13 | /// 14 | /// Says what to save 15 | /// 16 | Task SaveChangesAsync(ListSaveDiscardModes mode); 17 | 18 | /// 19 | /// Save Changes in the list 20 | /// 21 | /// Says what to save 22 | /// 23 | bool SaveChanges(ListSaveDiscardModes mode); 24 | 25 | /// 26 | /// Discard changes in list 27 | /// 28 | /// Says what to discard 29 | void DiscardChanges(ListSaveDiscardModes mode); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Tag.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Tag 17 | { 18 | public class Sorts : ItemBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'name' field 22 | public SortCommand Name => new SortCommand("name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | // In Projekten im SDK-Stil wie dem vorliegenden, bei dem verschiedene Assemblyattribute 4 | // üblicherweise in dieser Datei definiert wurden, werden diese Attribute jetzt während 5 | // der Builderstellung automatisch hinzugefügt und mit Werten aufgefüllt, die in den 6 | // Projekteigenschaften definiert sind. Informationen dazu, welche Attribute einbezogen 7 | // werden und wie dieser Prozess angepasst werden kann, finden Sie unter https://aka.ms/assembly-info-properties. 8 | 9 | 10 | // Wenn "ComVisible" auf FALSE festgelegt wird, sind die Typen in dieser Assembly 11 | // für COM-Komponenten nicht sichtbar. Wenn Sie von COM aus auf einen Typ in dieser 12 | // Assembly zugreifen müssen, legen Sie das ComVisible-Attribut für den betreffenden 13 | // Typ auf TRUE fest. 14 | 15 | [assembly: ComVisible(false)] 16 | 17 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM 18 | // bereitgestellt wird. 19 | 20 | [assembly: Guid("b364068a-74d7-4f7e-b966-e3e2cce15b1c")] 21 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Category.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Category 17 | { 18 | public class Sorts : ItemBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'name' field 22 | public SortCommand Name => new SortCommand("name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Post.CategoriesList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Post 17 | { 18 | public class CategoriesList : FieldItemList 19 | { 20 | public CategoriesList() : this(null) { } 21 | 22 | public CategoriesList(Post? post) : base(post, "Categories", "2ftkqyzs", 3) { } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Tag.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Tag 17 | { 18 | public class Filters : ItemBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'name' field in PocketBase 22 | public FieldFilterText Name => new FieldFilterText("name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Users2.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Users2 17 | { 18 | public class Sorts : ItemAuthBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'public_name' field 22 | public SortCommand PublicName => new SortCommand("public_name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Log/LogRequestModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Models.Log 10 | { 11 | public class LogRequestModel 12 | { 13 | public string? Id { get; set; } 14 | 15 | [JsonConverter(typeof(DateTimeConverter))] 16 | public DateTime? Created { get; set; } 17 | 18 | [JsonConverter(typeof(DateTimeConverter))] 19 | public DateTime? Updated { get; set; } 20 | 21 | public string? Url { get; set; } 22 | public string? Method { get; set; } 23 | public int? Status { get; set; } 24 | public string? Auth { get; set; } 25 | public string? RemoteIP { get; set; } 26 | public string? UserIP { get; set; } 27 | public string? Referer { get; set; } 28 | public string? UserAgent { get; set; } 29 | public IDictionary? Meta { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Category.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Category 17 | { 18 | public class Filters : ItemBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'name' field in PocketBase 22 | public FieldFilterText Name => new FieldFilterText("name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/GetItemsFilter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | /// 14 | /// Filter to apply in GetItems 15 | /// 16 | [Flags] 17 | public enum GetItemsFilter : short 18 | { 19 | /// No filter 20 | None = 0, 21 | 22 | /// Load items from PocketBase 23 | Load = 1, 24 | 25 | /// Created items not synced to PocketBase 26 | New = 2, 27 | 28 | /// Removed items not synced to PocketBase 29 | Erased = 4, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Users2.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Users2 17 | { 18 | public class Filters : ItemAuthBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'public_name' field in PocketBase 22 | public FieldFilterText PublicName => new FieldFilterText("public_name"); 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FieldFilter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Base class for a Filter over a Field 15 | /// 16 | public abstract class FieldFilter 17 | { 18 | /// 19 | /// The Field name to be filtered 20 | /// 21 | protected string FieldName { get; } 22 | 23 | /// 24 | /// Ctor 25 | /// 26 | /// 27 | public FieldFilter(string fieldName) 28 | { 29 | FieldName = fieldName; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 iluvadev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/ItemSyncStatuses.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm 12 | { 13 | /// 14 | /// Statuses of synchronization for an Item 15 | /// 16 | public enum ItemSyncStatuses 17 | { 18 | /// Unknown status 19 | Unknown = 0, 20 | 21 | /// The item is not Created in PocketBase 22 | ToBeCreated = 1, 23 | 24 | /// The item is Loaded (partially or not) from PocketBase 25 | Loaded = 2, 26 | 27 | /// The item is deleted but not yet in PocketBase 28 | ToBeDeleted = 3, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IOwnedByItem.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | 12 | namespace PocketBaseClient.Orm.Structures 13 | { 14 | /// 15 | /// Definition for types that belongs to an ItemBase 16 | /// 17 | public interface IOwnedByItem 18 | { 19 | /// 20 | /// The Owner 21 | /// 22 | ItemBase? Owner { get; set; } 23 | 24 | /// 25 | /// Notifies a modification of the field to the Owner 26 | /// 27 | void NotifyModificationToOwner() 28 | //=> Owner?.SetPropertyModified(Name); 29 | => Owner?.SetModified(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.SelectMultipleList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public class SelectMultipleList : FieldBasicList 19 | { 20 | public SelectMultipleList() : this(null) { } 21 | 22 | public SelectMultipleList(TestForType? testForType) : base(testForType, "SelectMultiple", "8dks1xfy", 10) { } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 PRCV1 (the main developer) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.Test/PocketBaseClient.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | all 17 | 18 | 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | all 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.RelationMultipleLimitList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public class RelationMultipleLimitList : FieldItemList 19 | { 20 | public RelationMultipleLimitList() : this(null) { } 21 | 22 | public RelationMultipleLimitList(TestForType? testForType) : base(testForType, "RelationMultipleLimit", "otxwaoam", 5) { } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsNumber.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map PocketBase Options for fields of type Number 17 | /// 18 | public class PocketBaseFieldOptionsNumber 19 | { 20 | /// 21 | /// Max number 22 | /// 23 | [JsonPropertyName("max")] 24 | public float? Max { get; set; } 25 | 26 | /// 27 | /// Min number 28 | /// 29 | [JsonPropertyName("min")] 30 | public float? Min { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.RelationMultipleNoLimitList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public class RelationMultipleNoLimitList : FieldItemList 19 | { 20 | public RelationMultipleNoLimitList() : this(null) { } 21 | 22 | public RelationMultipleNoLimitList(TestForType? testForType) : base(testForType, "RelationMultipleNoLimit", "a4chtr6c", null) { } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk.Tests/pocketbase-csharp-sdk.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | pocketbase_csharp_sdk.Tests 6 | enable 7 | enable 8 | 9 | false 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/User.AvatarFile.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Structures; 14 | 15 | namespace PocketBaseClient.DemoTest.Models 16 | { 17 | public partial class User 18 | { 19 | public class AvatarFile : FieldFileBase 20 | { 21 | 22 | /// 23 | public override long? MaxSize => 5242880; 24 | 25 | public AvatarFile() : base("avatar", owner: null) { } 26 | 27 | public AvatarFile(User? user) : base("avatar", user) { } 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Collection/CollectionModel.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace pocketbase_csharp_sdk.Models.Collection 10 | { 11 | public class CollectionModel 12 | { 13 | public string? Id { get; set; } 14 | 15 | [JsonConverter(typeof(DateTimeConverter))] 16 | public DateTime? Created { get; set; } 17 | [JsonConverter(typeof(DateTimeConverter))] 18 | public DateTime? Updated { get; set; } 19 | 20 | public string? Name { get; set; } 21 | public bool? System { get; set; } 22 | public string? Type { get; set; } 23 | 24 | public string? ListRule { get; set; } 25 | public string? ViewRule { get; set; } 26 | public string? CreateRule { get; set; } 27 | public string? UpdateRule { get; set; } 28 | public string? DeleteRule { get; set; } 29 | 30 | public CollectionOptionsModel? Options { get; set; } 31 | public IEnumerable? Schema { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Json/DateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.Json; 8 | using System.Text.Json.Serialization; 9 | using System.Threading.Tasks; 10 | 11 | namespace pocketbase_csharp_sdk.Json 12 | { 13 | public class DateTimeConverter : JsonConverter 14 | { 15 | public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 16 | { 17 | var value = reader.GetString(); 18 | if (!DateTime.TryParse(value, out var dt)) 19 | return null; 20 | 21 | return DateTime.SpecifyKind(dt, DateTimeKind.Utc); ; 22 | } 23 | 24 | public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options) 25 | { 26 | if (value is null) 27 | { 28 | writer.WriteNullValue(); 29 | } 30 | else 31 | { 32 | writer.WriteStringValue(value?.ToString()); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IFieldBasicList[T].cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | 14 | /// 15 | /// Definition for field types of Lists 16 | /// 17 | public interface IFieldBasicList : IBasicList, IOwnedByItem, ILimitable 18 | { 19 | /// 20 | /// The number of elements in the list 21 | /// 22 | int Count { get; } 23 | 24 | /// 25 | /// Says if the element is contained in the list 26 | /// 27 | /// The element to check if is contained 28 | /// 29 | bool Contains(T? element); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/ItemBaseSorts.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Definition for Sort options to sort filtered data in PocketBase 15 | /// 16 | public class ItemBaseSorts 17 | { 18 | /// Makes a SortCommand to Order by the 'id' field 19 | public SortCommand Id => new SortCommand("id"); 20 | 21 | /// Makes a SortCommand to Order by the 'created' field 22 | public SortCommand Created => new SortCommand("created"); 23 | 24 | /// Makes a SortCommand to Order by the 'updated' field 25 | public SortCommand Updated => new SortCommand("updated"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Services/HealthService.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace pocketbase_csharp_sdk.Services 9 | { 10 | public class HealthService : BaseService 11 | { 12 | private readonly PocketBase pocketBase; 13 | 14 | protected override string BasePath(string? path = null) => "api/health"; 15 | 16 | public HealthService(PocketBase pocketBase) : base(pocketBase) 17 | { 18 | this.pocketBase = pocketBase; 19 | } 20 | 21 | /// 22 | /// Returns the health status of the server. 23 | /// 24 | public Task CheckHealthAsync() 25 | { 26 | return pocketBase.SendAsync(BasePath(), HttpMethod.Get); 27 | } 28 | 29 | /// 30 | /// Returns the health status of the server. 31 | /// 32 | public ApiHealthModel? CheckHealth() 33 | { 34 | return pocketBase.Send(BasePath(), HttpMethod.Get); 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/ListSaveDiscardModes.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | /// 14 | /// Save or Discard modes 15 | /// 16 | public enum ListSaveDiscardModes 17 | { 18 | /// 19 | /// Save or Discard only changes in the list references 20 | /// 21 | OnlyListChanges = 0, 22 | 23 | /// 24 | /// Save or Discard only changes in the objects of the list 25 | /// 26 | OnlyItemsChanges = 1, 27 | 28 | /// 29 | /// Save or Discard all changes: list references and referenced objects 30 | /// 31 | AllChanges = 2 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/pocketbase-csharp-sdk.Tests/bin/Debug/net6.0/pocketbase-csharp-sdk.Tests.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/pocketbase-csharp-sdk.Tests", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/ItemBaseFilters.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Definition for Filters to query data in PocketBase 15 | /// 16 | public class ItemBaseFilters 17 | { 18 | /// Makes a Filter to Query data over the 'id' field 19 | public FieldFilterText Id => new FieldFilterText("id"); 20 | 21 | /// Makes a Filter to Query data over the 'created' field 22 | public FieldFilterDate Created => new FieldFilterDate("created"); 23 | 24 | /// Makes a Filter to Query data over the 'updated' field 25 | public FieldFilterDate Updated => new FieldFilterDate("updated"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseApplicationModel.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map the PocketBase application information 17 | /// 18 | public class PocketBaseApplicationModel 19 | { 20 | /// 21 | /// The name of the PocketBase application 22 | /// 23 | [JsonPropertyName("appName")] 24 | public string? Name { get; set; } 25 | 26 | /// 27 | /// The Url of the PocketBase application (the server) 28 | /// 29 | [JsonPropertyName("appUrl")] 30 | public string? Url { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/Thumbnail.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PocketBaseClient.Orm.Structures 8 | { 9 | public class Thumbnail 10 | { 11 | protected FieldFileBase FieldFile { get; } 12 | protected string ThumbDimensions { get; } 13 | 14 | public Thumbnail(FieldFileBase fieldFile, string thumbDimensions) 15 | { 16 | FieldFile = fieldFile; 17 | ThumbDimensions = thumbDimensions; 18 | } 19 | 20 | /// 21 | /// Gets the Stream of the Thumbnail (async) 22 | /// 23 | /// 24 | public async Task GetStreamAsync() 25 | => await FieldFile.GetStreamAsync(ThumbDimensions); 26 | 27 | /// 28 | /// Saves the remote Thumbnail to local file (async) 29 | /// 30 | /// 31 | /// 32 | public async Task SaveToLocalFileAsync(string localPathFile) 33 | => await FieldFile.SaveToLocalFileAsync(localPathFile, ThumbDimensions); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Post.StatusEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using System.ComponentModel; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Post 17 | { 18 | public enum StatusEnum 19 | { 20 | [Description("draft")] 21 | Draft, 22 | 23 | [Description("to review")] 24 | ToReview, 25 | 26 | [Description("reviewed")] 27 | Reviewed, 28 | 29 | [Description("to publish")] 30 | ToPublish, 31 | 32 | [Description("published")] 33 | Published, 34 | 35 | 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileMultipleRestrictionsList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public class FileMultipleRestrictionsList : FieldFileList 19 | { 20 | public FileMultipleRestrictionsList() : this(null) { } 21 | 22 | public FileMultipleRestrictionsList(TestForType? testForType) : base(testForType, "FileMultipleRestrictions", "o4hs5o8n", 10) { } 23 | 24 | internal List GetRemovedFileNames() => RemovedFileNames; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileMultipleNoRestrictionsList.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Structures; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public class FileMultipleNoRestrictionsList : FieldFileList 19 | { 20 | public FileMultipleNoRestrictionsList() : this(null) { } 21 | 22 | public FileMultipleNoRestrictionsList(TestForType? testForType) : base(testForType, "FileMultipleNoRestrictions", "mqokykua", 10) { } 23 | 24 | internal List GetRemovedFileNames() => RemovedFileNames; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileSingleNoRestrictionFile.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Structures; 14 | 15 | namespace PocketBaseClient.DemoTest.Models 16 | { 17 | public partial class TestForType 18 | { 19 | public class FileSingleNoRestrictionFile : FieldFileBase 20 | { 21 | 22 | /// 23 | public override long? MaxSize => 5242880; 24 | 25 | public FileSingleNoRestrictionFile() : base("file_single_no_restriction", owner: null) { } 26 | 27 | public FileSingleNoRestrictionFile(TestForType? testForType) : base("file_single_no_restriction", testForType) { } 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsDateTime.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Json; 12 | using System.Text.Json.Serialization; 13 | 14 | namespace PocketBaseClient.CodeGenerator.Models 15 | { 16 | /// 17 | /// Model to map PocketBase Options for fields of type Datetime 18 | /// 19 | public class PocketBaseFieldOptionsDatetime 20 | { 21 | /// 22 | /// The max date 23 | /// 24 | [JsonPropertyName("max")] 25 | [JsonConverter(typeof(DateTimeConverter))] 26 | public DateTime? Max { get; set; } 27 | 28 | /// 29 | /// The min date 30 | /// 31 | [JsonPropertyName("min")] 32 | [JsonConverter(typeof(DateTimeConverter))] 33 | public DateTime? Min { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FilterCommandComposed.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | internal class FilterCommandComposed 14 | { 15 | public FilterCommandComposeOptions ComposeFilterOption { get; } 16 | public FilterCommand FilterCommand { get; } 17 | 18 | public string Command 19 | { 20 | get 21 | { 22 | var strOperand = (ComposeFilterOption == FilterCommandComposeOptions.And) ? "&&" : "||"; 23 | return $" {strOperand}({FilterCommand.Command})"; 24 | } 25 | } 26 | 27 | public FilterCommandComposed(FilterCommandComposeOptions composeFilterOption, FilterCommand filterCommand) 28 | { 29 | ComposeFilterOption = composeFilterOption; 30 | FilterCommand = filterCommand; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileMultipleNoRestrictionsFile.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Structures; 14 | 15 | namespace PocketBaseClient.DemoTest.Models 16 | { 17 | public partial class TestForType 18 | { 19 | public class FileMultipleNoRestrictionsFile : FieldFileBase 20 | { 21 | 22 | /// 23 | public override long? MaxSize => 5242880; 24 | 25 | public FileMultipleNoRestrictionsFile() : base("file_multiple_no_restrictions", owner: null) { } 26 | 27 | public FileMultipleNoRestrictionsFile(TestForType? testForType) : base("file_multiple_no_restrictions", testForType) { } 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/FieldInfoBool.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Models.Collection; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Generation 14 | { 15 | /// 16 | /// Information about a Field of type Bool of an Item in a Collection, for the code generation 17 | /// 18 | internal class FieldInfoBool : FieldInfo 19 | { 20 | /// 21 | public override string TypeName => "bool"; 22 | 23 | /// 24 | public override string FilterType => "FieldFilterBool"; 25 | 26 | /// 27 | /// Ctor 28 | /// 29 | /// 30 | /// 31 | public FieldInfoBool(ItemInfo itemInfo, SchemaFieldModel schemaField) : base(itemInfo, schemaField) { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/FieldInfoJson.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Models.Collection; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Generation 14 | { 15 | /// 16 | /// Information about a Field of type Json of an Item in a Collection, for the code generation 17 | /// 18 | internal class FieldInfoJson : FieldInfo 19 | { 20 | /// 21 | public override string TypeName => "dynamic"; 22 | 23 | /// 24 | public override string FilterType => "FieldFilterText"; 25 | 26 | /// 27 | /// Ctor 28 | /// 29 | /// 30 | /// 31 | public FieldInfoJson(ItemInfo itemInfo, SchemaFieldModel schemaField) : base(itemInfo, schemaField) { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/GeneratedCodeFile.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.CodeGenerator.Generation 12 | { 13 | /// 14 | /// Representation of a generated file with its content 15 | /// 16 | internal class GeneratedCodeFile 17 | { 18 | /// 19 | /// File name 20 | /// 21 | public string FileName { get; set; } 22 | 23 | /// 24 | /// Content 25 | /// 26 | public string Content { get; set; } 27 | 28 | /// 29 | /// Ctor 30 | /// 31 | /// 32 | /// 33 | public GeneratedCodeFile(string fileName, string content) 34 | { 35 | FileName = fileName; 36 | Content = content; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/User.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class User 17 | { 18 | public class Sorts : ItemAuthBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'name' field 22 | public SortCommand Name => new SortCommand("name"); 23 | 24 | /// Makes a SortCommand to Order by the 'avatar' field 25 | public SortCommand Avatar => new SortCommand("avatar"); 26 | 27 | /// Makes a SortCommand to Order by the 'url' field 28 | public SortCommand Url => new SortCommand("url"); 29 | 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsText.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map PocketBase Options for fields of type Text 17 | /// 18 | public class PocketBaseFieldOptionsText 19 | { 20 | /// 21 | /// Max length of the field values 22 | /// 23 | [JsonPropertyName("max")] 24 | public int? Max { get; set; } 25 | 26 | /// 27 | /// Min length of the field values 28 | /// 29 | [JsonPropertyName("min")] 30 | public int? Min { get; set; } 31 | 32 | /// 33 | /// Pattern for the field values 34 | /// 35 | [JsonPropertyName("pattern")] 36 | public string? Pattern { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sdk/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/pocketbase-csharp-sdk.Tests/pocketbase-csharp-sdk.Tests.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/pocketbase-csharp-sdk.Tests/pocketbase-csharp-sdk.Tests.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "--project", 36 | "${workspaceFolder}/pocketbase-csharp-sdk.Tests/pocketbase-csharp-sdk.Tests.csproj" 37 | ], 38 | "problemMatcher": "$msCompile" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/ItemAuthBaseSorts.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | 12 | namespace PocketBaseClient.Orm.Filters 13 | { 14 | /// 15 | /// Definition for Sort options to sort filtered data in PocketBase 16 | /// 17 | public class ItemAuthBaseSorts : ItemBaseSorts 18 | { 19 | /// Makes a SortCommand to Order by the 'email' field 20 | public SortCommand Email => new SortCommand("email"); 21 | 22 | /// Makes a SortCommand to Order by the 'emailVisibility' field 23 | public SortCommand EmailVisibility => new SortCommand("emailVisibility"); 24 | 25 | /// Makes a SortCommand to Order by the 'username' field 26 | public SortCommand Username => new SortCommand("username"); 27 | 28 | /// Makes a SortCommand to Order by the 'verified' field 29 | public SortCommand Verified => new SortCommand("verified"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsSelect.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map PocketBase Options for fields of type Select 17 | /// 18 | public class PocketBaseFieldOptionsSelect 19 | { 20 | /// 21 | /// Max number of elements in the field 22 | /// 23 | [JsonPropertyName("maxSelect")] 24 | public int? MaxSelect { get; set; } 25 | 26 | /// 27 | /// Says if the field can contain multiple values 28 | /// 29 | [JsonIgnore] 30 | public bool IsMultiple => MaxSelect == null || MaxSelect > 1; 31 | 32 | /// 33 | /// Available values to select 34 | /// 35 | [JsonPropertyName("values")] 36 | public List? Values { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseCredentials.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.ComponentModel.DataAnnotations; 12 | using System.Text.Json.Serialization; 13 | 14 | namespace PocketBaseClient.CodeGenerator.Models 15 | { 16 | /// 17 | /// Model to map PocketBase credentials 18 | /// 19 | internal class PocketBaseCredentials 20 | { 21 | /// 22 | /// The credentials email 23 | /// 24 | [Display(Name = "Type an Admin email")] 25 | [DataType(DataType.EmailAddress)] 26 | [Required] 27 | [MinLength(5)] 28 | public string? Email { get; set; } 29 | 30 | /// 31 | /// The password 32 | /// 33 | [Display(Name = "Type the password")] 34 | [DataType(DataType.Password)] 35 | [Required] 36 | [MinLength(5)] 37 | [JsonIgnore] 38 | public string? Password { get; set; } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/User.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class User 17 | { 18 | public class Filters : ItemAuthBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'name' field in PocketBase 22 | public FieldFilterText Name => new FieldFilterText("name"); 23 | 24 | /// Gets a Filter to Query data over the 'avatar' field in PocketBase 25 | public FieldFilterText Avatar => new FieldFilterText("avatar"); 26 | 27 | /// Gets a Filter to Query data over the 'url' field in PocketBase 28 | public FieldFilterUri Url => new FieldFilterUri("url"); 29 | 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/ItemAuthBaseFilters.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | 12 | namespace PocketBaseClient.Orm.Filters 13 | { 14 | /// 15 | /// Definition for Filters to query data in PocketBase 16 | /// 17 | public class ItemAuthBaseFilters : ItemBaseFilters 18 | { 19 | /// Makes a Filter to Query data over the 'email' field 20 | public FieldFilterMailAddress Email => new FieldFilterMailAddress("email"); 21 | 22 | /// Makes a Filter to Query data over the 'emailVisibility' field 23 | public FieldFilterBool EmailVisibility => new FieldFilterBool("emailVisibility"); 24 | 25 | /// Makes a Filter to Query data over the 'username' field 26 | public FieldFilterText Username => new FieldFilterText("username"); 27 | 28 | /// Makes a Filter to Query data over the 'verified' field 29 | public FieldFilterBool Verified => new FieldFilterBool("verified"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/UrlConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json; 12 | using System.Text.Json.Serialization; 13 | 14 | namespace PocketBaseClient.Orm.Json 15 | { 16 | /// 17 | /// Converter for url types 18 | /// 19 | public class UrlConverter : JsonConverter 20 | { 21 | /// 22 | public override Uri? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 23 | { 24 | var value = reader.GetString(); 25 | if (string.IsNullOrEmpty(value)) 26 | return null; 27 | 28 | return new Uri(value); 29 | } 30 | 31 | /// 32 | public override void Write(Utf8JsonWriter writer, Uri? value, JsonSerializerOptions options) 33 | { 34 | if (value is null) 35 | writer.WriteNullValue(); 36 | else 37 | writer.WriteStringValue(value.ToString()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/pocketbase-csharp-sdk.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.2.0-prerelease 5 | net8.0 6 | pocketbase_csharp_sdk 7 | enable 8 | enable 9 | https://github.com/PRCV1/pocketbase-csharp-sdk 10 | https://github.com/PRCV1/pocketbase-csharp-sdk 11 | git 12 | PocketBase C# SDK 13 | Lukas Müller 14 | Multiplatform C# SDK for PocketBase 15 | True 16 | README.md 17 | True 18 | snupkg 19 | LICENSE.txt 20 | True 21 | 22 | 23 | 24 | 25 | True 26 | \ 27 | 28 | 29 | True 30 | \ 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/pocketbase-csharp-sdk - Backup.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1.1.0-prerelease 5 | net6.0;net7.0 6 | pocketbase_csharp_sdk 7 | enable 8 | enable 9 | https://github.com/PRCV1/pocketbase-csharp-sdk 10 | https://github.com/PRCV1/pocketbase-csharp-sdk 11 | git 12 | PocketBase C# SDK 13 | Lukas Müller 14 | Multiplatform C# SDK for PocketBase 15 | True 16 | README.md 17 | True 18 | snupkg 19 | LICENSE.txt 20 | True 21 | 22 | 23 | 24 | 25 | True 26 | \ 27 | 28 | 29 | True 30 | \ 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/CollectionAuthBase[T].cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | 12 | using pocketbase_csharp_sdk.Models; 13 | using pocketbase_csharp_sdk.Models.Log; 14 | using pocketbase_csharp_sdk.Services; 15 | using PocketBaseClient.Services; 16 | using System.Web; 17 | 18 | namespace PocketBaseClient.Orm 19 | { 20 | /// 21 | /// Base class for an Authentication Collection of PocketBase, with registries mapped in the ORM 22 | /// 23 | /// The type of the mapped registries 24 | public abstract partial class CollectionAuthBase : CollectionBase 25 | where T : ItemAuthBase, new() 26 | { 27 | private AuthCollectionService? _Auth; 28 | public AuthCollectionService Auth => _Auth ??= new AuthCollectionService(this); 29 | 30 | /// 31 | /// Ctor 32 | /// 33 | /// 34 | protected CollectionAuthBase(DataServiceBase context) : base(context) { } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Extensions/ObjectExtensions.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json; 12 | 13 | namespace PocketBaseClient 14 | { 15 | /// 16 | /// Extensions for Objects 17 | /// 18 | internal static class ObjectExtensions 19 | { 20 | 21 | /// 22 | /// Converts the object to json 23 | /// 24 | /// 25 | /// 26 | public static string ToJson(this object obj) 27 | { 28 | return JsonSerializer.Serialize(obj); 29 | } 30 | 31 | /// 32 | /// Converts the object to json, indenting the result 33 | /// 34 | /// 35 | /// 36 | public static string ToJsonIndented(this object obj) 37 | { 38 | var options = new JsonSerializerOptions { WriteIndented = true }; 39 | return JsonSerializer.Serialize(obj, options); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForRelated.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForRelated 17 | { 18 | public class Sorts : ItemBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'number_unique' field 22 | public SortCommand NumberUnique => new SortCommand("number_unique"); 23 | 24 | /// Makes a SortCommand to Order by the 'number_nonempty' field 25 | public SortCommand NumberNonempty => new SortCommand("number_nonempty"); 26 | 27 | /// Makes a SortCommand to Order by the 'number_nonempty_unique' field 28 | public SortCommand NumberNonemptyUnique => new SortCommand("number_nonempty_unique"); 29 | 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Models/Files/FilepathFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk.Models.Files 8 | { 9 | 10 | /// 11 | /// simple class for uploading files to PocketBase, accepting a path to a file 12 | /// 13 | public class FilepathFile : BaseFile, IFile 14 | { 15 | public string? FilePath { get; set; } 16 | private Stream? _stream; 17 | public Stream? GetStream() 18 | { 19 | if(_stream is not null) 20 | { 21 | _stream.Position = 0; 22 | return _stream; 23 | } 24 | if (string.IsNullOrWhiteSpace(FilePath)) 25 | { 26 | return null; 27 | } 28 | 29 | try 30 | { 31 | return File.OpenRead(FilePath); 32 | } 33 | catch 34 | { 35 | return null; 36 | } 37 | } 38 | 39 | public FilepathFile() 40 | { 41 | 42 | } 43 | 44 | public FilepathFile(string? filePath) 45 | { 46 | this.FilePath = filePath; 47 | } 48 | public FilepathFile(string? fileName,Stream stream) 49 | { 50 | this.FilePath = fileName; 51 | this.FileName = fileName; 52 | _stream = stream; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/EmailConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Net.Mail; 12 | using System.Text.Json; 13 | using System.Text.Json.Serialization; 14 | 15 | namespace PocketBaseClient.Orm.Json 16 | { 17 | /// 18 | /// Converter for email types 19 | /// 20 | public class EmailConverter : JsonConverter 21 | { 22 | /// 23 | public override MailAddress? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 24 | { 25 | var value = reader.GetString(); 26 | if (string.IsNullOrEmpty(value)) 27 | return null; 28 | 29 | return new MailAddress(value); 30 | } 31 | 32 | /// 33 | public override void Write(Utf8JsonWriter writer, MailAddress? value, JsonSerializerOptions options) 34 | { 35 | if (value is null) 36 | writer.WriteNullValue(); 37 | else 38 | writer.WriteStringValue(value.Address); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileSingleRestrictionFile.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Structures; 14 | 15 | namespace PocketBaseClient.DemoTest.Models 16 | { 17 | public partial class TestForType 18 | { 19 | public class FileSingleRestrictionFile : FieldFileBase 20 | { 21 | 22 | /// 23 | public override long? MaxSize => 5242880; 24 | 25 | public FileSingleRestrictionFile() : base("file_single_restriction", owner: null) { } 26 | 27 | public FileSingleRestrictionFile(TestForType? testForType) : base("file_single_restriction", testForType) { } 28 | 29 | #region Thumbs 30 | private Thumbnail? _Thumb100x100f = null; 31 | public Thumbnail Thumb100x100f => _Thumb100x100f ??= new Thumbnail(this, "100x100f"); 32 | 33 | #endregion Thumbs 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Author.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Author 17 | { 18 | public class Sorts : ItemBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'name' field 22 | public SortCommand Name => new SortCommand("name"); 23 | 24 | /// Makes a SortCommand to Order by the 'email' field 25 | public SortCommand Email => new SortCommand("email"); 26 | 27 | /// Makes a SortCommand to Order by the 'url' field 28 | public SortCommand Url => new SortCommand("url"); 29 | 30 | /// Makes a SortCommand to Order by the 'profile' field 31 | public SortCommand Profile => new SortCommand("profile"); 32 | 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.FileMultipleRestrictionsFile.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Structures; 14 | 15 | namespace PocketBaseClient.DemoTest.Models 16 | { 17 | public partial class TestForType 18 | { 19 | public class FileMultipleRestrictionsFile : FieldFileBase 20 | { 21 | 22 | /// 23 | public override long? MaxSize => 5242880; 24 | 25 | public FileMultipleRestrictionsFile() : base("file_multiple_restrictions", owner: null) { } 26 | 27 | public FileMultipleRestrictionsFile(TestForType? testForType) : base("file_multiple_restrictions", testForType) { } 28 | 29 | #region Thumbs 30 | private Thumbnail? _Thumb100x100f = null; 31 | public Thumbnail Thumb100x100f => _Thumb100x100f ??= new Thumbnail(this, "100x100f"); 32 | 33 | #endregion Thumbs 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/FileConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json; 12 | using System.Text.Json.Serialization; 13 | 14 | namespace PocketBaseClient.Orm.Json 15 | { 16 | /// 17 | /// Converter for File types 18 | /// 19 | /// The FieldFile type 20 | public class FileConverter : JsonConverter 21 | where T: FieldFileBase, new() 22 | { 23 | /// 24 | public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 25 | { 26 | var value = reader.GetString(); 27 | if (value == null) 28 | return null; 29 | 30 | return new T() { FileName = value }; 31 | } 32 | 33 | /// 34 | public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options) 35 | { 36 | if (value is null) 37 | writer.WriteNullValue(); 38 | else 39 | writer.WriteStringValue(value.FileName); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForRelated.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForRelated 17 | { 18 | public class Filters : ItemBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'number_unique' field in PocketBase 22 | public FieldFilterNumber NumberUnique => new FieldFilterNumber("number_unique"); 23 | 24 | /// Gets a Filter to Query data over the 'number_nonempty' field in PocketBase 25 | public FieldFilterNumber NumberNonempty => new FieldFilterNumber("number_nonempty"); 26 | 27 | /// Gets a Filter to Query data over the 'number_nonempty_unique' field in PocketBase 28 | public FieldFilterNumber NumberNonemptyUnique => new FieldFilterNumber("number_nonempty_unique"); 29 | 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/DemoTestApplication.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient; 13 | using PocketBaseClient.DemoTest.Services; 14 | 15 | namespace PocketBaseClient.DemoTest 16 | { 17 | public partial class DemoTestApplication : PocketBaseClientApplication 18 | { 19 | private DemoTestDataService? _Data = null; 20 | /// Access to Data for Application demo-test 21 | public DemoTestDataService Data => _Data ??= new DemoTestDataService(this); 22 | 23 | private DemoTestAuthService? _Auth = null; 24 | /// Access to Auth for Application demo-test 25 | public new DemoTestAuthService Auth => _Auth ??= new DemoTestAuthService(this); 26 | 27 | #region Constructors 28 | public DemoTestApplication() : this("https://orm-csharp-test.pockethost.io") { } 29 | public DemoTestApplication(string url, string appName = "demo-test") : base(url, appName) { } 30 | #endregion Constructors 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Services/DemoTestAuthService.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient; 13 | using PocketBaseClient.Services; 14 | using PocketBaseClient.Orm; 15 | using PocketBaseClient.DemoTest.Models; 16 | 17 | namespace PocketBaseClient.DemoTest.Services 18 | { 19 | public partial class DemoTestAuthService : AuthServiceBase 20 | { 21 | #region Auth Collections 22 | /// Auth for Collection 'users' in PocketBase 23 | public AuthCollectionService User => (DemoTestDataService.GetCollection() as CollectionAuthBase)!.Auth; 24 | /// Auth for Collection 'users2' in PocketBase 25 | public AuthCollectionService Users2 => (DemoTestDataService.GetCollection() as CollectionAuthBase)!.Auth; 26 | #endregion Auth Collections 27 | 28 | #region Constructor 29 | public DemoTestAuthService(PocketBaseClientApplication app) : base(app) { } 30 | #endregion Constructor 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/PocketBaseClient/PocketBaseClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | $(TargetsForTfmSpecificBuildOutput) 6 | enable 7 | enable 8 | True 9 | PocketBaseClient-csharp 10 | 0.6.1 11 | 0.6.1 12 | 0.6.1 13 | https://github.com/iluvadev/PocketBaseClient-csharp 14 | MIT 15 | iluvadev 16 | https://github.com/iluvadev/PocketBaseClient-csharp 17 | git 18 | pocketbase,orm,c# 19 | 6.0 20 | Client in C# for interacting with a particular PocketBase application, with an ORM to manage Collections and Registries. 21 | 22 | 23 | 24 | embedded 25 | 26 | 27 | 28 | embedded 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.SelectSingleEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using System.ComponentModel; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public enum SelectSingleEnum 19 | { 20 | [Description("Option 1")] 21 | Option1, 22 | 23 | [Description("Option 2")] 24 | Option2, 25 | 26 | [Description("Option 3")] 27 | Option3, 28 | 29 | [Description("Option 4")] 30 | Option4, 31 | 32 | [Description("Option 5")] 33 | Option5, 34 | 35 | [Description("Option 6")] 36 | Option6, 37 | 38 | [Description("Option 7")] 39 | Option7, 40 | 41 | [Description("Option 8")] 42 | Option8, 43 | 44 | [Description("Option 9")] 45 | Option9, 46 | 47 | [Description("Option 10")] 48 | Option10, 49 | 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/TestForType.SelectMultipleEnum.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using System.ComponentModel; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class TestForType 17 | { 18 | public enum SelectMultipleEnum 19 | { 20 | [Description("Option 1")] 21 | Option1, 22 | 23 | [Description("Option 2")] 24 | Option2, 25 | 26 | [Description("Option 3")] 27 | Option3, 28 | 29 | [Description("Option 4")] 30 | Option4, 31 | 32 | [Description("Option 5")] 33 | Option5, 34 | 35 | [Description("Option 6")] 36 | Option6, 37 | 38 | [Description("Option 7")] 39 | Option7, 40 | 41 | [Description("Option 8")] 42 | Option8, 43 | 44 | [Description("Option 9")] 45 | Option9, 46 | 47 | [Description("Option 10")] 48 | Option10, 49 | 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Services/AuthServiceBase.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk; 12 | using pocketbase_csharp_sdk.Services; 13 | 14 | namespace PocketBaseClient.Services 15 | { 16 | 17 | /// 18 | /// Authentication Operations 19 | /// 20 | public class AuthServiceBase : ServiceBase 21 | { 22 | /// 23 | /// Current Authenticated information 24 | /// 25 | public AuthStore AuthStore => App.Sdk.AuthStore; 26 | 27 | private AuthAdminService? _Admin = null; 28 | /// 29 | /// Authenticate as Admin actions 30 | /// 31 | public AuthAdminService Admin => _Admin ??= new AuthAdminService(App); 32 | 33 | 34 | private UserService? _UserService; 35 | /// 36 | /// User Service 37 | /// 38 | public UserService UserService => _UserService ?? new UserService(App.Sdk); 39 | 40 | /// 41 | /// Ctor 42 | /// 43 | /// 44 | public AuthServiceBase(PocketBaseClientApplication app) : base(app) { } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/RelationConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using PocketBaseClient.Services; 12 | using System.Text.Json; 13 | using System.Text.Json.Serialization; 14 | 15 | namespace PocketBaseClient.Orm.Json 16 | { 17 | /// 18 | /// Converter for relation types 19 | /// 20 | /// The mapped related type 21 | public class RelationConverter : JsonConverter 22 | where T : ItemBase, new() 23 | { 24 | /// 25 | public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 26 | { 27 | var value = reader.GetString(); 28 | if (string.IsNullOrEmpty(value)) 29 | return null; 30 | 31 | return DataServiceBase.GetCollection()!.AddIdFromPb(value); 32 | } 33 | 34 | /// 35 | public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options) 36 | { 37 | if (value is null) 38 | writer.WriteNullValue(); 39 | else 40 | writer.WriteStringValue(value.Id); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Author.Filters.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Author 17 | { 18 | public class Filters : ItemBaseFilters 19 | { 20 | 21 | /// Gets a Filter to Query data over the 'name' field in PocketBase 22 | public FieldFilterText Name => new FieldFilterText("name"); 23 | 24 | /// Gets a Filter to Query data over the 'email' field in PocketBase 25 | public FieldFilterMailAddress Email => new FieldFilterMailAddress("email"); 26 | 27 | /// Gets a Filter to Query data over the 'url' field in PocketBase 28 | public FieldFilterUri Url => new FieldFilterUri("url"); 29 | 30 | /// Gets a Filter to Query data over the 'profile' field in PocketBase 31 | public FieldFilterText Profile => new FieldFilterText("profile"); 32 | 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FieldFilterMailAddress.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Net.Mail; 12 | 13 | namespace PocketBaseClient.Orm.Filters 14 | { 15 | /// 16 | /// Filter definitions for Fields of type eMail 17 | /// 18 | public class FieldFilterMailAddress : FieldFilterText 19 | { 20 | /// 21 | /// Ctor 22 | /// 23 | /// 24 | public FieldFilterMailAddress(string fieldName) : base(fieldName) 25 | { 26 | } 27 | 28 | /// 29 | /// The Field is Equal to 30 | /// 31 | /// The value to compare 32 | /// 33 | public FilterCommand Equal(MailAddress value) 34 | => Equal(value.Address); 35 | 36 | /// 37 | /// The Field is NOT Equal to 38 | /// 39 | /// The value to compare 40 | /// 41 | public FilterCommand NotEqual(MailAddress value) 42 | => NotEqual(value.Address); 43 | } 44 | } -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsRelation.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map PocketBase Options for fields of type Relation 17 | /// 18 | public class PocketBaseFieldOptionsRelation 19 | { 20 | /// 21 | /// Max number of elements in the field 22 | /// 23 | [JsonPropertyName("maxSelect")] 24 | public int? MaxSelect { get; set; } 25 | 26 | /// 27 | /// Says if the field can contain multiple values 28 | /// 29 | [JsonIgnore] 30 | public bool IsMultiple => MaxSelect == null || MaxSelect > 1; 31 | 32 | /// 33 | /// Indicates if server will performs cascade delete 34 | /// 35 | [JsonPropertyName("cascadeDelete")] 36 | public bool? CascadeDelete { get; set; } 37 | 38 | /// 39 | /// The related collectionId 40 | /// 41 | [JsonPropertyName("collectionId")] 42 | public string? CollectionId { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/CollectionBase.ItemList.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using PocketBaseClient.Orm.Structures; 12 | using System.Collections; 13 | 14 | namespace PocketBaseClient.Orm 15 | { 16 | public partial class CollectionBase 17 | { 18 | /// 19 | IEnumerator IEnumerable.GetEnumerator() 20 | => GetObjects().GetEnumerator(); 21 | 22 | 23 | /// 24 | object? IBasicList.Add(object? element) 25 | => AddInternal(element); 26 | internal abstract object? AddInternal(object? element); 27 | 28 | /// 29 | object? IBasicList.Remove(object? element) 30 | => RemoveInternal(element); 31 | protected abstract object? RemoveInternal(object? element); 32 | 33 | 34 | /// 35 | async Task IBasicCollection.SaveChangesAsync(ListSaveDiscardModes mode) 36 | => await SaveChangesAsync(true); 37 | 38 | /// 39 | bool IBasicCollection.SaveChanges(ListSaveDiscardModes mode) 40 | => SaveChanges(true); 41 | 42 | /// 43 | void IBasicCollection.DiscardChanges(ListSaveDiscardModes mode) 44 | => DiscardChanges(); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FieldFilterEnum.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Filter definitions for Fields of type Date 15 | /// 16 | /// The enum type 17 | public class FieldFilterEnum : FieldFilterText 18 | where T : struct, IConvertible 19 | { 20 | /// 21 | /// Ctor 22 | /// 23 | /// 24 | public FieldFilterEnum(string fieldName) : base(fieldName) 25 | { 26 | } 27 | 28 | /// 29 | /// The Field is Equal to 30 | /// 31 | /// The value to compare 32 | /// 33 | public FilterCommand Equal(T value) 34 | => Equal(value.GetDescription() ?? value.ToString()!); 35 | 36 | /// 37 | /// The Field is NOT Equal to 38 | /// 39 | /// The value to compare 40 | /// 41 | public FilterCommand NotEqual(T value) 42 | => NotEqual(value.GetDescription() ?? value.ToString()!); 43 | } 44 | } -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/Services/RecordService.cs: -------------------------------------------------------------------------------- 1 | using pocketbase_csharp_sdk.Enum; 2 | using pocketbase_csharp_sdk.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Web; 10 | 11 | namespace pocketbase_csharp_sdk.Services 12 | { 13 | public class RecordService : BaseSubCrudService 14 | { 15 | 16 | protected override string BasePath(string? path = null) 17 | { 18 | var encoded = UrlEncode(path); 19 | return $"/api/collections/{encoded}/records"; 20 | } 21 | 22 | private readonly PocketBase client; 23 | 24 | public RecordService(PocketBase client) : base(client) 25 | { 26 | this.client = client; 27 | } 28 | 29 | private Uri GetFileUrl(string sub, string recordId, string fileName, IDictionary? query = null) 30 | { 31 | var url = $"api/files/{sub}/{UrlEncode(recordId)}/{fileName}"; 32 | return client.BuildUrl(url, query); 33 | } 34 | 35 | public Task DownloadFileAsync(string collectionId, string recordId, string fileName, ThumbFormat? thumbFormat = null, CancellationToken cancellationToken = default) 36 | { 37 | var url = $"api/files/{UrlEncode(collectionId)}/{UrlEncode(recordId)}/{fileName}"; 38 | 39 | //TODO find out how the specify the actual resolution to resize 40 | var query = new Dictionary() 41 | { 42 | { "thumb", ThumbFormatHelper.GetNameForQuery(thumbFormat) } 43 | }; 44 | 45 | return client.GetStreamAsync(url, query, cancellationToken); 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Models/PocketBaseFieldOptionsEmailUrl.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json.Serialization; 12 | 13 | namespace PocketBaseClient.CodeGenerator.Models 14 | { 15 | /// 16 | /// Model to map PocketBase Options for fields of type Email or Url 17 | /// 18 | public class PocketBaseFieldOptionsEmailUrl 19 | { 20 | /// 21 | /// Exepted domains 22 | /// 23 | [JsonPropertyName("exceptDomains")] 24 | public List? ExceptDomains { get; set; } 25 | 26 | /// 27 | /// Excepted domains as string joined by ',' 28 | /// 29 | [JsonIgnore] 30 | public string ExceptDomainsJoined => (ExceptDomains?.Any() ?? false) ? string.Join(',', ExceptDomains) : string.Empty; 31 | 32 | /// 33 | /// Only domains accepted 34 | /// 35 | [JsonPropertyName("onlyDomains")] 36 | public List? OnlyDomains { get; set; } 37 | 38 | /// 39 | /// Only domains accepted as string joined by ',' 40 | /// 41 | [JsonIgnore] 42 | public string OnlyDomainsJoined => (OnlyDomains?.Any() ?? false) ? string.Join(',', OnlyDomains) : string.Empty; 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sdk/README.md: -------------------------------------------------------------------------------- 1 | PocketBase C# SDK 2 | ====================================================================== 3 | This project is currently still under development. It is not recommended to use it in a productive environment. Things can and will change. 4 | 5 | Community-developed C# SDK (Multiplatform) for interacting with the [PocketBase API](https://pocketbase.io/docs) 6 | 7 | - [PocketBase C# SDK](#pocketbase-c-sdk) 8 | - [Installation](#installation) 9 | - [Nuget](#nuget) 10 | - [Usage](#usage) 11 | - [Development](#development) 12 | - [Requirements](#requirements) 13 | - [Steps](#steps) 14 | 15 | # Installation 16 | 17 | ## Nuget 18 | 19 | Coming soon 20 | 21 | # Usage 22 | ```c# 23 | //create a new Client which connects to your PocketBase-API 24 | var client = new PocketBase("http://127.0.0.1:8090"); 25 | 26 | //authenticate as a Admin 27 | var admin = await client.Admin.AuthenticateWithPassword("test@test.de", "0123456789"); 28 | 29 | //or as a User 30 | var user = await client.User.AuthenticateWithPassword("kekw@kekw.com", "0123456789"); 31 | 32 | //query some data (for example, some restaurants) 33 | //note that each CRUD action requires a data type which inherits from the base class 'ItemBaseModel'. 34 | var restaurantList = await client.Records.ListAsync("restaurants"); 35 | 36 | //like this one 37 | class Restaurant : ItemBaseModel 38 | { 39 | public string? Name { get; set; } 40 | } 41 | ``` 42 | 43 | # Development 44 | 45 | ## Requirements 46 | - Visual Studio (Community Edition should work just fine) 47 | - .NET 6/7 SDK 48 | 49 | ## Steps 50 | 1. Clone this repository 51 | ```cmd 52 | git clone https://github.com/PRCV1/pocketbase-csharp-sdk 53 | ``` 54 | 2. Open the [pocketbase-csharp-sdk.sln](pocketbase-csharp-sdk.sln) with Visual Studio (Community Edition should work just fine) -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/EnumConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text.Json; 12 | using System.Text.Json.Serialization; 13 | 14 | namespace PocketBaseClient.Orm.Json 15 | { 16 | /// 17 | /// Converter for select types (enums) 18 | /// 19 | /// The enum type 20 | public class EnumConverter : JsonConverter where T : struct, IConvertible 21 | { 22 | /// 23 | public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 24 | { 25 | var value = reader.GetString(); 26 | if(string.IsNullOrEmpty(value)) 27 | return null; 28 | 29 | var valuesDesc = typeof(T).GetEnumValuesWithDescription(); 30 | var kvp = valuesDesc?.FirstOrDefault(kvp => kvp.Value == value); 31 | if (kvp == null) 32 | return null; 33 | 34 | return kvp.Value.Key; 35 | } 36 | 37 | /// 38 | public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options) 39 | { 40 | if (value is null) 41 | writer.WriteNullValue(); 42 | else 43 | writer.WriteStringValue(value.Value.GetDescription()); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk.Tests/PocketBaseTests.cs: -------------------------------------------------------------------------------- 1 | using FluentAssertions; 2 | using Moq; 3 | using Moq.Protected; 4 | using System.Net; 5 | 6 | namespace pocketbase_csharp_sdk.Tests 7 | { 8 | [TestClass] 9 | public class PocketBaseTests 10 | { 11 | 12 | [TestMethod] 13 | [DataRow("https://example.com/", "test")] 14 | [DataRow("https://example.com/", "/test")] 15 | [DataRow("https://example.com", "test")] 16 | [DataRow("https://example.com", "/test")] 17 | public void Test_BaseUrls(string baseUrl, string url) 18 | { 19 | var client = new PocketBase(baseUrl); 20 | 21 | var fullUrl = client.BuildUrl(url).ToString(); 22 | 23 | fullUrl.Should().Be("https://example.com/test"); 24 | } 25 | 26 | [TestMethod] 27 | [DataRow("test")] 28 | [DataRow("/test")] 29 | public void Test_Relative_Urls(string relativeUrl) 30 | { 31 | var client = new PocketBase("/api"); 32 | 33 | var url = client.BuildUrl(relativeUrl).ToString(); 34 | 35 | url.Should().Be("/api/test"); 36 | } 37 | 38 | [TestMethod] 39 | public void Test_With_Query_Paramters() 40 | { 41 | var client = new PocketBase("https://example.com"); 42 | 43 | Dictionary parameters = new() 44 | { 45 | { "a", null }, 46 | { "b", 123 }, 47 | { "c", "123" }, 48 | { "d", new object?[] { "1", 2, null } }, 49 | { "@encodeA", "@encodeB" }, 50 | }; 51 | var url = client.BuildUrl("/test", parameters).ToString(); 52 | 53 | url.Should().Be("https://example.com/test?b=123&c=123&d=1&d=2&%40encodeA=%40encodeB"); 54 | } 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/FieldInfoFileOne.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Models.Collection; 12 | using PocketBaseClient.CodeGenerator.Models; 13 | 14 | namespace PocketBaseClient.CodeGenerator.Generation 15 | { 16 | internal class FieldInfoFileOne : FieldInfoFile 17 | { 18 | 19 | /// 20 | public override string TypeName => TypeFileName; 21 | 22 | /// 23 | public override string FilterType => "FieldFilterText"; 24 | 25 | 26 | /// 27 | /// Ctor 28 | /// 29 | /// 30 | /// 31 | /// 32 | public FieldInfoFileOne(ItemInfo itemInfo, SchemaFieldModel schemaField, PocketBaseFieldOptionsFile options) : base(itemInfo, schemaField, options) 33 | { 34 | RelatedFiles.Add(@$".Union(new List() {{ {PropertyName} }})"); 35 | } 36 | 37 | /// 38 | protected override List GetLinesForPropertyDecorators() 39 | { 40 | var list = base.GetLinesForPropertyDecorators(); 41 | 42 | list.Add($"[JsonConverter(typeof(FileConverter<{TypeFileName}>))]"); 43 | 44 | return list; 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/FieldInfoSelectOne.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Models.Collection; 12 | using PocketBaseClient.CodeGenerator.Models; 13 | 14 | namespace PocketBaseClient.CodeGenerator.Generation 15 | { 16 | /// 17 | /// Information about a Field of type Select with only One value of an Item in a Collection, for the code generation 18 | /// 19 | internal class FieldInfoSelectOne : FieldInfoSelect 20 | { 21 | /// 22 | public override string TypeName => EnumName; 23 | 24 | /// 25 | public override string FilterType => $"FieldFilterEnum<{EnumName}>"; 26 | 27 | /// 28 | /// Ctor 29 | /// 30 | /// 31 | /// 32 | /// 33 | public FieldInfoSelectOne(ItemInfo itemInfo, SchemaFieldModel schemaField, PocketBaseFieldOptionsSelect options) : base(itemInfo, schemaField, options) { } 34 | 35 | 36 | /// 37 | protected override List GetLinesForPropertyDecorators() 38 | { 39 | var list = base.GetLinesForPropertyDecorators(); 40 | 41 | list.Add($@"[JsonConverter(typeof(EnumConverter<{EnumName}>))]"); 42 | 43 | return list; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IBasicList[T].cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | 12 | namespace PocketBaseClient.Orm.Structures 13 | { 14 | public interface IBasicList : IBasicList, IEnumerable, IAsyncEnumerable 15 | { 16 | 17 | /// 18 | /// Adds an element to the list 19 | /// 20 | /// The element to be added 21 | /// 22 | T? Add(T? element); 23 | 24 | /// 25 | /// Adds all elements to the list 26 | /// 27 | /// The elements to be added 28 | void AddRange(IEnumerable elements) 29 | { 30 | foreach (var element in elements) 31 | Add(element); 32 | } 33 | 34 | /// 35 | /// Removes the element from the list 36 | /// 37 | /// The element to be removed 38 | /// 39 | T? Remove(T? element); 40 | 41 | /// 42 | /// Removes all elements from the list 43 | /// 44 | /// The elements to be removed 45 | void RemoveRange(IEnumerable elements) 46 | { 47 | foreach (var element in elements) 48 | Remove(element); 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/PocketBaseClient/PocketBaseClientApplication.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk; 12 | using PocketBaseClient.Services; 13 | 14 | namespace PocketBaseClient 15 | { 16 | /// 17 | /// Class for a Client of a concrete PocketBase application 18 | /// 19 | public partial class PocketBaseClientApplication 20 | { 21 | /// 22 | /// The Application Name 23 | /// 24 | public string? AppName { get; set; } 25 | 26 | /// 27 | /// The Url to connect with the application 28 | /// 29 | public string AppUrl { get; init; } 30 | 31 | private AuthServiceBase? _Auth = null; 32 | /// 33 | /// Authentication operations 34 | /// 35 | public AuthServiceBase Auth => _Auth ??= new AuthServiceBase(this); 36 | 37 | /// 38 | /// Access to the PocketBase Sdk 39 | /// 40 | public PocketBase Sdk { get; } 41 | 42 | /// 43 | /// Ctor 44 | /// 45 | /// 46 | /// 47 | public PocketBaseClientApplication(string url, string? appName = null) 48 | { 49 | AppUrl = url; 50 | AppName = appName; 51 | Sdk = new PocketBase(url); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Structures/IFieldFileList[T].cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Structures 12 | { 13 | /// 14 | /// Definition for field types of Lists of files 15 | /// 16 | public interface IFieldFileList : IFieldBasicList 17 | where T : FieldFileBase, new() 18 | { 19 | 20 | /// 21 | /// Adds a file from a Local file 22 | /// 23 | /// The entire path of the local file 24 | /// 25 | T? AddFromLocalFile(string localPathFile); 26 | 27 | 28 | /// 29 | /// Says if the fileName is contained in the list 30 | /// 31 | /// The fileName to check if is contained 32 | /// 33 | bool Contains(string fileName); 34 | 35 | 36 | /// 37 | /// Removes the file with fileName from the list 38 | /// 39 | /// The fileName of the element to be removed 40 | /// 41 | T? Remove(string fileName); 42 | 43 | /// 44 | /// Removes all elements with fileNames from the list 45 | /// 46 | /// The filenames of the elements to be removed 47 | void RemoveRange(IEnumerable fileNames); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Validators/OnlyDomainsAttribute.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.ComponentModel.DataAnnotations; 12 | using System.Net.Mail; 13 | 14 | namespace PocketBaseClient.Orm.Validators 15 | { 16 | /// 17 | /// Validator for the "only domains" restriction 18 | /// 19 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] 20 | sealed public class OnlyDomainsAttribute : ValidationAttribute 21 | { 22 | /// 23 | /// The "only domains" defined in server 24 | /// 25 | public string OnlyDomainsValues { get; } 26 | private List OnlyDomainsList => OnlyDomainsValues?.Split(',').ToList() ?? new List(); 27 | 28 | /// 29 | /// Ctor 30 | /// 31 | /// 32 | public OnlyDomainsAttribute(string exceptDomainsValues) 33 | { 34 | OnlyDomainsValues = exceptDomainsValues; 35 | } 36 | 37 | /// 38 | public override bool IsValid(object? value) 39 | { 40 | if (value == null) return false; 41 | 42 | if (value is MailAddress email) 43 | return OnlyDomainsList.Contains(email.Host); 44 | 45 | if (value is Uri uri) 46 | return OnlyDomainsList.Contains(uri.Host); 47 | 48 | return false; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Validators/ExceptDomainsAttribute.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.ComponentModel.DataAnnotations; 12 | using System.Net.Mail; 13 | 14 | namespace PocketBaseClient.Orm.Validators 15 | { 16 | /// 17 | /// Validator for the "except domains" restriction 18 | /// 19 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] 20 | sealed public class ExceptDomainsAttribute : ValidationAttribute 21 | { 22 | /// 23 | /// The "except domains" defined in server 24 | /// 25 | public string ExceptDomainsValues { get; } 26 | private List ExceptDomainsList => ExceptDomainsValues?.Split(',').ToList() ?? new List(); 27 | 28 | /// 29 | /// Ctor 30 | /// 31 | /// 32 | public ExceptDomainsAttribute(string exceptDomainsValues) 33 | { 34 | ExceptDomainsValues = exceptDomainsValues; 35 | } 36 | 37 | /// 38 | public override bool IsValid(object? value) 39 | { 40 | if (value == null) return true; 41 | 42 | if (value is MailAddress email) 43 | return !ExceptDomainsList.Contains(email.Host); 44 | 45 | if (value is Uri uri) 46 | return !ExceptDomainsList.Contains(uri.Host); 47 | 48 | return true; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionTags.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionTags : CollectionBase 19 | { 20 | /// 21 | public override string Id => "8zo94eumxnj7ghx"; 22 | 23 | /// 24 | public override string Name => "tags"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'tags' 30 | /// The DataService for the collection 31 | internal CollectionTags(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'tags' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new Tag.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'tags' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Program.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.CodeGenerator 12 | { 13 | class Program 14 | { 15 | public static string Banner = @" 16 | _____ _ _ ____ _____ _ _ _ 17 | | __ \ | | | | | _ \ / ____| (_) | | 18 | | |__) |__ ___| | _____| |_| |_) | __ _ ___ ___| | | |_ ___ _ __ | |_ 19 | | ___/ _ \ / __| |/ / _ \ __| _ < / _` / __|/ _ \ | | | |/ _ \ '_ \| __| 20 | | | | (_) | (__| < __/ |_| |_) | (_| \__ \ __/ |____| | | __/ | | | |_ 21 | |_| \___/ \___|_|\_\___|\__|____/ \__,_|___/\___|\_____|_|_|\___|_| |_|\__| 22 | _____ _ _____ _ 23 | / ____| | | / ____| | | 24 | | | ___ __| | ___| | __ ___ _ __ ___ _ __ __ _| |_ ___ _ __ 25 | | | / _ \ / _` |/ _ \ | |_ |/ _ \ '_ \ / _ \ '__/ _` | __/ _ \| '__| 26 | | |___| (_) | (_| | __/ |__| | __/ | | | __/ | | (_| | || (_) | | 27 | \_____\___/ \__,_|\___|\_____|\___|_| |_|\___|_| \__,_|\__\___/|_| 28 | "; 29 | 30 | 31 | public static string Welcome = @$" 32 | 33 | Welcome to PocketBaseClient CodeGenerator 34 | An application to generate client side code in c# for your PocketBase application 35 | "; 36 | 37 | static int Main(string[] args) 38 | { 39 | Interactive.Process.Start(); 40 | return 0; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionPosts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionPosts : CollectionBase 19 | { 20 | /// 21 | public override string Id => "ev0tqm560oseykn"; 22 | 23 | /// 24 | public override string Name => "posts"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'posts' 30 | /// The DataService for the collection 31 | internal CollectionPosts(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'posts' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new Post.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'posts' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionUsers.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionUsers : CollectionAuthBase 19 | { 20 | /// 21 | public override string Id => "_pb_users_auth_"; 22 | 23 | /// 24 | public override string Name => "users"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'users' 30 | /// The DataService for the collection 31 | internal CollectionUsers(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'users' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new User.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'users' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Extensions/RandomExtensions.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.Text; 12 | 13 | namespace PocketBaseClient 14 | { 15 | internal static class RandomExtensions 16 | { 17 | //const string defaultRandomAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 18 | const string defaultRandomAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; 19 | 20 | // PseudorandomString generates a pseudorandom string with the specified length. 21 | // 22 | // The generated string matches [A-Za-z0-9]+ and it's transparent to URL-encoding. 23 | // 24 | // For a cryptographically random string (but a little bit slower) use RandomString instead. 25 | public static string PseudorandomString(this Random rnd, int length) 26 | { 27 | return PseudorandomStringWithAlphabet(rnd, length, defaultRandomAlphabet); 28 | } 29 | 30 | // PseudorandomStringWithAlphabet generates a pseudorandom string 31 | // with the specified length and characters set. 32 | // 33 | // For a cryptographically random (but a little bit slower) use RandomStringWithAlphabet instead. 34 | public static string PseudorandomStringWithAlphabet(this Random rnd, int length, string alphabet) 35 | { 36 | var sb = new StringBuilder(); 37 | var max = alphabet.Length; 38 | 39 | for (int i = 0; i < length; i++) 40 | sb.Append(alphabet[rnd.Next(max)]); 41 | return sb.ToString(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FieldFilterBool.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Filter definitions for Fields of type Bool 15 | /// 16 | public class FieldFilterBool : FieldFilter 17 | { 18 | /// 19 | /// Ctor 20 | /// 21 | /// 22 | public FieldFilterBool(string fieldName) : base(fieldName) 23 | { 24 | } 25 | 26 | /// 27 | /// The Field is Equal to 28 | /// 29 | /// The value to compare 30 | /// 31 | public FilterCommand Equal(bool value) 32 | => new($"{FieldName}={value}"); 33 | 34 | /// 35 | /// The Field is NOT Equal to 36 | /// 37 | /// The value to compare 38 | /// 39 | public FilterCommand NotEqual(bool value) 40 | => new($"{FieldName}!={value}"); 41 | 42 | /// 43 | /// The Field is TRUE 44 | /// 45 | /// 46 | public FilterCommand IsTrue() 47 | => Equal(true); 48 | 49 | /// 50 | /// The Field is FALSE 51 | /// 52 | /// 53 | public FilterCommand IsFalse() 54 | => Equal(false); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/PocketBaseClient.CodeGenerator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | true 7 | true 8 | win-x64;linux-x64;osx-x64 9 | true 10 | 11 | enable 12 | enable 13 | pbcodegen 14 | 0.6.1 15 | 0.6.1 16 | 0.6.1 17 | PocketBaseClient-csharp: CodeGenerator 18 | True 19 | https://github.com/iluvadev/PocketBaseClient-csharp 20 | MIT 21 | iluvadev 22 | PocketBaseClient.CodeGenerator 23 | true 24 | AnyCPU 25 | False 26 | https://github.com/iluvadev/PocketBaseClient-csharp 27 | git 28 | pocketbase, orm 29 | 30 | 31 | 32 | embedded 33 | 34 | 35 | 36 | embedded 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionUsers2.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionUsers2 : CollectionAuthBase 19 | { 20 | /// 21 | public override string Id => "y89kc8kxl8vts1k"; 22 | 23 | /// 24 | public override string Name => "users2"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'users2' 30 | /// The DataService for the collection 31 | internal CollectionUsers2(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'users2' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new Users2.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'users2' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionAuthors.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionAuthors : CollectionBase 19 | { 20 | /// 21 | public override string Id => "juwfyaf8ba9i3yx"; 22 | 23 | /// 24 | public override string Name => "authors"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'authors' 30 | /// The DataService for the collection 31 | internal CollectionAuthors(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'authors' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new Author.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'authors' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PocketBaseClient.CodeGenerator/Generation/FieldInfoRelationOne.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using pocketbase_csharp_sdk.Models.Collection; 12 | using PocketBaseClient.CodeGenerator.Models; 13 | using System; 14 | using System.Collections.Generic; 15 | using System.Linq; 16 | using System.Text; 17 | using System.Threading.Tasks; 18 | 19 | namespace PocketBaseClient.CodeGenerator.Generation 20 | { 21 | internal class FieldInfoRelationOne : FieldInfoRelation 22 | { 23 | 24 | /// 25 | public override string TypeName => ReferencedClassName; 26 | 27 | /// 28 | public override bool IsTypeNullableInProperty => true; 29 | 30 | /// 31 | public override string FilterType => $"FieldFilterItem<{ReferencedClassName}>"; 32 | 33 | /// 34 | /// Ctor 35 | /// 36 | /// 37 | /// 38 | /// 39 | public FieldInfoRelationOne(ItemInfo itemInfo, SchemaFieldModel schemaField, PocketBaseFieldOptionsRelation options) : base(itemInfo, schemaField, options) 40 | { 41 | RelatedItems.Add(@$".Union(new List() {{ {PropertyName} }})"); 42 | } 43 | 44 | /// 45 | protected override List GetLinesForPropertyDecorators() 46 | { 47 | var list = base.GetLinesForPropertyDecorators(); 48 | 49 | list.Add($@"[JsonConverter(typeof(RelationConverter<{ReferencedClassName}>))]"); 50 | 51 | return list; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionCategories.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionCategories : CollectionBase 19 | { 20 | /// 21 | public override string Id => "fgj34p0gy01o41e"; 22 | 23 | /// 24 | public override string Name => "categories"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'categories' 30 | /// The DataService for the collection 31 | internal CollectionCategories(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'categories' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new Category.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'categories' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sdk/pocketbase-csharp-sdk/ClientException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace pocketbase_csharp_sdk 8 | { 9 | public class ClientException : Exception 10 | { 11 | 12 | /// 13 | /// The Url of the failed request 14 | /// 15 | public string Url { get; } 16 | 17 | /// 18 | /// Indicates whether the error is a result from request cancellation/abort 19 | /// 20 | public bool IsAbort { get; } 21 | 22 | /// 23 | /// The status code of the failed request 24 | /// 25 | public int StatusCode { get; } 26 | 27 | /// 28 | /// Contains the JSON API error response 29 | /// 30 | public IDictionary? Response { get; } 31 | 32 | /// 33 | /// The original response error 34 | /// 35 | public Exception? OriginalError { get; } 36 | 37 | public ClientException(string url, bool isAbort = false, int statusCode = 500, IDictionary? response = null, Exception? originalError = null) 38 | { 39 | Url = url; 40 | IsAbort = isAbort; 41 | StatusCode = statusCode; 42 | Response = response; 43 | OriginalError = originalError; 44 | } 45 | 46 | public override string Message => FormatMessage(); 47 | 48 | private string FormatMessage() 49 | { 50 | Dictionary result = new() 51 | { 52 | {"url", Url }, 53 | {"isAbort", IsAbort }, 54 | {"statusCode", StatusCode }, 55 | {"response", Response }, 56 | {"originalError", OriginalError }, 57 | }; 58 | 59 | return $"ClientException: {result}"; 60 | } 61 | 62 | public override string ToString() 63 | { 64 | return $"ClientException: {FormatMessage()}"; 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionTestForTypes.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionTestForTypes : CollectionBase 19 | { 20 | /// 21 | public override string Id => "fyyuitlkl66dgyt"; 22 | 23 | /// 24 | public override string Name => "test_for_types"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'test_for_types' 30 | /// The DataService for the collection 31 | internal CollectionTestForTypes(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'test_for_types' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new TestForType.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'test_for_types' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/FileListConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using PocketBaseClient.Orm.Structures; 12 | using System.Text.Json; 13 | using System.Text.Json.Serialization; 14 | 15 | namespace PocketBaseClient.Orm.Json 16 | { 17 | /// 18 | /// Converter for list of file type 19 | /// 20 | /// The type of the list 21 | /// The mapped related type 22 | public class FileListConverter : JsonConverter 23 | where L : FieldFileList, new() 24 | where T : FieldFileBase, new() 25 | { 26 | /// 27 | public override L? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 28 | { 29 | L valueList = new(); 30 | var strArray = JsonSerializer.Deserialize(ref reader, options) ?? Array.Empty(); 31 | 32 | foreach (var str in strArray) 33 | { 34 | var value = new T() { FileName = str }; 35 | valueList.Add(value); 36 | valueList.OriginalFileNames.Add(str); 37 | } 38 | return valueList; 39 | } 40 | 41 | /// 42 | public override void Write(Utf8JsonWriter writer, L? value, JsonSerializerOptions options) 43 | { 44 | if (value is null) 45 | writer.WriteNullValue(); 46 | else 47 | { 48 | writer.WriteStartArray(); 49 | foreach (var val in value!) 50 | writer.WriteStringValue(val.FileName); 51 | writer.WriteEndArray(); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/CollectionTestForRelateds.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm; 13 | using PocketBaseClient.Orm.Filters; 14 | using PocketBaseClient.Services; 15 | 16 | namespace PocketBaseClient.DemoTest.Models 17 | { 18 | public partial class CollectionTestForRelateds : CollectionBase 19 | { 20 | /// 21 | public override string Id => "v2ge3yxdn90bhss"; 22 | 23 | /// 24 | public override string Name => "test_for_related"; 25 | 26 | /// 27 | public override bool System => false; 28 | 29 | /// Contructor: The Collection 'test_for_related' 30 | /// The DataService for the collection 31 | internal CollectionTestForRelateds(DataServiceBase context) : base(context) { } 32 | 33 | /// Query data at PocketBase, defining a Filter over collection 'test_for_related' 34 | public CollectionQuery Filter(Func filter) 35 | => new CollectionQuery(this, filter(new TestForRelated.Filters())); 36 | 37 | /// Query all data at PocketBase, over collection 'test_for_related' 38 | public CollectionQuery All() 39 | => new CollectionQuery(this, null); 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/RelationListConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using PocketBaseClient.Orm.Structures; 12 | using PocketBaseClient.Services; 13 | using System.Text.Json; 14 | using System.Text.Json.Serialization; 15 | 16 | namespace PocketBaseClient.Orm.Json 17 | { 18 | /// 19 | /// Converter for list of relations type 20 | /// 21 | /// The type of the list 22 | /// The mapped related type 23 | public class RelationListConverter : JsonConverter 24 | where L : FieldItemList, new() 25 | where T : ItemBase, new() 26 | { 27 | /// 28 | public override L? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 29 | { 30 | L valueList = new(); 31 | var strArray = JsonSerializer.Deserialize(ref reader, options) ?? Array.Empty(); 32 | 33 | foreach (var str in strArray) 34 | { 35 | var value = DataServiceBase.GetCollection()!.AddIdFromPb(str); 36 | if (value != null) 37 | valueList.Add(value); 38 | } 39 | return valueList; 40 | } 41 | 42 | /// 43 | public override void Write(Utf8JsonWriter writer, L? value, JsonSerializerOptions options) 44 | { 45 | if (value is null) 46 | writer.WriteNullValue(); 47 | else 48 | { 49 | writer.WriteStartArray(); 50 | foreach (var val in value!) 51 | writer.WriteStringValue(val.Id); 52 | writer.WriteEndArray(); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Test/PocketBaseClient.DemoTest/Models/Post.Sorts.cs: -------------------------------------------------------------------------------- 1 | 2 | // This file was generated automatically for the PocketBase Application demo-test (https://orm-csharp-test.pockethost.io) 3 | // See CodeGenerationSummary.txt for more details 4 | // 5 | // PocketBaseClient-csharp project: https://github.com/iluvadev/PocketBaseClient-csharp 6 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 7 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 8 | // 9 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 10 | // pocketbase project: https://github.com/pocketbase/pocketbase 11 | 12 | using PocketBaseClient.Orm.Filters; 13 | 14 | namespace PocketBaseClient.DemoTest.Models 15 | { 16 | public partial class Post 17 | { 18 | public class Sorts : ItemBaseSorts 19 | { 20 | 21 | /// Makes a SortCommand to Order by the 'title' field 22 | public SortCommand Title => new SortCommand("title"); 23 | 24 | /// Makes a SortCommand to Order by the 'author' field 25 | public SortCommand Author => new SortCommand("author"); 26 | 27 | /// Makes a SortCommand to Order by the 'summary' field 28 | public SortCommand Summary => new SortCommand("summary"); 29 | 30 | /// Makes a SortCommand to Order by the 'content' field 31 | public SortCommand Content => new SortCommand("content"); 32 | 33 | /// Makes a SortCommand to Order by the 'published' field 34 | public SortCommand Published => new SortCommand("published"); 35 | 36 | /// Makes a SortCommand to Order by the 'status' field 37 | public SortCommand Status => new SortCommand("status"); 38 | 39 | /// Makes a SortCommand to Order by the 'categories' field 40 | public SortCommand Categories => new SortCommand("categories"); 41 | 42 | /// Makes a SortCommand to Order by the 'tags' field 43 | public SortCommand Tags => new SortCommand("tags"); 44 | 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Extensions/EnumExtensions.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using System.ComponentModel; 12 | using System.Reflection; 13 | 14 | namespace PocketBaseClient 15 | { 16 | /// 17 | /// Extensions for Enums 18 | /// 19 | internal static class EnumExtensions 20 | { 21 | /// 22 | /// Gets the Description defined in a 23 | /// 24 | /// 25 | /// 26 | /// 27 | public static string? GetDescription(this T enumValue) where T : struct, IConvertible 28 | { 29 | string? output = null; 30 | FieldInfo? fi = enumValue.GetType().GetField(enumValue.ToString() ?? ""); 31 | var attrs = fi?.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[]; 32 | if (attrs?.Length > 0) 33 | output = attrs[0].Description; 34 | return output; 35 | } 36 | 37 | /// 38 | /// Gets the enum values with their Descriptions defined in a 39 | /// 40 | /// 41 | /// 42 | /// 43 | /// 44 | public static IDictionary GetEnumValuesWithDescription(this Type type) where T : struct, IConvertible 45 | { 46 | if (!type.IsEnum) throw new ArgumentException("T must be an enumerated type"); 47 | 48 | return type.GetEnumValues().OfType().ToDictionary(key => key, val => val.GetDescription()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Filters/FieldFilterUri.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | namespace PocketBaseClient.Orm.Filters 12 | { 13 | /// 14 | /// Filter definitions for Fields of type Url 15 | /// 16 | public class FieldFilterUri : FieldFilterText 17 | { 18 | /// 19 | /// Ctor 20 | /// 21 | /// 22 | public FieldFilterUri(string fieldName) : base(fieldName) 23 | { 24 | } 25 | 26 | /// 27 | /// The Field is Equal to 28 | /// 29 | /// The value to compare 30 | /// 31 | public FilterCommand Equal(Uri value) 32 | => Equal(value.ToString()); 33 | 34 | /// 35 | /// The Field is NOT Equal to 36 | /// 37 | /// The value to compare 38 | /// 39 | public FilterCommand NotEqual(Uri value) 40 | => NotEqual(value.ToString()); 41 | 42 | /// 43 | /// The Field Starts With 44 | /// 45 | /// The value to compare 46 | /// 47 | public FilterCommand StartsWith(Uri value) 48 | => StartsWith(value.ToString()); 49 | 50 | /// 51 | /// The Field do NOT Starts With 52 | /// 53 | /// The value to compare 54 | /// 55 | public FilterCommand NotStartsWith(Uri value) 56 | => NotStartsWith(value.ToString()); 57 | } 58 | } -------------------------------------------------------------------------------- /src/PocketBaseClient/Orm/Json/EnumListConverter.cs: -------------------------------------------------------------------------------- 1 | // Project site: https://github.com/iluvadev/PocketBaseClient-csharp 2 | // 3 | // Issues: https://github.com/iluvadev/PocketBaseClient-csharp/issues 4 | // License (MIT): https://github.com/iluvadev/PocketBaseClient-csharp/blob/main/LICENSE 5 | // 6 | // Copyright (c) 2022, iluvadev, and released under MIT License. 7 | // 8 | // pocketbase-csharp-sdk project: https://github.com/PRCV1/pocketbase-csharp-sdk 9 | // pocketbase project: https://github.com/pocketbase/pocketbase 10 | 11 | using PocketBaseClient.Orm.Structures; 12 | using System.Text.Json; 13 | using System.Text.Json.Serialization; 14 | 15 | namespace PocketBaseClient.Orm.Json 16 | { 17 | /// 18 | /// Converter for list of select types (list of enums) 19 | /// 20 | /// The list type 21 | /// The enum type 22 | public class EnumListConverter : JsonConverter 23 | where L : IBasicList, new() 24 | where T : struct, IConvertible 25 | { 26 | /// 27 | public override L? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 28 | { 29 | L valueList = new(); 30 | var strArray = JsonSerializer.Deserialize(ref reader, options) ?? Array.Empty(); 31 | 32 | var valuesDesc = typeof(T).GetEnumValuesWithDescription(); 33 | foreach (var str in strArray) 34 | { 35 | var value = valuesDesc?.FirstOrDefault(kvp => kvp.Value == str).Key; 36 | if (value != null) 37 | valueList.Add(value.Value); 38 | } 39 | return valueList; 40 | } 41 | 42 | /// 43 | public override void Write(Utf8JsonWriter writer, L? value, JsonSerializerOptions options) 44 | { 45 | if (value is null) 46 | writer.WriteNullValue(); 47 | else 48 | { 49 | writer.WriteStartArray(); 50 | foreach (var val in value!) 51 | writer.WriteStringValue(val.GetDescription()); 52 | writer.WriteEndArray(); 53 | } 54 | } 55 | } 56 | } 57 | --------------------------------------------------------------------------------