stonyx 0.2.3-alpha.0 → 0.2.3-alpha.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/.claude/index.md +94 -0
- package/.github/workflows/ci.yml +5 -25
- package/.github/workflows/publish.yml +24 -116
- package/README.md +29 -187
- package/config/environment copy.js +1 -2
- package/config/environment.js +1 -2
- package/docs/api.md +89 -0
- package/docs/cli.md +78 -0
- package/docs/configuration.md +72 -0
- package/docs/conventions/framework-modules.md +121 -0
- package/docs/conventions/index.md +23 -0
- package/docs/conventions/orm-conventions.md +158 -0
- package/docs/conventions/project-structure.md +106 -0
- package/docs/conventions/rest-conventions.md +96 -0
- package/docs/conventions/testing-conventions.md +56 -0
- package/docs/developing-modules.md +108 -0
- package/docs/index.md +15 -0
- package/docs/lifecycle.md +47 -0
- package/docs/logging.md +52 -0
- package/docs/modules.md +78 -0
- package/docs/testing.md +64 -0
- package/package.json +7 -3
- package/scripts/postinstall.js +0 -5
- package/src/cli/help.js +48 -0
- package/src/cli/load-commands.js +56 -0
- package/src/cli/new.js +232 -0
- package/src/cli/serve.js +38 -0
- package/src/cli/test-setup.js +8 -0
- package/src/cli/test.js +27 -0
- package/src/cli.js +63 -0
- package/src/lifecycle.js +17 -0
- package/src/main.js +11 -0
- package/src/bootstrap.cjs +0 -9
- package/stonyx-bootstrap.cjs +0 -9
package/.claude/index.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Stonyx CLI Guide
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Stonyx is the core framework package. The CLI is provided by the `stonyx` binary defined in `package.json`.
|
|
6
|
+
|
|
7
|
+
In a project that depends on `stonyx`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D stonyx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The CLI is then available as `npx stonyx` or via pnpm scripts.
|
|
14
|
+
|
|
15
|
+
## Commands
|
|
16
|
+
|
|
17
|
+
### `stonyx serve` (alias: `s`)
|
|
18
|
+
|
|
19
|
+
Bootstrap Stonyx and run the application.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
stonyx serve # loads app.js by default
|
|
23
|
+
stonyx serve --entry custom.js # custom entry point
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Behavior:
|
|
27
|
+
1. Loads `.env` file
|
|
28
|
+
2. Imports `config/environment.js`
|
|
29
|
+
3. Initializes Stonyx with all detected `@stonyx/*` modules
|
|
30
|
+
4. Runs startup lifecycle hooks
|
|
31
|
+
5. Imports and instantiates the entry point class
|
|
32
|
+
6. Registers SIGTERM/SIGINT handlers for graceful shutdown
|
|
33
|
+
|
|
34
|
+
### `stonyx test` (alias: `t`)
|
|
35
|
+
|
|
36
|
+
Bootstrap Stonyx in test mode and run QUnit tests.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
stonyx test # runs test/**/*-test.js
|
|
40
|
+
stonyx test test/unit/foo-test.js # specific file
|
|
41
|
+
stonyx test "test/integration/**/*-test.js" # glob pattern
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Sets `NODE_ENV=test` and auto-loads test setup which merges `test/config/environment.js` overrides.
|
|
45
|
+
|
|
46
|
+
### `stonyx help` (alias: `h`)
|
|
47
|
+
|
|
48
|
+
Show available commands including built-in and module-provided commands.
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
stonyx help
|
|
52
|
+
stonyx --help
|
|
53
|
+
stonyx -h
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### `stonyx new <app-name>`
|
|
57
|
+
|
|
58
|
+
Scaffold a new Stonyx project with interactive module selection.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
stonyx new my-backend
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Prompts for:
|
|
65
|
+
- Package name
|
|
66
|
+
- Which `@stonyx/*` modules to include (REST server, WebSockets, ORM, cron, OAuth, events)
|
|
67
|
+
|
|
68
|
+
Creates:
|
|
69
|
+
- `package.json` with selected dependencies
|
|
70
|
+
- `app.js` entry point
|
|
71
|
+
- `config/environment.js` and `config/environment.example.js`
|
|
72
|
+
- Module-specific directories (`models/`, `requests/`, `crons/`, etc.)
|
|
73
|
+
- `test/` structure with `unit/`, `integration/`, `acceptance/`
|
|
74
|
+
- `.gitignore` and `.nvmrc`
|
|
75
|
+
- Runs `pnpm install`
|
|
76
|
+
|
|
77
|
+
## Module Command System
|
|
78
|
+
|
|
79
|
+
Stonyx modules can register CLI commands by exporting a `./commands` entry in their `package.json` exports map. The CLI auto-discovers these from installed `@stonyx/*` packages.
|
|
80
|
+
|
|
81
|
+
Module commands appear under "Module commands" in `stonyx help` output. They can optionally request Stonyx bootstrap before running (via `bootstrap: true`).
|
|
82
|
+
|
|
83
|
+
## Creating a Stonyx Project Manually
|
|
84
|
+
|
|
85
|
+
If not using `stonyx new`:
|
|
86
|
+
|
|
87
|
+
1. Create project directory
|
|
88
|
+
2. Add `.nvmrc` with current LTS Node version
|
|
89
|
+
3. `pnpm init` and set `"type": "module"`
|
|
90
|
+
4. `pnpm add -D stonyx` plus desired `@stonyx/*` modules
|
|
91
|
+
5. Create `config/environment.js` with module config
|
|
92
|
+
6. Create `app.js` entry point class
|
|
93
|
+
7. Create standard directories per selected modules
|
|
94
|
+
8. Add `@abofs/code-conventions` for linting
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -2,35 +2,15 @@ name: CI
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
pull_request:
|
|
5
|
-
branches:
|
|
6
|
-
- dev
|
|
7
|
-
- main
|
|
5
|
+
branches: [dev, main]
|
|
8
6
|
|
|
9
7
|
concurrency:
|
|
10
8
|
group: ci-${{ github.head_ref || github.ref }}
|
|
11
9
|
cancel-in-progress: true
|
|
12
10
|
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
13
14
|
jobs:
|
|
14
15
|
test:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
steps:
|
|
18
|
-
- name: Checkout code
|
|
19
|
-
uses: actions/checkout@v3
|
|
20
|
-
|
|
21
|
-
- name: Setup pnpm
|
|
22
|
-
uses: pnpm/action-setup@v4
|
|
23
|
-
with:
|
|
24
|
-
version: 9
|
|
25
|
-
|
|
26
|
-
- name: Set up Node.js
|
|
27
|
-
uses: actions/setup-node@v3
|
|
28
|
-
with:
|
|
29
|
-
node-version: 24.13.0
|
|
30
|
-
cache: 'pnpm'
|
|
31
|
-
|
|
32
|
-
- name: Install dependencies
|
|
33
|
-
run: pnpm install --frozen-lockfile
|
|
34
|
-
|
|
35
|
-
- name: Run tests
|
|
36
|
-
run: pnpm test
|
|
16
|
+
uses: abofs/stonyx-workflows/.github/workflows/ci.yml@main
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
name: Publish to NPM
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
|
-
|
|
4
|
+
repository_dispatch:
|
|
5
|
+
types: [cascade-publish]
|
|
5
6
|
workflow_dispatch:
|
|
6
7
|
inputs:
|
|
7
8
|
version-type:
|
|
@@ -9,7 +10,6 @@ on:
|
|
|
9
10
|
required: true
|
|
10
11
|
type: choice
|
|
11
12
|
options:
|
|
12
|
-
- alpha
|
|
13
13
|
- patch
|
|
14
14
|
- minor
|
|
15
15
|
- major
|
|
@@ -17,127 +17,35 @@ on:
|
|
|
17
17
|
description: 'Custom version (optional, overrides version-type)'
|
|
18
18
|
required: false
|
|
19
19
|
type: string
|
|
20
|
-
|
|
21
|
-
# Auto-publish alpha on PR
|
|
22
20
|
pull_request:
|
|
23
21
|
types: [opened, synchronize, reopened]
|
|
24
|
-
branches: [main
|
|
25
|
-
|
|
26
|
-
# Auto-publish stable on merge to main
|
|
22
|
+
branches: [main]
|
|
27
23
|
push:
|
|
28
24
|
branches: [main]
|
|
29
25
|
|
|
26
|
+
concurrency:
|
|
27
|
+
group: ${{ github.event_name == 'repository_dispatch' && 'cascade-update' || format('publish-{0}', github.ref) }}
|
|
28
|
+
cancel-in-progress: false
|
|
29
|
+
|
|
30
30
|
permissions:
|
|
31
31
|
contents: write
|
|
32
|
-
id-token: write
|
|
33
|
-
pull-requests: write
|
|
32
|
+
id-token: write
|
|
33
|
+
pull-requests: write
|
|
34
34
|
|
|
35
35
|
jobs:
|
|
36
36
|
publish:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- name: Set up Node.js
|
|
53
|
-
uses: actions/setup-node@v3
|
|
54
|
-
with:
|
|
55
|
-
node-version: 24.13.0
|
|
56
|
-
cache: 'pnpm'
|
|
57
|
-
registry-url: 'https://registry.npmjs.org'
|
|
58
|
-
|
|
59
|
-
- name: Install dependencies
|
|
60
|
-
run: pnpm install --frozen-lockfile
|
|
61
|
-
|
|
62
|
-
- name: Run tests
|
|
63
|
-
run: pnpm test
|
|
64
|
-
|
|
65
|
-
- name: Configure git
|
|
66
|
-
run: |
|
|
67
|
-
git config user.name "github-actions[bot]"
|
|
68
|
-
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
69
|
-
|
|
70
|
-
# Determine version type based on trigger
|
|
71
|
-
- name: Determine version bump type
|
|
72
|
-
id: version-type
|
|
73
|
-
run: |
|
|
74
|
-
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
|
75
|
-
echo "type=alpha" >> $GITHUB_OUTPUT
|
|
76
|
-
elif [ "${{ github.event_name }}" = "push" ]; then
|
|
77
|
-
echo "type=patch" >> $GITHUB_OUTPUT
|
|
78
|
-
elif [ "${{ github.event.inputs.custom-version }}" != "" ]; then
|
|
79
|
-
echo "type=custom" >> $GITHUB_OUTPUT
|
|
80
|
-
else
|
|
81
|
-
echo "type=${{ github.event.inputs.version-type }}" >> $GITHUB_OUTPUT
|
|
82
|
-
fi
|
|
83
|
-
|
|
84
|
-
# Version bumping
|
|
85
|
-
- name: Bump version (custom)
|
|
86
|
-
if: steps.version-type.outputs.type == 'custom'
|
|
87
|
-
run: pnpm version ${{ github.event.inputs.custom-version }} --no-git-tag-version
|
|
88
|
-
|
|
89
|
-
- name: Bump version (alpha)
|
|
90
|
-
if: steps.version-type.outputs.type == 'alpha'
|
|
91
|
-
run: pnpm version prerelease --preid=alpha --no-git-tag-version
|
|
92
|
-
|
|
93
|
-
- name: Bump version (patch/minor/major)
|
|
94
|
-
if: steps.version-type.outputs.type == 'patch' || steps.version-type.outputs.type == 'minor' || steps.version-type.outputs.type == 'major'
|
|
95
|
-
run: pnpm version ${{ steps.version-type.outputs.type }} --no-git-tag-version
|
|
96
|
-
|
|
97
|
-
- name: Get package version
|
|
98
|
-
id: package-version
|
|
99
|
-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
|
|
100
|
-
|
|
101
|
-
# Publishing
|
|
102
|
-
- name: Publish to NPM (alpha)
|
|
103
|
-
if: contains(steps.package-version.outputs.version, 'alpha')
|
|
104
|
-
run: pnpm publish --tag alpha --access public --no-git-checks
|
|
105
|
-
|
|
106
|
-
- name: Publish to NPM (stable)
|
|
107
|
-
if: "!contains(steps.package-version.outputs.version, 'alpha')"
|
|
108
|
-
run: pnpm publish --access public
|
|
109
|
-
|
|
110
|
-
# Only commit and tag for stable releases (push to main or manual stable)
|
|
111
|
-
- name: Commit version bump and create tag
|
|
112
|
-
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
|
|
113
|
-
run: |
|
|
114
|
-
git add package.json
|
|
115
|
-
git commit -m "chore: release v${{ steps.package-version.outputs.version }}"
|
|
116
|
-
git tag v${{ steps.package-version.outputs.version }}
|
|
117
|
-
git push origin main --tags
|
|
118
|
-
|
|
119
|
-
- name: Create GitHub Release
|
|
120
|
-
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !contains(steps.package-version.outputs.version, 'alpha'))
|
|
121
|
-
uses: actions/create-release@v1
|
|
122
|
-
env:
|
|
123
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
124
|
-
with:
|
|
125
|
-
tag_name: v${{ steps.package-version.outputs.version }}
|
|
126
|
-
release_name: v${{ steps.package-version.outputs.version }}
|
|
127
|
-
draft: false
|
|
128
|
-
prerelease: false
|
|
129
|
-
|
|
130
|
-
# Add PR comment with alpha version info
|
|
131
|
-
- name: Comment on PR with alpha version
|
|
132
|
-
if: github.event_name == 'pull_request'
|
|
133
|
-
uses: actions/github-script@v6
|
|
134
|
-
with:
|
|
135
|
-
script: |
|
|
136
|
-
const version = '${{ steps.package-version.outputs.version }}';
|
|
137
|
-
const packageName = require('./package.json').name;
|
|
138
|
-
github.rest.issues.createComment({
|
|
139
|
-
issue_number: context.issue.number,
|
|
140
|
-
owner: context.repo.owner,
|
|
141
|
-
repo: context.repo.repo,
|
|
142
|
-
body: `## 🚀 Alpha Version Published\n\n**Version:** \`${version}\`\n\n**Install:**\n\`\`\`bash\npnpm add ${packageName}@${version}\n# or\npnpm add ${packageName}@alpha # latest alpha\n\`\`\`\n\nThis alpha version is now available for testing!`
|
|
143
|
-
});
|
|
37
|
+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
|
|
38
|
+
uses: abofs/stonyx-workflows/.github/workflows/npm-publish.yml@main
|
|
39
|
+
with:
|
|
40
|
+
version-type: ${{ github.event.inputs.version-type }}
|
|
41
|
+
custom-version: ${{ github.event.inputs.custom-version }}
|
|
42
|
+
cascade-source: ${{ github.event.client_payload.source_package || '' }}
|
|
43
|
+
secrets: inherit
|
|
44
|
+
|
|
45
|
+
cascade:
|
|
46
|
+
needs: publish
|
|
47
|
+
uses: abofs/stonyx-workflows/.github/workflows/cascade.yml@main
|
|
48
|
+
with:
|
|
49
|
+
package-name: ${{ needs.publish.outputs.package-name }}
|
|
50
|
+
published-version: ${{ needs.publish.outputs.published-version }}
|
|
51
|
+
secrets: inherit
|
package/README.md
CHANGED
|
@@ -1,206 +1,48 @@
|
|
|
1
1
|
# Stonyx
|
|
2
2
|
|
|
3
|
-
**Stonyx** is a lightweight, modular framework for building modern Node.js applications. It provides a
|
|
3
|
+
**Stonyx** is a lightweight, modular framework for building modern Node.js applications. It provides a plug-and-play architecture, centralized color-coded logging, and seamless async module integration.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* ✅ Don’t even hit the ground — just fly
|
|
10
|
-
* ✅ High performance
|
|
11
|
-
|
|
12
|
-
Stonyx acts as a **base application host**, allowing you to add official modules (`@stonyx/*`) or your own custom modules without boilerplate initialization.
|
|
13
|
-
|
|
14
|
-
---
|
|
5
|
+
- 100% JavaScript (ES Modules)
|
|
6
|
+
- Drop-in module system — no boilerplate
|
|
7
|
+
- Automatic async module loading and initialization
|
|
8
|
+
- Built-in CLI for bootstrapping and testing
|
|
15
9
|
|
|
16
10
|
## Quick Start
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
For standard applications, the **bootstrap file** ensures that the Stonyx framework and all submodules are fully loaded before your application code runs:
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
// index.js - your project's entry point
|
|
24
|
-
import Stonyx from './stonyx-bootstrap.cjs';
|
|
25
|
-
await Stonyx.ready; // wait until all modules are initialized
|
|
26
|
-
|
|
27
|
-
const { default: App } = await import('./app.js'); // your application
|
|
28
|
-
new App();
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### CommonJS Bootstrap Helper
|
|
32
|
-
Auto-generated and added to your project post installation
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
// stonyx-bootstrap.cjs
|
|
36
|
-
const Stonyx = require('stonyx').default;
|
|
37
|
-
const config = require('./config/environment.js').default;
|
|
38
|
-
|
|
39
|
-
new Stonyx(config, __dirname);
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
## Core Features
|
|
45
|
-
|
|
46
|
-
### 1. **Modular Architecture**
|
|
47
|
-
|
|
48
|
-
* Automatically detects modules in `devDependencies` prefixed with `@stonyx/`.
|
|
49
|
-
* Supports async initialization with `stonyx-async` modules.
|
|
50
|
-
* Safe module sequencing for submodule development with `waitForModule()`.
|
|
51
|
-
|
|
52
|
-
### 2. **Color-Coded Logging**
|
|
53
|
-
|
|
54
|
-
* Centralized logging via [Chronicle](https://github.com/abofs/chronicle).
|
|
55
|
-
* Module-specific logs configurable in `environment.js`:
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
restServer: { logColor: 'yellow', logMethod: 'api', logTimestamp: true }
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
* Create custom logs for any class with minimal configuration.
|
|
62
|
-
|
|
63
|
-
### 3. **Singleton Design**
|
|
64
|
-
|
|
65
|
-
* Only one instance of Stonyx exists per project.
|
|
66
|
-
* Ensures consistent access to modules, logs, and configuration.
|
|
67
|
-
|
|
68
|
-
### 4. **Plug-and-Play Module Loading**
|
|
69
|
-
|
|
70
|
-
* Modules with `stonyx-module` keyword in `package.json` are auto-initialized.
|
|
71
|
-
* Modules with `stonyx-async` keyword are awaited automatically before usage.
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## Official Modules
|
|
76
|
-
|
|
77
|
-
### **[@stonyx/cron](https://github.com/abofs/stonyx-cron)**
|
|
78
|
-
|
|
79
|
-
Lightweight asynchronous job scheduling utility.
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
import Cron from '@stonyx/cron';
|
|
83
|
-
|
|
84
|
-
const cron = new Cron();
|
|
85
|
-
cron.register('exampleJob', async () => console.log('Job executed!'), 5, true);
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
* Efficient scheduling using a min-heap.
|
|
89
|
-
* Optional logging via `config.cron`.
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
### **[@stonyx/events](https://github.com/abofs/stonyx-events)**
|
|
94
|
-
|
|
95
|
-
Lightweight pub/sub event system for application-wide event handling.
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
import Events from '@stonyx/events';
|
|
99
|
-
|
|
100
|
-
const events = new Events();
|
|
101
|
-
|
|
102
|
-
// Register available events
|
|
103
|
-
events.setup(['userLogin', 'userLogout', 'dataChange']);
|
|
104
|
-
|
|
105
|
-
// Subscribe to events
|
|
106
|
-
events.subscribe('userLogin', (user) => {
|
|
107
|
-
console.log(`${user.name} logged in`);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Emit events
|
|
111
|
-
events.emit('userLogin', { name: 'Alice' });
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
* Singleton pattern for shared event bus
|
|
115
|
-
* Async support with error isolation
|
|
116
|
-
* Type-safe event registration
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
### **[@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server)**
|
|
121
|
-
|
|
122
|
-
Dynamic REST server module with auto-route registration.
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
import Stonyx from 'stonyx';
|
|
126
|
-
import config from './config/environment.js';
|
|
127
|
-
|
|
128
|
-
new Stonyx(config);
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
* Zero configuration for routes: drop request classes into the `requests` directory.
|
|
132
|
-
* Automatic path generation, JSON parsing, and CORS handling.
|
|
133
|
-
* Supports per-route authentication hooks.
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
### **[@stonyx/orm](https://github.com/abofs/stonyx-orm)**
|
|
138
|
-
|
|
139
|
-
Lightweight ORM with model definitions, relationships, serializers, and optional REST integration.
|
|
140
|
-
|
|
141
|
-
```js
|
|
142
|
-
import Stonyx from 'stonyx';
|
|
143
|
-
import config from './config/environment.js';
|
|
144
|
-
|
|
145
|
-
new Stonyx(config);
|
|
146
|
-
|
|
147
|
-
// Define models
|
|
148
|
-
import { Model, attr, hasMany, belongsTo } from '@stonyx/orm';
|
|
149
|
-
|
|
150
|
-
class Owner extends Model {
|
|
151
|
-
id = attr('string');
|
|
152
|
-
pets = hasMany('animal');
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
* Auto-loads models, serializers, transforms, and access classes.
|
|
157
|
-
* Optional JSON file persistence with auto-save intervals.
|
|
158
|
-
* Integrates with `@stonyx/rest-server` for automatic route setup.
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
## Configuration
|
|
163
|
-
|
|
164
|
-
All modules are configurable via `config/environment.js`:
|
|
165
|
-
|
|
166
|
-
```js
|
|
167
|
-
export default {
|
|
168
|
-
restServer: { logColor: 'yellow', port: 3000 },
|
|
169
|
-
orm: { logColor: 'white', db: { file: './db.json', autosave: true } },
|
|
170
|
-
cron: { log: true }
|
|
171
|
-
};
|
|
12
|
+
```bash
|
|
13
|
+
npm install stonyx
|
|
172
14
|
```
|
|
173
15
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
## Running the Application
|
|
16
|
+
The CLI handles everything — no manual `new Stonyx()` calls needed:
|
|
177
17
|
|
|
178
18
|
```bash
|
|
179
|
-
|
|
180
|
-
|
|
19
|
+
stonyx serve # Bootstrap + run app.js
|
|
20
|
+
stonyx test # Bootstrap + run tests
|
|
181
21
|
```
|
|
182
22
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
## Developing Submodules
|
|
23
|
+
Stonyx reads `config/environment.js`, initializes all `@stonyx/*` modules from your `devDependencies`, and runs your application.
|
|
186
24
|
|
|
187
|
-
|
|
25
|
+
## Documentation
|
|
188
26
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
27
|
+
| Section | Description |
|
|
28
|
+
|---------|-------------|
|
|
29
|
+
| [CLI](docs/cli.md) | Commands, aliases, and module commands |
|
|
30
|
+
| [Configuration](docs/configuration.md) | Environment config, module config, test overrides |
|
|
31
|
+
| [Modules](docs/modules.md) | Module architecture, async loading, official modules |
|
|
32
|
+
| [Logging](docs/logging.md) | Chronicle integration and custom log types |
|
|
33
|
+
| [Lifecycle](docs/lifecycle.md) | Startup and shutdown hooks |
|
|
34
|
+
| [Testing](docs/testing.md) | Test runner, helpers, and conventions |
|
|
35
|
+
| [Developing Modules](docs/developing-modules.md) | Guide for building custom Stonyx modules |
|
|
36
|
+
| [API Reference](docs/api.md) | Public exports and class documentation |
|
|
192
37
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// Wait for specific async module readiness
|
|
196
|
-
await waitForModule('restServer');
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
* Use `waitForModule()` **only for submodule development**, testing, or when you need to ensure a specific module is fully initialized before continuing.
|
|
200
|
-
* Official modules automatically initialize during normal application startup, so end-users do **not** need to call `waitForModule()`.
|
|
38
|
+
## Official Modules
|
|
201
39
|
|
|
202
|
-
|
|
40
|
+
| Module | Description |
|
|
41
|
+
|--------|-------------|
|
|
42
|
+
| [@stonyx/cron](https://github.com/abofs/stonyx-cron) | Lightweight async job scheduling |
|
|
43
|
+
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
44
|
+
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, and serializers |
|
|
203
45
|
|
|
204
46
|
## License
|
|
205
47
|
|
|
206
|
-
Apache 2.0
|
|
48
|
+
Apache 2.0
|
package/config/environment.js
CHANGED
package/docs/api.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
Public exports available from the `stonyx` package.
|
|
4
|
+
|
|
5
|
+
## Exports Map
|
|
6
|
+
|
|
7
|
+
| Import Path | Export | Description |
|
|
8
|
+
|-------------|--------|-------------|
|
|
9
|
+
| `stonyx` | `default` (Stonyx class) | Main framework class (singleton) |
|
|
10
|
+
| `stonyx` | `waitForModule(name)` | Wait for an async module to be ready |
|
|
11
|
+
| `stonyx/config` | `default` (config object) | Live reference to Stonyx configuration |
|
|
12
|
+
| `stonyx/log` | `default` (Chronicle instance) | Live reference to Chronicle logger |
|
|
13
|
+
| `stonyx/lifecycle` | `runStartupHooks(modules)` | Run startup hooks on a module array |
|
|
14
|
+
| `stonyx/lifecycle` | `runShutdownHooks(modules)` | Run shutdown hooks in reverse order |
|
|
15
|
+
| `stonyx/test-helpers` | `setupIntegrationTests(hooks)` | QUnit hook for integration test setup |
|
|
16
|
+
|
|
17
|
+
## Stonyx Class
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import Stonyx from 'stonyx';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Constructor
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
new Stonyx(config, rootPath)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **config** — Full environment configuration object
|
|
30
|
+
- **rootPath** — Absolute path to the project root
|
|
31
|
+
|
|
32
|
+
Returns the existing instance if one already exists (singleton pattern).
|
|
33
|
+
|
|
34
|
+
### Static Properties
|
|
35
|
+
|
|
36
|
+
| Property | Type | Description |
|
|
37
|
+
|----------|------|-------------|
|
|
38
|
+
| `Stonyx.instance` | `Stonyx` | The singleton instance |
|
|
39
|
+
| `Stonyx.ready` | `Promise` | Resolves when all modules are initialized |
|
|
40
|
+
| `Stonyx.initialized` | `boolean` | Whether Stonyx has started initialization |
|
|
41
|
+
|
|
42
|
+
### Static Getters
|
|
43
|
+
|
|
44
|
+
| Getter | Returns | Throws |
|
|
45
|
+
|--------|---------|--------|
|
|
46
|
+
| `Stonyx.config` | Config object | If not initialized |
|
|
47
|
+
| `Stonyx.log` | Chronicle instance | If not initialized |
|
|
48
|
+
|
|
49
|
+
### Instance Properties
|
|
50
|
+
|
|
51
|
+
| Property | Type | Description |
|
|
52
|
+
|----------|------|-------------|
|
|
53
|
+
| `instance.config` | `object` | Merged environment configuration |
|
|
54
|
+
| `instance.chronicle` | `Chronicle` | Logger instance |
|
|
55
|
+
| `instance.modules` | `Array` | Loaded module instances |
|
|
56
|
+
|
|
57
|
+
## waitForModule
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { waitForModule } from 'stonyx';
|
|
61
|
+
|
|
62
|
+
await waitForModule('rest-server');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Waits for a specific `@stonyx/*` module to complete initialization. Pass the module name **without** the `@stonyx/` prefix.
|
|
66
|
+
|
|
67
|
+
Throws if the module is not registered in project dependencies.
|
|
68
|
+
|
|
69
|
+
## Lifecycle Functions
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { runStartupHooks, runShutdownHooks } from 'stonyx/lifecycle';
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### runStartupHooks(modules)
|
|
76
|
+
|
|
77
|
+
Calls `startup()` on each module in array order. Skips modules without a `startup` method.
|
|
78
|
+
|
|
79
|
+
### runShutdownHooks(modules)
|
|
80
|
+
|
|
81
|
+
Calls `shutdown()` on each module in **reverse** array order. Errors are caught and logged — one failing hook does not prevent others from running.
|
|
82
|
+
|
|
83
|
+
## setupIntegrationTests
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
import { setupIntegrationTests } from 'stonyx/test-helpers';
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Registers a QUnit `before` hook that waits for `Stonyx.ready`. Use within a `module()` block to ensure Stonyx is fully initialized before tests run.
|