Skip to content
Merged
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
4 changes: 2 additions & 2 deletions logseq_chat.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ depends: [
"sqlite3"
]
pin-depends: [
["datascript_ocaml.dev" "git+https://github.com/logseq/datascript-ocaml.git#67f10f27db0a9fb075d47c385db39c52651ec846"]
["datascript-ocaml-native.dev" "git+https://github.com/logseq/datascript-ocaml.git#67f10f27db0a9fb075d47c385db39c52651ec846"]
["datascript_ocaml.dev" "git+https://github.com/logseq/datascript-ocaml.git#e439cbac48b28800820984ea3e285cf26a4f92b5"]
["datascript-ocaml-native.dev" "git+https://github.com/logseq/datascript-ocaml.git#e439cbac48b28800820984ea3e285cf26a4f92b5"]
["persistent_sorted_set_ocaml.dev" "git+https://github.com/logseq/persistent-sorted-set-ocaml.git#4016dae1cdf4304207d8277ff9957656cdd8b177"]
["melange-edn-core.0.5.0" "git+https://github.com/logseq/melange-edn.git#main"]
["melange-edn-native.0.5.0" "git+https://github.com/logseq/melange-edn.git#main"]
Expand Down
4 changes: 2 additions & 2 deletions shared/src/logseq_chat/core/cache_model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let one value_type indexed unique =
}

let string_decode = function Ds.String value -> value | _ -> failwith "expected string"
let int_decode = function Ds.Int value -> value | _ -> failwith "expected int"
let int_decode = function Ds.Int64 value -> Int64.to_int value | _ -> failwith "expected int"

