@rws-framework/client 2.18.0 → 2.18.2

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.
@@ -252,7 +252,7 @@ async function getTemplate(filePath, addDependency, templateName = null, isDev =
252
252
 
253
253
  if (templateExists) {
254
254
  const templateContent = fs.readFileSync(templatePath, 'utf-8').replace(/<!--[\s\S]*?-->/g, '');
255
- htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport './${templateName}.html';\n`;
255
+ htmlFastImports = `import * as T from '@microsoft/fast-element';\nimport { html, css, ref, when, repeat, slotted, children } from '@microsoft/fast-element'; \nimport './${templateName}.html';\n`;
256
256
  template = `
257
257
  //@ts-ignore
258
258
  let rwsTemplate: any = T.html\`${templateContent}\`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.18.0",
4
+ "version": "2.18.2",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -1,8 +1,9 @@
1
1
  import { RWSView } from '../../_decorator';
2
2
  import { RWSViewComponent } from '../../_component';
3
+ import { attr } from '@microsoft/fast-element';
3
4
 
4
- @RWSView('the-loader')
5
- class RWSLoader extends RWSViewComponent {
5
+ @RWSView('rws-loader')
6
+ class RWSLoader extends RWSViewComponent {
6
7
  connectedCallback(): void {
7
8
  super.connectedCallback();
8
9
  }
@@ -1,14 +1,14 @@
1
1
  //loader
2
2
  //save
3
- $loader-color: var(--primary-color, #eb7b13);
4
- $loader-size: 56px;
3
+ $loader-color: var(--rws-loader-color, #eb7b13);
4
+ $loader-size: 26px;
5
5
  $loader-height: 20px;
6
6
  $loader-border-size: 8px;
7
7
  $loader-gap: 12px;
8
8
  $loader-animation-duration: 1s;
9
9
 
10
- // @import "~/scss-loading-animations/src/loaders";
10
+ @import "~/scss-loading-animations/src/loaders";
11
11
 
12
- // .loader {
13
- // @include loader01;
14
- // }
12
+ .loader {
13
+ @include loader06;
14
+ }
@@ -27,7 +27,6 @@ class ReFormer extends RWSViewComponent {
27
27
 
28
28
  modelTypesChanged(oldVal:IKDBTypesResponse, newVal: IKDBTypesResponse)
29
29
  {
30
- console.log({newVal})
31
30
  if(newVal){
32
31
  this.formFields = newVal.data.types.filter((item) => !['id', 'created_at', 'updated_at'].includes(item.fieldName))
33
32
  }
@@ -29,8 +29,6 @@ class RWSResourceFormComponent extends RWSViewComponent {
29
29
  for(const type of this.dbModelData.data.types){
30
30
  this.formOrdering.push(type as unknown as IReFormerMassOrdering);
31
31
  }
32
-
33
- console.log('ordering', this.formOrdering);
34
32
  }
35
33
  }
36
34
 
@@ -5,8 +5,13 @@ import { RWSView} from '../../_decorator';
5
5
  @RWSView('rws-modal')
6
6
  class RWSModal extends RWSViewComponent {
7
7
  @observable closeModal: () => void
8
+ @observable onShowModal: ($: ShadowRoot) => void
9
+
8
10
  connectedCallback(): void {
9
- super.connectedCallback();
11
+ super.connectedCallback();
12
+ if(this.onShowModal){
13
+ this.onShowModal(this.shadowRoot);
14
+ }
10
15
  }
11
16
  }
12
17
 
@@ -45,7 +45,7 @@ type IBackendRoute = IHTTProute | IPrefixedHTTProutes;
45
45
 
46
46
  class ApiService extends TheService {
47
47
  static _DEFAULT: boolean = true;
48
- private token?: string;
48
+ public token?: string;
49
49
 
50
50
  constructor(@ConfigService public config: ConfigServiceInstance) {
51
51
  super();
@@ -60,7 +60,7 @@ class ApiService extends TheService {
60
60
 
61
61
  public async isGetTargetReachable(url: string, options: IAPIOptions = {}): Promise<boolean> {
62
62
  try {
63
- return !!(await calls.pureGet(url, options, this.token));
63
+ return !!(await calls.pureGet.bind(this)(url, options));
64
64
  } catch (error) {
65
65
  return false;
66
66
  }
@@ -89,16 +89,16 @@ class ApiService extends TheService {
89
89
  public delete = calls.delete;
90
90
 
91
91
  public back = {
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),
92
+ get: async <T>(routeName: string, options?: IAPIOptions, token?: string): Promise<T> => calls.get.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
93
+ post: async <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
94
+ put: async <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
95
+ delete: async <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
96
+ uploadFile: async (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),
97
97
  };
98
98
 
99
99
  async getResource(resourceName: string): Promise<IKDBTypesResponse>
100
100
  {
101
- return calls.get(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`)
101
+ return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<IKDBTypesResponse>
102
102
  }
103
103
  }
104
104
 
@@ -2,7 +2,7 @@ import { ApiServiceInstance, IBackendRoute, IHTTProute } from "../ApiService";
2
2
  import { ConfigServiceInstance } from "../ConfigService";
3
3
 
