Skip to content

Commit d0a86a7

Browse files
authored
Merge pull request #38 from dfpc-coe/flow
Add Flow Stripping
2 parents c8e77d9 + 8faf38e commit d0a86a7

7 files changed

Lines changed: 401 additions & 333 deletions

File tree

.github/workflows/doc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- name: Checkout
28-
uses: actions/checkout@v4
28+
uses: actions/checkout@v6
2929
- name: Setup Pages
3030
uses: actions/configure-pages@v5
31-
- uses: actions/setup-node@v4
31+
- uses: actions/setup-node@v6
3232
with:
3333
node-version: 22
3434
registry-url: https://registry.npmjs.org/
@@ -37,7 +37,7 @@ jobs:
3737
- name: npm run doc
3838
run: npm run doc
3939
- name: Upload artifact
40-
uses: actions/upload-pages-artifact@v3
40+
uses: actions/upload-pages-artifact@v4
4141
with:
4242
path: './docs/'
4343
- name: Deploy to GitHub Pages

.github/workflows/release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@ jobs:
3131
- name: npm publish
3232
run: npm publish --provenance --access public
3333

34-
- name: Get tag
35-
id: tag
36-
uses: dawidd6/action-get-tag@v1
37-
3834
- name: Generate CHANGELOG
39-
run: grep -Pzo "### ${{steps.tag.outputs.tag}}(?s).*?(?=###)" CHANGELOG.md > RELEASE
35+
run: grep -Pzo "### ${{ github.ref_name }}(?s).*?(?=###)" CHANGELOG.md > RELEASE
4036

4137
- name: Github Release
4238
uses: softprops/action-gh-release@v2

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
runs-on: ubuntu-latest
1717
if: github.event.pull_request.draft == false
1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v6
2020
with:
2121
ref: ${{ github.event.pull_request.head.sha }}
2222

23-
- uses: actions/setup-node@v4
23+
- uses: actions/setup-node@v6
2424
with:
2525
node-version: 22
2626
registry-url: https://registry.npmjs.org/

index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,25 @@ export type TAKOptions = {
8686
socketBatchSize?: number;
8787
};
8888

89+
export type WriteOptions = {
90+
/** Remove any existing flow tags and replace them with a fresh
91+
* `NodeCoT-*` entry before serializing to XML.
92+
* Useful when re-submitting CoTs back to TAK Server over 8089.
93+
* @default false */
94+
stripFlow?: boolean;
95+
};
96+
8997
const DEFAULT_WRITE_QUEUE_SIZE = 10_000;
9098
const DEFAULT_SOCKET_BATCH_SIZE = 64;
9199

100+
function cloneCoT(cot: CoT): CoT {
101+
const cloned = new CoT(JSON.parse(JSON.stringify(cot.raw)));
102+
cloned.metadata = JSON.parse(JSON.stringify(cot.metadata));
103+
cloned.path = cot.path;
104+
105+
return cloned;
106+
}
107+
92108
export default class TAK extends EventEmitter {
93109
id: number | string;
94110
type: string;
@@ -394,14 +410,17 @@ export default class TAK extends EventEmitter {
394410
*
395411
* @param cots Array of CoT objects to send
396412
*/
397-
async write(cots: CoT[]): Promise<void> {
413+
async write(cots: CoT[], opts: WriteOptions = {}): Promise<void> {
398414
for (let i = 0; i < cots.length; ) {
399415
if (this.destroyed) return;
400416

401417
// Serialize upfront and push XML strings into the ring buffer
402418
while (
403419
i < cots.length &&
404-
this.queue.push(CoTParser.to_xml(cots[i]))
420+
this.queue.push(CoTParser.to_xml(
421+
opts.stripFlow ? cloneCoT(cots[i]) : cots[i],
422+
opts.stripFlow ? { resetFlow: true } : undefined,
423+
))
405424
) {
406425
i++;
407426
}

0 commit comments

Comments
 (0)