@telorun/cache-memory 0.2.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/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ # SUSTAINABLE USE LICENSE (Fair-code)
2
+
3
+ Copyright (c) 2026 CodeNet Sp. z o.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and distribute the Software for any purpose—including commercial purposes—subject to the following conditions:
6
+
7
+ 1. ANTI-COMPETITION RESTRICTION: The Software may not be provided to third parties as a managed service, commercial SaaS (Software-as-a-Service), PaaS (Platform-as-a-Service), BaaS (Backend-as-a-Service), or similar offering where the primary value provided to the user is the functionality of the Software itself, without a separate commercial license from the copyright holder.
8
+
9
+ 2. PERMITTED COMMERCIAL USE: You are free to use the Software to build, host, and monetize your own commercial applications, products, and services, provided such use does not violate Clause 1.
10
+
11
+ 3. ATTRIBUTION: This copyright notice and license must be included in all copies or substantial portions of the Software.
12
+
13
+ 4. CONTRIBUTIONS: Contributions to the Software are welcome and encouraged. By contributing, you agree that your contributions may be incorporated into the Software and distributed under this license.
14
+
15
+ 5. DISCLAIMER: The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
16
+
17
+ For commercial licensing, managed hosting exemptions, or enterprise inquiries, please contact <contact@codenet.pl>.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/telorun/telo/main/assets/telo.png" alt="Telo" width="200" />
3
+ </p>
4
+
5
+ <h1 align="center">Telo</h1>
6
+
7
+ <p align="center">Runtime for declarative backends.</p>
8
+
9
+ <p align="center">
10
+ <a href="https://github.com/telorun/telo/actions/workflows/test.yml"><img alt="Tests" src="https://github.com/telorun/telo/actions/workflows/test.yml/badge.svg" /></a>
11
+ <a href="https://www.npmjs.com/package/@telorun/cli"><img alt="node" src="https://img.shields.io/node/v/@telorun/cli" /></a>
12
+ <br />
13
+ <a href="https://github.com/telorun/telo/commits/main"><img alt="Last commit" src="https://img.shields.io/github/last-commit/telorun/telo" /></a>
14
+ <a href="https://github.com/telorun/telo/issues"><img alt="Issues" src="https://img.shields.io/github/issues/telorun/telo" /></a>
15
+ <a href="https://github.com/telorun/telo/pulls"><img alt="Pull requests" src="https://img.shields.io/github/issues-pr/telorun/telo" /></a>
16
+ <br />
17
+ <img alt="Changesets" src="https://img.shields.io/badge/maintained%20with-changesets-176de3" />
18
+ </p>
19
+
20
+ Telo is an execution engine (Micro-Kernel) that runs logic defined entirely in YAML manifests. Instead of writing imperative backend code, you define your routes, databases, schemas, and AI workflows as atomic, interconnected YAML documents. Telo takes those manifests and runs them.
21
+
22
+ Built to be language-agnostic and infinitely extensible.
23
+
24
+ ```bash
25
+ # Reconcile your manifest into a running backend
26
+ $ telo ./examples/hello-api.yaml
27
+
28
+ {"level":30,"time":1771610393008,"pid":1310178,"hostname":"dev","msg":"Server listening at http://127.0.0.1:8844"}
29
+ ```
30
+
31
+ ## Why use Telo?
32
+
33
+ - **Open Standards:** Built on YAML, JSON Schema, and CEL — no proprietary DSL.
34
+ - **Static Analysis:** CEL type checking, reference validation, and IDE diagnostics catch errors before runtime.
35
+ - **Micro-Kernel Architecture:** Telo itself knows nothing about HTTP or SQL. Everything is a module you import, scope, and compose with typed variable and secret contracts.
36
+ - **Language Agnostic:** Available as a Node.js runtime today, with a shared YAML runtime contract that allows for future Rust or Go implementations without changing your manifests.
37
+
38
+ ## What It Does
39
+
40
+ - **Loads** YAML resources and compiles CEL expressions (`${{ }}`) into an in-memory registry.
41
+ - **Resolves** resource dependencies via a multi-pass init loop, handling ordering automatically.
42
+ - **Indexes** resources by Kind and Name for constant-time lookup.
43
+ - **Dispatches** execution to the controller that owns each Kind.
44
+
45
+ ## Example manifest
46
+
47
+ Here is an example Telo application that defines a simple HTTP API:
48
+
49
+ ```yaml
50
+ kind: Telo.Application
51
+ metadata:
52
+ name: feedback
53
+ version: 1.0.0
54
+ description: |
55
+ A complete feedback collection REST API — no code, pure YAML.
56
+ Persists entries to SQLite and serves them over HTTP.
57
+ imports:
58
+ Http: std/http-server@0.12.0
59
+ Sql: std/sql@0.9.2
60
+ targets:
61
+ - !ref Migrations
62
+ - !ref Server
63
+ ---
64
+ # SQLite database — swap driver/host/database for PostgreSQL with zero YAML changes
65
+ kind: Sql.Connection
66
+ metadata:
67
+ name: Db
68
+ driver: sqlite
69
+ file: ./tmp/feedback.db
70
+ ---
71
+ # Migrations: applied automatically before the server starts
72
+ kind: Sql.Migrations
73
+ metadata:
74
+ name: Migrations
75
+ connection: !ref Db
76
+ ---
77
+ kind: Sql.Migration
78
+ metadata:
79
+ name: Migration_20260413_182154_CreateFeedback
80
+ version: 20260413_182154_CreateFeedback
81
+ sql: |
82
+ CREATE TABLE IF NOT EXISTS feedback (
83
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
84
+ text TEXT NOT NULL,
85
+ source TEXT,
86
+ score INTEGER NOT NULL DEFAULT 0,
87
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
88
+ )
89
+ ---
90
+ kind: Http.Server
91
+ metadata:
92
+ name: Server
93
+ baseUrl: http://localhost:8844
94
+ port: 8844
95
+ logger: true
96
+ openapi:
97
+ info:
98
+ title: Feedback API
99
+ version: 1.0.0
100
+ mounts:
101
+ - path: /v1
102
+ mount: !ref FeedbackRoutes
103
+ ---
104
+ kind: Http.Api
105
+ metadata:
106
+ name: FeedbackRoutes
107
+ routes:
108
+ # POST /v1/feedback — insert a new entry, score derived from body length heuristic
109
+ - request:
110
+ path: /feedback
111
+ method: POST
112
+ schema:
113
+ body:
114
+ type: object
115
+ properties:
116
+ text:
117
+ type: string
118
+ minLength: 1
119
+ source:
120
+ type: string
121
+ required: [ text ]
122
+ handler:
123
+ kind: Sql.Exec
124
+ connection: !ref Db
125
+ inputs:
126
+ sql: "INSERT INTO feedback (text, source, score) VALUES (?, ?, ?)"
127
+ bindings:
128
+ - "${{ request.body.text }}"
129
+ - "${{ request.body.source }}"
130
+ - "${{ size(request.body.text) }}"
131
+ response:
132
+ - status: 201
133
+ headers:
134
+ Content-Type: application/json
135
+ body:
136
+ ok: true
137
+ message: Feedback received
138
+
139
+ # GET /v1/feedback — list all entries, newest first
140
+ - request:
141
+ path: /feedback
142
+ method: GET
143
+ handler:
144
+ kind: Sql.Select
145
+ connection: !ref Db
146
+ from: feedback
147
+ columns: [ id, text, source, score, created_at ]
148
+ orderBy:
149
+ - { column: created_at, direction: desc }
150
+ response:
151
+ - status: 200
152
+ headers:
153
+ Content-Type: application/json
154
+ body: "${{ result.rows }}"
155
+
156
+ # GET /v1/feedback/{id} — fetch a single entry
157
+ - request:
158
+ path: /feedback/{id}
159
+ method: GET
160
+ schema:
161
+ params:
162
+ type: object
163
+ properties:
164
+ id:
165
+ type: integer
166
+ required: [ id ]
167
+ handler:
168
+ kind: Sql.Select
169
+ connection: !ref Db
170
+ from: feedback
171
+ columns: [ id, text, source, score, created_at ]
172
+ where:
173
+ - { column: id, op: "=", value: "${{ request.params.id }}" }
174
+ response:
175
+ - status: 200
176
+ when: "size(result.rows) > 0"
177
+ headers:
178
+ Content-Type: application/json
179
+ body: "${{ result.rows[0] }}"
180
+ - status: 404
181
+ headers:
182
+ Content-Type: application/json
183
+ body:
184
+ ok: false
185
+ message: Not found
186
+ ```
187
+
188
+ ## Status
189
+
190
+ Telo is under **active development**. The core runtime, module system, and standard library are functional, but the API surface — including YAML shapes — may change without notice. Not yet recommended for production use.
191
+
192
+ ## The Meaning of Telo
193
+
194
+ The name Telo is derived from the Greek root Telos - meaning the "end goal", "purpose", or "final state". That is exactly the philosophy behind this runtime. In standard imperative programming, you have to write thousands of lines of code to tell a server exactly how to start. With Telo, you simply declare your desired final state.
195
+
196
+ You define the end state. Telo makes it real.
197
+
198
+ ## Philosophy
199
+
200
+ Modern platforms often spend disproportionate effort on technical mechanics-wiring frameworks, managing infrastructure, and negotiating toolchains-while the original business problem gets delayed or diluted. Telo pushes in the opposite direction: it treats kernel execution as a stable, predictable host so teams can concentrate on the **business logic and outcomes** instead of the plumbing.
201
+
202
+ By separating "what the system should do" from "how it is hosted", the runtime reduces friction for domain‑level changes. Teams can move faster on product requirements, experiment more safely, and keep conversations centered on value delivered rather than implementation trivia.
203
+
204
+ Telo also aims to **join forces across all programming language communities**, so the best ideas, patterns, and implementations can converge into a shared kernel truth without forcing everyone into a single stack.
205
+
206
+ YAML also makes the system more **AI‑friendly** than traditional programming languages: it is explicit, structured, and easier for tools to generate, review, and transform without losing intent.
207
+
208
+ ## Modularity
209
+
210
+ Telo is built around **modules** that own specific resource kinds. A module is loaded from a manifest, declares which kinds it implements, and then receives only the resources of those kinds. This keeps concerns isolated and lets teams compose systems from focused building blocks rather than monolithic services.
211
+
212
+ At kernel execution time, execution is always routed by **Kind.Name**. The kernel resolves the Kind to its owning module and hands off execution. Modules can call back into the kernel to execute other resources, enabling composition without tight coupling.
213
+
214
+ ## Architecture
215
+
216
+ The architecture is inspired by Kubernetes-style manifests: declarative resources, explicit kinds, and a control plane that routes work based on those definitions.
217
+ Those manifests were taken to the next level by allowing them to run inside a standalone runtime host.
218
+
219
+ ## See more at
220
+
221
+ - [Telo Kernel](./kernel/README.md)
222
+ - [Telo SDK for module authors](sdk/README.md)
223
+ - [Modules](modules/README.md)
224
+
225
+ ## License
226
+
227
+ See [LICENSE](https://github.com/telorun/telo/blob/main/LICENSE).
228
+
229
+ ## Contribution Note
230
+
231
+ By contributing, you agree that code and examples in this repository may be translated or re‑implemented in other programming languages (including by AI systems) to support the project’s polyglot goals.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { ControllerContext, ResourceContext, ResourceInstance } from "@telorun/sdk";
2
+ import type { CacheLookupResult, CacheStore } from "@telorun/cache";
3
+ interface StoreResource {
4
+ metadata: {
5
+ name: string;
6
+ module?: string;
7
+ };
8
+ maxEntries?: number;
9
+ }
10
+ /**
11
+ * In-process cache store. Holds entries in a Map (insertion order = write
12
+ * order, used for FIFO eviction) and classifies freshness against each entry's
13
+ * fresh / stale windows on read.
14
+ */
15
+ declare class MemoryStore implements ResourceInstance, CacheStore {
16
+ private readonly entries;
17
+ private readonly maxEntries;
18
+ constructor(resource: StoreResource);
19
+ get(key: string): Promise<CacheLookupResult>;
20
+ set(key: string, value: unknown, ttlMs: number, staleTtlMs: number): Promise<void>;
21
+ delete(key: string): Promise<void>;
22
+ provide(): Promise<MemoryStore>;
23
+ teardown(): Promise<void>;
24
+ snapshot(): Record<string, unknown>;
25
+ }
26
+ export declare function register(_ctx: ControllerContext): void;
27
+ export declare function create(resource: StoreResource, _ctx: ResourceContext): Promise<MemoryStore>;
28
+ export {};
@@ -0,0 +1,56 @@
1
+ /**
2
+ * In-process cache store. Holds entries in a Map (insertion order = write
3
+ * order, used for FIFO eviction) and classifies freshness against each entry's
4
+ * fresh / stale windows on read.
5
+ */
6
+ class MemoryStore {
7
+ entries = new Map();
8
+ maxEntries;
9
+ constructor(resource) {
10
+ this.maxEntries = resource.maxEntries ?? 10000;
11
+ }
12
+ async get(key) {
13
+ const entry = this.entries.get(key);
14
+ const now = Date.now();
15
+ if (!entry || now >= entry.expireAt) {
16
+ if (entry)
17
+ this.entries.delete(key);
18
+ return { state: "miss", value: null, age: null };
19
+ }
20
+ const state = now < entry.freshUntil ? "fresh" : "stale";
21
+ return { state, value: entry.value, age: now - entry.storedAt };
22
+ }
23
+ async set(key, value, ttlMs, staleTtlMs) {
24
+ const now = Date.now();
25
+ // Re-insert at the tail so recency reflects the latest write.
26
+ this.entries.delete(key);
27
+ this.entries.set(key, {
28
+ value,
29
+ storedAt: now,
30
+ freshUntil: now + ttlMs,
31
+ expireAt: now + ttlMs + staleTtlMs,
32
+ });
33
+ while (this.entries.size > this.maxEntries) {
34
+ const oldest = this.entries.keys().next().value;
35
+ if (oldest === undefined)
36
+ break;
37
+ this.entries.delete(oldest);
38
+ }
39
+ }
40
+ async delete(key) {
41
+ this.entries.delete(key);
42
+ }
43
+ async provide() {
44
+ return this;
45
+ }
46
+ async teardown() {
47
+ this.entries.clear();
48
+ }
49
+ snapshot() {
50
+ return {};
51
+ }
52
+ }
53
+ export function register(_ctx) { }
54
+ export async function create(resource, _ctx) {
55
+ return new MemoryStore(resource);
56
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@telorun/cache-memory",
3
+ "version": "0.2.0",
4
+ "description": "Telo cache-memory module — in-process, freshness-aware CacheMemory.Store.",
5
+ "keywords": [
6
+ "telo",
7
+ "cache",
8
+ "memory",
9
+ "in-process"
10
+ ],
11
+ "author": "Bartosz Pasiński <bartosz.pasinski@codenet.pl>",
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/telorun/telo.git",
16
+ "directory": "modules/cache-memory/nodejs"
17
+ },
18
+ "homepage": "https://github.com/telorun/telo#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/telorun/telo/issues"
21
+ },
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "bun": "./src/index.ts",
30
+ "import": "./dist/index.js"
31
+ },
32
+ "./store": {
33
+ "types": "./dist/store-controller.d.ts",
34
+ "bun": "./src/store-controller.ts",
35
+ "import": "./dist/store-controller.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist/**",
40
+ "src/**"
41
+ ],
42
+ "dependencies": {
43
+ "@telorun/cache": "0.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.0.0",
47
+ "typescript": "^5.0.0",
48
+ "@telorun/sdk": "0.33.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@telorun/sdk": "*"
52
+ },
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.lib.json"
55
+ }
56
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import type { ControllerContext, ResourceContext, ResourceInstance } from "@telorun/sdk";
2
+ import type { CacheLookupResult, CacheStore } from "@telorun/cache";
3
+
4
+ interface StoreResource {
5
+ metadata: { name: string; module?: string };
6
+ maxEntries?: number;
7
+ }
8
+
9
+ interface Envelope {
10
+ value: unknown;
11
+ storedAt: number;
12
+ freshUntil: number;
13
+ expireAt: number;
14
+ }
15
+
16
+ /**
17
+ * In-process cache store. Holds entries in a Map (insertion order = write
18
+ * order, used for FIFO eviction) and classifies freshness against each entry's
19
+ * fresh / stale windows on read.
20
+ */
21
+ class MemoryStore implements ResourceInstance, CacheStore {
22
+ private readonly entries = new Map<string, Envelope>();
23
+ private readonly maxEntries: number;
24
+
25
+ constructor(resource: StoreResource) {
26
+ this.maxEntries = resource.maxEntries ?? 10000;
27
+ }
28
+
29
+ async get(key: string): Promise<CacheLookupResult> {
30
+ const entry = this.entries.get(key);
31
+ const now = Date.now();
32
+ if (!entry || now >= entry.expireAt) {
33
+ if (entry) this.entries.delete(key);
34
+ return { state: "miss", value: null, age: null };
35
+ }
36
+ const state = now < entry.freshUntil ? "fresh" : "stale";
37
+ return { state, value: entry.value, age: now - entry.storedAt };
38
+ }
39
+
40
+ async set(key: string, value: unknown, ttlMs: number, staleTtlMs: number): Promise<void> {
41
+ const now = Date.now();
42
+ // Re-insert at the tail so recency reflects the latest write.
43
+ this.entries.delete(key);
44
+ this.entries.set(key, {
45
+ value,
46
+ storedAt: now,
47
+ freshUntil: now + ttlMs,
48
+ expireAt: now + ttlMs + staleTtlMs,
49
+ });
50
+ while (this.entries.size > this.maxEntries) {
51
+ const oldest = this.entries.keys().next().value;
52
+ if (oldest === undefined) break;
53
+ this.entries.delete(oldest);
54
+ }
55
+ }
56
+
57
+ async delete(key: string): Promise<void> {
58
+ this.entries.delete(key);
59
+ }
60
+
61
+ async provide(): Promise<MemoryStore> {
62
+ return this;
63
+ }
64
+
65
+ async teardown(): Promise<void> {
66
+ this.entries.clear();
67
+ }
68
+
69
+ snapshot(): Record<string, unknown> {
70
+ return {};
71
+ }
72
+ }
73
+
74
+ export function register(_ctx: ControllerContext): void {}
75
+
76
+ export async function create(
77
+ resource: StoreResource,
78
+ _ctx: ResourceContext,
79
+ ): Promise<MemoryStore> {
80
+ return new MemoryStore(resource);
81
+ }