vona-module-a-static 5.0.27 → 5.1.1

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 CHANGED
File without changes
@@ -64,3 +64,4 @@ declare module 'vona' {
64
64
  }
65
65
  }
66
66
  /** scope: end */
67
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/.metadata/index.ts"],"names":[],"mappings":"AACA,8BAA8B;AAC9B,cAAc,oCAAoC,CAAC;AACnD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,sBAAsB,CAAC;AAC9B,OAAO,QAAQ,sBAAsB,CAAC;IAElC,UAAiB,uBAAuB;QACtC,iBAAiB,EAAE,8BAA8B,CAAC;KACnD;CAGJ;AACD,OAAO,QAAQ,sBAAsB,CAAC;IAE9B,UAAiB,sBAAsB;KAGtC;IAEC,UAAiB,sBAAsB;QACrC,IAAI,aAAa,IAAI,kCAAkC,CAAC;QACxD,IAAI,UAAU,IAAI,iBAAiB,CAAC;QACpC,IAAI,aAAa,IAAI,8BAA8B,CAAC;KACrD;CACV;AACD,4BAA4B;AAC5B,mBAAmB;AACnB,cAAc,8BAA8B,CAAC;AAE7C,OAAO,MAAM,CAAC;AACd,OAAO,QAAQ,MAAM,CAAC;CAGrB;AACD,OAAO,QAAQ,sBAAsB,CAAC;IAE9B,UAAiB,gBAAgB;KAGhC;IAEC,UAAiB,gBAAgB;QAC/B,IAAI,aAAa,IAAI,4BAA4B,CAAC;QAClD,IAAI,UAAU,IAAI,sBAAsB,CAAC;KAE1C;CACV;AACD,iBAAiB;AACjB,mBAAmB;AACnB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,gBAAgB,CAAC;CACjC;AACD,iBAAiB;AACjB,mBAAmB;AACnB,OAAO,KAAK,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AACzG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAiB,YAAY;QAC3B,sBAAsB,EAAE,OAAO,CAAC,wBAAwB,EAAE,0BAA0B,CAAC,CAAC;KACvF;CACF;AACD,iBAAiB;AACjB,mBAAmB;AACnB,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAGzD,qBACa,kBAAmB,SAAQ,aAAa;CAAG;AAExD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACnB;AAED,OAAO,MAAM,CAAC;AACd,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAiB,gBAAgB;QAC/B,UAAU,EAAE,kBAAkB,CAAC;KAChC;IAED,UAAiB,mBAAmB;QAClC,MAAM,EAAE,kBAAkB,CAAC;KAC5B;CAOF;AACD,iBAAiB"}
@@ -1,2 +1,3 @@
1
1
  export declare const __ThisModule__ = "a-static";
2
2
  export { ScopeModuleAStatic as ScopeModule } from './index.ts';
3
+ //# sourceMappingURL=this.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"this.d.ts","sourceRoot":"","sources":["../../src/.metadata/this.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { IMiddlewareSystemOptionsStatic } from './middlewareSystem.static.ts';
2
1
  import { BeanEventBase } from 'vona-module-a-event';
