Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"Bash(timeout:*)",
"mcp__darklang-push-notifications__send_ntfy_notification",
"mcp__push-notifications__send_pushover_notification",
"mcp__push-notifications__send_ntfy_notification"
"mcp__push-notifications__send_ntfy_notification",
"Bash(git log:*)",
"Bash(git ls-tree:*)"
],
"deny": []
}
}
}
2 changes: 1 addition & 1 deletion backend/fsdark.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "LibPackageManager", "src\Li
EndProject

# Cloud stuff
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "LibBinarySerialization", "src\LibBinarySerialization\LibBinarySerialization.fsproj", "{5830D9BF-CA28-47B0-964F-343FAB28751B}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "LibSerialization", "src\LibSerialization\LibSerialization.fsproj", "{5830D9BF-CA28-47B0-964F-343FAB28751B}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "LibService", "src\LibService\LibService.fsproj", "{824DD2A5-7F01-4A8A-9ABD-9F91F52582AD}"
EndProject
Expand Down
10 changes: 5 additions & 5 deletions backend/src/BuiltinCliHost/Libs/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module PackageIDs = LibExecution.PackageIDs
module Json = BuiltinExecution.Libs.Json
module C2DT = LibExecution.CommonToDarkTypes
module D = LibExecution.DvalDecoder
module PM = LibPackageManager.PackageManager

module Utils = BuiltinCliHost.Utils

Expand Down Expand Up @@ -130,8 +131,8 @@ module ExecutionError =
let typeRef = TCustomType(Ok fqTypeName, [])


let pmRT = LibPackageManager.PackageManager.rt
let ptPM = LibPackageManager.PackageManager.pt
let pmRT = PM.rt
let ptPM = PM.pt

