@lbdudc/gp-gis-dsl 0.2.0 → 0.2.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/README.md CHANGED
@@ -9,13 +9,13 @@ It parses a DSL instance and generates the spec for the web-based GIS SPL.
9
9
  ## Installation
10
10
 
11
11
  ```bash
12
- npm install
12
+ npm install @lbdudc/gp-gis-dsl
13
13
  ```
14
14
 
15
15
  ## Usage
16
16
 
17
17
  ```js
18
- import gisdslParser from "gisdsl";
18
+ import gisdslParser from "@lbdudc/gp-gis-dsl";
19
19
 
20
20
  const spec = gisdslParser(inputString);
21
21
  ```
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@lbdudc/gp-gis-dsl",
3
- "version": "0.2.0",
4
- "homepage": "https://gitlab.lbd.org.es/publico/gis-publisher/gis-dsl",
3
+ "version": "0.2.1",
4
+ "homepage": "https://github.com/lbdudc/gis-dsl#readme",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/lbdudc/gis-dsl.git"
8
+ },
5
9
  "description": "A library that parses a DSL instance and generates the spec for the web-based GIS SPL.",
6
10
  "bin": {
7
11
  "gis-dsl": "src/cli.js"
@@ -1,162 +1,162 @@
1
- function transformation(spec) {
2
- _relationships(spec);
3
- const newSpec = {
4
- features: [
5
- "GEMA_SPL",
6
- "DataManagement",
7
- "GraphicalUserInterface",
8
- "MapViewer",
9
- "Tools",
10
- "DM_SpatialDatabase",
11
- "DM_GenerationType",
12
- "DM_DataServer",
13
- "MV_MapServer",
14
- "MV_Tools",
15
- "MV_MapManagement",
16
- "DM_SD_PostGIS",
17
- "MV_T_Pan",
18
- "MV_T_Zoom",
19
- "DM_GT_Sequence",
20
- "MV_MM_MultipleMapViewer",
21
- "MV_MM_MMV_MapSelectorInMapViewer",
22
- "MV_MM_MMV_MapSelectorInMenuElement",
23
- "MV_MS_GeoServer",
24
- "GUI_Forms",
25
- "GUI_F_Editable",
26
- "GUI_F_Creatable",
27
- "GUI_F_Removable",
28
- "GUI_F_R_ConfirmationAlert",
29
- "GUI_Lists",
30
- "GUI_L_FormLink",
31
- "GUI_L_F_BasicSearch",
32
- "GUI_L_Filterable",
33
- "GUI_L_Sortable",
34
- "GUI_L_LocateInMap",
35
- "GUI_L_ViewListAsMap",
36
- "GUI_L_Export",
37
- "GUI_StaticPages",
38
- "MV_ContextInformation",
39
- "MV_CI_Scale",
40
- "MV_CI_Map",
41
- "MV_CI_CenterCoordinates",
42
- "MV_CI_Dimensions",
43
- "MV_DetailOnClick",
44
- "MV_LayerManagement",
45
- "MV_LM_CenterViewOnLayer",
46
- "MV_LM_Order",
47
- "MV_LM_Opacity",
48
- "MV_LM_HideLayer",
49
- "MV_LM_Style",
50
- "MV_LM_ExternalLayer",
51
- "MV_LM_StylePreview",
52
- "MV_T_Export",
53
- "MV_T_E_Type",
54
- "MV_T_E_F_URL",
55
- "MV_T_E_F_PDF",
56
- "MV_T_E_SetScale",
57
- "MV_T_E_ShowLegend",
58
- "MV_T_InformationMode",
59
- "MV_T_MeasureControl",
60
- "MV_T_M_Distance",
61
- "MV_T_M_Line",
62
- "MV_T_M_Polygon",
63
- "MV_T_ZoomWindow",
64
- "GUI_Menu",
65
- "GUI_M_Position",
66
- "GUI_M_Top",
67
- "DM_DataInput",
68
- "DM_DI_DataFeeding",
69
- "DM_DI_DF_Shapefile",
70
- "T_GIS",
71
- "T_EntitiesInformation",
72
- "D_C_Postgres",
73
- "D_C_Geoserver",
74
- "D_C_Nginx",
75
- ],
76
- basicData: {
77
- name: spec.name,
78
- },
79
- data: {
80
- dataModel: {
81
- entities: spec.entities,
82
- enums: [],
83
- },
84
- },
85
- mapViewer: {
86
- maps: spec.maps,
87
- layers: spec.layers,
88
- styles: spec.styles,
89
- },
90
- };
91
-
92
- if (spec.extra) {
93
- newSpec.basicData.extra = spec.extra;
94
- }
95
-
96
- return newSpec;
97
- }
98
-
99
- function _relationships(spec) {
100
- let source, target;
101
-
102
- spec.relationships.forEach((r) => {
103
- source = spec.getEntity(r.source);
104
- target = spec.getEntity(r.target);
105
- let sourceOwner = false;
106
- let targetOwner = false;
107
- let sourceMultiple = _multiple(r.sourceOpts.multiplicity);
108
- let targetMultiple = _multiple(r.targetOpts.multiplicity);
109
- if (sourceMultiple && !targetMultiple) {
110
- targetOwner = true;
111
- } else {
112
- sourceOwner = true;
113
- }
114
-
115
- source.properties.push({
116
- name: r.sourceOpts.label,
117
- class: target.name,
118
- owner: sourceOwner,
119
- bidirectional: r.targetOpts.label,
120
- multiple: sourceMultiple,
121
- required: _required(r.sourceOpts.multiplicity),
122
- });
123
-
124
- target.properties.push({
125
- name: r.targetOpts.label,
126
- class: source.name,
127
- owner: targetOwner,
128
- bidirectional: r.sourceOpts.label,
129
- multiple: targetMultiple,
130
- required: _required(r.targetOpts.multiplicity),
131
- });
132
- });
133
- }
134
-
135
- function _multiple(multiplicity) {
136
- return ["1..1", "0..1"].find((a) => a == multiplicity) == null;
137
- }
138
-
139
- function _required(multiplicity) {
140
- return ["1..1", "1..*"].find((a) => a == multiplicity) != null;
141
- }
142
-
143
- function getPropertyParams(symbols) {
144
- if (!symbols.length) return null;
145
-
146
- const ret = {};
147
- if (symbols.includes("identifier")) {
148
- ret.pk = true;
149
- }
150
- if (symbols.includes("required")) {
151
- ret.required = true;
152
- }
153
- if (symbols.includes("unique")) {
154
- ret.unique = true;
155
- }
156
- if (symbols.includes("display_string")) {
157
- ret.displayString = true;
158
- }
159
- return ret;
160
- }
161
-
162
- export { transformation, getPropertyParams };
1
+ function transformation(spec) {
2
+ _relationships(spec);
3
+ const newSpec = {
4
+ features: [
5
+ "GEMA_SPL",
6
+ "DataManagement",
7
+ "GraphicalUserInterface",
8
+ "MapViewer",
9
+ "Tools",
10
+ "DM_SpatialDatabase",
11
+ "DM_GenerationType",
12
+ "DM_DataServer",
13
+ "MV_MapServer",
14
+ "MV_Tools",
15
+ "MV_MapManagement",
16
+ "DM_SD_PostGIS",
17
+ "MV_T_Pan",
18
+ "MV_T_Zoom",
19
+ "DM_GT_Sequence",
20
+ "MV_MM_MultipleMapViewer",
21
+ "MV_MM_MMV_MapSelectorInMapViewer",
22
+ "MV_MM_MMV_MapSelectorInMenuElement",
23
+ "MV_MS_GeoServer",
24
+ "GUI_Forms",
25
+ "GUI_F_Editable",
26
+ "GUI_F_Creatable",
27
+ "GUI_F_Removable",
28
+ "GUI_F_R_ConfirmationAlert",
29
+ "GUI_Lists",
30
+ "GUI_L_FormLink",
31
+ "GUI_L_F_BasicSearch",
32
+ "GUI_L_Filterable",
33
+ "GUI_L_Sortable",
34
+ "GUI_L_LocateInMap",
35
+ "GUI_L_ViewListAsMap",
36
+ "GUI_L_Export",
37
+ "GUI_StaticPages",
38
+ "MV_ContextInformation",
39
+ "MV_CI_Scale",
40
+ "MV_CI_Map",
41
+ "MV_CI_CenterCoordinates",
42
+ "MV_CI_Dimensions",
43
+ "MV_DetailOnClick",
44
+ "MV_LayerManagement",
45
+ "MV_LM_CenterViewOnLayer",
46
+ "MV_LM_Order",
47
+ "MV_LM_Opacity",
48
+ "MV_LM_HideLayer",
49
+ "MV_LM_Style",
50
+ "MV_LM_ExternalLayer",
51
+ "MV_LM_StylePreview",
52
+ "MV_T_Export",
53
+ "MV_T_E_Type",
54
+ "MV_T_E_F_URL",
55
+ "MV_T_E_F_PDF",
56
+ "MV_T_E_SetScale",
57
+ "MV_T_E_ShowLegend",
58
+ "MV_T_InformationMode",
59
+ "MV_T_MeasureControl",
60
+ "MV_T_M_Distance",
61
+ "MV_T_M_Line",
62
+ "MV_T_M_Polygon",
63
+ "MV_T_ZoomWindow",
64
+ "GUI_Menu",
65
+ "GUI_M_Position",
66
+ "GUI_M_Top",
67
+ "DM_DataInput",
68
+ "DM_DI_DataFeeding",
69
+ "DM_DI_DF_Shapefile",
70
+ "T_GIS",
71
+ "T_EntitiesInformation",
72
+ "D_C_Postgres",
73
+ "D_C_Geoserver",
74
+ "D_C_Nginx",
75
+ ],
76
+ basicData: {
77
+ name: spec.name,
78
+ },
79
+ data: {
80
+ dataModel: {
81
+ entities: spec.entities,
82
+ enums: [],
83
+ },
84
+ },
85
+ mapViewer: {
86
+ maps: spec.maps,
87
+ layers: spec.layers,
88
+ styles: spec.styles,
89
+ },
90
+ };
91
+
92
+ if (spec.extra) {
93
+ newSpec.basicData.extra = spec.extra;
94
+ }
95
+
96
+ return newSpec;
97
+ }
98
+
99
+ function _relationships(spec) {
100
+ let source, target;
101
+
102
+ spec.relationships.forEach((r) => {
103
+ source = spec.getEntity(r.source);
104
+ target = spec.getEntity(r.target);
105
+ let sourceOwner = false;
106
+ let targetOwner = false;
107
+ let sourceMultiple = _multiple(r.sourceOpts.multiplicity);
108
+ let targetMultiple = _multiple(r.targetOpts.multiplicity);
109
+ if (sourceMultiple && !targetMultiple) {
110
+ targetOwner = true;
111
+ } else {
112
+ sourceOwner = true;
113
+ }
114
+
115
+ source.properties.push({
116
+ name: r.sourceOpts.label,
117
+ class: target.name,
118
+ owner: sourceOwner,
119
+ bidirectional: r.targetOpts.label,
120
+ multiple: sourceMultiple,
121
+ required: _required(r.sourceOpts.multiplicity),
122
+ });
123
+
124
+ target.properties.push({
125
+ name: r.targetOpts.label,
126
+ class: source.name,
127
+ owner: targetOwner,
128
+ bidirectional: r.sourceOpts.label,
129
+ multiple: targetMultiple,
130
+ required: _required(r.targetOpts.multiplicity),
131
+ });
132
+ });
133
+ }
134
+
135
+ function _multiple(multiplicity) {
136
+ return ["1..1", "0..1"].find((a) => a == multiplicity) == null;
137
+ }
138
+
139
+ function _required(multiplicity) {
140
+ return ["1..1", "1..*"].find((a) => a == multiplicity) != null;
141
+ }
142
+
143
+ function getPropertyParams(symbols) {
144
+ if (!symbols.length) return null;
145
+
146
+ const ret = {};
147
+ if (symbols.includes("identifier")) {
148
+ ret.pk = true;
149
+ }
150
+ if (symbols.includes("required")) {
151
+ ret.required = true;
152
+ }
153
+ if (symbols.includes("unique")) {
154
+ ret.unique = true;
155
+ }
156
+ if (symbols.includes("display_string")) {
157
+ ret.displayString = true;
158
+ }
159
+ return ret;
160
+ }
161
+
162
+ export { transformation, getPropertyParams };
package/src/cli.js CHANGED
@@ -1,34 +1,34 @@
1
- #!/usr/bin/env node
2
-
3
- import meow from "meow";
4
- import fs from "fs";
5
- import gisdslParser from "./index.js";
6
- import path from "path";
7
-
8
- const usage = "Usage: gisdsl input output";
9
-
10
- const cli = meow(usage, {
11
- importMeta: import.meta,
12
- flags: {
13
- debug: {
14
- type: "boolean",
15
- default: false,
16
- },
17
- },
18
- });
19
-
20
- if (cli.input.length < 2) {
21
- cli.showHelp();
22
- }
23
-
24
- const inputPath = path.resolve(process.cwd(), cli.input.at(0));
25
- const input = fs.readFileSync(inputPath, {
26
- encoding: "utf-8",
27
- });
28
-
29
- const spec = gisdslParser(input, cli.flags.debug);
30
-
31
- const outputPath = path.resolve(process.cwd(), cli.input.at(1));
32
- fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2), "utf8");
33
-
34
- console.log(`File ${cli.input.at(1)} generated`);
1
+ #!/usr/bin/env node
2
+
3
+ import meow from "meow";
4
+ import fs from "fs";
5
+ import gisdslParser from "./index.js";
6
+ import path from "path";
7
+
8
+ const usage = "Usage: gisdsl input output";
9
+
10
+ const cli = meow(usage, {
11
+ importMeta: import.meta,
12
+ flags: {
13
+ debug: {
14
+ type: "boolean",
15
+ default: false,
16
+ },
17
+ },
18
+ });
19
+
20
+ if (cli.input.length < 2) {
21
+ cli.showHelp();
22
+ }
23
+
24
+ const inputPath = path.resolve(process.cwd(), cli.input.at(0));
25
+ const input = fs.readFileSync(inputPath, {
26
+ encoding: "utf-8",
27
+ });
28
+
29
+ const spec = gisdslParser(input, cli.flags.debug);
30
+
31
+ const outputPath = path.resolve(process.cwd(), cli.input.at(1));
32
+ fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2), "utf8");
33
+
34
+ console.log(`File ${cli.input.at(1)} generated`);
@@ -1,26 +1,26 @@
1
- import antlr4 from "antlr4";
2
-
3
- import SyntaxGenericError from "./SyntaxGenericError.js";
4
-
5
- /**
6
- * Custom Error Listener
7
- *
8
- * @returns {object}
9
- */
10
- class ErrorListener extends antlr4.error.ErrorListener {
11
- /**
12
- * Checks syntax error
13
- *
14
- * @param {object} recognizer The parsing support code essentially. Most of it is error recovery stuff
15
- * @param {object} symbol Offending symbol
16
- * @param {int} line Line of offending symbol
17
- * @param {int} column Position in line of offending symbol
18
- * @param {string} message Error message
19
- * @param {string} payload Stack trace
20
- */
21
- syntaxError(recognizer, symbol, line, column, message) {
22
- throw new SyntaxGenericError({ line, column, message });
23
- }
24
- }
25
-
26
- export default ErrorListener;
1
+ import antlr4 from "antlr4";
2
+
3
+ import SyntaxGenericError from "./SyntaxGenericError.js";
4
+
5
+ /**
6
+ * Custom Error Listener
7
+ *
8
+ * @returns {object}
9
+ */
10
+ class ErrorListener extends antlr4.error.ErrorListener {
11
+ /**
12
+ * Checks syntax error
13
+ *
14
+ * @param {object} recognizer The parsing support code essentially. Most of it is error recovery stuff
15
+ * @param {object} symbol Offending symbol
16
+ * @param {int} line Line of offending symbol
17
+ * @param {int} column Position in line of offending symbol
18
+ * @param {string} message Error message
19
+ * @param {string} payload Stack trace
20
+ */
21
+ syntaxError(recognizer, symbol, line, column, message) {
22
+ throw new SyntaxGenericError({ line, column, message });
23
+ }
24
+ }
25
+
26
+ export default ErrorListener;
package/src/index.js CHANGED
@@ -1,26 +1,26 @@
1
- import antlr4 from "antlr4";
2
- import GISGrammarLexer from "./lib/GISGrammarLexer.js";
3
- import GISGrammarParser from "./lib/GISGrammarParser.js";
4
- import ErrorListener from "./error/ErrorListener.js";
5
- import GISVisitor from "./GISVisitor.js";
6
- import store from "./store.js";
7
-
8
- export default function parse(inputStr, debug = false) {
9
- const chars = new antlr4.InputStream(inputStr);
10
- const lexer = new GISGrammarLexer(chars);
11
- lexer.strictMode = false; // do not use js strictMode
12
-
13
- const tokens = new antlr4.CommonTokenStream(lexer);
14
- const parser = new GISGrammarParser(tokens);
15
-
16
- const errorListener = new ErrorListener();
17
- // Do this after creating the parser and before running it
18
- parser.removeErrorListeners(); // Remove default ConsoleErrorListener
19
- parser.addErrorListener(errorListener); // Add custom error listener
20
-
21
- const visitor = new GISVisitor(store, debug);
22
- const tree = parser.parse();
23
- visitor.start(tree);
24
-
25
- return store.getLastGeneratedProduct();
26
- }
1
+ import antlr4 from "antlr4";
2
+ import GISGrammarLexer from "./lib/GISGrammarLexer.js";
3
+ import GISGrammarParser from "./lib/GISGrammarParser.js";
4
+ import ErrorListener from "./error/ErrorListener.js";
5
+ import GISVisitor from "./GISVisitor.js";
6
+ import store from "./store.js";
7
+
8
+ export default function parse(inputStr, debug = false) {
9
+ const chars = new antlr4.InputStream(inputStr);
10
+ const lexer = new GISGrammarLexer(chars);
11
+ lexer.strictMode = false; // do not use js strictMode
12
+
13
+ const tokens = new antlr4.CommonTokenStream(lexer);
14
+ const parser = new GISGrammarParser(tokens);
15
+
16
+ const errorListener = new ErrorListener();
17
+ // Do this after creating the parser and before running it
18
+ parser.removeErrorListeners(); // Remove default ConsoleErrorListener
19
+ parser.addErrorListener(errorListener); // Add custom error listener
20
+
21
+ const visitor = new GISVisitor(store, debug);
22
+ const tree = parser.parse();
23
+ visitor.start(tree);
24
+
25
+ return store.getLastGeneratedProduct();
26
+ }
@@ -1,21 +1,21 @@
1
- export default class GeoJSONLayer {
2
- constructor(id, label, entityId, editable, style) {
3
- this.name = id;
4
- this.type = "geojson";
5
- this.label = label;
6
- this.entityName = entityId;
7
- this.editable = editable;
8
- this.defaultStyle = style;
9
- this.availableStyles = [style];
10
- }
11
-
12
- getId() {
13
- return this.name;
14
- }
15
-
16
- toString() {
17
- return `GeoJSONLayer(${this.name} as ${this.label}) for entity ${
18
- this.entityName
19
- } ${this.editable ? "(editable)" : ""}`;
20
- }
21
- }
1
+ export default class GeoJSONLayer {
2
+ constructor(id, label, entityId, editable, style) {
3
+ this.name = id;
4
+ this.type = "geojson";
5
+ this.label = label;
6
+ this.entityName = entityId;
7
+ this.editable = editable;
8
+ this.defaultStyle = style;
9
+ this.availableStyles = [style];
10
+ }
11
+
12
+ getId() {
13
+ return this.name;
14
+ }
15
+
16
+ toString() {
17
+ return `GeoJSONLayer(${this.name} as ${this.label}) for entity ${
18
+ this.entityName
19
+ } ${this.editable ? "(editable)" : ""}`;
20
+ }
21
+ }
@@ -1,14 +1,14 @@
1
- export default class GeoJSONLayerStyle {
2
- constructor(id, fillColor, strokeColor, fillOpacity, strokeOpacity) {
3
- this.name = id;
4
- this.type = "GeoJSONLayerStyle";
5
- this.fillColor = fillColor;
6
- this.strokeColor = strokeColor;
7
- this.fillOpacity = fillOpacity;
8
- this.strokeOpacity = strokeOpacity;
9
- }
10
-
11
- getId() {
12
- return this.name;
13
- }
14
- }
1
+ export default class GeoJSONLayerStyle {
2
+ constructor(id, fillColor, strokeColor, fillOpacity, strokeOpacity) {
3
+ this.name = id;
4
+ this.type = "GeoJSONLayerStyle";
5
+ this.fillColor = fillColor;
6
+ this.strokeColor = strokeColor;
7
+ this.fillOpacity = fillOpacity;
8
+ this.strokeOpacity = strokeOpacity;
9
+ }
10
+
11
+ getId() {
12
+ return this.name;
13
+ }
14
+ }
@@ -1,16 +1,16 @@
1
- export default class TileLayer {
2
- constructor(id, label, url) {
3
- this.name = id;
4
- this.type = "tilelayer";
5
- this.label = label;
6
- this.url = url;
7
- }
8
-
9
- getId() {
10
- return this.name;
11
- }
12
-
13
- toString() {
14
- return `TileLayer(${this.name} as ${this.label}) with url ${this.url}`;
15
- }
16
- }
1
+ export default class TileLayer {
2
+ constructor(id, label, url) {
3
+ this.name = id;
4
+ this.type = "tilelayer";
5
+ this.label = label;
6
+ this.url = url;
7
+ }
8
+
9
+ getId() {
10
+ return this.name;
11
+ }
12
+
13
+ toString() {
14
+ return `TileLayer(${this.name} as ${this.label}) with url ${this.url}`;
15
+ }
16
+ }
@@ -1,30 +1,30 @@
1
- export default class WMSLayer {
2
- constructor(id, label) {
3
- this.name = id;
4
- this.type = "wms";
5
- this.label = label;
6
- this.list = null;
7
- this.layers = [];
8
- this.availableStyles = [];
9
- this.defaultStyles = [];
10
- }
11
-
12
- getId() {
13
- return this.name;
14
- }
15
-
16
- addSubLayer(entityId, style) {
17
- this.list = entityId;
18
- this.layers.push(entityId);
19
- this.defaultStyles = style;
20
- this.availableStyles.push(style);
21
- }
22
-
23
- toString() {
24
- return `WMSLayer(${this.name} as ${this.label}) - ${
25
- this.layers.length
26
- } sublayers for entities ${this.layers
27
- .map((sl) => sl.entityId)
28
- .join(", ")}`;
29
- }
30
- }
1
+ export default class WMSLayer {
2
+ constructor(id, label) {
3
+ this.name = id;
4
+ this.type = "wms";
5
+ this.label = label;
6
+ this.list = null;
7
+ this.layers = [];
8
+ this.availableStyles = [];
9
+ this.defaultStyles = [];
10
+ }
11
+
12
+ getId() {
13
+ return this.name;
14
+ }
15
+
16
+ addSubLayer(entityId, style) {
17
+ this.list = entityId;
18
+ this.layers.push(entityId);
19
+ this.defaultStyles = style;
20
+ this.availableStyles.push(style);
21
+ }
22
+
23
+ toString() {
24
+ return `WMSLayer(${this.name} as ${this.label}) - ${
25
+ this.layers.length
26
+ } sublayers for entities ${this.layers
27
+ .map((sl) => sl.entityId)
28
+ .join(", ")}`;
29
+ }
30
+ }
@@ -1,13 +1,13 @@
1
- export default class WMSStyle {
2
- constructor(id, sldPath) {
3
- this.name = id;
4
- this.type = "WMSLayerSLDStyle";
5
- this.cached = true;
6
- this.sldPath = sldPath;
7
- this.sld = `@include:${sldPath}`;
8
- }
9
-
10
- getId() {
11
- return this.name;
12
- }
13
- }
1
+ export default class WMSStyle {
2
+ constructor(id, sldPath) {
3
+ this.name = id;
4
+ this.type = "WMSLayerSLDStyle";
5
+ this.cached = true;
6
+ this.sldPath = sldPath;
7
+ this.sld = `@include:${sldPath}`;
8
+ }
9
+
10
+ getId() {
11
+ return this.name;
12
+ }
13
+ }
package/src/store.js CHANGED
@@ -1,74 +1,74 @@
1
- const store = {
2
- products: [],
3
- currentProduct: null,
4
- currentEntity: null,
5
- lastGeneratedProduct: null,
6
- };
7
-
8
- function getProducts() {
9
- return store.products;
10
- }
11
-
12
- function getCurrentProduct() {
13
- return store.currentProduct;
14
- }
15
-
16
- function setCurrentProduct(productName) {
17
- if (!productName) {
18
- store.currentProduct = null;
19
- } else {
20
- store.currentProduct = getProduct(productName);
21
- if (!store.currentProduct) {
22
- throw `GIS ${productName} does not exist!!!`;
23
- }
24
- }
25
- }
26
-
27
- function getCurrentEntity() {
28
- return store.currentEntity;
29
- }
30
-
31
- function setCurrentEntity(entityName) {
32
- if (!entityName) {
33
- store.currentEntity = null;
34
- } else {
35
- store.currentEntity = getCurrentProduct().getEntity(entityName);
36
- if (!store.currentEntity) {
37
- throw `Entity ${entityName} does not exist in current product!!!`;
38
- }
39
- }
40
- }
41
-
42
- function getProduct(name) {
43
- return store.products.find((e) => e.name == name);
44
- }
45
-
46
- function addProduct(id, product) {
47
- store.products.push(product);
48
- }
49
-
50
- function getLastGeneratedProduct() {
51
- return store.lastGeneratedProduct;
52
- }
53
-
54
- function setLastGeneratedProduct(generatedProduct) {
55
- store.lastGeneratedProduct = generatedProduct;
56
- }
57
-
58
- function reset() {
59
- store.products.splice(0, store.products.length);
60
- store.lastGeneratedProduct = null;
61
- }
62
-
63
- export default {
64
- getCurrentProduct,
65
- setCurrentProduct,
66
- getCurrentEntity,
67
- setCurrentEntity,
68
- getProducts,
69
- getProduct,
70
- addProduct,
71
- getLastGeneratedProduct,
72
- setLastGeneratedProduct,
73
- reset,
74
- };
1
+ const store = {
2
+ products: [],
3
+ currentProduct: null,
4
+ currentEntity: null,
5
+ lastGeneratedProduct: null,
6
+ };
7
+
8
+ function getProducts() {
9
+ return store.products;
10
+ }
11
+
12
+ function getCurrentProduct() {
13
+ return store.currentProduct;
14
+ }
15
+
16
+ function setCurrentProduct(productName) {
17
+ if (!productName) {
18
+ store.currentProduct = null;
19
+ } else {
20
+ store.currentProduct = getProduct(productName);
21
+ if (!store.currentProduct) {
22
+ throw `GIS ${productName} does not exist!!!`;
23
+ }
24
+ }
25
+ }
26
+
27
+ function getCurrentEntity() {
28
+ return store.currentEntity;
29
+ }
30
+
31
+ function setCurrentEntity(entityName) {
32
+ if (!entityName) {
33
+ store.currentEntity = null;
34
+ } else {
35
+ store.currentEntity = getCurrentProduct().getEntity(entityName);
36
+ if (!store.currentEntity) {
37
+ throw `Entity ${entityName} does not exist in current product!!!`;
38
+ }
39
+ }
40
+ }
41
+
42
+ function getProduct(name) {
43
+ return store.products.find((e) => e.name == name);
44
+ }
45
+
46
+ function addProduct(id, product) {
47
+ store.products.push(product);
48
+ }
49
+
50
+ function getLastGeneratedProduct() {
51
+ return store.lastGeneratedProduct;
52
+ }
53
+
54
+ function setLastGeneratedProduct(generatedProduct) {
55
+ store.lastGeneratedProduct = generatedProduct;
56
+ }
57
+
58
+ function reset() {
59
+ store.products.splice(0, store.products.length);
60
+ store.lastGeneratedProduct = null;
61
+ }
62
+
63
+ export default {
64
+ getCurrentProduct,
65
+ setCurrentProduct,
66
+ getCurrentEntity,
67
+ setCurrentEntity,
68
+ getProducts,
69
+ getProduct,
70
+ addProduct,
71
+ getLastGeneratedProduct,
72
+ setLastGeneratedProduct,
73
+ reset,
74
+ };