vona-module-a-static 5.0.19 → 5.0.22

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.
@@ -0,0 +1,7 @@
1
+ import { Meta } from 'vona-module-a-meta';
2
+ import { BeanAssetBase } from 'vona-module-a-static';
3
+
4
+ export interface I<%=argv.beanNameCapitalize%>GetPath {}
5
+
6
+ @Meta()
7
+ export class Meta<%=argv.beanNameCapitalize%> extends BeanAssetBase<I<%=argv.beanNameCapitalize%>GetPath> {}
@@ -1,9 +1,7 @@
1
1
  import { Meta } from 'vona-module-a-meta';
2
2
  import { BeanStaticBase } from 'vona-module-a-static';
3
3
 
4
- export interface Meta<%=argv.beanNameCapitalize%> {
5
- get(path: 'path'): string;
6
- }
4
+ export type Type<%=argv.beanNameCapitalize%>GetPath = never;
7
5
 
8
6
  @Meta()
9
- export class Meta<%=argv.beanNameCapitalize%> extends BeanStaticBase {}
7
+ export class Meta<%=argv.beanNameCapitalize%> extends BeanStaticBase<Type<%=argv.beanNameCapitalize%>GetPath> {}
package/dist/index.js CHANGED
@@ -118,7 +118,7 @@ async function _getFullPathInner(ctx, dir, filename, options) {
118
118
  // trim prefix
119
119
  if (options.apiStaticPrefix !== '/') {
120
120
  const filePrefix = path.normalize(options.apiStaticPrefix.replace(/^\//, ''));
121
- if (filename.indexOf(filePrefix) !== 0) return;
121
+ if (filename.indexOf(filePrefix) !== 0) throw new Error(`invalid filename: ${filename}`);
122
122
  filename = filename.slice(filePrefix.length);
123
123
  }
124
124
  // check
@@ -128,13 +128,13 @@ async function _getFullPathInner(ctx, dir, filename, options) {
128
128
  if (wordFirst === 'public') {
129
129
  const fullPath = path.normalize(path.join(dir, parts.join(path.sep)));
130
130
  // files that can be accessd should be under options.dir
131
- if (fullPath.indexOf(dir) !== 0) return;
131
+ if (fullPath.indexOf(dir) !== 0) throw new Error(`unsafe filename: ${filename}`);
132
132
  return fullPath;
133
133
  }
134
134
  // static
135
135
  const moduleRelativeName = `${wordFirst}-${parts.shift()}`;
136
136
  const module = ctx.app.meta.modules[moduleRelativeName];
137
- if (!module) return;
137
+ if (!module) throw new Error(`invalid filename: ${filename}`);
138
138
  const fullPath = ctx.app.util.getAssetPathPhysical(moduleRelativeName, 'static', parts.join(path.sep));
139
139
  return fullPath;
140
140
  }
@@ -151,14 +151,16 @@ let ScopeModuleAStatic = (_dec = Scope(), _dec2 = BeanInfo({
151
151
 
152
152
  /** scope: end */
153
153
 
154
+ class BeanAssetBase extends BeanBase {
155
+ get(scene, assetPath) {
156
+ return this.app.util.getAssetPathPhysical(this[SymbolModuleBelong], scene, assetPath);
157
+ }
158
+ }
159
+
154
160
  class BeanStaticBase extends BeanBase {
155
- __get__(prop) {
156
- if (prop === 'get') {
157
- return path => {
158
- return this.app.util.combineStaticPath(path, this[SymbolModuleBelong]);
159
- };
160
- }
161
+ get(path) {
162
+ return this.app.util.combineStaticPath(path, this[SymbolModuleBelong]);
161
163
  }
162
164
  }
163
165
 
164
- export { BeanStaticBase, EventResolvePath, MiddlewareSystemStatic, ScopeModuleAStatic, SymbolStaticGetFullPathInner };
166
+ export { BeanAssetBase, BeanStaticBase, EventResolvePath, MiddlewareSystemStatic, ScopeModuleAStatic, SymbolStaticGetFullPathInner };
@@ -0,0 +1,4 @@
1
+ import { BeanBase } from 'vona';
2
+ export declare class BeanAssetBase<IAssetGetPath> extends BeanBase {
3
+ get<K extends keyof IAssetGetPath, V extends IAssetGetPath[K]>(scene: K, assetPath: V): string;
4
+ }
@@ -1,4 +1,4 @@
1
1
  import { BeanBase } from 'vona';
2
- export declare class BeanStaticBase extends BeanBase {
3
- protected __get__(prop: string): ((path: string) => string) | undefined;
2
+ export declare class BeanStaticBase<TypeStaticGetPath> extends BeanBase {
3
+ get(path: TypeStaticGetPath): string;
4
4
  }
@@ -1 +1,2 @@
1
+ export * from './beanAssetBase.ts';
1
2
  export * from './beanStaticBase.ts';
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "vona-module-a-static",
3
3
  "type": "module",
4
- "version": "5.0.19",
4
+ "version": "5.0.22",
5
5
  "title": "a-static",
6
6
  "vonaModule": {
7
7
  "dependencies": {},
8
8
  "metas": {
9
9
  "static": {
10
10
  "scopeResource": true,
11
- "boilerplate": "cli/boilerplate"
11
+ "boilerplate": "cli/static/boilerplate"
12
+ },
13
+ "asset": {
14
+ "scopeResource": true,
15
+ "boilerplate": "cli/asset/boilerplate"
12
16
  }
13
17
  }
14
18
  },