@paralect/hive 0.1.39 → 0.1.40
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/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import db from "db";
|
|
|
3
3
|
import ifUpdated from "helpers/db/ifUpdated";
|
|
4
4
|
import schemaMappings from "./schemaMappings";
|
|
5
5
|
import getDependentFields from './getDependentFields';
|
|
6
|
-
import
|
|
6
|
+
import isZodArray from "helpers/isZodArray";
|
|
7
7
|
|
|
8
8
|
const updatedSchemaMappings = (() => {
|
|
9
9
|
const result = {};
|
|
@@ -103,7 +103,7 @@ const addOnDependentEntitiesUpdatedHandlers = ({ schemaName }) => {
|
|
|
103
103
|
"updated",
|
|
104
104
|
ifUpdated(dependentFields, async ({ doc }) => {
|
|
105
105
|
const toUpdate = _.pick(doc, ["_id", ...dependentFields]);
|
|
106
|
-
if (schema.shape[dependentFieldName]
|
|
106
|
+
if (isZodArray(schema.shape[dependentFieldName])) {
|
|
107
107
|
db.services[schemaName].atomic.update(
|
|
108
108
|
{ [`${dependentFieldName}._id`]: doc._id },
|
|
109
109
|
{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import isZodArray from "helpers/isZodArray";
|
|
3
4
|
|
|
4
5
|
const getZodKeys = schema => {
|
|
5
6
|
// make sure schema is not null or undefined
|
|
@@ -7,7 +8,7 @@ const getZodKeys = schema => {
|
|
|
7
8
|
// check if schema is nullable or optional
|
|
8
9
|
if (schema instanceof z.ZodNullable || schema instanceof z.ZodOptional) return getZodKeys(schema.unwrap());
|
|
9
10
|
// check if schema is an array
|
|
10
|
-
if (schema
|
|
11
|
+
if (isZodArray(schema)) return getZodKeys(schema.element);
|
|
11
12
|
// check if schema is an object
|
|
12
13
|
if (schema instanceof z.ZodObject) {
|
|
13
14
|
// get key/value pairs from schema
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import db from "db";
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { z, ZodArray } from 'zod';
|
|
5
3
|
|
|
6
4
|
import schemaMappings from "./schemaMappings";
|
|
7
5
|
import getDependentFields from './getDependentFields';
|
|
6
|
+
import isZodArray from "helpers/isZodArray";
|
|
8
7
|
|
|
9
8
|
const schemaMappingService = db.services.schemaMappings;
|
|
10
9
|
|
|
@@ -27,15 +26,6 @@ const zodSchemaToSchemaMappings = () => {
|
|
|
27
26
|
return newSchemaMappings;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
const isZodArray = (schema) => {
|
|
31
|
-
if (schema instanceof ZodArray) return true;
|
|
32
|
-
|
|
33
|
-
if (schema._def?.innerType) {
|
|
34
|
-
return isZodArray(schema._def.innerType);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return false;
|
|
38
|
-
};
|
|
39
29
|
|
|
40
30
|
export default async () => {
|
|
41
31
|
const prevSchema = await schemaMappingService.findOne({});
|