Skip to content

Commit 6a5b275

Browse files
committed
add: storage primitives
Signed-off-by: shayanhabibi <[email protected]>
1 parent 9108384 commit 6a5b275

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<PropertyGroup>
5+
<FablePackageType>library</FablePackageType>
6+
<TargetFramework>net9.0</TargetFramework>
7+
<PackageId>Partas.Solid.Primitives.Storage</PackageId>
8+
<Title>Partas.Solid.Primitives.Storage</Title>
9+
<Company>F# Community</Company>
10+
<Description>Bindings for Solid-js primitives</Description>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<RepositoryUrl>https://github.com/shayanhabibi/Partas.Solid.Primitives</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<PackageTags>Partas;Oxpecker;F#;FSharp;Fable;fable-javascript;Web;Framework;Solid;Solidjs;Bindings;Primitives</PackageTags>
15+
<Authors>Shayan Habibi</Authors>
16+
<Copyright>Copyright (c) Shayan Habibi 2025</Copyright>
17+
<Version>0.1.0</Version>
18+
<PackageVersion>0.1.0</PackageVersion>
19+
<GitNetInitialVersion>0.1.0</GitNetInitialVersion>
20+
<NpmDependencies>
21+
<NpmPackage Name="@solid-primitives/storage" Version="&gt;= 4.3.2" />
22+
</NpmDependencies>
23+
</PropertyGroup>
24+
25+
26+
<ItemGroup>
27+
<Compile Include="Program.fs" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<PackageReference Include="Fable.Core" Version="4.5.0" />
32+
<PackageReference Include="Fable.Package.SDK" Version="1.3.1">
33+
<IncludeAssets>runtime; build; native; analyzers; buildtransitive</IncludeAssets>
34+
<PrivateAssets>all</PrivateAssets>
35+
</PackageReference>
36+
<PackageReference Include="Partas.Solid" Version="2.*" />
37+
</ItemGroup>
38+
39+
40+
<ItemGroup>
41+
<ProjectReference Include="..\Partas.Solid.Primitives.Common\Partas.Solid.Primitives.Common.fsproj" />
42+
</ItemGroup>
43+
44+
</Project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace Partas.Solid.Primitives
2+
3+
open System
4+
open Fable.Core
5+
open Fable.Core.JS
6+
open Fable.Core.JsInterop
7+
open Partas.Solid
8+
[<Erase; AutoOpen>]
9+
module StorageSpec =
10+
[<Erase>]
11+
module Spec =
12+
[<Literal>]
13+
let path = "@solid-primitives/storage"
14+
[<Literal>]
15+
let version = "4.3.2"
16+
17+
type SyncStorage =
18+
abstract getItem: key: string -> string option
19+
abstract setItem: key: string * value: string -> unit
20+
abstract removeItem: key: string -> unit
21+
[<EmitIndexer>]
22+
abstract Item: string -> obj
23+
type AsyncStorage =
24+
abstract getItem: key: string -> Promise<string option>
25+
abstract setItem: key: string * value: string -> Promise<obj>
26+
abstract removeItem: key: string -> Promise<unit>
27+
[<EmitIndexer>]
28+
abstract Item: string -> obj
29+
type SyncStorageWithOptions<'Options> =
30+
abstract getItem: key: string * ?options: 'Options -> string option
31+
abstract setItem: key: string * value: string * ?options: 'Options -> unit
32+
abstract removeItem: key: string * ?options: 'Options -> unit
33+
[<EmitIndexer>]
34+
abstract Item: string -> obj
35+
type AsyncStorageWithOptions<'Options> =
36+
abstract getItem: key: string * ?options: 'Options -> Promise<string option>
37+
abstract setItem: key: string * value: string * ?options: 'Options -> Promise<obj>
38+
abstract removeItem: key: string * ?options: 'Options -> Promise<unit>
39+
[<EmitIndexer>]
40+
abstract Item: string -> obj
41+
42+
type PersistenceSyncData =
43+
abstract key: string with get,set
44+
abstract newValue: string option with get,set
45+
abstract timeStamp: float with get,set
46+
abstract url: string option with get,set
47+
type PersistenceSyncCallback = PersistenceSyncData -> unit
48+
type PersistenceSyncSubscribe = PersistenceSyncCallback -> unit
49+
type PersistenceSyncUpdate = string * string option -> unit
50+
type PersistenceSyncAPI = PersistenceSyncSubscribe * PersistenceSyncUpdate
51+
[<Pojo>]
52+
type PersistenceOptions<'T, 'Options>(
53+
?name: string
54+
,?serialize: 'T -> string
55+
,?deserialize: string -> 'T
56+
,?sync: PersistenceSyncAPI
57+
,?storage: U4<SyncStorage, AsyncStorage, SyncStorageWithOptions<'Options>, AsyncStorageWithOptions<'Options>>
58+
,?storageOptions: 'Options
59+
) =
60+
[<DefaultValue>]
61+
val mutable name: string
62+
[<DefaultValue>]
63+
val mutable serialize: 'T -> string
64+
[<DefaultValue>]
65+
val mutable deserialize: string -> 'T
66+
[<DefaultValue>]
67+
val mutable sync: PersistenceSyncAPI
68+
[<DefaultValue>]
69+
val mutable storage: U4<SyncStorage, AsyncStorage, SyncStorageWithOptions<'Options>, AsyncStorageWithOptions<'Options>>
70+
[<DefaultValue>]
71+
val mutable storageOptions: 'Options
72+
73+
type PersistedState<'T> = Accessor<'T> * Setter<'T> * obj
74+
75+
76+
[<Erase; AutoOpen>]
77+
type Storage =
78+
[<ImportMember(Spec.path)>]
79+
static member makePersisted<'T>(signal: Signal<'T>, ?options: PersistenceOptions<'T, _>): PersistedState<'T> = jsNative
80+
[<ImportMember(Spec.path)>]
81+
static member storageSync: PersistenceSyncAPI = jsNative
82+
// TODO broadcast channel overload
83+
[<ImportMember(Spec.path)>]
84+
static member messageSync(?channel: Browser.Types.Window): PersistenceSyncAPI = jsNative
85+
// TODO
86+
// [<ImportMember(Spec.path)>]
87+
// static member wsSync(ws: WebSocket, ?warnOnError: bool): PersistenceSyncAPI = jsNative
88+
[<ImportMember(Spec.path)>]
89+
static member multiplexSync([<ParamArray>] syncAPIs: PersistenceSyncAPI[]): PersistenceSyncAPI = jsNative

0 commit comments

Comments
 (0)