-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ add lite version of
osiris
package (#416)
- Loading branch information
Showing
11 changed files
with
575 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"reporter": [ | ||
"text-summary", | ||
"json", | ||
"html", | ||
"lcov" | ||
], | ||
"reportsDir": "./coverage", | ||
"src": [ | ||
"src/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<h1 align="center"><code>@neuronek/osiris</code></h1> | ||
|
||
<p align="center"> | ||
Osiris was the god of knowledge so here we have package that represents all the data models available in the system along with their rules, think about this package as barebones of application as a whole which can be used in any environment with any infrastructure - this was made because plans to build desktop application and mobile application which should have preferably same logic as the server but without touching external sources in sake of privacy. | ||
</p> | ||
|
||
> This version of package stands for simplified version to start with application as previous one (like complete one) was too big to start with to deliver a minimally functioning application, this one introduces bare functionality that should be introduced and will be evolved over time until the need for the original one will be gone. | ||
<h2 align="center">Installation</h2> | ||
|
||
You should avoid installing this package by now, so documentation is omited by the purpose. | ||
|
||
<h2 align="center">Usage</h2> | ||
|
||
Here is an example of how package should be used and what's purpose of such package: | ||
|
||
```ts | ||
import { Subject, Ingestion, Substance } from "@neuronek/osiris" | ||
|
||
// Data can be mapped from outer infrastructure, | ||
// in case of server this would be based on profile | ||
// in other cases a username provided by user | ||
// as "What we should call you?" selection. | ||
const subject = new Subject({ | ||
username: "elonmusk", | ||
}) | ||
|
||
// Similary to Subjects, we map infromation | ||
// from database to Substance class. | ||
const caffeine = new Substance({ | ||
name: "Caffeine", | ||
// ... | ||
}) | ||
|
||
// Creation of ingestion, the library will | ||
// parse the input and create neccessary datamodels | ||
// for the provided input. | ||
const ingestion = Ingestion.ingest({ | ||
subject: subject, | ||
substance: caffeine, | ||
description: "Cup of coffee", | ||
dosage: "80mg" | ||
// other known metadata... | ||
}) | ||
|
||
// Check time to soberity from ingestion | ||
ingestion.whenSober() // Will output DateTime after "Aftereffects" stage. | ||
|
||
// As example presented, think about library as embeedable "domain" of | ||
// software distributed as npm package used by various application in | ||
// project. As a creator of package I wonder to provide a shells for services | ||
// which would allow users to implement their own way of ex. fetching substances | ||
// however this seems to big for now. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default { | ||
concurrency: 5, | ||
failFast: false, | ||
failWithoutAssertions: false, | ||
environmentVariables: { | ||
NODE_ENV: 'testing' | ||
}, | ||
verbose: false, | ||
nodeArguments: ['--loader=ts-node/esm', '--experimental-specifier-resolution=node', '--no-warnings'], | ||
extensions: { | ||
ts: 'module' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@neuronek/osiris", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "🧪 Community-based psychoactive substance database with a focus on safety, harm reduction and education. Including well-designed wrapper for easier data manipulation. Note: This project is still in early development and the data might be inaccurate.", | ||
"author": { | ||
"name": "Jakub Olan", | ||
"email": "keinsell@protonmail.com", | ||
"url": "https://github.com/keinsell" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"module": "dist/index.cjs", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup-node", | ||
"predev": "pnpm run generate", | ||
"dev": "tsx src/index.ts --watch --no-clear" | ||
}, | ||
"dependencies": { | ||
"js-quantities": "^1.7.6", | ||
"nanoid": "^4.0.2", | ||
"pqm": "^1.0.0", | ||
"ramda": "^0.28.0", | ||
"slugify": "^1.6.5", | ||
"type-fest": "^3.5.5", | ||
"unitmath": "^0.8.8" | ||
}, | ||
"devDependencies": { | ||
"@ava/typescript": "^3.0.1", | ||
"@graphql-codegen/cli": "2.16.4", | ||
"@graphql-codegen/client-preset": "1.2.6", | ||
"@graphql-codegen/introspection": "2.2.3", | ||
"@swc/core": "^1.3.27", | ||
"@swc/wasm": "^1.3.27", | ||
"@types/js-quantities": "^1.6.3", | ||
"@types/ms": "^0.7.31", | ||
"@types/node": "^18.11.18", | ||
"@types/nodemon": "1.19.2", | ||
"@types/ramda": "^0.28.22", | ||
"ava": "^5.1.1", | ||
"c8": "^7.12.0", | ||
"eslint-config-node": "*", | ||
"nodemon": "2.0.20", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^6.5.0", | ||
"tsx": "3.12.2", | ||
"typescript": "^4.9.4" | ||
}, | ||
"packageManager": "pnpm@8.6.0", | ||
"volta": { | ||
"node": "19.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { nanoid } from 'nanoid' | ||
|
||
// TODO: Should be immutable dataclass | ||
export class Subject { | ||
public readonly username: string | ||
|
||
constructor( | ||
subject: { | ||
username: string | ||
} | ||
) { | ||
this.username = subject.username | ||
} | ||
} | ||
|
||
// TODO: Should be immutable dataclass | ||
export class Substance { | ||
/** Unique identifier of Substance, should be starting with "substance_" */ | ||
public readonly id: string | ||
public readonly name: string | ||
|
||
constructor(substance: { id?: string, name: string }) { | ||
this.id = substance.id ?? `substance_${nanoid(16)}` | ||
this.name = substance.name | ||
} | ||
} | ||
|
||
// TODO: This should be immutable dataclass | ||
// TODO: Ffs TypeScript do not have Result types therefore Constructor will throw a error when wrong unit is provided, it's not acceptable for me so there should be static method which will provide typesafe validation and error. | ||
/** Dosage is built with amount of unit, to ensure data consistency around | ||
* ingestion with known dosage and unknown dosage this class was created. | ||
* | ||
* @example | ||
* ```ts | ||
* const albertHoffman = new Dosage({ unit: "ug", amount: 200 }) | ||
* ``` | ||
*/ | ||
export class Dosage { | ||
public readonly unitName: string | ||
public readonly massAmount: number | ||
|
||
constructor( | ||
dosage: { | ||
// TODO: What units should be typed/supported? Overall most of shit is in miligrams but when we look at the | ||
// alcohol there we have mililiters with concentration that can be converted into grams. | ||
// This class is representation of dosage and I think we should assume all dosages will be in mass units. | ||
unit: string | ||
amount: number | ||
} | ||
) { | ||
this.massAmount = dosage.amount | ||
this.unitName = dosage.unit | ||
} | ||
} | ||
|
||
// TODO: Probably should be immutable class as initial properties aren't changed at all and additional data can be | ||
// calculated on methods once class was validated and created. | ||
export class Ingestion { | ||
// TODO: What about combined ingestions or mixtures of substances - let's say quilla mind where there are like 50 substances in one cap. | ||
// Resolving issue described before will be huge stepforward as this is blocker to a lot of features such as supplement reminding. | ||
public readonly substance: Substance | ||
public readonly dosage: Dosage | ||
public readonly subject: Subject | ||
public readonly ingestedAt: Date | ||
public readonly notes: string | null | ||
|
||
constructor(ingestion: { | ||
substance: Substance, | ||
dosage: Dosage | ||
subject: Subject | ||
ingestedAt?: Date | ||
notes?: string | ||
}) { | ||
this.dosage = ingestion.dosage | ||
this.substance = ingestion.substance | ||
this.subject = ingestion.subject | ||
this.ingestedAt = ingestion.ingestedAt || new Date() | ||
this.notes = ingestion.notes ?? null | ||
|
||
// TODO: During creation of ingestion we should classify dosage (ex. light, common) | ||
// TODO: During creation of ingestion we should calculate all of the data that we may want to get from ingestion, | ||
// Eventually this can be done with usage of methods to save compute and calculate shit on the fly. | ||
} | ||
} | ||
|
||
// Example... | ||
|
||
const keinsell = new Subject({ username: 'keinsell' }) | ||
const caffeine = new Substance({ name: 'caffeine' }) | ||
const cupOfCoffee = new Ingestion({ | ||
subject: keinsell, | ||
substance: caffeine, | ||
dosage: new Dosage({ unit: 'mg', amount: 80 }), | ||
notes: 'Standard cup of my favourite coffee just to get started with application that allow me to track when I drink my favourite coffee. #trippingOnTrimetyloxamines' | ||
}) | ||
|
||
console.log(cupOfCoffee) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowUnreachableCode": false, | ||
"allowUnusedLabels": false, | ||
"exactOptionalPropertyTypes": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitOverride": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noUncheckedIndexedAccess": true, | ||
"noUnusedLocals": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"inlineSources": true, | ||
"isolatedModules": true, | ||
"allowJs": false, | ||
"strictNullChecks": true, | ||
"noUnusedParameters": true, | ||
"preserveWatchOutput": false, | ||
"skipLibCheck": false, | ||
"strict": true, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"allowSyntheticDefaultImports": false, | ||
"outDir": "./dist", | ||
"lib": [ | ||
"ESNext" | ||
], | ||
"module": "NodeNext", | ||
"moduleResolution": "node", | ||
"target": "ESNext" | ||
}, | ||
"ts-node": { | ||
"swc": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default { | ||
entry: ['src/index.ts'], | ||
silent: false, | ||
splitting: true, | ||
target: 'node18', | ||
sourcemap: true, | ||
dts: true, | ||
minify: true, | ||
format: ['esm'], | ||
clean: true, | ||
treeshake: true, | ||
metafile: true, | ||
shims: true, | ||
loader: { | ||
'.md': 'file' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.