@zerotal/core 1.0.0
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/CHANGELOG.md +79 -0
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/package.json +72 -0
- package/src/application/Application.ts +1671 -0
- package/src/application/BootDoctor.ts +108 -0
- package/src/application/DevErrorPage.ts +567 -0
- package/src/application/ExceptionHandler.ts +183 -0
- package/src/application/currentApp.ts +73 -0
- package/src/assets/assets.ts +79 -0
- package/src/assets/index.ts +16 -0
- package/src/auth/AuthenticatedUser.ts +18 -0
- package/src/build/PackageLinter.ts +146 -0
- package/src/build/PackageScaffold.ts +127 -0
- package/src/build/codemod.ts +64 -0
- package/src/build/index.ts +12 -0
- package/src/command/Command.ts +254 -0
- package/src/command/CommandRunner.ts +593 -0
- package/src/command/OutputWriter.ts +61 -0
- package/src/command/builtin/CompileCommand.ts +46 -0
- package/src/command/builtin/CssBuildCommand.ts +71 -0
- package/src/command/builtin/KeyGenerateCommand.ts +58 -0
- package/src/command/builtin/LintPackagesCommand.ts +72 -0
- package/src/command/builtin/MakeCommandCommand.ts +85 -0
- package/src/command/builtin/MakeControllerCommand.ts +95 -0
- package/src/command/builtin/MakeEventCommand.ts +85 -0
- package/src/command/builtin/MakeJobCommand.ts +53 -0
- package/src/command/builtin/MakeListenerCommand.ts +35 -0
- package/src/command/builtin/MakeMiddlewareCommand.ts +63 -0
- package/src/command/builtin/MakeNotificationCommand.ts +48 -0
- package/src/command/builtin/MakeObserverCommand.ts +78 -0
- package/src/command/builtin/MakePackageCommand.ts +45 -0
- package/src/command/builtin/MakePolicyCommand.ts +66 -0
- package/src/command/builtin/MakeProviderCommand.ts +75 -0
- package/src/command/builtin/MakeRequestCommand.ts +47 -0
- package/src/command/builtin/MakeResourceCommand.ts +61 -0
- package/src/command/builtin/MakeTestCommand.ts +120 -0
- package/src/command/builtin/ReloadCommand.ts +52 -0
- package/src/command/builtin/ReplCommand.ts +174 -0
- package/src/command/builtin/RouteListCommand.ts +188 -0
- package/src/command/builtin/ServeCommand.ts +321 -0
- package/src/command/builtin/StartCommand.ts +3 -0
- package/src/command/builtin/StatusCommand.ts +71 -0
- package/src/command/builtin/TestCommand.ts +172 -0
- package/src/command/builtin/WorkerCommand.ts +27 -0
- package/src/command/builtin/index.ts +53 -0
- package/src/command/scaffold/worker.ts.txt +12 -0
- package/src/command/scaffold/zerotal.ts.txt +26 -0
- package/src/command/startZerotal.ts +55 -0
- package/src/config/AppConfig.ts +253 -0
- package/src/config/ConfigLoader.ts +117 -0
- package/src/config/ConfigManager.ts +169 -0
- package/src/config/index.ts +46 -0
- package/src/config/registry.ts +59 -0
- package/src/config/validation.ts +117 -0
- package/src/container/Container.ts +606 -0
- package/src/container/ContextualBindingBuilder.ts +57 -0
- package/src/container/ScopedResolver.ts +117 -0
- package/src/container/index.ts +32 -0
- package/src/container/inject.ts +55 -0
- package/src/container/types.ts +71 -0
- package/src/context/RequestContext.ts +91 -0
- package/src/contracts/auth.ts +24 -0
- package/src/contracts/index.ts +23 -0
- package/src/contracts/session.ts +70 -0
- package/src/contracts/transaction.ts +26 -0
- package/src/conventions/ConventionLoader.ts +128 -0
- package/src/conventions/builtinConcerns.ts +131 -0
- package/src/crypt/Crypt.ts +141 -0
- package/src/crypt/URLSigner.ts +96 -0
- package/src/datetime/Carbon.ts +1396 -0
- package/src/datetime/CarbonInterval.ts +421 -0
- package/src/datetime/clock.ts +28 -0
- package/src/datetime/index.ts +23 -0
- package/src/datetime/temporal-shim.ts +1 -0
- package/src/dev/BuildOutput.ts +131 -0
- package/src/dev/CssPlugins.ts +184 -0
- package/src/dev/DevBuildHook.ts +74 -0
- package/src/dev/DevOrchestrator.ts +213 -0
- package/src/dev/DevReloadMiddleware.ts +101 -0
- package/src/dev/DevReloadServer.ts +85 -0
- package/src/dev/DevWsServer.ts +45 -0
- package/src/dev/index.ts +19 -0
- package/src/dev/reloadClient.ts +39 -0
- package/src/env/Def.ts +232 -0
- package/src/env/EnvSchema.ts +105 -0
- package/src/env/index.ts +34 -0
- package/src/env/t.ts +128 -0
- package/src/errors/ConfigError.ts +12 -0
- package/src/errors/ContainerErrors.ts +143 -0
- package/src/errors/HttpError.ts +127 -0
- package/src/errors/ValidationError.ts +19 -0
- package/src/errors/ZerotalError.ts +25 -0
- package/src/errors/index.ts +46 -0
- package/src/events/CallQueuedListener.ts +66 -0
- package/src/events/Emitter.ts +280 -0
- package/src/events/EventFake.ts +160 -0
- package/src/events/FrameworkEvents.ts +252 -0
- package/src/facade/Facade.ts +101 -0
- package/src/facade/facades/App.ts +155 -0
- package/src/facade/facades/Artisan.ts +63 -0
- package/src/facade/facades/Config.ts +21 -0
- package/src/facade/facades/Events.ts +19 -0
- package/src/facade/facades/index.ts +28 -0
- package/src/global.d.ts +9 -0
- package/src/hash/Hash.ts +60 -0
- package/src/health/Health.ts +221 -0
- package/src/health/index.ts +27 -0
- package/src/helpers/Collection.ts +435 -0
- package/src/helpers/config.ts +59 -0
- package/src/helpers/fluent.ts +52 -0
- package/src/helpers/html.ts +11 -0
- package/src/helpers/index.ts +266 -0
- package/src/helpers/make.ts +35 -0
- package/src/helpers/markdown.ts +73 -0
- package/src/helpers/pageElements.ts +27 -0
- package/src/helpers/request.ts +62 -0
- package/src/helpers/response.ts +411 -0
- package/src/helpers/str.ts +208 -0
- package/src/http/Http.ts +298 -0
- package/src/http/HttpClient.ts +289 -0
- package/src/http/Resource.ts +171 -0
- package/src/http/UploadedFile.ts +204 -0
- package/src/http/Uri.ts +490 -0
- package/src/http/index.ts +46 -0
- package/src/http/negotiate.ts +213 -0
- package/src/http/originGuard.ts +76 -0
- package/src/http/sniffContentType.ts +105 -0
- package/src/http/url.ts +204 -0
- package/src/http/withHeaders.ts +24 -0
- package/src/index.ts +250 -0
- package/src/lock/LockManager.ts +228 -0
- package/src/lock/config.ts +49 -0
- package/src/lock/drivers/LockDriver.ts +32 -0
- package/src/lock/drivers/MemoryLockDriver.ts +52 -0
- package/src/lock/drivers/RedisLockDriver.ts +58 -0
- package/src/lock/drivers/SqliteLockDriver.ts +85 -0
- package/src/lock/errors.ts +20 -0
- package/src/lock/facades/Lock.ts +114 -0
- package/src/lock/index.ts +53 -0
- package/src/logger/Log.ts +35 -0
- package/src/logger/LogManager.ts +430 -0
- package/src/logger/LoggerMiddleware.ts +125 -0
- package/src/logger/channels/ConsoleChannel.ts +139 -0
- package/src/logger/channels/DailyChannel.ts +74 -0
- package/src/logger/channels/NullChannel.ts +17 -0
- package/src/logger/channels/SingleChannel.ts +34 -0
- package/src/logger/channels/StackChannel.ts +29 -0
- package/src/logger/config.ts +90 -0
- package/src/logger/format.ts +96 -0
- package/src/logger/frameworkLog.ts +93 -0
- package/src/logger/index.ts +68 -0
- package/src/logger/renderTable.ts +111 -0
- package/src/logger/types.ts +212 -0
- package/src/macros/config.macro.ts +50 -0
- package/src/metrics/HttpMetrics.ts +114 -0
- package/src/metrics/index.ts +18 -0
- package/src/middleware/BaseMiddleware.ts +72 -0
- package/src/middleware/CorsMiddleware.ts +152 -0
- package/src/middleware/RateLimiter.ts +255 -0
- package/src/middleware/SecureHeadersMiddleware.ts +127 -0
- package/src/middleware/ThrottleMiddleware.ts +252 -0
- package/src/middleware/WebhookMiddleware.ts +204 -0
- package/src/pipeline/ContextRegistry.ts +42 -0
- package/src/pipeline/HttpContext.ts +865 -0
- package/src/pipeline/Pipeline.ts +150 -0
- package/src/pipeline/currentPage.ts +46 -0
- package/src/pipeline/types.ts +80 -0
- package/src/provider/LockProvider.ts +64 -0
- package/src/provider/LogProvider.ts +137 -0
- package/src/provider/ServiceProvider.ts +84 -0
- package/src/provider/StorageProvider.ts +45 -0
- package/src/router/FileRouter.ts +526 -0
- package/src/router/Route.ts +76 -0
- package/src/router/RouteHandler.ts +335 -0
- package/src/router/Router.ts +1247 -0
- package/src/router/domain.ts +65 -0
- package/src/security/index.ts +22 -0
- package/src/storage/FakeDisk.ts +233 -0
- package/src/storage/StorageFilesMiddleware.ts +150 -0
- package/src/storage/StorageManager.ts +173 -0
- package/src/storage/config.ts +47 -0
- package/src/storage/drivers/LocalDriver.ts +138 -0
- package/src/storage/drivers/S3Driver.ts +169 -0
- package/src/storage/errors.ts +135 -0
- package/src/storage/facades/Storage.ts +3 -0
- package/src/storage/global.d.ts +7 -0
- package/src/storage/index.ts +22 -0
- package/src/storage/root.ts +59 -0
- package/src/storage/types.ts +104 -0
- package/src/support/appKey.ts +38 -0
- package/src/support/cookie.ts +72 -0
- package/src/support/crypto.ts +52 -0
- package/src/support/deepMerge.ts +117 -0
- package/src/support/env.ts +71 -0
- package/src/support/network.ts +79 -0
- package/src/support/port.ts +197 -0
- package/src/support/str.ts +122 -0
- package/src/view/FileRouteResolver.ts +59 -0
- package/src/view/index.ts +144 -0
- package/src/view/jsx-runtime.ts +233 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Changelog â @zerotal/core
|
|
2
|
+
|
|
3
|
+
All notable changes to this package are documented here. The format is
|
|
4
|
+
based on [Keep a Changelog](https://keepachangelog.com/); this package
|
|
5
|
+
follows the Zerotal monorepo's unified versioning.
|
|
6
|
+
|
|
7
|
+
**Maturity: `stable`**
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `@zerotal/core/storage` — file storage (local and S3-compatible disks) now
|
|
14
|
+
ships inside core. Previously the separate `@zerotal/storage` package, which
|
|
15
|
+
has been removed; import from `@zerotal/core/storage` instead. File writes are
|
|
16
|
+
not an optional concern — the logger's own trail, uploads, and the media
|
|
17
|
+
library all need one way to put bytes somewhere.
|
|
18
|
+
- `Storage.publicUrl(path, { disk, expiresIn })` — a URL the browser can fetch,
|
|
19
|
+
with the kind chosen by the disk's own config: permanent for a served disk,
|
|
20
|
+
signed and expiring for a `signed` one, and `DiskNotServedError` for a disk
|
|
21
|
+
with no public URL. Handing back the stored path instead produced a _relative_
|
|
22
|
+
`src` that the browser resolved against the embedding page.
|
|
23
|
+
- `Storage.isServed(disk?)` — branch a template without catching an error.
|
|
24
|
+
- A served disk's URL base defaults to its `serve.path`, so `url()` and the
|
|
25
|
+
serving prefix cannot drift apart. An explicit `url` still wins, for a CDN.
|
|
26
|
+
- File serving. A disk that declares `serve` in `config/storage.ts` is exposed
|
|
27
|
+
over HTTP by `StorageFilesMiddleware`; one without it has no URL at all. The
|
|
28
|
+
default `public` disk is served at `/storage`, the default `local` disk is not.
|
|
29
|
+
`serve.signed` requires a valid `temporaryUrl()` signature and answers a bad
|
|
30
|
+
one with `404` rather than `403`.
|
|
31
|
+
- Private by default, with one public directory. Everything under the storage
|
|
32
|
+
root is private except `storage/public/`; a local disk rooted outside it can
|
|
33
|
+
only be served with `serve.signed`, and serving it openly throws
|
|
34
|
+
`UnsafePublicMountError` at boot. The default `public` disk now lives at
|
|
35
|
+
`storage/public` and is served at `/storage/public`, so the filesystem path
|
|
36
|
+
and the URL are the same shape.
|
|
37
|
+
- The built-in disk roots derive from the storage root, so they follow
|
|
38
|
+
`ZT_STORAGE_ROOT` instead of hardcoding `./storage`.
|
|
39
|
+
- The storage root. Every local disk must resolve inside `<project>/storage`
|
|
40
|
+
(or `ZT_STORAGE_ROOT`); one rooted elsewhere throws
|
|
41
|
+
`StorageRootEscapeError` at construction. The per-disk guard stops a path
|
|
42
|
+
escaping its disk; this stops the disk escaping the project.
|
|
43
|
+
- `StorageDriver.stream?()` — an optional lazy handle, so serving a large file
|
|
44
|
+
does not read it into memory first. Implemented by `LocalDriver` and
|
|
45
|
+
`FakeDisk`; the middleware falls back to `getBuffer()` without it.
|
|
46
|
+
- `StorageDriver.append()` — appends to a file, creating it when absent.
|
|
47
|
+
`LocalDriver` implements it natively; `S3Driver` throws
|
|
48
|
+
`UnsupportedOperationError`, since an S3 object is immutable and emulating an
|
|
49
|
+
append means rewriting the whole object.
|
|
50
|
+
- Logging now writes to two always-on sinks: the terminal, and a date-rotated
|
|
51
|
+
file under `./storage/logs` kept for 14 days. Configure with `console` and
|
|
52
|
+
`file` in `config/logging.ts`; either can be set to `false`. The file trail is
|
|
53
|
+
off under `APP_ENV=test`.
|
|
54
|
+
|
|
55
|
+
- Named log channels are now _additional_ destinations rather than the sole one.
|
|
56
|
+
An entry routed to a channel still reaches both sinks, except that a channel
|
|
57
|
+
already covering a sink suppresses that baseline for its own entries.
|
|
58
|
+
- `LogManager` taps observe every entry, no longer filtered by the routed
|
|
59
|
+
channel's level — so an observer sees what the application logged, not what
|
|
60
|
+
one channel happened to accept.
|
|
61
|
+
|
|
62
|
+
### Fixed
|
|
63
|
+
|
|
64
|
+
- A facade returned from an `async` function no longer throws. The runtime reads
|
|
65
|
+
`.then` to test for a thenable, and the proxy answered by resolving the
|
|
66
|
+
container; `then`/`catch`/`finally` and the well-known symbols are now
|
|
67
|
+
answered without a lookup.
|
|
68
|
+
|
|
69
|
+
## [1.0.0] — 2026-08-05
|
|
70
|
+
|
|
71
|
+
_First public release._
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
|
|
75
|
+
- **`Application.withWebSocket()` multiplexes handlers by path** instead of last-write-wins. Previously a single `_wsHandlers`/`_wsUpgradeData` slot meant a second registration silently clobbered the first, so an app using both flow (`/__flow/ws`) and broadcasting (`/app/ws`) only got one working endpoint. Registrations are now stored per-path (with an optional catch-all); each connection is tagged with its request path on upgrade and open/message/close route to the matching handler. `withWebSocket(handlers, upgradeData?, path?)` gained an optional `path`.
|
|
76
|
+
|
|
77
|
+
### Notes
|
|
78
|
+
|
|
79
|
+
- Conforms to the Zerotal package conventions (provider in `src/provider/`, PascalCase config factory, `ZerotalError`-based errors, test coverage).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zerotal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# @zerotal/core
|
|
2
|
+
|
|
3
|
+
> The foundation of the Zerotal framework — IoC container, application lifecycle, HTTP pipeline, and the conventions everything else builds on.
|
|
4
|
+
|
|
5
|
+
`@zerotal/core` is the heart of Zerotal, a Bun-native, full-stack TypeScript web framework. It owns the IoC container, the `Application` bootstrap/lifecycle engine, service providers, the router and HTTP pipeline, the typed config system, facades, events, JSX server-side views, and the console runtime. Every other Zerotal package (`@zerotal/orm`, `@zerotal/auth`, `@zerotal/session`, …) plugs into the primitives defined here.
|
|
6
|
+
|
|
7
|
+
Part of the [Zerotal](../../README.md) framework. Requires **Bun ≥ 1.3.14** (uses Bun-native APIs).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun add @zerotal/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What's inside
|
|
16
|
+
|
|
17
|
+
- **Container** — an IoC container with singleton/scoped/transient/value lifetimes, `@inject()` auto-wiring, contextual bindings, aliases, resolution hooks, and per-request scopes via `AsyncLocalStorage`.
|
|
18
|
+
- **Application** — the singleton that owns the container, discovers providers and config, loads routes, and drives the boot → start → stop lifecycle.
|
|
19
|
+
- **Router** — explicit (`Router.get/post/resource/view/...`) and file-based routing into one router, with groups, named routes, model binding, and `route()` URL generation.
|
|
20
|
+
- **Middleware** — the `Pipe` interface plus built-ins: `CorsMiddleware`, `ThrottleMiddleware`, `RateLimiter`, `SecureHeadersMiddleware`, `WebhookMiddleware`.
|
|
21
|
+
- **HttpContext** — the per-request object holding the `Request`/`Response`, route params, authenticated user, and input/response helpers.
|
|
22
|
+
- **Config** — a typed, dot-path config system (`config("app.name")`) backed by `config/*.ts` files, plus the `env()` helper for deployment state.
|
|
23
|
+
- **Facades** — thin static accessors over container bindings; core ships `Config`, `Events`, and `Artisan`.
|
|
24
|
+
- **Events** — a class-based event bus (`Emitter`) and a catalogue of framework events.
|
|
25
|
+
- **Views** — a JSX server-side rendering runtime (`@zerotal/core/jsx-runtime`) with layouts, `safe()`/`esc()`, and `view()`.
|
|
26
|
+
- **Commands** — the `Command` base class, `CommandRunner`, and a set of built-in CLI commands.
|
|
27
|
+
- **Encryption / Hashing** — `Crypt` (authenticated encryption), `Hash` (password hashing), and signed-URL helpers.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Bootstrap an application
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// bootstrap/app.ts
|
|
35
|
+
import { Application, basePath } from "@zerotal/core";
|
|
36
|
+
|
|
37
|
+
export default Application.create().routing({ web: basePath("routes/web.ts") });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`Application.create()` builds the singleton once; providers under `app/providers/*` and config under `config/*.ts` are auto-discovered at boot. `currentApp()` returns it anywhere afterward.
|
|
41
|
+
|
|
42
|
+
### Define routes
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { Router } from "@zerotal/core";
|
|
46
|
+
import { PostController } from "../app/controllers/PostController.ts";
|
|
47
|
+
|
|
48
|
+
Router.get("/posts", PostController, "index");
|
|
49
|
+
Router.get("/posts/:slug", PostController, "show").name("posts.show").bind("post", Post);
|
|
50
|
+
Router.resource("articles", PostController);
|
|
51
|
+
|
|
52
|
+
// Inline closure handler — no controller needed
|
|
53
|
+
Router.get("/health", ({ http }) => http.json({ ok: true }));
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### A controller using HttpContext
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import type { Context } from "@zerotal/core";
|
|
60
|
+
import { Post } from "../models/Post.ts";
|
|
61
|
+
|
|
62
|
+
export class PostController {
|
|
63
|
+
async index({ http }: Context): Promise<void> {
|
|
64
|
+
const posts = await Post.all();
|
|
65
|
+
http.json({ posts });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async store({ http }: Context): Promise<void> {
|
|
69
|
+
const { title, body } = await http.body<{ title: string; body: string }>();
|
|
70
|
+
const post = await Post.create({ title, body, userId: http.user!.id });
|
|
71
|
+
http.json(post, 201);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Bind and resolve from the container
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { ServiceProvider, inject } from "@zerotal/core";
|
|
80
|
+
|
|
81
|
+
export class AppServiceProvider extends ServiceProvider {
|
|
82
|
+
onRegister(): void {
|
|
83
|
+
this.app.container.singleton(CacheManager, async (c) => {
|
|
84
|
+
const cfg = await c.make("config");
|
|
85
|
+
return new CacheManager(cfg.get("cache"));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Auto-wiring — declare constructor dependencies with @inject
|
|
91
|
+
@inject(CacheManager)
|
|
92
|
+
export class PostRepository {
|
|
93
|
+
constructor(private cache: CacheManager) {}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Read configuration
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { config, env } from "@zerotal/core";
|
|
101
|
+
|
|
102
|
+
config("app.name"); // typed as string via the ConfigRegistry
|
|
103
|
+
config("app.port", 3000); // with a fallback
|
|
104
|
+
const dbUrl = env("DATABASE_URL", "sqlite://./database.sqlite");
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Subpath exports
|
|
108
|
+
|
|
109
|
+
| Import | Provides |
|
|
110
|
+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
111
|
+
| `@zerotal/core` | The full public API: `Application`, `Container`, `Router`/`Route`, `HttpContext`, middleware, errors, events, config, facades, helpers, crypto, and view authoring helpers. |
|
|
112
|
+
| `@zerotal/core/commands` | Built-in console commands — `ServeCommand`, `WorkerCommand`, `KeyGenerateCommand`, `RouteListCommand`, the `Make*` scaffolders, and more. |
|
|
113
|
+
| `@zerotal/core/helpers` | Standalone helper functions — `env`, `config`, `basePath`, `request`, `response` builders, `Str`, `Collection`, and pipe/tap utilities. |
|
|
114
|
+
| `@zerotal/core/facades` | The built-in facades: `Config`, `Events`, `Artisan`. |
|
|
115
|
+
| `@zerotal/core/macros/config` | The config macro used by the build tooling. |
|
|
116
|
+
| `@zerotal/core/jsx-runtime` | The JSX runtime for server-side views — set `jsxImportSource: "@zerotal/core"` in tsconfig to use it. |
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- [Application lifecycle](../../docs/application.md)
|
|
121
|
+
- [Container](../../docs/container.md)
|
|
122
|
+
- [Routing](../../docs/routing)
|
|
123
|
+
- [Controllers](../../docs/controllers.md)
|
|
124
|
+
- [Middleware](../../docs/middleware.md)
|
|
125
|
+
- [Context](../../docs/context.md)
|
|
126
|
+
- [Service providers](../../docs/providers.md)
|
|
127
|
+
- [Configuration](../../docs/config-system.md)
|
|
128
|
+
- [Views](../../docs/view.md)
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerotal/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"maturity": "stable",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./src/index.ts",
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts",
|
|
12
|
+
"./contracts": "./src/contracts/index.ts",
|
|
13
|
+
"./lock": "./src/lock/index.ts",
|
|
14
|
+
"./logger": "./src/logger/index.ts",
|
|
15
|
+
"./commands": "./src/command/builtin/index.ts",
|
|
16
|
+
"./helpers": "./src/helpers/index.ts",
|
|
17
|
+
"./facades": "./src/facade/facades/index.ts",
|
|
18
|
+
"./carbon": "./src/datetime/index.ts",
|
|
19
|
+
"./http": "./src/http/index.ts",
|
|
20
|
+
"./storage": "./src/storage/index.ts",
|
|
21
|
+
"./view": "./src/view/index.ts",
|
|
22
|
+
"./env": "./src/env/index.ts",
|
|
23
|
+
"./config": "./src/config/index.ts",
|
|
24
|
+
"./security": "./src/security/index.ts",
|
|
25
|
+
"./dev": "./src/dev/index.ts",
|
|
26
|
+
"./build": "./src/build/index.ts",
|
|
27
|
+
"./assets": "./src/assets/index.ts",
|
|
28
|
+
"./health": "./src/health/index.ts",
|
|
29
|
+
"./metrics": "./src/metrics/index.ts",
|
|
30
|
+
"./macros/config": "./src/macros/config.macro.ts",
|
|
31
|
+
"./jsx-runtime": "./src/view/jsx-runtime.ts",
|
|
32
|
+
"./jsx-dev-runtime": "./src/view/jsx-runtime.ts"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"src",
|
|
37
|
+
"!src/**/*.test.ts",
|
|
38
|
+
"!src/**/*.test.tsx",
|
|
39
|
+
"!src/**/*.spec.ts",
|
|
40
|
+
"!src/**/__fixtures__/**"
|
|
41
|
+
],
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"bun": ">=1.3.14"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"test": "bun test",
|
|
50
|
+
"typecheck": "tsc --noEmit"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@js-temporal/polyfill": "^0.5.1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"typescript": "^5.8.0"
|
|
57
|
+
},
|
|
58
|
+
"description": "The Zerotal framework core — application lifecycle, container, HTTP, routing, config, events, and helpers.",
|
|
59
|
+
"keywords": [
|
|
60
|
+
"zerotal",
|
|
61
|
+
"bun",
|
|
62
|
+
"typescript",
|
|
63
|
+
"framework"
|
|
64
|
+
],
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "git+https://github.com/zerotaldev/zerotal.git",
|
|
68
|
+
"directory": "packages/core"
|
|
69
|
+
},
|
|
70
|
+
"homepage": "https://github.com/zerotaldev/zerotal/tree/main/packages/core#readme",
|
|
71
|
+
"bugs": "https://github.com/zerotaldev/zerotal/issues"
|
|
72
|
+
}
|