Skip to content

Commit 32b551f

Browse files
authored
Merge pull request #100 from SolidOS/newFace
Improved library
2 parents 67f6af2 + b42320e commit 32b551f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7102
-4209
lines changed

.babelrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ permissions:
88
on:
99
push:
1010
branches:
11-
- "**"
11+
- main
1212
pull_request:
1313
branches:
14-
- "**"
14+
- main
1515
workflow_dispatch:
1616

1717
jobs:
@@ -22,7 +22,6 @@ jobs:
2222
strategy:
2323
matrix:
2424
node-version:
25-
- 18.x
2625
- 20.x
2726
- 22.x
2827

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
node_modules
2-
lib
2+
dist
3+
coverage
34

45
### VisualStudioCode Patch ###
56
# Ignore all local history of files
67
.history
8+
.idea
9+
.vscode
710

8-
src/versionInfo.ts
11+
src/versionInfo.ts

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,134 @@
11
# solid-logic
2-
Core business logic of SolidOS
32

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+
[![MIT license](https://img.shields.io/github/license/solidos/solidos)](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
5132

6133
Solid-logic was a move to separate business logic from UI functionality so that people using different UI frameworks could use logic code.
7134

babel.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
presets: [
3+
['@babel/preset-env', {
4+
targets: {
5+
browsers: ['> 1%', 'last 3 versions', 'not dead']
6+
}
7+
}],
8+
'@babel/preset-typescript'
9+
]
10+
}

eslint.config.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import tsParser from '@typescript-eslint/parser'
2+
import importPlugin from 'eslint-plugin-import'
3+
4+
export default [
5+
{
6+
ignores: [
7+
'dist/**',
8+
'lib/**',
9+
'node_modules/**',
10+
'coverage/**'
11+
],
12+
},
13+
{
14+
files: ['src/**/*.ts'],
15+
languageOptions: {
16+
parser: tsParser,
17+
parserOptions: {
18+
project: ['./tsconfig.json'],
19+
sourceType: 'module',
20+
},
21+
},
22+
plugins: {
23+
import: importPlugin,
24+
},
25+
rules: {
26+
// Style rules (not handled by TypeScript)
27+
semi: ['error', 'never'],
28+
quotes: ['error', 'single'],
29+
30+
// Disable ESLint rules that TypeScript handles better
31+
'no-unused-vars': 'off', // TypeScript handles this via noUnusedLocals
32+
'no-undef': 'off', // TypeScript handles undefined variables
33+
},
34+
},
35+
{
36+
files: ['test/**/*.ts'],
37+
languageOptions: {
38+
parser: tsParser,
39+
parserOptions: {
40+
project: ['./tsconfig.test.json'],
41+
},
42+
},
43+
rules: {
44+
semi: ['error', 'never'],
45+
quotes: ['error', 'single'],
46+
'no-console': 'off', // Allow console in tests
47+
'no-undef': 'off', // Tests may define globals
48+
}
49+
}
50+
]

jest.config.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

jest.config.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @type {import('jest').Config} */
2+
export default {
3+
// verbose: true, // Uncomment for detailed test output
4+
collectCoverage: true,
5+
coverageDirectory: 'coverage',
6+
testEnvironment: 'jsdom',
7+
testEnvironmentOptions: {
8+
customExportConditions: ['node'],
9+
},
10+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
11+
transform: {
12+
'^.+\\.[tj]sx?$': ['babel-jest', { configFile: './babel.config.mjs' }],
13+
},
14+
setupFilesAfterEnv: ['./test/helpers/setup.ts'],
15+
testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'],
16+
roots: ['<rootDir>/src', '<rootDir>/test'],
17+
}

0 commit comments

Comments
 (0)