stonyx 0.2.3-beta.9 → 0.2.3-beta.90
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/README.md +16 -5
- package/config/{environment.js → environment copy.ts } +16 -12
- package/dist/cli/help.d.ts +8 -0
- package/dist/cli/help.js +43 -0
- package/dist/cli/load-commands.d.ts +10 -0
- package/dist/cli/load-commands.js +49 -0
- package/dist/cli/new.d.ts +26 -0
- package/dist/cli/new.js +293 -0
- package/dist/cli/serve.d.ts +6 -0
- package/dist/cli/serve.js +49 -0
- package/dist/cli/test-setup.d.ts +1 -0
- package/dist/cli/test-setup.js +30 -0
- package/dist/cli/test.d.ts +4 -0
- package/dist/cli/test.js +23 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +53 -0
- package/dist/exports/config.d.ts +2 -0
- package/dist/exports/config.js +2 -0
- package/dist/exports/log.d.ts +2 -0
- package/{src → dist}/exports/log.js +1 -2
- package/dist/exports/test-helpers.d.ts +5 -0
- package/dist/exports/test-helpers.js +7 -0
- package/dist/lifecycle.d.ts +7 -0
- package/dist/lifecycle.js +18 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +98 -0
- package/dist/modules.d.ts +5 -0
- package/dist/modules.js +93 -0
- package/dist/util/import-config.d.ts +1 -0
- package/dist/util/import-config.js +10 -0
- package/dist/util/resolve-entry-point.d.ts +1 -0
- package/dist/util/resolve-entry-point.js +14 -0
- package/dist/util/resolve-module-name.d.ts +14 -0
- package/dist/util/resolve-module-name.js +33 -0
- package/package.json +41 -12
- package/scripts/postinstall.js +24 -2
- package/.claude/index.md +0 -96
- package/.github/workflows/ci.yml +0 -16
- package/.github/workflows/publish.yml +0 -51
- package/docs/api.md +0 -89
- package/docs/cli.md +0 -78
- package/docs/configuration.md +0 -72
- package/docs/conventions/discord-conventions.md +0 -62
- package/docs/conventions/framework-modules.md +0 -127
- package/docs/conventions/index.md +0 -24
- package/docs/conventions/orm-conventions.md +0 -158
- package/docs/conventions/project-structure.md +0 -105
- package/docs/conventions/rest-conventions.md +0 -96
- package/docs/conventions/testing-conventions.md +0 -56
- package/docs/developing-modules.md +0 -108
- package/docs/index.md +0 -15
- package/docs/lifecycle.md +0 -47
- package/docs/logging.md +0 -52
- package/docs/modules.md +0 -78
- package/docs/testing.md +0 -64
- package/src/cli/help.js +0 -48
- package/src/cli/load-commands.js +0 -56
- package/src/cli/new.js +0 -237
- package/src/cli/serve.js +0 -38
- package/src/cli/test-setup.js +0 -8
- package/src/cli/test.js +0 -27
- package/src/cli.js +0 -63
- package/src/exports/config.js +0 -3
- package/src/exports/test-helpers.js +0 -8
- package/src/lifecycle.js +0 -17
- package/src/main.js +0 -101
- package/src/modules.js +0 -112
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# Project Structure
|
|
2
|
-
|
|
3
|
-
## Entry Point
|
|
4
|
-
|
|
5
|
-
The application entry point is always `app.js` at the project root. This file exports a default class that initializes the application.
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import log from 'stonyx/log';
|
|
9
|
-
|
|
10
|
-
export default class App {
|
|
11
|
-
constructor() {
|
|
12
|
-
if (App.instance) return App.instance;
|
|
13
|
-
App.instance = this;
|
|
14
|
-
|
|
15
|
-
this.ready = this.init();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async init() {
|
|
19
|
-
log.info('Initializing Application');
|
|
20
|
-
// Application setup here
|
|
21
|
-
log.info('Application has been initialized');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## File Layout
|
|
27
|
-
|
|
28
|
-
Flat file structure at root level — non-directory project files live at the project root.
|
|
29
|
-
|
|
30
|
-
### Standard Directories
|
|
31
|
-
|
|
32
|
-
| Directory | Purpose | When to create |
|
|
33
|
-
|-----------|---------|----------------|
|
|
34
|
-
| `config/` | Configuration files | Always |
|
|
35
|
-
| `models/` | ORM model definitions | When using `@stonyx/orm` |
|
|
36
|
-
| `serializers/` | Data serializers | When using `@stonyx/orm` |
|
|
37
|
-
| `access/` | Access control definitions | When using `@stonyx/orm` |
|
|
38
|
-
| `transforms/` | Value transforms | When using `@stonyx/orm` |
|
|
39
|
-
| `hooks/` | Lifecycle hooks | When using `@stonyx/orm` |
|
|
40
|
-
| `requests/` | REST request handlers | When using `@stonyx/rest-server` |
|
|
41
|
-
| `crons/` | Scheduled tasks | When using `@stonyx/cron` |
|
|
42
|
-
| `clients/` | External API clients | When fetching external data |
|
|
43
|
-
| `test/`| Tests | Always |
|
|
44
|
-
| `utils.js` or `utils/` | Project-specific reusable logic | As needed (never duplicate `@stonyx/utils`) |
|
|
45
|
-
|
|
46
|
-
### Nested Model Directories
|
|
47
|
-
|
|
48
|
-
Use nested directories under `models/` for `belongsTo` child models:
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
models/
|
|
52
|
-
character.js
|
|
53
|
-
character/
|
|
54
|
-
relationship.js
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Config Conventions
|
|
58
|
-
|
|
59
|
-
### `config/environment.js`
|
|
60
|
-
|
|
61
|
-
Destructure env vars at the top, apply defaults with `??`, export a plain object:
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
const {
|
|
65
|
-
CORS_ORIGIN,
|
|
66
|
-
DB_FILE,
|
|
67
|
-
NODE_ENV,
|
|
68
|
-
REST_PORT,
|
|
69
|
-
} = process.env;
|
|
70
|
-
|
|
71
|
-
const environment = NODE_ENV ?? 'development';
|
|
72
|
-
|
|
73
|
-
export default {
|
|
74
|
-
orm: {
|
|
75
|
-
db: {
|
|
76
|
-
file: DB_FILE ?? 'db.json',
|
|
77
|
-
schema: './config/db-schema.js'
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
restServer: {
|
|
81
|
-
origin: CORS_ORIGIN ?? '*',
|
|
82
|
-
port: REST_PORT ?? 3000
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
**Do NOT re-declare module defaults.** Only include config values that differ from the module's built-in defaults.
|
|
88
|
-
|
|
89
|
-
### `config/db-schema.js`
|
|
90
|
-
|
|
91
|
-
Extends `Model` and uses `hasMany` to define each collection:
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
import { Model, hasMany } from '@stonyx/orm';
|
|
95
|
-
|
|
96
|
-
export default class DBModel extends Model {
|
|
97
|
-
owners = hasMany('owner');
|
|
98
|
-
animals = hasMany('animal');
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Reference Projects
|
|
103
|
-
|
|
104
|
-
- `smart-lock-backend/` — full example with REST, ORM, sockets, crons, hooks
|
|
105
|
-
- `nextgoal-backend/` — example with models, transforms, filters, bot commands
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# REST Conventions
|
|
2
|
-
|
|
3
|
-
## Request Classes
|
|
4
|
-
|
|
5
|
-
One request class per file in `requests/`. Each class extends `Request` from `@stonyx/rest-server`.
|
|
6
|
-
|
|
7
|
-
**Class ordering:** properties → `handlers` object → `auth()` hook → validation/middleware methods
|
|
8
|
-
|
|
9
|
-
### Public Request (no auth)
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
import { Request } from '@stonyx/rest-server';
|
|
13
|
-
|
|
14
|
-
export default class PublicRequest extends Request {
|
|
15
|
-
testProp = 'stonyx';
|
|
16
|
-
|
|
17
|
-
handlers = {
|
|
18
|
-
get: {
|
|
19
|
-
'/': (_request, _state) => {
|
|
20
|
-
return { data: 'foo' };
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
'/url-params/:x/:y/:z': ({ params }, _state) => {
|
|
24
|
-
return params;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
// Middleware chaining: [middlewareFn, handlerFn]
|
|
28
|
-
'/foo': [this.validationSuccessSample, (_request, state) => {
|
|
29
|
-
return { data: state };
|
|
30
|
-
}],
|
|
31
|
-
|
|
32
|
-
'/fail': [this.validationFailureSample, (_request, _state) => {
|
|
33
|
-
return { unreachable: 'response' };
|
|
34
|
-
}],
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
validationSuccessSample(_request, state) {
|
|
39
|
-
state.newProp = 'bar';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
validationFailureSample() {
|
|
43
|
-
return 504; // returning a status code rejects the request
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Private Request (with auth)
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
import { Request } from '@stonyx/rest-server';
|
|
52
|
-
|
|
53
|
-
export default class PrivateRequest extends Request {
|
|
54
|
-
handlers = {
|
|
55
|
-
get: {
|
|
56
|
-
'/success': (_request, _state) => {
|
|
57
|
-
return { data: 'foo' };
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
'/failure': (_request, _state) => {
|
|
61
|
-
return { data: 'foo' };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
auth(request, _state) {
|
|
67
|
-
if (request.path === '/failure') return 505;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Key Patterns
|
|
73
|
-
|
|
74
|
-
### `handlers` Object
|
|
75
|
-
|
|
76
|
-
Keyed by HTTP method (`get`, `post`, `put`, `delete`), each containing route-to-handler mappings.
|
|
77
|
-
|
|
78
|
-
Handler signature: `(request, state) => responseData`
|
|
79
|
-
|
|
80
|
-
### Middleware Chaining
|
|
81
|
-
|
|
82
|
-
Use `[middlewareFn, handlerFn]` arrays to chain middleware before a handler. The middleware function receives `(request, state)` and can:
|
|
83
|
-
- Mutate `state` to pass data to the handler
|
|
84
|
-
- Return a status code number to reject the request early
|
|
85
|
-
|
|
86
|
-
### `auth()` Hook
|
|
87
|
-
|
|
88
|
-
Runs before all handlers in the class. Return an error status code to reject the request. If `auth()` returns nothing (undefined), the request proceeds.
|
|
89
|
-
|
|
90
|
-
### Route Parameters
|
|
91
|
-
|
|
92
|
-
Express-style route params (`:param`) are available via `request.params`.
|
|
93
|
-
|
|
94
|
-
### Binding
|
|
95
|
-
|
|
96
|
-
Handler functions defined as arrow functions or class methods have access to `this` (the request class instance).
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Testing Conventions
|
|
2
|
-
|
|
3
|
-
## Directory Structure
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
test/
|
|
7
|
-
unit/
|
|
8
|
-
integration/
|
|
9
|
-
acceptance/
|
|
10
|
-
config/
|
|
11
|
-
environment.js # test config overrides
|
|
12
|
-
sample/ # fixtures and mocks (alternative: test/mocks/)
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## File Naming
|
|
16
|
-
|
|
17
|
-
All test files use the `*-test.js` suffix: `animal-test.js`, `public-request-test.js`.
|
|
18
|
-
|
|
19
|
-
## Test Framework
|
|
20
|
-
|
|
21
|
-
- **QUnit** — test framework
|
|
22
|
-
- **Sinon** — stubs, spies, and mocks
|
|
23
|
-
|
|
24
|
-
Run tests with `stonyx test` (alias: `stonyx t`), which:
|
|
25
|
-
1. Sets `NODE_ENV=test`
|
|
26
|
-
2. Loads test setup (bootstrap with test config overrides)
|
|
27
|
-
3. Runs QUnit against `test/**/*-test.js`
|
|
28
|
-
|
|
29
|
-
## Test Config Overrides
|
|
30
|
-
|
|
31
|
-
Place test-specific config at `test/config/environment.js`. Stonyx auto-merges these overrides when running in test mode.
|
|
32
|
-
|
|
33
|
-
## Sample / Fixture Files
|
|
34
|
-
|
|
35
|
-
Each stonyx module's `test/sample/` directory contains reference implementations. Mirror this structure in your project tests:
|
|
36
|
-
|
|
37
|
-
- `test/sample/models/` — model fixtures
|
|
38
|
-
- `test/sample/serializers/` — serializer fixtures
|
|
39
|
-
- `test/sample/access/` — access control fixtures
|
|
40
|
-
- `test/sample/transforms/` — transform fixtures
|
|
41
|
-
- `test/sample/requests/` — request handler fixtures
|
|
42
|
-
|
|
43
|
-
The file ordering in tests should mirror the sample files from each module's `test/sample/` directory.
|
|
44
|
-
|
|
45
|
-
## Running Tests
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
# Run all tests
|
|
49
|
-
stonyx test
|
|
50
|
-
|
|
51
|
-
# Run specific test file
|
|
52
|
-
stonyx test test/unit/animal-test.js
|
|
53
|
-
|
|
54
|
-
# Run specific glob
|
|
55
|
-
stonyx test "test/integration/**/*-test.js"
|
|
56
|
-
```
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# Developing Modules
|
|
2
|
-
|
|
3
|
-
Guide for building custom Stonyx modules.
|
|
4
|
-
|
|
5
|
-
## Package Setup
|
|
6
|
-
|
|
7
|
-
Your module's `package.json` must include:
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"name": "@stonyx/my-module",
|
|
12
|
-
"keywords": ["stonyx-module"],
|
|
13
|
-
"main": "src/index.js"
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Add `stonyx-async` to keywords if your module requires asynchronous initialization.
|
|
18
|
-
|
|
19
|
-
## Module Class
|
|
20
|
-
|
|
21
|
-
Export a default class. Optionally define `init()`, `startup()`, and `shutdown()` methods:
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
export default class MyModule {
|
|
25
|
-
// Called during module loading (async modules only)
|
|
26
|
-
async init() {
|
|
27
|
-
// Connect to services, load resources, etc.
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Called after ALL modules are initialized, before app entry runs
|
|
31
|
-
async startup() {
|
|
32
|
-
// Register routes, start listeners, etc.
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Called on SIGTERM/SIGINT, in reverse load order
|
|
36
|
-
async shutdown() {
|
|
37
|
-
// Close connections, flush data, etc.
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Default Configuration
|
|
43
|
-
|
|
44
|
-
Async modules must include `config/environment.js` with sensible defaults:
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
export default {
|
|
48
|
-
logColor: 'cyan',
|
|
49
|
-
logMethod: 'myModule',
|
|
50
|
-
logTimestamp: true,
|
|
51
|
-
// Module-specific defaults...
|
|
52
|
-
};
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
User project config is merged on top of these defaults.
|
|
56
|
-
|
|
57
|
-
## Waiting for Other Modules
|
|
58
|
-
|
|
59
|
-
If your module depends on another async module being ready:
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
import { waitForModule } from 'stonyx';
|
|
63
|
-
|
|
64
|
-
export default class MyModule {
|
|
65
|
-
async init() {
|
|
66
|
-
await waitForModule('rest-server');
|
|
67
|
-
// @stonyx/rest-server is now fully initialized
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Pass the module name without the `@stonyx/` prefix.
|
|
73
|
-
|
|
74
|
-
## Standalone Development
|
|
75
|
-
|
|
76
|
-
When running a module standalone (project path contains `stonyx-`), Stonyx auto-transforms the config structure. Your module's config is wrapped under its camelCase name:
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
// If your module is @stonyx/rest-server and config is { port: 3000 }
|
|
80
|
-
// Stonyx transforms it to: { restServer: { port: 3000 } }
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Custom CLI Commands
|
|
84
|
-
|
|
85
|
-
Modules can register CLI commands by adding a `./commands` export:
|
|
86
|
-
|
|
87
|
-
```json
|
|
88
|
-
{
|
|
89
|
-
"exports": {
|
|
90
|
-
"./commands": "./src/commands.js"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
// src/commands.js
|
|
97
|
-
export default {
|
|
98
|
-
'my-module:setup': {
|
|
99
|
-
description: 'Initialize module resources',
|
|
100
|
-
bootstrap: true,
|
|
101
|
-
run: async ({ args, cwd }) => {
|
|
102
|
-
// Command implementation
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Use namespaced command names (e.g., `my-module:setup`) to avoid conflicts with other modules. See [CLI](cli.md#module-commands) for details.
|
package/docs/index.md
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Stonyx Documentation
|
|
2
|
-
|
|
3
|
-
## Guides
|
|
4
|
-
|
|
5
|
-
- [CLI](cli.md) — Commands, usage, and module-contributed commands
|
|
6
|
-
- [Configuration](configuration.md) — Environment config, module config, and test overrides
|
|
7
|
-
- [Modules](modules.md) — Module discovery, sync vs async, and official modules
|
|
8
|
-
- [Lifecycle](lifecycle.md) — Startup/shutdown hooks and signal handling
|
|
9
|
-
- [Logging](logging.md) — Color-coded logging via Chronicle
|
|
10
|
-
- [Testing](testing.md) — Running tests, config overrides, and integration helpers
|
|
11
|
-
- [Developing Modules](developing-modules.md) — Guide for building custom Stonyx modules
|
|
12
|
-
|
|
13
|
-
## Reference
|
|
14
|
-
|
|
15
|
-
- [API Reference](api.md) — Public exports and class documentation
|
package/docs/lifecycle.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Lifecycle Hooks
|
|
2
|
-
|
|
3
|
-
Stonyx modules can define `startup()` and `shutdown()` methods that run at specific points in the application lifecycle.
|
|
4
|
-
|
|
5
|
-
## Startup Hooks
|
|
6
|
-
|
|
7
|
-
Called sequentially (in module load order) after all modules have been initialized, right before your application entry point runs.
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
export default class MyModule {
|
|
11
|
-
async startup() {
|
|
12
|
-
// Called after all modules are init'd, before app.js runs
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Shutdown Hooks
|
|
18
|
-
|
|
19
|
-
Called sequentially in **reverse** module load order when the process receives `SIGTERM` or `SIGINT`. Errors in one hook do not prevent other hooks from running.
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
export default class MyModule {
|
|
23
|
-
async shutdown() {
|
|
24
|
-
// Clean up connections, flush buffers, etc.
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Signal Handling
|
|
30
|
-
|
|
31
|
-
The `stonyx serve` command registers signal handlers automatically:
|
|
32
|
-
|
|
33
|
-
- **SIGTERM** — triggers shutdown hooks, then `process.exit(0)`
|
|
34
|
-
- **SIGINT** — triggers shutdown hooks, then `process.exit(0)`
|
|
35
|
-
|
|
36
|
-
Shutdown is idempotent — calling the handler multiple times only runs hooks once.
|
|
37
|
-
|
|
38
|
-
## Using Lifecycle Hooks Directly
|
|
39
|
-
|
|
40
|
-
For advanced use cases, the lifecycle functions are available as a public export:
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
import { runStartupHooks, runShutdownHooks } from 'stonyx/lifecycle';
|
|
44
|
-
|
|
45
|
-
await runStartupHooks(modules); // Calls startup() on each module in order
|
|
46
|
-
await runShutdownHooks(modules); // Calls shutdown() on each module in reverse order
|
|
47
|
-
```
|
package/docs/logging.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Logging
|
|
2
|
-
|
|
3
|
-
Stonyx provides centralized, color-coded logging via [Chronicle](https://github.com/abofs/chronicle).
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Every Stonyx instance creates a Chronicle logger with a default `title` log type (green). Modules and user services can register additional log types with custom colors.
|
|
8
|
-
|
|
9
|
-
## Module Logs
|
|
10
|
-
|
|
11
|
-
Modules that specify `logColor` in their configuration automatically get a Chronicle log type:
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
// config/environment.js
|
|
15
|
-
export default {
|
|
16
|
-
restServer: {
|
|
17
|
-
logColor: 'yellow',
|
|
18
|
-
logMethod: 'api', // Optional — defaults to the config key name
|
|
19
|
-
logTimestamp: true, // Optional — adds timestamps to log output
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
This creates a `chronicle.api()` method that outputs in yellow with timestamps.
|
|
25
|
-
|
|
26
|
-
## Custom Logs
|
|
27
|
-
|
|
28
|
-
You can define logs for any class or service in your project — not just Stonyx modules:
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
export default {
|
|
32
|
-
myWorker: {
|
|
33
|
-
logColor: 'cyan',
|
|
34
|
-
logMethod: 'worker',
|
|
35
|
-
logTimestamp: true,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Any top-level config key with a `logColor` property will have a log type created automatically.
|
|
41
|
-
|
|
42
|
-
## Accessing the Logger
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
import log from 'stonyx/log';
|
|
46
|
-
|
|
47
|
-
log.title('Application started');
|
|
48
|
-
log.api('Request received'); // If restServer config defines logMethod: 'api'
|
|
49
|
-
log.worker('Processing job'); // If myWorker config defines logMethod: 'worker'
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
The `stonyx/log` export is a live reference to the Chronicle instance. It will throw if accessed before Stonyx is initialized.
|
package/docs/modules.md
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# Module System
|
|
2
|
-
|
|
3
|
-
Stonyx uses a plug-and-play module architecture. Modules are automatically detected, loaded, and initialized at startup.
|
|
4
|
-
|
|
5
|
-
## How Modules Are Discovered
|
|
6
|
-
|
|
7
|
-
Stonyx scans your project's `devDependencies` for packages prefixed with `@stonyx/`. Each matching package must include the `stonyx-module` keyword in its `package.json` to be loaded.
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"name": "@stonyx/my-module",
|
|
12
|
-
"keywords": ["stonyx-module"],
|
|
13
|
-
"main": "src/index.js"
|
|
14
|
-
}
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Sync vs Async Modules
|
|
18
|
-
|
|
19
|
-
### Sync Modules
|
|
20
|
-
|
|
21
|
-
Modules with only the `stonyx-module` keyword are treated as synchronous. They are instantiated but their promise resolves immediately — no init phase is awaited.
|
|
22
|
-
|
|
23
|
-
### Async Modules
|
|
24
|
-
|
|
25
|
-
Modules that also include the `stonyx-async` keyword require initialization before they're ready:
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"keywords": ["stonyx-module", "stonyx-async"]
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Async modules **must** include a `config/environment.js` with default configuration. This is merged with the user's project config before initialization.
|
|
34
|
-
|
|
35
|
-
Async modules can define an `init()` method that Stonyx awaits:
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
export default class MyModule {
|
|
39
|
-
async init() {
|
|
40
|
-
// Connect to database, start server, etc.
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
All module `init()` calls run concurrently via `Promise.all`.
|
|
46
|
-
|
|
47
|
-
## Module Lifecycle
|
|
48
|
-
|
|
49
|
-
1. **Discovery** — scan `devDependencies` for `@stonyx/*` packages
|
|
50
|
-
2. **Validation** — verify `stonyx-module` keyword exists
|
|
51
|
-
3. **Config merge** — async module defaults merged with user config
|
|
52
|
-
4. **Log setup** — module-specific Chronicle log created if `logColor` is set
|
|
53
|
-
5. **Instantiation** — module class is `new`'d
|
|
54
|
-
6. **Initialization** — `init()` called (async modules only)
|
|
55
|
-
7. **Startup hooks** — `startup()` called after all modules init (see [Lifecycle](lifecycle.md))
|
|
56
|
-
8. **Shutdown hooks** — `shutdown()` called on process exit (see [Lifecycle](lifecycle.md))
|
|
57
|
-
|
|
58
|
-
## waitForModule
|
|
59
|
-
|
|
60
|
-
For submodule developers who need to ensure another async module is ready:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
import { waitForModule } from 'stonyx';
|
|
64
|
-
|
|
65
|
-
await waitForModule('rest-server'); // Waits for @stonyx/rest-server
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
> **Note:** `waitForModule` is only needed during submodule development or testing. End-user applications don't need it — the CLI ensures all modules are initialized before running your app.
|
|
69
|
-
|
|
70
|
-
## Official Modules
|
|
71
|
-
|
|
72
|
-
| Module | Description |
|
|
73
|
-
|--------|-------------|
|
|
74
|
-
| [@stonyx/cron](https://github.com/abofs/stonyx-cron) | Lightweight async job scheduling with min-heap |
|
|
75
|
-
| [@stonyx/rest-server](https://github.com/abofs/stonyx-rest-server) | Dynamic REST server with auto-route registration |
|
|
76
|
-
| [@stonyx/orm](https://github.com/abofs/stonyx-orm) | ORM with models, relationships, serializers, and optional REST integration |
|
|
77
|
-
|
|
78
|
-
See each module's repository for its specific documentation.
|
package/docs/testing.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# Testing
|
|
2
|
-
|
|
3
|
-
Stonyx includes built-in test infrastructure using [QUnit](https://qunitjs.com/).
|
|
4
|
-
|
|
5
|
-
## Running Tests
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
stonyx test # Runs test/**/*-test.js by default
|
|
9
|
-
stonyx test "test/unit/**/*.js" # Custom glob pattern
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
The test command:
|
|
13
|
-
1. Sets `NODE_ENV=test`
|
|
14
|
-
2. Bootstraps Stonyx via a `--require` setup file
|
|
15
|
-
3. Applies [test config overrides](configuration.md#test-environment-overrides)
|
|
16
|
-
4. Runs QUnit with the specified glob
|
|
17
|
-
|
|
18
|
-
## Test Config Overrides
|
|
19
|
-
|
|
20
|
-
Create `test/config/environment.js` to override configuration during tests:
|
|
21
|
-
|
|
22
|
-
```js
|
|
23
|
-
export default {
|
|
24
|
-
debug: false,
|
|
25
|
-
restServer: { port: 0 },
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
These are deep-merged into the main config. See [Configuration](configuration.md#test-environment-overrides).
|
|
30
|
-
|
|
31
|
-
## Integration Test Helper
|
|
32
|
-
|
|
33
|
-
For tests that need Stonyx fully initialized (e.g., testing modules with database connections):
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { setupIntegrationTests } from 'stonyx/test-helpers';
|
|
37
|
-
|
|
38
|
-
const { module, test } = QUnit;
|
|
39
|
-
|
|
40
|
-
module('My Integration Test', function(hooks) {
|
|
41
|
-
setupIntegrationTests(hooks);
|
|
42
|
-
|
|
43
|
-
test('can access modules', function(assert) {
|
|
44
|
-
// Stonyx is fully initialized here
|
|
45
|
-
assert.ok(true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
`setupIntegrationTests` adds a `before` hook that waits for `Stonyx.ready` to resolve.
|
|
51
|
-
|
|
52
|
-
## Test File Convention
|
|
53
|
-
|
|
54
|
-
Place tests under `test/` with the `-test.js` suffix:
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
test/
|
|
58
|
-
unit/
|
|
59
|
-
my-feature-test.js
|
|
60
|
-
cli/
|
|
61
|
-
serve-test.js
|
|
62
|
-
integration/
|
|
63
|
-
api-test.js
|
|
64
|
-
```
|
package/src/cli/help.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export default async function help({ args, builtInCommands, loadModuleCommands } = {}) {
|
|
2
|
-
console.log('\nUsage: stonyx <command> [...args]\n');
|
|
3
|
-
console.log('Commands:\n');
|
|
4
|
-
|
|
5
|
-
if (builtInCommands) {
|
|
6
|
-
for (const [name, { description }] of Object.entries(builtInCommands)) {
|
|
7
|
-
console.log(` ${name.padEnd(20)} ${description}`);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (loadModuleCommands) {
|
|
12
|
-
try {
|
|
13
|
-
const moduleCommands = await loadModuleCommands();
|
|
14
|
-
const entries = Object.entries(moduleCommands);
|
|
15
|
-
|
|
16
|
-
if (entries.length) {
|
|
17
|
-
console.log('\nModule commands:\n');
|
|
18
|
-
|
|
19
|
-
for (const [name, { description }] of entries) {
|
|
20
|
-
console.log(` ${name.padEnd(20)} ${description}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
} catch {
|
|
24
|
-
// Module commands not available (e.g., no project context)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
console.log('\nAliases: s=serve, t=test, n=new, h=help\n');
|
|
29
|
-
|
|
30
|
-
console.log('Project conventions:\n');
|
|
31
|
-
console.log(' Entry point: app.js');
|
|
32
|
-
console.log(' Config: config/environment.js');
|
|
33
|
-
console.log(' DB schema: config/db-schema.js');
|
|
34
|
-
console.log(' Models: models/');
|
|
35
|
-
console.log(' Serializers: serializers/');
|
|
36
|
-
console.log(' Access control: access/');
|
|
37
|
-
console.log(' Transforms: transforms/');
|
|
38
|
-
console.log(' Hooks: hooks/');
|
|
39
|
-
console.log(' REST requests: requests/');
|
|
40
|
-
console.log(' Cron jobs: crons/');
|
|
41
|
-
console.log(' Tests: test/{unit,integration,acceptance}/');
|
|
42
|
-
console.log('');
|
|
43
|
-
console.log(' Logging: import log from \'stonyx/log\' (never console.log)');
|
|
44
|
-
console.log(' Utilities: import from \'@stonyx/utils/*\' (never raw fs)');
|
|
45
|
-
console.log(' Lint config: import from \'@abofs/code-conventions\'');
|
|
46
|
-
console.log(' Package manager: pnpm');
|
|
47
|
-
console.log('');
|
|
48
|
-
}
|