|
1 | 1 | # solid-logic |
2 | | -Core business logic of SolidOS |
3 | 2 |
|
4 | | -# Adendum |
| 3 | +<img src="https://raw.githubusercontent.com/solid/community-server/main/templates/images/solid.svg" alt="[Solid logo]" height="150" align="right"/> |
| 4 | + |
| 5 | +[](https://github.com/solidos/solidos/blob/main/LICENSE.md) |
| 6 | + |
| 7 | + |
| 8 | +Core business logic of SolidOS which can be used for any webapp as well. |
| 9 | + |
| 10 | + |
| 11 | +# Usage |
| 12 | + |
| 13 | +## 📦 Install via npm |
| 14 | + |
| 15 | +```sh |
| 16 | +npm install solid-logic rdflib |
| 17 | +``` |
| 18 | + |
| 19 | +> **Important**: `rdflib` is a peer dependency - you must install it separately. |
| 20 | +
|
| 21 | +### Import in your project (ESM/TypeScript) |
| 22 | + |
| 23 | +```js |
| 24 | +import { solidLogicSingleton, store, authn } from 'solid-logic'; |
| 25 | + |
| 26 | +// Example usage |
| 27 | +console.log('Current user:', authn.currentUser()); |
| 28 | +``` |
| 29 | + |
| 30 | +## 🌐 Use directly in a browser |
| 31 | + |
| 32 | +Both UMD and ESM bundles externalize rdflib to keep bundle sizes small and avoid version conflicts. |
| 33 | + |
| 34 | +## Available Files |
| 35 | + |
| 36 | +| Format | File | Usage | Global Variable | |
| 37 | +|--------|------|-------|----------------| |
| 38 | +| UMD | `dist/solid-logic.js` | Development | `window.SolidLogic` | |
| 39 | +| UMD | `dist/solid-logic.min.js` | Production | `window.SolidLogic` | |
| 40 | +| ESM | `dist/solid-logic.esm.js` | Development | Import only | |
| 41 | +| ESM | `dist/solid-logic.esm.min.js` | Production | Import only | |
| 42 | + |
| 43 | +### UMD Bundle (Script Tags) |
| 44 | + |
| 45 | +**⚠️ Important**: Load rdflib **before** solid-logic or you'll get `$rdf is not defined` errors. |
| 46 | + |
| 47 | +```html |
| 48 | +<!-- 1. Load rdflib first (creates window.$rdf) --> |
| 49 | +<script src="https://cdn.jsdelivr.net/npm/rdflib/dist/rdflib.min.js"></script> |
| 50 | + |
| 51 | +<!-- 2. Load solid-logic (expects $rdf to exist) --> |
| 52 | +<script src="https://unpkg.com/solid-logic/dist/solid-logic.min.js"></script> |
| 53 | + |
| 54 | +<script> |
| 55 | + // Access via global variable |
| 56 | + const { solidLogicSingleton, store, authn } = window.SolidLogic; |
| 57 | + |
| 58 | + // Example usage |
| 59 | + console.log('Store:', store); |
| 60 | + console.log('Authentication:', authn.currentUser()); |
| 61 | +</script> |
| 62 | +``` |
| 63 | + |
| 64 | +### ESM Bundle (Native Modules) |
| 65 | + |
| 66 | +```html |
| 67 | +<script type="module"> |
| 68 | + import * as $rdf from 'https://esm.sh/rdflib'; |
| 69 | + import { solidLogicSingleton, store, authn } from 'https://esm.sh/solid-logic'; |
| 70 | +
|
| 71 | + // Example usage |
| 72 | + console.log('Store:', store); |
| 73 | + console.log('Authentication:', authn.currentUser()); |
| 74 | +</script> |
| 75 | +``` |
| 76 | + |
| 77 | +### ESM with Import Maps (Recommended) |
| 78 | + |
| 79 | +```html |
| 80 | +<script type="importmap"> |
| 81 | +{ |
| 82 | + "imports": { |
| 83 | + "rdflib": "https://esm.sh/rdflib", |
| 84 | + "solid-logic": "https://esm.sh/solid-logic" |
| 85 | + } |
| 86 | +} |
| 87 | +</script> |
| 88 | +<script type="module"> |
| 89 | + import * as $rdf from 'rdflib'; |
| 90 | + import { solidLogicSingleton, store, authn } from 'solid-logic'; |
| 91 | +
|
| 92 | + // Example usage - cleaner imports! |
| 93 | + console.log('Store:', store); |
| 94 | + console.log('Authentication:', authn.currentUser()); |
| 95 | +</script> |
| 96 | +``` |
| 97 | + |
| 98 | +## Common Exports |
| 99 | + |
| 100 | +```js |
| 101 | +import { |
| 102 | + solidLogicSingleton, // Complete singleton instance |
| 103 | + store, // RDF store |
| 104 | + authn, // Authentication logic |
| 105 | + authSession, // Authentication session |
| 106 | + ACL_LINK, // ACL constants |
| 107 | + getSuggestedIssuers, // Identity provider suggestions |
| 108 | + createTypeIndexLogic, // Type index functionality |
| 109 | + // Error classes |
| 110 | + UnauthorizedError, |
| 111 | + NotFoundError, |
| 112 | + FetchError |
| 113 | +} from 'solid-logic'; |
| 114 | +``` |
| 115 | + |
| 116 | +# How to develop |
| 117 | + |
| 118 | +Check the scripts in the `package.json` for build, watch, lint and test. |
| 119 | + |
| 120 | +# Used stack |
| 121 | + |
| 122 | +* TypeScript + Babel |
| 123 | +* Jest |
| 124 | +* ESLint |
| 125 | +* Webpack |
| 126 | + |
| 127 | +# How to release |
| 128 | + |
| 129 | +Change version and push directly to main. This will trigger the npm release latest script in CI. |
| 130 | + |
| 131 | +# History |
5 | 132 |
|
6 | 133 | Solid-logic was a move to separate business logic from UI functionality so that people using different UI frameworks could use logic code. |
7 | 134 |
|
|
0 commit comments