Type each known TLV's value by its tag, on read and on write #30
+1
-1
@@ -72,7 +72,7 @@
|
||||
A decimal key naming a tag the table knows, `{ 1063: … }`, is refused in favour of the name, and
|
||||
so are `alert_on_msg_delivery` and `failed_broadcast_area_identifier` in favour of
|
||||
`alert_on_message_delivery` and `broadcast_area_identifier`, the names they read back under. The
|
||||
two alternate names are gone from `tlvs` too, which is now typed by `TlvName`: index it with one.
|
||||
two alternate names are gone from `tlvs` too, which is now typed by `TlvName`: narrow a `string` with `isTlvName()` before indexing it.
|
||||
- `cmds.broadcast_sm_resp.tlvMap` is removed; nothing read it.
|
||||
|
||||
## 0.5.0
|
||||
|
||||
@@ -655,7 +655,7 @@ if (isCommand(pduObj, 'submit_sm')) {
|
||||
| Messages | `encodeMessage`, `decodeMessage`, `splitMessage`, `bitCount`, `messageOctets`, `concatOf`, `concatInfo`, `detect`, `unencodable`, `messageClassOf`, `dataCodingByEncoding`, `encodingByDataCoding` |
|
||||
| Receipts | `dlrFromPdu`, `parseReceipt`, `receiptCodes` |
|
||||
| Time and ids | `smppDate`, `smppTime`, `uuidv7` |
|
||||
| Spec tables | `cmds`, `consts`, `encodings`, `errors`, `tlvs`, `types`, the `cmdsById`, `constsById`, `errorsById` and `tlvsById` maps, and all of them grouped as `defs`. `isCommandName`, `isErrorName`, `isEncodingName`, `commandNameById` and `errorNameById` narrow a value into them. |
|
||||
| Spec tables | `cmds`, `consts`, `encodings`, `errors`, `tlvs`, `types`, the `cmdsById`, `constsById`, `errorsById` and `tlvsById` maps, and all of them grouped as `defs`. `isCommandName`, `isErrorName`, `isEncodingName`, `isTlvName`, `commandNameById` and `errorNameById` narrow a value into them. |
|
||||
| Types | Every option, result, event payload and table entry has a named type: `ClientOptions`, `ServerOptions`, `SendSmsOptions`, `SendSmsResult`, `Sms`, `Dlr`, `MessageDlr`, `Receipt`, `PduObject`, `PduHeader`, `SmppLog`, `Result` and the rest in `dist/index.d.ts`. |
|
||||
|
||||
## What changed per release
|
||||
|
||||
+1
-1
@@ -253,7 +253,7 @@ function readTlv(pdu: Buffer, offset: number): Result<{ octets: number; occurren
|
||||
return { occurrence: { definition, tagId, value }, octets: 4 + tagLength };
|
||||
}
|
||||
|
||||
function isTlvName(name: string): name is TlvName {
|
||||
export function isTlvName(name: string): name is TlvName {
|
||||
return Object.hasOwn(specs, name);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ export { cmds, cmdsById, commandNameById, isCommandName } from './defs/commands.
|
||||
export { consts, constsById } from './defs/constants.ts';
|
||||
export { dataCodingByEncoding, detect, encodingByDataCoding, encodings, isEncodingName, messageClassOf, unencodable } from './defs/encodings.ts';
|
||||
export { errorNameById, errors, errorsById, isErrorName } from './defs/errors.ts';
|
||||
export { tlvs, tlvsById } from './defs/tlvs.ts';
|
||||
export { isTlvName, tlvs, tlvsById } from './defs/tlvs.ts';
|
||||
export { types } from './defs/types.ts';
|
||||
|
||||
export {
|
||||
|
||||
+5
-1
@@ -3,7 +3,7 @@ import test, { describe } from 'node:test';
|
||||
import { PduRefusedError, refusalAnswer } from '../src/pdu-refusal.ts';
|
||||
import { isCommand, isResp, objToPdu, pduReturn, pduToObj } from '../src/pdu.ts';
|
||||
import { paramText } from '../src/defs/types.ts';
|
||||
import { tlvsById } from '../src/defs/tlvs.ts';
|
||||
import { isTlvName, tlvsById } from '../src/defs/tlvs.ts';
|
||||
|
||||
function encode(...args: Parameters<typeof objToPdu>): Buffer {
|
||||
const { buffer, err } = objToPdu(...args);
|
||||
@@ -502,6 +502,10 @@ describe('TLVs', () => {
|
||||
const { err } = objToPdu({ cmdName: 'broadcast_sm_resp', params, tlvs: { failed_broadcast_area_identifier: { tagValue: areas } } });
|
||||
|
||||
assert.match(err?.message ?? '', /key it broadcast_area_identifier/);
|
||||
assert.deepEqual(
|
||||
['broadcast_area_identifier', 'failed_broadcast_area_identifier', 'constructor'].map(isTlvName),
|
||||
[true, false, false],
|
||||
);
|
||||
});
|
||||
|
||||
test('refuses a repeatable TLV given one value, and a lone TLV given several', () => {
|
||||
|
||||
Reference in New Issue
Block a user