let text_attribute name indexed =
{ attr_name = name
Expand All @@ -82,7 +82,7 @@ let text_attribute name indexed =
let number_attribute name indexed =
{ attr_name = name
; attr_spec = one Ds.NumberType indexed None
; attr_encode = (fun value -> Ds.Int value)
; attr_encode = (fun value -> Ds.Int64 (Int64.of_int value))
; attr_decode = int_decode
}

Expand Down
13 changes: 8 additions & 5 deletions shared/src/logseq_chat/core/datascript_value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ let built_in_ref_attrs =
let built_in_ref_attr attr = List.mem attr built_in_ref_attrs

let value_type_is_ref db value =
match value with
| Ds.Keyword "db.type/ref" -> true
| Ds.Ref eid | Ds.Int eid ->
let check_eid eid =
Seq.exists
(fun (datom : Ds.datom) -> datom.v = Ds.Keyword "db.type/ref")
(Ds.Db.datoms db Ds.Eavt ~e:eid ~a:"db/ident" ())
in
match value with
| Ds.Keyword "db.type/ref" -> true
| Ds.Ref eid -> check_eid eid
| Ds.Int64 eid -> check_eid (Int64.to_int eid)
| _ -> false

let entity_declares_ref db attr =
Expand All @@ -33,7 +36,7 @@ let is_ref_attr db attr =
let ref_eid db attr value =
match value with
| Ds.Ref eid -> Some eid
| Ds.Int eid -> if is_ref_attr db attr then Some eid else None
| Ds.Int64 eid -> if is_ref_attr db attr then Some (Int64.to_int eid) else None
| _ -> None

let optional_ref_eid db attr value =
Expand All @@ -44,7 +47,7 @@ let datoms_by_ref db index attr eid =
let candidates =
Seq.append
(Ds.Db.datoms db index ~a:attr ~v:(Ds.Ref eid) ())
(Ds.Db.datoms db index ~a:attr ~v:(Ds.Int eid) ())
(Ds.Db.datoms db index ~a:attr ~v:(Ds.Int64 (Int64.of_int eid)) ())
in
Seq.filter
(fun (datom : Ds.datom) ->
Expand Down
2 changes: 1 addition & 1 deletion shared/src/logseq_chat/core/e2e_seed_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let reset_user_page_entities conn =

let uuid_attr value = Ds.One_value (Ds.Uuid value)
let string_attr value = Ds.One_value (Ds.String value)
let int_attr value = Ds.One_value (Ds.Int value)
let int_attr value = Ds.One_value (Ds.Int64 (Int64.of_int value))
let ref_attr id = Ds.One_value (Ds.Ref_to (Ds.Temp_id id))

let many_refs ids =
Expand Down
6 changes: 3 additions & 3 deletions shared/src/logseq_chat/core/entity_sync.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ let rec generic_value (input : Value.value) : Ds.value =
| Value.Null -> Ds.Nil
| Value.Bool value -> Ds.Bool value
| Value.String value -> Ds.String value
| Value.Int value -> Ds.Int value
| Value.Int64 value -> Ds.Int (Int64.to_int value)
| Value.Int value -> Ds.Int64 (Int64.of_int value)
| Value.Int64 value -> Ds.Int64 value
| Value.Float value -> Ds.Float value
| Value.Binary value -> Ds.String value
| Value.Big_decimal value -> Ds.Float (float_of_string value)
| Value.Big_int value -> Ds.Int (Int64.to_int (Int64.of_string value))
| Value.Big_int value -> Ds.Int64 (Int64.of_string value)
| Value.Date value -> Ds.Instant value
| Value.Uuid value -> Ds.Uuid value
| Value.Uri value -> Ds.String value
Expand Down
14 changes: 7 additions & 7 deletions shared/src/logseq_chat/core/flashcards.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ let state_value card =
[
(Ds.Keyword "stability", Ds.Float card.stability);
(Ds.Keyword "difficulty", Ds.Float card.difficulty);
(Ds.Keyword "elapsed-days", Ds.Int card.elapsed_days);
(Ds.Keyword "scheduled-days", Ds.Int card.scheduled_days);
(Ds.Keyword "reps", Ds.Int card.reps);
(Ds.Keyword "lapses", Ds.Int card.lapses);
(Ds.Keyword "elapsed-days", Ds.Int64 (Int64.of_int card.elapsed_days));
(Ds.Keyword "scheduled-days", Ds.Int64 (Int64.of_int card.scheduled_days));
(Ds.Keyword "reps", Ds.Int64 (Int64.of_int card.reps));
(Ds.Keyword "lapses", Ds.Int64 (Int64.of_int card.lapses));
(Ds.Keyword "state", Ds.Keyword (state_name card.state));
(Ds.Keyword "last-repeat", Ds.Int card.last_repeat);
(Ds.Keyword "last-repeat", Ds.Int64 (Int64.of_int card.last_repeat));
]
in
let entries =
Expand All @@ -163,12 +163,12 @@ let map_value key entries =
let float_value value =
match value with
| Some (Ds.Float value) -> Some value
| Some (Ds.Int value) -> Some (float_of_int value)
| Some (Ds.Int64 value) -> Some (Int64.to_float value)
| _ -> None

let int_value value =
match value with
| Some (Ds.Int value) -> Some value
| Some (Ds.Int64 value) -> Some (Int64.to_int value)
| Some (Ds.Instant value) -> Some (Int64.to_int value)
| _ -> None

Expand Down
8 changes: 4 additions & 4 deletions shared/src/logseq_chat/core/graph_bootstrap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let graph_metadata graph_id e2ee now =
kv "logseq.kv/graph-uuid" (Ds.Uuid graph_id)
; kv "logseq.kv/graph-remote?" (Ds.Bool true)
; kv "logseq.kv/graph-rtc-e2ee?" (Ds.Bool e2ee)
; kv "logseq.kv/graph-created-at" (Ds.Int now)
; kv "logseq.kv/graph-created-at" (Ds.Int64 (Int64.of_int now))
; kv "logseq.kv/local-graph-uuid" (Ds.Uuid (fresh_local_graph_uuid ()))
]

Expand Down Expand Up @@ -113,7 +113,7 @@ let normalize_scalar_maps (tx : Ds.tx_op) =

let valid_ref_value (value : Ds.value) =
match value with
| Ds.TxRef | Ds.Ref _ | Ds.Ref_to _ | Ds.Int _ | Ds.String _
| Ds.TxRef | Ds.Ref _ | Ds.Ref_to _ | Ds.Int64 _ | Ds.String _
| Ds.Keyword _ -> true
| Ds.Symbol value ->
value = "db/current-tx" || value = "datomic.tx"
Expand Down Expand Up @@ -249,11 +249,11 @@ let refresh_initial_timestamps now (tx : Ds.tx_op) =
(fun (attr, value) ->
( attr
, if attr = "block/created-at" || attr = "block/updated-at"
then Ds.One_value (Ds.Int now)
then Ds.One_value (Ds.Int64 (Int64.of_int now))
else if
attr = "file/created-at"
|| attr = "file/last-modified-at"
then Ds.One_value (Ds.Instant (Int64.of_int now))
then Ds.One_value (Ds.Int64 (Int64.of_int now))
else value ))
entity.Ds.attrs;
}
Expand Down
8 changes: 4 additions & 4 deletions shared/src/logseq_chat/core/graph_read.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let uuid_value = function
| _ -> None

