Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .adiorc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";
import get from "lodash/get.js";
import getWorkspaces from "get-yarn-workspaces";

export default {
Expand All @@ -10,10 +9,10 @@ export default {
const { node } = path;
if (node.type === "CallExpression") {
if (
get(node, "callee.property.name") === "resolve" &&
get(node, "callee.object.name") === "require"
node?.callee?.property?.name === "resolve" &&
node?.callee?.object?.name === "require"
) {
const possiblePackage = get(node, "arguments.0.value");
const possiblePackage = node?.arguments?.[0]?.value;
if (typeof possiblePackage === "string") {
return push(possiblePackage);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/api-aco/src/utils/ListCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cloneDeep from "lodash/cloneDeep.js";

export type Constructor<T> = new (...args: any[]) => T;

export interface IListCachePredicate<T> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export class ListCache<T> implements IListCache<T> {
}

getItems(): T[] {
return cloneDeep(this.state);
return structuredClone(this.state);
}

addItems(items: T[]): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import cloneDeep from "lodash/cloneDeep.js";

export type Constructor<T> = new (...args: any[]) => T;

export interface IListCachePredicate<T> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export class ListCache<T> implements IListCache<T> {
}

getItems(): T[] {
return cloneDeep(this.state);
return structuredClone(this.state);
}

addItems(items: T[]): void {
Expand Down
4 changes: 1 addition & 3 deletions packages/api-headless-cms-ddb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
"@webiny/handler-db": "0.0.0",
"@webiny/utils": "0.0.0",
"dataloader": "^2.2.3",
"dot-object": "^2.1.5",
"dot-prop": "^10.1.0",
"flattie": "^1.1.1",
"lodash": "^4.18.1"
},
"devDependencies": {
"@types/dot-object": "^2.1.6",
"@types/jsonpack": "^1.1.6",
"@webiny/build-tools": "0.0.0",
"@webiny/di": "^0.2.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dot from "dot-object";
import { flattie } from "flattie";
import type { CmsEntryFieldFilterPluginCreateResponse } from "~/plugins/CmsEntryFieldFilterPlugin.js";
import { CmsEntryFieldFilterPlugin } from "~/plugins/CmsEntryFieldFilterPlugin.js";
import { extractWhereParams } from "~/operations/entry/filtering/where.js";
Expand All @@ -11,7 +11,7 @@ export const searchableJsonFilterCreate = () => {

const filters = [];

const accessPatterns = dot.dot(objectValue);
const accessPatterns = flattie(objectValue, ".", true);

for (const key in accessPatterns) {
const value = accessPatterns[key];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CmsEntry, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
import WebinyError from "@webiny/error";
import * as dotProp from "dot-prop";
import { immutableGet } from "@webiny/utils/dotProp/index.js";
import lodashSortBy from "lodash/sortBy.js";
import { extractSort } from "./extractSort.js";
import type { Field } from "./types.js";
Expand Down Expand Up @@ -53,7 +53,7 @@ export const sort = <T extends CmsEntryValues = CmsEntryValues>(
const itemsToSort = items.map(item => {
return {
id: item.id,
value: field.transform(dotProp.getProperty(item, valuePath))
value: field.transform(immutableGet(item, valuePath))
};
});
const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, "value");
Expand Down
1 change: 0 additions & 1 deletion packages/api-headless-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@webiny/project": "0.0.0",
"@webiny/utils": "0.0.0",
"@webiny/validation": "0.0.0",
"dot-prop-immutable": "^2.1.1",
"graphql": "^16.13.2",
"graphql-tag": "^2.12.6",
"lodash": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dotPropImmutable from "dot-prop-immutable";
import { immutableGet, immutableSet } from "@webiny/utils/dotProp/index.js";
import { parseIdentifier } from "@webiny/utils";
import type { CmsContext, CmsEntryValues, CmsModel } from "~/types/index.js";
import { buildReferenceFieldPaths } from "./references/buildPaths.js";
Expand Down Expand Up @@ -54,7 +54,7 @@ export const referenceFieldsMapping = async <TValues extends CmsEntryValues = Cm
*/
for (const path of referenceFieldPaths) {
// It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.
const refValue = dotPropImmutable.get(values, path) as CmsRefEntry | undefined;
const refValue = immutableGet<CmsRefEntry | undefined>(values, path);
if (!refValue) {
continue;
}
Expand All @@ -71,7 +71,7 @@ export const referenceFieldsMapping = async <TValues extends CmsEntryValues = Cm
id: entryId
});

output = dotPropImmutable.set(output, path, {
output = immutableSet(output, path, {
id,
entryId,
modelId: refValue.modelId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CmsDynamicZoneTemplate, CmsEntryValues, CmsModelField } from "~/types/index.js";
import dotPropImmutable from "dot-prop-immutable";
import { immutableGet } from "@webiny/utils/dotProp/index.js";
import { getBaseFieldType } from "~/utils/getBaseFieldType.js";

type INarrowedCmsModelField = Pick<CmsModelField, "fieldId" | "list" | "type" | "settings">;
Expand All @@ -18,7 +18,7 @@ const resolveBaseRef = <TValues extends CmsEntryValues = CmsEntryValues>(
const { field, parentPaths, input, collection, isMultipleValues } = params;
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
if (field.list) {
const inputValue = dotPropImmutable.get(input, `${field.fieldId}`, []);
const inputValue = immutableGet(input, `${field.fieldId}`, []);
if (!Array.isArray(inputValue)) {
return collection;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
const templates: CmsDynamicZoneTemplate[] = field.settings?.templates || [];

if (field.list) {
const values = dotPropImmutable.get(input, field.fieldId, []);
const values = immutableGet(input, field.fieldId, []);
if (!Array.isArray(values)) {
return collection;
}
Expand All @@ -102,12 +102,22 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
return collection;
}

const value = dotPropImmutable.get(input, field.fieldId, {});
const value = immutableGet(input, field.fieldId, {});
if (!value) {
return collection;
}
/**
* We know what the value possibly has _templateId field, but TS doesn't. We need to ignore it here.
*/
// @ts-expect-error
const templateId = value["_templateId"] as string | undefined;
if (!templateId) {
return collection;
}

const template = templates.find(tpl => tpl.id === value["_templateId"]);
const template = templates.find(tpl => {
return tpl.id === templateId;
});

if (!template) {
return collection;
Expand Down Expand Up @@ -139,7 +149,7 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
}

const objFieldPath = `${field.fieldId}`;
const objFieldInputValue = dotPropImmutable.get(input, objFieldPath, []);
const objFieldInputValue = immutableGet(input, objFieldPath, []);

/**
* If field is multiple values one, we need to go through the input and use the existing keys.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CmsContext } from "~/types/index.js";
import dotPropImmutable from "dot-prop-immutable";
import { immutableGet } from "@webiny/utils/dotProp/index.js";
import { WebinyError } from "@webiny/error";

interface ReferenceObject {
Expand Down Expand Up @@ -33,7 +33,7 @@ export const validateReferencedEntries = async ({
* Group references by modelId.
*/
for (const path of referenceFieldPaths) {
const ref = dotPropImmutable.get(output, path) as ReferenceObject | any;
const ref = immutableGet<ReferenceObject | any>(output, path);

const result = getReferenceFieldValue(ref);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from "lodash/set.js";
import { mutableSet } from "@webiny/utils/dotProp/index.js";
import type { Resolvers } from "@webiny/handler-graphql/types.js";
import WebinyError from "@webiny/error";
import type { ApiEndpoint, CmsContext, CmsModel, CmsModelField } from "~/types/index.js";
Expand Down Expand Up @@ -117,7 +117,7 @@ export const createFieldResolversFactory = (factoryParams: CreateFieldResolversF
value
});

set(
mutableSet(
valueIsRoot && parent.values ? parent.values : parent,
fieldId,
transformedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from "lodash/set.js";
import { mutableSet } from "@webiny/utils/dotProp/index.js";
import type { GenericRecord } from "@webiny/api/types.js";
import type { CmsEntryResolverFactory, CmsModel } from "~/types/index.js";
import type { IContentEntryTraverser } from "~/features/contentEntry/ContentEntryTraverser/ContentEntryTraverser.js";
Expand Down Expand Up @@ -57,7 +57,7 @@ class GraphQlInputNormalizer {
input: value
});

set(values, path, normalizedValue);
mutableSet(values, path, normalizedValue);
}
});

Expand Down
1 change: 0 additions & 1 deletion packages/app-aco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@webiny/shared-aco": "0.0.0",
"@webiny/utils": "0.0.0",
"@webiny/validation": "0.0.0",
"dot-prop-immutable": "^2.1.1",
"graphql": "^16.13.2",
"graphql-tag": "^2.12.6",
"lodash": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from "lodash/get.js";
import { immutableGet } from "@webiny/utils/dotProp/index.js";
import type { FilterDTO } from "~/components/AdvancedSearch/domain/index.js";

interface NestedObject {
Expand Down Expand Up @@ -27,7 +27,7 @@ export class GraphQLInputMapper {
const values = JSON.parse(value);
return this.createNestedObject(
this.createKeys(field, condition),
this.convertToBooleanOrString(get(values, keys))
this.convertToBooleanOrString(immutableGet(values, keys.join(".")))
);
} catch {
return this.createNestedObject(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import cloneDeep from "lodash/cloneDeep.js";
import { makeAutoObservable, runInAction } from "mobx";
import { makeAutoObservable, observable, runInAction, toJS } from "mobx";
import { mdbid } from "@webiny/utils";

import type { FilterDTO } from "../domain/index.js";
import { FilterMapper, Loading, Sorter } from "../domain/index.js";
import type { FiltersGatewayInterface } from "../gateways/index.js";
Expand All @@ -10,19 +8,20 @@ export class FilterRepository {
private gateway: FiltersGatewayInterface;
private sorter: Sorter<FilterDTO>;
private loading: Loading;
private filters: FilterDTO[] = [];
private filters;
public readonly namespace: string;

constructor(gateway: FiltersGatewayInterface, namespace: string) {
this.gateway = gateway;
this.loading = new Loading();
this.namespace = namespace;
this.filters = observable.array<FilterDTO>([]);
this.sorter = new Sorter(["createdOn_DESC"]);
makeAutoObservable(this);
}

getFilters() {
return cloneDeep(this.filters);
return structuredClone(toJS(this.filters));
}

getLoading() {
Expand Down Expand Up @@ -58,15 +57,23 @@ export class FilterRepository {
}

runInAction(() => {
this.filters = this.sorter.sort(response.map(filter => FilterMapper.toDTO(filter)));
this.filters.replace(
this.sorter.sort(
response.map(filter => {
return FilterMapper.toDTO(filter);
})
)
);
});
}

async getFilterById(id: string) {
const filterInCache = this.filters.find(filter => filter.id === id);
const filterInCache = this.filters.find(filter => {
return filter.id === id;
});

if (filterInCache) {
return cloneDeep(filterInCache);
return structuredClone(toJS(filterInCache));
}

const response = await this.runWithLoading<FilterDTO>(this.gateway.get(id));
Expand All @@ -77,10 +84,10 @@ export class FilterRepository {

const filterDTO = FilterMapper.toDTO(response);
runInAction(() => {
this.filters = this.sorter.sort([filterDTO, ...this.filters]);
this.filters.replace(this.sorter.sort([filterDTO, ...toJS(this.filters)]));
});

return cloneDeep(filterDTO);
return structuredClone(toJS(filterDTO));
}

async createFilter(filter: FilterDTO) {
Expand All @@ -99,10 +106,10 @@ export class FilterRepository {

const filterDTO = FilterMapper.toDTO(response);
runInAction(() => {
this.filters = this.sorter.sort([filterDTO, ...this.filters]);
this.filters.replace(this.sorter.sort([filterDTO, ...toJS(this.filters)]));
});

return cloneDeep(filterDTO);
return structuredClone(toJS(filterDTO));
}

async updateFilter(filter: FilterDTO) {
Expand All @@ -122,14 +129,17 @@ export class FilterRepository {
const filterDTO = FilterMapper.toDTO(response);

runInAction(() => {
this.filters = this.sorter.sort([
...this.filters.slice(0, filterIndex),
{
...this.filters[filterIndex],
...filterDTO
},
...this.filters.slice(filterIndex + 1)
]);
const filters = toJS(this.filters);
this.filters.replace(
this.sorter.sort([
...filters.slice(0, filterIndex),
{
...filters[filterIndex],
...filterDTO
},
...filters.slice(filterIndex + 1)
])
);
});
}
}
Expand All @@ -149,7 +159,9 @@ export class FilterRepository {

if (response) {
runInAction(() => {
this.filters = this.sorter.sort(this.filters.filter(filter => filter.id !== id));
this.filters.replace(
this.sorter.sort(toJS(this.filters.filter(filter => filter.id !== id)))
);
});
}
}
Expand Down
Loading
Loading