@statezero/core 0.1.29 → 0.1.31
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/dist/cli/commands/syncActions.js +2 -2
- package/dist/syncEngine/registries/metricRegistry.d.ts +5 -0
- package/dist/syncEngine/registries/metricRegistry.js +8 -0
- package/dist/syncEngine/registries/querysetStoreRegistry.d.ts +5 -0
- package/dist/syncEngine/registries/querysetStoreRegistry.js +32 -8
- package/package.json +1 -1
|
@@ -100,8 +100,7 @@ const JS_ACTION_TEMPLATE = `/**
|
|
|
100
100
|
|
|
101
101
|
import axios from 'axios';
|
|
102
102
|
import { z } from 'zod';
|
|
103
|
-
import { configInstance } from '{{modulePath}}';
|
|
104
|
-
import { parseStateZeroError } from '{{modulePath}}/flavours/django/errors.js';
|
|
103
|
+
import { configInstance, parseStateZeroError } from '{{modulePath}}';
|
|
105
104
|
|
|
106
105
|
{{#if inputSchemaString}}
|
|
107
106
|
/**
|
|
@@ -437,6 +436,7 @@ function prepareActionTemplateData(modulePath, functionName, actionName, actionD
|
|
|
437
436
|
}
|
|
438
437
|
async function generateActionFile(backend, actionName, actionDefinition) {
|
|
439
438
|
const functionName = _.camelCase(actionName);
|
|
439
|
+
// Apply the same logic as syncModels.js
|
|
440
440
|
const modulePath = process.env.NODE_ENV === "test" ? "../../../src" : "@statezero/core";
|
|
441
441
|
const appName = (actionDefinition.app || "general").toLowerCase();
|
|
442
442
|
const outDir = path.join(backend.GENERATED_ACTIONS_DIR, appName);
|
|
@@ -8,6 +8,11 @@ export class LiveMetric {
|
|
|
8
8
|
metricType: any;
|
|
9
9
|
field: any;
|
|
10
10
|
get lqs(): import("./querysetStoreRegistry").LiveQueryset;
|
|
11
|
+
/**
|
|
12
|
+
* Refresh the metric data from the database
|
|
13
|
+
* Delegates to the underlying store's sync method
|
|
14
|
+
*/
|
|
15
|
+
refreshFromDb(): any;
|
|
11
16
|
/**
|
|
12
17
|
* Getter that always returns the current value from the store
|
|
13
18
|
*/
|
|
@@ -17,6 +17,14 @@ export class LiveMetric {
|
|
|
17
17
|
get lqs() {
|
|
18
18
|
return querysetStoreRegistry.getEntity(this.queryset);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Refresh the metric data from the database
|
|
22
|
+
* Delegates to the underlying store's sync method
|
|
23
|
+
*/
|
|
24
|
+
refreshFromDb() {
|
|
25
|
+
const store = metricRegistry.getStore(this.metricType, this.queryset, this.field);
|
|
26
|
+
return store.sync();
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Getter that always returns the current value from the store
|
|
22
30
|
*/
|
|
@@ -9,6 +9,11 @@ export class LiveQueryset {
|
|
|
9
9
|
* Serializes the lqs as a simple array of objects, for freezing e.g in the metric stores
|
|
10
10
|
*/
|
|
11
11
|
serialize(): any;
|
|
12
|
+
/**
|
|
13
|
+
* Refresh the queryset data from the database
|
|
14
|
+
* Delegates to the underlying store's sync method
|
|
15
|
+
*/
|
|
16
|
+
refreshFromDb(): any;
|
|
12
17
|
/**
|
|
13
18
|
* Get the current items from the store
|
|
14
19
|
* @private
|
|
@@ -41,28 +41,37 @@ export class LiveQueryset {
|
|
|
41
41
|
__classPrivateFieldSet(this, _LiveQueryset_proxy, new Proxy(__classPrivateFieldGet(this, _LiveQueryset_array, "f"), {
|
|
42
42
|
get: (target, prop, receiver) => {
|
|
43
43
|
// Expose the touch method through the proxy
|
|
44
|
-
if (prop ===
|
|
44
|
+
if (prop === "touch") {
|
|
45
45
|
return () => this.touch();
|
|
46
46
|
}
|
|
47
|
-
if (prop ===
|
|
47
|
+
if (prop === "serialize") {
|
|
48
48
|
return () => this.serialize();
|
|
49
49
|
}
|
|
50
50
|
// Special handling for iterators and common array methods
|
|
51
51
|
if (prop === Symbol.iterator) {
|
|
52
52
|
return () => this.getCurrentItems()[Symbol.iterator]();
|
|
53
53
|
}
|
|
54
|
-
else if (typeof prop ===
|
|
54
|
+
else if (typeof prop === "string" &&
|
|
55
|
+
[
|
|
56
|
+
"forEach",
|
|
57
|
+
"map",
|
|
58
|
+
"filter",
|
|
59
|
+
"reduce",
|
|
60
|
+
"some",
|
|
61
|
+
"every",
|
|
62
|
+
"find",
|
|
63
|
+
].includes(prop)) {
|
|
55
64
|
return (...args) => this.getCurrentItems()[prop](...args);
|
|
56
65
|
}
|
|
57
|
-
else if (prop ===
|
|
66
|
+
else if (prop === "length") {
|
|
58
67
|
return this.getCurrentItems().length;
|
|
59
68
|
}
|
|
60
|
-
else if (typeof prop ===
|
|
69
|
+
else if (typeof prop === "string" && !isNaN(parseInt(prop))) {
|
|
61
70
|
// Handle numeric indices
|
|
62
71
|
return this.getCurrentItems()[prop];
|
|
63
72
|
}
|
|
64
73
|
return target[prop];
|
|
65
|
-
}
|
|
74
|
+
},
|
|
66
75
|
}), "f");
|
|
67
76
|
return __classPrivateFieldGet(this, _LiveQueryset_proxy, "f");
|
|
68
77
|
}
|
|
@@ -74,12 +83,20 @@ export class LiveQueryset {
|
|
|
74
83
|
// Get the current primary keys from the store
|
|
75
84
|
const pks = store.render();
|
|
76
85
|
// Map primary keys to full model objects
|
|
77
|
-
return pks.map(pk => {
|
|
86
|
+
return pks.map((pk) => {
|
|
78
87
|
// Get the full model instance from the model store
|
|
79
88
|
const pkField = __classPrivateFieldGet(this, _LiveQueryset_ModelClass, "f").primaryKeyField;
|
|
80
89
|
return __classPrivateFieldGet(this, _LiveQueryset_ModelClass, "f").fromPk(pk, __classPrivateFieldGet(this, _LiveQueryset_queryset, "f")).serialize();
|
|
81
90
|
});
|
|
82
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Refresh the queryset data from the database
|
|
94
|
+
* Delegates to the underlying store's sync method
|
|
95
|
+
*/
|
|
96
|
+
refreshFromDb() {
|
|
97
|
+
const store = querysetStoreRegistry.getStore(__classPrivateFieldGet(this, _LiveQueryset_queryset, "f"));
|
|
98
|
+
return store.sync();
|
|
99
|
+
}
|
|
83
100
|
/**
|
|
84
101
|
* Get the current items from the store
|
|
85
102
|
* @private
|
|
@@ -90,10 +107,17 @@ export class LiveQueryset {
|
|
|
90
107
|
// Get the current primary keys from the store
|
|
91
108
|
const pks = store.render();
|
|
92
109
|
// Map primary keys to full model objects
|
|
93
|
-
const instances = pks
|
|
110
|
+
const instances = pks
|
|
111
|
+
.map((pk) => {
|
|
94
112
|
// Get the full model instance from the model store
|
|
95
113
|
const pkField = __classPrivateFieldGet(this, _LiveQueryset_ModelClass, "f").primaryKeyField;
|
|
96
114
|
return __classPrivateFieldGet(this, _LiveQueryset_ModelClass, "f").fromPk(pk, __classPrivateFieldGet(this, _LiveQueryset_queryset, "f"));
|
|
115
|
+
})
|
|
116
|
+
.filter((instance) => {
|
|
117
|
+
// Filter out ghost entries - instances where the model data doesn't exist i.e because it has
|
|
118
|
+
// been deleted on the backend but the event hasn't been propagated to this queryset
|
|
119
|
+
const storedData = modelStoreRegistry.getEntity(__classPrivateFieldGet(this, _LiveQueryset_ModelClass, "f"), instance.pk);
|
|
120
|
+
return storedData !== null && storedData !== undefined;
|
|
97
121
|
});
|
|
98
122
|
if (!sortAndFilter)
|
|
99
123
|
return instances;
|
package/package.json
CHANGED