@shaferllc/keel 0.36.0 → 0.58.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/README.md +14 -2
- package/dist/core/application.d.ts +58 -2
- package/dist/core/application.js +99 -3
- package/dist/core/authorization.d.ts +52 -0
- package/dist/core/authorization.js +97 -0
- package/dist/core/broadcasting.d.ts +49 -0
- package/dist/core/broadcasting.js +84 -0
- package/dist/core/broker.d.ts +398 -0
- package/dist/core/broker.js +602 -0
- package/dist/core/crypto.d.ts +1 -1
- package/dist/core/crypto.js +12 -3
- package/dist/core/database.d.ts +26 -1
- package/dist/core/database.js +65 -2
- package/dist/core/decorators.d.ts +39 -0
- package/dist/core/decorators.js +72 -0
- package/dist/core/exceptions.d.ts +77 -6
- package/dist/core/exceptions.js +168 -10
- package/dist/core/helpers.d.ts +6 -0
- package/dist/core/helpers.js +12 -0
- package/dist/core/http/kernel.js +14 -2
- package/dist/core/http/router.d.ts +14 -0
- package/dist/core/http/router.js +30 -1
- package/dist/core/index.d.ts +28 -6
- package/dist/core/index.js +15 -3
- package/dist/core/logger.d.ts +5 -0
- package/dist/core/logger.js +24 -2
- package/dist/core/migrations.js +3 -3
- package/dist/core/model.d.ts +19 -1
- package/dist/core/model.js +72 -4
- package/dist/core/provider.d.ts +13 -4
- package/dist/core/provider.js +12 -2
- package/dist/core/redis.d.ts +78 -0
- package/dist/core/redis.js +176 -0
- package/dist/core/request-logger.d.ts +26 -0
- package/dist/core/request-logger.js +48 -0
- package/dist/core/request.d.ts +17 -1
- package/dist/core/request.js +27 -1
- package/dist/core/scheduler.d.ts +60 -0
- package/dist/core/scheduler.js +166 -0
- package/dist/core/session.js +17 -2
- package/dist/core/storage.d.ts +57 -0
- package/dist/core/storage.js +98 -0
- package/dist/core/template.d.ts +50 -0
- package/dist/core/template.js +753 -0
- package/dist/core/testing.d.ts +54 -0
- package/dist/core/testing.js +141 -0
- package/dist/core/transformer.d.ts +89 -0
- package/dist/core/transformer.js +152 -0
- package/dist/core/validation.d.ts +20 -0
- package/dist/core/validation.js +52 -1
- package/dist/core/vite.d.ts +117 -0
- package/dist/core/vite.js +258 -0
- package/dist/vite/index.d.ts +40 -0
- package/dist/vite/index.js +146 -0
- package/package.json +16 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File storage over a pluggable `Disk` — like the database and mail layers, the
|
|
3
|
+
* core imports no filesystem or SDK, so it runs on Node and the edge. Point a
|
|
4
|
+
* disk at the local filesystem (Node), S3 (`fetch`), or a Cloudflare R2 binding;
|
|
5
|
+
* `MemoryDisk` is the built-in default for tests.
|
|
6
|
+
*
|
|
7
|
+
* setDisk(new MemoryDisk()); // or setDisk(r2Disk(env.BUCKET))
|
|
8
|
+
* await storage().put("avatars/1.png", bytes);
|
|
9
|
+
* const bytes = await storage().get("avatars/1.png");
|
|
10
|
+
* const url = storage().url("avatars/1.png");
|
|
11
|
+
*
|
|
12
|
+
* Register several disks by name and select one with `storage("s3")`.
|
|
13
|
+
*/
|
|
14
|
+
function toBytes(contents) {
|
|
15
|
+
if (typeof contents === "string")
|
|
16
|
+
return new TextEncoder().encode(contents);
|
|
17
|
+
if (contents instanceof Uint8Array)
|
|
18
|
+
return contents;
|
|
19
|
+
return new Uint8Array(contents);
|
|
20
|
+
}
|
|
21
|
+
/* ------------------------------ memory disk ------------------------------- */
|
|
22
|
+
/** An in-memory `Disk` — the default; ideal for tests. Not shared across processes. */
|
|
23
|
+
export class MemoryDisk {
|
|
24
|
+
baseUrl;
|
|
25
|
+
files = new Map();
|
|
26
|
+
constructor(baseUrl = "/storage") {
|
|
27
|
+
this.baseUrl = baseUrl;
|
|
28
|
+
}
|
|
29
|
+
async put(path, bytes) {
|
|
30
|
+
this.files.set(path, bytes);
|
|
31
|
+
}
|
|
32
|
+
async get(path) {
|
|
33
|
+
return this.files.get(path) ?? null;
|
|
34
|
+
}
|
|
35
|
+
async exists(path) {
|
|
36
|
+
return this.files.has(path);
|
|
37
|
+
}
|
|
38
|
+
async delete(path) {
|
|
39
|
+
this.files.delete(path);
|
|
40
|
+
}
|
|
41
|
+
async list(prefix = "") {
|
|
42
|
+
return [...this.files.keys()].filter((p) => p.startsWith(prefix)).sort();
|
|
43
|
+
}
|
|
44
|
+
url(path) {
|
|
45
|
+
return `${this.baseUrl}/${path}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/* -------------------------------- storage --------------------------------- */
|
|
49
|
+
export class Storage {
|
|
50
|
+
disk;
|
|
51
|
+
constructor(disk) {
|
|
52
|
+
this.disk = disk;
|
|
53
|
+
}
|
|
54
|
+
/** Write a file (string, bytes, or ArrayBuffer — strings are UTF-8 encoded). */
|
|
55
|
+
put(path, contents) {
|
|
56
|
+
return this.disk.put(path, toBytes(contents));
|
|
57
|
+
}
|
|
58
|
+
/** Read a file's raw bytes, or null if it doesn't exist. */
|
|
59
|
+
get(path) {
|
|
60
|
+
return this.disk.get(path);
|
|
61
|
+
}
|
|
62
|
+
/** Read a file as UTF-8 text, or null if it doesn't exist. */
|
|
63
|
+
async getText(path) {
|
|
64
|
+
const bytes = await this.disk.get(path);
|
|
65
|
+
return bytes == null ? null : new TextDecoder().decode(bytes);
|
|
66
|
+
}
|
|
67
|
+
exists(path) {
|
|
68
|
+
return this.disk.exists(path);
|
|
69
|
+
}
|
|
70
|
+
delete(path) {
|
|
71
|
+
return this.disk.delete(path);
|
|
72
|
+
}
|
|
73
|
+
list(prefix) {
|
|
74
|
+
return this.disk.list(prefix);
|
|
75
|
+
}
|
|
76
|
+
url(path) {
|
|
77
|
+
return this.disk.url(path);
|
|
78
|
+
}
|
|
79
|
+
/** The underlying driver, for backend-specific operations. */
|
|
80
|
+
get driver() {
|
|
81
|
+
return this.disk;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/* -------------------------------- global ---------------------------------- */
|
|
85
|
+
const disks = new Map([["default", new Storage(new MemoryDisk())]]);
|
|
86
|
+
/** Register a disk, optionally under a name (default: `"default"`). */
|
|
87
|
+
export function setDisk(disk, name = "default") {
|
|
88
|
+
const store = new Storage(disk);
|
|
89
|
+
disks.set(name, store);
|
|
90
|
+
return store;
|
|
91
|
+
}
|
|
92
|
+
/** The default disk, or a named one registered with `setDisk(disk, name)`. */
|
|
93
|
+
export function storage(name = "default") {
|
|
94
|
+
const store = disks.get(name);
|
|
95
|
+
if (!store)
|
|
96
|
+
throw new Error(`No storage disk named "${name}". Register it with setDisk().`);
|
|
97
|
+
return store;
|
|
98
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A string templating engine in the spirit of AdonisJS Edge — `{{ }}`
|
|
3
|
+
* interpolation and `@`-prefixed tags for logic, includes, layouts, and
|
|
4
|
+
* components.
|
|
5
|
+
*
|
|
6
|
+
* const t = new TemplateEngine();
|
|
7
|
+
* t.register("hello", "Hello, {{ name }}!");
|
|
8
|
+
* await t.render("hello", { name: "Ada" }); // "Hello, Ada!"
|
|
9
|
+
*
|
|
10
|
+
* Unlike engines that compile templates to a function via `eval`/`new
|
|
11
|
+
* Function`, this one *interprets* them against a small, safe expression
|
|
12
|
+
* evaluator — no dynamic code generation — so it runs unchanged on Node and on
|
|
13
|
+
* Cloudflare Workers (where `eval` is forbidden). The expression language is a
|
|
14
|
+
* practical subset of JS: literals, property/index access, method and helper
|
|
15
|
+
* calls, the usual operators, ternaries, arrays/objects, and `|` filters.
|
|
16
|
+
*/
|
|
17
|
+
/** HTML-escape a value for safe interpolation. */
|
|
18
|
+
export declare function escapeHtml(value: unknown): string;
|
|
19
|
+
export type Filter = (value: unknown, ...args: unknown[]) => unknown;
|
|
20
|
+
export interface RenderContext {
|
|
21
|
+
sections: Record<string, string>;
|
|
22
|
+
slots: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
export declare class TemplateEngine {
|
|
25
|
+
private templates;
|
|
26
|
+
private globals;
|
|
27
|
+
private filters;
|
|
28
|
+
constructor();
|
|
29
|
+
/** Register a template by name from its source string. */
|
|
30
|
+
register(name: string, source: string): this;
|
|
31
|
+
/** Register many templates at once (e.g. a Node loader reads files and passes them here). */
|
|
32
|
+
registerAll(sources: Record<string, string>): this;
|
|
33
|
+
/** True if a template is registered. */
|
|
34
|
+
has(name: string): boolean;
|
|
35
|
+
/** Expose a value/function to every template as a global. */
|
|
36
|
+
global(name: string, value: unknown): this;
|
|
37
|
+
/** Register a `{{ value | name }}` filter. */
|
|
38
|
+
filter(name: string, fn: Filter): this;
|
|
39
|
+
/** Render a registered template with the given state. */
|
|
40
|
+
render(name: string, state?: Record<string, unknown>): Promise<string>;
|
|
41
|
+
private ev;
|
|
42
|
+
private renderNodes;
|
|
43
|
+
private renderNode;
|
|
44
|
+
}
|
|
45
|
+
/** The default template engine (register templates/globals/filters on it). */
|
|
46
|
+
export declare function templates(): TemplateEngine;
|
|
47
|
+
/** Replace the default template engine. */
|
|
48
|
+
export declare function setTemplateEngine(e: TemplateEngine): TemplateEngine;
|
|
49
|
+
/** Render a registered template on the default engine. */
|
|
50
|
+
export declare function render(name: string, state?: Record<string, unknown>): Promise<string>;
|