retold-data-service 2.0.12 → 2.0.13
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 +64 -55
- package/docs/README.md +24 -66
- package/docs/_cover.md +7 -7
- package/docs/_sidebar.md +24 -11
- package/docs/_topbar.md +2 -0
- package/docs/api/constructor.md +67 -0
- package/docs/api/initializeDataEndpoints.md +54 -0
- package/docs/api/initializePersistenceEngine.md +34 -0
- package/docs/api/initializeService.md +44 -0
- package/docs/api/onAfterInitialize.md +48 -0
- package/docs/api/onBeforeInitialize.md +45 -0
- package/docs/api/onInitialize.md +38 -0
- package/docs/api/reference.md +35 -0
- package/docs/api/stopService.md +34 -0
- package/docs/architecture.md +78 -14
- package/docs/behavior-injection.md +121 -78
- package/docs/css/docuserve.css +73 -0
- package/docs/dal-access.md +135 -56
- package/docs/index.html +1 -1
- package/docs/quick-start.md +169 -0
- package/docs/retold-catalog.json +144 -0
- package/docs/retold-keyword-index.json +3530 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
# Retold Data Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
> An all-in-one Fable service that turns a compiled Stricture schema into a complete REST API
|
|
4
6
|
|
|
5
7
|
Retold Data Service combines Meadow (data access), Orator (API server), and Meadow Endpoints (REST routes) into a single service provider. Point it at a compiled Stricture model and it auto-generates typed CRUD endpoints for every entity -- complete with filtering, pagination, soft deletes, and behavior injection hooks.
|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
|
-
- **Zero-Boilerplate REST**
|
|
10
|
-
- **Provider-Agnostic**
|
|
11
|
-
- **Schema-Driven**
|
|
12
|
-
- **Lifecycle Hooks**
|
|
13
|
-
- **Behavior Injection**
|
|
14
|
-
- **DAL Access**
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
11
|
+
- **Zero-Boilerplate REST** -- define your schema once, get full CRUD endpoints for every entity automatically
|
|
12
|
+
- **Provider-Agnostic** -- swap between MySQL, MSSQL, PostgreSQL, SQLite, MongoDB, DGraph, Solr, or ALASQL without changing application code
|
|
13
|
+
- **Schema-Driven** -- Stricture DDL compiles into a model that drives endpoint generation, validation, and defaults
|
|
14
|
+
- **Lifecycle Hooks** -- `onBeforeInitialize`, `onInitialize`, and `onAfterInitialize` for custom startup logic
|
|
15
|
+
- **Behavior Injection** -- pre- and post-operation hooks on every CRUD operation for custom business logic
|
|
16
|
+
- **DAL Access** -- direct programmatic data access alongside the REST endpoints for server-side logic
|
|
17
|
+
- **Backplane Endpoints** -- dynamic model loading, provider switching, and settings management at runtime
|
|
18
|
+
- **Fable Service Provider** -- first-class service in the Fable ecosystem with logging, configuration, and DI
|
|
19
|
+
- **Double-Init Protection** -- guards against accidental re-initialization
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install retold-data-service
|
|
25
|
+
```
|
|
17
26
|
|
|
18
27
|
## Quick Start
|
|
19
28
|
|
|
@@ -21,27 +30,30 @@ Retold Data Service combines Meadow (data access), Orator (API server), and Mead
|
|
|
21
30
|
const libFable = require('fable');
|
|
22
31
|
const libRetoldDataService = require('retold-data-service');
|
|
23
32
|
|
|
24
|
-
const _Fable = new libFable(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
33
|
+
const _Fable = new libFable(
|
|
34
|
+
{
|
|
35
|
+
APIServerPort: 8086,
|
|
36
|
+
MySQL:
|
|
37
|
+
{
|
|
38
|
+
Server: '127.0.0.1',
|
|
39
|
+
Port: 3306,
|
|
40
|
+
User: 'root',
|
|
41
|
+
Password: 'secret',
|
|
42
|
+
Database: 'bookstore',
|
|
43
|
+
ConnectionPoolLimit: 20
|
|
44
|
+
},
|
|
45
|
+
MeadowConnectionMySQLAutoConnect: true
|
|
46
|
+
});
|
|
36
47
|
|
|
37
48
|
_Fable.serviceManager.addServiceType('RetoldDataService', libRetoldDataService);
|
|
38
49
|
|
|
39
|
-
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
51
|
+
{
|
|
52
|
+
StorageProvider: 'MySQL',
|
|
53
|
+
StorageProviderModule: 'meadow-connection-mysql',
|
|
54
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
55
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
56
|
+
});
|
|
45
57
|
|
|
46
58
|
_Fable.RetoldDataService.initializeService(
|
|
47
59
|
(pError) =>
|
|
@@ -54,13 +66,7 @@ _Fable.RetoldDataService.initializeService(
|
|
|
54
66
|
});
|
|
55
67
|
```
|
|
56
68
|
|
|
57
|
-
##
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
npm install retold-data-service
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## How It Works
|
|
69
|
+
## Architecture
|
|
64
70
|
|
|
65
71
|
Retold Data Service orchestrates the full Meadow stack into a single initialization sequence:
|
|
66
72
|
|
|
@@ -72,7 +78,7 @@ Fable (Core)
|
|
|
72
78
|
├── Meadow (Data Access Layer)
|
|
73
79
|
│ ├── Schema (from compiled Stricture model)
|
|
74
80
|
│ ├── FoxHound (Query DSL)
|
|
75
|
-
│ └── Provider (MySQL / MSSQL / SQLite /
|
|
81
|
+
│ └── Provider (MySQL / MSSQL / PostgreSQL / SQLite / MongoDB / etc.)
|
|
76
82
|
└── Meadow Endpoints (REST Routes)
|
|
77
83
|
├── Create POST /1.0/Entity
|
|
78
84
|
├── Read GET /1.0/Entity/:ID
|
|
@@ -93,19 +99,22 @@ Fable (Core)
|
|
|
93
99
|
| `FullMeadowSchemaPath` | `process.cwd() + '/model/'` | Path to the compiled schema |
|
|
94
100
|
| `FullMeadowSchemaFilename` | `'MeadowModel-Extended.json'` | Compiled model filename |
|
|
95
101
|
| `AutoStartOrator` | `true` | Start the HTTP server automatically |
|
|
96
|
-
| `
|
|
102
|
+
| `AutoInitializeDataService` | `true` | Auto-initialize on construction |
|
|
97
103
|
|
|
98
104
|
## SQLite Example
|
|
99
105
|
|
|
100
106
|
For embedded or test scenarios, use the in-memory SQLite provider:
|
|
101
107
|
|
|
102
108
|
```javascript
|
|
109
|
+
const libFable = require('fable');
|
|
110
|
+
const libRetoldDataService = require('retold-data-service');
|
|
103
111
|
const libMeadowConnectionSQLite = require('meadow-connection-sqlite');
|
|
104
112
|
|
|
105
|
-
const _Fable = new libFable(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
113
|
+
const _Fable = new libFable(
|
|
114
|
+
{
|
|
115
|
+
APIServerPort: 8086,
|
|
116
|
+
SQLite: { SQLiteFilePath: ':memory:' }
|
|
117
|
+
});
|
|
109
118
|
|
|
110
119
|
_Fable.serviceManager.addServiceType('RetoldDataService', libRetoldDataService);
|
|
111
120
|
_Fable.serviceManager.addServiceType('MeadowSQLiteProvider', libMeadowConnectionSQLite);
|
|
@@ -114,12 +123,13 @@ _Fable.serviceManager.instantiateServiceProvider('MeadowSQLiteProvider');
|
|
|
114
123
|
_Fable.MeadowSQLiteProvider.connectAsync(
|
|
115
124
|
(pError) =>
|
|
116
125
|
{
|
|
117
|
-
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
127
|
+
{
|
|
128
|
+
StorageProvider: 'SQLite',
|
|
129
|
+
StorageProviderModule: 'meadow-connection-sqlite',
|
|
130
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
131
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
132
|
+
});
|
|
123
133
|
|
|
124
134
|
_Fable.RetoldDataService.initializeService(
|
|
125
135
|
(pError) =>
|
|
@@ -185,7 +195,7 @@ _Fable.DAL.Book.doReads(tmpQuery,
|
|
|
185
195
|
|
|
186
196
|
## Backplane Endpoints
|
|
187
197
|
|
|
188
|
-
For dynamic model loading
|
|
198
|
+
For dynamic model loading and provider management at runtime:
|
|
189
199
|
|
|
190
200
|
| Endpoint | Method | Description |
|
|
191
201
|
|----------|--------|-------------|
|
|
@@ -216,15 +226,14 @@ npx docsify-cli serve docs
|
|
|
216
226
|
|
|
217
227
|
## Related Packages
|
|
218
228
|
|
|
219
|
-
- [meadow](https://github.com/stevenvelozo/meadow)
|
|
220
|
-
- [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints)
|
|
221
|
-
- [
|
|
222
|
-
- [
|
|
229
|
+
- [meadow](https://github.com/stevenvelozo/meadow) -- data access and ORM
|
|
230
|
+
- [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) -- auto-generated REST endpoints
|
|
231
|
+
- [foxhound](https://github.com/stevenvelozo/foxhound) -- query DSL for SQL generation
|
|
232
|
+
- [stricture](https://github.com/stevenvelozo/stricture) -- schema definition DDL compiler
|
|
233
|
+
- [orator](https://github.com/stevenvelozo/orator) -- API server abstraction
|
|
234
|
+
- [fable](https://github.com/stevenvelozo/fable) -- application services framework
|
|
235
|
+
- [retold-harness](https://github.com/stevenvelozo/retold-harness) -- application harness using this service
|
|
223
236
|
|
|
224
237
|
## License
|
|
225
238
|
|
|
226
239
|
MIT
|
|
227
|
-
|
|
228
|
-
## Contributing
|
|
229
|
-
|
|
230
|
-
Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the [Retold Contributing Guide](https://github.com/stevenvelozo/retold/blob/main/docs/contributing.md).
|
package/docs/README.md
CHANGED
|
@@ -1,76 +1,34 @@
|
|
|
1
1
|
# Retold Data Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An all-in-one Fable service that turns a compiled Stricture schema into a complete REST API. Combines Meadow (data access), Orator (API server), and Meadow Endpoints (REST routes) into a single service provider with lifecycle hooks and behavior injection.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- **Schema-Driven** — load a compiled Stricture model and get full CRUD endpoints for every table automatically
|
|
8
|
-
- **Pluggable Storage** — configure any Meadow-compatible provider (MySQL, SQLite, MSSQL, ALASQL) via options
|
|
9
|
-
- **Fable Service** — extends `fable-serviceproviderbase`, integrating with the Fable ecosystem for logging, configuration, and service management
|
|
10
|
-
- **Lifecycle Hooks** — override `onBeforeInitialize`, `onInitialize`, and `onAfterInitialize` for custom startup logic
|
|
11
|
-
- **Behavior Injection** — add pre- and post-operation hooks to any CRUD endpoint
|
|
12
|
-
- **DAL Access** — query your data directly through `fable.DAL.<Entity>` for programmatic access alongside the REST API
|
|
13
|
-
- **Auto-Start** — optionally start the Orator web server automatically on initialization
|
|
14
|
-
|
|
15
|
-
## Quick Start
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
const libFable = require('fable');
|
|
19
|
-
const libRetoldDataService = require('retold-data-service');
|
|
20
|
-
|
|
21
|
-
const _Fable = new libFable({
|
|
22
|
-
Product: 'MyApp',
|
|
23
|
-
APIServerPort: 8086,
|
|
24
|
-
MySQL: {
|
|
25
|
-
Server: '127.0.0.1',
|
|
26
|
-
Port: 3306,
|
|
27
|
-
User: 'root',
|
|
28
|
-
Password: 'secret',
|
|
29
|
-
Database: 'mydb',
|
|
30
|
-
ConnectionPoolLimit: 20
|
|
31
|
-
},
|
|
32
|
-
MeadowConnectionMySQLAutoConnect: true
|
|
33
|
-
});
|
|
5
|
+
## What It Does
|
|
34
6
|
|
|
35
|
-
|
|
36
|
-
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService', {
|
|
37
|
-
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
38
|
-
FullMeadowSchemaFilename: 'MeadowModel-Extended.json',
|
|
39
|
-
StorageProvider: 'MySQL',
|
|
40
|
-
StorageProviderModule: 'meadow-connection-mysql',
|
|
41
|
-
AutoStartOrator: true
|
|
42
|
-
});
|
|
7
|
+
Retold Data Service orchestrates several Retold modules into a unified service:
|
|
43
8
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
```
|
|
9
|
+
- **[Meadow](https://github.com/stevenvelozo/meadow)** provides the data access layer and ORM
|
|
10
|
+
- **[Meadow Endpoints](https://github.com/stevenvelozo/meadow-endpoints)** generates REST routes for every entity
|
|
11
|
+
- **[Orator](https://github.com/stevenvelozo/orator)** serves the HTTP API via Restify
|
|
12
|
+
- **[FoxHound](https://github.com/stevenvelozo/foxhound)** builds SQL queries from a declarative DSL
|
|
13
|
+
- **[Stricture](https://github.com/stevenvelozo/stricture)** compiles schema definitions into the model
|
|
51
14
|
|
|
52
|
-
##
|
|
15
|
+
## Features
|
|
53
16
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
17
|
+
- **Zero-Boilerplate REST** -- Define your schema once, get full CRUD endpoints for every entity automatically
|
|
18
|
+
- **Provider-Agnostic** -- Swap between MySQL, MSSQL, PostgreSQL, SQLite, MongoDB, DGraph, Solr, or ALASQL
|
|
19
|
+
- **Schema-Driven** -- Stricture DDL compiles into a model that drives endpoint generation, validation, and defaults
|
|
20
|
+
- **Lifecycle Hooks** -- `onBeforeInitialize`, `onInitialize`, and `onAfterInitialize` for custom startup logic
|
|
21
|
+
- **Behavior Injection** -- Pre- and post-operation hooks on every CRUD operation
|
|
22
|
+
- **DAL Access** -- Direct programmatic data access alongside the REST endpoints
|
|
23
|
+
- **Backplane Endpoints** -- Dynamic model loading and provider switching at runtime
|
|
24
|
+
- **Fable Service Provider** -- First-class service with logging, configuration, and DI
|
|
57
25
|
|
|
58
26
|
## Related Packages
|
|
59
27
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
| [stricture](https://github.com/stevenvelozo/stricture) | Schema definition DDL compiler |
|
|
68
|
-
| [retold-harness](https://github.com/stevenvelozo/retold-harness) | Application harness using Retold Data Service |
|
|
69
|
-
|
|
70
|
-
## Testing
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
npm test
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Tests run against an in-memory SQLite database and require no external services.
|
|
28
|
+
- [meadow](https://github.com/stevenvelozo/meadow) -- Data access layer and ORM
|
|
29
|
+
- [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) -- REST endpoint generation
|
|
30
|
+
- [foxhound](https://github.com/stevenvelozo/foxhound) -- Query DSL for SQL generation
|
|
31
|
+
- [stricture](https://github.com/stevenvelozo/stricture) -- Schema definition DDL compiler
|
|
32
|
+
- [orator](https://github.com/stevenvelozo/orator) -- API server abstraction
|
|
33
|
+
- [fable](https://github.com/stevenvelozo/fable) -- Application services framework
|
|
34
|
+
- [retold-harness](https://github.com/stevenvelozo/retold-harness) -- Application harness using this service
|
package/docs/_cover.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Retold Data Service <small>
|
|
1
|
+
# Retold Data Service <small>v2.0.11</small>
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Schema-driven REST API generation for the Retold ecosystem
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
5
|
+
- Zero-boilerplate CRUD endpoints from Stricture DDL models
|
|
6
|
+
- Pluggable storage providers across SQL and NoSQL engines
|
|
7
|
+
- Lifecycle hooks and behavior injection for custom logic
|
|
8
|
+
- Direct DAL access for server-side data operations
|
|
9
9
|
|
|
10
|
+
[Getting Started](#retold-data-service)
|
|
10
11
|
[GitHub](https://github.com/stevenvelozo/retold-data-service)
|
|
11
|
-
[Get Started](#retold-data-service)
|
package/docs/_sidebar.md
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
- Getting Started
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
- [Overview](/)
|
|
3
|
+
- [Quick Start](quick-start.md)
|
|
4
|
+
- [Configuration](configuration.md)
|
|
5
|
+
|
|
6
|
+
- Architecture
|
|
7
|
+
- [System Design](architecture.md)
|
|
8
|
+
- [Initialization](initialization.md)
|
|
9
|
+
- [Schema Definition](schema-definition.md)
|
|
10
|
+
|
|
5
11
|
- Usage
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
- [REST Endpoints](endpoints.md)
|
|
13
|
+
- [DAL Access](dal-access.md)
|
|
14
|
+
- [Behavior Injection](behavior-injection.md)
|
|
15
|
+
- [Lifecycle Hooks](lifecycle-hooks.md)
|
|
16
|
+
|
|
17
|
+
- API Reference
|
|
18
|
+
- [Overview](api/reference.md)
|
|
19
|
+
- [constructor](api/constructor.md)
|
|
20
|
+
- [initializeService](api/initializeService.md)
|
|
21
|
+
- [stopService](api/stopService.md)
|
|
22
|
+
- [initializePersistenceEngine](api/initializePersistenceEngine.md)
|
|
23
|
+
- [initializeDataEndpoints](api/initializeDataEndpoints.md)
|
|
24
|
+
- [onBeforeInitialize](api/onBeforeInitialize.md)
|
|
25
|
+
- [onInitialize](api/onInitialize.md)
|
|
26
|
+
- [onAfterInitialize](api/onAfterInitialize.md)
|
package/docs/_topbar.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# constructor
|
|
2
|
+
|
|
3
|
+
Create a new RetoldDataService instance with merged default and custom options.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`constructor(pFable, pOptions, pServiceHash)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `pFable` | Fable | The Fable application instance |
|
|
14
|
+
| `pOptions` | Object | Service configuration options |
|
|
15
|
+
| `pServiceHash` | String | Optional service hash identifier |
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
| Option | Type | Default | Description |
|
|
20
|
+
|--------|------|---------|-------------|
|
|
21
|
+
| `StorageProvider` | String | `'MySQL'` | Meadow provider name |
|
|
22
|
+
| `StorageProviderModule` | String | `'meadow-connection-mysql'` | npm module for the provider |
|
|
23
|
+
| `FullMeadowSchemaPath` | String | `process.cwd() + '/model/'` | Path to compiled schema |
|
|
24
|
+
| `FullMeadowSchemaFilename` | String | `'MeadowModel-Extended.json'` | Schema filename |
|
|
25
|
+
| `AutoInitializeDataService` | Boolean | `true` | Auto-initialize on construction |
|
|
26
|
+
| `AutoStartOrator` | Boolean | `true` | Start Orator web server during init |
|
|
27
|
+
|
|
28
|
+
## What Happens
|
|
29
|
+
|
|
30
|
+
1. Merges default options with provided `pOptions`
|
|
31
|
+
2. Registers `OratorServiceServer` (Restify) as a Fable service
|
|
32
|
+
3. Registers `Orator` as a Fable service
|
|
33
|
+
4. Creates an internal Meadow instance
|
|
34
|
+
5. Creates empty `_DAL` and `_MeadowEndpoints` maps
|
|
35
|
+
6. Decorates `fable.DAL` and `fable.MeadowEndpoints` with these maps
|
|
36
|
+
7. Sets `serviceInitialized = false`
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const libFable = require('fable');
|
|
42
|
+
const libRetoldDataService = require('retold-data-service');
|
|
43
|
+
|
|
44
|
+
const _Fable = new libFable(
|
|
45
|
+
{
|
|
46
|
+
APIServerPort: 8086,
|
|
47
|
+
MySQL:
|
|
48
|
+
{
|
|
49
|
+
Server: '127.0.0.1',
|
|
50
|
+
Port: 3306,
|
|
51
|
+
User: 'root',
|
|
52
|
+
Password: 'secret',
|
|
53
|
+
Database: 'bookstore',
|
|
54
|
+
ConnectionPoolLimit: 20
|
|
55
|
+
},
|
|
56
|
+
MeadowConnectionMySQLAutoConnect: true
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
_Fable.serviceManager.addServiceType('RetoldDataService', libRetoldDataService);
|
|
60
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService',
|
|
61
|
+
{
|
|
62
|
+
StorageProvider: 'MySQL',
|
|
63
|
+
StorageProviderModule: 'meadow-connection-mysql',
|
|
64
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
65
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
66
|
+
});
|
|
67
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# initializeDataEndpoints
|
|
2
|
+
|
|
3
|
+
Core initialization step that loads the compiled Stricture model and creates a Meadow DAL and MeadowEndpoints controller for every entity.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`initializeDataEndpoints(fCallback)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `fCallback` | Function | Callback `(pError)` when all endpoints are created |
|
|
14
|
+
|
|
15
|
+
## Behavior
|
|
16
|
+
|
|
17
|
+
1. Loads the compiled Stricture schema from `options.FullMeadowSchemaPath` + `options.FullMeadowSchemaFilename`
|
|
18
|
+
2. Extracts the entity list from `fullModel.Tables`
|
|
19
|
+
3. For each entity:
|
|
20
|
+
- Creates a Meadow DAL from the table's `MeadowSchema` property via `loadFromPackageObject()`
|
|
21
|
+
- Sets the DAL's storage provider to `options.StorageProvider`
|
|
22
|
+
- Creates a MeadowEndpoints controller wrapping the DAL
|
|
23
|
+
- Connects routes to the Orator service server via `connectRoutes()`
|
|
24
|
+
4. Stores all DALs in `this._DAL` (also accessible via `fable.DAL`)
|
|
25
|
+
5. Stores all endpoint controllers in `this._MeadowEndpoints` (also accessible via `fable.MeadowEndpoints`)
|
|
26
|
+
|
|
27
|
+
## After Initialization
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
// Access DAL for any entity
|
|
31
|
+
let tmpBookDAL = _Fable.DAL.Book;
|
|
32
|
+
|
|
33
|
+
// Access endpoints controller for any entity
|
|
34
|
+
let tmpBookEndpoints = _Fable.MeadowEndpoints.Book;
|
|
35
|
+
|
|
36
|
+
// List all entities
|
|
37
|
+
console.log(_Fable.RetoldDataService.entityList);
|
|
38
|
+
// ['Book', 'Author', 'BookAuthorJoin', ...]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Generated Endpoints Per Entity
|
|
42
|
+
|
|
43
|
+
For each entity (e.g. `Book`), these routes are connected:
|
|
44
|
+
|
|
45
|
+
| Method | URL | Operation |
|
|
46
|
+
|--------|-----|-----------|
|
|
47
|
+
| GET | `/1.0/Book/:ID` | Read single record |
|
|
48
|
+
| GET | `/1.0/Books/:Begin/:Cap` | Read multiple records |
|
|
49
|
+
| POST | `/1.0/Book` | Create record |
|
|
50
|
+
| PUT | `/1.0/Book` | Update record |
|
|
51
|
+
| DELETE | `/1.0/Book/:ID` | Soft-delete record |
|
|
52
|
+
| GET | `/1.0/Books/Count` | Count records |
|
|
53
|
+
| GET | `/1.0/Book/Schema` | Get entity schema |
|
|
54
|
+
| GET | `/1.0/Book/Schema/New` | Get default record |
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# initializePersistenceEngine
|
|
2
|
+
|
|
3
|
+
Dynamically loads and instantiates the configured storage provider module.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`initializePersistenceEngine(fCallback)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `fCallback` | Function | Callback `(pError)` when the provider is loaded |
|
|
14
|
+
|
|
15
|
+
## Behavior
|
|
16
|
+
|
|
17
|
+
Calls `fable.serviceManager.addAndInstantiateServiceType()` with:
|
|
18
|
+
- Service name: `Meadow{StorageProvider}Provider` (e.g. `MeadowMySQLProvider`)
|
|
19
|
+
- Module: `require(this.options.StorageProviderModule)`
|
|
20
|
+
|
|
21
|
+
This is called automatically during `initializeService()`. You typically do not call this directly.
|
|
22
|
+
|
|
23
|
+
## Supported Providers
|
|
24
|
+
|
|
25
|
+
| StorageProvider | StorageProviderModule | Fable Service Name |
|
|
26
|
+
|----------------|----------------------|-------------------|
|
|
27
|
+
| `MySQL` | `meadow-connection-mysql` | `MeadowMySQLProvider` |
|
|
28
|
+
| `SQLite` | `meadow-connection-sqlite` | `MeadowSQLiteProvider` |
|
|
29
|
+
| `MSSQL` | `meadow-connection-mssql` | `MeadowMSSQLProvider` |
|
|
30
|
+
| `PostgreSQL` | `meadow-connection-postgresql` | `MeadowPostgreSQLProvider` |
|
|
31
|
+
| `MongoDB` | `meadow-connection-mongodb` | `MeadowMongoDBProvider` |
|
|
32
|
+
| `DGraph` | `meadow-connection-dgraph` | `MeadowDGraphProvider` |
|
|
33
|
+
| `Solr` | `meadow-connection-solr` | `MeadowSolrProvider` |
|
|
34
|
+
| `ALASQL` | `meadow-connection-alasql` | `MeadowALASQLProvider` |
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# initializeService
|
|
2
|
+
|
|
3
|
+
Main entry point for initializing the full service stack. Chains all lifecycle steps via Fable's Anticipate pattern.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`initializeService(fCallback)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `fCallback` | Function | Callback `(pError)` when initialization completes |
|
|
14
|
+
|
|
15
|
+
## Initialization Sequence
|
|
16
|
+
|
|
17
|
+
1. Check for double-initialization (returns error if already initialized)
|
|
18
|
+
2. `onBeforeInitialize()` -- custom pre-init hook
|
|
19
|
+
3. Start Orator web server (if `AutoStartOrator` is `true`)
|
|
20
|
+
4. `initializePersistenceEngine()` -- load storage provider
|
|
21
|
+
5. `onInitialize()` -- custom mid-init hook
|
|
22
|
+
6. `initializeDataEndpoints()` -- load model, create DALs and endpoints
|
|
23
|
+
7. `onAfterInitialize()` -- custom post-init hook
|
|
24
|
+
8. Set `serviceInitialized = true`
|
|
25
|
+
|
|
26
|
+
## Error Handling
|
|
27
|
+
|
|
28
|
+
- If already initialized, calls back with `Error("...already been initialized...")`
|
|
29
|
+
- If any step in the chain fails, the error propagates to `fCallback`
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
_Fable.RetoldDataService.initializeService(
|
|
35
|
+
(pError) =>
|
|
36
|
+
{
|
|
37
|
+
if (pError)
|
|
38
|
+
{
|
|
39
|
+
console.error('Initialization failed:', pError);
|
|
40
|
+
return process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
console.log('REST API running on port', _Fable.settings.APIServerPort);
|
|
43
|
+
});
|
|
44
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# onAfterInitialize
|
|
2
|
+
|
|
3
|
+
Lifecycle hook called after all data endpoints are created and routes are connected.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`onAfterInitialize(fCallback)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `fCallback` | Function | Callback `(pError)` to continue the initialization chain |
|
|
14
|
+
|
|
15
|
+
## Default Behavior
|
|
16
|
+
|
|
17
|
+
No-op -- calls `fCallback()` immediately.
|
|
18
|
+
|
|
19
|
+
## Override
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
class MyDataService extends require('retold-data-service')
|
|
23
|
+
{
|
|
24
|
+
onAfterInitialize(fCallback)
|
|
25
|
+
{
|
|
26
|
+
this.fable.log.info('Injecting custom behaviors...');
|
|
27
|
+
|
|
28
|
+
this.fable.MeadowEndpoints.Book.controller.BehaviorInjection.setBehavior(
|
|
29
|
+
'Read-PostOperation',
|
|
30
|
+
(pRequest, pRequestState, fRequestComplete) =>
|
|
31
|
+
{
|
|
32
|
+
// Enrich book records with author data
|
|
33
|
+
pRequestState.Record.CustomField = 'injected';
|
|
34
|
+
return fRequestComplete(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return fCallback();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Use Cases
|
|
43
|
+
|
|
44
|
+
- Behavior injection on entity endpoints
|
|
45
|
+
- Cache warming
|
|
46
|
+
- Background task scheduling
|
|
47
|
+
- Custom endpoint registration after entity routes
|
|
48
|
+
- Seed data verification
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# onBeforeInitialize
|
|
2
|
+
|
|
3
|
+
Lifecycle hook called before Orator starts and before the persistence engine loads.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
`onBeforeInitialize(fCallback)`
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
| Parameter | Type | Description |
|
|
12
|
+
|-----------|------|-------------|
|
|
13
|
+
| `fCallback` | Function | Callback `(pError)` to continue the initialization chain |
|
|
14
|
+
|
|
15
|
+
## Default Behavior
|
|
16
|
+
|
|
17
|
+
No-op -- calls `fCallback()` immediately.
|
|
18
|
+
|
|
19
|
+
## Override
|
|
20
|
+
|
|
21
|
+
Subclass `RetoldDataService` to add custom pre-initialization logic:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
class MyDataService extends require('retold-data-service')
|
|
25
|
+
{
|
|
26
|
+
onBeforeInitialize(fCallback)
|
|
27
|
+
{
|
|
28
|
+
this.fable.log.info('Validating environment...');
|
|
29
|
+
|
|
30
|
+
if (!process.env.DATABASE_URL)
|
|
31
|
+
{
|
|
32
|
+
return fCallback(new Error('DATABASE_URL is required'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return fCallback();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Use Cases
|
|
41
|
+
|
|
42
|
+
- Environment validation
|
|
43
|
+
- Early configuration overrides
|
|
44
|
+
- External service health checks
|
|
45
|
+
- Feature flag loading
|