@stonyx/orm 0.3.2-beta.235 → 0.3.2-beta.236
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 +19 -1
- package/package.json +1 -1
- package/src/main.ts +19 -1
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
|
@@ -19,7 +19,6 @@ import log from 'stonyx/log';
|
|
|
19
19
|
import { forEachFileImport } from '@stonyx/utils/file';
|
|
20
20
|
import { kebabCaseToPascalCase, pluralize } from '@stonyx/utils/string';
|
|
21
21
|
import { registerPluralName } from './plural-registry.js';
|
|
22
|
-
import setupRestServer from './setup-rest-server.js';
|
|
23
22
|
import baseTransforms from './transforms.js';
|
|
24
23
|
import Store from './store.js';
|
|
25
24
|
import Serializer from './serializer.js';
|
|
@@ -131,6 +130,25 @@ export default class Orm {
|
|
|
131
130
|
promises.push(db.init());
|
|
132
131
|
}
|
|
133
132
|
if (restServer.enabled === 'true') {
|
|
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
|
|
140
|
+
// ERR_MODULE_NOT_FOUND for an ORM-only consumer that never installed the
|
|
141
|
+
// optional peer.
|
|
142
|
+
//
|
|
143
|
+
// NOT the same reason the SQL/DynamoDB drivers above are lazy: those
|
|
144
|
+
// modules carry no static peer specifier that survives to `dist/`
|
|
145
|
+
// (postgres-db.ts:15 and mysql-db.ts:17 are `import type`, erased by
|
|
146
|
+
// tsc), so the `await import()` there is not what isolates pg / mysql2 /
|
|
147
|
+
// @aws-sdk — that happens one layer down, in src/*/connection.ts (and
|
|
148
|
+
// src/dynamodb/dynamodb-db.ts).
|
|
149
|
+
// setup-rest-server.js is the only dist module whose laziness is
|
|
150
|
+
// load-bearing for peer resolution. (#280)
|
|
151
|
+
const { default: setupRestServer } = await import('./setup-rest-server.js');
|
|
134
152
|
promises.push(setupRestServer(restServer.route, paths.access, restServer.metaRoute));
|
|
135
153
|
}
|
|
136
154
|
// Wire up memory resolver so store.find() can check model memory flags
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -20,7 +20,6 @@ import log from 'stonyx/log';
|
|
|
20
20
|
import { forEachFileImport } from '@stonyx/utils/file';
|
|
21
21
|
import { kebabCaseToPascalCase, pluralize } from '@stonyx/utils/string';
|
|
22
22
|
import { registerPluralName } from './plural-registry.js';
|
|
23
|
-
import setupRestServer from './setup-rest-server.js';
|
|
24
23
|
import baseTransforms from './transforms.js';
|
|
25
24
|
import Store from './store.js';
|
|
26
25
|
import Serializer from './serializer.js';
|
|
@@ -177,6 +176,25 @@ export default class Orm {
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
if (restServer.enabled === 'true') {
|
|
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
|
|
186
|
+
// ERR_MODULE_NOT_FOUND for an ORM-only consumer that never installed the
|
|
187
|
+
// optional peer.
|
|
188
|
+
//
|
|
189
|
+
// NOT the same reason the SQL/DynamoDB drivers above are lazy: those
|
|
190
|
+
// modules carry no static peer specifier that survives to `dist/`
|
|
191
|
+
// (postgres-db.ts:15 and mysql-db.ts:17 are `import type`, erased by
|
|
192
|
+
// tsc), so the `await import()` there is not what isolates pg / mysql2 /
|
|
193
|
+
// @aws-sdk — that happens one layer down, in src/*/connection.ts (and
|
|
194
|
+
// src/dynamodb/dynamodb-db.ts).
|
|
195
|
+
// setup-rest-server.js is the only dist module whose laziness is
|
|
196
|
+
// load-bearing for peer resolution. (#280)
|
|
197
|
+
const { default: setupRestServer } = await import('./setup-rest-server.js');
|
|
180
198
|
promises.push(setupRestServer(restServer.route, paths.access, restServer.metaRoute));
|
|
181
199
|
}
|
|
182
200
|
|