@vesk/compiler 0.2.15 → 0.2.16

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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAgC,MAAM,0BAA0B,CAAC;AAGnH,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,UAIjC,CAAC;AA6CF,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,YAAY,CAY/E;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAQ/D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAuB3D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAoC7D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAgC,MAAM,0BAA0B,CAAC;AAGnH,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,UAIjC,CAAC;AA6CF,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,YAAY,CAY/E;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAQ/D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAuB3D;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAsC7D"}
package/dist/config.js CHANGED
@@ -119,12 +119,14 @@ export function validateConfig(config) {
119
119
  typeof plugin.onBuildStart === 'function' ||
120
120
  typeof plugin.onBuildEnd === 'function' ||
121
121
  typeof plugin.onRequest === 'function' ||
122
+ typeof plugin.onStart === 'function' ||
123
+ typeof plugin.onStop === 'function' ||
122
124
  typeof plugin.onHead === 'function' ||
123
125
  typeof plugin.onHtml === 'function' ||
124
126
  (plugin.provides && typeof plugin.provides === 'object' && Object.keys(plugin.provides).length > 0);
125
127
  if (!hasKnownHook) {
126
128
  throw new Error(`[vesk] Plugin "${plugin.name}" implements none of the recognized ` +
127
- 'hooks (onCSS, onFileWatch, onTransformJS, onBuildStart, onBuildEnd, onRequest, onHead, onHtml) ' +
129
+ 'hooks (onCSS, onFileWatch, onTransformJS, onBuildStart, onBuildEnd, onRequest, onStart, onStop, onHead, onHtml) ' +
128
130
  'or provides — it will never be called. Check the plugin package version, or see ' +
129
131
  '/docu/cli/plugin-api.md for the current hook contract.');
130
132
  }
@@ -0,0 +1,30 @@
1
+ import type { VeskEventHandlers } from '@vesk/compiler/src/types';
2
+ /**
3
+ * App lifecycle + per-request events.
4
+ *
5
+ * Convention file: `app/_events.ts` (or `.js`), exporting `onStart`,
6
+ * `onRequest` and/or `onStop` handlers:
7
+ *
8
+ * ```ts
9
+ * // app/_events.ts
10
+ * import type { ServerEventContext } from '@vesk/types';
11
+ * export async function onStart(ctx: ServerEventContext) {
12
+ * await ctx.set('db', await connect());
13
+ * }
14
+ * export async function onRequest(ctx: ServerEventContext) { }
15
+ * export async function onStop(ctx: ServerEventContext) { }
16
+ * ```
17
+ *
18
+ * The `_` prefix marks the file private — it is never routed. Values `set()`
19
+ * in `onStart` land in the server-wide context (`serverLocals()`) and are
20
+ * pre-seeded into every request's `locals()`.
21
+ */
22
+ export declare const EVENTS_FILE_NAMES: string[];
23
+ /** Resolve the app-level events file, if present. */
24
+ export declare function collectEventsFile(appDir: string): string | null;
25
+ export declare function isEventsFile(path: string): boolean;
26
+ /** Load an events file (cache-busted so dev edits reload without restart). */
27
+ export declare function loadEvents(sourcePath: string): Promise<VeskEventHandlers>;
28
+ /** Run the handlers registered for one event, serially, in export order. */
29
+ export declare function runEventHandlers(handlers: VeskEventHandlers, name: 'onStart' | 'onRequest' | 'onStop', ctx: Record<string, unknown>): Promise<void>;
30
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,iBAAiB,UAA+B,CAAC;AAE9D,qDAAqD;AACrD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM/D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKlD;AAED,8EAA8E;AAC9E,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAa/E;AAED,4EAA4E;AAC5E,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,IAAI,CAAC,CAIf"}
package/dist/events.js ADDED
@@ -0,0 +1,65 @@
1
+ import { existsSync } from 'fs';
2
+ import { join } from 'path';
3
+ /**
4
+ * App lifecycle + per-request events.
5
+ *
6
+ * Convention file: `app/_events.ts` (or `.js`), exporting `onStart`,
7
+ * `onRequest` and/or `onStop` handlers:
8
+ *
9
+ * ```ts
10
+ * // app/_events.ts
11
+ * import type { ServerEventContext } from '@vesk/types';
12
+ * export async function onStart(ctx: ServerEventContext) {
13
+ * await ctx.set('db', await connect());
14
+ * }
15
+ * export async function onRequest(ctx: ServerEventContext) { }
16
+ * export async function onStop(ctx: ServerEventContext) { }
17
+ * ```
18
+ *
19
+ * The `_` prefix marks the file private — it is never routed. Values `set()`
20
+ * in `onStart` land in the server-wide context (`serverLocals()`) and are
21
+ * pre-seeded into every request's `locals()`.
22
+ */
23
+ export const EVENTS_FILE_NAMES = ['_events.ts', '_events.js'];
24
+ /** Resolve the app-level events file, if present. */
25
+ export function collectEventsFile(appDir) {
26
+ for (const name of EVENTS_FILE_NAMES) {
27
+ const candidate = join(appDir, name);
28
+ if (existsSync(candidate))
29
+ return candidate;
30
+ }
31
+ return null;
32
+ }
33
+ export function isEventsFile(path) {
34
+ for (const name of EVENTS_FILE_NAMES) {
35
+ if (path.endsWith('/' + name))
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+ /** Load an events file (cache-busted so dev edits reload without restart). */
41
+ export async function loadEvents(sourcePath) {
42
+ try {
43
+ const url = new URL('file://' + sourcePath);
44
+ url.searchParams.set('t', String(Date.now()) + Math.random().toString(36).slice(2));
45
+ const mod = (await import(url.href));
46
+ const handlers = {};
47
+ if (typeof mod.onStart === 'function')
48
+ handlers.onStart = mod.onStart;
49
+ if (typeof mod.onRequest === 'function')
50
+ handlers.onRequest = mod.onRequest;
51
+ if (typeof mod.onStop === 'function')
52
+ handlers.onStop = mod.onStop;
53
+ return handlers;
54
+ }
55
+ catch {
56
+ return {};
57
+ }
58
+ }
59
+ /** Run the handlers registered for one event, serially, in export order. */
60
+ export async function runEventHandlers(handlers, name, ctx) {
61
+ const fn = handlers[name];
62
+ if (typeof fn !== 'function')
63
+ return;
64
+ await fn(ctx);
65
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAiC,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEtG,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBA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B,sBAAsB,CAC1C,KAAK,EAAE,eAAe,EAAE,EACxB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC;IAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAmIzH"}
@@ -89,7 +89,8 @@ export async function loadMiddleware(sourcePath) {
89
89
  export async function executeMiddlewareChain(chain, request, params, options = {}) {
90
90
  const { onLast, plugins } = options;
91
91
  const url = new URL(request.url, 'http://localhost');
92
- const locals = {};
92
+ const serverStore = globalThis.__vesk_server_ctx;
93
+ const locals = Object.assign({}, serverStore || {});
93
94
  const cookies = parseCookies(request.headers?.get('cookie') || '');
94
95
  const ctx = new Proxy({
95
96
  request,
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { IRRoot } from '@vesk/compiler/src/ir';
2
- export type { RouteNode, ApiRouteNode, MiddlewareContext, VeskPlugin, VeskCors, VeskRateLimit, VeskSecurityPreset, VeskSecurity, VeskConfig, MdConfig, MdHtmlMode, MdProps, MarkdownOptions, MdHtmlWarning, MiddlewareEntry, MiddlewareChainOptions, RenderPageResult, SSGResult, DataScriptPayload, ExternalDataScript, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, SsrDataSink, VeskResponse, SetCookieOptions, } from '@vesk/types';
2
+ export type { RouteNode, ApiRouteNode, MiddlewareContext, ServerEventContext, VeskEventHandlers, VeskPlugin, VeskCors, VeskRateLimit, VeskSecurityPreset, VeskSecurity, VeskConfig, MdConfig, MdHtmlMode, MdProps, MarkdownOptions, MdHtmlWarning, MiddlewareEntry, MiddlewareChainOptions, RenderPageResult, SSGResult, DataScriptPayload, ExternalDataScript, Tracked, Resource, UseFetchOptions, UseFetchStreamOptions, SsrDataSink, VeskResponse, SetCookieOptions, } from '@vesk/types';
3
3
  export interface CompileFileResult {
4
4
  ir: IRRoot;
5
5
  componentMap: Map<string, Function>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,OAAO,EACP,eAAe,EACf,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,aAAa,EAAE,YAAY,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,aAA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C9C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,aAAa,EAAE,kBAAkB,CAAC;IAC9D,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,aAAa,EAAE,UAAU,EAAE,CAAC;IAC7C;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,shBAahB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "type": "module",
5
5
  "description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sveltejs/acorn-typescript": "^1.0.0",
23
- "@vesk/types": "^0.2.15",
23
+ "@vesk/types": "^0.2.16",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",