sdc_client 0.58.6 → 0.158.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.
Files changed (39) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/.idea/inspectionProfiles/Project_Default.xml +17 -0
  3. package/.idea/workspace.xml +122 -23
  4. package/.readthedocs.yaml +13 -0
  5. package/dist/index.js +70 -51
  6. package/dist/ugly.index.js +1 -1
  7. package/docs/api-reference.rst +225 -0
  8. package/docs/conf.py +11 -0
  9. package/docs/controllers.rst +228 -0
  10. package/docs/events-and-dom.rst +120 -0
  11. package/docs/getting-started.rst +143 -0
  12. package/docs/index.rst +22 -0
  13. package/docs/models.rst +351 -0
  14. package/docs/overview.rst +66 -0
  15. package/docs/requirements.txt +1 -0
  16. package/eslint.config.js +60 -0
  17. package/gulp/gulp.jsx +15 -13
  18. package/package.json +13 -3
  19. package/src/index.js +44 -11
  20. package/src/simpleDomControl/AbstractSDC.js +287 -286
  21. package/src/simpleDomControl/sdc_controller.js +157 -132
  22. package/src/simpleDomControl/sdc_dom_events.js +99 -88
  23. package/src/simpleDomControl/sdc_events.js +39 -40
  24. package/src/simpleDomControl/sdc_main.js +88 -67
  25. package/src/simpleDomControl/sdc_model.js +1513 -0
  26. package/src/simpleDomControl/sdc_params.js +44 -29
  27. package/src/simpleDomControl/sdc_server_call.js +153 -154
  28. package/src/simpleDomControl/sdc_socket.js +8 -829
  29. package/src/simpleDomControl/sdc_test_utils.js +77 -80
  30. package/src/simpleDomControl/sdc_utils.js +295 -176
  31. package/src/simpleDomControl/sdc_view.js +245 -177
  32. package/test/model.test.js +332 -0
  33. package/test/models/Author.js +145 -0
  34. package/test/models/Book.js +112 -0
  35. package/test/models/BookContent.js +114 -0
  36. package/test/models/SdcUser.js +75 -0
  37. package/test/models/src.js +8 -0
  38. package/test/sdc_model_dates.ai.test.js +57 -0
  39. package/test/sdc_server_call.ai.test.js +267 -0
@@ -1,26 +1,34 @@
1
- import {getParamsNameOfFunction, checkIfParamNumberBoolOrString} from "./sdc_utils.js";
2
- import {DATA_CONTROLLER_KEY} from "./sdc_view.js";
3
-
1
+ import {
2
+ getParamsNameOfFunction,
3
+ checkIfParamNumberBoolOrString,
4
+ } from "./sdc_utils.js";
5
+ import { DATA_CONTROLLER_KEY } from "./sdc_view.js";
4
6
 
5
7
  export function prepareData(data, paramNameList = []) {
6
- const data_json_key = 'SDC_JSON_MODEL=['
8
+ const data_json_key = "SDC_JSON_MODEL=[";
7
9
  return Object.fromEntries(
8
- Object.entries(data).filter(([key, element]) => {
9
- return key !== DATA_CONTROLLER_KEY && !paramNameList.includes(key);
10
- }).map(([key, element]) => {
11
- if (typeof element === 'string' && element.startsWith(data_json_key)) {
12
- try {
13
- const {pk, fields} = JSON.parse(element.slice(data_json_key.length, -1));
14
- return [key, {
15
- ...fields,
16
- id: pk,
17
- pk
18
- }];
19
- } catch {
10
+ Object.entries(data)
11
+ .filter(([key, element]) => {
12
+ return key !== DATA_CONTROLLER_KEY && !paramNameList.includes(key);
13
+ })
14
+ .map(([key, element]) => {
15
+ if (typeof element === "string" && element.startsWith(data_json_key)) {
16
+ try {
17
+ const { pk, fields } = JSON.parse(
18
+ element.slice(data_json_key.length, -1),
19
+ );
20
+ return [
21
+ key,
22
+ {
23
+ ...fields,
24
+ id: pk,
25
+ pk,
26
+ },
27
+ ];
28
+ } catch {}
20
29
  }
21
- }
22
- return [key, element];
23
- })
30
+ return [key, element];
31
+ }),
24
32
  );
25
33
  }
26
34
 
@@ -40,11 +48,11 @@ function getParamList(paramNameList, $element) {
40
48
  if (data.hasOwnProperty(data_name)) {
41
49
  returnList.push(data[data_name]);
42
50
  } else {
43
- returnList.push('undefined');
51
+ returnList.push("undefined");
44
52
  }
45
53
  }
46
54
 
47
- returnList.push(restData)
55
+ returnList.push(restData);
48
56
  return returnList;
49
57
  }
