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
2 changes: 2 additions & 0 deletions src/metadata/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export * from './constants.js';
import isMetadata from './is-metadata.js';
import normaliseName from './normalise-name.js';

export {
isMetadata,
normaliseName,
};
12 changes: 12 additions & 0 deletions src/metadata/is-metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const METADATA_START = '[';

/**
* Checks whether a field path targets metadata (ie. starts with `[`).
* Attention: This does not guarantee the metadata itself exists.
*
* @param {string} path - Field path to check
* @returns {boolean} True when field path follows metadata format
*/
const isMetadata = (path) => path[0] === METADATA_START;

export default isMetadata;
57 changes: 57 additions & 0 deletions src/metadata/is-metadata.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import isMetadata from './is-metadata.js';

test.each([
// Current
'[workspace]',
'[type]',
'[id]',
'[title]',
'[state]',
'[classification]',
'[createdAt]',
'[lastModifiedAt]',

// Legacy
'[organisation]',
'[jurisdiction]',
'[case_type]',
'[reference]',
'[case_reference]',
'[security_classification]',
'[created]',
'[created_date]',
'[modified]',
'[last_modified]',
'[last_modified_date]',
])('should be recognised as metadata when name between brackets: %s', (actual) => {
expect(isMetadata(actual)).toBeTruthy();
});

test.each([
'workspace',
'type',
'id',
'title',
'state',
'classification',
'createdAt',
'lastModifiedAt',
'organisation',
'jurisdiction',
'case_type',
'reference',
'case_reference',
'security_classification',
'created',
'created_date',
'modified',
'last_modified',
'last_modified_date',
'randomField',
'randomPath.to.field',
'collection[123]',
'collection[id:item-1]',
'collection[123].value.member',
])('should not be recognised as metadata when name not between brackets: %s', (actual) => {
expect(isMetadata(actual)).toBeFalsy();
});
3 changes: 3 additions & 0 deletions src/metadata/normalise-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ const normaliseName = (metadataName) => {
case 'security_classification': // Legacy
return NAMES.CLASSIFICATION;
case 'createdat':
case 'created': // Legacy
case 'created_date': // Legacy
return NAMES.CREATED_AT;
case 'lastmodifiedat':
case 'modified': // Legacy
case 'last_modified': // Legacy
case 'last_modified_date': // Legacy
return NAMES.LAST_MODIFIED_AT;
default:
return;
Expand Down
3 changes: 3 additions & 0 deletions src/metadata/normalise-name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('createdAt', () => {
test.each([
['identity', NAMES.CREATED_AT, NAMES.CREATED_AT],
['case insensitive', '[CREATEDat]', NAMES.CREATED_AT],
['legacy', '[created]', NAMES.CREATED_AT],
['legacy', '[created_date]', NAMES.CREATED_AT],
['no brackets', 'createdAt', NAMES.CREATED_AT],
['no brackets + case insensitive', 'CREATEDat', NAMES.CREATED_AT],
Expand All @@ -100,7 +101,9 @@ describe('lastModifiedAt', () => {
test.each([
['identity', NAMES.LAST_MODIFIED_AT, NAMES.LAST_MODIFIED_AT],
['case insensitive', '[lastMODIFIEDat]', NAMES.LAST_MODIFIED_AT],
['legacy', '[modified]', NAMES.LAST_MODIFIED_AT],
['legacy', '[last_modified]', NAMES.LAST_MODIFIED_AT],
['legacy', '[last_modified_date]', NAMES.LAST_MODIFIED_AT],
['no brackets', 'lastModifiedAt', NAMES.LAST_MODIFIED_AT],
['no brackets + case insensitive', 'lastMODIFIEDat', NAMES.LAST_MODIFIED_AT],
['no brackets + legacy', 'last_modified', NAMES.LAST_MODIFIED_AT],
Expand Down
4 changes: 2 additions & 2 deletions src/record/extract-value.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {isMetadata} from '../metadata/index.js';
import * as Metadata from '../metadata/index.js';
import comboExtractor from '../path/combo-extractor.js';

const METADATA_START = '[';
const COLLECTION_ITEM_PATTERN = /^(?<name>[^[\]]+)(?:\[(?:(?<colIndex>\d+)|id:(?<colId>[^[\]]+))\])?$/;

/**
Expand All @@ -17,7 +17,7 @@ const COLLECTION_ITEM_PATTERN = /^(?<name>[^[\]]+)(?:\[(?:(?<colIndex>\d+)|id:(?
const extractValue = (record) => comboExtractor(valueExtractor(record))

const valueExtractor = (record) => (path) => {
if (path[0] === METADATA_START) {
if (isMetadata(path)) {
return metadataExtractor(record)(path);
}

Expand Down