@zwave-js/config 15.15.2 → 15.16.0
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/build/cjs/Logic.d.ts +1 -1
- package/build/cjs/Logic.js +6 -7
- package/build/cjs/Logic.js.map +2 -2
- package/build/cjs/LogicParser.d.ts +66 -84
- package/build/cjs/LogicParser.js +410 -1337
- package/build/cjs/LogicParser.js.map +3 -3
- package/build/cjs/_version.d.ts +1 -1
- package/build/cjs/_version.js +1 -1
- package/build/cjs/_version.js.map +1 -1
- package/build/cjs/devices/DeviceConfig.d.ts +3 -3
- package/build/cjs/devices/DeviceConfig.js.map +2 -2
- package/build/cjs/devices/ParamInformation.d.ts +2 -0
- package/build/cjs/devices/ParamInformation.js +15 -1
- package/build/cjs/devices/ParamInformation.js.map +2 -2
- package/build/esm/Logic.d.ts +1 -1
- package/build/esm/Logic.d.ts.map +1 -1
- package/build/esm/Logic.js +6 -8
- package/build/esm/Logic.js.map +1 -1
- package/build/esm/LogicParser.d.ts +66 -84
- package/build/esm/LogicParser.d.ts.map +1 -1
- package/build/esm/LogicParser.js +432 -2335
- package/build/esm/LogicParser.js.map +1 -1
- package/build/esm/_version.d.ts +1 -1
- package/build/esm/_version.js +1 -1
- package/build/esm/devices/DeviceConfig.d.ts +3 -3
- package/build/esm/devices/DeviceConfig.d.ts.map +1 -1
- package/build/esm/devices/DeviceConfig.js.map +1 -1
- package/build/esm/devices/ParamInformation.d.ts +2 -0
- package/build/esm/devices/ParamInformation.d.ts.map +1 -1
- package/build/esm/devices/ParamInformation.js +16 -0
- package/build/esm/devices/ParamInformation.js.map +1 -1
- package/config/devices/0x003b/be468zp.json +1 -1
- package/config/devices/0x003b/be469.json +2 -3
- package/config/devices/0x003b/be469zp.json +2 -3
- package/config/devices/0x0063/55258_zw4002.json +34 -1
- package/config/devices/0x0090/918.json +97 -0
- package/config/devices/0x0090/hc620.json +4 -0
- package/config/devices/0x027a/zse11.json +134 -0
- package/config/devices/templates/master_template.json +1 -1
- package/config/eslint.config.mjs +24 -19
- package/package.json +8 -10
|
@@ -93,11 +93,21 @@ Parameter #${parameterNumber} is missing defaultValue, which is required unless
|
|
|
93
93
|
Parameter #${parameterNumber} has a non-numeric property defaultValue`);
|
|
94
94
|
}
|
|
95
95
|
this.defaultValue = definition.defaultValue;
|
|
96
|
+
if (definition.recommendedValue != void 0 && typeof definition.recommendedValue !== "number") {
|
|
97
|
+
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
98
|
+
Parameter #${parameterNumber} has a non-numeric property recommendedValue`);
|
|
99
|
+
}
|
|
100
|
+
this.recommendedValue = definition.recommendedValue;
|
|
96
101
|
if (definition.allowManualEntry != void 0 && definition.allowManualEntry !== false) {
|
|
97
102
|
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
98
103
|
Parameter #${parameterNumber}: allowManualEntry must be false or omitted!`);
|
|
99
104
|
}
|
|
100
105
|
this.allowManualEntry = definition.allowManualEntry ?? (this.readOnly ? false : true);
|
|
106
|
+
if (definition.destructive != void 0 && typeof definition.destructive !== "boolean") {
|
|
107
|
+
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
108
|
+
Parameter #${parameterNumber} has a non-boolean property destructive`);
|
|
109
|
+
}
|
|
110
|
+
this.destructive = definition.destructive;
|
|
101
111
|
if ((0, import_typeguards.isArray)(definition.options) && !definition.options.every((opt) => (0, import_typeguards.isObject)(opt) && typeof opt.label === "string" && typeof opt.value === "number")) {
|
|
102
112
|
(0, import_utils_safe.throwInvalidConfig)("devices", `packages/config/config/devices/${parent.filename}:
|
|
103
113
|
Parameter #${parameterNumber}: options is malformed!`);
|
|
@@ -114,10 +124,12 @@ Parameter #${parameterNumber}: options is malformed!`);
|
|
|
114
124
|
maxValue;
|
|
115
125
|
unsigned;
|
|
116
126
|
defaultValue;
|
|
127
|
+
recommendedValue;
|
|
117
128
|
unit;
|
|
118
129
|
readOnly;
|
|
119
130
|
writeOnly;
|
|
120
131
|
allowManualEntry;
|
|
132
|
+
destructive;
|
|
121
133
|
options;
|
|
122
134
|
condition;
|
|
123
135
|
evaluateCondition(deviceId) {
|
|
@@ -134,10 +146,12 @@ Parameter #${parameterNumber}: options is malformed!`);
|
|
|
134
146
|
"maxValue",
|
|
135
147
|
"unsigned",
|
|
136
148
|
"defaultValue",
|
|
149
|
+
"recommendedValue",
|
|
137
150
|
"unit",
|
|
138
151
|
"readOnly",
|
|
139
152
|
"writeOnly",
|
|
140
|
-
"allowManualEntry"
|
|
153
|
+
"allowManualEntry",
|
|
154
|
+
"destructive"
|
|
141
155
|
]),
|
|
142
156
|
options: (0, import_ConditionalItem.evaluateDeep)(this.options, deviceId, true)
|
|
143
157
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/devices/ParamInformation.ts"],
|
|
4
|
-
"sourcesContent": ["import { tryParseParamNumber } from \"@zwave-js/core\";\nimport {\n\ttype JSONObject,\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tpick,\n} from \"@zwave-js/shared\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport { throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype ConditionalItem,\n\tconditionApplies,\n\tevaluateDeep,\n\tvalidateCondition,\n} from \"./ConditionalItem.js\";\nimport type { ConditionalDeviceConfig } from \"./DeviceConfig.js\";\nimport type { DeviceID } from \"./shared.js\";\n\nexport class ConditionalParamInformation\n\timplements ConditionalItem<ParamInformation>\n{\n\tpublic constructor(\n\t\tparent: ConditionalDeviceConfig,\n\t\tparameterNumber: number,\n\t\tvalueBitMask: number | undefined,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.parent = parent;\n\t\tthis.parameterNumber = parameterNumber;\n\t\tthis.valueBitMask = valueBitMask;\n\t\t// No need to validate here, this should be done one level higher\n\t\tthis.condition = definition.$if;\n\n\t\tif (typeof definition.label !== \"string\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string label`,\n\t\t\t);\n\t\t}\n\t\tthis.label = definition.label;\n\n\t\tif (\n\t\t\tdefinition.description != undefined\n\t\t\t&& typeof definition.description !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string description`,\n\t\t\t);\n\t\t}\n\t\tthis.description = definition.description;\n\n\t\tif (\n\t\t\ttypeof definition.valueSize !== \"number\"\n\t\t\t|| definition.valueSize <= 0\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has an invalid value size`,\n\t\t\t);\n\t\t}\n\t\tthis.valueSize = definition.valueSize;\n\n\t\tif (\n\t\t\tdefinition.minValue != undefined\n\t\t\t&& typeof definition.minValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property minValue`,\n\t\t\t);\n\t\t}\n\t\tthis.minValue = definition.minValue;\n\n\t\tif (\n\t\t\tdefinition.maxValue != undefined\n\t\t\t&& typeof definition.maxValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property maxValue`,\n\t\t\t);\n\t\t}\n\t\tthis.maxValue = definition.maxValue;\n\n\t\tif (\n\t\t\tdefinition.unsigned != undefined\n\t\t\t&& typeof definition.unsigned !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property unsigned`,\n\t\t\t);\n\t\t}\n\t\tthis.unsigned = definition.unsigned === true;\n\n\t\tif (\n\t\t\tdefinition.unit != undefined\n\t\t\t&& typeof definition.unit !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string unit`,\n\t\t\t);\n\t\t}\n\t\tthis.unit = definition.unit;\n\n\t\tif (definition.readOnly != undefined && definition.readOnly !== true) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: readOnly must true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.readOnly = definition.readOnly;\n\n\t\tif (\n\t\t\tdefinition.writeOnly != undefined\n\t\t\t&& definition.writeOnly !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: writeOnly must be true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.writeOnly = definition.writeOnly;\n\n\t\tif (definition.defaultValue == undefined) {\n\t\t\tif (!this.readOnly) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} is missing defaultValue, which is required unless the parameter is readOnly`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (typeof definition.defaultValue !== \"number\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property defaultValue`,\n\t\t\t);\n\t\t}\n\t\tthis.defaultValue = definition.defaultValue;\n\n\t\tif (\n\t\t\tdefinition.allowManualEntry != undefined\n\t\t\t&& definition.allowManualEntry !== false\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: allowManualEntry must be false or omitted!`,\n\t\t\t);\n\t\t}\n\t\t// Default to allowing manual entry, except if the param is readonly\n\t\tthis.allowManualEntry = definition.allowManualEntry\n\t\t\t?? (this.readOnly ? false : true);\n\n\t\tif (\n\t\t\tisArray(definition.options)\n\t\t\t&& !definition.options.every(\n\t\t\t\t(opt: unknown) =>\n\t\t\t\t\tisObject(opt)\n\t\t\t\t\t&& typeof opt.label === \"string\"\n\t\t\t\t\t&& typeof opt.value === \"number\",\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: options is malformed!`,\n\t\t\t);\n\t\t}\n\n\t\tthis.options = definition.options?.map(\n\t\t\t(opt: any) =>\n\t\t\t\tnew ConditionalConfigOption(opt.value, opt.label, opt.$if),\n\t\t) ?? [];\n\t}\n\n\tprivate parent: ConditionalDeviceConfig;\n\tpublic readonly parameterNumber: number;\n\tpublic readonly valueBitMask?: number;\n\tpublic readonly label: string;\n\tpublic readonly description?: string;\n\tpublic readonly valueSize: number;\n\tpublic readonly minValue?: number;\n\tpublic readonly maxValue?: number;\n\tpublic readonly unsigned?: boolean;\n\tpublic readonly defaultValue: number;\n\tpublic readonly unit?: string;\n\tpublic readonly readOnly?: true;\n\tpublic readonly writeOnly?: true;\n\tpublic readonly allowManualEntry: boolean;\n\tpublic readonly options: readonly ConditionalConfigOption[];\n\n\tpublic readonly condition?: string;\n\n\tpublic evaluateCondition(\n\t\tdeviceId?: DeviceID,\n\t): ParamInformation | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\tconst ret = {\n\t\t\t...pick(this, [\n\t\t\t\t\"parameterNumber\",\n\t\t\t\t\"valueBitMask\",\n\t\t\t\t\"label\",\n\t\t\t\t\"description\",\n\t\t\t\t\"valueSize\",\n\t\t\t\t\"minValue\",\n\t\t\t\t\"maxValue\",\n\t\t\t\t\"unsigned\",\n\t\t\t\t\"defaultValue\",\n\t\t\t\t\"unit\",\n\t\t\t\t\"readOnly\",\n\t\t\t\t\"writeOnly\",\n\t\t\t\t\"allowManualEntry\",\n\t\t\t]),\n\t\t\toptions: evaluateDeep(this.options, deviceId, true),\n\t\t};\n\t\t// Infer minValue from options if possible\n\t\tif (ret.minValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.minValue = Math.min(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"minValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (ret.maxValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.maxValue = Math.max(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"maxValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error TS doesn't seem to understand that we do set min/maxValue\n\t\treturn ret;\n\t}\n}\n\nexport type ParamInformation =\n\t& Omit<\n\t\tConditionalParamInformation,\n\t\t\"condition\" | \"evaluateCondition\" | \"options\" | \"minValue\" | \"maxValue\"\n\t>\n\t& {\n\t\toptions: readonly ConfigOption[];\n\t\tminValue: NonNullable<ConditionalParamInformation[\"minValue\"]>;\n\t\tmaxValue: NonNullable<ConditionalParamInformation[\"maxValue\"]>;\n\t};\n\nexport class ConditionalConfigOption implements ConditionalItem<ConfigOption> {\n\tpublic constructor(\n\t\tpublic readonly value: number,\n\t\tpublic readonly label: string,\n\t\tpublic readonly condition?: string,\n\t) {}\n\n\tpublic evaluateCondition(deviceId?: DeviceID): ConfigOption | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\treturn pick(this, [\"value\", \"label\"]);\n\t}\n}\n\nexport interface ConfigOption {\n\tvalue: number;\n\tlabel: string;\n}\n\nexport type ConditionalParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tConditionalParamInformation[]\n>;\n\nexport type ParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tParamInformation\n>;\n\nexport function parseConditionalParamInformationMap(\n\tdefinition: JSONObject,\n\tparent: ConditionalDeviceConfig,\n\terrorPrefix: string = \"\",\n): ConditionalParamInfoMap {\n\tconst paramInformation = new ObjectKeyMap<\n\t\t{ parameter: number; valueBitMask?: number },\n\t\tConditionalParamInformation[]\n\t>();\n\n\tconst filename = parent.filename;\n\n\tif (isArray(definition.paramInformation)) {\n\t\t// Check that every param has a param number\n\t\tif (!definition.paramInformation.every((entry: any) => \"#\" in entry)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}required property \"#\" missing in at least one entry of paramInformation`,\n\t\t\t);\n\t\t}\n\n\t\t// And a valid $if condition\n\t\tfor (const entry of definition.paramInformation) {\n\t\t\tvalidateCondition(\n\t\t\t\tfilename,\n\t\t\t\tentry,\n\t\t\t\t`${errorPrefix}At least one entry of paramInformation contains an`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const paramDefinition of definition.paramInformation) {\n\t\t\tconst { [\"#\"]: paramNo, ...defn } = paramDefinition;\n\t\t\tconst key = tryParseParamNumber(paramNo);\n\t\t\tif (!key) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}found invalid param number \"${paramNo}\" in paramInformation`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!paramInformation.has(key)) paramInformation.set(key, []);\n\t\t\tparamInformation\n\t\t\t\t.get(key)!\n\t\t\t\t.push(\n\t\t\t\t\tnew ConditionalParamInformation(\n\t\t\t\t\t\tparent,\n\t\t\t\t\t\tkey.parameter,\n\t\t\t\t\t\tkey.valueBitMask,\n\t\t\t\t\t\tdefn,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t}\n\t} else if (isObject(definition.paramInformation)) {\n\t\t// Silently ignore this old format\n\t} else {\n\t\tthrowInvalidConfig(\n\t\t\t`device`,\n\t\t\t`packages/config/config/devices/${filename}:\n${errorPrefix}paramInformation must be an array!`,\n\t\t);\n\t}\n\n\treturn paramInformation;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAAA,kBAAoC;AACpC,oBAKO;AACP,wBAAkC;AAClC,wBAAmC;AACnC,6BAKO;AAID,MAAO,4BAA2B;EAlBxC,OAkBwC;;;EAGvC,YACC,QACA,iBACA,cACA,YAAsB;AAEtB,SAAK,SAAS;AACd,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAEpB,SAAK,YAAY,WAAW;AAE5B,QAAI,OAAO,WAAW,UAAU,UAAU;AACzC,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,yBAAyB;IAEnD;AACA,SAAK,QAAQ,WAAW;AAExB,QACC,WAAW,eAAe,UACvB,OAAO,WAAW,gBAAgB,UACpC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,+BAA+B;IAEzD;AACA,SAAK,cAAc,WAAW;AAE9B,QACC,OAAO,WAAW,cAAc,YAC7B,WAAW,aAAa,GAC1B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,4BAA4B;IAEtD;AACA,SAAK,YAAY,WAAW;AAE5B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,g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ParseParamNumber } from \"@zwave-js/core\";\nimport {\n\ttype JSONObject,\n\tObjectKeyMap,\n\ttype ReadonlyObjectKeyMap,\n\tpick,\n} from \"@zwave-js/shared\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport { throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype ConditionalItem,\n\tconditionApplies,\n\tevaluateDeep,\n\tvalidateCondition,\n} from \"./ConditionalItem.js\";\nimport type { ConditionalDeviceConfig } from \"./DeviceConfig.js\";\nimport type { DeviceID } from \"./shared.js\";\n\nexport class ConditionalParamInformation\n\timplements ConditionalItem<ParamInformation>\n{\n\tpublic constructor(\n\t\tparent: ConditionalDeviceConfig,\n\t\tparameterNumber: number,\n\t\tvalueBitMask: number | undefined,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.parent = parent;\n\t\tthis.parameterNumber = parameterNumber;\n\t\tthis.valueBitMask = valueBitMask;\n\t\t// No need to validate here, this should be done one level higher\n\t\tthis.condition = definition.$if;\n\n\t\tif (typeof definition.label !== \"string\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string label`,\n\t\t\t);\n\t\t}\n\t\tthis.label = definition.label;\n\n\t\tif (\n\t\t\tdefinition.description != undefined\n\t\t\t&& typeof definition.description !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string description`,\n\t\t\t);\n\t\t}\n\t\tthis.description = definition.description;\n\n\t\tif (\n\t\t\ttypeof definition.valueSize !== \"number\"\n\t\t\t|| definition.valueSize <= 0\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has an invalid value size`,\n\t\t\t);\n\t\t}\n\t\tthis.valueSize = definition.valueSize;\n\n\t\tif (\n\t\t\tdefinition.minValue != undefined\n\t\t\t&& typeof definition.minValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property minValue`,\n\t\t\t);\n\t\t}\n\t\tthis.minValue = definition.minValue;\n\n\t\tif (\n\t\t\tdefinition.maxValue != undefined\n\t\t\t&& typeof definition.maxValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property maxValue`,\n\t\t\t);\n\t\t}\n\t\tthis.maxValue = definition.maxValue;\n\n\t\tif (\n\t\t\tdefinition.unsigned != undefined\n\t\t\t&& typeof definition.unsigned !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property unsigned`,\n\t\t\t);\n\t\t}\n\t\tthis.unsigned = definition.unsigned === true;\n\n\t\tif (\n\t\t\tdefinition.unit != undefined\n\t\t\t&& typeof definition.unit !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-string unit`,\n\t\t\t);\n\t\t}\n\t\tthis.unit = definition.unit;\n\n\t\tif (definition.readOnly != undefined && definition.readOnly !== true) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: readOnly must true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.readOnly = definition.readOnly;\n\n\t\tif (\n\t\t\tdefinition.writeOnly != undefined\n\t\t\t&& definition.writeOnly !== true\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\n\t\tParameter #${parameterNumber}: writeOnly must be true or omitted!`,\n\t\t\t);\n\t\t}\n\t\tthis.writeOnly = definition.writeOnly;\n\n\t\tif (definition.defaultValue == undefined) {\n\t\t\tif (!this.readOnly) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} is missing defaultValue, which is required unless the parameter is readOnly`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (typeof definition.defaultValue !== \"number\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property defaultValue`,\n\t\t\t);\n\t\t}\n\t\tthis.defaultValue = definition.defaultValue;\n\n\t\tif (\n\t\t\tdefinition.recommendedValue != undefined\n\t\t\t&& typeof definition.recommendedValue !== \"number\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-numeric property recommendedValue`,\n\t\t\t);\n\t\t}\n\t\tthis.recommendedValue = definition.recommendedValue;\n\n\t\tif (\n\t\t\tdefinition.allowManualEntry != undefined\n\t\t\t&& definition.allowManualEntry !== false\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: allowManualEntry must be false or omitted!`,\n\t\t\t);\n\t\t}\n\t\t// Default to allowing manual entry, except if the param is readonly\n\t\tthis.allowManualEntry = definition.allowManualEntry\n\t\t\t?? (this.readOnly ? false : true);\n\n\t\tif (\n\t\t\tdefinition.destructive != undefined\n\t\t\t&& typeof definition.destructive !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber} has a non-boolean property destructive`,\n\t\t\t);\n\t\t}\n\t\tthis.destructive = definition.destructive;\n\n\t\tif (\n\t\t\tisArray(definition.options)\n\t\t\t&& !definition.options.every(\n\t\t\t\t(opt: unknown) =>\n\t\t\t\t\tisObject(opt)\n\t\t\t\t\t&& typeof opt.label === \"string\"\n\t\t\t\t\t&& typeof opt.value === \"number\",\n\t\t\t)\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${parent.filename}:\nParameter #${parameterNumber}: options is malformed!`,\n\t\t\t);\n\t\t}\n\n\t\tthis.options = definition.options?.map(\n\t\t\t(opt: any) =>\n\t\t\t\tnew ConditionalConfigOption(opt.value, opt.label, opt.$if),\n\t\t) ?? [];\n\t}\n\n\tprivate parent: ConditionalDeviceConfig;\n\tpublic readonly parameterNumber: number;\n\tpublic readonly valueBitMask?: number;\n\tpublic readonly label: string;\n\tpublic readonly description?: string;\n\tpublic readonly valueSize: number;\n\tpublic readonly minValue?: number;\n\tpublic readonly maxValue?: number;\n\tpublic readonly unsigned?: boolean;\n\tpublic readonly defaultValue: number;\n\tpublic readonly recommendedValue?: number;\n\tpublic readonly unit?: string;\n\tpublic readonly readOnly?: true;\n\tpublic readonly writeOnly?: true;\n\tpublic readonly allowManualEntry: boolean;\n\tpublic readonly destructive?: boolean;\n\tpublic readonly options: readonly ConditionalConfigOption[];\n\n\tpublic readonly condition?: string;\n\n\tpublic evaluateCondition(\n\t\tdeviceId?: DeviceID,\n\t): ParamInformation | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\tconst ret = {\n\t\t\t...pick(this, [\n\t\t\t\t\"parameterNumber\",\n\t\t\t\t\"valueBitMask\",\n\t\t\t\t\"label\",\n\t\t\t\t\"description\",\n\t\t\t\t\"valueSize\",\n\t\t\t\t\"minValue\",\n\t\t\t\t\"maxValue\",\n\t\t\t\t\"unsigned\",\n\t\t\t\t\"defaultValue\",\n\t\t\t\t\"recommendedValue\",\n\t\t\t\t\"unit\",\n\t\t\t\t\"readOnly\",\n\t\t\t\t\"writeOnly\",\n\t\t\t\t\"allowManualEntry\",\n\t\t\t\t\"destructive\",\n\t\t\t]),\n\t\t\toptions: evaluateDeep(this.options, deviceId, true),\n\t\t};\n\t\t// Infer minValue from options if possible\n\t\tif (ret.minValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.minValue = Math.min(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"minValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (ret.maxValue == undefined) {\n\t\t\tif (ret.allowManualEntry === false && ret.options.length > 0) {\n\t\t\t\tret.maxValue = Math.max(...ret.options.map((o) => o.value));\n\t\t\t} else {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"devices\",\n\t\t\t\t\t`packages/config/config/devices/${this.parent.filename}:\nParameter #${this.parameterNumber} is missing required property \"maxValue\"!`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// @ts-expect-error TS doesn't seem to understand that we do set min/maxValue\n\t\treturn ret;\n\t}\n}\n\nexport type ParamInformation =\n\t& Omit<\n\t\tConditionalParamInformation,\n\t\t\"condition\" | \"evaluateCondition\" | \"options\" | \"minValue\" | \"maxValue\"\n\t>\n\t& {\n\t\toptions: readonly ConfigOption[];\n\t\tminValue: NonNullable<ConditionalParamInformation[\"minValue\"]>;\n\t\tmaxValue: NonNullable<ConditionalParamInformation[\"maxValue\"]>;\n\t};\n\nexport class ConditionalConfigOption implements ConditionalItem<ConfigOption> {\n\tpublic constructor(\n\t\tpublic readonly value: number,\n\t\tpublic readonly label: string,\n\t\tpublic readonly condition?: string,\n\t) {}\n\n\tpublic evaluateCondition(deviceId?: DeviceID): ConfigOption | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\treturn pick(this, [\"value\", \"label\"]);\n\t}\n}\n\nexport interface ConfigOption {\n\tvalue: number;\n\tlabel: string;\n}\n\nexport type ConditionalParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tConditionalParamInformation[]\n>;\n\nexport type ParamInfoMap = ReadonlyObjectKeyMap<\n\t{ parameter: number; valueBitMask?: number },\n\tParamInformation\n>;\n\nexport function parseConditionalParamInformationMap(\n\tdefinition: JSONObject,\n\tparent: ConditionalDeviceConfig,\n\terrorPrefix: string = \"\",\n): ConditionalParamInfoMap {\n\tconst paramInformation = new ObjectKeyMap<\n\t\t{ parameter: number; valueBitMask?: number },\n\t\tConditionalParamInformation[]\n\t>();\n\n\tconst filename = parent.filename;\n\n\tif (isArray(definition.paramInformation)) {\n\t\t// Check that every param has a param number\n\t\tif (!definition.paramInformation.every((entry: any) => \"#\" in entry)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t`device`,\n\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}required property \"#\" missing in at least one entry of paramInformation`,\n\t\t\t);\n\t\t}\n\n\t\t// And a valid $if condition\n\t\tfor (const entry of definition.paramInformation) {\n\t\t\tvalidateCondition(\n\t\t\t\tfilename,\n\t\t\t\tentry,\n\t\t\t\t`${errorPrefix}At least one entry of paramInformation contains an`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const paramDefinition of definition.paramInformation) {\n\t\t\tconst { [\"#\"]: paramNo, ...defn } = paramDefinition;\n\t\t\tconst key = tryParseParamNumber(paramNo);\n\t\t\tif (!key) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t`device`,\n\t\t\t\t\t`packages/config/config/devices/${filename}: \n${errorPrefix}found invalid param number \"${paramNo}\" in paramInformation`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!paramInformation.has(key)) paramInformation.set(key, []);\n\t\t\tparamInformation\n\t\t\t\t.get(key)!\n\t\t\t\t.push(\n\t\t\t\t\tnew ConditionalParamInformation(\n\t\t\t\t\t\tparent,\n\t\t\t\t\t\tkey.parameter,\n\t\t\t\t\t\tkey.valueBitMask,\n\t\t\t\t\t\tdefn,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t}\n\t} else if (isObject(definition.paramInformation)) {\n\t\t// Silently ignore this old format\n\t} else {\n\t\tthrowInvalidConfig(\n\t\t\t`device`,\n\t\t\t`packages/config/config/devices/${filename}:\n${errorPrefix}paramInformation must be an array!`,\n\t\t);\n\t}\n\n\treturn paramInformation;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAAA,kBAAoC;AACpC,oBAKO;AACP,wBAAkC;AAClC,wBAAmC;AACnC,6BAKO;AAID,MAAO,4BAA2B;EAlBxC,OAkBwC;;;EAGvC,YACC,QACA,iBACA,cACA,YAAsB;AAEtB,SAAK,SAAS;AACd,SAAK,kBAAkB;AACvB,SAAK,eAAe;AAEpB,SAAK,YAAY,WAAW;AAE5B,QAAI,OAAO,WAAW,UAAU,UAAU;AACzC,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,yBAAyB;IAEnD;AACA,SAAK,QAAQ,WAAW;AAExB,QACC,WAAW,eAAe,UACvB,OAAO,WAAW,gBAAgB,UACpC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,+BAA+B;IAEzD;AACA,SAAK,cAAc,WAAW;AAE9B,QACC,OAAO,WAAW,cAAc,YAC7B,WAAW,aAAa,GAC1B;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,4BAA4B;IAEtD;AACA,SAAK,YAAY,WAAW;AAE5B,QACC,WAAW,YAAY,UACpB,OAAO,WAAW,aAAa,UACjC;AACD,gDACC,WACA,kCAAkC,OAAO,QAAQ;aACxC,eAAe,sCAAsC;IAEhE;AACA,SAAK,WA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AAW,gBAAgB,GAAG;EAElD,OAAO;AACN,8CACC,UACA,kCAAkC,QAAQ;EAC3C,WAAW,oCAAoC;EAEhD;AAEA,SAAO;AACR;AAjEgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/esm/Logic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type RulesLogic } from "json-logic-js";
|
|
2
|
-
export declare function parseLogic(
|
|
2
|
+
export declare function parseLogic(input: string): RulesLogic;
|
|
3
3
|
export declare function evaluate(logic: string, context: unknown): string | number | boolean;
|
|
4
4
|
//# sourceMappingURL=Logic.d.ts.map
|
package/build/esm/Logic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logic.d.ts","sourceRoot":"","sources":["../../src/Logic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Logic.d.ts","sourceRoot":"","sources":["../../src/Logic.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,UAAU,EAAwB,MAAM,eAAe,CAAC;AAsCtE,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAMpD;AAED,wBAAgB,QAAQ,CACvB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACd,MAAM,GAAG,MAAM,GAAG,OAAO,CAG3B"}
|
package/build/esm/Logic.js
CHANGED
|
@@ -4,9 +4,9 @@ import semverGt from "semver/functions/gt.js";
|
|
|
4
4
|
import semverGte from "semver/functions/gte.js";
|
|
5
5
|
import semverLt from "semver/functions/lt.js";
|
|
6
6
|
import semverLte from "semver/functions/lte.js";
|
|
7
|
-
import { parse } from "./LogicParser.js";
|
|
8
7
|
// The types are not correct:
|
|
9
8
|
import { default as JsonLogic } from "json-logic-js";
|
|
9
|
+
import { parse, toRulesLogic } from "./LogicParser.js";
|
|
10
10
|
const { add_operation, apply } = JsonLogic;
|
|
11
11
|
function tryOr(operation, onError) {
|
|
12
12
|
return ((...args) => {
|
|
@@ -23,14 +23,12 @@ add_operation("ver >", tryOr((a, b) => semverGt(padVersion(a), padVersion(b)), f
|
|
|
23
23
|
add_operation("ver <=", tryOr((a, b) => semverLte(padVersion(a), padVersion(b)), false));
|
|
24
24
|
add_operation("ver <", tryOr((a, b) => semverLt(padVersion(a), padVersion(b)), false));
|
|
25
25
|
add_operation("ver ===", tryOr((a, b) => semverEq(padVersion(a), padVersion(b)), false));
|
|
26
|
-
export function parseLogic(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
throw new Error(`Invalid logic: ${logic}\n${e.message}`);
|
|
26
|
+
export function parseLogic(input) {
|
|
27
|
+
const expr = parse(input);
|
|
28
|
+
if (!expr) {
|
|
29
|
+
throw new Error(`Failed to parse expression: ${input}`);
|
|
33
30
|
}
|
|
31
|
+
return toRulesLogic(expr);
|
|
34
32
|
}
|
|
35
33
|
export function evaluate(logic, context) {
|
|
36
34
|
const rules = parseLogic(logic);
|
package/build/esm/Logic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logic.js","sourceRoot":"","sources":["../../src/Logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,SAAS,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"Logic.js","sourceRoot":"","sources":["../../src/Logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,SAAS,M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,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAC9D,CAAC;AACF,aAAa,CACZ,SAAS,EACT,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAC9D,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,KAAa;IACvC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,QAAQ,CACvB,KAAa,EACb,OAAgB;IAEhB,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,93 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { RulesLogic } from "json-logic-js";
|
|
2
|
+
export declare enum SyntaxKind {
|
|
3
|
+
Group = 0,
|
|
4
|
+
Or = 1,
|
|
5
|
+
And = 2,
|
|
6
|
+
Comparison = 3,
|
|
7
|
+
Identifier = 4,
|
|
8
|
+
NumberLiteral = 5,
|
|
9
|
+
Version = 6
|
|
5
10
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
export declare enum Operator {
|
|
12
|
+
Equal = 0,
|
|
13
|
+
NotEqual = 1,
|
|
14
|
+
LessThan = 2,
|
|
15
|
+
LessThanOrEqual = 3,
|
|
16
|
+
GreaterThan = 4,
|
|
17
|
+
GreaterThanOrEqual = 5
|
|
10
18
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
export interface ClassParts extends Array<string | ClassParts> {
|
|
17
|
-
}
|
|
18
|
-
export interface ClassExpectation {
|
|
19
|
-
type: "class";
|
|
20
|
-
parts: ClassParts;
|
|
21
|
-
inverted: boolean;
|
|
22
|
-
ignoreCase: boolean;
|
|
23
|
-
}
|
|
24
|
-
export interface AnyExpectation {
|
|
25
|
-
type: "any";
|
|
26
|
-
}
|
|
27
|
-
export interface EndExpectation {
|
|
28
|
-
type: "end";
|
|
29
|
-
}
|
|
30
|
-
export interface OtherExpectation {
|
|
31
|
-
type: "other";
|
|
32
|
-
description: string;
|
|
33
|
-
}
|
|
34
|
-
export type Expectation = LiteralExpectation | ClassExpectation | AnyExpectation | EndExpectation | OtherExpectation;
|
|
35
|
-
declare class _PeggySyntaxError extends Error {
|
|
36
|
-
static buildMessage(expected: Expectation[], found: string | null): string;
|
|
37
|
-
message: string;
|
|
38
|
-
expected: Expectation[];
|
|
39
|
-
found: string | null;
|
|
40
|
-
location: FileRange;
|
|
41
|
-
name: string;
|
|
42
|
-
constructor(message: string, expected: Expectation[], found: string | null, location: FileRange);
|
|
43
|
-
format(sources: {
|
|
44
|
-
source?: any;
|
|
45
|
-
text: string;
|
|
46
|
-
}[]): string;
|
|
47
|
-
}
|
|
48
|
-
export interface TraceEvent {
|
|
49
|
-
type: string;
|
|
50
|
-
rule: string;
|
|
51
|
-
result?: any;
|
|
52
|
-
location: FileRange;
|
|
53
|
-
}
|
|
54
|
-
export interface ParseOptions {
|
|
55
|
-
filename?: string;
|
|
56
|
-
startRule?: "start";
|
|
57
|
-
tracer?: any;
|
|
58
|
-
[key: string]: any;
|
|
59
|
-
}
|
|
60
|
-
export type ParseFunction = <Options extends ParseOptions>(input: string, options?: Options) => Options extends {
|
|
61
|
-
startRule: infer StartRule;
|
|
62
|
-
} ? StartRule extends "start" ? Start : Start : Start;
|
|
63
|
-
export declare const parse: ParseFunction;
|
|
64
|
-
export declare const PeggySyntaxError: typeof _PeggySyntaxError;
|
|
65
|
-
export type PeggySyntaxError = _PeggySyntaxError;
|
|
66
|
-
export type Start = Group | Or | And | Comparison;
|
|
67
|
-
export type Group = Or;
|
|
68
|
-
export type Or = {
|
|
69
|
-
or: [And | Comparison, ...OrTails[]];
|
|
19
|
+
export type Expression = Or | And | Comparison;
|
|
20
|
+
type Or = {
|
|
21
|
+
kind: SyntaxKind.Or;
|
|
22
|
+
operands: Expression[];
|
|
70
23
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
24
|
+
type And = {
|
|
25
|
+
kind: SyntaxKind.And;
|
|
26
|
+
operands: Expression[];
|
|
74
27
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
28
|
+
type Comparison = {
|
|
29
|
+
kind: SyntaxKind.Comparison;
|
|
30
|
+
left: Identifier;
|
|
31
|
+
operator: Operator;
|
|
32
|
+
right: NumberLiteral | Version;
|
|
79
33
|
};
|
|
80
|
-
|
|
81
|
-
|
|
34
|
+
type Identifier = {
|
|
35
|
+
kind: SyntaxKind.Identifier;
|
|
36
|
+
name: string;
|
|
82
37
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
38
|
+
type NumberLiteral = {
|
|
39
|
+
kind: SyntaxKind.NumberLiteral;
|
|
40
|
+
value: number;
|
|
41
|
+
};
|
|
42
|
+
type Version = {
|
|
43
|
+
kind: SyntaxKind.Version;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
export declare enum TokenKind {
|
|
47
|
+
Identifier = 0,
|
|
48
|
+
NumberLiteral = 1,
|
|
49
|
+
Dot = 2,// "."
|
|
50
|
+
LeftParen = 3,// "("
|
|
51
|
+
RightParen = 4,// ")"
|
|
52
|
+
BarBar = 5,// "||"
|
|
53
|
+
AmpAmp = 6,// "&&"
|
|
54
|
+
EqualsEquals = 7,// "=="
|
|
55
|
+
EqualsEqualsEquals = 8,// "==="
|
|
56
|
+
ExclamationEquals = 9,// "!="
|
|
57
|
+
ExclamationEqualsEquals = 10,// "!=="
|
|
58
|
+
LessThan = 11,// "<"
|
|
59
|
+
LessThanEquals = 12,// "<="
|
|
60
|
+
GreaterThan = 13,// ">"
|
|
61
|
+
GreaterThanEquals = 14
|
|
62
|
+
}
|
|
63
|
+
export type Token = {
|
|
64
|
+
start: number;
|
|
65
|
+
kind: TokenKind;
|
|
66
|
+
value?: string;
|
|
86
67
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
export
|
|
91
|
-
export
|
|
68
|
+
/**
|
|
69
|
+
* Splits a string into tokens to be consumed by the Parser.
|
|
70
|
+
*/
|
|
71
|
+
export declare function tokenize(input: string): Generator<Token>;
|
|
72
|
+
export declare function parse(input: string): Expression | undefined;
|
|
73
|
+
export declare function toRulesLogic(expr: Expression): RulesLogic;
|
|
92
74
|
export {};
|
|
93
75
|
//# sourceMappingURL=LogicParser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LogicParser.d.ts","sourceRoot":"","sources":["../../src/LogicParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LogicParser.d.ts","sourceRoot":"","sources":["../../src/LogicParser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,oBAAY,UAAU;IACrB,KAAK,IAAA;IACL,EAAE,IAAA;IACF,GAAG,IAAA;IACH,UAAU,IAAA;IACV,UAAU,IAAA;IACV,aAAa,IAAA;IACb,OAAO,IAAA;CACP;AAED,oBAAY,QAAQ;IACnB,KAAK,IAAA;IACL,QAAQ,IAAA;IACR,QAAQ,IAAA;IACR,eAAe,IAAA;IACf,WAAW,IAAA;IACX,kBAAkB,IAAA;CAClB;AAED,MAAM,MAAM,UAAU,GACnB,EAAE,GACF,GAAG,GACH,UAAU,CAAC;AAEd,KAAK,EAAE,GA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