vla 0.1.6 → 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.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Timo Mämecke
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 deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
package/README.md CHANGED
@@ -51,7 +51,7 @@ class UserRepo extends Vla.Repo {
51
51
  - **Clear Architecture** – Actions, Services, Repos, Resources, and Facades for organized code
52
52
  - **Clean Dependency Injection** - No decorators, no reflection, just `this.inject()`
53
53
  - **Built-in Memoization** – Automatic request-scoped caching for database queries
54
- - **Easy Testing** – Test classes, not file pathsno more brittle module mocks
54
+ - **Easy Testing** – Test classes, not file paths, no more brittle module mocks
55
55
  - **Module System** – Scale to large apps with domain-separated modules and Facades
56
56
  - **Request Context** – First-class context injection with AsyncLocalStorage
57
57
  - **Tree Shakeable** – Only bundle what you use
package/dist/index.d.mts CHANGED
@@ -203,19 +203,27 @@ declare function createModule<const ModuleName extends string>(moduleName: Modul
203
203
  //#endregion
204
204
  //#region src/kernel/scoped-als.d.ts
205
205
  declare function withKernel<T>(scopedKernel: Kernel, fn: () => T): T;
206
+ declare function getKernelFromContext(): Kernel | null;
206
207
  //#endregion
207
208
  //#region src/kernel/scoped-global.d.ts
208
209
  declare function setGlobalInvokeKernel(kernel: Kernel): void;
210
+ declare function getKernelFromGlobal(): Kernel | null;
209
211
  //#endregion
210
212
  //#region src/kernel/scoped-provider.d.ts
211
213
  type CurrentKernelFn = () => Kernel | Promise<Kernel>;
212
214
  declare function setInvokeKernelProvider(fn: CurrentKernelFn): void;
215
+ declare function getKernelFromProvider(): Promise<Kernel | null>;
213
216
  //#endregion
214
217
  //#region src/index.d.ts
215
218
  declare const Vla: {
216
219
  createModule: typeof createModule;
217
220
  createContext: typeof createContext;
218
221
  withKernel: typeof withKernel;
222
+ getKernel: {
223
+ fromContext: typeof getKernelFromContext;
224
+ fromGlobal: typeof getKernelFromGlobal;
225
+ fromProvider: typeof getKernelFromProvider;
226
+ };
219
227
  setGlobalInvokeKernel: typeof setGlobalInvokeKernel;
220
228
  setInvokeKernelProvider: typeof setInvokeKernelProvider;
221
229
  Kernel: typeof Kernel;
@@ -307,4 +315,4 @@ declare const Vla: {
307
315
  DevStable: typeof DevStable;
308
316
  };
309
317
  //#endregion
310
- export { InstantiableClass, Kernel, Layer, ModuleClass, Resolved, Scope, Token, UnwrapKey, UserSurface, Visibility, Vla, VlaInternalKeys, createContext, createModule, setGlobalInvokeKernel, setInvokeKernelProvider, withKernel };
318
+ export { InstantiableClass, Kernel, Layer, ModuleClass, Resolved, Scope, Token, UnwrapKey, UserSurface, Visibility, Vla, VlaInternalKeys, createContext, createModule, getKernelFromContext, getKernelFromGlobal, getKernelFromProvider, setGlobalInvokeKernel, setInvokeKernelProvider, withKernel };
package/dist/index.mjs CHANGED
@@ -163,7 +163,7 @@ const als = new AsyncLocalStorage();
163
163
  function withKernel(scopedKernel, fn) {
164
164
  return als.run(scopedKernel, fn);
165
165
  }
166
- function getAlsInvokeKernel() {
166
+ function getKernelFromContext() {
167
167
  return als.getStore() ?? null;
168
168
  }
169
169
 
@@ -173,7 +173,7 @@ let globalKernel = null;
173
173
  function setGlobalInvokeKernel(kernel) {
174
174
  globalKernel = kernel;
175
175
  }
176
- function getGlobalKernel() {
176
+ function getKernelFromGlobal() {
177
177
  return globalKernel;
178
178
  }
179
179
 
@@ -183,14 +183,14 @@ let currentKernelFn = null;
183
183
  function setInvokeKernelProvider(fn) {
184
184
  currentKernelFn = fn;
185
185
  }
186
- async function getKernelProvider() {
187
- return currentKernelFn ? await currentKernelFn() : void 0;
186
+ async function getKernelFromProvider() {
187
+ return currentKernelFn ? await currentKernelFn() : null;
188
188
  }
189
189
 
190
190
  //#endregion
191
191
  //#region src/kernel/scoped-invoke.ts
192
192
  async function getInvokeKernel() {
193
- return await getKernelProvider() ?? getAlsInvokeKernel() ?? getGlobalKernel()?.scoped() ?? new Kernel();
193
+ return await getKernelFromProvider() ?? getKernelFromContext() ?? getKernelFromGlobal()?.scoped() ?? new Kernel();
194
194
  }
195
195
 
196
196
  //#endregion
@@ -412,10 +412,15 @@ const Vla = {
412
412
  createModule,
413
413
  createContext,
414
414
  withKernel,
415
+ getKernel: {
416
+ fromContext: getKernelFromContext,
417
+ fromGlobal: getKernelFromGlobal,
418
+ fromProvider: getKernelFromProvider
419
+ },
415
420
  setGlobalInvokeKernel,
416
421
  setInvokeKernelProvider,
417
422
  Kernel
418
423
  };
419
424
 
420
425
  //#endregion
421
- export { Kernel, Vla, createContext, createModule, setGlobalInvokeKernel, setInvokeKernelProvider, withKernel };
426
+ export { Kernel, Vla, createContext, createModule, getKernelFromContext, getKernelFromGlobal, getKernelFromProvider, setGlobalInvokeKernel, setInvokeKernelProvider, withKernel };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vla",
3
3
  "type": "module",
4
- "version": "0.1.6",
4
+ "version": "0.2.0",
5
5
  "description": "Data layer kernel for backend- and fullstack apps",
6
6
  "author": "Timo Mämecke <hello@timo.wtf>",
7
7
  "license": "MIT",
@@ -28,7 +28,9 @@
28
28
  "dev": "tsdown --watch",
29
29
  "test": "vitest",
30
30
  "typecheck": "tsc --noEmit",
31
- "prepublishOnly": "pnpm run build"
31
+ "prepublishOnly": "pnpm run build",
32
+ "lint": "biome lint",
33
+ "format": "biome format"
32
34
  },
33
35
  "devDependencies": {
34
36
  "@biomejs/biome": "2.3.10",