let builtinsToUse : RT.Builtins =
LibExecution.Builtin.combine
Expand Down Expand Up @@ -169,9 +170,8 @@ let execute
[ mod'.fns |> List.map PT2RT.PackageFn.toRT
mod'.submodules.fns |> List.map PT2RT.PackageFn.toRT ]

// TODO we should probably use LibPM's in-memory grafting thing instead of this
// (no need for RT.PM.withExtras to exist, I think)
let pm = pmRT |> PackageManager.withExtras types values fns
// Layer the parsed script's types/values/fns on top of the base RT PM
let pm = pmRT |> RT.PackageManager.withExtras types values fns

let tracing = Exe.noTracing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ProjectReference Include="../LibExecution/LibExecution.fsproj" />
<ProjectReference Include="../LibDB/LibDB.fsproj" />
<ProjectReference Include="../LibCloud/LibCloud.fsproj" />
<ProjectReference Include="../LibBinarySerialization/LibBinarySerialization.fsproj" />
<ProjectReference Include="../LibSerialization/LibSerialization.fsproj" />
<ProjectReference Include="../LibPackageManager/LibPackageManager.fsproj" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/BuiltinPM/Builtin.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let fnRenames : Builtin.FnRenames =
let builtins (pm : PT.PackageManager) : Builtins =
Builtin.combine
[ Libs.Packages.builtins pm
Libs.PackageOps.builtins
Libs.PackageOps.builtins pm
Libs.Instances.builtins
Libs.Branches.builtins
Libs.Sync.builtins
Expand Down
2 changes: 1 addition & 1 deletion backend/src/BuiltinPM/BuiltinPM.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ProjectReference Include="../Prelude/Prelude.fsproj" />
<ProjectReference Include="../LibExecution/LibExecution.fsproj" />
<ProjectReference Include="../LibPackageManager/LibPackageManager.fsproj" />
<ProjectReference Include="../LibBinarySerialization/LibBinarySerialization.fsproj" />
<ProjectReference Include="../LibSerialization/LibSerialization.fsproj" />
<ProjectReference Include="../LibDB/LibDB.fsproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
Expand Down
3 changes: 2 additions & 1 deletion backend/src/BuiltinPM/Libs/Branches.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ open LibExecution.RuntimeTypes
module VT = LibExecution.ValueType
module Dval = LibExecution.Dval
module Builtin = LibExecution.Builtin
module Branches = LibPackageManager.Branches
module DarkDateTime = LibExecution.DarkDateTime
module PackageIDs = LibExecution.PackageIDs

module Branches = LibPackageManager.PT.SQL.Branches

open Builtin.Shortcuts


Expand Down
27 changes: 1 addition & 26 deletions backend/src/BuiltinPM/Libs/Instances.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,7 @@ let fns : List<BuiltInFn> =
function
| _, _, _, [ DUuid instanceID ] ->
uply {
let! instanceOpt = Instances.getByID instanceID

return
instanceOpt
|> Option.map instanceToDT
|> Dval.option (KTCustomType(instanceTypeName, []))
}
| _ -> incorrectArgs ()
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }


{ name = fn "scmGetInstanceByName" 0
typeParams = []
parameters = [ Param.make "name" TString "" ]
returnType = TypeReference.option (TCustomType(Ok instanceTypeName, []))
description = "Get an instance by name. Returns None if not found."
fn =
function
| _, _, _, [ DString name ] ->
uply {
let! instanceOpt = Instances.getByName name
let! instanceOpt = Instances.get instanceID

return
instanceOpt
Expand All @@ -84,11 +62,8 @@ let fns : List<BuiltInFn> =
| _, _, _, [ DUnit ] ->
uply {
let! instances = Instances.list ()

let instanceDvals = instances |> List.map instanceToDT

let vt = VT.customType instanceTypeName []

return DList(vt, instanceDvals)
}
| _ -> incorrectArgs ()
Expand Down
65 changes: 9 additions & 56 deletions backend/src/BuiltinPM/Libs/PackageOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let packageOpTypeName =


// TODO: review/reconsider the accessibility of these fns
let fns : List<BuiltInFn> =
let fns (pm : PT.PackageManager) : List<BuiltInFn> =
[ { name = fn "scmAddOps" 0
typeParams = []
parameters =
Expand All @@ -44,11 +44,12 @@ let fns : List<BuiltInFn> =
let branchID = C2DT.Option.fromDT D.uuid branchID
let ops = ops |> List.choose PT2DT.PackageOp.fromDT

// Insert ops with deduplication, get count of actually inserted ops
let! insertedCount =
LibPackageManager.Inserts.insertAndApplyOps branchID ops
// Insert ops with deduplication
do! pm.applyOps (branchID, ops)

return resultOk (DInt64 insertedCount)
// TODO: Return actual inserted count (not total ops count)
// Currently applyOps doesn't return count, so we return attempted count
return resultOk (DInt64(int64 (List.length ops)))
with ex ->
return resultError (DString ex.Message)
}
Expand All @@ -58,55 +59,6 @@ let fns : List<BuiltInFn> =
deprecated = NotDeprecated }


{ name = fn "scmGetRecentOps" 0
typeParams = []
parameters =
[ Param.make "branchID" (TypeReference.option TUuid) ""
Param.make "limit" TInt64 "" ]
returnType = TList(TCustomType(Ok packageOpTypeName, []))
description = "Get recent package ops from the database."
fn =
function
| _, _, _, [ branchID; DInt64 limit ] ->
uply {
let branchID = C2DT.Option.fromDT D.uuid branchID

let! ops = LibPackageManager.Queries.getRecentOps branchID limit

return
DList(
VT.customType PT2DT.PackageOp.typeName [],
ops |> List.map PT2DT.PackageOp.toDT
)
}
| _ -> incorrectArgs ()
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }


{ name = fn "scmGetRecentOpsAllBranches" 0
typeParams = []
parameters = [ Param.make "limit" TInt64 "" ]
returnType = TList(TCustomType(Ok packageOpTypeName, []))
description = "Get recent package ops from ALL branches (no branch filter)."
fn =
function
| _, _, _, [ DInt64 limit ] ->
uply {
let! ops = LibPackageManager.Queries.getRecentOpsAllBranches limit
return
DList(
VT.customType PT2DT.PackageOp.typeName [],
ops |> List.map PT2DT.PackageOp.toDT
)
}
| _ -> incorrectArgs ()
sqlSpec = NotQueryable
previewable = Impure
deprecated = NotDeprecated }


{ name = fn "scmGetOpsSince" 0
typeParams = []
parameters =
Expand All @@ -120,7 +72,7 @@ let fns : List<BuiltInFn> =
uply {
let branchID = C2DT.Option.fromDT D.uuid branchID

let! ops = LibPackageManager.Queries.getOpsSince branchID since
let! ops = LibPackageManager.PT.SQL.Sync.getOpsSince branchID since

return
DList(
Expand All @@ -134,4 +86,5 @@ let fns : List<BuiltInFn> =
deprecated = NotDeprecated } ]


let builtins : Builtins = LibExecution.Builtin.make [] fns
let builtins (pm : PT.PackageManager) : Builtins =
LibExecution.Builtin.make [] (fns pm)
2 changes: 1 addition & 1 deletion backend/src/BuiltinPM/Libs/Packages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let fns (pm : PT.PackageManager) : List<BuiltInFn> =
function
| _, _, _, [ DUnit ] ->
uply {
let! stats = LibPackageManager.Stats.get ()
let! stats = LibPackageManager.PT.SQL.Stats.get ()

return
DRecord(
Expand Down
6 changes: 4 additions & 2 deletions backend/src/BuiltinPM/Libs/Sync.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ open LibExecution.RuntimeTypes
module Builtin = LibExecution.Builtin
module Dval = LibExecution.Dval

module Sync = LibPackageManager.PT.SQL.Sync

open Builtin.Shortcuts


Expand All @@ -24,7 +26,7 @@ let fns : List<BuiltInFn> =
function
| _, _, _, [ DUuid instanceID ] ->
uply {
let! lastSync = LibPackageManager.Sync.getLastSyncDate instanceID
let! lastSync = Sync.getLastSyncDate instanceID

return lastSync |> Option.map DDateTime |> Dval.option KTDateTime
}
Expand All @@ -46,7 +48,7 @@ let fns : List<BuiltInFn> =
function
| _, _, _, [ DUuid instanceID; DInt64 opsPushed; DInt64 opsFetched ] ->
uply {
do! LibPackageManager.Sync.recordSync instanceID opsPushed opsFetched
do! Sync.recordSync instanceID opsPushed opsFetched

return DUnit
}
Expand Down
3 changes: 2 additions & 1 deletion backend/src/Cli/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Exe = LibExecution.Execution
module PackageIDs = LibExecution.PackageIDs
module BuiltinCli = BuiltinCli.Builtin
module BuiltinCliHost = BuiltinCliHost.Libs.Cli
module PM = LibPackageManager.PackageManager

// Dual logging (console + cli.log file)
let private logError (message : string) : unit =
Expand Down Expand Up @@ -122,7 +123,7 @@ let main (args : string[]) =
EmbeddedResources.extract ()
initSerializers ()

let cliPackageManager = LibPackageManager.PackageManager.rt
let cliPackageManager = PM.rt
cliPackageManager.init.Result

let result = execute cliPackageManager (Array.toList args)
Expand Down
Loading