let int_value = function
| Some (Ds.Int value) -> Some value
| Some (Ds.Int64 value) -> Some (Int64.to_int value)
| Some (Ds.Instant value) -> Some (Int64.to_int value)
| _ -> None

Expand Down Expand Up @@ -665,7 +665,7 @@ let recent_journal_page_ids limit db =
List.of_seq (Ds.Db.datoms db Ds.Aevt ~a:"block/journal-day" ())
|> List.filter_map (fun (datom : Ds.datom) ->
match datom.v with
| Ds.Int day ->
| Ds.Int64 day ->
if page_is_hidden db datom.e then None else Some (day, datom.e)
| _ -> None)
|> List.sort (fun (left, _) (right, _) -> compare right left)
Expand All @@ -688,8 +688,8 @@ let journal_page_uuid db day =
List.of_seq (Ds.Db.datoms db Ds.Aevt ~a:"block/journal-day" ())
|> List.find_map (fun (datom : Ds.datom) ->
match datom.v with
| Ds.Int candidate ->
if candidate = day && not (page_is_hidden db datom.e) then
| Ds.Int64 candidate ->
if Int64.equal candidate (Int64.of_int day) && not (page_is_hidden db datom.e) then
uuid_for_eid db datom.e
else None
| _ -> None)
Expand Down
2 changes: 1 addition & 1 deletion shared/src/logseq_chat/core/pending_ops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let rec semantic_value_from_datascript input =
let ( let* ) = Result.bind in
match input with
| Ds.String value -> Ok (String_value value)
| Ds.Int value -> Ok (Int_value value)
| Ds.Int64 value -> Ok (Int_value (Int64.to_int value))
| Ds.Instant value -> Ok (Instant_value (Int64.to_int value))
| Ds.Float value -> Ok (Float_value value)
| Ds.Bool value -> Ok (Bool_value value)
Expand Down
59 changes: 32 additions & 27 deletions shared/src/logseq_chat/core/pending_projection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let favorite_block_eid db page_uuid =
let rec datascript_value (value : Ops.semantic_value) : Ds.value =
match value with
| Ops.String_value value -> Ds.String value
| Ops.Int_value value -> Ds.Int value
| Ops.Int_value value -> Ds.Int64 (Int64.of_int value)
| Ops.Instant_value value -> Ds.Instant (Int64.of_int value)
| Ops.Float_value value -> Ds.Float value
| Ops.Bool_value value -> Ds.Bool value
Expand All @@ -77,12 +77,12 @@ let rec datascript_value (value : Ops.semantic_value) : Ds.value =
let rec semantic_value_equal_value db left right =
match (left, right) with
| Ds.String value, Ops.String_value expected -> value = expected
| Ds.Int value, Ops.Int_value expected -> value = expected
| Ds.Int64 value, Ops.Int_value expected -> Int64.equal value (Int64.of_int expected)
| Ds.Instant value, Ops.Instant_value expected -> Int64.equal value (Int64.of_int expected)
| Ds.Float value, Ops.Float_value expected ->
Float.equal value expected
| Ds.Int value, Ops.Float_value expected ->
Float.equal (Float.of_int value) expected
| Ds.Int64 value, Ops.Float_value expected ->
Float.equal (Int64.to_float value) expected
| Ds.Bool value, Ops.Bool_value expected -> value = expected
| Ds.Keyword value, Ops.Keyword_value expected -> value = expected
| Ds.Map entries, Ops.Map_value expected ->
Expand All @@ -100,12 +100,12 @@ let rec semantic_value_equal_value db left right =
expected
| Ds.Ref eid, Ops.Ref_uuid uuid ->
Ds.entid db "block/uuid" (Ds.Uuid uuid) = Some eid
| Ds.Int eid, Ops.Ref_uuid uuid ->
Ds.entid db "block/uuid" (Ds.Uuid uuid) = Some eid
| Ds.Int64 eid, Ops.Ref_uuid uuid ->
Ds.entid db "block/uuid" (Ds.Uuid uuid) = Some (Int64.to_int eid)
| Ds.Ref eid, Ops.Ref_ident ident ->
Ds.entid db "db/ident" (Ds.Keyword ident) = Some eid
| Ds.Int eid, Ops.Ref_ident ident ->
Ds.entid db "db/ident" (Ds.Keyword ident) = Some eid
| Ds.Int64 eid, Ops.Ref_ident ident ->
Ds.entid db "db/ident" (Ds.Keyword ident) = Some (Int64.to_int eid)
| _ -> false

