@stonyx/orm 0.3.2-alpha.105 → 0.3.2-alpha.107
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 +52 -2
- package/dist/main.js +15 -5
- package/package.json +1 -1
- package/src/main.ts +15 -5
package/README.md
CHANGED
|
@@ -40,6 +40,12 @@ All properties prefixed with `__` (`__data`, `__relationships`, `__model`, `__se
|
|
|
40
40
|
npm install @stonyx/orm
|
|
41
41
|
````
|
|
42
42
|
|
|
43
|
+
That is the whole install for an ORM-only app. The database drivers and
|
|
44
|
+
`@stonyx/rest-server` are **optional peer dependencies**: a default install does
|
|
45
|
+
not put them on disk, and none of them is loaded unless your configuration asks
|
|
46
|
+
for it. Add only the ones you actually use — see
|
|
47
|
+
[Optional peer dependencies](#optional-peer-dependencies).
|
|
48
|
+
|
|
43
49
|
## Usage example
|
|
44
50
|
|
|
45
51
|
This module is part of the **Stonyx framework**. To use it, first configure the `restServer` key in your `environment.js` file:
|
|
@@ -106,7 +112,9 @@ export default {
|
|
|
106
112
|
tablePrefix: DYNAMODB_TABLE_PREFIX, // optional table name prefix
|
|
107
113
|
} : undefined,
|
|
108
114
|
restServer: {
|
|
109
|
-
|
|
115
|
+
// 'true' requires @stonyx/rest-server to be installed — see
|
|
116
|
+
// "Optional peer dependencies" below.
|
|
117
|
+
enabled: ORM_USE_REST_SERVER ?? 'false',
|
|
110
118
|
route: ORM_REST_ROUTE ?? '/'
|
|
111
119
|
}
|
|
112
120
|
}
|
|
@@ -127,6 +135,46 @@ stonyx serve
|
|
|
127
135
|
|
|
128
136
|
For further framework instructions, see the [Stonyx repository](https://github.com/abofs/stonyx).
|
|
129
137
|
|
|
138
|
+
## Optional peer dependencies
|
|
139
|
+
|
|
140
|
+
`@stonyx/orm` boots with **none** of its optional peers installed. Each one is
|
|
141
|
+
imported lazily, and only when your configuration selects it:
|
|
142
|
+
|
|
143
|
+
| Configuration | Package you must install |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `orm.restServer.enabled: 'true'` | `@stonyx/rest-server` |
|
|
146
|
+
| `orm.postgres` or `orm.timescale` | `pg` |
|
|
147
|
+
| `orm.mysql` | `mysql2` |
|
|
148
|
+
| `orm.dynamodb` | `@aws-sdk/client-dynamodb`, `@aws-sdk/lib-dynamodb` |
|
|
149
|
+
|
|
150
|
+
If a configuration key selects one that is not on disk, the failure surfaces
|
|
151
|
+
from `Orm.init()` while the framework boots:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
Cannot find package '@stonyx/rest-server' imported from .../@stonyx/orm/dist/orm-request.js
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**ORM-only, no REST server.** This is the shape the `environment.js` above is
|
|
158
|
+
written for: keep `orm.restServer.enabled` at `'false'` and install nothing
|
|
159
|
+
beyond `@stonyx/orm`. Models, relationships, serializers, transforms and hooks
|
|
160
|
+
work unchanged; only the generated REST routes are absent.
|
|
161
|
+
|
|
162
|
+
> **The module's own default is the other way round.** The `config/environment.js`
|
|
163
|
+
> that ships inside `@stonyx/orm` defaults `restServer.enabled` to `'true'`, so
|
|
164
|
+
> an app that omits the `restServer` key *entirely* gets REST switched on and
|
|
165
|
+
> needs `@stonyx/rest-server` installed. Set the key explicitly, whichever way
|
|
166
|
+
> you want it.
|
|
167
|
+
|
|
168
|
+
**Turning REST on.**
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
npm install @stonyx/rest-server
|
|
172
|
+
ORM_USE_REST_SERVER=true stonyx serve
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
See [REST Server Integration](#rest-server-integration) for access classes and
|
|
176
|
+
route configuration.
|
|
177
|
+
|
|
130
178
|
## Models
|
|
131
179
|
|
|
132
180
|
Define a model with attributes and relationships:
|
|
@@ -916,7 +964,9 @@ test('validation hook rejects negative age', async () => {
|
|
|
916
964
|
|
|
917
965
|
## Project Structure
|
|
918
966
|
|
|
919
|
-
For a full architectural reference, see
|
|
967
|
+
For a full architectural reference, see
|
|
968
|
+
[docs/project-structure.md](https://github.com/abofs/stonyx-orm/blob/dev/docs/project-structure.md).
|
|
969
|
+
That file is repo-only — it is not in the published tarball, so the link is absolute.
|
|
920
970
|
|
|
921
971
|
## License
|
|
922
972
|
|
package/dist/main.js
CHANGED
|
@@ -130,12 +130,22 @@ export default class Orm {
|
|
|
130
130
|
promises.push(db.init());
|
|
131
131
|
}
|
|
132
132
|
if (restServer.enabled === 'true') {
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
//
|
|
133
|
+
// MUST stay dynamic. setup-rest-server.js names the optional
|
|
134
|
+
// '@stonyx/rest-server' peer in its own static graph — directly, and
|
|
135
|
+
// through orm-request.ts / meta-request.ts, which import `Request` at
|
|
136
|
+
// module scope because they extend it (correctly: an `extends` base
|
|
137
|
+
// class cannot be awaited). Node links a module's entire static graph
|
|
138
|
+
// before evaluating any of it, so a static import here puts that
|
|
139
|
+
// specifier on the entry graph and `import('@stonyx/orm')` throws
|
|
137
140
|
// ERR_MODULE_NOT_FOUND for an ORM-only consumer that never installed the
|
|
138
|
-
// optional peer.
|
|
141
|
+
// optional peer.
|
|
142
|
+
//
|
|
143
|
+
// NOT the same reason the SQL/DynamoDB drivers above are lazy: those
|
|
144
|
+
// modules carry no static peer specifier at all, so the `await import()`
|
|
145
|
+
// there is not what isolates pg / mysql2 / @aws-sdk — that happens one
|
|
146
|
+
// layer down, in src/*/connection.ts (and src/dynamodb/dynamodb-db.ts).
|
|
147
|
+
// setup-rest-server.js is the only dist module whose laziness is
|
|
148
|
+
// load-bearing for peer resolution. (#280)
|
|
139
149
|
const { default: setupRestServer } = await import('./setup-rest-server.js');
|
|
140
150
|
promises.push(setupRestServer(restServer.route, paths.access, restServer.metaRoute));
|
|
141
151
|
}
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -176,12 +176,22 @@ export default class Orm {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
if (restServer.enabled === 'true') {
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
//
|
|
179
|
+
// MUST stay dynamic. setup-rest-server.js names the optional
|
|
180
|
+
// '@stonyx/rest-server' peer in its own static graph — directly, and
|
|
181
|
+
// through orm-request.ts / meta-request.ts, which import `Request` at
|
|
182
|
+
// module scope because they extend it (correctly: an `extends` base
|
|
183
|
+
// class cannot be awaited). Node links a module's entire static graph
|
|
184
|
+
// before evaluating any of it, so a static import here puts that
|
|
185
|
+
// specifier on the entry graph and `import('@stonyx/orm')` throws
|
|
183
186
|
// ERR_MODULE_NOT_FOUND for an ORM-only consumer that never installed the
|
|
184
|
-
// optional peer.
|
|
187
|
+
// optional peer.
|
|
188
|
+
//
|
|
189
|
+
// NOT the same reason the SQL/DynamoDB drivers above are lazy: those
|
|
190
|
+
// modules carry no static peer specifier at all, so the `await import()`
|
|
191
|
+
// there is not what isolates pg / mysql2 / @aws-sdk — that happens one
|
|
192
|
+
// layer down, in src/*/connection.ts (and src/dynamodb/dynamodb-db.ts).
|
|
193
|
+
// setup-rest-server.js is the only dist module whose laziness is
|
|
194
|
+
// load-bearing for peer resolution. (#280)
|
|
185
195
|
const { default: setupRestServer } = await import('./setup-rest-server.js');
|
|
186
196
|
promises.push(setupRestServer(restServer.route, paths.access, restServer.metaRoute));
|
|
187
197
|
}
|