@c9up/ream 0.2.1 → 0.2.2
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/dist/Ignitor.d.ts.map +1 -1
- package/dist/Ignitor.js +15 -1
- package/dist/Ignitor.js.map +1 -1
- package/dist/errors/aggregate.d.ts +24 -0
- package/dist/errors/aggregate.d.ts.map +1 -0
- package/dist/errors/aggregate.js +24 -0
- package/dist/errors/aggregate.js.map +1 -0
- package/dist/events/services/main.d.ts.map +1 -1
- package/dist/events/services/main.js +3 -10
- package/dist/events/services/main.js.map +1 -1
- package/dist/http/Exception.d.ts +76 -6
- package/dist/http/Exception.d.ts.map +1 -1
- package/dist/http/Exception.js +178 -85
- package/dist/http/Exception.js.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/router/Router.js +1 -1
- package/dist/router/Router.js.map +1 -1
- package/dist/services/app.d.ts.map +1 -1
- package/dist/services/app.js +3 -21
- package/dist/services/app.js.map +1 -1
- package/dist/services/console.d.ts.map +1 -1
- package/dist/services/console.js +3 -19
- package/dist/services/console.js.map +1 -1
- package/dist/services/createServiceProxy.d.ts +19 -0
- package/dist/services/createServiceProxy.d.ts.map +1 -0
- package/dist/services/createServiceProxy.js +44 -0
- package/dist/services/createServiceProxy.js.map +1 -0
- package/dist/services/router.d.ts.map +1 -1
- package/dist/services/router.js +3 -12
- package/dist/services/router.js.map +1 -1
- package/dist/services/server.d.ts.map +1 -1
- package/dist/services/server.js +3 -22
- package/dist/services/server.js.map +1 -1
- package/dist/types/container.d.ts +64 -0
- package/dist/types/container.d.ts.map +1 -0
- package/dist/types/container.js +23 -0
- package/dist/types/container.js.map +1 -0
- package/events.win32-x64-msvc.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +9 -1
- package/scheduler.win32-x64-msvc.node +0 -0
- package/src/Ignitor.ts +15 -1
- package/src/errors/aggregate.ts +33 -0
- package/src/events/services/main.ts +6 -12
- package/src/http/Exception.ts +225 -99
- package/src/index.ts +15 -2
- package/src/router/Router.ts +1 -1
- package/src/services/app.ts +6 -23
- package/src/services/console.ts +6 -21
- package/src/services/createServiceProxy.ts +47 -0
- package/src/services/router.ts +6 -14
- package/src/services/server.ts +6 -24
- package/src/types/container.ts +66 -0
package/src/services/router.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { Router } from '../router/Router.js'
|
|
12
|
+
import { createServiceProxy } from './createServiceProxy.js'
|
|
12
13
|
|
|
13
14
|
let instance: Router | undefined
|
|
14
15
|
|
|
@@ -34,19 +35,10 @@ export function getRouter(): Router | undefined {
|
|
|
34
35
|
* Router proxy — defers all property access to the underlying instance.
|
|
35
36
|
* Throws if accessed before Ignitor initializes it.
|
|
36
37
|
*/
|
|
37
|
-
const router: Router =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
'Ensure your route files are loaded as preloads in reamrc.ts, not at import time.',
|
|
43
|
-
)
|
|
44
|
-
}
|
|
45
|
-
// Bind methods so private-field writes inside the class resolve
|
|
46
|
-
// against the real instance brand instead of the Proxy.
|
|
47
|
-
const value = Reflect.get(instance, prop, instance)
|
|
48
|
-
return typeof value === 'function' ? value.bind(instance) : value
|
|
49
|
-
},
|
|
50
|
-
})
|
|
38
|
+
const router: Router = createServiceProxy<Router>(
|
|
39
|
+
() => instance,
|
|
40
|
+
'Router accessed before initialization. ' +
|
|
41
|
+
'Ensure your route files are loaded as preloads in reamrc.ts, not at import time.',
|
|
42
|
+
)
|
|
51
43
|
|
|
52
44
|
export default router
|
package/src/services/server.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Server } from '../server/Server.js'
|
|
11
|
+
import { createServiceProxy } from './createServiceProxy.js'
|
|
11
12
|
|
|
12
13
|
let instance: Server | undefined
|
|
13
14
|
|
|
@@ -29,29 +30,10 @@ export function getServer(): Server | undefined {
|
|
|
29
30
|
return instance
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
const server: Server =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// `import { setX } from '.../services/x'` into a crash at import time, far
|
|
38
|
-
// from any real use. They are not members of what this stands in for, so
|
|
39
|
-
// answer undefined and let a genuine access be the one that reports.
|
|
40
|
-
if (typeof prop === 'symbol' || prop === 'then') {
|
|
41
|
-
return undefined
|
|
42
|
-
}
|
|
43
|
-
if (!instance) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
'Server accessed before initialization. ' +
|
|
46
|
-
'Ensure your kernel files are loaded as preloads in reamrc.ts.',
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
// Bind methods to the real instance so private-field access inside
|
|
50
|
-
// them resolves against the underlying class brand — passing the
|
|
51
|
-
// Proxy as `this` breaks `#field` writes (Proxy isn't branded).
|
|
52
|
-
const value = Reflect.get(instance, prop, instance)
|
|
53
|
-
return typeof value === 'function' ? value.bind(instance) : value
|
|
54
|
-
},
|
|
55
|
-
})
|
|
33
|
+
const server: Server = createServiceProxy<Server>(
|
|
34
|
+
() => instance,
|
|
35
|
+
'Server accessed before initialization. ' +
|
|
36
|
+
'Ensure your kernel files are loaded as preloads in reamrc.ts.',
|
|
37
|
+
)
|
|
56
38
|
|
|
57
39
|
export default server
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The container's known bindings, as a type.
|
|
3
|
+
*
|
|
4
|
+
* Resolving from the container is a string lookup, so without a shared
|
|
5
|
+
* interface every `container.make('router')` returns `unknown` and every app
|
|
6
|
+
* casts. AdonisJS solves it with an augmentable `ContainerBindings`, and every
|
|
7
|
+
* package in its ecosystem adds its own token to it:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* declare module '@c9up/ream/types' {
|
|
11
|
+
* interface ContainerBindings {
|
|
12
|
+
* auth: AuthManager
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Ream core registers the entries below; anything else — `auth` (warden),
|
|
18
|
+
* `logger` (spectrum), `db` (atlas) — reaches this interface by augmentation
|
|
19
|
+
* from the package that owns it, which is why the interface is open rather
|
|
20
|
+
* than a closed union.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { Application } from '../Application.js'
|
|
24
|
+
import type { ConfigStore } from '../ConfigLoader.js'
|
|
25
|
+
import type { Console } from '../console/Console.js'
|
|
26
|
+
import type { Kernel } from '../console/Kernel.js'
|
|
27
|
+
import type { Emitter } from '../events/Emitter.js'
|
|
28
|
+
import type { HttpContext } from '../http/HttpContext.js'
|
|
29
|
+
import type { MiddlewareRegistry } from '../middleware/Pipeline.js'
|
|
30
|
+
import type { MigrationRegistry } from '../migrations/MigrationRegistry.js'
|
|
31
|
+
import type { Router } from '../router/Router.js'
|
|
32
|
+
import type { CookieSigner } from '../security/CookieSigner.js'
|
|
33
|
+
import type { SignedUrl } from '../security/SignedUrl.js'
|
|
34
|
+
import type { Server } from '../server/Server.js'
|
|
35
|
+
|
|
36
|
+
export interface ContainerBindings {
|
|
37
|
+
/** The application instance. */
|
|
38
|
+
app: Application
|
|
39
|
+
/** Absolute path to the application root. */
|
|
40
|
+
appRoot: string
|
|
41
|
+
/** The config store built from `config/*.ts`. */
|
|
42
|
+
config: ConfigStore
|
|
43
|
+
/** The console application (AdonisJS calls its equivalent `ace`). */
|
|
44
|
+
console: Console
|
|
45
|
+
/** The console kernel that dispatches commands. */
|
|
46
|
+
consoleKernel: Kernel
|
|
47
|
+
/** The event emitter. */
|
|
48
|
+
emitter: Emitter
|
|
49
|
+
/** Cookie/value signing and encryption, backed by `APP_KEY`. */
|
|
50
|
+
encryption: CookieSigner
|
|
51
|
+
/** The `HttpContext` class itself — for `HttpContext.getOrFail()` style access. */
|
|
52
|
+
HttpContext: typeof HttpContext
|
|
53
|
+
/** Named middleware registered by the app kernel. */
|
|
54
|
+
middleware: MiddlewareRegistry
|
|
55
|
+
/** Migration sources contributed by data packages (atlas, eon, ...). */
|
|
56
|
+
migrations: MigrationRegistry
|
|
57
|
+
/** The HTTP router. */
|
|
58
|
+
router: Router
|
|
59
|
+
/** The HTTP server. */
|
|
60
|
+
server: Server
|
|
61
|
+
/** Signed-URL generation and verification. */
|
|
62
|
+
signedUrl: SignedUrl
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A token this container knows how to resolve. */
|
|
66
|
+
export type ContainerBinding = keyof ContainerBindings
|