let semantic_value_equal db left right =
Expand Down Expand Up @@ -194,7 +194,7 @@ let journal_page_eid db day =
Seq.find_map
(fun datom ->
match datom.Ds.v with
| Ds.Int value when value = day -> Some datom.Ds.e
| Ds.Int64 value when Int64.equal value (Int64.of_int day) -> Some datom.Ds.e
| _ -> None)
(Db.datoms db Ds.Aevt ~a:"block/journal-day" ())

Expand Down Expand Up @@ -237,8 +237,8 @@ let insert_tx db (block : Outliner.outliner_block) created_at =
; ( "block/parent"
, Ds.One_value (Ds.Ref_to (lookup block.parent_uuid)) )
; ( "block/order", Ds.One_value (Ds.String block.order) )
; ( "block/created-at", Ds.One_value (Ds.Int created_at) )
; ( "block/updated-at", Ds.One_value (Ds.Int created_at) )
; ( "block/created-at", Ds.One_value (Ds.Int64 (Int64.of_int created_at)) )
; ( "block/updated-at", Ds.One_value (Ds.Int64 (Int64.of_int created_at)) )
]
@ many_refs "block/refs" (refs_for_title db block.title)
@ many_refs "block/tags" (tag_eids_for_title db block.title));
Expand Down Expand Up @@ -319,8 +319,8 @@ let create_attrs uuid title created_at =
; ( "block/name"
, Ds.One_value (Ds.String (String.lowercase_ascii title)) )
; ("block/title", Ds.One_value (Ds.String title))
; ("block/created-at", Ds.One_value (Ds.Int created_at))
; ("block/updated-at", Ds.One_value (Ds.Int created_at))
; ("block/created-at", Ds.One_value (Ds.Int64 (Int64.of_int created_at)))
; ("block/updated-at", Ds.One_value (Ds.Int64 (Int64.of_int created_at)))
]

