@statezero/core 0.2.14 → 0.2.16
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/actions/backend1/django_app/calculate-hash.js +5 -2
- package/dist/actions/backend1/django_app/get-current-username.js +5 -2
- package/dist/actions/backend1/django_app/get-server-status.js +5 -2
- package/dist/actions/backend1/django_app/get-user-info.js +5 -2
- package/dist/actions/backend1/django_app/process-data.js +5 -2
- package/dist/actions/backend1/django_app/send-notification.js +5 -2
- package/dist/actions/default/django_app/calculate-hash.js +5 -2
- package/dist/actions/default/django_app/get-current-username.js +5 -2
- package/dist/actions/default/django_app/get-server-status.js +5 -2
- package/dist/actions/default/django_app/get-user-info.js +5 -2
- package/dist/actions/default/django_app/process-data.js +5 -2
- package/dist/actions/default/django_app/send-notification.js +5 -2
- package/dist/cli/commands/syncActions.js +11 -5
- package/dist/filtering/localFiltering.js +22 -3
- package/dist/flavours/django/serializers.d.ts +9 -0
- package/dist/flavours/django/serializers.js +31 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './calculate-hash.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of calculateHash.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -31,10 +32,12 @@ export const calculateHashResponseSchema = z.object({ original_text: z.string(),
|
|
|
31
32
|
*/
|
|
32
33
|
export async function calculateHash(text, algorithm = "sha256", axiosOverrides = {}) {
|
|
33
34
|
// Construct the data payload from the function arguments
|
|
34
|
-
const
|
|
35
|
+
const rawPayload = {
|
|
35
36
|
text,
|
|
36
37
|
algorithm
|
|
37
38
|
};
|
|
39
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
40
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
38
41
|
const config = configInstance.getConfig();
|
|
39
42
|
const backend = config.backendConfigs['backend1'];
|
|
40
43
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-current-username.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getCurrentUsername.
|
|
11
12
|
*/
|
|
@@ -19,7 +20,9 @@ export const getCurrentUsernameResponseSchema = z.object({ username: z.string(),
|
|
|
19
20
|
*/
|
|
20
21
|
export async function getCurrentUsername(axiosOverrides = {}) {
|
|
21
22
|
// Construct the data payload from the function arguments
|
|
22
|
-
const
|
|
23
|
+
const rawPayload = {};
|
|
24
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
25
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
23
26
|
const config = configInstance.getConfig();
|
|
24
27
|
const backend = config.backendConfigs['backend1'];
|
|
25
28
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-server-status.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getServerStatus.
|
|
11
12
|
*/
|
|
@@ -22,7 +23,9 @@ export const getServerStatusResponseSchema = z.object({ status: z.string(),
|
|
|
22
23
|
*/
|
|
23
24
|
export async function getServerStatus(axiosOverrides = {}) {
|
|
24
25
|
// Construct the data payload from the function arguments
|
|
25
|
-
const
|
|
26
|
+
const rawPayload = {};
|
|
27
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
28
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
26
29
|
const config = configInstance.getConfig();
|
|
27
30
|
const backend = config.backendConfigs['backend1'];
|
|
28
31
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-user-info.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getUserInfo.
|
|
11
12
|
*/
|
|
@@ -24,7 +25,9 @@ export const getUserInfoResponseSchema = z.object({ username: z.string(),
|
|
|
24
25
|
*/
|
|
25
26
|
export async function getUserInfo(axiosOverrides = {}) {
|
|
26
27
|
// Construct the data payload from the function arguments
|
|
27
|
-
const
|
|
28
|
+
const rawPayload = {};
|
|
29
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
30
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
28
31
|
const config = configInstance.getConfig();
|
|
29
32
|
const backend = config.backendConfigs['backend1'];
|
|
30
33
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './process-data.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of processData.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -29,10 +30,12 @@ export const processDataResponseSchema = z.object({ operation: z.string(),
|
|
|
29
30
|
*/
|
|
30
31
|
export async function processData(data, operation, axiosOverrides = {}) {
|
|
31
32
|
// Construct the data payload from the function arguments
|
|
32
|
-
const
|
|
33
|
+
const rawPayload = {
|
|
33
34
|
data,
|
|
34
35
|
operation
|
|
35
36
|
};
|
|
37
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
38
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
36
39
|
const config = configInstance.getConfig();
|
|
37
40
|
const backend = config.backendConfigs['backend1'];
|
|
38
41
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './send-notification.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of sendNotification.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -31,11 +32,13 @@ export const sendNotificationResponseSchema = z.object({ success: z.boolean(),
|
|
|
31
32
|
*/
|
|
32
33
|
export async function sendNotification(message, recipients, priority = "low", axiosOverrides = {}) {
|
|
33
34
|
// Construct the data payload from the function arguments
|
|
34
|
-
const
|
|
35
|
+
const rawPayload = {
|
|
35
36
|
message,
|
|
36
37
|
recipients,
|
|
37
38
|
priority
|
|
38
39
|
};
|
|
40
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
41
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
39
42
|
const config = configInstance.getConfig();
|
|
40
43
|
const backend = config.backendConfigs['backend1'];
|
|
41
44
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './calculate-hash.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of calculateHash.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -31,10 +32,12 @@ export const calculateHashResponseSchema = z.object({ original_text: z.string(),
|
|
|
31
32
|
*/
|
|
32
33
|
export async function calculateHash(text, algorithm = "sha256", axiosOverrides = {}) {
|
|
33
34
|
// Construct the data payload from the function arguments
|
|
34
|
-
const
|
|
35
|
+
const rawPayload = {
|
|
35
36
|
text,
|
|
36
37
|
algorithm
|
|
37
38
|
};
|
|
39
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
40
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
38
41
|
const config = configInstance.getConfig();
|
|
39
42
|
const backend = config.backendConfigs['default'];
|
|
40
43
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-current-username.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getCurrentUsername.
|
|
11
12
|
*/
|
|
@@ -19,7 +20,9 @@ export const getCurrentUsernameResponseSchema = z.object({ username: z.string(),
|
|
|
19
20
|
*/
|
|
20
21
|
export async function getCurrentUsername(axiosOverrides = {}) {
|
|
21
22
|
// Construct the data payload from the function arguments
|
|
22
|
-
const
|
|
23
|
+
const rawPayload = {};
|
|
24
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
25
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
23
26
|
const config = configInstance.getConfig();
|
|
24
27
|
const backend = config.backendConfigs['default'];
|
|
25
28
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-server-status.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getServerStatus.
|
|
11
12
|
*/
|
|
@@ -22,7 +23,9 @@ export const getServerStatusResponseSchema = z.object({ status: z.string(),
|
|
|
22
23
|
*/
|
|
23
24
|
export async function getServerStatus(axiosOverrides = {}) {
|
|
24
25
|
// Construct the data payload from the function arguments
|
|
25
|
-
const
|
|
26
|
+
const rawPayload = {};
|
|
27
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
28
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
26
29
|
const config = configInstance.getConfig();
|
|
27
30
|
const backend = config.backendConfigs['default'];
|
|
28
31
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './get-user-info.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the response of getUserInfo.
|
|
11
12
|
*/
|
|
@@ -24,7 +25,9 @@ export const getUserInfoResponseSchema = z.object({ username: z.string(),
|
|
|
24
25
|
*/
|
|
25
26
|
export async function getUserInfo(axiosOverrides = {}) {
|
|
26
27
|
// Construct the data payload from the function arguments
|
|
27
|
-
const
|
|
28
|
+
const rawPayload = {};
|
|
29
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
30
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
28
31
|
const config = configInstance.getConfig();
|
|
29
32
|
const backend = config.backendConfigs['default'];
|
|
30
33
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './process-data.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of processData.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -29,10 +30,12 @@ export const processDataResponseSchema = z.object({ operation: z.string(),
|
|
|
29
30
|
*/
|
|
30
31
|
export async function processData(data, operation, axiosOverrides = {}) {
|
|
31
32
|
// Construct the data payload from the function arguments
|
|
32
|
-
const
|
|
33
|
+
const rawPayload = {
|
|
33
34
|
data,
|
|
34
35
|
operation
|
|
35
36
|
};
|
|
37
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
38
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
36
39
|
const config = configInstance.getConfig();
|
|
37
40
|
const backend = config.backendConfigs['default'];
|
|
38
41
|
if (!backend) {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import { configInstance, parseStateZeroError } from '../../../../src';
|
|
8
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '../../../../src';
|
|
9
|
+
import actionSchema from './send-notification.schema.json' assert { type: 'json' };
|
|
9
10
|
/**
|
|
10
11
|
* Zod schema for the input of sendNotification.
|
|
11
12
|
* NOTE: This is an object schema for validating the data payload.
|
|
@@ -31,11 +32,13 @@ export const sendNotificationResponseSchema = z.object({ success: z.boolean(),
|
|
|
31
32
|
*/
|
|
32
33
|
export async function sendNotification(message, recipients, priority = "low", axiosOverrides = {}) {
|
|
33
34
|
// Construct the data payload from the function arguments
|
|
34
|
-
const
|
|
35
|
+
const rawPayload = {
|
|
35
36
|
message,
|
|
36
37
|
recipients,
|
|
37
38
|
priority
|
|
38
39
|
};
|
|
40
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
41
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
39
42
|
const config = configInstance.getConfig();
|
|
40
43
|
const backend = config.backendConfigs['default'];
|
|
41
44
|
if (!backend) {
|
|
@@ -100,7 +100,8 @@ const JS_ACTION_TEMPLATE = `/**
|
|
|
100
100
|
|
|
101
101
|
import axios from 'axios';
|
|
102
102
|
import { z } from 'zod';
|
|
103
|
-
import { configInstance, parseStateZeroError } from '{{modulePath}}';
|
|
103
|
+
import { configInstance, parseStateZeroError, serializeActionPayload } from '{{modulePath}}';
|
|
104
|
+
import actionSchema from './{{schemaFileName}}' assert { type: 'json' };
|
|
104
105
|
|
|
105
106
|
{{#if inputSchemaString}}
|
|
106
107
|
/**
|
|
@@ -133,13 +134,16 @@ export const {{functionName}}ResponseSchema = z.object({ {{{responseSchemaString
|
|
|
133
134
|
export async function {{functionName}}({{{jsFunctionParams}}}) {
|
|
134
135
|
// Construct the data payload from the function arguments
|
|
135
136
|
{{#if payloadProperties}}
|
|
136
|
-
const
|
|
137
|
+
const rawPayload = {
|
|
137
138
|
{{{payloadProperties}}}
|
|
138
139
|
};
|
|
139
140
|
{{else}}
|
|
140
|
-
const
|
|
141
|
+
const rawPayload = {};
|
|
141
142
|
{{/if}}
|
|
142
143
|
|
|
144
|
+
// Serialize payload - handles model instances (extracts PK), files, dates, etc.
|
|
145
|
+
const payload = serializeActionPayload(rawPayload, actionSchema.input_properties);
|
|
146
|
+
|
|
143
147
|
const config = configInstance.getConfig();
|
|
144
148
|
const backend = config.backendConfigs['{{configKey}}'];
|
|
145
149
|
|
|
@@ -444,10 +448,12 @@ async function generateActionFile(backend, actionName, actionDefinition) {
|
|
|
444
448
|
// Always include the backend key as the top-level folder
|
|
445
449
|
const outDir = path.join(backend.GENERATED_ACTIONS_DIR, backend.NAME, appName);
|
|
446
450
|
await fs.mkdir(outDir, { recursive: true });
|
|
447
|
-
const templateData = prepareActionTemplateData(modulePath, functionName, actionName, actionDefinition, backend.NAME);
|
|
448
451
|
const fileName = _.kebabCase(actionName);
|
|
452
|
+
const schemaFileName = `${fileName}.schema.json`;
|
|
453
|
+
const templateData = prepareActionTemplateData(modulePath, functionName, actionName, actionDefinition, backend.NAME);
|
|
454
|
+
templateData.schemaFileName = schemaFileName;
|
|
449
455
|
// Write the raw schema file (like models do)
|
|
450
|
-
const schemaFilePath = path.join(outDir,
|
|
456
|
+
const schemaFilePath = path.join(outDir, schemaFileName);
|
|
451
457
|
await fs.writeFile(schemaFilePath, JSON.stringify(actionDefinition, null, 2));
|
|
452
458
|
// Write JS and TS files
|
|
453
459
|
const jsFilePath = path.join(outDir, `${fileName}.js`);
|
|
@@ -83,6 +83,7 @@ function processFieldPath(fieldPath, value, ModelClass, options = {}) {
|
|
|
83
83
|
let currentModel = ModelClass;
|
|
84
84
|
let processedPath = [];
|
|
85
85
|
let isRelationship = false;
|
|
86
|
+
let isM2M = false; // Track if this is a many-to-many relationship
|
|
86
87
|
let finalFieldName = null; // Track the actual field name for schema lookup
|
|
87
88
|
for (let i = 0; i < fieldParts.length; i++) {
|
|
88
89
|
let part = fieldParts[i];
|
|
@@ -109,6 +110,7 @@ function processFieldPath(fieldPath, value, ModelClass, options = {}) {
|
|
|
109
110
|
// For many-to-many relationships, don't append the primary key field
|
|
110
111
|
// M2M fields store an array of PKs directly, not objects
|
|
111
112
|
if (relationshipType === 'many-to-many') {
|
|
113
|
+
isM2M = true;
|
|
112
114
|
// Keep path as-is (e.g., 'comprehensive_models')
|
|
113
115
|
// Sift will handle array membership check
|
|
114
116
|
finalFieldName = part;
|
|
@@ -154,7 +156,7 @@ function processFieldPath(fieldPath, value, ModelClass, options = {}) {
|
|
|
154
156
|
}
|
|
155
157
|
// Handle the single lookup operation if present
|
|
156
158
|
if (lookup) {
|
|
157
|
-
return createOperatorFromLookup(finalPath, lookup, normalizedValue, isRelationship, currentModel, finalFieldName);
|
|
159
|
+
return createOperatorFromLookup(finalPath, lookup, normalizedValue, isRelationship, currentModel, finalFieldName, isM2M);
|
|
158
160
|
}
|
|
159
161
|
// If there's no explicit lookup and this is a relationship field,
|
|
160
162
|
// we've already appended the PK field name to the path
|
|
@@ -201,9 +203,10 @@ function createDatePartComparisonOperator(field, datePart, comparisonOperator, v
|
|
|
201
203
|
* @param {boolean} isRelationship - Whether the field is a relationship
|
|
202
204
|
* @param {Class} ModelClass - The model class (unused, for future extensibility)
|
|
203
205
|
* @param {string} finalFieldName - The final field name (unused, for future extensibility)
|
|
206
|
+
* @param {boolean} isM2M - Whether the field is a many-to-many relationship
|
|
204
207
|
* @returns {Object} Object with field name and sift operator
|
|
205
208
|
*/
|
|
206
|
-
function createOperatorFromLookup(field, lookup, value, isRelationship, ModelClass, finalFieldName) {
|
|
209
|
+
function createOperatorFromLookup(field, lookup, value, isRelationship, ModelClass, finalFieldName, isM2M = false) {
|
|
207
210
|
// Helper function to escape special characters in regex
|
|
208
211
|
function escapeRegExp(string) {
|
|
209
212
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -212,7 +215,23 @@ function createOperatorFromLookup(field, lookup, value, isRelationship, ModelCla
|
|
|
212
215
|
if (isRelationship) {
|
|
213
216
|
// For relationship fields with lookups, we need special handling
|
|
214
217
|
if (lookup === 'isnull') {
|
|
215
|
-
|
|
218
|
+
if (isM2M) {
|
|
219
|
+
// For M2M fields, isnull=True means null OR empty array, but not undefined because
|
|
220
|
+
// that can mean the field was not fetched so we can't be sure
|
|
221
|
+
// isnull=False means has at least one item
|
|
222
|
+
// Use a custom function since sift doesn't support $or inside field operators
|
|
223
|
+
return {
|
|
224
|
+
field,
|
|
225
|
+
operator: {
|
|
226
|
+
$where: function (fieldValue) {
|
|
227
|
+
const isEmpty = fieldValue === null ||
|
|
228
|
+
(Array.isArray(fieldValue) && fieldValue.length === 0);
|
|
229
|
+
return value ? isEmpty : !isEmpty;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
// For FK/O2O, check for both undefined and null values
|
|
216
235
|
return {
|
|
217
236
|
field,
|
|
218
237
|
operator: value ? { $in: [null, undefined] } : { $nin: [null, undefined] }
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serializes an action payload based on the action's input schema.
|
|
3
|
+
* Automatically handles model instances (extracts PK), files, dates, etc.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} payload - The raw payload with potentially model instances
|
|
6
|
+
* @param {Object} inputProperties - The action's input_properties schema
|
|
7
|
+
* @returns {Object} Serialized payload ready for API transmission
|
|
8
|
+
*/
|
|
9
|
+
export function serializeActionPayload(payload: Object, inputProperties: Object): Object;
|
|
1
10
|
export namespace fileFieldSerializer {
|
|
2
11
|
function toInternal(value: any, context?: {}): any;
|
|
3
12
|
function toLive(value: any, context?: {}): any;
|
|
@@ -186,6 +186,37 @@ const serializers = {
|
|
|
186
186
|
"many-to-many": m2mFieldSerializer,
|
|
187
187
|
},
|
|
188
188
|
};
|
|
189
|
+
/**
|
|
190
|
+
* Serializes an action payload based on the action's input schema.
|
|
191
|
+
* Automatically handles model instances (extracts PK), files, dates, etc.
|
|
192
|
+
*
|
|
193
|
+
* @param {Object} payload - The raw payload with potentially model instances
|
|
194
|
+
* @param {Object} inputProperties - The action's input_properties schema
|
|
195
|
+
* @returns {Object} Serialized payload ready for API transmission
|
|
196
|
+
*/
|
|
197
|
+
export function serializeActionPayload(payload, inputProperties) {
|
|
198
|
+
if (!payload || !inputProperties)
|
|
199
|
+
return payload;
|
|
200
|
+
const serializedPayload = {};
|
|
201
|
+
for (const [field, value] of Object.entries(payload)) {
|
|
202
|
+
const fieldSchema = inputProperties[field];
|
|
203
|
+
if (!fieldSchema || value === undefined) {
|
|
204
|
+
serializedPayload[field] = value;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const { type, format } = fieldSchema;
|
|
208
|
+
// Check if we have a serializer for this type/format combo
|
|
209
|
+
const typeSerializers = serializers[type];
|
|
210
|
+
const serializer = typeSerializers?.[format];
|
|
211
|
+
if (serializer) {
|
|
212
|
+
serializedPayload[field] = serializer.toInternal(value, { field });
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
serializedPayload[field] = value;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return serializedPayload;
|
|
219
|
+
}
|
|
189
220
|
export class ModelSerializer {
|
|
190
221
|
constructor(modelClass) {
|
|
191
222
|
this.modelClass = modelClass;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,4 +36,5 @@ import { cleanupEventHandler } from "./syncEngine/stores/operationEventHandlers.
|
|
|
36
36
|
import { setAdapters } from "./reactiveAdaptor.js";
|
|
37
37
|
import { wrapReactiveModel } from "./reactiveAdaptor.js";
|
|
38
38
|
import { wrapReactiveQuerySet } from "./reactiveAdaptor.js";
|
|
39
|
-
|
|
39
|
+
import { serializeActionPayload } from "./flavours/django/serializers.js";
|
|
40
|
+
export { EventType, PusherEventReceiver, setEventReceiver, getEventReceiver, setNamespaceResolver, setupStateZero, resetStateZero, FileObject, querysetStoreRegistry, modelStoreRegistry, metricRegistry, syncManager, Operation, operationRegistry, Q, StateZeroError, ValidationError, DoesNotExist, PermissionDenied, MultipleObjectsReturned, ASTValidationError, ConfigError, parseStateZeroError, QuerySet, Manager, ResultTuple, Model, setConfig, getConfig, setBackendConfig, initializeEventReceiver, configInstance, getModelClass, initEventHandler, cleanupEventHandler, setAdapters, wrapReactiveModel, wrapReactiveQuerySet, serializeActionPayload };
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ import { QuerySet } from "./flavours/django/querySet.js";
|
|
|
13
13
|
import { Manager } from "./flavours/django/manager.js";
|
|
14
14
|
import { Model } from "./flavours/django/model.js";
|
|
15
15
|
import { FileObject } from "./flavours/django/files.js";
|
|
16
|
+
import { serializeActionPayload } from "./flavours/django/serializers.js";
|
|
16
17
|
// Configuration
|
|
17
18
|
import { setConfig, getConfig, setBackendConfig, initializeEventReceiver, configInstance, getModelClass, } from "./config.js";
|
|
18
19
|
import { setAdapters, wrapReactiveModel, wrapReactiveQuerySet, } from "./reactiveAdaptor.js";
|
|
@@ -36,4 +37,6 @@ Q, StateZeroError, ValidationError, DoesNotExist, PermissionDenied, MultipleObje
|
|
|
36
37
|
// Configuration
|
|
37
38
|
setConfig, getConfig, setBackendConfig, initializeEventReceiver, configInstance, getModelClass,
|
|
38
39
|
// Reactivity framework integration
|
|
39
|
-
initEventHandler, cleanupEventHandler, setAdapters, wrapReactiveModel, wrapReactiveQuerySet,
|
|
40
|
+
initEventHandler, cleanupEventHandler, setAdapters, wrapReactiveModel, wrapReactiveQuerySet,
|
|
41
|
+
// Action utilities
|
|
42
|
+
serializeActionPayload, };
|
package/package.json
CHANGED