Skip to content
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/datasync-content-store-filesystem",
"version": "2.0.5",
"version": "2.1.0",
"description": "Datasync content store library - saves data in filesystem",
"main": "./dist",
"types": "./typings",
Expand Down
38 changes: 38 additions & 0 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (
export class FilesystemStore {
private readonly assetStore: any
private readonly config: any
private readonly _config: any;
private readonly pattern: {
contentTypeKeys: string[],
entryKeys: string[],
Expand All @@ -40,6 +41,7 @@ export class FilesystemStore {

constructor(assetStore, config) {
this.assetStore = assetStore
this._config = config;
this.config = config.contentStore
const baseDirKeys = this.config.baseDir.split(sep)
this.pattern = ({} as any)
Expand Down Expand Up @@ -454,6 +456,14 @@ export class FilesystemStore {
private publishEntry(data) {
return new Promise(async (resolve, reject) => {
try {
if (this._config?.enableContentReferences) {
// Check if reference exists and update the field
this._updateReferenceFields(data, data._content_type?.schema, 'reference');
}
if (this._config?.enableAssetReferences) {
// Check if reference exists and update the field
this._updateAssetFields(data, data._content_type?.schema, 'file');
}
let entry = cloneDeep(data)
entry = filter(entry) // to remove _content_type and checkpoint from entry data

Expand Down Expand Up @@ -651,4 +661,32 @@ export class FilesystemStore {
}
}
// tslint:disable-next-line: max-file-line-count

private _updateReferenceFields(data, ctSchema, fieldType) {
for (const field of ctSchema) {
if (field.data_type === fieldType) {
data[field.uid] = {
reference_to: field.reference_to?.[0],
value: data[field.uid]?.[0]?.uid,
};
}
if (field.schema) {
this._updateReferenceFields(data[field.uid], field.schema, fieldType);
}
}
}

private _updateAssetFields(data, ctSchema, fieldType) {
for (const field of ctSchema) {
if (field.data_type === fieldType) {
data[field.uid] = {
reference_to: "_assets",
value: data[field.uid],
};
}
if (field.schema) {
this._updateAssetFields(data[field.uid], field.schema, fieldType);
}
}
}
}
3 changes: 3 additions & 0 deletions typings/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
export declare class FilesystemStore {
private readonly assetStore;
private readonly config;
private readonly _config;
private readonly pattern;
private readonly unwanted;
private readonly localePath;
Expand All @@ -28,4 +29,6 @@ export declare class FilesystemStore {
private _getAssetFieldsHelper;
private _updateEntryAssetReference;
private _nullifyDeletedAssetField;
private _updateReferenceFields;
private _updateAssetFields;
}
Loading