let rec compile db (intent : Ops.pending_intent) =
Expand Down Expand Up @@ -412,13 +412,13 @@ let rec compile db (intent : Ops.pending_intent) =
("db/ident", Ds.Keyword "logseq.class/Asset"))
] )
; ( "block/created-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "block/updated-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "logseq.property.asset/type"
, Ds.One_value (Ds.String value.asset_type) )
; ( "logseq.property.asset/size"
, Ds.One_value (Ds.Int value.asset_size) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.asset_size)) )
; ( "logseq.property.asset/checksum"
, Ds.One_value (Ds.String value.asset_checksum) )
; ( "logseq.property.asset/remote-metadata"
Expand Down Expand Up @@ -551,9 +551,9 @@ let rec compile db (intent : Ops.pending_intent) =
("db/ident", Ds.Keyword "logseq.class/Root"))
] )
; ( "block/created-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "block/updated-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
];
]
| Ops.Create_journal value ->
Expand All @@ -571,11 +571,11 @@ let rec compile db (intent : Ops.pending_intent) =
(Ds.String (String.lowercase_ascii value.title)) )
; ("block/title", Ds.One_value (Ds.String value.title))
; ( "block/journal-day"
, Ds.One_value (Ds.Int value.journal_day) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.journal_day)) )
; ( "block/created-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "block/updated-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
]
in
let attrs =
Expand Down Expand Up @@ -622,9 +622,9 @@ let rec compile db (intent : Ops.pending_intent) =
; ("block/parent", Ds.One_value (Ds.Ref_to page_ref))
; ("block/order", Ds.One_value (Ds.String "a0"))
; ( "block/created-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "block/updated-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
];
]))
| Ops.Add_tag value ->
Expand Down Expand Up @@ -672,9 +672,9 @@ let rec compile db (intent : Ops.pending_intent) =
; ( "block/order"
, Ds.One_value (Ds.String value.order) )
; ( "block/created-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
; ( "block/updated-at"
, Ds.One_value (Ds.Int value.created_at) )
, Ds.One_value (Ds.Int64 (Int64.of_int value.created_at)) )
];
]))
| Ops.Delete_page value ->
Expand All @@ -701,11 +701,16 @@ let rec compile db (intent : Ops.pending_intent) =
else
let parent =
match one_value db reference "block/parent" with
| Some (Ds.Ref eid) | Some (Ds.Int eid) ->
| Some (Ds.Ref eid) ->
[
( "logseq.property.recycle/original-parent"
, Ds.One_value (Ds.Ref eid) )
]
| Some (Ds.Int64 eid) ->
[
( "logseq.property.recycle/original-parent"
, Ds.One_value (Ds.Ref (Int64.to_int eid)) )
]
| _ -> []
in
let order =
Expand Down Expand Up @@ -777,7 +782,7 @@ let rec satisfied db (intent : Ops.pending_intent) =
(one_value db reference "logseq.property.asset/type")
= Some value.asset_type
&& one_value db reference "logseq.property.asset/size"
= Some (Ds.Int value.asset_size)
= Some (Ds.Int64 (Int64.of_int value.asset_size))
&& string_value
(one_value db reference "logseq.property.asset/checksum")
= Some value.asset_checksum
Expand Down
10 changes: 5 additions & 5 deletions shared/src/logseq_chat/core/storage_codec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ let rec value_of_transit input : Ds.value =
| Value.Null -> Ds.Nil
| Value.Bool value -> Ds.Bool value
| Value.String value -> Ds.String value
| Value.Int value -> Ds.Int value
| Value.Int64 value -> Ds.Int (Int64.to_int value)
| Value.Int value -> Ds.Int64 (Int64.of_int value)
| Value.Int64 value -> Ds.Int64 value
| Value.Float value -> Ds.Float value
| Value.Binary value -> Ds.String value
| Value.Big_decimal value -> Ds.Float (float_of_string value)
| Value.Big_int value -> Ds.Int (Int64.to_int (Int64.of_string value))
| Value.Big_int value -> Ds.Int64 (Int64.of_string value)
| Value.Date value -> Ds.Instant value
| Value.Uuid value -> Ds.Uuid value
| Value.Uri value -> Ds.String value
Expand All @@ -257,14 +257,14 @@ let rec value_of_transit input : Ds.value =
let rec value_to_transit input : Value.value =
match input with
| Ds.Nil -> Value.Null
| Ds.Int value -> Value.Int value
| Ds.Int64 value -> Value.Int64 value
| Ds.Float value -> Value.Float value
| Ds.String value -> Value.String value
| Ds.Symbol value -> Value.Symbol value
| Ds.Bool value -> Value.Bool value
| Ds.Keyword value -> Value.Keyword value
| Ds.Uuid value -> Value.Tagged ("u", Value.String value)
| Ds.Instant value -> Value.Tagged ("m", Value.Int (Int64.to_int value))
| Ds.Instant value -> Value.Tagged ("m", Value.Int64 value)
| Ds.Regex value -> Value.Tagged ("regex", Value.String value)
| Ds.Ref value -> Value.Int value
| Ds.List values -> Value.List (List.map value_to_transit values)
Expand Down
Loading
Loading