Skip to content

Commit

Permalink
Merge pull request #2633 from IDEMSInternational/fix/dynamic-data-app…
Browse files Browse the repository at this point in the history
…-meta

fix: dynamic data for data list including app metadata fields
  • Loading branch information
jfmcquade authored Dec 16, 2024
2 parents 38d8f0f + 9de931c commit 7530a3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/app/shared/services/dynamic-data/adapters/reactiveMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const REACTIVE_SCHEMA_BASE: RxJsonSchema<any> = {
title: "base schema for id-primary key data",
// NOTE - important to start at 0 and not timestamp (e.g. 20221220) as will check
// for migration strategies for each version which is hugely inefficient
version: 1,
version: 2,
primaryKey: "id",
type: "object",
properties: {
Expand All @@ -40,6 +40,11 @@ export const REACTIVE_SCHEMA_BASE: RxJsonSchema<any> = {
maxLength: 128, // <- the primary key must have set maxLength
},
row_index: { type: "integer", minimum: 0, maximum: 10000, multipleOf: 1, final: true },
APP_META: {
type: "object",
additionalProperties: true,
default: {},
},
},
required: ["id"],
indexes: ["row_index"],
Expand All @@ -49,6 +54,13 @@ const MIGRATIONS: MigrationStrategies = {
const newDoc = { ...oldDoc, row_index: 0 };
return newDoc;
},
2: (oldDoc) => {
const newDoc = {
...oldDoc,
APP_META: oldDoc.APP_META ?? {},
};
return newDoc;
},
};

interface IDataUpdate {
Expand Down
5 changes: 3 additions & 2 deletions src/app/shared/services/dynamic-data/dynamic-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,9 @@ export class DynamicDataService extends AsyncServiceBase {
}
const schema = REACTIVE_SCHEMA_BASE;
for (const key of Object.keys(fields)) {
if (!schema.properties[key]) {
// assign any provided metadata, with fallback 'string' type if not specified
// assign any provided metadata, with fallback 'string' type if not specified
// ignore any `_` fields as these will be merged into APP_META (do not satisfy rxdb regex)
if (!schema.properties[key] && !key.startsWith("_")) {
const type = metadata[key]?.type || "string";
schema.properties[key] = { ...metadata[key], type };
}
Expand Down

0 comments on commit 7530a3b

Please sign in to comment.