diff --git a/license b/license new file mode 100644 index 0000000..4a66f67 --- /dev/null +++ b/license @@ -0,0 +1,440 @@ +HIPPOCRATIC LICENSE + +Version 3.0, October 2021 + +https://firstdonoharm.dev/version/3/0/full.txt + +TERMS AND CONDITIONS + +TERMS AND CONDITIONS FOR USE, COPY, MODIFICATION, PREPARATION OF DERIVATIVE +WORK, REPRODUCTION, AND DISTRIBUTION: + +1. DEFINITIONS: + +This section defines certain terms used throughout this license agreement. + +1.1. “License” means the terms and conditions, as stated herein, for use, copy, +modification, preparation of derivative work, reproduction, and distribution of +Software (as defined below). + +1.2. “Licensor” means the copyright and/or patent owner or entity authorized by +the copyright and/or patent owner that is granting the License. + +1.3. “Licensee” means the individual or entity exercising permissions granted by +this License, including the use, copy, modification, preparation of derivative +work, reproduction, and distribution of Software (as defined below). + +1.4. “Software” means any copyrighted work, including but not limited to +software code, authored by Licensor and made available under this License. + +1.5. “Supply Chain” means the sequence of processes involved in the production +and/or distribution of a commodity, good, or service offered by the Licensee. + +1.6. “Supply Chain Impacted Party” or “Supply Chain Impacted Parties” means any +person(s) directly impacted by any of Licensee’s Supply Chain, including the +practices of all persons or entities within the Supply Chain prior to a good or +service reaching the Licensee. + +1.7. “Duty of Care” is defined by its use in tort law, delict law, and/or +similar bodies of law closely related to tort and/or delict law, including +without limitation, a requirement to act with the watchfulness, attention, +caution, and prudence that a reasonable person in the same or similar +circumstances would use towards any Supply Chain Impacted Party. + +1.8. “Worker” is defined to include any and all permanent, temporary, and agency +workers, as well as piece-rate, salaried, hourly paid, legal young (minors), +part-time, night, and migrant workers. + +2. INTELLECTUAL PROPERTY GRANTS: + +This section identifies intellectual property rights granted to a Licensee. + +2.1. Grant of Copyright License: Subject to the terms and conditions of this +License, Licensor hereby grants to Licensee a worldwide, non-exclusive, +no-charge, royalty-free copyright license to use, copy, modify, prepare +derivative work, reproduce, or distribute the Software, Licensor authored +modified software, or other work derived from the Software. + +2.2. Grant of Patent License: Subject to the terms and conditions of this +License, Licensor hereby grants Licensee a worldwide, non-exclusive, no-charge, +royalty-free patent license to make, have made, use, offer to sell, sell, +import, and otherwise transfer Software. + +3. ETHICAL STANDARDS: + +This section lists conditions the Licensee must comply with in order to have +rights under this License. + +The rights granted to the Licensee by this License are expressly made subject to +the Licensee’s ongoing compliance with the following conditions: + + * 3.1. The Licensee SHALL NOT, whether directly or indirectly, through agents + or assigns: + + * 3.1.1. Infringe upon any person’s right to life or security of person, + engage in extrajudicial killings, or commit murder, without lawful cause + (See Article 3, United Nations Universal Declaration of Human Rights; + Article 6, International Covenant on Civil and Political Rights) + + * 3.1.2. Hold any person in slavery, servitude, or forced labor (See Article + 4, United Nations Universal Declaration of Human Rights; Article 8, + International Covenant on Civil and Political Rights); + + * 3.1.3. Contribute to the institution of slavery, slave trading, forced + labor, or unlawful child labor (See Article 4, United Nations Universal + Declaration of Human Rights; Article 8, International Covenant on Civil and + Political Rights); + + * 3.1.4. Torture or subject any person to cruel, inhumane, or degrading + treatment or punishment (See Article 5, United Nations Universal + Declaration of Human Rights; Article 7, International Covenant on Civil and + Political Rights); + + * 3.1.5. Discriminate on the basis of sex, gender, sexual orientation, race, + ethnicity, nationality, religion, caste, age, medical disability or + impairment, and/or any other like circumstances (See Article 7, United + Nations Universal Declaration of Human Rights; Article 2, International + Covenant on Economic, Social and Cultural Rights; Article 26, International + Covenant on Civil and Political Rights); + + * 3.1.6. Prevent any person from exercising his/her/their right to seek an + effective remedy by a competent court or national tribunal (including + domestic judicial systems, international courts, arbitration bodies, and + other adjudicating bodies) for actions violating the fundamental rights + granted to him/her/them by applicable constitutions, applicable laws, or by + this License (See Article 8, United Nations Universal Declaration of Human + Rights; Articles 9 and 14, International Covenant on Civil and Political + Rights); + + * 3.1.7. Subject any person to arbitrary arrest, detention, or exile (See + Article 9, United Nations Universal Declaration of Human Rights; Article 9, + International Covenant on Civil and Political Rights); + + * 3.1.8. Subject any person to arbitrary interference with a person’s + privacy, family, home, or correspondence without the express written + consent of the person (See Article 12, United Nations Universal Declaration + of Human Rights; Article 17, International Covenant on Civil and Political + Rights); + + * 3.1.9. Arbitrarily deprive any person of his/her/their property (See + Article 17, United Nations Universal Declaration of Human Rights); + + * 3.1.10. Forcibly remove indigenous peoples from their lands or territories + or take any action with the aim or effect of dispossessing indigenous + peoples from their lands, territories, or resources, including without + limitation the intellectual property or traditional knowledge of indigenous + peoples, without the free, prior, and informed consent of indigenous + peoples concerned (See Articles 8 and 10, United Nations Declaration on the + Rights of Indigenous Peoples); + + * 3.1.11. Fossil Fuel Divestment: Be an individual or entity, or a + representative, agent, affiliate, successor, attorney, or assign of an + individual or entity, on the FFI Solutions Carbon Underground 200 list + [https://www.ffisolutions.com/research-analytics-index-solutions/research-screening/the-carbon-underground-200/?cn-reloaded=1]; + + * 3.1.12. Ecocide: Commit ecocide: + + * 3.1.12.1. For the purpose of this section, “ecocide” means unlawful or + wanton acts committed with knowledge that there is a substantial + likelihood of severe and either widespread or long-term damage to the + environment being caused by those acts; + + * 3.1.12.2. For the purpose of further defining ecocide and the terms + contained in the previous paragraph: + + * 3.1.12.2.1. “Wanton” means with reckless disregard for damage which + would be clearly excessive in relation to the social and economic + benefits anticipated; + + * 3.1.12.2.2. “Severe” means damage which involves very serious adverse + changes, disruption, or harm to any element of the environment, + including grave impacts on human life or natural, cultural, or + economic resources; + + * 3.1.12.2.3. “Widespread” means damage which extends beyond a limited + geographic area, crosses state boundaries, or is suffered by an entire + ecosystem or species or a large number of human beings; + + * 3.1.12.2.4. “Long-term” means damage which is irreversible or which + cannot be redressed through natural recovery within a reasonable + period of time; and + + * 3.1.12.2.5. “Environment” means the earth, its biosphere, cryosphere, + lithosphere, hydrosphere, and atmosphere, as well as outer space + + (See Section II, Independent Expert Panel for the Legal Definition of + Ecocide, Stop Ecocide Foundation and the Promise Institute for Human + Rights at UCLA School of Law, June 2021); + + * 3.1.13. Extractive Industries: Be an individual or entity, or a + representative, agent, affiliate, successor, attorney, or assign of an + individual or entity, that engages in fossil fuel or mineral exploration, + extraction, development, or sale; + + * 3.1.14. Boycott / Divestment / Sanctions: Be an individual or entity, or a + representative, agent, affiliate, successor, attorney, or assign of an + individual or entity, identified by the Boycott, Divestment, Sanctions + (“BDS”) movement on its website (https://bdsmovement.net/ + [https://bdsmovement.net/] and + https://bdsmovement.net/get-involved/what-to-boycott + [https://bdsmovement.net/get-involved/what-to-boycott]) as a target for + boycott; + + * 3.1.15. Taliban: Be an individual or entity that: + + * 3.1.15.1. engages in any commercial transactions with the Taliban; or + + * 3.1.15.2. is a representative, agent, affiliate, successor, attorney, or + assign of the Taliban; + + * 3.1.16. Myanmar: Be an individual or entity that: + + * 3.1.16.1. engages in any commercial transactions with the + Myanmar/Burmese military junta; or + + * 3.1.16.2. is a representative, agent, affiliate, successor, attorney, or + assign of the Myanmar/Burmese government; + + * 3.1.17. Xinjiang Uygur Autonomous Region: Be an individual or entity, or a + representative, agent, affiliate, successor, attorney, or assign of any + individual or entity, that does business in, purchases goods from, or + otherwise benefits from goods produced in the Xinjiang Uygur Autonomous + Region of China; + + * 3.1.18. US Tariff Act: Be an individual or entity: + + * 3.1.18.1. which U.S. Customs and Border Protection (CBP) has currently + issued a Withhold Release Order (WRO) or finding against based on + reasonable suspicion of forced labor; or + + * 3.1.18.2. that is a representative, agent, affiliate, successor, + attorney, or assign of an individual or entity that does business with + an individual or entity which currently has a WRO or finding from CBP + issued against it based on reasonable suspicion of forced labor; + + * 3.1.19. Mass Surveillance: Be a government agency or multinational + corporation, or a representative, agent, affiliate, successor, attorney, + or assign of a government or multinational corporation, which participates + in mass surveillance programs; + + * 3.1.20. Military Activities: Be an entity or a representative, agent, + affiliate, successor, attorney, or assign of an entity which conducts + military activities; + + * 3.1.21. Law Enforcement: Be an individual or entity, or a representative, + agent, affiliate, successor, attorney, or assign of an individual or + entity, that provides good or services to, or otherwise enters into any + commercial contracts with, any local, state, or federal law enforcement + agency; + + * 3.1.22. Media: Be an individual or entity, or a representative, agent, + affiliate, successor, attorney, or assign of an individual or entity, that + broadcasts messages promoting killing, torture, or other forms of extreme + violence; + + * 3.1.23. Interfere with Workers’ free exercise of the right to organize and + associate (See Article 20, United Nations Universal Declaration of Human + Rights; C087 - Freedom of Association and Protection of the Right to + Organise Convention, 1948 (No. 87), International Labour Organization; + Article 8, International Covenant on Economic, Social and Cultural Rights); + and + + * 3.1.24. Harm the environment in a manner inconsistent with local, state, + national, or international law. + + * 3.2. The Licensee SHALL: + + * 3.2.1. Social Auditing: Only use social auditing mechanisms that adhere to + Worker-Driven Social Responsibility Network’s Statement of Principles + (https://wsr-network.org/what-is-wsr/statement-of-principles/ + [https://wsr-network.org/what-is-wsr/statement-of-principles/]) over + traditional social auditing mechanisms, to the extent the Licensee uses + any social auditing mechanisms at all; + + * 3.2.2. Workers on Board of Directors: Ensure that if the Licensee has a + Board of Directors, 30% of Licensee’s board seats are held by Workers paid + no more than 200% of the compensation of the lowest paid Worker of the + Licensee; + + * 3.2.3. Supply Chain: Provide clear, accessible supply chain data to the + public in accordance with the following conditions: + + * 3.2.3.1. All data will be on Licensee’s website and/or, to the extent + Licensee is a representative, agent, affiliate, successor, attorney, + subsidiary, or assign, on Licensee’s principal’s or parent’s website or + some other online platform accessible to the public via an internet + search on a common internet search engine; and + + * 3.2.3.2. Data published will include, where applicable, manufacturers, + top tier suppliers, subcontractors, cooperatives, component parts + producers, and farms; + + * 3.2.4. Provide equal pay for equal work where the performance of such work + requires equal skill, effort, and responsibility, and which are performed + under similar working conditions, except where such payment is made + pursuant to: + + * 3.2.4.1. A seniority system; + + * 3.2.4.2. A merit system; + + * 3.2.4.3. A system which measures earnings by quantity or quality of + production; or + + * 3.2.4.4. A differential based on any other factor other than sex, gender, + sexual orientation, race, ethnicity, nationality, religion, caste, age, + medical disability or impairment, and/or any other like circumstances + (See 29 U.S.C.A. § 206(d)(1); Article 23, United Nations Universal + Declaration of Human Rights; Article 7, International Covenant on + Economic, Social and Cultural Rights; Article 26, International Covenant + on Civil and Political Rights); and + + * 3.2.5. Allow for reasonable limitation of working hours and periodic + holidays with pay (See Article 24, United Nations Universal Declaration of + Human Rights; Article 7, International Covenant on Economic, Social and + Cultural Rights). + +4. SUPPLY CHAIN IMPACTED PARTIES: + +This section identifies additional individuals or entities that a Licensee could +harm as a result of violating the Ethical Standards section, the condition that +the Licensee must voluntarily accept a Duty of Care for those individuals or +entities, and the right to a private right of action that those individuals or +entities possess as a result of violations of the Ethical Standards section. + +4.1. In addition to the above Ethical Standards, Licensee voluntarily accepts a +Duty of Care for Supply Chain Impacted Parties of this License, including +individuals and communities impacted by violations of the Ethical Standards. The +Duty of Care is breached when a provision within the Ethical Standards section +is violated by a Licensee, one of its successors or assigns, or by an individual +or entity that exists within the Supply Chain prior to a good or service +reaching the Licensee. + +4.2. Breaches of the Duty of Care, as stated within this section, shall create a +private right of action, allowing any Supply Chain Impacted Party harmed by the +Licensee to take legal action against the Licensee in accordance with applicable +negligence laws, whether they be in tort law, delict law, and/or similar bodies +of law closely related to tort and/or delict law, regardless if Licensee is +directly responsible for the harms suffered by a Supply Chain Impacted Party. +Nothing in this section shall be interpreted to include acts committed by +individuals outside of the scope of his/her/their employment. + +5. NOTICE: This section explains when a Licensee must notify others of the +License. + +5.1. Distribution of Notice: Licensee must ensure that everyone who receives a +copy of or uses any part of Software from Licensee, with or without changes, +also receives the License and the copyright notice included with Software (and +if included by the Licensor, patent, trademark, and attribution notice). +Licensee must ensure that License is prominently displayed so that any +individual or entity seeking to download, copy, use, or otherwise receive any +part of Software from Licensee is notified of this License and its terms and +conditions. Licensee must cause any modified versions of the Software to carry +prominent notices stating that Licensee changed the Software. + +5.2. Modified Software: Licensee is free to create modifications of the Software +and distribute only the modified portion created by Licensee, however, any +derivative work stemming from the Software or its code must be distributed +pursuant to this License, including this Notice provision. + +5.3. Recipients as Licensees: Any individual or entity that uses, copies, +modifies, reproduces, distributes, or prepares derivative work based upon the +Software, all or part of the Software’s code, or a derivative work developed by +using the Software, including a portion of its code, is a Licensee as defined +above and is subject to the terms and conditions of this License. + +6. REPRESENTATIONS AND WARRANTIES: + +6.1. Disclaimer of Warranty: TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE +COMES “AS IS,” WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR SHALL NOT +BE LIABLE TO ANY PERSON OR ENTITY FOR ANY DAMAGES OR OTHER LIABILITY ARISING +FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THIS LICENSE, UNDER ANY +LEGAL CLAIM. + +6.2. Limitation of Liability: LICENSEE SHALL HOLD LICENSOR HARMLESS AGAINST ANY +AND ALL CLAIMS, DEBTS, DUES, LIABILITIES, LIENS, CAUSES OF ACTION, DEMANDS, +OBLIGATIONS, DISPUTES, DAMAGES, LOSSES, EXPENSES, ATTORNEYS’ FEES, COSTS, +LIABILITIES, AND ALL OTHER CLAIMS OF EVERY KIND AND NATURE WHATSOEVER, WHETHER +KNOWN OR UNKNOWN, ANTICIPATED OR UNANTICIPATED, FORESEEN OR UNFORESEEN, ACCRUED +OR UNACCRUED, DISCLOSED OR UNDISCLOSED, ARISING OUT OF OR RELATING TO LICENSEE’S +USE OF THE SOFTWARE. NOTHING IN THIS SECTION SHOULD BE INTERPRETED TO REQUIRE +LICENSEE TO INDEMNIFY LICENSOR, NOR REQUIRE LICENSOR TO INDEMNIFY LICENSEE. + +7. TERMINATION + +7.1. Violations of Ethical Standards or Breaching Duty of Care: If Licensee +violates the Ethical Standards section or Licensee, or any other person or +entity within the Supply Chain prior to a good or service reaching the Licensee, +breaches its Duty of Care to Supply Chain Impacted Parties, Licensee must remedy +the violation or harm caused by Licensee within 30 days of being notified of the +violation or harm. If Licensee fails to remedy the violation or harm within 30 +days, all rights in the Software granted to Licensee by License will be null and +void as between Licensor and Licensee. + +7.2. Failure of Notice: If any person or entity notifies Licensee in writing +that Licensee has not complied with the Notice section of this License, Licensee +can keep this License by taking all practical steps to comply within 30 days +after the notice of noncompliance. If Licensee does not do so, Licensee’s +License (and all rights licensed hereunder) will end immediately. + +7.3. Judicial Findings: In the event Licensee is found by a civil, criminal, +administrative, or other court of competent jurisdiction, or some other +adjudicating body with legal authority, to have committed actions which are in +violation of the Ethical Standards or Supply Chain Impacted Party sections of +this License, all rights granted to Licensee by this License will terminate +immediately. + +7.4. Patent Litigation: If Licensee institutes patent litigation against any +entity (including a cross-claim or counterclaim in a suit) alleging that the +Software, all or part of the Software’s code, or a derivative work developed +using the Software, including a portion of its code, constitutes direct or +contributory patent infringement, then any patent license, along with all other +rights, granted to Licensee under this License will terminate as of the date +such litigation is filed. + +7.5. Additional Remedies: Termination of the License by failing to remedy harms +in no way prevents Licensor or Supply Chain Impacted Party from seeking +appropriate remedies at law or in equity. + +8. MISCELLANEOUS: + +8.1. Conditions: Sections 3, 4.1, 5.1, 5.2, 7.1, 7.2, 7.3, and 7.4 are +conditions of the rights granted to Licensee in the License. + +8.2. Equitable Relief: Licensor and any Supply Chain Impacted Party shall be +entitled to equitable relief, including injunctive relief or specific +performance of the terms hereof, in addition to any other remedy to which they +are entitled at law or in equity. + +8.3. Copyleft: Modified software, source code, or other derivative work must be +licensed, in its entirety, under the exact same conditions as this License. + +8.4. Severability: If any term or provision of this License is determined to be +invalid, illegal, or unenforceable by a court of competent jurisdiction, any +such determination of invalidity, illegality, or unenforceability shall not +affect any other term or provision of this License or invalidate or render +unenforceable such term or provision in any other jurisdiction. If the +determination of invalidity, illegality, or unenforceability by a court of +competent jurisdiction pertains to the terms or provisions contained in the +Ethical Standards section of this License, all rights in the Software granted to +Licensee shall be deemed null and void as between Licensor and Licensee. + +8.5. Section Titles: Section titles are solely written for organizational +purposes and should not be used to interpret the language within each section. + +8.6. Citations: Citations are solely written to provide context for the source +of the provisions in the Ethical Standards. + +8.7. Section Summaries: Some sections have a brief italicized description which +is provided for the sole purpose of briefly describing the section and should +not be used to interpret the terms of the License. + +8.8. Entire License: This is the entire License between the Licensor and +Licensee with respect to the claims released herein and that the consideration +stated herein is the only consideration or compensation to be paid or exchanged +between them for this License. This License cannot be modified or amended except +in a writing signed by Licensor and Licensee. + +8.9. Successors and Assigns: This License shall be binding upon and inure to the +benefit of the Licensor’s and Licensee’s respective heirs, successors, and +assigns. \ No newline at end of file diff --git a/readme.md b/readme.md index 3c1b03f..4b70b1f 100644 --- a/readme.md +++ b/readme.md @@ -4,33 +4,6 @@ it's made by queernerds, for queernerds, for protecting queernerds and queernerd communities. other use cases include investigative journalism, documentation and archivism, ARGs & treasure hunts, or anything that involves making sense of computer data. -## how does this work? - -wgu & the modular object format are specifically designed to be extremely versatile, and well, modular. the simplest way to think of wgu is like microsoft excel, except that data can be plotted to a graph (or to charts), if you choose. - -this means that you can see how data connects and morphs (via transforms or functions) into new data. - -### object instances - -almost all data within wgu are **object instances**. these are stored as json object literals while at rest, that serealize into the struct `wgu::ObjectInstance`. - -data within object instances is categorized based on the data's origin (whether it's provided as the object's base input, calculated locally, or pulled in from elsewhere). - -the inner structure of these categories depends on the object instance's `object_type`, and is defined in the object's template. alongside these categories, objects also contain metadata like logs, hashes, and timestamps - -### modularity & object templates - -modules can expose object templates as TOML strings (`wgu::modules::ModuleItem::Template`, serealized into `wgu::ObjectTemplate`), and rustlang functions to validate inputs (`... ModuleItem::Validator`), or to calculate properties / make new objects (`... ModuleItem::Function`). - -object templates can define several options for each property: - -- `transforms`: uses this property as an input of a new object -- `subobjects`: creates a parent-child relationship between this and at least one more object, based on the properties sharing a value and their transformations -- `conditions`: values other properties need to hold for this property to be valid -- `array`: makes the property act as an array - -for more information, see the wiki! - ## timeline hopefully, soon? @@ -39,4 +12,4 @@ i'll try my best,,, ## license -i'll probably use agpl3 for all versions before v1.0.0, and hl3-full after that. +wgu is licensed under hl3-full. see the [license file](https://git.gay/selstacker/wgu/src/branch/main/license) and [firstdonoharm.dev](https://firstdonoharm.dev) for more information. diff --git a/server/Cargo.lock b/server/Cargo.lock index 7e94b15..b650552 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -2,78 +2,18 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crypto-common" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "hashbrown" version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "indexmap" version = "2.12.0" @@ -90,12 +30,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" -[[package]] -name = "libc" -version = "0.2.178" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" - [[package]] name = "memchr" version = "2.7.6" @@ -178,17 +112,6 @@ dependencies = [ "serde_core", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "syn" version = "2.0.110" @@ -239,32 +162,18 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wgu" version = "0.0.1" dependencies = [ - "hex", "serde", "serde_json", - "sha2", "toml", ] diff --git a/server/Cargo.toml b/server/Cargo.toml index c6307df..9ef1a1f 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -5,8 +5,6 @@ version = "0.0.1" edition = "2024" [dependencies] -hex = "0.4.3" serde = { version = "*", features = ["derive"] } serde_json = "1.0.145" -sha2 = "0.10.9" toml = "0.9.8" diff --git a/server/src/lib.rs b/server/src/lib.rs index 22f7b9f..3130634 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -1,83 +1,20 @@ pub mod modules; pub mod types; - -use std::time::{SystemTime, UNIX_EPOCH}; -use std::collections::HashMap; - -use crate::modules::{ModuleItem, FunctionItem, item_registry}; -use crate::types::{FunctionTemplate, FunctionTemplateObject, ObjectInstance, ObjectTemplate}; +use crate::modules::{ModuleItem, item_registry}; +use crate::types::{ObjectInstance, ObjectTemplate}; use serde_json::{Value, json}; -use sha2::{Sha256, Digest}; -use hex; - -impl ObjectTemplate { - fn from_object_type(object_type: &str) -> Result { - let modules = item_registry(); - - let template: ObjectTemplate = match modules.get(object_type) { - Some(ModuleItem::Template(template_str)) => toml::from_str(template_str).unwrap(), - Some(_) => panic!("{} is not a ModuleItem::Template", object_type), - None => return Err(format!("ModuleItem {} doesn't exist", object_type)) - }; - - Ok(template) - } -} impl ObjectInstance { - pub fn from_object_type(object_type: &str, input: Value) -> Result { - let mut instance = ObjectInstance { - object_type: object_type.to_string(), - input: json!(input), - ..ObjectInstance::default() - }; - - // https://stackoverflow.com/questions/26593387/how-can-i-get-the-current-time-in-milliseconds - instance.created = format!("{:?}", SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("time should go forward") - .as_millis()); - - instance.edited = format!("{:?}", SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("time should go forward") - .as_millis()); - - instance.hashed = format!("{:?}", SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("time should go forward") - .as_millis()); - - let input_sha256_bytes = Sha256::digest( - format!("{}+{}", - instance.object_type, - json!(instance.input) - ) - ); - - instance.input_sha256 = hex::encode(input_sha256_bytes); - - let full_sha256_bytes = Sha256::digest( - format!("{}+{}+{}+{}+{}", - instance.object_type, - instance.hashed, - json!(instance.input), - json!(instance.local), - json!(instance.remote) - ) - ); - - instance.full_sha256 = hex::encode(full_sha256_bytes); - - ObjectInstance::validate(&instance)?; - Ok(instance) - } - pub fn validate(obj: &ObjectInstance) -> Result<(), String> { let modules = item_registry(); let object_type = &obj.object_type; - let template = ObjectTemplate::from_object_type(object_type)?; + + let template: ObjectTemplate = match modules.get(object_type.as_str()) { + Some(ModuleItem::Template(template_str)) => toml::from_str(template_str).unwrap(), + Some(_) => panic!("{} is not a ModuleItem::Template", object_type), + None => return Err(format!("template {} doesn't exist", object_type)) + }; match modules.get(format!("{}:func:validator", object_type).as_str()) { Some(ModuleItem::Validator(validate)) => validate(&obj)?, @@ -87,7 +24,7 @@ impl ObjectInstance { for (name, property) in template.input { for transform in property.transforms { - let destination: Vec<&str> = transform.splitn(2, ":").collect(); + let destination = transform.split(":").collect::>(); let temp_object = ObjectInstance { object_type: destination[0].to_string(), @@ -108,115 +45,14 @@ impl ObjectInstance { Ok(()) } - pub fn run_transform( - obj: &ObjectInstance, - source: &str, - destination: &str - ) - -> Result - { - let object_type = &obj.object_type; - let template = ObjectTemplate::from_object_type(object_type)?; - - // assuming that the property to transform (source) is 'input.some.thing.nya', - // source_parts[0] is the category (input) - // source_parts[1] is the name (some.thing.nya) - let source_parts: Vec<&str> = source.splitn(2, ".").collect(); - - // assuming that the transform destination is 'meta/text:value', - // destination_parts[0] is the object type (meta/text) - // destination_parts[1] is the property under `input` (value) - let destination_parts: Vec<&str> = destination.splitn(2, ":").collect(); - - let source_instance_category = match source_parts[0] { - "input" => &obj.input, - "local" => &obj.local, - "remote" => &obj.remote, - _ => return Err(format!("the category specified in the transformation source ({}) is invalid (must be input OR local OR remote)", source_parts[0])) + pub fn from_template(object_type: &str, input: Value) -> Result { + let instance = ObjectInstance { + object_type: object_type.to_string(), + input: json!(input), + ..ObjectInstance::default() }; - let source_template_category = match source_parts[0] { - "input" => template.input, - "local" => template.local, - "remote" => template.remote, - _ => unreachable!() - }; - - let template_property = match source_template_category.get(source_parts[1]) { - Some(template_property) => template_property, - None => return Err(format!("the property specified as the transformation source ({}) doesn't exist in the template", source)) - }; - - if template_property.transforms.contains(&destination.to_string()) { - let result = ObjectInstance::from_object_type(destination_parts[0], json!({ - destination_parts[1]: source_instance_category.get(source_parts[1]) - }))?; - - Ok(result) - } else { - Err(format!("invalid destination {}", destination)) - } - } - - pub fn run_function( - function: &str, - inputs: FunctionItem, - params: Option - ) - -> Result - { - let modules = item_registry(); - - // same thing as in ObjectTemplate::from_object_type - let (template, function): (FunctionTemplate, _) = match modules.get(function) { - Some(ModuleItem::Function((template_str, function))) => (toml::from_str(template_str).unwrap(), function), - Some(_) => return Err(format!("the ModuleItem `{}` is not a ModuleItem::Function", function)), - None => return Err(format!("the ModuleItem `{}` doesn't exist", function)) - }; - - validate_function_data(&inputs, &template.inputs, "input")?; - - if let Some(params) = ¶ms { - validate_function_data(params, &template.params, "parameter")?; - } - - let result = function(inputs.clone(), params.clone())?; - validate_function_data(&result, &template.outputs, "output")?; - - Ok(result) + ObjectInstance::validate(&instance)?; + Ok(instance) } } - -// helpers - -fn validate_function_data(data: &FunctionItem, template: &HashMap, category: &str) -> Result<(), String> { - for (name, template_object) in template { - if let None = data.get(name) && template_object.required { - return Err(format!("required {} {} doesn't exist", category, name)) - } - } - - for (name, instances) in data { - let template_object = match template.get(name) { - Some(template_object) => template_object, - None => return Err(format!("{} {} doesn't exist in the template", "input", name)) - }; - - let expected_count = &template_object.count; - let expected_object_type = &template_object.object_type; - - if instances.len() != *expected_count { - return Err(format!("the amount of object instances in the {} {} ({}) doesn't match the expected amount ({})", category, name, instances.len(), expected_count)); - } - - for instance in instances { - if instance.object_type != *expected_object_type { - return Err(format!("the object type of one or more object instances in the {} {} ({}) doesn't match the expected type ({})", category, name, instance.object_type, expected_object_type)) - } - - ObjectInstance::validate(&instance)?; - } - } - - Ok(()) -} diff --git a/server/src/main.rs b/server/src/main.rs index 58e4d92..c782b90 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,33 +1,35 @@ -use std::collections::HashMap; - use serde_json::json; use wgu::types::ObjectInstance; +use wgu::modules::{ModuleItem, item_registry}; fn main() -> Result<(), String> { + let modules = item_registry(); + // change these! - // 1 | creating a new object instance let object_type = "meta/number"; let input = json!({ "value": 1312 }); + let function = "local"; - let some_object = ObjectInstance::from_object_type(object_type, input)?; + // this creates a new object instance + let some_object = ObjectInstance::from_template(object_type, input)?; println!("this is an object:"); - println!("{:#?}", some_object); + println!("{:?}", some_object); println!(""); - // 2 | running a function on it - let function = "meta/number:func:local"; - let mut function_input = HashMap::new(); - function_input.insert(format!("main"), vec![some_object.clone()]); + // this runs a function on it to calculate other properties + let some_object_with_data = match modules.get(format!("{}:func:{}", object_type, function).as_str()) { + Some(ModuleItem::Calculator(calc)) => calc(&some_object)?, + Some(_) => return Err(format!("if you're trying to run a ModuleItem::Function and not a ModuleItem::Calculator, you'll have to add the match arm for that")), + None => { + return Err(format!("the ModuleItem `{}:func:{}` doesn't exist. this is not necessarily bad in this example (if you changed `object_type`)", object_type, function)); + } + }; - println!("running function {}", function); - println!("input: {:#?}", function_input); - - let some_object_with_data = ObjectInstance::run_function(function, function_input, None)?; - - println!("output: {:#?}", some_object_with_data); + println!("this is the same object with data:"); + println!("{:?}", some_object_with_data); Ok(()) } diff --git a/server/src/modules.rs b/server/src/modules.rs index 266aec6..feae52c 100644 --- a/server/src/modules.rs +++ b/server/src/modules.rs @@ -3,15 +3,14 @@ use std::collections::HashMap; pub mod meta; -pub type FunctionItem = HashMap>; - pub enum ModuleItem { Template(&'static str), Validator(fn(&ObjectInstance) -> Result<(), String>), - Function(( - &'static str, // template - fn(inputs: FunctionItem, params: Option) -> Result - )) + Calculator(fn(&ObjectInstance) -> Result), + Function(fn( + inputs: HashMap<&str, &ObjectInstance>, + params: Option> + ) -> Result, String>) } pub fn item_registry() -> HashMap<&'static str, ModuleItem> { diff --git a/server/src/modules/meta.rs b/server/src/modules/meta.rs index 6c90840..30e65fe 100644 --- a/server/src/modules/meta.rs +++ b/server/src/modules/meta.rs @@ -5,7 +5,6 @@ mod dummy; mod text; mod number; mod bool; -mod connection; pub fn registry() -> HashMap<&'static str, ModuleItem> { let mut map = HashMap::new(); @@ -14,18 +13,15 @@ pub fn registry() -> HashMap<&'static str, ModuleItem> { // meta/text map.insert("meta/text", ModuleItem::Template(text::TEMPLATE)); map.insert("meta/text:func:validator", ModuleItem::Validator(text::validate)); - map.insert("meta/text:func:local", ModuleItem::Function((text::TEMPLATE_LOCAL, text::local))); + map.insert("meta/text:func:local", ModuleItem::Calculator(text::local)); // meta/number map.insert("meta/number", ModuleItem::Template(number::TEMPLATE)); map.insert("meta/number:func:validator", ModuleItem::Validator(number::validate)); - map.insert("meta/number:func:local", ModuleItem::Function((number::TEMPLATE_LOCAL, number::local))); + map.insert("meta/number:func:local", ModuleItem::Calculator(number::local)); // meta/bool map.insert("meta/bool", ModuleItem::Template(bool::TEMPLATE)); map.insert("meta/bool:func:validator", ModuleItem::Validator(bool::validate)); - - // meta/connection - map.insert("meta/connection", ModuleItem::Template(connection::TEMPLATE)); map } diff --git a/server/src/modules/meta/bool.rs b/server/src/modules/meta/bool.rs index cdddc68..0448bc3 100644 --- a/server/src/modules/meta/bool.rs +++ b/server/src/modules/meta/bool.rs @@ -5,7 +5,7 @@ pub const TEMPLATE: &str = r#" transforms = [] subobjects = [] conditions = [] -array = false +duplicates = false "#; pub fn validate(obj: &ObjectInstance) -> Result<(), String> { diff --git a/server/src/modules/meta/connection.rs b/server/src/modules/meta/connection.rs deleted file mode 100644 index 13036db..0000000 --- a/server/src/modules/meta/connection.rs +++ /dev/null @@ -1,41 +0,0 @@ -pub const TEMPLATE: &str = r#" -[input.variant] -transforms = ["meta/text:value"] -subobjects = [] -conditions = [ - ["input.variant", "function"] - ["input.variant", "transform"] - ["input.variant", "subobject"] - ["input.variant", "custom"] -] -array = false - -[input.from] -transforms = ["meta/text:value"] -subobjects = [] -conditions = [] -array = true - -[input.to] -transforms = ["meta/text:value"] -subobjects = [] -conditions = [] -array = true - -[input.property] -transforms = ["meta/text:value"] -subobjects = [] -conditions = [ - ["input.variant", "transform"] - ["input.variant", "subobject"] -] -array = false - -[input.value] -transforms = ["meta/text:value"] -subobjects = [] -conditions = [ - ["input.variant", "custom"] -] -array = false -"#; diff --git a/server/src/modules/meta/dummy.rs b/server/src/modules/meta/dummy.rs index 6b0e707..31d0885 100644 --- a/server/src/modules/meta/dummy.rs +++ b/server/src/modules/meta/dummy.rs @@ -1,7 +1,6 @@ -pub const TEMPLATE: &str = r#" -[input.value] +pub const TEMPLATE: &str = r#"[input.value] transforms = ["meta/text:value"] subobjects = [] conditions = [] -array = false +duplicates = false "#; diff --git a/server/src/modules/meta/number.rs b/server/src/modules/meta/number.rs index aebe6ac..f6330a2 100644 --- a/server/src/modules/meta/number.rs +++ b/server/src/modules/meta/number.rs @@ -1,32 +1,18 @@ -use std::collections::HashMap; use serde_json::json; - -use crate::{modules::FunctionItem, types::ObjectInstance}; +use crate::ObjectInstance; pub const TEMPLATE: &str = r#" [input.value] transforms = [] subobjects = [] conditions = [] -array = false +duplicates = false [local.length] transforms = ["meta/number:value"] subobjects = [] conditions = [] -array = false -"#; - -pub const TEMPLATE_LOCAL: &str = r#" -[inputs.main] -required = true -object_type = "meta/number" -count = 1 - -[outputs.main] -required = true -object_type = "meta/number" -count = 1 +duplicates = false "#; pub fn validate(obj: &ObjectInstance) -> Result<(), String> { @@ -39,28 +25,18 @@ pub fn validate(obj: &ObjectInstance) -> Result<(), String> { Ok(()) } -pub fn local( - inputs: FunctionItem, - _params: Option -) - -> Result -{ - let Some(main) = inputs.get("main") - else { unreachable!() }; +pub fn local(obj: &ObjectInstance) -> Result { + let _value = obj.input.get("value") + .ok_or("input.value must exist")?; - let main_obj = &main[0]; + let value = _value.as_number() + .ok_or("input.value must be a number")?; - let Some(value) = &main_obj.input.get("value") - else { unreachable!() }; - - let mut result_obj = ObjectInstance::from_object_type("meta/number", main_obj.input.clone())?; - - result_obj.local = json!({ + let mut new = obj.clone(); + new.local = json!({ "length": value.to_string().len() }); - let mut result = HashMap::new(); - result.insert(format!("main"), vec![result_obj]); - - Ok(result) + Ok(new) } + diff --git a/server/src/modules/meta/text.rs b/server/src/modules/meta/text.rs index 38d9d7d..d3270fb 100644 --- a/server/src/modules/meta/text.rs +++ b/server/src/modules/meta/text.rs @@ -1,33 +1,18 @@ -use std::collections::HashMap; use serde_json::json; - -use crate::{modules::FunctionItem, types::ObjectInstance}; +use crate::ObjectInstance; pub const TEMPLATE: &str = r#" [input.value] transforms = [] subobjects = [] conditions = [] -array = false +duplicates = false [local.length] transforms = ["meta/number:value"] subobjects = [] conditions = [] -array = false -"#; - - -pub const TEMPLATE_LOCAL: &str = r#" -[inputs.main] -required = true -object_type = "meta/text" -count = 1 - -[outputs.main] -required = true -object_type = "meta/text" -count = 1 +duplicates = false "#; pub fn validate(obj: &ObjectInstance) -> Result<(), String> { @@ -40,28 +25,17 @@ pub fn validate(obj: &ObjectInstance) -> Result<(), String> { Ok(()) } -pub fn local( - inputs: FunctionItem, - _params: Option -) - -> Result -{ - let Some(main) = inputs.get("main") - else { unreachable!() }; +pub fn local(obj: &ObjectInstance) -> Result { + let value = obj.input.get("value") + .ok_or("input.value must exist")?; - let main_obj = &main[0]; + let value = value.as_str() + .ok_or("input.value must be a string")?; - let Some(value) = &main_obj.input.get("value") - else { unreachable!() }; - - let mut result_obj = ObjectInstance::from_object_type("meta/text", main_obj.input.clone())?; - - result_obj.local = json!({ - "length": value.to_string().len() + let mut new = obj.clone(); + new.local = json!({ + "length": value.len() }); - let mut result = HashMap::new(); - result.insert(format!("main"), vec![result_obj]); - - Ok(result) + Ok(new) } diff --git a/server/src/types.rs b/server/src/types.rs index f54a115..ef57cb9 100644 --- a/server/src/types.rs +++ b/server/src/types.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; #[derive(Serialize, Deserialize, Debug, Default, Clone)] pub struct ObjectInstance { - pub version: usize, + pub variant: u32, pub plotted: bool, pub created: String, pub edited: String, @@ -24,39 +24,24 @@ pub struct Log { level: String, variant: String, timestamp: String, - message: String + message: String, } #[derive(Deserialize, Debug, Default)] #[serde(default)] pub struct ObjectTemplate { - pub input: HashMap, - pub local: HashMap, - pub remote: HashMap + pub input: HashMap, + pub local: HashMap, + pub remote: HashMap, } // part of ObjectTemplate #[derive(Deserialize, Debug, Default)] #[serde(default)] -pub struct ObjectTemplateProperty { +pub struct TemplateProperty { pub transforms: Vec, pub subobjects: Vec, pub conditions: Vec<[String; 2]>, - pub array: bool + pub duplicates: bool } -#[derive(Deserialize, Debug, Default)] -#[serde(default)] -pub struct FunctionTemplate { - pub inputs: HashMap, - pub params: HashMap, - pub outputs: HashMap -} - -#[derive(Deserialize, Debug, Default)] -#[serde(default)] -pub struct FunctionTemplateObject { - pub required: bool, - pub object_type: String, - pub count: usize -}