@rws-framework/client 2.15.5 → 2.16.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.
@@ -9,6 +9,7 @@ module.exports = async function(content) {
9
9
  const isDev = this._compiler.options.mode === 'development';
10
10
  const saveFile = content.indexOf('@save') > -1;
11
11
  const plugin = new RWSScssPlugin({
12
+ appRootDir: this.query?.appRootDir,
12
13
  rwsWorkspaceDir: this.query?.rwsWorkspaceDir
13
14
  });
14
15
  let fromTs = false;
@@ -61,6 +61,7 @@ module.exports = async function(content) {
61
61
  try {
62
62
  if(tagName){
63
63
  const [template, htmlFastImports, templateExists] = await LoadersHelper.getTemplate(filePath, this.addDependency, templateName, isDev);
64
+
64
65
  const styles = await LoadersHelper.getStyles(filePath, this.query?.rwsWorkspaceDir, this.query?.appRootDir,this.addDependency, templateExists, stylesPath, isDev);
65
66
 
66
67
  if(className){
@@ -69,7 +70,7 @@ module.exports = async function(content) {
69
70
  if(replacedViewDecoratorContent){
70
71
  processedContent = `${template}\n${styles}\n${replacedViewDecoratorContent}`;
71
72
  }
72
- }
73
+ }
73
74
 
74
75
  processedContent = `${htmlFastImports ? htmlFastImports + '\n' : ''}${processedContent}`;
75
76
  }
@@ -63,12 +63,10 @@ const RWSWebpackWrapper = async (appRoot, rwsFrontendConfig, _packageDir) => {
63
63
  const WEBPACK_AFTER_ACTIONS = rwsFrontendConfig.actions || [];
64
64
  const WEBPACK_AFTER_ERROR_ACTIONS = rwsFrontendConfig.error_actions || [];
65
65
 
66
- const modules_setup = [path.resolve(tools.findRootWorkspacePath(executionDir), 'node_modules')];
67
-
66
+ const modules_setup = [path.join(_packageDir, 'node_modules'), path.join(executionDir, 'node_modules'), path.join(tools.findRootWorkspacePath(appRoot), 'node_modules')];
68
67
  let optimConfig = null;
69
68
  let aliases = rwsFrontendConfig.aliases || {};
70
-
71
- aliases = { ...aliases, ...loadAliases(_packageDir, path.resolve(_MAIN_PACKAGE, 'node_modules'), executionDir) }
69
+ aliases = { ...aliases, ...loadAliases(_packageDir, tsConfig,path.resolve(_MAIN_PACKAGE, 'node_modules'), executionDir) }
72
70
 
73
71
  // #SECTION PLUGIN STARTING HOOKS
74
72
 
@@ -115,7 +113,7 @@ const RWSWebpackWrapper = async (appRoot, rwsFrontendConfig, _packageDir) => {
115
113
  }
116
114
 
117
115
  // #SECTION RWS WEBPACK BUILD
118
- const cfgExport = createWebpackConfig({
116
+ const cfgExport = await createWebpackConfig({
119
117
  executionDir,
120
118
  _packageDir,
121
119
  isDev,
@@ -52,7 +52,7 @@ class RWSScssPlugin {
52
52
  scssPath = _scss_import.processImportPath(scssPath, this.getRWSWorkspaceDir(), this.getRWSRootDir(),path.dirname(scssPath))
53
53
 
54
54
 
55
- let scssCode = _scss_fs.getCodeFromFile(scssPath, this.getRWSWorkspaceDir());
55
+ let scssCode = _scss_fs.getCodeFromFile(scssPath, this.getRWSWorkspaceDir(), this.getRWSRootDir());
56
56
 
57
57
  return await _scss_compiler.compileScssCode(scssCode, path.dirname(scssPath), this.getRWSWorkspaceDir(), this.getRWSRootDir());
58
58
  }
@@ -70,7 +70,7 @@ class RWSScssPlugin {
70
70
  }
71
71
 
72
72
  getRWSRootDir() {
73
- return this.rwsWorkspaceDir;
73
+ return this.appRootDir;
74
74
  }
75
75
  }
76
76
 
@@ -13,9 +13,9 @@ function processImportPath(importPath, rwsWorkspaceDir, appRootDir, fileRootDir
13
13
  _scss_fs = _scss_fs_builder(this);
14
14
  const workspaceDir = this.getRWSWorkspaceDir ? this.getRWSWorkspaceDir() : rwsWorkspaceDir;
15
15
  const appRoot = this.getRWSWorkspaceDir ? this.getRWSRootDir() : appRootDir;
16
-
16
+
17
17
  if (importPath.split('')[0] === '~') {
18
- return fillSCSSExt(replaceWithNodeModules(importPath, appRootDir, null, true), noext);
18
+ return fillSCSSExt(replaceWithNodeModules(importPath, appRoot, null, true), noext);
19
19
  }
20
20
 
21
21
  if (importPath.indexOf('@rws-mixins') === 0) {
@@ -67,26 +67,6 @@ function underscorePath(path, noext = false) {
67
67
  return partSplit.join('/');
68
68
  }
69
69
 
70
- function fillSCSSExt(scssPath, noext = false) {
71
- const underscoredPath = underscorePath(scssPath, noext);
72
- if (!fs.existsSync(scssPath) && fs.existsSync(underscoredPath)) {
73
- return underscoredPath;
74
- }
75
-
76
- if (noext) {
77
- return scssPath;
78
- }
79
-
80
- if ((!fs.existsSync(scssPath) || (fs.existsSync(scssPath) && fs.statSync(scssPath).isDirectory())) && fs.existsSync(`${scssPath}.scss`)) {
81
- return `${scssPath}.scss`;
82
- }
83
-
84
- if (fs.existsSync(`_${scssPath}.scss`)) {
85
- return `${scssPath}.scss`;
86
- }
87
-
88
- return scssPath;
89
- }
90
70
 
91
71
  function fillSCSSExt(scssPath, noext = false) {
92
72
  const underscoredPath = underscorePath(scssPath, noext);
@@ -157,7 +137,8 @@ function detectImports(code) {
157
137
 
158
138
  function replaceWithNodeModules(input, appRootDir, fileDir = null, absolute = false, token = '~') {
159
139
  _scss_fs = _scss_fs_builder(this);
160
- return input.replace(token, absolute ? `${path.resolve(appRootDir, 'node_modules')}/` : this.node_modules_dir(fileDir ? fileDir : appRootDir));
140
+
141
+ return input.replace(token, absolute ? `${path.join(appRootDir, 'node_modules')}/` : this.node_modules_dir(fileDir ? fileDir : appRootDir));
161
142
  }
162
143
 
163
144
  function processImports(imports, fileRootDir, rwsWorkspaceDir, importStorage = {}, sub = false) {
@@ -184,8 +165,8 @@ function processImports(imports, fileRootDir, rwsWorkspaceDir, importStorage = {
184
165
  const appRoot = this.getRWSWorkspaceDir ? this.getRWSRootDir() : importData[4];
185
166
 
186
167
  let importPath = processImportPath(originalImportPath, workspaceDir, appRoot, fileRootDir);
187
-
188
- let replacedScssContent = getStorage(importPath, _scss_fs.getCodeFromFile(importPath, workspaceDir).replace(/\/\*[\s\S]*?\*\//g, ''));
168
+
169
+ let replacedScssContent = getStorage(importPath, _scss_fs.getCodeFromFile(importPath, workspaceDir, appRoot).replace(/\/\*[\s\S]*?\*\//g, ''));
189
170
 
190
171
  const recursiveImports = extractScssImports(replacedScssContent, workspaceDir, appRoot, importPath)[0];
191
172
 
@@ -1,8 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import { RWSConfigBuilder, rwsPath } from '@rws-framework/console';
3
- import { _DEFAULT_CONFIG } from '../../_default.cfg';
3
+ // import { _DEFAULT_CONFIG } from '../../_default.cfg';
4
4
 
5
- import { IRWSPlugin } from '../../../src/types/IRWSPlugin';
5
+ import { IPluginSpawnOption, IRWSPlugin, IStaticRWSPlugin } from '../../../src/types/IRWSPlugin';
6
6
 
7
7
  interface IRWSViteConfig {
8
8
  executionDir: string;
@@ -24,25 +24,23 @@ interface IRWSViteConfig {
24
24
  devDebug?: any,
25
25
  devRouteProxy?: any,
26
26
  tsConfigPath: string,
27
- rwsPlugins?: {
28
- [key: string]: IRWSPlugin
29
- },
27
+ rwsPlugins?: IPluginSpawnOption<any>[],
30
28
  _packageDir?: string,
31
29
  BuildConfigurator: RWSConfigBuilder<any>
32
30
  }
33
31
 
34
- async function getBuildConfig(rwsFrontBuildConfig): Promise<IRWSViteConfig>
32
+ async function getBuildConfig(rwsFrontBuildConfig: Partial<IRWSViteConfig>): Promise<IRWSViteConfig>
35
33
  {
36
- const BuildConfigurator = new RWSConfigBuilder(rwsPath.findPackageDir(process.cwd()) + '/.rws.json', {..._DEFAULT_CONFIG, ...rwsFrontBuildConfig});
34
+ const BuildConfigurator = new RWSConfigBuilder(rwsPath.findPackageDir(process.cwd()) + '/.rws.json', {...rwsFrontBuildConfig});
37
35
  const _packageDir = rwsPath.findPackageDir(process.cwd());
38
36
 
39
37
  const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || rwsFrontBuildConfig.executionDir || process.cwd(), _packageDir);
40
38
  const isWatcher = process.argv.includes('--watch') || false;
41
39
 
42
- const isDev = isWatcher ? true : (BuildConfigurator.get('dev', rwsFrontBuildConfig.dev) || false);
43
- const isHotReload = BuildConfigurator.get('hot', rwsFrontBuildConfig.hot);
44
- const isReport = BuildConfigurator.get('report', rwsFrontBuildConfig.report);
45
- const isParted = BuildConfigurator.get('parted', rwsFrontBuildConfig.parted || false);
40
+ const isDev = isWatcher ? true : (BuildConfigurator.get('dev', rwsFrontBuildConfig.isDev) || false);
41
+ const isHotReload = BuildConfigurator.get('isHotReload', rwsFrontBuildConfig.isHotReload);
42
+ const isReport = BuildConfigurator.get('isReport', rwsFrontBuildConfig.isReport);
43
+ const isParted = BuildConfigurator.get('isParted', rwsFrontBuildConfig.isParted || false);
46
44
 
47
45
  const partedPrefix = BuildConfigurator.get('partedPrefix', rwsFrontBuildConfig.partedPrefix);
48
46
  const partedDirUrlPrefix = BuildConfigurator.get('partedDirUrlPrefix', rwsFrontBuildConfig.partedDirUrlPrefix);
@@ -53,7 +51,7 @@ async function getBuildConfig(rwsFrontBuildConfig): Promise<IRWSViteConfig>
53
51
 
54
52
  const outputFileName = BuildConfigurator.get('outputFileName') || rwsFrontBuildConfig.outputFileName;
55
53
  const publicDir = BuildConfigurator.get('publicDir') || rwsFrontBuildConfig.publicDir;
56
- const serviceWorkerPath = BuildConfigurator.get('serviceWorker') || rwsFrontBuildConfig.serviceWorker;
54
+ const serviceWorkerPath = BuildConfigurator.get('serviceWorkerPath') || rwsFrontBuildConfig.serviceWorkerPath;
57
55
 
58
56
  const publicIndex = BuildConfigurator.get('publicIndex') || rwsFrontBuildConfig.publicIndex;
59
57
 
@@ -68,14 +66,14 @@ async function getBuildConfig(rwsFrontBuildConfig): Promise<IRWSViteConfig>
68
66
 
69
67
  const tsConfigPath = rwsPath.relativize(BuildConfigurator.get('tsConfigPath') || rwsFrontBuildConfig.tsConfigPath, executionDir);
70
68
 
71
- const rwsPlugins = {};
69
+ const rwsPlugins: IPluginSpawnOption<any>[] = [];
72
70
 
73
- if(rwsFrontBuildConfig.rwsPlugins){
74
- for(const pluginEntry of rwsFrontBuildConfig.rwsPlugins){
75
- const pluginBuilder = (await import(`${pluginEntry}`)).default;
76
- rwsPlugins[pluginEntry] = new pluginBuilder(BuildConfigurator, rwsFrontBuildConfig);
77
- }
78
- }
71
+ // if(rwsFrontBuildConfig.rwsPlugins){
72
+ // for(const pluginEntry of Object.values(rwsFrontBuildConfig.rwsPlugins)){
73
+ // const pluginBuilder = (await import(`${pluginEntry}`)).default as IStaticRWSPlugin<any>;
74
+ // rwsPlugins[pluginEntry] = new pluginBuilder(BuildConfigurator, rwsFrontBuildConfig);
75
+ // }
76
+ // }
79
77
 
80
78
  return {
81
79
  executionDir,
@@ -1,3 +1,3 @@
1
- import { createViteConfig } from './vite_config';
1
+ import { getBuildConfig } from './_build_config';
2
2
 
3
- export { createViteConfig };
3
+ export { getBuildConfig };
@@ -1,9 +1,22 @@
1
1
  const path = require('path');
2
2
 
3
- function loadAliases(packageDir, nodeModulesPath, srcDir){
3
+ function loadAliases(packageDir, tsConfig, nodeModulesPath, executionDir){
4
+
5
+ const tsPaths = {}
6
+
7
+ for(const aliasKey of Object.keys(tsConfig.config.compilerOptions.paths)){
8
+ const alias = tsConfig.config.compilerOptions.paths[aliasKey];
9
+ tsPaths[aliasKey] = path.resolve(executionDir, alias[0]);
10
+ }
11
+
4
12
  return {
5
- '@rws-framework/foundation': path.resolve(packageDir, 'foundation', 'rws-foundation.js')
13
+ ...tsPaths,
14
+ '@rws-framework/foundation': path.resolve(packageDir, 'foundation', 'rws-foundation.js'),
15
+ '@rws-framework/foundation/*': path.resolve(packageDir, 'foundation', '*'),
16
+ // 'entities/lib/maps/entities.json': path.resolve(nodeModulesPath, 'entities/lib/maps/entities.json'),
17
+ // 'entities/lib/maps/legacy.json': path.resolve(nodeModulesPath, 'entities/lib/maps/legacy.json'),
18
+ // 'entities/lib/maps/xml.json': path.resolve(nodeModulesPath, 'entities/lib/maps/xml.json')
6
19
  }
7
20
  }
8
21
 
9
- module.exports = { loadAliases }
22
+ module.exports = { loadAliases }
@@ -5,6 +5,7 @@ const { RWSConfigBuilder } = require('@rws-framework/console')
5
5
  const { rwsPath } = require('@rws-framework/console');
6
6
  const { _DEFAULT_CONFIG } = require('../../_default.cfg');
7
7
 
8
+
8
9
  async function getBuildConfig(rwsFrontBuildConfig, _packageDir){
9
10
  const BuildConfigurator = new RWSConfigBuilder(path.join(rwsPath.findPackageDir(process.cwd()), '.rws.json'), {..._DEFAULT_CONFIG, ...rwsFrontBuildConfig});
10
11
  const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || rwsFrontBuildConfig.executionDir || process.env.RWS_APP_ROOT || process.cwd(), _packageDir);
@@ -37,7 +38,7 @@ async function getBuildConfig(rwsFrontBuildConfig, _packageDir){
37
38
 
38
39
  const devRouteProxy = BuildConfigurator.get('devRouteProxy') || rwsFrontBuildConfig.devRouteProxy;
39
40
 
40
- const tsConfig = BuildConfigurator.get('tsConfig') || rwsFrontBuildConfig.tsConfig;
41
+ const tsConfig = await (BuildConfigurator.get('tsConfig') || rwsFrontBuildConfig.tsConfig)(_packageDir, true, false);
41
42
 
42
43
  const rwsPlugins = {};
43
44
 
@@ -10,8 +10,14 @@ function processEnvDefines(BuildConfigurator, config, devDebug) {
10
10
  const rwsDefines = BuildConfigurator.get('env') || config.env || null;
11
11
 
12
12
  if (rwsDefines) {
13
- _rws_defines = { ..._rws_defines, ...rwsDefines }
13
+ const stringifiedDefines = Object.entries(rwsDefines).reduce((acc, [key, value]) => ({
14
+ ...acc,
15
+ [`process.env.${key}`]: JSON.stringify(value)
16
+ }), {});
17
+ _rws_defines = { ..._rws_defines, ...stringifiedDefines }
14
18
  }
19
+
20
+ console.log({_rws_defines});
15
21
 
16
22
  return _rws_defines;
17
23
  }
@@ -17,7 +17,7 @@ module.exports = {
17
17
  plugins: rwsPlugins
18
18
  });
19
19
 
20
- console.log(chalk.blue('\nTSCONFIG:'), util.inspect(tsConfig, {
20
+ console.log(chalk.blue('\nTSCONFIG:'), util.inspect(tsConfig.config, {
21
21
  depth: null,
22
22
  colors: true,
23
23
  maxArrayLength: null
@@ -10,12 +10,21 @@ const chalk = require('chalk');
10
10
  const { timingCounterStart, timingCounterStop } = require('./_timing');
11
11
  const { rwsRuntimeHelper, rwsPath } = require('@rws-framework/console');
12
12
 
13
- function getRWSLoaders(packageDir, executionDir, tsConfig, appRootDir, entrypoint) {
13
+ function getRWSLoaders(packageDir, executionDir, tsConfigData, appRootDir, entrypoint) {
14
14
  const scssLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_scss_loader.js');
15
15
  const tsLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_ts_loader.js');
16
16
  const htmlLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_html_loader.js');
17
17
 
18
+ const tsConfigPath = tsConfigData.path;
19
+
18
20
  const loaders = [
21
+ {
22
+ test: /\.json$/,
23
+ type: 'javascript/auto',
24
+ include: [
25
+ path.resolve(appRootDir, 'node_modules/entities/lib/maps')
26
+ ],
27
+ },
19
28
  {
20
29
  test: /\.html$/,
21
30
  use: [
@@ -30,14 +39,20 @@ function getRWSLoaders(packageDir, executionDir, tsConfig, appRootDir, entrypoin
30
39
  {
31
40
  loader: 'ts-loader',
32
41
  options: {
33
- ...tsConfig,
34
- configFile: false,
42
+ configFile: tsConfigPath,
43
+ compilerOptions: {
44
+ emitDecoratorMetadata: true,
45
+ experimentalDecorators: true,
46
+ target: "ES2018",
47
+ module: "commonjs"
48
+ },
35
49
  transpileOnly: false,
36
50
  logLevel: "info",
37
51
  logInfoToStdOut: true,
38
52
  context: executionDir,
39
53
  errorFormatter: (message, colors) => {
40
- const messageText = message.message || message;
54
+ console.log({message});
55
+ const messageText = typeof message === 'object' ? JSON.stringify(message, null, 2) : message;
41
56
  return `\nTS Error: ${messageText}\n`;
42
57
  },
43
58
  }
@@ -51,20 +66,25 @@ function getRWSLoaders(packageDir, executionDir, tsConfig, appRootDir, entrypoin
51
66
  }
52
67
  ],
53
68
  include: [
54
- path.resolve(executionDir, 'src'),
55
- path.resolve(packageDir, 'src'),
56
- path.resolve(packageDir, 'foundation', 'rws-foundation.d.ts')
69
+ ...tsConfigData.includes.map(item => item.abs()),
70
+ path.resolve(packageDir, 'foundation', 'rws-foundation.d.ts')
57
71
  ],
58
- exclude: [
59
- /node_modules\/(?!\@rws-framework\/[A-Z0-9a-z])/,
72
+ exclude: [
73
+ ...tsConfigData.excludes.map(item => item.abs()),
60
74
  /\.debug\.ts$/,
61
75
  /\.d\.ts$/
62
- ],
76
+ ]
63
77
  },
64
78
  {
65
79
  test: /\.scss$/i,
66
80
  use: [
67
- scssLoader,
81
+ {
82
+ loader: scssLoader,
83
+ options: {
84
+ rwsWorkspaceDir: executionDir,
85
+ appRootDir
86
+ }
87
+ },
68
88
  ],
69
89
  },
70
90
  ];
@@ -243,4 +263,4 @@ let rwsTemplate: any = T.html\`${templateContent}\`;
243
263
  return [template, htmlFastImports, templateExists];
244
264
  }
245
265
 
246
- module.exports = { getRWSLoaders, extractRWSViewArgs, getTemplate, getStyles }
266
+ module.exports = { getRWSLoaders, extractRWSViewArgs, getTemplate, getStyles }
File without changes
@@ -12,7 +12,7 @@ const _defaultOpts = {
12
12
  }
13
13
  }
14
14
 
15
- const externals = (pkgPath, declaredCodeBase, nodeModules, automatedChunks, externalOptions = _defaultOpts) => ({context, request}, callback) => {
15
+ const externals = (declaredCodeBase, nodeModules, automatedChunks, externalOptions = _defaultOpts) => ({context, request}, callback) => {
16
16
  let theOptions = _defaultOpts;
17
17
 
18
18
  if(externalOptions !== null){
@@ -21,24 +21,24 @@ const externals = (pkgPath, declaredCodeBase, nodeModules, automatedChunks, exte
21
21
 
22
22
  const codeBase = path.resolve(declaredCodeBase);
23
23
 
24
- const ignored = [
25
- // /css-loader/,
24
+ const ignored = [
26
25
  /tslib/,
27
26
  /reflect-metadata/,
28
- /\@microsoft\/fast-foundation\/.*/
27
+ /\@microsoft\/fast-foundation\/.*/,
29
28
  ]
30
29
 
31
- const enforced = [
32
- /entities/,
30
+ const enforced = [
33
31
  /\@microsoft\/fast-foundation\/.*\/di/,
34
- /\@microsoft\/fast-foundation\/.*\/foundation-element/
32
+ /\@microsoft\/fast-foundation\/.*\/foundation-element/,
35
33
  ]
36
34
 
37
35
  const frontendDirs = [
38
36
  codeBase,
39
- pkgPath
37
+ path.resolve(__dirname,'..','..','..')
40
38
  ];
41
39
 
40
+ console.log({frontendDirs})
41
+
42
42
  const inFrontendContext = frontendDirs.some(dir => context.startsWith(dir)) ||
43
43
  externalOptions._vars.frontendRequestContextCache.some(package => context.indexOf(package.request) > -1)
44
44
 
@@ -1,7 +1,8 @@
1
1
  const { getRWSLoaders } = require('./_loaders');
2
2
  const path = require('path');
3
3
 
4
- function createWebpackConfig({
4
+
5
+ async function createWebpackConfig({
5
6
  executionDir,
6
7
  _packageDir,
7
8
  isDev,
@@ -20,7 +21,8 @@ function createWebpackConfig({
20
21
  devExternalsVars,
21
22
  appRootDir,
22
23
  entrypoint
23
- }) {
24
+ }) {
25
+
24
26
  return {
25
27
  context: executionDir,
26
28
  entry: {
@@ -39,15 +41,19 @@ function createWebpackConfig({
39
41
  modules: modules_setup,
40
42
  alias: {
41
43
  ...aliases
44
+ },
45
+ fallback: {
46
+ fs: false,
47
+ path: false
42
48
  }
43
49
  },
44
50
  module: {
45
51
  rules: getRWSLoaders(_packageDir, executionDir, tsConfig, appRootDir, entrypoint),
46
52
  },
47
53
  plugins: WEBPACK_PLUGINS,
48
- externals: rwsExternals(_packageDir, executionDir, modules_setup, automatedChunks, {
49
- _vars: devExternalsVars
50
- })
54
+ // externals: rwsExternals(_packageDir, executionDir, modules_setup, automatedChunks, {
55
+ // _vars: devExternalsVars
56
+ // })
51
57
  }
52
58
  }
53
59
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.15.5",
4
+ "version": "2.16.0",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -32,6 +32,7 @@
32
32
  "@types/moment": "^2.13.0",
33
33
  "deepmerge": "^4.3.1",
34
34
  "dragula": "^3.7.3",
35
+ "entities": "6.0.0",
35
36
  "he": "^1.2.0",
36
37
  "json5": "^2.2.3",
37
38
  "lodash": "^4.17.21",
@@ -39,7 +40,7 @@
39
40
  "partial-json-parser": "^1.0.0",
40
41
  "reflect-metadata": "^0.2.2",
41
42
  "resolve-url-loader": "^5.0.0",
42
- "sanitize-html": "^2.12.1",
43
+ "sanitize-html": "^2.14.0",
43
44
  "socket.io-client": "^4.7.2",
44
45
  "upload": "^1.3.2",
45
46
  "url-router": "^13.0.0",
@@ -4,6 +4,7 @@ import { RWSClientInstance } from "../client";
4
4
  import { RWSPlugin, DefaultRWSPluginOptionsType } from "../plugins/_plugin";
5
5
  import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
6
6
  import deepmerge from 'deepmerge';
7
+ import { IPluginSpawnOption } from "../types/IRWSPlugin";
7
8
 
8
9
  type RWSInfoType = { components: string[] };
9
10
 
@@ -72,15 +73,12 @@ function get(this: RWSClientInstance, key: string): any | null
72
73
  return null;
73
74
  }
74
75
 
75
- type PluginConstructor<T extends DefaultRWSPluginOptionsType> = new (options: T) => RWSPlugin<T>;
76
- type RWSPluginEntry<T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> = IStaticRWSPlugin<T>;
77
-
78
- function addPlugin<T extends DefaultRWSPluginOptionsType>(this: RWSClientInstance, pluginEntry: RWSPluginEntry){
76
+ function addPlugin<T extends DefaultRWSPluginOptionsType>(this: RWSClientInstance, pluginEntry: IPluginSpawnOption<T>){
79
77
  const rwsWindow: RWSWindow = loadRWSRichWindow();
80
- const pluginClass: PluginConstructor<T> = (Array.isArray(pluginEntry) ? pluginEntry[0] : pluginEntry) as unknown as PluginConstructor<T>;
78
+ const pluginClass: IStaticRWSPlugin<T> = pluginEntry.pluginEntry;
81
79
  const pluginOptions: T = (Array.isArray(pluginEntry) ? pluginEntry[1] : { enabled: true }) as T;
82
80
 
83
- if(!Object.keys(rwsWindow.RWS.plugins).includes(pluginClass.name)){
81
+ if(!Object.keys(rwsWindow.RWS.plugins).find(item => { item === pluginClass.name })){
84
82
  const pluginInstance: RWSPlugin<T> = new pluginClass(pluginOptions);
85
83
  this.plugins[pluginClass.name] = pluginInstance;
86
84
  rwsWindow.RWS.plugins[pluginClass.name] = pluginInstance;
package/src/client.ts CHANGED
@@ -1,4 +1,4 @@
1
- import IRWSConfig, { RWSPluginEntry } from './types/IRWSConfig';
1
+ import IRWSConfig from './types/IRWSConfig';
2
2
 
3
3
  import RWSNotify from './types/RWSNotify';
4
4
 
@@ -25,14 +25,6 @@ import ConfigHelper from './client/config';
25
25
  import { DefaultRWSPluginOptionsType, RWSPlugin } from './plugins/_plugin';
26
26
  import { IStaticRWSPlugin } from './types/IRWSPlugin'
27
27
 
28
- interface IHotModule extends NodeModule {
29
- hot?: {
30
- accept(dependencies: string[], callback?: (updatedDependencies: string[]) => void): void;
31
- accept(dependency: string, callback?: () => void): void;
32
- accept(errHandler?: (err: Error) => void): void;
33
- dispose(callback: (data: any) => void): void;
34
- }
35
- }
36
28
 
37
29
  type RWSEventListener = (event: CustomEvent) => void;
38
30
 
@@ -74,9 +66,9 @@ class RWSClient {
74
66
  }
75
67
  }
76
68
 
77
- addPlugin<T extends DefaultRWSPluginOptionsType>(pluginEntry: IStaticRWSPlugin)
69
+ addPlugin<T extends DefaultRWSPluginOptionsType>(pluginEntry: IStaticRWSPlugin<T>, options?: T)
78
70
  {
79
- this.config.plugins.push(pluginEntry);
71
+ this.config.plugins.push({pluginEntry, options});
80
72
  }
81
73
 
82
74
  async setup(config: IRWSConfig = {}): Promise<IRWSConfig> {
@@ -210,4 +202,4 @@ class RWSClient {
210
202
  }
211
203
 
212
204
  export default DI.createInterface<RWSClient>(x => x.singleton(RWSClient));
213
- export { IHotModule, RWSClient as RWSClientInstance };
205
+ export { RWSClient as RWSClientInstance };
@@ -1,4 +1,4 @@
1
- import {DI, Container, Registration } from '../../foundation/rws-foundation';
1
+ import {DI, Container, Registration, InterfaceSymbol, Key } from '../../foundation/rws-foundation';
2
2
  import {loadRWSRichWindow} from '../types/RWSWindow';
3
3
 
4
4
  export default () => {
@@ -13,4 +13,4 @@ export default () => {
13
13
  return richWindow.RWS.container;
14
14
  };
15
15
 
16
- export { DI, Container, Registration }
16
+ export { DI, Container, Registration, InterfaceSymbol, Key }
package/src/index.ts CHANGED
@@ -21,9 +21,8 @@ import { RWSPlugin } from './plugins/_plugin';
21
21
 
22
22
  import type { DefaultRWSPluginOptionsType } from './plugins/_plugin';
23
23
 
24
- import type { IRWSPlugin, IStaticRWSPlugin } from './types/IRWSPlugin';
24
+ import type { IRWSPlugin, IStaticRWSPlugin, IPluginSpawnOption } from './types/IRWSPlugin';
25
25
  import RWSClient, { RWSClientInstance } from './client';
26
- import type { RWSPluginEntry } from './types/IRWSConfig';
27
26
  import type IRWSUser from './types/IRWSUser';
28
27
  import RWSViewComponent from './components/_component';
29
28
  import type { IAssetShowOptions } from './components/_component';
@@ -31,24 +30,39 @@ import type { IAssetShowOptions } from './components/_component';
31
30
  import RWSContainer from './components/_container';
32
31
 
33
32
  import type { RWSDecoratorOptions } from './components/_decorator';
33
+ import type { IKDBTypeInfo, IKDBTypesResponse } from './types/IBackendCore';
34
34
 
35
35
  import { RWSIgnore, RWSInject, RWSView } from './components/_decorator';
36
36
 
37
37
  import { declareRWSComponents } from './components';
38
38
 
39
39
  export default RWSClient;
40
+
41
+ export type {
42
+ IKDBTypeInfo, IKDBTypesResponse,
43
+ NotifyUiType,
44
+ NotifyLogType,
45
+ IBackendRoute as IRWSBackendRoute,
46
+ RWSDecoratorOptions as IRWSDecoratorOptions,
47
+ IHTTProute as IRWSHttpRoute,
48
+ IPrefixedHTTProutes as IRWSPrefixedHTTProutes,
49
+ IAssetShowOptions as IRWSAssetShowOptions,
50
+ IRWSConfig,
51
+ IRWSUser,
52
+ TagsProcessorType,
53
+ HTMLTagTransformerType,
54
+ HTMLTag,
55
+ HTMLAttributes
56
+ }
57
+
40
58
  export {
41
59
  RWSClient,
42
60
  RWSClientInstance,
43
61
 
44
62
  RWSPlugin,
45
- RWSPluginEntry,
63
+ IPluginSpawnOption,
46
64
  IRWSPlugin, IStaticRWSPlugin,
47
- DefaultRWSPluginOptionsType,
48
-
49
- NotifyUiType,
50
- NotifyLogType,
51
-
65
+ DefaultRWSPluginOptionsType,
52
66
  ApiServiceInstance,
53
67
  ApiService,
54
68
  UtilsServiceInstance,
@@ -64,18 +78,7 @@ export {
64
78
  ServiceWorkerService,
65
79
 
66
80
  RWSNotify,
67
- IBackendRoute as IRWSBackendRoute,
68
- RWSDecoratorOptions as IRWSDecoratorOptions,
69
- IHTTProute as IRWSHttpRoute,
70
- IPrefixedHTTProutes as IRWSPrefixedHTTProutes,
71
- IAssetShowOptions as IRWSAssetShowOptions,
72
- IRWSConfig,
73
- IRWSUser,
74
- TagsProcessorType,
75
- HTMLTagTransformerType,
76
- HTMLTag,
77
- HTMLAttributes,
78
-
81
+
79
82
  RWSView,
80
83
  sanitizedAttr,
81
84
  RWSIgnore,
@@ -3,62 +3,59 @@ import { Container } from "../components/_container";
3
3
  import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
4
4
  import IRWSUser from "../types/IRWSUser";
5
5
  import { RWSInfoType } from "../client/components";
6
- import { IRWSPlugin } from "../types/IRWSPlugin";
6
+ import { IRWSPlugin, IStaticRWSPlugin } from "../types/IRWSPlugin";
7
7
 
8
- type DefaultRWSPluginOptionsType = { enabled: boolean };
9
- type PluginInfoType = { name: string }
8
+ export type DefaultRWSPluginOptionsType = { enabled?: boolean };
9
+ type PluginInfoType = { name: string };
10
10
  type PluginConstructor<T extends DefaultRWSPluginOptionsType> = new (options: T) => RWSPlugin<T>;
11
- abstract class RWSPlugin<PluginOptions extends DefaultRWSPluginOptionsType> implements IRWSPlugin{
11
+
12
+ abstract class RWSPlugin<T extends DefaultRWSPluginOptionsType> extends IRWSPlugin<T> {
12
13
  protected isLoaded: boolean = false;
13
- protected options: PluginOptions;
14
- protected container: Container;
15
- protected window: RWSWindow;
14
+ protected options!: T;
15
+ protected container!: Container;
16
+ protected window!: RWSWindow;
16
17
 
17
18
  static container: Container;
18
19
  static window: RWSWindow;
19
20
 
20
- constructor(options: PluginOptions = { enabled: false } as PluginOptions){
21
+ constructor(options: T = { enabled: true } as T) {
22
+ super();
21
23
  this.isLoaded = true;
22
24
  this.container = RWSPlugin.container;
23
25
  this.window = RWSPlugin.window;
24
26
  this.options = options;
25
27
  }
26
28
 
27
- async onClientStart(): Promise<void>
28
- {
29
-
29
+ async onClientStart(): Promise<void> {
30
+ // Implementation
30
31
  }
31
32
 
32
- async onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void>
33
- {
34
-
33
+ async onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void> {
34
+ // Implementation
35
35
  }
36
36
 
37
- async onComponentsDeclare(): Promise<void>
38
- {
39
-
37
+ async onComponentsDeclare(): Promise<void> {
38
+ // Implementation
40
39
  }
41
40
 
42
- async onSetUser(user: IRWSUser): Promise<void>{
43
-
41
+ async onSetUser(user: IRWSUser): Promise<void> {
42
+ // Implementation
44
43
  }
45
-
46
44
 
47
-
48
- static getPlugin<Plugin extends RWSPlugin<T>, T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType>(pluginClass: PluginConstructor<T>): Plugin | null
49
- {
45
+ static getPlugin<P extends RWSPlugin<T>, T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType>(
46
+ pluginClass: IStaticRWSPlugin<T>
47
+ ): P | null {
50
48
  const plugin = this.window.RWS.plugins[pluginClass.name];
51
- return plugin ? plugin as Plugin : null;
49
+ return plugin ? plugin as P : null;
52
50
  }
53
51
 
54
-
55
- static getAllPlugins(): RWSPlugin<DefaultRWSPluginOptionsType>[]
56
- {
57
- return Object.keys(this.window.RWS.plugins).map((key) => this.window.RWS.plugins[key]);
52
+ static getAllPlugins(): Array<RWSPlugin<DefaultRWSPluginOptionsType>> {
53
+ return Object.keys(this.window.RWS.plugins)
54
+ .map((key) => this.window.RWS.plugins[key]);
58
55
  }
59
56
  }
60
57
 
61
58
  RWSPlugin.window = loadRWSRichWindow();
62
59
  RWSPlugin.container = RWSContainer();
63
60
 
64
- export { RWSPlugin, DefaultRWSPluginOptionsType }
61
+ export { RWSPlugin };
@@ -1,3 +1,4 @@
1
+ import { IKDBTypesResponse } from '../types/IBackendCore';
1
2
  import TheService from './_service';
2
3
 
3
4
  //@4DI
@@ -5,6 +6,8 @@ import ConfigService, { ConfigServiceInstance } from './ConfigService';
5
6
 
6
7
  import { upload, UploadResponse } from 'upload';
7
8
 
9
+ import { backend } from './_api/backend';
10
+ import { calls } from './_api/calls';
8
11
 
9
12
  interface RequestOptions {
10
13
  method?: string;
@@ -19,182 +22,49 @@ interface IAPIOptions {
19
22
  },
20
23
  }
21
24
 
22
- interface IHTTProute {
25
+ interface IHTTProute<P = {[key: string]: any}> {
23
26
  name: string;
24
- path: string;
27
+ path: string;
28
+ method: string;
29
+ noParams?: boolean;
30
+ options?: any;
31
+ plugins?: P
25
32
  }
26
33
 
27
-
28
- interface IPrefixedHTTProutes {
34
+ interface IPrefixedHTTProutes<P = {[key: string]: any}> {
29
35
  prefix: string;
30
- routes: IHTTProute[];
36
+ controllerName: string;
37
+ exportAutoRoutes?: boolean,
38
+ routes: IHTTProute<P>[];
31
39
  }
32
40
 
41
+
33
42
  type IBackendRoute = IHTTProute | IPrefixedHTTProutes;
34
43
 
35
44
 
36
- const _DEFAULT_CONTENT_TYPE = 'application/json';
37
45
 
38
46
  class ApiService extends TheService {
39
47
  static _DEFAULT: boolean = true;
40
48
  private token?: string;
41
49
 
42
- constructor(@ConfigService private config: ConfigServiceInstance) {
50
+ constructor(@ConfigService public config: ConfigServiceInstance) {
43
51
  super();
44
52
  }
45
53
 
46
- private addHeader(headers: Headers | [string, string][] | {[key: string]: string}, key: string, val: string)
47
- {
48
- if (headers instanceof Headers) {
49
- headers.append(key, val);
50
- } else if (Array.isArray(headers)) {
51
- headers.push([key, val]);
52
- } else {
53
- headers[key] = val;
54
- }
55
- }
56
-
57
- // Function to get headers
58
- private getHeaders(optHeaders: HeadersInit = {}): HeadersInit {
59
- const headers: HeadersInit = { ...optHeaders };
60
-
61
- if (!('Content-Type' in headers)) {
62
- this.addHeader(headers, 'Content-Type', _DEFAULT_CONTENT_TYPE);
63
- }
64
-
65
- if (this.token) {
66
- this.addHeader(headers, 'Authorization', `Bearer ${this.token}`);
67
- }
68
-
69
- if((headers as any)['Content-Type']){
70
- this.addHeader(headers, 'Accept', '*/*');
71
- }else{
72
- this.addHeader(headers, 'Accept', (headers as any)['Content-Type']);
73
- }
74
-
75
- return headers;
76
- }
77
-
78
54
  public setToken(token: string)
79
55
  {
80
56
  this.token = token;
81
57
  }
82
58
 
83
- public async pureGet(url: string, options: IAPIOptions = {}): Promise<string> {
84
- try {
85
- const response = await fetch(url, {
86
- headers: this.getHeaders(options.headers),
87
- });
88
- return await response.text();
89
- } catch (error) {
90
- console.error('GET request failed:', error);
91
- throw error;
92
- }
93
- }
59
+
94
60
 
95
61
  public async isGetTargetReachable(url: string, options: IAPIOptions = {}): Promise<boolean> {
96
62
  try {
97
- return !!(await this.pureGet(url, options));
63
+ return !!(await calls.pureGet(url, options, this.token));
98
64
  } catch (error) {
99
65
  return false;
100
66
  }
101
- }
102
-
103
- public async get<T>(url: string, options: IAPIOptions = {}): Promise<T> {
104
- try {
105
- const response = await fetch(url, {
106
- headers: this.getHeaders(options.headers),
107
- });
108
- return await response.json();
109
- } catch (error) {
110
- console.error('GET request failed:', error);
111
- throw error;
112
- }
113
- }
114
-
115
- public async post<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}): Promise<T> {
116
- try {
117
- const response = await fetch(url, {
118
- method: 'POST',
119
- headers: this.getHeaders(options.headers),
120
- body: payload ? JSON.stringify(payload) : null,
121
- });
122
- return await response.json();
123
- } catch (error) {
124
- console.error('POST request failed:', error);
125
- throw error;
126
- }
127
- }
128
-
129
- public async put<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}): Promise<T> {
130
- try {
131
- const response = await fetch(url, {
132
- method: 'PUT',
133
- headers: this.getHeaders(options.headers),
134
- body: payload ? JSON.stringify(payload) : null,
135
- });
136
- return await response.json();
137
- } catch (error) {
138
- console.error('PUT request failed:', error);
139
- throw error;
140
- }
141
- }
142
-
143
- public async delete<T>(url: string, options: IAPIOptions = {}): Promise<T> {
144
- try {
145
- const response = await fetch(url, {
146
- method: 'DELETE',
147
- headers: this.getHeaders(options.headers),
148
- });
149
- return await response.json();
150
- } catch (error) {
151
- console.error('DELETE request failed:', error);
152
- throw error;
153
- }
154
- }
155
-
156
- private getBackendUrl(routeName: string, params: {[key: string]: string} = {})
157
- {
158
-
159
-
160
- const routesPackage = this.config.get('backendRoutes');
161
-
162
- let routes: IHTTProute[] = [];
163
-
164
- routesPackage.forEach((item: IBackendRoute) => {
165
- // Check if item is an instance of IPrefixedHTTProutes
166
- if ('prefix' in item && 'routes' in item && Array.isArray(item.routes)) {
167
- // Handle the case where item is of type IPrefixedHTTProutes
168
- routes = [...routes, ...item.routes.map((subRouteItem: IHTTProute): IHTTProute => {
169
- const subRoute: IHTTProute = {
170
- path: item.prefix + subRouteItem.path,
171
- name: subRouteItem.name
172
- };
173
-
174
- return subRoute;
175
- })];
176
- } else {
177
- // Handle the case where item is of type IHTTProute
178
- routes.push(item as IHTTProute);
179
- }
180
- });
181
-
182
- const route = routes.find((item: IHTTProute) => item.name === routeName);
183
-
184
- if(!route){
185
- throw new Error(`Backend route '${routeName}' does not exist.`);
186
- }
187
-
188
- let apiPath = route.path;
189
-
190
- Object.keys(params).forEach((paramKey: string) => {
191
- const paramValue = params[paramKey];
192
-
193
- apiPath = apiPath.replace(`:${paramKey}`, paramValue);
194
- });
195
-
196
- return `${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}${apiPath}`;
197
- }
67
+ }
198
68
 
199
69
  async uploadFile(url: string, file: File, onProgress: (progress: number) => void, payload: any = {}): Promise<UploadResponse>
200
70
  {
@@ -212,32 +82,25 @@ class ApiService extends TheService {
212
82
  );
213
83
  }
214
84
 
85
+ public pureGet = calls.pureGet;
86
+ public get = calls.get;
87
+ public post = calls.post;
88
+ public put = calls.put;
89
+ public delete = calls.delete;
90
+
215
91
  public back = {
216
- get: <T>(routeName: string, options?: IAPIOptions): Promise<T> => this.get(this.getBackendUrl(routeName, options?.routeParams), options),
217
- post: <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => this.post(this.getBackendUrl(routeName, options?.routeParams), payload, options),
218
- put: <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => this.put(this.getBackendUrl(routeName, options?.routeParams), payload, options),
219
- delete: <T>(routeName: string, options?: IAPIOptions): Promise<T> => this.delete(this.getBackendUrl(routeName, options?.routeParams), options),
220
- uploadFile: (routeName: string, file: File, onProgress: (progress: number) => void, options: IAPIOptions = {}, payload: any = {}): Promise<UploadResponse> => this.uploadFile(this.getBackendUrl(routeName, options?.routeParams), file, onProgress, payload),
92
+ get: <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.get(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options, this.token),
93
+ post: <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options, this.token),
94
+ put: <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options, this.token),
95
+ delete: <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options, this.token),
96
+ uploadFile: (routeName: string, file: File, onProgress: (progress: number) => void, options: IAPIOptions = {}, payload: any = {}): Promise<UploadResponse> => this.uploadFile(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), file, onProgress, payload),
221
97
  };
222
98
 
223
- connectToAmplify()
99
+ async getResource(resourceName: string): Promise<IKDBTypesResponse>
224
100
  {
225
- // "use client"
226
- // const client = generateClient<Schema>() // use this Data client for CRUDL requests
227
-
228
-
229
- // /*== STEP 3 ===============================================================
230
- // Fetch records from the database and use them in your frontend component.
231
- // (THIS SNIPPET WILL ONLY WORK IN THE FRONTEND CODE FILE.)
232
- // =========================================================================*/
233
-
234
- // /* For example, in a React component, you can use this snippet in your
235
- // function's RETURN statement */
236
- // // const { data: todos } = client.models.Todo.list()
237
-
238
- // // return <ul>{todos.map(todo => <li key={todo.id}>{todo.content}</li>)}</ul>
101
+ return calls.get(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`)
239
102
  }
240
103
  }
241
104
 
242
105
  export default ApiService.getSingleton();
243
- export { IBackendRoute, RequestOptions, ApiService as ApiServiceInstance, IHTTProute, IPrefixedHTTProutes };
106
+ export { IBackendRoute, RequestOptions, ApiService as ApiServiceInstance, IHTTProute, IPrefixedHTTProutes, IAPIOptions };
@@ -68,15 +68,6 @@ class ConfigService extends TheService {
68
68
  public set<V extends keyof IRWSConfig>(key: V, value: IRWSConfig[V]){
69
69
  this.data[key] = value;
70
70
  }
71
-
72
- public async reloadConfig(cfgString: string): Promise<ConfigService>
73
- {
74
- const module = await import(/* webpackIgnore: true */ cfgString);
75
- const cfg: () => IRWSConfig = module.defaults;
76
- this.data = cfg();
77
-
78
- return this;
79
- }
80
71
 
81
72
  async waitForConfig(tagName: string): Promise<boolean>
82
73
  {
@@ -0,0 +1,88 @@
1
+ import { ApiServiceInstance, IBackendRoute, IHTTProute } from "../ApiService";
2
+ import { ConfigServiceInstance } from "../ConfigService";
3
+
4
+ export const backend = {
5
+ getBackendUrl(this: ApiServiceInstance, routeName: string, params: {[key: string]: string} = {})
6
+ {
7
+ const config = this.config;
8
+ const routesPackage = config.get('backendRoutes');
9
+
10
+ let routes: IHTTProute[] = [];
11
+
12
+ routesPackage.forEach((item: IBackendRoute) => {
13
+ // Check if item is an instance of IPrefixedHTTProutes
14
+ if ('prefix' in item && 'routes' in item && Array.isArray(item.routes)) {
15
+ // Handle the case where item is of type IPrefixedHTTProutes
16
+ if(item.exportAutoRoutes){
17
+ item.routes = [...item.routes,
18
+ {
19
+ name: `list`,
20
+ path: '/',
21
+ method: 'GET'
22
+ },
23
+ {
24
+ name: `create`,
25
+ path: '/',
26
+ method: 'POST'
27
+ },
28
+ {
29
+ name: `show`,
30
+ path: '/:id',
31
+ method: 'GET'
32
+ },
33
+ {
34
+ name: `update`,
35
+ path: '/:id',
36
+ method: 'PUT'
37
+ },
38
+ {
39
+ name: `delete`,
40
+ path: '/:id',
41
+ method: 'DELETE'
42
+ },
43
+ ];
44
+ }
45
+
46
+ routes = [...routes, ...item.routes.map((subRouteItem: IHTTProute): IHTTProute => {
47
+ const subRoute: IHTTProute = {
48
+ path: item.prefix + subRouteItem.path,
49
+ name: backend.checkPrefixedRouteName(subRouteItem.name, item.controllerName),
50
+ method: subRouteItem.method || 'GET'
51
+ };
52
+
53
+ return subRoute;
54
+ })];
55
+
56
+ console.log({routes});
57
+ } else {
58
+ // Handle the case where item is of type IHTTProute
59
+ routes.push(item as IHTTProute);
60
+ }
61
+ });
62
+
63
+ const route = routes.find((item: IHTTProute) => item.name === routeName);
64
+
65
+ if(!route){
66
+ throw new Error(`Backend route '${routeName}' does not exist.`);
67
+ }
68
+
69
+ let apiPath = route.path;
70
+
71
+ Object.keys(params).forEach((paramKey: string) => {
72
+ const paramValue = params[paramKey];
73
+
74
+ apiPath = apiPath.replace(`:${paramKey}`, paramValue);
75
+ });
76
+
77
+ return `${config.get('backendUrl')}${config.get('apiPrefix') || ''}${apiPath}`;
78
+ },
79
+ checkPrefixedRouteName(routeName: string, prefixName: string){
80
+ let finalRoute = routeName;
81
+
82
+ if(routeName.indexOf(prefixName) === -1){
83
+ finalRoute = `${prefixName}:${routeName}`;
84
+ }
85
+
86
+ return finalRoute;
87
+ }
88
+ }
@@ -0,0 +1,95 @@
1
+ import { IAPIOptions } from "../ApiService";
2
+
3
+ const _DEFAULT_CONTENT_TYPE = 'application/json';
4
+
5
+ export const calls = {
6
+ addHeader(headers: Headers | [string, string][] | {[key: string]: string}, key: string, val: string)
7
+ {
8
+ if (headers instanceof Headers) {
9
+ headers.append(key, val);
10
+ } else if (Array.isArray(headers)) {
11
+ headers.push([key, val]);
12
+ } else {
13
+ headers[key] = val;
14
+ }
15
+ },
16
+ getHeaders(token: string = null, optHeaders: HeadersInit = {}): HeadersInit {
17
+ const headers: HeadersInit = { ...optHeaders };
18
+
19
+ if (!('Content-Type' in headers)) {
20
+ this.addHeader(headers, 'Content-Type', _DEFAULT_CONTENT_TYPE);
21
+ }
22
+
23
+ if (token) {
24
+ this.addHeader(headers, 'Authorization', `Bearer ${token}`);
25
+ }
26
+
27
+ if((headers as any)['Content-Type']){
28
+ this.addHeader(headers, 'Accept', '*/*');
29
+ }else{
30
+ this.addHeader(headers, 'Accept', (headers as any)['Content-Type']);
31
+ }
32
+
33
+ return headers;
34
+ },
35
+ async pureGet(url: string, options: IAPIOptions = {}, token: string = null): Promise<string> {
36
+ try {
37
+ const response = await fetch(url, {
38
+ headers: this.getHeaders(token, options.headers),
39
+ });
40
+ return await response.text();
41
+ } catch (error) {
42
+ console.error('GET request failed:', error);
43
+ throw error;
44
+ }
45
+ },
46
+ async get<T>(url: string, options: IAPIOptions = {}, token: string = null): Promise<T> {
47
+ try {
48
+ const response = await fetch(url, {
49
+ headers: this.getHeaders(token, options.headers),
50
+ });
51
+ return await response.json();
52
+ } catch (error) {
53
+ console.error('GET request failed:', error);
54
+ throw error;
55
+ }
56
+ },
57
+ async post<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}, token: string = null): Promise<T> {
58
+ try {
59
+ const response = await fetch(url, {
60
+ method: 'POST',
61
+ headers: this.getHeaders(token, options.headers),
62
+ body: payload ? JSON.stringify(payload) : null,
63
+ });
64
+ return await response.json();
65
+ } catch (error) {
66
+ console.error('POST request failed:', error);
67
+ throw error;
68
+ }
69
+ },
70
+ async put<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}, token: string = null): Promise<T> {
71
+ try {
72
+ const response = await fetch(url, {
73
+ method: 'PUT',
74
+ headers: this.getHeaders(token, options.headers),
75
+ body: payload ? JSON.stringify(payload) : null,
76
+ });
77
+ return await response.json();
78
+ } catch (error) {
79
+ console.error('PUT request failed:', error);
80
+ throw error;
81
+ }
82
+ },
83
+ async delete<T>(url: string, options: IAPIOptions = {}, token: string = null): Promise<T> {
84
+ try {
85
+ const response = await fetch(url, {
86
+ method: 'DELETE',
87
+ headers: this.getHeaders(token, options.headers),
88
+ });
89
+ return await response.json();
90
+ } catch (error) {
91
+ console.error('DELETE request failed:', error);
92
+ throw error;
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,12 @@
1
+ export interface IKDBTypeInfo {
2
+ fieldName: string;
3
+ type: string;
4
+ boundModel?: string
5
+ }
6
+
7
+ export interface IKDBTypesResponse {
8
+ success: boolean;
9
+ data: {
10
+ types: IKDBTypeInfo[];
11
+ };
12
+ }
@@ -1,10 +1,7 @@
1
1
  import RWSViewComponent from '../components/_component';
2
- import { RWSPlugin, DefaultRWSPluginOptionsType } from '../plugins/_plugin';
3
- import { IStaticRWSPlugin } from './IRWSPlugin';
2
+ import { IPluginSpawnOption } from './IRWSPlugin';
4
3
 
5
4
  export type IFrontRoutes = Record<string, unknown>;
6
- export type RWSPluginEntry<T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> = new (...args: any[]) => RWSPlugin<T>;
7
-
8
5
  export default interface IRWSConfig {
9
6
  [key: string]: any
10
7
  dev?: boolean
@@ -25,7 +22,7 @@ export default interface IRWSConfig {
25
22
  rwsDefines?: {[key: string]: any}
26
23
  partedFileDir?: string
27
24
  partedPrefix?: string
28
- plugins?: IStaticRWSPlugin[]
25
+ plugins?: IPluginSpawnOption<any>[]
29
26
  routing_enabled?: boolean
30
27
  _noLoad?: boolean
31
28
  }
@@ -1,19 +1,24 @@
1
- import { DefaultRWSPluginOptionsType } from "../plugins/_plugin";
1
+ import { DefaultRWSPluginOptionsType, RWSPlugin } from "../plugins/_plugin";
2
2
  import IRWSUser from "./IRWSUser";
3
3
  import { Container } from "../components/_container";
4
4
  import RWSWindow from "./RWSWindow";
5
5
  import { RWSInfoType } from "../client/components";
6
6
 
7
+ export abstract class IRWSPlugin<T extends DefaultRWSPluginOptionsType> {
8
+ abstract onClientStart(): Promise<void>;
9
+ abstract onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void>;
10
+ abstract onComponentsDeclare(): Promise<void>;
11
+ abstract onSetUser(user: IRWSUser): Promise<void>;
12
+ protected abstract options: T;
13
+ protected abstract container: Container;
14
+ protected abstract window: RWSWindow;
15
+ }
7
16
 
8
- export interface IRWSPlugin {
9
- onClientStart(): Promise<void>
10
- onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void>
11
- onComponentsDeclare(): Promise<void>
12
- onSetUser(user: IRWSUser): Promise<void>
17
+ export interface IStaticRWSPlugin<T extends DefaultRWSPluginOptionsType> {
18
+ new (options: T): RWSPlugin<T>;
13
19
  }
14
20
 
15
- export interface IStaticRWSPlugin<PluginOptions extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> {
16
- new (...args: any[]): IRWSPlugin;
17
- container: Container;
18
- window: RWSWindow;
21
+ export interface IPluginSpawnOption<T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType> {
22
+ pluginEntry: IStaticRWSPlugin<T>;
23
+ options?: T;
19
24
  }
@@ -0,0 +1,5 @@
1
+ export interface IRWSResourceQuery {
2
+ fieldName: string,
3
+ type: String,
4
+ boundModel: string
5
+ }