@oh-my-ghaad/react 0.0.1 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +7 -0
- package/README.md +148 -0
- package/package.json +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
## [0.0.6](https://github.com/cmgriffing/oh-my-ghaad/compare/v0.0.5...v0.0.6) (2025-10-04)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## [0.0.5](https://github.com/cmgriffing/oh-my-ghaad/compare/v0.0.4...v0.0.5) (2025-10-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [0.0.4](https://github.com/cmgriffing/oh-my-ghaad/compare/v0.0.3...v0.0.4) (2025-10-04)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## [0.0.3](https://github.com/cmgriffing/oh-my-ghaad/compare/v0.0.2...v0.0.3) (2025-10-04)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.0.2](https://github.com/cmgriffing/oh-my-ghaad/compare/v0.0.1...v0.0.2) (2025-10-04)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [0.0.1](https://github.com/cmgriffing/oh-my-ghaad/compare/46e2539da2b72e0d1f95ce739d19f5137a726adb...v0.0.1) (2025-10-04)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* bring demo-app up to functional and add mvp methods for engine ([46e2539](https://github.com/cmgriffing/oh-my-ghaad/commit/46e2539da2b72e0d1f95ce739d19f5137a726adb))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Chris Griffing
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @oh-my-ghaad/react
|
|
2
|
+
|
|
3
|
+
React integration for Oh My GHAAD, providing a hook to easily use Git repositories as JSON databases in your React applications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The React package provides a `useGHaaD` hook that integrates the core Engine with React's state management system, allowing you to:
|
|
8
|
+
- Access the Engine instance in your React components
|
|
9
|
+
- Subscribe to Engine updates
|
|
10
|
+
- Track repository status changes
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @oh-my-ghaad/react @oh-my-ghaad/core
|
|
16
|
+
# or
|
|
17
|
+
yarn add @oh-my-ghaad/react @oh-my-ghaad/core
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @oh-my-ghaad/react @oh-my-ghaad/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Basic Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Engine } from '@oh-my-ghaad/core';
|
|
26
|
+
import { GithubAdapter } from '@oh-my-ghaad/adapter-github';
|
|
27
|
+
import { useGHaaD } from '@oh-my-ghaad/react';
|
|
28
|
+
import { useEffect, useState } from 'react';
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
|
|
31
|
+
// Define your collection schema
|
|
32
|
+
const widgetSchema = z.object({
|
|
33
|
+
id: z.string(),
|
|
34
|
+
name: z.string(),
|
|
35
|
+
type: z.enum(['gauge', 'chart', 'counter']),
|
|
36
|
+
config: z.object({
|
|
37
|
+
color: z.string(),
|
|
38
|
+
size: z.enum(['small', 'medium', 'large']),
|
|
39
|
+
enabled: z.boolean()
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Create a collection
|
|
44
|
+
const widgetsCollection = {
|
|
45
|
+
id: 'widgets',
|
|
46
|
+
names: {
|
|
47
|
+
singular: 'widget',
|
|
48
|
+
plural: 'widgets',
|
|
49
|
+
path: 'widgets'
|
|
50
|
+
},
|
|
51
|
+
validator: widgetSchema,
|
|
52
|
+
idFunction: () => crypto.randomUUID()
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Create the engine instance
|
|
56
|
+
const engine = new Engine({
|
|
57
|
+
adapters: [new GithubAdapter()],
|
|
58
|
+
collections: [widgetsCollection],
|
|
59
|
+
appConfig: {
|
|
60
|
+
persisted: true
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Use the hook in your component
|
|
65
|
+
function WidgetsList() {
|
|
66
|
+
const { engine, repoStatus, lastUpdated } = useGHaaD(engine);
|
|
67
|
+
const [widgets, setWidgets] = useState<z.infer<typeof widgetSchema>[]>([]);
|
|
68
|
+
const [loading, setLoading] = useState(true);
|
|
69
|
+
|
|
70
|
+
// Fetch widgets when the component mounts or when lastUpdated changes
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
async function fetchWidgets() {
|
|
73
|
+
try {
|
|
74
|
+
setLoading(true);
|
|
75
|
+
const items = await engine.fetchCollectionItems('widgets');
|
|
76
|
+
setWidgets(items);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('Failed to fetch widgets:', error);
|
|
79
|
+
} finally {
|
|
80
|
+
setLoading(false);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fetchWidgets();
|
|
85
|
+
}, [lastUpdated]); // Re-fetch when the engine updates
|
|
86
|
+
|
|
87
|
+
if (loading) {
|
|
88
|
+
return <div>Loading widgets...</div>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div>
|
|
93
|
+
<div>Repository Status: {repoStatus}</div>
|
|
94
|
+
{widgets.map(widget => (
|
|
95
|
+
<div key={widget.id}>
|
|
96
|
+
<h3>{widget.name}</h3>
|
|
97
|
+
<p>Type: {widget.type}</p>
|
|
98
|
+
<p>Size: {widget.config.size}</p>
|
|
99
|
+
<button
|
|
100
|
+
onClick={async () => {
|
|
101
|
+
try {
|
|
102
|
+
await engine.updateInCollection('widgets', widget.id, {
|
|
103
|
+
...widget,
|
|
104
|
+
config: {
|
|
105
|
+
...widget.config,
|
|
106
|
+
enabled: !widget.config.enabled
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('Failed to update widget:', error);
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
Toggle Enabled
|
|
115
|
+
</button>
|
|
116
|
+
</div>
|
|
117
|
+
))}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
### useGHaaD Hook
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
function useGHaaD(
|
|
129
|
+
engine: Engine,
|
|
130
|
+
subscription?: Subscription
|
|
131
|
+
): {
|
|
132
|
+
engine: Engine;
|
|
133
|
+
repoStatus: RepoStatus;
|
|
134
|
+
lastUpdated: number;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The hook returns:
|
|
139
|
+
- `engine`: The Engine instance
|
|
140
|
+
- `repoStatus`: Current status of the repository
|
|
141
|
+
- `lastUpdated`: Timestamp of the last update
|
|
142
|
+
|
|
143
|
+
## Related Packages
|
|
144
|
+
|
|
145
|
+
- [@oh-my-ghaad/core](../core/README.md) - Core functionality
|
|
146
|
+
- [@oh-my-ghaad/adapter-github](../adapter-github/README.md) - GitHub adapter implementation
|
|
147
|
+
|
|
148
|
+
For more examples and detailed usage, see the [main README](../../README.md) and the [demo app](../../apps/demo-app/README.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-ghaad/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": ">= 18.0.0",
|
|
18
|
-
"@oh-my-ghaad/core": "0.0.
|
|
18
|
+
"@oh-my-ghaad/core": "0.0.6"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "tsup src/index.ts --watch --dts --format esm,cjs",
|