4
4
  export const backend = {
5
- getBackendUrl(this: ApiServiceInstance, routeName: string, params: {[key: string]: string} = {})
5
+ getBackendUrl(this: ApiServiceInstance, routeName: string, params: {[key: string]: string} = {}): string
6
6
  {
7
7
  const config = this.config;
8
8
  const routesPackage = config.get('backendRoutes');
@@ -1,10 +1,11 @@
1
- import { IAPIOptions } from "../ApiService";
1
+ import { ApiServiceInstance, IAPIOptions } from "../ApiService";
2
2
 
3
3
  const _DEFAULT_CONTENT_TYPE = 'application/json';
4
4
 
5
+ type HeadersType = Headers | [string, string][] | Record<string, string>;
6
+
5
7
  export const calls = {
6
- addHeader(headers: Headers | [string, string][] | {[key: string]: string}, key: string, val: string)
7
- {
8
+ addHeader(headers: HeadersType, key: string, val: string): void {
8
9
  if (headers instanceof Headers) {
9
10
  headers.append(key, val);
10
11
  } else if (Array.isArray(headers)) {
@@ -13,29 +14,31 @@ export const calls = {
13
14
  headers[key] = val;
14
15
  }
15
16
  },
16
- getHeaders(token: string = null, optHeaders: HeadersInit = {}): HeadersInit {
17
- const headers: HeadersInit = { ...optHeaders };
17
+
18
+ getHeaders(token: string | null = null, optHeaders: HeadersInit = {}): HeadersInit {
19
+ const headers: Record<string, string> = { ...(optHeaders as Record<string, string>) };
18
20
 
19
21
  if (!('Content-Type' in headers)) {
20
22
  this.addHeader(headers, 'Content-Type', _DEFAULT_CONTENT_TYPE);
21
- }
22
-
23
+ }
24
+
23
25
  if (token) {
24
- this.addHeader(headers, 'Authorization', `Bearer ${token}`);
25
- }
26
+ this.addHeader(headers, 'Authorization', `Bearer ${token}`);
27
+ }
26
28
 
27
- if((headers as any)['Content-Type']){
29
+ if (headers['Content-Type']) {
28
30
  this.addHeader(headers, 'Accept', '*/*');
29
- }else{
30
- this.addHeader(headers, 'Accept', (headers as any)['Content-Type']);
31
+ } else {
32
+ this.addHeader(headers, 'Accept', headers['Content-Type'] || _DEFAULT_CONTENT_TYPE);
31
33
  }
32
34
 
33
35
  return headers;
34
36
  },
35
- async pureGet(url: string, options: IAPIOptions = {}, token: string = null): Promise<string> {
37
+
38
+ async pureGet(this: ApiServiceInstance, url: string, options: IAPIOptions = {}): Promise<string> {
36
39
  try {
37
40
  const response = await fetch(url, {
38
- headers: this.getHeaders(token, options.headers),
41
+ headers: calls.getHeaders(this.token, options.headers),
39
42
  });
40
43
  return await response.text();
41
44
  } catch (error) {
@@ -43,53 +46,71 @@ export const calls = {
43
46
  throw error;
44
47
  }
45
48
  },
46
- async get<T>(url: string, options: IAPIOptions = {}, token: string = null): Promise<T> {
49
+
50
+ async get<T>(this: ApiServiceInstance, url: string, options: IAPIOptions = {}): Promise<T> {
47
51
  try {
48
52
  const response = await fetch(url, {
49
- headers: this.getHeaders(token, options.headers),
53
+ headers: calls.getHeaders(this.token, options.headers),
50
54
  });
51
- return await response.json();
55
+ const data: T = await response.json();
56
+ return data;
52
57
  } catch (error) {
53
58
  console.error('GET request failed:', error);
54
59
  throw error;
55
60
  }
56
- },
57
- async post<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}, token: string = null): Promise<T> {
61
+ },
62
+
63
+ async post<T, P extends object = object>(
64
+ this: ApiServiceInstance,
65
+ url: string,
66
+ payload?: P,
67
+ options: IAPIOptions = {}
68
+ ): Promise<T> {
58
69
  try {
59
70
  const response = await fetch(url, {
60
71
  method: 'POST',
61
- headers: this.getHeaders(token, options.headers),
72
+ headers: calls.getHeaders(this.token, options.headers),
62
73
  body: payload ? JSON.stringify(payload) : null,
63
74
  });
64
- return await response.json();
75
+ const data: T = await response.json();
76
+ return data;
65
77
  } catch (error) {
66
78
  console.error('POST request failed:', error);
67
79
  throw error;
68
80
  }
69
- },
70
- async put<T, P extends object = object>(url: string, payload?: P, options: IAPIOptions = {}, token: string = null): Promise<T> {
81
+ },
82
+
83
+ async put<T, P extends object = object>(
84
+ this: ApiServiceInstance,
85
+ url: string,
86
+ payload: P,
87
+ options: IAPIOptions = {}
88
+ ): Promise<T> {
71
89
  try {
72
90
  const response = await fetch(url, {
73
91
  method: 'PUT',
74
- headers: this.getHeaders(token, options.headers),
75
- body: payload ? JSON.stringify(payload) : null,
92
+ headers: calls.getHeaders(this.token, options.headers),
93
+ body: JSON.stringify(payload),
76
94
  });
77
- return await response.json();
95
+ const data: T = await response.json();
96
+ return data;
78
97
  } catch (error) {
79
98
  console.error('PUT request failed:', error);
80
99
  throw error;
81
100
  }
82
- },
83
- async delete<T>(url: string, options: IAPIOptions = {}, token: string = null): Promise<T> {
101
+ },
102
+
103
+ async delete<T>(this: ApiServiceInstance, url: string, options: IAPIOptions = {}): Promise<T> {
84
104
  try {
85
105
  const response = await fetch(url, {
86
106
  method: 'DELETE',
87
- headers: this.getHeaders(token, options.headers),
107
+ headers: calls.getHeaders(this.token, options.headers),
88
108
  });
89
- return await response.json();
109
+ const data: T = await response.json();
110
+ return data;
90
111
  } catch (error) {
91
112
  console.error('DELETE request failed:', error);
92
113
  throw error;
93
114
  }
94
115
  }
95
- }
116
+ };