Skip to content

Commit

Permalink
Merge pull request #4 from skilesare/main
Browse files Browse the repository at this point in the history
Merge changes - Refactor
  • Loading branch information
skilesare committed Mar 5, 2022
2 parents 4d7901c + 266185e commit ecd2cb0
Show file tree
Hide file tree
Showing 11 changed files with 1,483 additions and 1,209 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ Library for Converting Types and Creating Workable Motoko Collections

This library provides for both Stable and Unstable collections and conversions. These methods help with keeping data in unstable workable runtime memory while providing methods to convert those objects to stable collections that can be put into upgrade variables for persistence across upgrades or for shipping the objects to other canisters and returning them as async functions.

I have refactored the files into separate libraries to silo some of the functionality.

type.mo - holds most types and few conversion functions to stabilize/destabilize candy values, properties, and workspace types.

conversion.mo - holds most of the conversion functions

clone.mo - has some clone functions for deep cloning classes

properties.mo - property and class functions for updating and manipulating classes

workspace.mo - useful for keeping workable data in chunks that can be moved around canisters.

CandyValue and CandyValueUnstable allow you to specify your variables in a variant class that makes keeping arrays and buffers of different types managable. ie stable var myCollection : [CandyValueStable] = [#Int(0), #Text("second value"), #Float(3.14)]

The property objects (adapted from https://github.com/DepartureLabsIC/non-fungible-token/blob/main/src/property.mo with copyright DepartureLabs and under MIT License, included here for compilability reasons.) allow for Key/Value collections that can be easily created, queried, and updated. We include conversions between stable and unstable properties.
Expand Down Expand Up @@ -76,3 +88,8 @@ Todo: Tests, examples

Note: This project was a part of the [ARAMAKME expirament](https://hwqwz-ryaaa-aaaai-aasoa-cai.raw.ic0.app/) and an example of how to integrate an ARAMAKME license into a library can be found in the /Example_Aramakme_License folder. The ARAMAKME license has since been removed from this library and it is licensed under the MIT License. Until they are all distributed, the ARAMAKME NFTs are still for sale as a nastalgoic piece of memorobilia, and all profits will be locked into an 8 year neuron benifiting [ICDevs.org](https://icdevs.org) who are sheparding this library as it moves forward and improves.


## Testing

printf "yes" | bash test_runner.sh

23 changes: 23 additions & 0 deletions dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"canisters": {

"test_runner": {
"main": "tests/test_runner.mo",
"type": "motoko"
}
},
"defaults": {
"build": {
"args": "",
"packtool": "vessel sources"
}
},
"dfx": "0.9.2",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
},
"version": 1
}
25 changes: 25 additions & 0 deletions package-set.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let upstream = https://github.com/dfinity/vessel-package-set/releases/download/mo-0.6.21-20220215/package-set.dhall sha256:b46f30e811fe5085741be01e126629c2a55d4c3d6ebf49408fb3b4a98e37589b
let Package =
{ name : Text, version : Text, repo : Text, dependencies : List Text }

let
-- This is where you can add your own packages to the package-set
additions =
[] : List Package

let
{- This is where you can override existing packages in the package-set
For example, if you wanted to use version `v2.0.0` of the foo library:
let overrides = [
{ name = "foo"
, version = "v2.0.0"
, repo = "https://github.com/bar/foo"
, dependencies = [] : List Text
}
]
-}
overrides =
[] : List Package

in upstream # additions # overrides
50 changes: 50 additions & 0 deletions src/clone.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
///////////////////////////////
//
// ©2021 @aramakme
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
///////////////////////////////


import Types "types";
import Array "mo:base/Array";

module {

type CandyValue = Types.CandyValue;
type CandyValueUnstable = Types.CandyValueUnstable;
type PropertyUnstable = Types.PropertyUnstable;


public func cloneValueUnstable(val : CandyValueUnstable) : CandyValueUnstable{
switch(val){
case(#Class(val)){

return #Class(Array.tabulate<PropertyUnstable>(val.size(), func(idx){
{name= val[idx].name; value=cloneValueUnstable(val[idx].value); immutable = val[idx].immutable};
}));
};
case(#Bytes(val)){
switch(val){
case(#frozen(val)){

#Bytes(#frozen(val));
};
case(#thawed(val)){

#Bytes(#thawed(val.clone()));
};
}
};
case(_){

val;
}
};
};

}
Loading

0 comments on commit ecd2cb0

Please sign in to comment.