@oh-my-ghaad/core 0.0.1 → 0.0.2
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/LICENSE +7 -0
- package/README.md +124 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -1
- package/src/types.ts +1 -1
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,124 @@
|
|
|
1
|
+
# @oh-my-ghaad/core
|
|
2
|
+
|
|
3
|
+
The core package provides the fundamental functionality for treating Git repositories as JSON databases. It handles the abstraction layer between your application and the Git platform adapters.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The core package provides:
|
|
8
|
+
|
|
9
|
+
- Collection management with Zod validation
|
|
10
|
+
- Repository configuration and initialization
|
|
11
|
+
- CRUD operations for JSON data
|
|
12
|
+
- Subscription system for real-time updates
|
|
13
|
+
- Adapter management for different Git platforms
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @oh-my-ghaad/core
|
|
19
|
+
# or
|
|
20
|
+
yarn add @oh-my-ghaad/core
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @oh-my-ghaad/core
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Basic Usage
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Engine } from '@oh-my-ghaad/core';
|
|
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: [/* your adapter */],
|
|
58
|
+
collections: [widgetsCollection],
|
|
59
|
+
appConfig: {
|
|
60
|
+
persisted: true
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Key Concepts
|
|
66
|
+
|
|
67
|
+
### Collections
|
|
68
|
+
|
|
69
|
+
Collections are the primary way to organize and validate your data. Each collection:
|
|
70
|
+
- Has a unique ID
|
|
71
|
+
- Uses Zod for schema validation
|
|
72
|
+
- Can be referenced by ID, singular name, or plural name
|
|
73
|
+
- Stores data in a dedicated directory in the repository
|
|
74
|
+
|
|
75
|
+
### Engine
|
|
76
|
+
|
|
77
|
+
The Engine is the main interface for interacting with your Git-based database. It:
|
|
78
|
+
- Manages adapters for different Git platforms
|
|
79
|
+
- Handles collection operations
|
|
80
|
+
- Provides real-time updates through subscriptions
|
|
81
|
+
- Manages repository configuration
|
|
82
|
+
|
|
83
|
+
### Adapters
|
|
84
|
+
|
|
85
|
+
Adapters are responsible for platform-specific operations. The core package defines the interface that all adapters must implement. See the [main README](../../README.md) for available adapters.
|
|
86
|
+
|
|
87
|
+
## API Reference
|
|
88
|
+
|
|
89
|
+
### Engine
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
class Engine {
|
|
93
|
+
constructor(config: {
|
|
94
|
+
adapters: (Adapter & IAdapter)[];
|
|
95
|
+
collections: Collection[];
|
|
96
|
+
appConfig: AppConfig;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Collection Operations
|
|
100
|
+
addToCollection<T>(collectionId: string, data: T): Promise<T[]>;
|
|
101
|
+
updateInCollection<T>(collectionId: string, itemId: string, data: T): Promise<T[]>;
|
|
102
|
+
removeFromCollection<T>(collectionId: string, itemId: string): Promise<T[]>;
|
|
103
|
+
fetchCollectionItems<T>(collectionId: string): Promise<T[]>;
|
|
104
|
+
fetchCollectionItem<T>(collectionId: string, itemId: string): Promise<T | null>;
|
|
105
|
+
|
|
106
|
+
// Repository Management
|
|
107
|
+
initialize(): Promise<void>;
|
|
108
|
+
sync(): Promise<void>;
|
|
109
|
+
setRepoOwner(owner: string): void;
|
|
110
|
+
setRepoName(name: string): void;
|
|
111
|
+
setToken(token: string): void;
|
|
112
|
+
|
|
113
|
+
// Subscription
|
|
114
|
+
subscribe(callback: (collections: Collection[]) => void): void;
|
|
115
|
+
unsubscribe(callback: (collections: Collection[]) => void): void;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Related Packages
|
|
120
|
+
|
|
121
|
+
- [@oh-my-ghaad/adapter-github](../adapter-github/README.md) - GitHub adapter implementation
|
|
122
|
+
- [@oh-my-ghaad/react](../react/README.md) - React integration
|
|
123
|
+
|
|
124
|
+
For more examples and detailed usage, see the [main README](../../README.md).
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-ghaad/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"dev": "tsup src/index.ts --watch --dts --format esm,cjs",
|
|
20
20
|
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
21
|
+
"prepublish": "pnpm run build",
|
|
21
22
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
22
23
|
}
|
|
23
24
|
}
|
package/src/types.ts
CHANGED