meadow-endpoints 4.0.5 → 4.0.9
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/CONTRIBUTING.md +50 -0
- package/Dockerfile_LUXURYCode +1 -39
- package/README.md +172 -51
- package/dist/indoctrinate_content_staging/Indoctrinate-Catalog-AppData.json +4548 -0
- package/docs/README.md +326 -0
- package/docs/_sidebar.md +37 -0
- package/docs/crud/README.md +220 -0
- package/docs/crud/count.md +168 -0
- package/docs/crud/create.md +194 -0
- package/docs/crud/delete.md +237 -0
- package/docs/crud/read.md +324 -0
- package/docs/crud/schema.md +349 -0
- package/docs/crud/update.md +203 -0
- package/docs/css/docuserve.css +73 -0
- package/docs/index.html +39 -0
- package/docs/retold-catalog.json +177 -0
- package/docs/retold-keyword-index.json +6720 -0
- package/package.json +24 -19
- package/source/Meadow-Endpoints.js +8 -1
- package/source/controller/Meadow-Endpoints-Controller-Base.js +14 -7
- package/source/controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +4 -1
- package/source/controller/components/Meadow-Endpoints-Controller-Error.js +4 -1
- package/source/controller/components/Meadow-Endpoints-Controller-Log.js +4 -1
- package/source/controller/utility/Meadow-Endpoints-Filter-Parser.js +13 -204
- package/source/controller/utility/Meadow-Endpoints-Session-Marshaler.js +10 -6
- package/source/controller/utility/Meadow-Endpoints-Stream-RecordArray.js +5 -2
- package/source/endpoints/delete/Meadow-Endpoint-Undelete.js +2 -2
- package/source/endpoints/read/Meadow-Endpoint-ReadDistinctList.js +3 -1
- package/source/endpoints/read/Meadow-Endpoint-ReadLiteList.js +3 -1
- package/source/endpoints/read/Meadow-Endpoint-ReadSelectList.js +3 -1
- package/source/endpoints/read/Meadow-Endpoint-Reads.js +3 -1
- package/source/endpoints/read/Meadow-Endpoint-ReadsBy.js +3 -1
- package/source/endpoints/update/Meadow-Operation-Update.js +9 -1
- package/test/MeadowEndpoints_basic_tests.js +1580 -65
- package/tsconfig.json +13 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Contributing to Retold
|
|
2
|
+
|
|
3
|
+
We welcome contributions to Retold and its modules. This guide covers the expectations and process for contributing.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
The Retold community values **empathy**, **equity**, **kindness**, and **thoughtfulness**. We expect all participants to treat each other with respect, assume good intent, and engage constructively. These values apply to all interactions: pull requests, issues, discussions, and code review.
|
|
8
|
+
|
|
9
|
+
## How to Contribute
|
|
10
|
+
|
|
11
|
+
### Pull Requests
|
|
12
|
+
|
|
13
|
+
Pull requests are the preferred method for contributing changes. To submit one:
|
|
14
|
+
|
|
15
|
+
1. Fork the module repository you want to change
|
|
16
|
+
2. Create a branch for your work
|
|
17
|
+
3. Make your changes, following the code style of the module you are editing
|
|
18
|
+
4. Ensure your changes have test coverage (see below)
|
|
19
|
+
5. Open a pull request against the module's main branch
|
|
20
|
+
|
|
21
|
+
**Submitting a pull request does not guarantee it will be accepted.** Maintainers review contributions for fit, quality, and alignment with the project's direction. A PR may be declined, or you may be asked to revise it. This is normal and not a reflection on the quality of your effort.
|
|
22
|
+
|
|
23
|
+
### Reporting Issues
|
|
24
|
+
|
|
25
|
+
If you find a bug or have a feature suggestion, open an issue on the relevant module's repository. Include enough detail to reproduce the problem or understand the proposal.
|
|
26
|
+
|
|
27
|
+
## Test Coverage
|
|
28
|
+
|
|
29
|
+
Every commit must include test coverage for the changes it introduces. Retold modules use Mocha in TDD style. Before submitting:
|
|
30
|
+
|
|
31
|
+
- **Write tests** for any new functionality or bug fixes
|
|
32
|
+
- **Run the existing test suite** with `npm test` and confirm all tests pass
|
|
33
|
+
- **Check coverage** with `npm run coverage` if the module supports it
|
|
34
|
+
|
|
35
|
+
Pull requests that break existing tests or lack coverage for new code will not be merged.
|
|
36
|
+
|
|
37
|
+
## Code Style
|
|
38
|
+
|
|
39
|
+
Follow the conventions of the module you are working in. The general Retold style is:
|
|
40
|
+
|
|
41
|
+
- **Tabs** for indentation, never spaces
|
|
42
|
+
- **Plain JavaScript** only (no TypeScript)
|
|
43
|
+
- **Allman-style braces** (opening brace on its own line)
|
|
44
|
+
- **Variable naming:** `pVariable` for parameters, `tmpVariable` for temporaries, `libSomething` for imports
|
|
45
|
+
|
|
46
|
+
When in doubt, match what the surrounding code does.
|
|
47
|
+
|
|
48
|
+
## Repository Structure
|
|
49
|
+
|
|
50
|
+
Each module is its own git repository. The [retold](https://github.com/stevenvelozo/retold) repository tracks module organization but does not contain module source code. Direct your pull request to the specific module repository where your change belongs.
|
package/Dockerfile_LUXURYCode
CHANGED
|
@@ -16,44 +16,6 @@ RUN echo "Building RETOLD development image..."
|
|
|
16
16
|
RUN echo "...installing vscode extensions..."
|
|
17
17
|
|
|
18
18
|
# Mocha unit testing in the sidebar
|
|
19
|
-
RUN code-server --install-extension hbenl.vscode-mocha-test-adapter
|
|
20
|
-
RUN code-server --install-extension hbenl.test-adapter-converter
|
|
21
|
-
RUN code-server --install-extension hbenl.vscode-test-explorer
|
|
22
|
-
|
|
23
|
-
# Magic indentation rainbow
|
|
24
|
-
RUN code-server --install-extension oderwat.indent-rainbow
|
|
25
|
-
RUN code-server --install-extension dbaeumer.vscode-eslint
|
|
26
|
-
|
|
27
|
-
# Contextual git
|
|
28
|
-
RUN code-server --install-extension eamodio.gitlens
|
|
29
|
-
|
|
30
|
-
# Other extensions (uncomment them to have them automagic, or run this from a terminal to install in the container):
|
|
31
|
-
|
|
32
|
-
# SQL Tools
|
|
33
|
-
RUN code-server --install-extension mtxr.sqltools
|
|
34
|
-
RUN code-server --install-extension mtxr.sqltools-driver-mysql
|
|
35
|
-
|
|
36
|
-
# Microsoft's AI code completion
|
|
37
|
-
# RUN code-server --install-extension VisualStudioExptTeam.vscodeintellicode
|
|
38
|
-
|
|
39
|
-
# Live server -- make sure to open up the port on the docker image
|
|
40
|
-
# RUN code-server --install-extension ritwickdey.LiveServer
|
|
41
|
-
|
|
42
|
-
# Quick link to required modules' documentation
|
|
43
|
-
RUN code-server --install-extension bengreenier.vscode-node-readme
|
|
44
|
-
|
|
45
|
-
# Switch up fonts
|
|
46
|
-
# RUN code-server --install-extension evan-buss.font-switcher
|
|
47
|
-
|
|
48
|
-
# Icons
|
|
49
|
-
# RUN code-server --install-extension vscode-icons-team.vscode-icons
|
|
50
|
-
# RUN code-server --install-extension PKief.material-icon-theme
|
|
51
|
-
|
|
52
|
-
# Hover over CSS colors to see them previewed
|
|
53
|
-
# RUN code-server --install-extension bierner.color-info
|
|
54
|
-
|
|
55
|
-
# An easy on the eyes color theme
|
|
56
|
-
# RUN code-server --install-extension daylerees.rainglow
|
|
57
19
|
|
|
58
20
|
RUN echo "...configuring mariadb (mysql) server..."
|
|
59
21
|
RUN sudo sed -i "s|bind-address|#bind-address|g" /etc/mysql/mariadb.conf.d/50-server.cnf
|
|
@@ -87,4 +49,4 @@ RUN . ~/.nvm/nvm.sh && source ~/.bashrc && nvm alias default 14
|
|
|
87
49
|
|
|
88
50
|
WORKDIR /home/coder/meadow-endpoints
|
|
89
51
|
|
|
90
|
-
ENTRYPOINT ["/usr/bin/MySQL-Laden-Entry.sh"]
|
|
52
|
+
ENTRYPOINT ["/usr/bin/MySQL-Laden-Entry.sh"]
|
package/README.md
CHANGED
|
@@ -1,82 +1,203 @@
|
|
|
1
1
|
# Meadow Endpoints
|
|
2
2
|
|
|
3
|
-
Automagic REST endpoints for
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
> Automagic REST endpoints for CRUD operations on the Retold framework
|
|
4
|
+
|
|
5
|
+
Meadow Endpoints generates a full suite of RESTful API routes from your Meadow data entities. Define your data model with Meadow, point Meadow Endpoints at it, and you get Create, Read, Update, Delete, Count, Schema, and Validate endpoints -- with authentication hooks, authorization, dynamic filtering, pagination, and behavior injection for customization. The design philosophy is to cover the 99% via configuration; the last 1% is easily hand-craftable.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Automatic Route Generation** - Full CRUD endpoints from a Meadow entity with zero boilerplate
|
|
10
|
+
- **Behavior Injection** - Pre/post operation hooks for authentication, authorization, and custom logic
|
|
11
|
+
- **Dynamic Filtering** - URL-based filter expressions for flexible querying
|
|
12
|
+
- **Pagination** - Built-in Begin/Cap parameters with configurable default limits
|
|
13
|
+
- **Bulk Operations** - Batch create, update, and upsert endpoints
|
|
14
|
+
- **Schema Endpoints** - Serve JSON Schema, default objects, and validation
|
|
15
|
+
- **Controller Architecture** - Extensible controller system with replaceable error handling, logging, and session management
|
|
16
|
+
- **Fable Integration** - First-class service in the Fable/Orator ecosystem
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const libFable = require('fable');
|
|
22
|
+
const libOrator = require('orator');
|
|
23
|
+
const libOratorServiceServerRestify = require('orator-serviceserver-restify');
|
|
24
|
+
const libMeadow = require('meadow');
|
|
25
|
+
const libMeadowEndpoints = require('meadow-endpoints');
|
|
26
|
+
|
|
27
|
+
const _Fable = new libFable({
|
|
28
|
+
Product: 'MyAPI',
|
|
29
|
+
ProductVersion: '1.0.0',
|
|
30
|
+
ServicePort: 8086
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Set up Orator
|
|
34
|
+
_Fable.serviceManager.addServiceType('Orator', libOrator);
|
|
35
|
+
_Fable.serviceManager.addServiceType('OratorServiceServer', libOratorServiceServerRestify);
|
|
36
|
+
_Fable.serviceManager.instantiateServiceProvider('Orator');
|
|
37
|
+
_Fable.serviceManager.instantiateServiceProvider('OratorServiceServer');
|
|
38
|
+
|
|
39
|
+
// Create a Meadow DAL for "Book"
|
|
40
|
+
const tmpMeadow = libMeadow.new(_Fable, 'Book')
|
|
41
|
+
.setProvider('MySQL')
|
|
42
|
+
.setDefaultIdentifier('IDBook')
|
|
43
|
+
.setSchema([
|
|
44
|
+
{ Column: 'IDBook', Type: 'AutoIdentity' },
|
|
45
|
+
{ Column: 'GUIDBook', Type: 'AutoGUID' },
|
|
46
|
+
{ Column: 'Title', Type: 'String', Size: '255' },
|
|
47
|
+
{ Column: 'Author', Type: 'String', Size: '128' },
|
|
48
|
+
{ Column: 'CreateDate', Type: 'CreateDate' },
|
|
49
|
+
{ Column: 'CreatingIDUser', Type: 'CreateIDUser' },
|
|
50
|
+
{ Column: 'UpdateDate', Type: 'UpdateDate' },
|
|
51
|
+
{ Column: 'UpdatingIDUser', Type: 'UpdateIDUser' },
|
|
52
|
+
{ Column: 'Deleted', Type: 'Deleted' }
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
// Generate and connect endpoints
|
|
56
|
+
const tmpMeadowEndpoints = new libMeadowEndpoints(tmpMeadow);
|
|
57
|
+
tmpMeadowEndpoints.connectRoutes(_Fable.Orator.serviceServer);
|
|
58
|
+
|
|
59
|
+
// Start the server
|
|
60
|
+
_Fable.Orator.startService(() =>
|
|
61
|
+
{
|
|
62
|
+
console.log('API running on port 8086');
|
|
63
|
+
// GET /1.0/Book/:IDBook - Read one
|
|
64
|
+
// GET /1.0/Book/s/:Begin/:Cap - Read many
|
|
65
|
+
// POST /1.0/Book - Create
|
|
66
|
+
// PUT /1.0/Book - Update
|
|
67
|
+
// DELETE /1.0/Book/:IDBook - Delete
|
|
68
|
+
// GET /1.0/Book/s/Count - Count
|
|
69
|
+
// GET /1.0/Book/Schema - Schema
|
|
70
|
+
});
|
|
71
|
+
```
|
|
14
72
|
|
|
15
|
-
|
|
73
|
+
## Installation
|
|
16
74
|
|
|
75
|
+
```bash
|
|
76
|
+
npm install meadow-endpoints
|
|
77
|
+
```
|
|
17
78
|
|
|
18
|
-
|
|
79
|
+
## How It Works
|
|
19
80
|
|
|
20
|
-
|
|
81
|
+
Meadow Endpoints takes a configured Meadow DAL instance and registers HTTP routes with an Orator service server. Each route follows an async waterfall pattern with behavior injection points for customization.
|
|
21
82
|
|
|
22
83
|
```
|
|
23
|
-
|
|
84
|
+
Orator (API Server)
|
|
85
|
+
└── Meadow Endpoints (Route Registration)
|
|
86
|
+
├── Controller (Request Lifecycle)
|
|
87
|
+
│ ├── Session Marshaler
|
|
88
|
+
│ ├── Behavior Injection
|
|
89
|
+
│ ├── Error Handler
|
|
90
|
+
│ └── Log Controller
|
|
91
|
+
└── Meadow DAL (Data Access)
|
|
92
|
+
└── Database Provider
|
|
24
93
|
```
|
|
25
94
|
|
|
26
|
-
|
|
95
|
+
## Generated Routes
|
|
27
96
|
|
|
28
|
-
|
|
29
|
-
npm run docker-dev-run
|
|
30
|
-
```
|
|
97
|
+
### CRUD
|
|
31
98
|
|
|
32
|
-
|
|
99
|
+
| Method | Route | Description |
|
|
100
|
+
|--------|-------|-------------|
|
|
101
|
+
| POST | `/{ver}/{entity}` | Create a record |
|
|
102
|
+
| POST | `/{ver}/{entity}/s` | Bulk create |
|
|
103
|
+
| GET | `/{ver}/{entity}/:ID` | Read one record |
|
|
104
|
+
| GET | `/{ver}/{entity}/s/:Begin/:Cap` | Read many with pagination |
|
|
105
|
+
| GET | `/{ver}/{entity}/s/FilteredTo/:Filter` | Read with filter |
|
|
106
|
+
| PUT | `/{ver}/{entity}` | Update a record |
|
|
107
|
+
| PUT | `/{ver}/{entity}/Upsert` | Insert or update |
|
|
108
|
+
| DELETE | `/{ver}/{entity}/:ID` | Delete a record |
|
|
109
|
+
| GET | `/{ver}/{entity}/Undelete/:ID` | Undelete a record |
|
|
110
|
+
| GET | `/{ver}/{entity}/s/Count` | Count records |
|
|
33
111
|
|
|
34
|
-
|
|
112
|
+
### Specialized Read
|
|
35
113
|
|
|
36
|
-
|
|
114
|
+
| Method | Route | Description |
|
|
115
|
+
|--------|-------|-------------|
|
|
116
|
+
| GET | `/{ver}/{entity}/Select` | Select list ({Hash, Value} pairs) |
|
|
117
|
+
| GET | `/{ver}/{entity}/s/Lite` | Lite list (minimal columns) |
|
|
118
|
+
| GET | `/{ver}/{entity}/s/Distinct/:Columns` | Distinct values |
|
|
119
|
+
| GET | `/{ver}/{entity}/Max/:Column` | Maximum value |
|
|
37
120
|
|
|
121
|
+
### Schema
|
|
38
122
|
|
|
123
|
+
| Method | Route | Description |
|
|
124
|
+
|--------|-------|-------------|
|
|
125
|
+
| GET | `/{ver}/{entity}/Schema` | JSON Schema |
|
|
126
|
+
| GET | `/{ver}/{entity}/Schema/New` | Empty default record |
|
|
127
|
+
| POST | `/{ver}/{entity}/Schema/Validate` | Validate a record |
|
|
39
128
|
|
|
40
|
-
##
|
|
129
|
+
## Behavior Injection
|
|
41
130
|
|
|
42
|
-
|
|
43
|
-
const libMeadowEndpointsControllerBase = require('meadow-endpoints').ControllerBase;
|
|
131
|
+
Hook into any endpoint's lifecycle for authorization and custom logic:
|
|
44
132
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
constructor(pMeadowEndpoints, pOptions)
|
|
48
|
-
{
|
|
49
|
-
super(pMeadowEndpoints, pOptions);
|
|
50
|
-
}
|
|
133
|
+
```javascript
|
|
134
|
+
const tmpEndpoints = new libMeadowEndpoints(tmpMeadow);
|
|
51
135
|
|
|
52
|
-
|
|
53
|
-
|
|
136
|
+
// Add customer-scoped reads
|
|
137
|
+
tmpEndpoints.controller.BehaviorInjection.setBehavior('Reads-QueryConfiguration',
|
|
138
|
+
(pRequest, pRequestState, fCallback) =>
|
|
54
139
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
140
|
+
pRequestState.Query.addFilter('IDCustomer', pRequestState.SessionData.CustomerID);
|
|
141
|
+
return fCallback();
|
|
142
|
+
});
|
|
143
|
+
```
|
|
59
144
|
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
constructor(pMeadowEndpoints, pOptions)
|
|
63
|
-
{
|
|
64
|
-
super(pMeadowEndpoints, pOptions);
|
|
145
|
+
### Injection Points
|
|
65
146
|
|
|
66
|
-
|
|
147
|
+
| Point | Phase |
|
|
148
|
+
|-------|-------|
|
|
149
|
+
| `Create-PreOperation` / `Create-PostOperation` | Before/after creation |
|
|
150
|
+
| `Create-QueryConfiguration` | After query built, before execution |
|
|
151
|
+
| `Read-PreOperation` / `Read-PostOperation` | Before/after single read |
|
|
152
|
+
| `Reads-QueryConfiguration` / `Reads-PostOperation` | Multi-record reads |
|
|
153
|
+
| `Update-QueryConfiguration` | After update query built |
|
|
154
|
+
| `Delete-PreOperation` / `Delete-PostOperation` | Before/after deletion |
|
|
155
|
+
| `Count-QueryConfiguration` | After count query built |
|
|
67
156
|
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
157
|
+
## Dynamic Filtering
|
|
71
158
|
|
|
72
|
-
module.exports = MyMeadowEndpointsController;
|
|
73
159
|
```
|
|
160
|
+
GET /1.0/Book/s/FilteredTo/Title~JavaScript
|
|
161
|
+
GET /1.0/Book/s/FilteredTo/Author=Frank Herbert
|
|
162
|
+
GET /1.0/Book/s/FilteredTo/Price>20
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Operators: `=`, `!=`, `>`, `<`, `>=`, `<=`, `~` (contains)
|
|
166
|
+
|
|
167
|
+
## Configuration
|
|
74
168
|
|
|
169
|
+
| Setting | Type | Default | Description |
|
|
170
|
+
|---------|------|---------|-------------|
|
|
171
|
+
| `MeadowEndpointVersion` | string | `"1.0"` | API version prefix |
|
|
172
|
+
| `MeadowDefaultMaxCap` | number | `250` | Default pagination limit |
|
|
173
|
+
| `MeadowEndpointsSessionDataSource` | string | `"Request"` | Session data source (`Request`, `Header`, `None`) |
|
|
174
|
+
| `SendErrorStatusCodes` | boolean | `false` | Set HTTP status codes on errors |
|
|
175
|
+
|
|
176
|
+
## Testing
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npm test
|
|
75
180
|
```
|
|
76
|
-
let libMySpecialController = require('TheCodeAbove.js');
|
|
77
181
|
|
|
78
|
-
|
|
182
|
+
## Documentation
|
|
183
|
+
|
|
184
|
+
Detailed documentation is available in the `docs/` folder and can be served locally:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npx docsify-cli serve docs
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Related Packages
|
|
191
|
+
|
|
192
|
+
- [meadow](https://github.com/stevenvelozo/meadow) - Data access and ORM
|
|
193
|
+
- [foxhound](https://github.com/stevenvelozo/foxhound) - Query DSL for SQL generation
|
|
194
|
+
- [orator](https://github.com/stevenvelozo/orator) - API server abstraction
|
|
195
|
+
- [fable](https://github.com/stevenvelozo/fable) - Application services framework
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT
|
|
79
200
|
|
|
80
|
-
|
|
201
|
+
## Contributing
|
|
81
202
|
|
|
82
|
-
|
|
203
|
+
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).
|