2
+ import type { IMiddlewareSystemOptionsStatic } from './middlewareSystem.static.ts';
3
3
  export interface TypeEventResolvePathData {
4
4
  dir: string;
5
5
  filename: string;
@@ -8,3 +8,4 @@ export interface TypeEventResolvePathData {
8
8
  export type TypeEventResolvePathResult = string | true | undefined;
9
9
  export declare class EventResolvePath extends BeanEventBase<TypeEventResolvePathData, TypeEventResolvePathResult> {
10
10
  }
11
+ //# sourceMappingURL=event.resolvePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.resolvePath.d.ts","sourceRoot":"","sources":["../../src/bean/event.resolvePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,qBAAqB,CAAC;AAE3D,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAEnF,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,8BAA8B,CAAC;CACzC;AAED,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEnE,qBACa,gBAAiB,SAAQ,aAAa,CAAC,wBAAwB,EAAE,0BAA0B,CAAC;CAAG"}
@@ -25,3 +25,4 @@ export declare class MiddlewareSystemStatic extends BeanBase implements IMiddlew
25
25
  }
26
26
  declare function getFullPath(ctx: VonaContext, dir: string, filename: string, options: IMiddlewareSystemOptionsStatic): Promise<string | true | undefined>;
27
27
  export {};
28
+ //# sourceMappingURL=middlewareSystem.static.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middlewareSystem.static.d.ts","sourceRoot":"","sources":["../../src/bean/middlewareSystem.static.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,iCAAiC,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAQxG,OAAO,EAAE,QAAQ,EAAW,MAAM,MAAM,CAAC;AAOzC,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,8BAA+B,SAAQ,iCAAiC;IACvF,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,CAAC;IAElC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,OAAO,WAAW,CAAC;CACjC;AAED,qBAgBa,sBAAuB,SAAQ,QAAS,YAAW,wBAAwB;IACtF,OAAO,CAAC,SAAS,CAAM;IAEjB,OAAO,CAAC,OAAO,EAAE,8BAA8B,EAAE,IAAI,EAAE,IAAI;IAIjE,YAAY,CAAC,OAAO,EAAE,8BAA8B;IAQpD,kBAAkB,CAAC,OAAO,EAAE,8BAA8B;CAyD3D;AAED,iBAAe,WAAW,CACxB,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAUpC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './.metadata/index.ts';
2
2
  export * from './lib/index.ts';
3
3
  export * from './types/index.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { BeanInfo, BeanBase, compose, BeanScopeBase, SymbolModuleBelong } from 'vona';
2
- import assert from 'node:assert';
3
- import { existsSync, mkdirSync } from 'node:fs';
4
- import path from 'node:path';
2
+ import { __decorate } from 'tslib';
5
3
  import staticCache from '@cabloy/koa-static-cache';
6
4
  import { isObject, isString } from '@cabloy/utils';
7
5
  import range from 'koa-range';
6
+ import assert from 'node:assert';
7
+ import { existsSync, mkdirSync } from 'node:fs';
8
+ import path from 'node:path';
8
9
  import { MiddlewareSystem } from 'vona-module-a-aspect';
9
10
  import { LRU } from 'ylru';
10
11
  import { Event, BeanEventBase } from 'vona-module-a-event';
@@ -14,25 +15,7 @@ const __ThisModule__ = 'a-static';
14
15
 
15
16
  const SymbolStaticGetFullPathInner = Symbol('SymbolStaticGetFullPathInner');
16
17
 
17
- var _dec$2, _dec2$2, _class$2;
18
- let MiddlewareSystemStatic = (_dec$2 = MiddlewareSystem({
19
- dependencies: 'a-instance:instance',
20
- apiStaticPrefix: '/api/static/',
21
- dirs: [],
22
- dynamic: true,
23
- preload: false,
24
- maxFiles: 1000,
25
- alias: {
26
- '/favicon.ico': '/api/static/home/index/img/vona.png'
27
- },
28
- getFullPath
29
- // maxAge: undefined,
30
- // buffer: false,
31
- // dir: '',
32
- // prefix: '/', // should be always '/', so as to support ssr site
33
- }), _dec2$2 = BeanInfo({
34
- module: "a-static"
35
- }), _dec$2(_class$2 = _dec2$2(_class$2 = class MiddlewareSystemStatic extends BeanBase {
18
+ let MiddlewareSystemStatic = class MiddlewareSystemStatic extends BeanBase {
36
19
  constructor(...args) {
37
20
  super(...args);
38
21
  this._composer = void 0;
@@ -83,7 +66,6 @@ let MiddlewareSystemStatic = (_dec$2 = MiddlewareSystem({
83
66
  if (newOptions.prefix) {
84
67
  prefixs.push(newOptions.prefix);
85
68
  }
86
-
87
69
  // ensure directory exists
88
70
  if (!existsSync(newOptions.dir)) {
89
71
  mkdirSync(newOptions.dir, {
@@ -94,7 +76,25 @@ let MiddlewareSystemStatic = (_dec$2 = MiddlewareSystem({
94
76
  }
95
77
  return middlewares;
96
78
  }
97
- }) || _class$2) || _class$2);
79
+ };
80
+ MiddlewareSystemStatic = __decorate([MiddlewareSystem({
81
+ dependencies: 'a-security:securities',
82
+ apiStaticPrefix: '/api/static/',
83
+ dirs: [],
84
+ dynamic: true,
85
+ preload: false,
86
+ maxFiles: 1000,
87
+ alias: {
88
+ '/favicon.ico': '/api/static/home/index/img/vona.png'
89
+ },
90
+ getFullPath
91
+ // maxAge: undefined,
92
+ // buffer: false,
93
+ // dir: '',
94
+ // prefix: '/', // should be always '/', so as to support ssr site
95
+ }), BeanInfo({
96
+ module: "a-static"
97
+ })], MiddlewareSystemStatic);
98
98
  async function getFullPath(ctx, dir, filename, options) {
99
99
  if (process.env.META_MODE === 'dev') {
100
100
  ctx[SymbolStaticGetFullPathInner] = () => {
@@ -147,16 +147,15 @@ async function _getFullPathInner(ctx, dir, filename, options) {
147
147
  return fullPath;
148
148
  }
149
149
 
150
- var _dec$1, _dec2$1, _class$1;
151
- let EventResolvePath = (_dec$1 = Event(), _dec2$1 = BeanInfo({
150
+ let EventResolvePath = class EventResolvePath extends BeanEventBase {};
151
+ EventResolvePath = __decorate([Event(), BeanInfo({
152
152
  module: "a-static"
153
- }), _dec$1(_class$1 = _dec2$1(_class$1 = class EventResolvePath extends BeanEventBase {}) || _class$1) || _class$1);
153
+ })], EventResolvePath);
154
154
 
155
- var _dec, _dec2, _class;
156
- let ScopeModuleAStatic = (_dec = Scope(), _dec2 = BeanInfo({
155
+ let ScopeModuleAStatic = class ScopeModuleAStatic extends BeanScopeBase {};
156
+ ScopeModuleAStatic = __decorate([Scope(), BeanInfo({
157
157
  module: "a-static"
158
- }), _dec(_class = _dec2(_class = class ScopeModuleAStatic extends BeanScopeBase {}) || _class) || _class);
159
-
158
+ })], ScopeModuleAStatic);
160
159
  /** scope: end */
161
160
 
162
161
  class BeanAssetBase extends BeanBase {
@@ -176,3 +175,4 @@ class BeanStaticBase extends BeanBase {
176
175
  }
177
176
 
178
177
  export { BeanAssetBase, BeanStaticBase, EventResolvePath, MiddlewareSystemStatic, ScopeModuleAStatic, SymbolStaticGetFullPathInner };
178
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/.metadata/this.ts","../src/types/static.ts","../src/bean/middlewareSystem.static.ts","../src/bean/event.resolvePath.ts","../src/.metadata/index.ts","../src/lib/beanAssetBase.ts","../src/lib/beanStaticBase.ts"],"sourcesContent":[null,null,null,null,null,null,null],"names":["__ThisModule__","SymbolStaticGetFullPathInner","Symbol","MiddlewareSystemStatic","BeanBase","constructor","args","_composer","execute","options","next","_getComposer","ctx","middlewares","_createMiddlewares","compose","Object","assign","maxAge","app","meta","isProd","buffer","dir","config","server","publicDir","prefix","dirs","concat","prefixs","rangeMiddleware","isMatch","some","p","path","startsWith","range","dirObj","assert","isObject","isString","newOptions","dynamic","files","LRU","maxFiles","push","existsSync","mkdirSync","recursive","staticCache","__decorate","MiddlewareSystem","dependencies","apiStaticPrefix","preload","alias","getFullPath","__z_BeanInfo","module","filename","process","env","META_MODE","_getFullPathInner","scopeSelf","scope","event","resolvePath","emit","filePrefix","normalize","replace","indexOf","slice","length","parts","split","sep","wordFirst","shift","fullPath","join","Error","moduleRelativeName","modules","util","getAssetPathPhysical","EventResolvePath","BeanEventBase","Event","ScopeModuleAStatic","BeanScopeBase","Scope","BeanAssetBase","get","scene","assetPath","SymbolModuleBelong","BeanStaticBase","combineStaticPath","getURL","path2","getAbsoluteUrl"],"mappings":";;;;;;;;;;;;;AAAO,MAAMA,cAAc,GAAG,UAAU;;MCA3BC,4BAA4B,GAAGC,MAAM,CAAC,8BAA8B;;ACmD1E,IAAMC,sBAAsB,GAA5B,MAAMA,sBAAuB,SAAQC,QAAQ,CAAA;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CAAA;AAAA,IAAA,IAAA,CAC1CC,SAAS,GAAA,MAAA;AAAA,EAAA;AAEjB,EAAA,MAAMC,OAAOA,CAACC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@@ -2,3 +2,4 @@ import { BeanBase } from 'vona';
2
2
  export declare class BeanAssetBase<IAssetGetPath> extends BeanBase {
3
3
  get<K extends keyof IAssetGetPath, V extends IAssetGetPath[K]>(scene: K, assetPath: V): string;
4
4
  }
5
+ //# sourceMappingURL=beanAssetBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanAssetBase.d.ts","sourceRoot":"","sources":["../../src/lib/beanAssetBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,MAAM,CAAC;AAEpD,qBAAa,aAAa,CAAC,aAAa,CAAE,SAAQ,QAAQ;IACxD,GAAG,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM;CAG/F"}
@@ -3,3 +3,4 @@ export declare class BeanStaticBase<TypeStaticGetPath> extends BeanBase {
3
3
  get(path: TypeStaticGetPath): string;
4
4
  getURL(path: TypeStaticGetPath): string;
5
5
  }
6
+ //# sourceMappingURL=beanStaticBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beanStaticBase.d.ts","sourceRoot":"","sources":["../../src/lib/beanStaticBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,MAAM,CAAC;AAEpD,qBAAa,cAAc,CAAC,iBAAiB,CAAE,SAAQ,QAAQ;IAC7D,GAAG,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM;IAIpC,MAAM,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM;CAIxC"}
@@ -1,2 +1,3 @@
1
1
  export * from './beanAssetBase.ts';
2
2
  export * from './beanStaticBase.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from './static.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -4,3 +4,4 @@ declare module 'vona-module-a-meta' {
4
4
  static: never;
5
5
  }
6
6
  }
7
+ //# sourceMappingURL=static.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/types/static.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,eAAyC,CAAC;AAEnF,OAAO,QAAQ,oBAAoB,CAAC;IAClC,UAAiB,eAAe;QAC9B,MAAM,EAAE,KAAK,CAAC;KACf;CACF"}
package/package.json CHANGED
@@ -1,26 +1,18 @@
1
1
  {
2
2
  "name": "vona-module-a-static",
3
- "type": "module",
4
- "version": "5.0.27",
5
- "title": "a-static",
6
- "vonaModule": {
7
- "dependencies": {},
8
- "metas": {
9
- "static": {
10
- "scopeResource": true,
11
- "boilerplate": "static/boilerplate"
12
- },
13
- "asset": {
14
- "scopeResource": true,
15
- "boilerplate": "asset/boilerplate"
16
- }
17
- }
18
- },
3
+ "version": "5.1.1",
19
4
  "description": "",
20
- "author": "",
21
5
  "keywords": [
22
6
  "Vona Module"
23
7
  ],
8
+ "author": "",
9
+ "files": [
10
+ "assets",
11
+ "cli",
12
+ "dist",
13
+ "src"
14
+ ],
15
+ "type": "module",
24
16
  "exports": {
25
17
  ".": {
26
18
  "types": [
@@ -31,11 +23,13 @@
31
23
  },
32
24
  "./package.json": "./package.json"
33
25
  },
34
- "files": [
35
- "assets",
36
- "cli",
37
- "dist"
38
- ],
26
+ "scripts": {
27
+ "clean": "rimraf dist tsconfig.build.tsbuildinfo",
28
+ "tsc:publish": "npm run clean && vona :bin:buildModule --sourcemap && tsc -p tsconfig.build.json",
29
+ "prepublishOnly": "npm run tsc:publish",
30
+ "prepack": "clean-package",
31
+ "postpack": "clean-package restore && npm run clean"
32
+ },
39
33
  "dependencies": {
40
34
  "@cabloy/koa-static-cache": "^6.0.1",
41
35
  "koa-range": "^0.3.0",
@@ -45,8 +39,19 @@
45
39
  "clean-package": "^2.2.0",
46
40
  "rimraf": "^6.0.1"
47
41
  },
48
- "scripts": {
49
- "clean": "rimraf dist tsconfig.build.tsbuildinfo",
50
- "tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
51
- }
52
- }
42
+ "title": "a-static",
43
+ "vonaModule": {
44
+ "dependencies": {},
45
+ "metas": {
46
+ "static": {
47
+ "scopeResource": true,
48
+ "boilerplate": "static/boilerplate"
49
+ },
50
+ "asset": {
51
+ "scopeResource": true,
52
+ "boilerplate": "asset/boilerplate"
53
+ }
54
+ }
55
+ },
56
+ "gitHead": "991189da4443b789fcf77872990b901ccf43bccb"
57
+ }
@@ -0,0 +1,93 @@
1
+ // eslint-disable
2
+ /** middlewareSystem: begin */
3
+ export * from '../bean/middlewareSystem.static.ts';
4
+ import type { IMiddlewareSystemOptionsStatic } from '../bean/middlewareSystem.static.ts';
5
+ import 'vona-module-a-aspect';
6
+ declare module 'vona-module-a-aspect' {
7
+
8
+ export interface IMiddlewareSystemRecord {
9
+ 'a-static:static': IMiddlewareSystemOptionsStatic;
10
+ }
11
+
12
+
13
+ }
14
+ declare module 'vona-module-a-static' {
15
+
16
+ export interface MiddlewareSystemStatic {
17
+ /** @internal */
18
+ get scope(): ScopeModuleAStatic;
19
+ }
20
+
21
+ export interface MiddlewareSystemStatic {
22
+ get $beanFullName(): 'a-static.middlewareSystem.static';
23
+ get $onionName(): 'a-static:static';
24
+ get $onionOptions(): IMiddlewareSystemOptionsStatic;
25
+ }
26
+ }
27
+ /** middlewareSystem: end */
28
+ /** event: begin */
29
+ export * from '../bean/event.resolvePath.ts';
30
+
31
+ import 'vona';
32
+ declare module 'vona' {
33
+
34
+
35
+ }
36
+ declare module 'vona-module-a-static' {
37
+
38
+ export interface EventResolvePath {
39
+ /** @internal */
40
+ get scope(): ScopeModuleAStatic;
41
+ }
42
+
43
+ export interface EventResolvePath {
44
+ get $beanFullName(): 'a-static.event.resolvePath';
45
+ get $onionName(): 'a-static:resolvePath';
46
+
47
+ }
48
+ }
49
+ /** event: end */
50
+ /** event: begin */
51
+ import type { EventResolvePath } from '../bean/event.resolvePath.ts';
52
+ export interface IModuleEvent {
53
+ 'resolvePath': EventResolvePath;
54
+ }
55
+ /** event: end */
56
+ /** event: begin */
57
+ import type { TypeEventResolvePathData, TypeEventResolvePathResult } from '../bean/event.resolvePath.ts';
58
+ import type { EventOn } from 'vona-module-a-event';
59
+ declare module 'vona-module-a-event' {
60
+ export interface IEventRecord {
61
+ 'a-static:resolvePath': EventOn<TypeEventResolvePathData, TypeEventResolvePathResult>;
62
+ }
63
+ }
64
+ /** event: end */
65
+ /** scope: begin */
66
+ import { BeanScopeBase, type BeanScopeUtil } from 'vona';
67
+ import { Scope } from 'vona-module-a-bean';
68
+
69
+ @Scope()
70
+ export class ScopeModuleAStatic extends BeanScopeBase {}
71
+
72
+ export interface ScopeModuleAStatic {
73
+ util: BeanScopeUtil;
74
+ event: IModuleEvent;
75
+ }
76
+
77
+ import 'vona';
78
+ declare module 'vona' {
79
+ export interface IBeanScopeRecord {
80
+ 'a-static': ScopeModuleAStatic;
81
+ }
82
+
83
+ export interface IBeanScopeContainer {
84
+ static: ScopeModuleAStatic;
85
+ }
86
+
87
+
88
+
89
+
90
+
91
+
92
+ }
93
+ /** scope: end */
@@ -0,0 +1,2 @@
1
+ export const __ThisModule__ = 'a-static';
2
+ export { ScopeModuleAStatic as ScopeModule } from './index.ts';
@@ -0,0 +1,14 @@
1
+ import { BeanEventBase, Event } from 'vona-module-a-event';
2
+
3
+ import type { IMiddlewareSystemOptionsStatic } from './middlewareSystem.static.ts';
4
+
5
+ export interface TypeEventResolvePathData {
6
+ dir: string;
7
+ filename: string;
8
+ options: IMiddlewareSystemOptionsStatic;
9
+ }
10
+
11
+ export type TypeEventResolvePathResult = string | true | undefined;
12
+
13
+ @Event()
14
+ export class EventResolvePath extends BeanEventBase<TypeEventResolvePathData, TypeEventResolvePathResult> {}
@@ -0,0 +1,179 @@
1
+ import type { Next, VonaContext } from 'vona';
2
+ import type { IDecoratorMiddlewareSystemOptions, IMiddlewareSystemExecute } from 'vona-module-a-aspect';
3
+
4
+ import staticCache from '@cabloy/koa-static-cache';
5
+ import { isObject, isString } from '@cabloy/utils';
6
+ import range from 'koa-range';
7
+ import assert from 'node:assert';
8
+ import { existsSync, mkdirSync } from 'node:fs';
9
+ import path from 'node:path';
10
+ import { BeanBase, compose } from 'vona';
11
+ import { MiddlewareSystem } from 'vona-module-a-aspect';
12
+ import { LRU } from 'ylru';
13
+
14
+ import { __ThisModule__ } from '../.metadata/this.ts';
15
+ import { SymbolStaticGetFullPathInner } from '../types/static.ts';
16
+
17
+ interface IStaticDirItem {
18
+ prefix: string;
19
+ dir: string;
20
+ }
21
+
22
+ export interface IMiddlewareSystemOptionsStatic extends IDecoratorMiddlewareSystemOptions {
23
+ apiStaticPrefix: string;
24
+ dir?: string;
25
+ dirs: (string | IStaticDirItem)[];
26
+ // support lazy load
27
+ dynamic: boolean;
28
+ preload: boolean;
29
+ buffer?: boolean;
30
+ maxFiles: number;
31
+ maxAge?: number;
32
+ alias: Record<string, string>;
33
+ getFullPath: typeof getFullPath;
34
+ }
35
+
36
+ @MiddlewareSystem<IMiddlewareSystemOptionsStatic>({
37
+ dependencies: 'a-security:securities',
38
+ apiStaticPrefix: '/api/static/',
39
+ dirs: [],
40
+ dynamic: true,
41
+ preload: false,
42
+ maxFiles: 1000,
43
+ alias: {
44
+ '/favicon.ico': '/api/static/home/index/img/vona.png',
45
+ },
46
+ getFullPath,
47
+ // maxAge: undefined,
48
+ // buffer: false,
49
+ // dir: '',
50
+ // prefix: '/', // should be always '/', so as to support ssr site
51
+ })
52
+ export class MiddlewareSystemStatic extends BeanBase implements IMiddlewareSystemExecute {
53
+ private _composer: any;
54
+
55
+ async execute(options: IMiddlewareSystemOptionsStatic, next: Next) {
56
+ return this._getComposer(options)(this.ctx, next);
57
+ }
58
+
59
+ _getComposer(options: IMiddlewareSystemOptionsStatic) {
60
+ if (!this._composer) {
61
+ const middlewares = this._createMiddlewares(options);
62
+ this._composer = compose(middlewares);
63
+ }
64
+ return this._composer;
65
+ }
66
+
67
+ _createMiddlewares(options: IMiddlewareSystemOptionsStatic) {
68
+ options = Object.assign(
69
+ {
70
+ maxAge: this.app.meta.isProd ? 31536000 : 0,
71
+ buffer: !!this.app.meta.isProd,
72
+ dir: this.app.config.server.publicDir,
73
+ prefix: '/',
74
+ },
75
+ options,
76
+ );
77
+
78
+ const dirs = (options.dirs || []).concat(options.dir!);
79
+
80
+ const prefixs: string[] = [];
81
+
82
+ function rangeMiddleware(ctx, next) {
83
+ // if match static file, and use range middleware.
84
+ const isMatch = prefixs.some(p => ctx.path.startsWith(p));
85
+ if (isMatch) {
86
+ return range(ctx, next);
87
+ }
88
+ return next();
89
+ }
90
+
91
+ const middlewares = [rangeMiddleware];
92
+
93
+ for (const dirObj of dirs) {
94
+ assert(isObject(dirObj) || isString(dirObj), '`config.static.dir` must be `string | Array<string|object>`.');
95
+
96
+ let newOptions: any;
97
+
98
+ if (isString(dirObj)) {
99
+ // copy origin options to new options ensure the safety of objects
100
+ newOptions = Object.assign({}, options, { dir: dirObj });
101
+ } else {
102
+ assert(isString(dirObj.dir), '`config.static.dir` should contains `[].dir` property when object style.');
103
+ newOptions = Object.assign({}, options, dirObj);
104
+ }
105
+
106
+ if (newOptions.dynamic && !newOptions.files) {
107
+ newOptions.files = new LRU(newOptions.maxFiles);
108
+ }
109
+
110
+ if (newOptions.prefix) {
111
+ prefixs.push(newOptions.prefix);
112
+ }
113
+
114
+ // ensure directory exists
115
+ if (!existsSync(newOptions.dir)) {
116
+ mkdirSync(newOptions.dir, { recursive: true });
117
+ }
118
+
119
+ middlewares.push(staticCache(newOptions));
120
+ }
121
+
122
+ return middlewares;
123
+ }
124
+ }
125
+
126
+ async function getFullPath(
127
+ ctx: VonaContext,
128
+ dir: string,
129
+ filename: string,
130
+ options: IMiddlewareSystemOptionsStatic,
131
+ ): Promise<string | true | undefined> {
132
+ if (process.env.META_MODE === 'dev') {
133
+ ctx[SymbolStaticGetFullPathInner] = () => {
134
+ return _getFullPathInner(ctx, dir, filename, options);
135
+ };
136
+ }
137
+ const scopeSelf = ctx.app.scope(__ThisModule__);
138
+ return scopeSelf.event.resolvePath.emit({ dir, filename, options }, ({ dir, filename, options }) => {
139
+ return _getFullPathInner(ctx, dir, filename, options);
140
+ });
141
+ }
142
+
143
+ async function _getFullPathInner(
144
+ ctx: VonaContext,
145
+ dir: string,
146
+ filename: string,
147
+ options: IMiddlewareSystemOptionsStatic,
148
+ ): Promise<string | undefined> {
149
+ // trim prefix
150
+ if (options.apiStaticPrefix !== '/') {
151
+ const filePrefix = path.normalize(options.apiStaticPrefix.replace(/^\//, ''));
152
+ if (filename.indexOf(filePrefix) !== 0) {
153
+ return;
154
+ // cannot throw error
155
+ // throw new Error(`invalid filename: ${filename}`);
156
+ }
157
+ filename = filename.slice(filePrefix.length);
158
+ }
159
+ // check
160
+ const parts = filename.split(path.sep);
161
+ const wordFirst = parts.shift();
162
+ // public
163
+ if (wordFirst === 'public') {
164
+ const fullPath = path.normalize(path.join(dir, parts.join(path.sep)));
165
+ // files that can be accessd should be under options.dir
166
+ if (fullPath.indexOf(dir) !== 0) throw new Error(`unsafe filename: ${filename}`);
167
+ return fullPath;
168
+ }
169
+ // static
170
+ const moduleRelativeName = `${wordFirst}-${parts.shift()}`;
171
+ const module = ctx.app.meta.modules[moduleRelativeName];
172
+ if (!module) {
173
+ return;
174
+ // cannot throw error
175
+ // throw new Error(`invalid filename: ${filename}`);
176
+ }
177
+ const fullPath = ctx.app.util.getAssetPathPhysical(moduleRelativeName, 'static', parts.join(path.sep));
178
+ return fullPath;
179
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './.metadata/index.ts';
2
+ export * from './lib/index.ts';
3
+ export * from './types/index.ts';
@@ -0,0 +1,7 @@
1
+ import { BeanBase, SymbolModuleBelong } from 'vona';
2
+
3
+ export class BeanAssetBase<IAssetGetPath> extends BeanBase {
4
+ get<K extends keyof IAssetGetPath, V extends IAssetGetPath[K]>(scene: K, assetPath: V): string {
5
+ return this.app.util.getAssetPathPhysical(this[SymbolModuleBelong], scene as any, assetPath as any);
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ import { BeanBase, SymbolModuleBelong } from 'vona';
2
+
3
+ export class BeanStaticBase<TypeStaticGetPath> extends BeanBase {
4
+ get(path: TypeStaticGetPath): string {
5
+ return this.app.util.combineStaticPath(path as string, this[SymbolModuleBelong]);
6
+ }
7
+
8
+ getURL(path: TypeStaticGetPath): string {
9
+ const path2 = this.get(path);
10
+ return this.app.util.getAbsoluteUrl(path2);
11
+ }
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from './beanAssetBase.ts';
2
+ export * from './beanStaticBase.ts';
@@ -0,0 +1 @@
1
+ export * from './static.ts';
@@ -0,0 +1,7 @@
1
+ export const SymbolStaticGetFullPathInner = Symbol('SymbolStaticGetFullPathInner');
2
+
3
+ declare module 'vona-module-a-meta' {
4
+ export interface IMetaNameRecord {
5
+ static: never;
6
+ }
7
+ }