@stonyx/rest-server 0.2.1-alpha.36 → 0.2.1-alpha.38
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 +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,12 @@ There are no subpath exports.
|
|
|
25
25
|
|
|
26
26
|
## Samples
|
|
27
27
|
|
|
28
|
-
The request classes in [`test/sample/requests/`](https://github.com/abofs/stonyx-rest-server/tree/dev/test/sample/requests) are the canonical usage reference. They import only `@stonyx/rest-server`, so you can copy them into your app's `requests/` directory
|
|
28
|
+
The request classes in [`test/sample/requests/`](https://github.com/abofs/stonyx-rest-server/tree/dev/test/sample/requests) are the canonical usage reference. They import only `@stonyx/rest-server`, `node:` built-ins and each other, so you can copy them into your app's `requests/` directory:
|
|
29
|
+
|
|
30
|
+
* **As TypeScript:** copy them unchanged. `stonyx serve` runs them with Node's type stripping, which loads a relative import only by its real file name, so `accounts.ts` imports `./base/api-request.ts`, not `.js`. For `tsc` to accept that specifier, set `"rewriteRelativeImportExtensions": true` and `"noEmit": true` in your `tsconfig.json` (TypeScript 5.7+); the `stonyx new` tsconfig sets neither, and reports `TS5097` without the first. `noEmit` matters because the scaffold's `build` script compiles into the app directory: route discovery loads a `.js` left beside a `.ts` as well, and that stale copy keeps answering after you edit the `.ts`. `stonyx serve` runs the `.ts` files, so `pnpm build` then only type-checks. If you have built before, delete the `.js` files in `requests/`.
|
|
31
|
+
* **As JavaScript:** remove all TypeScript-only syntax (annotations, `interface`, `import type` and inline `type` imports, `!` assertions; `stripTypeScriptTypes` from `node:module` does this), rename each file to `.js`, and change the `.ts` in that relative import to `.js`.
|
|
32
|
+
|
|
33
|
+
[`test/integration/sample-patterns-test.ts`](https://github.com/abofs/stonyx-rest-server/blob/dev/test/integration/sample-patterns-test.ts) exercises each one over HTTP. [`test/unit/sample-imports-test.ts`](https://github.com/abofs/stonyx-rest-server/blob/dev/test/unit/sample-imports-test.ts) fails if a sample imports anything other than `@stonyx/rest-server`, a `node:` built-in, or another sample file that exists under the exact name imported. The suite itself runs under tsx, which would load a `.js` specifier from a `.ts` file, so that check is what keeps the TypeScript copy loadable by `stonyx serve`. The samples are not included in the npm package.
|
|
29
34
|
|
|
30
35
|
| How do I… | Sample |
|
|
31
36
|
| :--- | :--- |
|
|
@@ -40,7 +45,7 @@ Two contracts the samples rely on, both pinned by `sample-patterns-test.ts`:
|
|
|
40
45
|
* `auth(request, state)` is synchronous. A returned Promise is not awaited; the request fails with **500** whatever the Promise resolves to. Do async checks in middleware.
|
|
41
46
|
* The last function of a route is called without binding `this`. Use an arrow function (as the samples do) to reach the class instance; a method reference fails with 500. Middleware functions are bound.
|
|
42
47
|
|
|
43
|
-
`private.ts` carries one deliberately invalid entry (`someInvalidMethod`) that the suite uses to check unknown methods are skipped. Do not copy
|
|
48
|
+
`private.ts` carries one deliberately invalid entry (`someInvalidMethod`) that the suite uses to check unknown methods are skipped, and its `auth` returns fixture statuses (505, 403) for the tests. Do not copy either; copy the `auth` in `base/api-request.ts`, which compares the token in constant time.
|
|
44
49
|
|
|
45
50
|
## Security notes
|
|
46
51
|
|