50
58
 
@@ -73,23 +81,30 @@ function getDomTagParamsWithList(paramNameList, $element, controller = null) {
73
81
  */
74
82
  function reg_runOnInitWithParameter(controller, $element, applyController) {
75
83
  if (!controller) {
76
- return false
77
- } else if (typeof controller.onInit !== 'function') {
78
- return false
84
+ return false;
85
+ } else if (typeof controller.onInit !== "function") {
86
+ return false;
79
87
  }
80
88
  let paramNameList;
81
- if (typeof controller._on_init_params === 'function') {
89
+ if (typeof controller._on_init_params === "function") {
82
90
  paramNameList = controller._on_init_params();
83
91
  } else {
84
92
  paramNameList = getParamsNameOfFunction(controller.onInit);
85
93
  }
86
94
 
87
-
88
- let initParams = getDomTagParamsWithList(paramNameList, $element, applyController._parentController);
95
+ let initParams = getDomTagParamsWithList(
96
+ paramNameList,
97
+ $element,
98
+ applyController._parentController,
99
+ );
89
100
  controller.onInit.apply(applyController, initParams);
90
101
  if (applyController === controller) {
91
102
  for (let mixinKey in controller._mixins) {
92
- reg_runOnInitWithParameter(controller._mixins[mixinKey], $element, applyController);
103
+ reg_runOnInitWithParameter(
104
+ controller._mixins[mixinKey],
105
+ $element,
106
+ applyController,
107
+ );
93
108
  }
94
109
  }
95
110
  }
@@ -100,4 +115,4 @@ export function runOnInitWithParameter($element, controller) {
100
115
 
101
116
  export function getUrlParam(controller, $element) {
102
117
  return getDomTagParamsWithList(controller._urlParams, $element);
103
- }
118
+ }
@@ -1,187 +1,186 @@
1
- import {uuidv4} from "./sdc_utils.js";
2
- import {trigger} from "./sdc_events.js";
1
+ import { uuidv4 } from "./sdc_utils.js";
2
+ import { trigger } from "./sdc_events.js";
3
3
 
4
4
  let IS_CONNECTED = false;
5
5
  let IS_CONNECTING = false;
6
- let SDC_SOCKET = null
6
+ let SDC_SOCKET = null;
7
7
  let OPEN_REQUESTS = {};
8
8
 
9
9
  export function callServer(app, controller, parsedContentUrl, funcName, args) {
10
- if (window.SERVER_CALL_VIA_WEB_SOCKET) {
11
- return socketCallServer(app, controller, funcName, args);
12
- } else {
13
- return postCallServer(parsedContentUrl, funcName, args);
14
- }
15
-
10
+ if (window.SERVER_CALL_VIA_WEB_SOCKET) {
11
+ return socketCallServer(app, controller, funcName, args);
12
+ } else {
13
+ return postCallServer(parsedContentUrl, funcName, args);
14
+ }
16
15
  }
17
16
 
18
17
  export function isConnected() {
19
- if (window.SERVER_CALL_VIA_WEB_SOCKET) {
20
- return socketIsConnected();
21
- } else {
22
- return Promise.resolve(true);
23
- }
18
+ if (window.SERVER_CALL_VIA_WEB_SOCKET) {
19
+ return socketIsConnected();
20
+ } else {
21
+ return Promise.resolve(true);
22
+ }
24
23
  }
25
24
 
26
25
  export function close() {
27
- if (window.SERVER_CALL_VIA_WEB_SOCKET) {
28
- socketClose();
29
- }
26
+ if (window.SERVER_CALL_VIA_WEB_SOCKET) {
27
+ socketClose();
28
+ }
30
29
  }
31
30
 
32
31
  function postCallServer(parsedContentUrl, funcName, args) {
33
- if(typeof args !== 'object' && Array.isArray(args) && args === null) {
34
- args = {'arg0': args}
35
- }
36
- args = {
37
- 'data': JSON.stringify(args),
38
- '_sdc_func_name': funcName, '_method': 'sdc_server_call'
39
- }
40
- return $.post({
41
- url: parsedContentUrl,
42
- data: args,
43
- beforeSend: function (xhr, settings) {
44
- xhr.setRequestHeader("X-CSRFToken", window.CSRF_TOKEN);
45
- }
46
- }).then((res) => {
47
- const data = res['_return_data'];
48
- _handle_response(data);
49
- return data;
50
- }).catch((res) => {
51
- const data = res.responseJSON;
52
- data.is_error = true;
53
- _handle_response(data);
54
- throw res;
32
+ if (typeof args !== "object" && Array.isArray(args) && args === null) {
33
+ args = { arg0: args };
34
+ }
35
+ args = {
36
+ data: JSON.stringify(args),
37
+ _sdc_func_name: funcName,
38
+ _method: "sdc_server_call",
39
+ };
40
+ return $.post({
41
+ url: parsedContentUrl,
42
+ data: args,
43
+ beforeSend: function (xhr, settings) {
44
+ xhr.setRequestHeader("X-CSRFToken", window.CSRF_TOKEN);
45
+ },
46
+ })
47
+ .then((res) => {
48
+ const data = res["_return_data"];
49
+ _handle_response(data);
50
+ return data;
51
+ })
52
+ .catch((res) => {
53
+ const data = res.responseJSON;
54
+ data.is_error = true;
55
+ _handle_response(data);
56
+ throw res;
55
57
  });
56
58
  }
57
59
 
58
60
  function socketCallServer(app, controller, funcName, args) {
59
-
60
- let id = uuidv4();
61
- isConnected().then(() => {
62
- SDC_SOCKET.send(JSON.stringify({
63
- event: 'sdc_call',
64
- id: id,
65
- controller: controller,
66
- app: app,
67
- function: funcName,
68
- args: args
69
- }));
70
- });
71
-
72
- return new Promise((resolve, reject) => {
73
- OPEN_REQUESTS[id] = [resolve, reject];
74
- });
61
+ let id = uuidv4();
62
+ isConnected().then(() => {
63
+ SDC_SOCKET.send(
64
+ JSON.stringify({
65
+ event: "sdc_call",
66
+ id: id,
67
+ controller: controller,
68
+ app: app,
69
+ function: funcName,
70
+ args: args,
71
+ }),
72
+ );
73
+ });
74
+
75
+ return new Promise((resolve, reject) => {
76
+ OPEN_REQUESTS[id] = [resolve, reject];
77
+ });
75
78
  }
76
79
 
77
80
  function _connect() {
78
- IS_CONNECTING = true;
79
- return new Promise((resolve) => {
80
- if (window.location.protocol === "https:") {
81
- SDC_SOCKET = new WebSocket(`wss://${window.location.host}/sdc_ws/ws/`);
82
- } else {
83
- SDC_SOCKET = new WebSocket(`ws://${window.location.host}/sdc_ws/ws/`);
84
- }
85
-
86
-
87
- SDC_SOCKET.onmessage = function (e) {
88
- let data = JSON.parse(e.data);
89
- _handle_response(data);
90
- };
91
-
92
- SDC_SOCKET.onclose = function () {
93
- if (IS_CONNECTED) {
94
- console.error('SDC Socket closed unexpectedly');
95
- }
96
- IS_CONNECTED = false;
97
- for (const [key, value] of Object.entries(OPEN_REQUESTS)) {
98
- value[1]({});
99
- delete OPEN_REQUESTS[key];
100
- }
101
-
102
- setTimeout(() => {
103
- _connect();
104
- }, 1000);
105
- };
106
-
107
- SDC_SOCKET.onerror = function (err) {
108
- console.error('Socket encountered error: ', err.message, 'Closing socket');
109
- if (IS_CONNECTED) {
110
- try {
111
- SDC_SOCKET.close();
112
- } catch (e) {
113
-
114
- }
115
- }
116
- };
117
-
118
- SDC_SOCKET.onopen = function () {
119
- IS_CONNECTED = true;
120
- IS_CONNECTING = false;
121
- resolve();
122
- }
123
- })
81
+ IS_CONNECTING = true;
82
+ return new Promise((resolve) => {
83
+ if (window.location.protocol === "https:") {
84
+ SDC_SOCKET = new WebSocket(`wss://${window.location.host}/sdc_ws/ws/`);
85
+ } else {
86
+ SDC_SOCKET = new WebSocket(`ws://${window.location.host}/sdc_ws/ws/`);
87
+ }
88
+
89
+ SDC_SOCKET.onmessage = function (e) {
90
+ let data = JSON.parse(e.data);
91
+ _handle_response(data);
92
+ };
93
+
94
+ SDC_SOCKET.onclose = function () {
95
+ if (IS_CONNECTED) {
96
+ console.error("SDC Socket closed unexpectedly");
97
+ }
98
+ IS_CONNECTED = false;
99
+ for (const [key, value] of Object.entries(OPEN_REQUESTS)) {
100
+ value[1]({});
101
+ delete OPEN_REQUESTS[key];
102
+ }
103
+
104
+ setTimeout(() => {
105
+ _connect();
106
+ }, 1000);
107
+ };
108
+
109
+ SDC_SOCKET.onerror = function (err) {
110
+ console.error(
111
+ "Socket encountered error: ",
112
+ err.message,
113
+ "Closing socket",
114
+ );
115
+ if (IS_CONNECTED) {
116
+ try {
117
+ SDC_SOCKET.close();
118
+ } catch (e) {}
119
+ }
120
+ };
121
+
122
+ SDC_SOCKET.onopen = function () {
123
+ IS_CONNECTED = true;
124
+ IS_CONNECTING = false;
125
+ resolve();
126
+ };
127
+ });
124
128
  }
125
129
 
126
130
  function _handle_response(data) {
127
- if(!data) {
128
- data = {};
131
+ if (!data) {
132
+ data = {};
133
+ }
134
+ if (data.is_error) {
135
+ if (data.msg || data.header) {
136
+ trigger("pushErrorMsg", data.header || "", data.msg || "");
129
137
  }
130
- if (data.is_error) {
131
- if (data.msg || data.header) {
132
- trigger('pushErrorMsg', data.header || '', data.msg || '');
133
- }
134
- if (data.id && OPEN_REQUESTS[data.id]) {
135
- OPEN_REQUESTS[data.id][1](data.data || null);
136
- delete OPEN_REQUESTS[data.id];
137
- }
138
- } else {
139
- if (data.msg || data.header) {
140
- trigger('pushMsg', data.header || '', data.msg || '');
141
- }
142
-
143
- if (data.type && data.type === 'sdc_recall') {
144
- if (data.id && OPEN_REQUESTS[data.id]) {
145
- OPEN_REQUESTS[data.id][0](data.data);
146
- delete OPEN_REQUESTS[data.id];
147
- }
148
- } else if (data.type && data.type === 'sdc_event') {
149
- let event = data.event;
150
- if (event) {
151
- trigger(event, data.payload);
152
- }
153
-
154
- } else if (data.type && data.type === 'sdc_redirect') {
155
- trigger('onNavLink', data.link);
156
- }
138
+ if (data.id && OPEN_REQUESTS[data.id]) {
139
+ OPEN_REQUESTS[data.id][1](data.data || null);
140
+ delete OPEN_REQUESTS[data.id];
141
+ }
142
+ } else {
143
+ if (data.msg || data.header) {
144
+ trigger("pushMsg", data.header || "", data.msg || "");
145
+ }
146
+
147
+ if (data.type && data.type === "sdc_recall") {
148
+ if (data.id && OPEN_REQUESTS[data.id]) {
149
+ OPEN_REQUESTS[data.id][0](data.data);
150
+ delete OPEN_REQUESTS[data.id];
151
+ }
152
+ } else if (data.type && data.type === "sdc_event") {
153
+ let event = data.event;
154
+ if (event) {
155
+ trigger(event, data.payload);
156
+ }
157
+ } else if (data.type && data.type === "sdc_redirect") {
158
+ trigger("onNavLink", data.link);
157
159
  }
160
+ }
158
161
  }
159
162
 
160
163
  function socketClose() {
161
- if (IS_CONNECTED) {
162
- IS_CONNECTED = false;
163
- try {
164
- SDC_SOCKET.close();
165
- } catch (e) {
166
-
167
- }
168
-
169
- }
164
+ if (IS_CONNECTED) {
165
+ IS_CONNECTED = false;
166
+ try {
167
+ SDC_SOCKET.close();
168
+ } catch (e) {}
169
+ }
170
170
  }
171
171
 
172
172
  function socketIsConnected() {
173
-
174
- return new Promise((resolve) => {
175
- if (IS_CONNECTED) {
176
- return resolve();
177
- } else if (IS_CONNECTING) {
178
- setTimeout(() => {
179
- isConnected().then(() => {
180
- resolve();
181
- });
182
- }, 200);
183
- } else {
184
- return resolve(_connect());
185
- }
186
- });
187
- }
173
+ return new Promise((resolve) => {
174
+ if (IS_CONNECTED) {
175
+ return resolve();
176
+ } else if (IS_CONNECTING) {
177
+ setTimeout(() => {
178
+ isConnected().then(() => {
179
+ resolve();
180
+ });
181
+ }, 200);
182
+ } else {
183
+ return resolve(_connect());
184
+ }
185
+ });
186
+ }