@sankhyalabs/sankhyablocks 2.0.2 → 2.1.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.
@@ -0,0 +1,66 @@
1
+ import { ApplicationContext } from "@sankhyalabs/core";
2
+ import { FormConfigFetcher } from "../http/data-fetcher/fetchers/form-config-fetcher";
3
+ import GridConfigFetcher from "../http/data-fetcher/fetchers/grid-config-fetcher";
4
+ const CONFIG_SOURCE = {
5
+ form: "form",
6
+ grid: "grid"
7
+ };
8
+ export class ConfigStorage {
9
+ static get() {
10
+ if (!ConfigStorage.instance) {
11
+ const application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
12
+ if (application != undefined) {
13
+ ConfigStorage.instance = new ConfigStorage();
14
+ application.getResourceID().then((resourceID) => {
15
+ const configName = application.configName;
16
+ ConfigStorage.resourceID = resourceID;
17
+ ConfigStorage.loadFormConfig(configName);
18
+ ConfigStorage.loadGridConfig(configName);
19
+ });
20
+ }
21
+ }
22
+ return this.instance;
23
+ }
24
+ static async loadFormConfig(name) {
25
+ if (name == undefined) {
26
+ return;
27
+ }
28
+ const cacheID = this.getCacheID(name, CONFIG_SOURCE.form);
29
+ if (!this.configById.has(cacheID)) {
30
+ this.configById.set(cacheID, this.formConfigFetcher.loadFormConfig(name, this.resourceID));
31
+ }
32
+ return this.configById.get(cacheID);
33
+ }
34
+ static async loadGridConfig(name) {
35
+ if (name == undefined) {
36
+ return;
37
+ }
38
+ const cacheID = this.getCacheID(name, CONFIG_SOURCE.grid);
39
+ if (!this.configById.has(cacheID)) {
40
+ this.configById.set(cacheID, this.gridConfigFetcher.getConfig(name, this.resourceID));
41
+ }
42
+ return this.configById.get(cacheID);
43
+ }
44
+ static async saveFormConfig(config, name) {
45
+ if (config == undefined || name == undefined) {
46
+ return;
47
+ }
48
+ const cacheID = this.getCacheID(name, CONFIG_SOURCE.form);
49
+ this.configById.delete(cacheID);
50
+ return this.formConfigFetcher.saveConfig(config, name, this.resourceID);
51
+ }
52
+ static async saveGridConfig(config, name) {
53
+ if (config == undefined || name == undefined) {
54
+ return;
55
+ }
56
+ const cacheID = this.getCacheID(name, CONFIG_SOURCE.grid);
57
+ this.configById.delete(cacheID);
58
+ return this.gridConfigFetcher.saveConfig(config, this.resourceID);
59
+ }
60
+ static getCacheID(name, source) {
61
+ return `req_${source}_${name}_${this.resourceID}`;
62
+ }
63
+ }
64
+ ConfigStorage.configById = new Map();
65
+ ConfigStorage.formConfigFetcher = new FormConfigFetcher();
66
+ ConfigStorage.gridConfigFetcher = new GridConfigFetcher();
@@ -0,0 +1,15 @@
1
+ import { IFormConfig } from "@sankhyalabs/ezui/dist/types/components/ez-form/ez-form";
2
+ import { IGridConfig } from "@sankhyalabs/ezui/dist/types/components/ez-grid/controller/EzGridController";
3
+ export declare class ConfigStorage {
4
+ private static instance;
5
+ private static configById;
6
+ private static formConfigFetcher;
7
+ private static gridConfigFetcher;
8
+ private static resourceID;
9
+ static get(): ConfigStorage;
10
+ static loadFormConfig(name: string): Promise<IFormConfig>;
11
+ static loadGridConfig(name: string): Promise<IGridConfig>;
12
+ static saveFormConfig(config: IFormConfig, name: string): Promise<boolean>;
13
+ static saveGridConfig(config: IGridConfig, name: string): Promise<boolean>;
14
+ private static getCacheID;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sankhyalabs/sankhyablocks",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Stencil Component Starter",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",