@openhealth/oht-custom-parser-lib 0.2.50 → 0.2.52
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/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/service/transformationRules.service.d.ts +22 -0
- package/dist/service/transformationRules.service.js +172 -0
- package/dist/service/transformationRules.service.js.map +1 -0
- package/dist/types/transformationRules.types.d.ts +42 -0
- package/dist/types/transformationRules.types.js +3 -0
- package/dist/types/transformationRules.types.js.map +1 -0
- package/dist/util-ts/transformationRules.d.ts +35 -0
- package/dist/util-ts/transformationRules.js +157 -0
- package/dist/util-ts/transformationRules.js.map +1 -0
- package/package.json +34 -33
- package/readme.md +99 -99
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export { parseExternalPatientId, parseGender, isPatientAgeValid, handleRejection
|
|
|
3
3
|
export { ohtMeasurementsExtractor, checkValueForPlausibleValues, extractReferenceRanges, extractReferenceAnnotation, parseExamValue, getRangeFromPositionAndRegex, extractUnit, extractValueFromGreaterLowerThan } from './service/ohtMeasurementsExtractor.service';
|
|
4
4
|
export { getSlackFileIssueNotificationMessage, sendMessageToSlack } from './service/slackMessages.service';
|
|
5
5
|
export { aggregateMessages, aggregateBiMessages, publishToTopic, generateBIMessages } from './service/errorHandling.service';
|
|
6
|
+
export { applyRules as applyTransformationRules, validateJsonataExpression as validateTransformationRuleExpression, } from './service/transformationRules.service';
|
|
6
7
|
export { LabToOhtContract, LabToOhtMapper, UnknownMeasurementExtraction, ReferenceAsAnnotation, UnitExtraction, RangeExtraction, RangeExtractionResponse, ValueExtraction, unitSynonyms, ValueExtractionResponse, } from './types/custom-parser.types';
|
|
7
8
|
export { AcfBiomarkerRangeAnnotationCheck, AcfBiomarkerGenericDisclaimerLogic, ManualCheck, BiomarkerCompatibility, ReferenceRangeType, AcfReferenceRange, VisualRange, NameAlias, AlternativeUnit, BiomarkerAcf, Biomarker, PipelineStep, DigitizationStatus, MeasurementValueComparator, BiomarkerValueType, DataImportFileUploadStatus, Sex, Digitization, PatientInfo, UnknownMeasurement, Measurement, DataImportFileUpload, MessagePayload, SignedUpload, ReportStyleConfig, LanguageCode, BiomarkerCustomisation, PartnerCustomPanel, ReportDisplaySettings, ReportCustomisation, OHTPartner, UploadType, } from './types/oht.types';
|
|
8
9
|
export { ErrorMessage } from './types/error.types';
|
|
10
|
+
export type { TransformationRule, TransformationContext, ApplyRulesResult as TransformationApplyRulesResult, ApplyRulesOptions as TransformationApplyRulesOptions, ValidationResult as TransformationValidationResult, } from './types/transformationRules.types';
|
|
9
11
|
export { makeApiCallWithRetry, parseErrorObj } from './util-ts/apiUtils';
|
|
10
12
|
export { extractValue, isBiomarkerValueNumerical, isBiomarkerExternalNoVisualRange, processAppendedMappings } from './util-ts/dataUtils';
|
|
11
13
|
export { readFileFromBucket, uploadFileBufferToGCS } from './util-ts/googleStorageUtils';
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getMappedBiomarkers = exports.getLowerThanPatterns = exports.getGreaterThanPatterns = exports.pinoLogger = exports.uploadFileBufferToGCS = exports.readFileFromBucket = exports.processAppendedMappings = exports.isBiomarkerExternalNoVisualRange = exports.isBiomarkerValueNumerical = exports.extractValue = exports.parseErrorObj = exports.makeApiCallWithRetry = exports.UploadType = exports.Sex = exports.DataImportFileUploadStatus = exports.BiomarkerValueType = exports.MeasurementValueComparator = exports.DigitizationStatus = exports.PipelineStep = exports.ReferenceRangeType = exports.BiomarkerCompatibility = exports.ManualCheck = exports.AcfBiomarkerGenericDisclaimerLogic = exports.AcfBiomarkerRangeAnnotationCheck = exports.unitSynonyms = exports.generateBIMessages = exports.publishToTopic = exports.aggregateBiMessages = exports.aggregateMessages = exports.sendMessageToSlack = exports.getSlackFileIssueNotificationMessage = exports.extractValueFromGreaterLowerThan = exports.extractUnit = exports.getRangeFromPositionAndRegex = exports.parseExamValue = exports.extractReferenceAnnotation = exports.extractReferenceRanges = exports.checkValueForPlausibleValues = exports.ohtMeasurementsExtractor = exports.postFileUploadSetStatus = exports.queryFileUploadsWithFilters = exports.handleRejection = exports.isPatientAgeValid = exports.parseGender = exports.parseExternalPatientId = exports.postDataImportFileUploadToCore = void 0;
|
|
6
|
+
exports.getMappedBiomarkers = exports.getLowerThanPatterns = exports.getGreaterThanPatterns = exports.pinoLogger = exports.uploadFileBufferToGCS = exports.readFileFromBucket = exports.processAppendedMappings = exports.isBiomarkerExternalNoVisualRange = exports.isBiomarkerValueNumerical = exports.extractValue = exports.parseErrorObj = exports.makeApiCallWithRetry = exports.UploadType = exports.Sex = exports.DataImportFileUploadStatus = exports.BiomarkerValueType = exports.MeasurementValueComparator = exports.DigitizationStatus = exports.PipelineStep = exports.ReferenceRangeType = exports.BiomarkerCompatibility = exports.ManualCheck = exports.AcfBiomarkerGenericDisclaimerLogic = exports.AcfBiomarkerRangeAnnotationCheck = exports.unitSynonyms = exports.validateTransformationRuleExpression = exports.applyTransformationRules = exports.generateBIMessages = exports.publishToTopic = exports.aggregateBiMessages = exports.aggregateMessages = exports.sendMessageToSlack = exports.getSlackFileIssueNotificationMessage = exports.extractValueFromGreaterLowerThan = exports.extractUnit = exports.getRangeFromPositionAndRegex = exports.parseExamValue = exports.extractReferenceAnnotation = exports.extractReferenceRanges = exports.checkValueForPlausibleValues = exports.ohtMeasurementsExtractor = exports.postFileUploadSetStatus = exports.queryFileUploadsWithFilters = exports.handleRejection = exports.isPatientAgeValid = exports.parseGender = exports.parseExternalPatientId = exports.postDataImportFileUploadToCore = void 0;
|
|
7
7
|
// ### SERVICES ###
|
|
8
8
|
var reportCreator_service_1 = require("./service/reportCreator.service");
|
|
9
9
|
Object.defineProperty(exports, "postDataImportFileUploadToCore", { enumerable: true, get: function () { return reportCreator_service_1.postDataImportFileUploadToCore; } });
|
|
@@ -31,6 +31,9 @@ Object.defineProperty(exports, "aggregateMessages", { enumerable: true, get: fun
|
|
|
31
31
|
Object.defineProperty(exports, "aggregateBiMessages", { enumerable: true, get: function () { return errorHandling_service_1.aggregateBiMessages; } });
|
|
32
32
|
Object.defineProperty(exports, "publishToTopic", { enumerable: true, get: function () { return errorHandling_service_1.publishToTopic; } });
|
|
33
33
|
Object.defineProperty(exports, "generateBIMessages", { enumerable: true, get: function () { return errorHandling_service_1.generateBIMessages; } });
|
|
34
|
+
var transformationRules_service_1 = require("./service/transformationRules.service");
|
|
35
|
+
Object.defineProperty(exports, "applyTransformationRules", { enumerable: true, get: function () { return transformationRules_service_1.applyRules; } });
|
|
36
|
+
Object.defineProperty(exports, "validateTransformationRuleExpression", { enumerable: true, get: function () { return transformationRules_service_1.validateJsonataExpression; } });
|
|
34
37
|
// ### TYPES ###
|
|
35
38
|
var custom_parser_types_1 = require("./types/custom-parser.types");
|
|
36
39
|
Object.defineProperty(exports, "unitSynonyms", { enumerable: true, get: function () { return custom_parser_types_1.unitSynonyms; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;AAAA,mBAAmB;AACnB,yEAEyC;AADvC,uIAAA,8BAA8B,OAAA;AAEhC,mFAO8C;AAN5C,oIAAA,sBAAsB,OAAA;AACtB,yHAAA,WAAW,OAAA;AACX,+HAAA,iBAAiB,OAAA;AACjB,6HAAA,eAAe,OAAA;AACf,yIAAA,2BAA2B,OAAA;AAC3B,qIAAA,uBAAuB,OAAA;AAEzB,+FASoD;AARlD,4IAAA,wBAAwB,OAAA;AACxB,gJAAA,4BAA4B,OAAA;AAC5B,0IAAA,sBAAsB,OAAA;AACtB,8IAAA,0BAA0B,OAAA;AAC1B,kIAAA,cAAc,OAAA;AACd,gJAAA,4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sBAAsB,OAAA;AACtB,+GAAA,kBAAkB,OAAA;AAOlB,yGAAA,YAAY,OAAA;AACZ,+GAAA,kBAAkB,OAAA;AAClB,uHAAA,0BAA0B,OAAA;AAC1B,+GAAA,kBAAkB,OAAA;AAClB,uHAAA,0BAA0B,OAAA;AAC1B,gGAAA,GAAG,OAAA;AAeH,uGAAA,UAAU,OAAA;AAWZ,kBAAkB;AAClB,+CAAuE;AAA/D,gHAAA,oBAAoB,OAAA;AAAE,yGAAA,aAAa,OAAA;AAC3C,iDAAuI;AAA/H,yGAAA,YAAY,OAAA;AAAE,sHAAA,yBAAyB,OAAA;AAAE,6HAAA,gCAAgC,OAAA;AAAE,oHAAA,uBAAuB,OAAA;AAC1G,mEAAuF;AAA/E,wHAAA,kBAAkB,OAAA;AAAE,2HAAA,qBAAqB,OAAA;AACjD,mDAA2D;AAAnD,yHAAA,OAAO,OAAc;AAC7B,mDAAkF;AAA1E,oHAAA,sBAAsB,OAAA;AAAE,kHAAA,oBAAoB,OAAA;AACpD,iDAA0D;AAAlD,gHAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TransformationRule, ApplyRulesResult, ApplyRulesOptions, ValidationResult } from '../types/transformationRules.types';
|
|
2
|
+
/**
|
|
3
|
+
* Apply multiple transformation rules to data
|
|
4
|
+
*
|
|
5
|
+
* Rules are applied sequentially in the order provided.
|
|
6
|
+
* Each rule is evaluated against the current state of the data after previous rules.
|
|
7
|
+
*
|
|
8
|
+
* @param rules - Array of transformation rules to apply
|
|
9
|
+
* @param inputData - OHT Exam data object (available as $exam in expressions)
|
|
10
|
+
* @param options - Optional configuration for rule application
|
|
11
|
+
* @param options.ohtReportJson - OHT Report/full document JSON (available as $report in expressions)
|
|
12
|
+
* @param options.contextJson - Context JSON like patient info (available as $context in expressions)
|
|
13
|
+
* @returns Promise<ApplyRulesResult> - Result containing transformed data, applied rule IDs, and any errors
|
|
14
|
+
*/
|
|
15
|
+
export declare const applyRules: (rules: TransformationRule[], inputData: Record<string, unknown>, options?: ApplyRulesOptions) => Promise<ApplyRulesResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Validate a JSONata expression
|
|
18
|
+
*
|
|
19
|
+
* @param expression - JSONata expression string to validate
|
|
20
|
+
* @returns ValidationResult - Object with valid flag and optional error message
|
|
21
|
+
*/
|
|
22
|
+
export declare const validateJsonataExpression: (expression: string) => ValidationResult;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateJsonataExpression = exports.applyRules = void 0;
|
|
7
|
+
const jsonata_1 = __importDefault(require("jsonata"));
|
|
8
|
+
const transformationRules_1 = require("../util-ts/transformationRules");
|
|
9
|
+
/**
|
|
10
|
+
* JSON Transformation Rules Engine
|
|
11
|
+
*
|
|
12
|
+
* This is a standalone, reusable library for applying transformation rules to JSON data.
|
|
13
|
+
* It uses JSONata expressions for powerful, declarative transformations.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
const createExpression = (expressionText, context) => {
|
|
18
|
+
const expression = (0, jsonata_1.default)(expressionText);
|
|
19
|
+
expression.assign('report', context.ohtReport);
|
|
20
|
+
expression.assign('exam', context.ohtExam);
|
|
21
|
+
expression.assign('context', context.context);
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Evaluate a JSONata condition with the given context
|
|
26
|
+
*
|
|
27
|
+
* @param condition - JSONata expression that returns a boolean
|
|
28
|
+
* @param context - Context object with root, item, and optional global data
|
|
29
|
+
* @returns Promise<boolean> - True if condition is met, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
const evaluateCondition = async (condition, context) => {
|
|
32
|
+
try {
|
|
33
|
+
if (!condition || condition.trim() === '') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
const expression = createExpression(condition, context);
|
|
37
|
+
const result = await expression.evaluate(context.ohtExam);
|
|
38
|
+
return Boolean(result);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error('Error evaluating condition:', error);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Evaluate a JSONata value expression
|
|
47
|
+
*
|
|
48
|
+
* @param valueExpression - JSONata expression to evaluate
|
|
49
|
+
* @param context - Context object with root, item, and optional global data
|
|
50
|
+
* @returns Promise<unknown> - Result of the expression evaluation
|
|
51
|
+
* @throws Error if expression evaluation fails
|
|
52
|
+
*/
|
|
53
|
+
const evaluateValueExpression = async (valueExpression, context) => {
|
|
54
|
+
try {
|
|
55
|
+
const expression = createExpression(valueExpression, context);
|
|
56
|
+
const result = await expression.evaluate(context.ohtExam);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('Error evaluating value expression:', error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Apply a single transformation rule to data
|
|
66
|
+
*
|
|
67
|
+
* @param rule - Transformation rule to apply
|
|
68
|
+
* @param data - Input data object
|
|
69
|
+
* @param options - Optional configuration (ohtReport and contextJson)
|
|
70
|
+
* @returns Promise<Record<string, unknown>> - Transformed data object
|
|
71
|
+
*/
|
|
72
|
+
const applyRule = async (rule, data, options = {}) => {
|
|
73
|
+
const context = {
|
|
74
|
+
ohtReport: options.ohtReportJson ?? {},
|
|
75
|
+
ohtExam: data,
|
|
76
|
+
context: options.contextJson ?? {},
|
|
77
|
+
};
|
|
78
|
+
const shouldApply = await evaluateCondition(rule.conditionExpression, context);
|
|
79
|
+
if (!shouldApply) {
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
const newValue = await evaluateValueExpression(rule.valueExpression, context);
|
|
83
|
+
const transformedData = { ...data };
|
|
84
|
+
if (rule.targetExpression.startsWith('$.')) {
|
|
85
|
+
const pathSegments = (0, transformationRules_1.parsePath)(rule.targetExpression);
|
|
86
|
+
(0, transformationRules_1.setValueByPath)(transformedData, pathSegments, newValue);
|
|
87
|
+
}
|
|
88
|
+
return transformedData;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Apply multiple transformation rules to data
|
|
92
|
+
*
|
|
93
|
+
* Rules are applied sequentially in the order provided.
|
|
94
|
+
* Each rule is evaluated against the current state of the data after previous rules.
|
|
95
|
+
*
|
|
96
|
+
* @param rules - Array of transformation rules to apply
|
|
97
|
+
* @param inputData - OHT Exam data object (available as $exam in expressions)
|
|
98
|
+
* @param options - Optional configuration for rule application
|
|
99
|
+
* @param options.ohtReportJson - OHT Report/full document JSON (available as $report in expressions)
|
|
100
|
+
* @param options.contextJson - Context JSON like patient info (available as $context in expressions)
|
|
101
|
+
* @returns Promise<ApplyRulesResult> - Result containing transformed data, applied rule IDs, and any errors
|
|
102
|
+
*/
|
|
103
|
+
const applyRules = async (rules, inputData, options = {}) => {
|
|
104
|
+
const result = await rules.reduce(async (accPromise, rule) => {
|
|
105
|
+
const acc = await accPromise;
|
|
106
|
+
try {
|
|
107
|
+
const context = {
|
|
108
|
+
ohtReport: options.ohtReportJson ?? {},
|
|
109
|
+
ohtExam: acc.data,
|
|
110
|
+
context: options.contextJson ?? {},
|
|
111
|
+
};
|
|
112
|
+
const shouldApply = await evaluateCondition(rule.conditionExpression, context);
|
|
113
|
+
if (shouldApply) {
|
|
114
|
+
const transformedData = await applyRule(rule, acc.data, options);
|
|
115
|
+
return {
|
|
116
|
+
data: transformedData,
|
|
117
|
+
appliedRules: [...acc.appliedRules, rule.id],
|
|
118
|
+
errors: acc.errors,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
data: acc.data,
|
|
126
|
+
appliedRules: acc.appliedRules,
|
|
127
|
+
errors: [
|
|
128
|
+
...acc.errors,
|
|
129
|
+
{
|
|
130
|
+
ruleId: rule.id,
|
|
131
|
+
ruleName: rule.name,
|
|
132
|
+
error: (0, transformationRules_1.getErrorMessage)(error),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}, Promise.resolve({
|
|
138
|
+
data: { ...inputData },
|
|
139
|
+
appliedRules: [],
|
|
140
|
+
errors: [],
|
|
141
|
+
}));
|
|
142
|
+
return {
|
|
143
|
+
success: result.errors.length === 0,
|
|
144
|
+
data: result.data,
|
|
145
|
+
appliedRules: result.appliedRules,
|
|
146
|
+
errors: result.errors,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
exports.applyRules = applyRules;
|
|
150
|
+
/**
|
|
151
|
+
* Validate a JSONata expression
|
|
152
|
+
*
|
|
153
|
+
* @param expression - JSONata expression string to validate
|
|
154
|
+
* @returns ValidationResult - Object with valid flag and optional error message
|
|
155
|
+
*/
|
|
156
|
+
const validateJsonataExpression = (expression) => {
|
|
157
|
+
try {
|
|
158
|
+
if (!expression || expression.trim() === '') {
|
|
159
|
+
return { valid: true };
|
|
160
|
+
}
|
|
161
|
+
(0, jsonata_1.default)(expression);
|
|
162
|
+
return { valid: true };
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
return {
|
|
166
|
+
valid: false,
|
|
167
|
+
error: (0, transformationRules_1.getErrorMessage)(error),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
exports.validateJsonataExpression = validateJsonataExpression;
|
|
172
|
+
//# sourceMappingURL=transformationRules.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformationRules.service.js","sourceRoot":"","sources":["../../service/transformationRules.service.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AA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,MAAM,KAAK,CAAC;QACnC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC,CAAC;AAxDW,QAAA,UAAU,cAwDrB;AAEF;;;;;GAKG;AACI,MAAM,yBAAyB,GAAG,CAAC,UAAkB,EAAoB,EAAE;IAChF,IAAI,CAAC;QACH,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzB,CAAC;QAED,IAAA,iBAAO,EAAC,UAAU,CAAC,CAAC;QACpB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,IAAA,qCAAe,EAAC,KAAK,CAAC;SAC9B,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAdW,QAAA,yBAAyB,6BAcpC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface TransformationRule {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
conditionExpression: string;
|
|
6
|
+
targetExpression: string;
|
|
7
|
+
valueExpression: string;
|
|
8
|
+
tags: string[];
|
|
9
|
+
createdAt: Date;
|
|
10
|
+
updatedAt: Date;
|
|
11
|
+
sampleOhtExam?: string;
|
|
12
|
+
sampleOhtReport?: string;
|
|
13
|
+
sampleContextJson?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TransformationContext {
|
|
16
|
+
ohtReport: Record<string, unknown>;
|
|
17
|
+
ohtExam: Record<string, unknown>;
|
|
18
|
+
context: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface ApplyRulesResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
data: Record<string, unknown>;
|
|
23
|
+
appliedRules: string[];
|
|
24
|
+
errors: Array<{
|
|
25
|
+
ruleId: string;
|
|
26
|
+
error: string;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface ApplyRulesOptions {
|
|
30
|
+
/**
|
|
31
|
+
* The full/global document (OHT Report) accessible inside JSONata expressions via $report
|
|
32
|
+
*/
|
|
33
|
+
ohtReportJson?: Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Additional context (e.g., patient info) accessible inside JSONata expressions via $context
|
|
36
|
+
*/
|
|
37
|
+
contextJson?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
export interface ValidationResult {
|
|
40
|
+
valid: boolean;
|
|
41
|
+
error?: string;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformationRules.types.js","sourceRoot":"","sources":["../../types/transformationRules.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an unknown error to a string message
|
|
3
|
+
* Handles Error objects, objects with message property, and other types
|
|
4
|
+
*
|
|
5
|
+
* @param error - The error to convert
|
|
6
|
+
* @returns String representation of the error
|
|
7
|
+
*/
|
|
8
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* Lightweight deep equality check for JSON-serializable objects.
|
|
11
|
+
* Only handles primitives, arrays, and plain objects (no functions, symbols, etc.)
|
|
12
|
+
* which is sufficient for transformation rule data.
|
|
13
|
+
*
|
|
14
|
+
* @param obj1 - First object to compare
|
|
15
|
+
* @param obj2 - Second object to compare
|
|
16
|
+
* @returns True if objects are deeply equal, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export declare function isDeepEqual(obj1: unknown, obj2: unknown): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a JSONPath-like target path into segments
|
|
21
|
+
* Supports dot notation, bracket notation, and array indices
|
|
22
|
+
*
|
|
23
|
+
* @param path - Path string (e.g., "$.user.name", "$.items[0]", "$.data['key']")
|
|
24
|
+
* @returns Array of path segments
|
|
25
|
+
*/
|
|
26
|
+
export declare function parsePath(path: string): Array<string | number>;
|
|
27
|
+
/**
|
|
28
|
+
* Set a value in an object using a parsed path
|
|
29
|
+
* Creates intermediate objects/arrays as needed
|
|
30
|
+
*
|
|
31
|
+
* @param obj - Target object to modify
|
|
32
|
+
* @param segments - Path segments from parsePath()
|
|
33
|
+
* @param value - Value to set
|
|
34
|
+
*/
|
|
35
|
+
export declare function setValueByPath(obj: Record<string, unknown>, segments: Array<string | number>, value: unknown): void;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getErrorMessage = getErrorMessage;
|
|
4
|
+
exports.isDeepEqual = isDeepEqual;
|
|
5
|
+
exports.parsePath = parsePath;
|
|
6
|
+
exports.setValueByPath = setValueByPath;
|
|
7
|
+
/**
|
|
8
|
+
* Converts an unknown error to a string message
|
|
9
|
+
* Handles Error objects, objects with message property, and other types
|
|
10
|
+
*
|
|
11
|
+
* @param error - The error to convert
|
|
12
|
+
* @returns String representation of the error
|
|
13
|
+
*/
|
|
14
|
+
function getErrorMessage(error) {
|
|
15
|
+
if (error instanceof Error) {
|
|
16
|
+
return error.message;
|
|
17
|
+
}
|
|
18
|
+
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
19
|
+
const maybeMessage = error.message;
|
|
20
|
+
return typeof maybeMessage === 'string' ? maybeMessage : String(maybeMessage);
|
|
21
|
+
}
|
|
22
|
+
return String(error);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Lightweight deep equality check for JSON-serializable objects.
|
|
26
|
+
* Only handles primitives, arrays, and plain objects (no functions, symbols, etc.)
|
|
27
|
+
* which is sufficient for transformation rule data.
|
|
28
|
+
*
|
|
29
|
+
* @param obj1 - First object to compare
|
|
30
|
+
* @param obj2 - Second object to compare
|
|
31
|
+
* @returns True if objects are deeply equal, false otherwise
|
|
32
|
+
*/
|
|
33
|
+
function isDeepEqual(obj1, obj2) {
|
|
34
|
+
// Same reference or both null/undefined
|
|
35
|
+
if (obj1 === obj2)
|
|
36
|
+
return true;
|
|
37
|
+
// Different types or one is null
|
|
38
|
+
if (typeof obj1 !== typeof obj2 || obj1 === null || obj2 === null || typeof obj1 !== 'object') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Handle arrays
|
|
42
|
+
if (Array.isArray(obj1) && Array.isArray(obj2)) {
|
|
43
|
+
if (obj1.length !== obj2.length)
|
|
44
|
+
return false;
|
|
45
|
+
return obj1.every((item, index) => isDeepEqual(item, obj2[index]));
|
|
46
|
+
}
|
|
47
|
+
// One is array, other is not
|
|
48
|
+
if (Array.isArray(obj1) !== Array.isArray(obj2)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// Handle plain objects
|
|
52
|
+
const keys1 = Object.keys(obj1);
|
|
53
|
+
const keys2 = Object.keys(obj2);
|
|
54
|
+
if (keys1.length !== keys2.length)
|
|
55
|
+
return false;
|
|
56
|
+
return keys1.every((key) => isDeepEqual(obj1[key], obj2[key]));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parse a JSONPath-like target path into segments
|
|
60
|
+
* Supports dot notation, bracket notation, and array indices
|
|
61
|
+
*
|
|
62
|
+
* @param path - Path string (e.g., "$.user.name", "$.items[0]", "$.data['key']")
|
|
63
|
+
* @returns Array of path segments
|
|
64
|
+
*/
|
|
65
|
+
function parsePath(path) {
|
|
66
|
+
// Remove leading $. if present
|
|
67
|
+
const cleanPath = path.startsWith('$.') ? path.substring(2) : path;
|
|
68
|
+
if (!cleanPath) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
const segments = [];
|
|
72
|
+
let currentSegment = '';
|
|
73
|
+
let i = 0;
|
|
74
|
+
while (i < cleanPath.length) {
|
|
75
|
+
const char = cleanPath[i];
|
|
76
|
+
// Handle bracket notation for arrays [0] or objects ['key']
|
|
77
|
+
if (char === '[') {
|
|
78
|
+
// Save any accumulated segment
|
|
79
|
+
if (currentSegment) {
|
|
80
|
+
segments.push(currentSegment);
|
|
81
|
+
currentSegment = '';
|
|
82
|
+
}
|
|
83
|
+
i += 1; // Move past [
|
|
84
|
+
let bracketContent = '';
|
|
85
|
+
// Extract content between brackets
|
|
86
|
+
while (i < cleanPath.length && cleanPath[i] !== ']') {
|
|
87
|
+
bracketContent += cleanPath[i];
|
|
88
|
+
i += 1;
|
|
89
|
+
}
|
|
90
|
+
// Parse bracket content
|
|
91
|
+
if (bracketContent) {
|
|
92
|
+
// Remove quotes if present (for string keys like ['key'])
|
|
93
|
+
if ((bracketContent.startsWith("'") && bracketContent.endsWith("'"))
|
|
94
|
+
|| (bracketContent.startsWith('"') && bracketContent.endsWith('"'))) {
|
|
95
|
+
segments.push(bracketContent.slice(1, -1));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Try to parse as number (for array indices)
|
|
99
|
+
const numValue = Number(bracketContent);
|
|
100
|
+
if (!Number.isNaN(numValue) && Number.isInteger(numValue)) {
|
|
101
|
+
segments.push(numValue);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
segments.push(bracketContent);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
i += 1; // Move past ]
|
|
109
|
+
}
|
|
110
|
+
else if (char === '.') {
|
|
111
|
+
// Dot separator - save current segment
|
|
112
|
+
if (currentSegment) {
|
|
113
|
+
segments.push(currentSegment);
|
|
114
|
+
currentSegment = '';
|
|
115
|
+
}
|
|
116
|
+
i += 1;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// Regular character - accumulate
|
|
120
|
+
currentSegment += char;
|
|
121
|
+
i += 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Add final segment if any
|
|
125
|
+
if (currentSegment) {
|
|
126
|
+
segments.push(currentSegment);
|
|
127
|
+
}
|
|
128
|
+
return segments;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Set a value in an object using a parsed path
|
|
132
|
+
* Creates intermediate objects/arrays as needed
|
|
133
|
+
*
|
|
134
|
+
* @param obj - Target object to modify
|
|
135
|
+
* @param segments - Path segments from parsePath()
|
|
136
|
+
* @param value - Value to set
|
|
137
|
+
*/
|
|
138
|
+
function setValueByPath(obj, segments, value) {
|
|
139
|
+
if (segments.length === 0) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
let current = obj;
|
|
143
|
+
// Navigate to parent, creating intermediate structures as needed
|
|
144
|
+
for (let i = 0; i < segments.length - 1; i += 1) {
|
|
145
|
+
const segment = segments[i];
|
|
146
|
+
const nextSegment = segments[i + 1];
|
|
147
|
+
if (!(segment in current)) {
|
|
148
|
+
// Create array if next segment is a number, otherwise create object
|
|
149
|
+
current[segment] = typeof nextSegment === 'number' ? [] : {};
|
|
150
|
+
}
|
|
151
|
+
current = current[segment];
|
|
152
|
+
}
|
|
153
|
+
// Set the final value
|
|
154
|
+
const lastSegment = segments[segments.length - 1];
|
|
155
|
+
current[lastSegment] = value;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=transformationRules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformationRules.js","sourceRoot":"","sources":["../../util-ts/transformationRules.ts"],"names":[],"mappings":";;AAOA,0CAWC;AAWD,kCA2BC;AASD,8BAwEC;AAUD,wCAuBC;AA1KD;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACtE,MAAM,YAAY,GAAI,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B,cAAc,CAAC,GAA4B,EAAE,QAAgC,EAAE,KAAc;IAC3G,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO;IACT,CAAC;IAED,IAAI,OAAO,GAAQ,GAAG,CAAC;IAEvB,iEAAiE;IACjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAEpC,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;YAC1B,oEAAoE;YACpE,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,sBAAsB;IACtB,MAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@openhealth/oht-custom-parser-lib",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Shared nodejs lib with with reusable functions",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"/dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "jest"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [],
|
|
14
|
-
"author": "",
|
|
15
|
-
"license": "ISC",
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"@google-cloud/pubsub": "^4.10.0",
|
|
18
|
-
"@google-cloud/storage": "^7.7.0",
|
|
19
|
-
"axios": "^1.6.7",
|
|
20
|
-
"bottleneck": "^2.19.5",
|
|
21
|
-
"dayjs": "^1.11.13",
|
|
22
|
-
"dotenv": "^16.4.5",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@openhealth/oht-custom-parser-lib",
|
|
3
|
+
"version": "0.2.52",
|
|
4
|
+
"description": "Shared nodejs lib with with reusable functions",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@google-cloud/pubsub": "^4.10.0",
|
|
18
|
+
"@google-cloud/storage": "^7.7.0",
|
|
19
|
+
"axios": "^1.6.7",
|
|
20
|
+
"bottleneck": "^2.19.5",
|
|
21
|
+
"dayjs": "^1.11.13",
|
|
22
|
+
"dotenv": "^16.4.5",
|
|
23
|
+
"jsonata": "^2.1.0",
|
|
24
|
+
"moment": "^2.30.1",
|
|
25
|
+
"mongodb": "^6.3.0",
|
|
26
|
+
"pino": "^8.19.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.14",
|
|
30
|
+
"axios-mock-adapter": "^2.1.0",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"ts-jest": "^29.2.5"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
# oht-custom-parser-lib
|
|
2
|
-
|
|
3
|
-
`oht-custom-parser-lib` is a shared library designed for use across multiple Node.js cloud functions. It contains common MongoDB connectors and data utilities that can be reused to avoid code duplication and ensure consistency.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Installation](#installation)
|
|
8
|
-
- [Usage](#usage)
|
|
9
|
-
- [Development](#development)
|
|
10
|
-
- [Patch Versions](#patch-versions)
|
|
11
|
-
- [Publish to npm Registry](#publish-to-npm-registry)
|
|
12
|
-
- [Using the Library in Cloud Functions](#using-the-library-in-cloud-functions)
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
To install `oht-custom-parser-lib`, you can add it as a dependency in your project using npm:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install oht-custom-parser-lib
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Or, if you want to install a specific version:
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install oht-custom-parser-lib@<version>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
After installing, you can import and use the library in your cloud functions:
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
const { connectToMongoDB } = require('oht-custom-parser-lib');
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Development
|
|
37
|
-
|
|
38
|
-
### Patch Versions
|
|
39
|
-
|
|
40
|
-
When making changes to the `oht-custom-parser-lib`, you need to update the version number before publishing. Follow these steps:
|
|
41
|
-
|
|
42
|
-
1. **Update the version number**: Use npm's version command to bump the version:
|
|
43
|
-
- **Patch** for bug fixes:
|
|
44
|
-
```bash
|
|
45
|
-
npm version patch
|
|
46
|
-
```
|
|
47
|
-
- **Minor** for new features:
|
|
48
|
-
```bash
|
|
49
|
-
npm version minor
|
|
50
|
-
```
|
|
51
|
-
- **Major** for breaking changes:
|
|
52
|
-
```bash
|
|
53
|
-
npm version major
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
This command will automatically update the version in the `package.json` and create a git tag.
|
|
57
|
-
|
|
58
|
-
2. **Commit Changes**: Ensure your changes and the version bump are committed to the repository.
|
|
59
|
-
|
|
60
|
-
### Publish to npm Registry
|
|
61
|
-
|
|
62
|
-
After updating the version, you can publish the library to the npm registry:
|
|
63
|
-
|
|
64
|
-
1. **Login to npm** (if you haven't already):
|
|
65
|
-
```bash
|
|
66
|
-
npm login
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
2. **Publish the package**:
|
|
70
|
-
```bash
|
|
71
|
-
npm publish
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
If this is a private package, use:
|
|
75
|
-
```bash
|
|
76
|
-
npm publish --access restricted
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
3. **Verify the publish**: You can check the package on [npmjs.com](https://www.npmjs.com/) to verify that the new version is available.
|
|
80
|
-
|
|
81
|
-
## Using the Library in Cloud Functions
|
|
82
|
-
|
|
83
|
-
To use `oht-custom-parser-lib` in your cloud functions:
|
|
84
|
-
|
|
85
|
-
1. **Install the Library**: Add `oht-custom-parser-lib` as a dependency in the cloud function's `package.json`:
|
|
86
|
-
|
|
87
|
-
```json
|
|
88
|
-
{
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"oht-custom-parser-lib": "^1.0.0"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
Replace `^1.0.0` with the appropriate version as needed.
|
|
96
|
-
|
|
97
|
-
2. **Install Dependencies**: Run `npm install` to install the library along with other dependencies.
|
|
98
|
-
|
|
99
|
-
3. **Deploy Your Function**: Deploy your cloud function as usual, ensuring that the updated dependencies are included.
|
|
1
|
+
# oht-custom-parser-lib
|
|
2
|
+
|
|
3
|
+
`oht-custom-parser-lib` is a shared library designed for use across multiple Node.js cloud functions. It contains common MongoDB connectors and data utilities that can be reused to avoid code duplication and ensure consistency.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Development](#development)
|
|
10
|
+
- [Patch Versions](#patch-versions)
|
|
11
|
+
- [Publish to npm Registry](#publish-to-npm-registry)
|
|
12
|
+
- [Using the Library in Cloud Functions](#using-the-library-in-cloud-functions)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
To install `oht-custom-parser-lib`, you can add it as a dependency in your project using npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install oht-custom-parser-lib
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or, if you want to install a specific version:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install oht-custom-parser-lib@<version>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
After installing, you can import and use the library in your cloud functions:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const { connectToMongoDB } = require('oht-custom-parser-lib');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Development
|
|
37
|
+
|
|
38
|
+
### Patch Versions
|
|
39
|
+
|
|
40
|
+
When making changes to the `oht-custom-parser-lib`, you need to update the version number before publishing. Follow these steps:
|
|
41
|
+
|
|
42
|
+
1. **Update the version number**: Use npm's version command to bump the version:
|
|
43
|
+
- **Patch** for bug fixes:
|
|
44
|
+
```bash
|
|
45
|
+
npm version patch
|
|
46
|
+
```
|
|
47
|
+
- **Minor** for new features:
|
|
48
|
+
```bash
|
|
49
|
+
npm version minor
|
|
50
|
+
```
|
|
51
|
+
- **Major** for breaking changes:
|
|
52
|
+
```bash
|
|
53
|
+
npm version major
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This command will automatically update the version in the `package.json` and create a git tag.
|
|
57
|
+
|
|
58
|
+
2. **Commit Changes**: Ensure your changes and the version bump are committed to the repository.
|
|
59
|
+
|
|
60
|
+
### Publish to npm Registry
|
|
61
|
+
|
|
62
|
+
After updating the version, you can publish the library to the npm registry:
|
|
63
|
+
|
|
64
|
+
1. **Login to npm** (if you haven't already):
|
|
65
|
+
```bash
|
|
66
|
+
npm login
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. **Publish the package**:
|
|
70
|
+
```bash
|
|
71
|
+
npm publish
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
If this is a private package, use:
|
|
75
|
+
```bash
|
|
76
|
+
npm publish --access restricted
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
3. **Verify the publish**: You can check the package on [npmjs.com](https://www.npmjs.com/) to verify that the new version is available.
|
|
80
|
+
|
|
81
|
+
## Using the Library in Cloud Functions
|
|
82
|
+
|
|
83
|
+
To use `oht-custom-parser-lib` in your cloud functions:
|
|
84
|
+
|
|
85
|
+
1. **Install the Library**: Add `oht-custom-parser-lib` as a dependency in the cloud function's `package.json`:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"oht-custom-parser-lib": "^1.0.0"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Replace `^1.0.0` with the appropriate version as needed.
|
|
96
|
+
|
|
97
|
+
2. **Install Dependencies**: Run `npm install` to install the library along with other dependencies.
|
|
98
|
+
|
|
99
|
+
3. **Deploy Your Function**: Deploy your cloud function as usual, ensuring that the updated dependencies are included.
|