@leapdev/app-platform 0.1.0-beta.26 → 0.1.0-beta.28
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/package.json +2 -2
- package/src/index.d.ts +9 -0
- package/src/index.js +12 -1
- package/src/lib/app-platform.d.ts +16 -0
- package/src/lib/app-platform.js +59 -38
- package/src/lib/domains/leap-document-data/index.d.ts +8 -0
- package/src/lib/domains/leap-document-data/index.js +11 -0
- package/src/lib/domains/leap-document-data/leap-document-data.model.d.ts +7 -0
- package/src/lib/domains/leap-document-data/leap-document-data.model.js +11 -0
- package/src/lib/domains/leap-document-data/leap-document-data.normalizer.d.ts +19 -0
- package/src/lib/domains/leap-document-data/leap-document-data.normalizer.js +101 -0
- package/src/lib/domains/leap-document-data/leap-document-data.service.d.ts +90 -0
- package/src/lib/domains/leap-document-data/leap-document-data.service.js +156 -0
- package/src/lib/ports/adapters/excel-custom-xml-part.adapter.d.ts +15 -0
- package/src/lib/ports/adapters/excel-custom-xml-part.adapter.js +113 -0
- package/src/lib/ports/adapters/in-memory-custom-xml-part.adapter.d.ts +22 -0
- package/src/lib/ports/adapters/in-memory-custom-xml-part.adapter.js +52 -0
- package/src/lib/ports/adapters/word-custom-xml-part.adapter.d.ts +16 -0
- package/src/lib/ports/adapters/word-custom-xml-part.adapter.js +118 -0
- package/src/lib/ports/custom-xml-part.port.d.ts +44 -0
- package/src/lib/ports/custom-xml-part.port.js +2 -0
- package/src/lib/ports/index.d.ts +7 -0
- package/src/lib/ports/index.js +10 -0
- package/src/lib/services/signalr/signalr.service.d.ts +7 -0
- package/src/lib/services/signalr/signalr.service.js +77 -76
- package/src/types.d.ts +3 -2
- package/src/types.js +3 -2
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LeapDocumentDataService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const xml_1 = require("../../functions/xml");
|
|
6
|
+
const constants_1 = require("../../models/constants");
|
|
7
|
+
const leap_model_1 = require("../../models/leap.model");
|
|
8
|
+
const ports_1 = require("../../ports");
|
|
9
|
+
const leap_document_data_model_1 = require("./leap-document-data.model");
|
|
10
|
+
const leap_document_data_normalizer_1 = require("./leap-document-data.normalizer");
|
|
11
|
+
/**
|
|
12
|
+
* Domain service for LeapDocumentData custom XML operations.
|
|
13
|
+
*
|
|
14
|
+
* Primary usage (host-based):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const service = new LeapDocumentDataService(HostApplicationType.Word);
|
|
17
|
+
* const data = await service.get();
|
|
18
|
+
* await service.upsert({ matterId: '12345' });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Testing usage (inject custom port):
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const service = LeapDocumentDataService.forPort(new InMemoryCustomXmlPartAdapter());
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Implements item-level operations via: read → mutate → serialize → setXml.
|
|
27
|
+
*
|
|
28
|
+
* Strategy:
|
|
29
|
+
* - Read: getXml → parse → normalize
|
|
30
|
+
* - Update: getXml → parse → merge → serialize → setXml
|
|
31
|
+
* - Upsert: attempts update, preserves unknown nodes by merging
|
|
32
|
+
*
|
|
33
|
+
* Conflict resolution: last-write-wins at the field level.
|
|
34
|
+
* Unknown nodes (fields not in LeapDocumentData type) are preserved during updates.
|
|
35
|
+
*/
|
|
36
|
+
class LeapDocumentDataService {
|
|
37
|
+
constructor(hostTypeOrPort, namespace, rootTagName) {
|
|
38
|
+
// Host-based construction (primary path)
|
|
39
|
+
if (typeof hostTypeOrPort === 'number') {
|
|
40
|
+
const hostType = hostTypeOrPort;
|
|
41
|
+
this.xmlPort = this.createAdapterForHost(hostType);
|
|
42
|
+
this.namespace = constants_1.constants.LeapDocumentDataNamespace;
|
|
43
|
+
this.rootTagName = constants_1.constants.LeapDocumentDataRootTagName;
|
|
44
|
+
}
|
|
45
|
+
// Port injection (testing/advanced path)
|
|
46
|
+
else {
|
|
47
|
+
this.xmlPort = hostTypeOrPort;
|
|
48
|
+
this.namespace = namespace !== null && namespace !== void 0 ? namespace : constants_1.constants.LeapDocumentDataNamespace;
|
|
49
|
+
this.rootTagName = rootTagName !== null && rootTagName !== void 0 ? rootTagName : constants_1.constants.LeapDocumentDataRootTagName;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a LeapDocumentDataService with a custom port.
|
|
54
|
+
*
|
|
55
|
+
* Use this for unit testing with InMemoryCustomXmlPartAdapter or for advanced scenarios
|
|
56
|
+
* where you need to provide a custom port implementation.
|
|
57
|
+
*
|
|
58
|
+
* @param xmlPort - Custom XML part port implementation
|
|
59
|
+
* @param namespace - Optional custom namespace (defaults to LeapDocumentData namespace)
|
|
60
|
+
* @param rootTagName - Optional custom root tag (defaults to LeapDocumentData root)
|
|
61
|
+
*/
|
|
62
|
+
static forPort(xmlPort, namespace, rootTagName) {
|
|
63
|
+
return new LeapDocumentDataService(xmlPort, namespace, rootTagName);
|
|
64
|
+
}
|
|
65
|
+
createAdapterForHost(hostType) {
|
|
66
|
+
switch (hostType) {
|
|
67
|
+
case leap_model_1.HostApplicationType.MicrosoftWord:
|
|
68
|
+
return new ports_1.WordCustomXmlPartAdapter();
|
|
69
|
+
case leap_model_1.HostApplicationType.MicrosoftExcel:
|
|
70
|
+
return new ports_1.ExcelCustomXmlPartAdapter();
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Unsupported host type: ${hostType}. LeapDocumentDataService supports Word and Excel.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the current LeapDocumentData from the custom XML part.
|
|
77
|
+
*/
|
|
78
|
+
get() {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const xml = yield this.xmlPort.getXml(this.namespace);
|
|
82
|
+
if (!xml) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const obj = yield (0, xml_1.toObj)(xml);
|
|
86
|
+
return (0, leap_document_data_normalizer_1.normalizeLeapDocumentData)(obj);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(`[LeapDocumentDataService] Failed to get document data: ${error}`);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set (replace) the LeapDocumentData in the custom XML part.
|
|
96
|
+
*
|
|
97
|
+
* This performs a full replacement. Use `upsert` to preserve unknown fields.
|
|
98
|
+
*/
|
|
99
|
+
set(documentData) {
|
|
100
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const xml = this.serializeToXml(documentData);
|
|
102
|
+
yield this.xmlPort.setXml(this.namespace, xml);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Upsert (update or insert) LeapDocumentData fields.
|
|
107
|
+
*
|
|
108
|
+
* Preserves unknown fields present in the existing XML part.
|
|
109
|
+
* If no part exists, creates one with the provided data.
|
|
110
|
+
*/
|
|
111
|
+
upsert(documentData) {
|
|
112
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const existing = yield this.get();
|
|
115
|
+
const merged = existing
|
|
116
|
+
? new leap_document_data_model_1.LeapDocumentData(Object.assign(Object.assign({}, existing), documentData))
|
|
117
|
+
: new leap_document_data_model_1.LeapDocumentData(documentData);
|
|
118
|
+
yield this.set(merged);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error(`[LeapDocumentDataService] Failed to upsert document data: ${error}`);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Delete the LeapDocumentData custom XML part.
|
|
128
|
+
*/
|
|
129
|
+
delete() {
|
|
130
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
yield this.xmlPort.delete(this.namespace);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Ensure the custom XML part exists (create if missing).
|
|
136
|
+
*/
|
|
137
|
+
ensurePart() {
|
|
138
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
yield this.xmlPort.ensurePart(this.namespace, this.rootTagName);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Serialize LeapDocumentData to XML string.
|
|
144
|
+
*/
|
|
145
|
+
serializeToXml(documentData) {
|
|
146
|
+
const entries = (0, leap_document_data_normalizer_1.serializeLeapDocumentDataEntries)(documentData);
|
|
147
|
+
const fields = entries
|
|
148
|
+
.map(([key, value]) => ` <${key}>${value}</${key}>`)
|
|
149
|
+
.join('\n');
|
|
150
|
+
return `<?xml version="1.0"?>
|
|
151
|
+
<${this.rootTagName} xmlns="${this.namespace}">
|
|
152
|
+
${fields}
|
|
153
|
+
</${this.rootTagName}>`;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.LeapDocumentDataService = LeapDocumentDataService;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CustomXmlPartPort } from '../custom-xml-part.port';
|
|
2
|
+
/**
|
|
3
|
+
* Excel adapter implementing CustomXmlPartPort.
|
|
4
|
+
*
|
|
5
|
+
* Uses Office.js Excel APIs to read/write custom XML parts.
|
|
6
|
+
* Excel custom XML part APIs differ from Word's async callback pattern.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ExcelCustomXmlPartAdapter implements CustomXmlPartPort {
|
|
9
|
+
getXml(namespace: string): Promise<string | null>;
|
|
10
|
+
setXml(namespace: string, xml: string): Promise<void>;
|
|
11
|
+
delete(namespace: string): Promise<void>;
|
|
12
|
+
ensurePart(namespace: string, rootTagName: string): Promise<void>;
|
|
13
|
+
private getCustomXmlPartsByNamespace;
|
|
14
|
+
private getCustomXmlPartByNamespace;
|
|
15
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="office-js" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ExcelCustomXmlPartAdapter = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/**
|
|
7
|
+
* Excel adapter implementing CustomXmlPartPort.
|
|
8
|
+
*
|
|
9
|
+
* Uses Office.js Excel APIs to read/write custom XML parts.
|
|
10
|
+
* Excel custom XML part APIs differ from Word's async callback pattern.
|
|
11
|
+
*/
|
|
12
|
+
class ExcelCustomXmlPartAdapter {
|
|
13
|
+
getXml(namespace) {
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
return Excel.run((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const customXmlPart = yield this.getCustomXmlPartByNamespace(context, namespace);
|
|
18
|
+
if (!customXmlPart) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const xmlResult = customXmlPart.getXml();
|
|
22
|
+
yield context.sync();
|
|
23
|
+
return xmlResult.value;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error(error, `[ExcelCustomXmlPartAdapter] Failed to get XML for namespace ${namespace}`);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
setXml(namespace, xml) {
|
|
33
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield Excel.run((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (!context.workbook) {
|
|
36
|
+
throw new Error('Excel workbook not available');
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
// Delete existing part if present
|
|
40
|
+
const existingPart = yield this.getCustomXmlPartByNamespace(context, namespace);
|
|
41
|
+
if (existingPart) {
|
|
42
|
+
existingPart.delete();
|
|
43
|
+
yield context.sync();
|
|
44
|
+
}
|
|
45
|
+
// Add new part
|
|
46
|
+
const customXmlParts = context.workbook.customXmlParts;
|
|
47
|
+
customXmlParts.add(xml);
|
|
48
|
+
yield context.sync();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error(error, `[ExcelCustomXmlPartAdapter] Failed to set XML for namespace ${namespace}`);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
delete(namespace) {
|
|
58
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
yield Excel.run((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
const customXmlCollection = yield this.getCustomXmlPartsByNamespace(context, namespace);
|
|
62
|
+
if (!customXmlCollection || customXmlCollection.items.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const part of customXmlCollection.items) {
|
|
66
|
+
part.delete();
|
|
67
|
+
}
|
|
68
|
+
yield context.sync();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(error, `[ExcelCustomXmlPartAdapter] Failed to delete parts for namespace ${namespace}`);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
ensurePart(namespace, rootTagName) {
|
|
78
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const existing = yield Excel.run((context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return this.getCustomXmlPartByNamespace(context, namespace);
|
|
81
|
+
}));
|
|
82
|
+
if (existing) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Create minimal XML part
|
|
86
|
+
const xml = `<?xml version="1.0"?><${rootTagName} xmlns="${namespace}"></${rootTagName}>`;
|
|
87
|
+
yield this.setXml(namespace, xml);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getCustomXmlPartsByNamespace(context, namespace) {
|
|
91
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (!context.workbook) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const customXmlParts = context.workbook.customXmlParts;
|
|
96
|
+
const customXmlCollection = customXmlParts.getByNamespace(namespace);
|
|
97
|
+
customXmlCollection.load('items');
|
|
98
|
+
yield context.sync();
|
|
99
|
+
return customXmlCollection;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getCustomXmlPartByNamespace(context, namespace) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const customXmlCollection = yield this.getCustomXmlPartsByNamespace(context, namespace);
|
|
105
|
+
if (customXmlCollection != null &&
|
|
106
|
+
customXmlCollection.items.length > 0) {
|
|
107
|
+
return customXmlCollection.items[0];
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ExcelCustomXmlPartAdapter = ExcelCustomXmlPartAdapter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CustomXmlPartPort } from '../custom-xml-part.port';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory adapter implementing CustomXmlPartPort for testing.
|
|
4
|
+
*
|
|
5
|
+
* Stores custom XML parts in a simple Map keyed by namespace.
|
|
6
|
+
* Does not perform XML validation - assumes well-formed XML.
|
|
7
|
+
*/
|
|
8
|
+
export declare class InMemoryCustomXmlPartAdapter implements CustomXmlPartPort {
|
|
9
|
+
private parts;
|
|
10
|
+
getXml(namespace: string): Promise<string | null>;
|
|
11
|
+
setXml(namespace: string, xml: string): Promise<void>;
|
|
12
|
+
delete(namespace: string): Promise<void>;
|
|
13
|
+
ensurePart(namespace: string, rootTagName: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Test helper: clear all stored parts.
|
|
16
|
+
*/
|
|
17
|
+
clear(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Test helper: get all stored parts.
|
|
20
|
+
*/
|
|
21
|
+
getAllParts(): Map<string, string>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryCustomXmlPartAdapter = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* In-memory adapter implementing CustomXmlPartPort for testing.
|
|
7
|
+
*
|
|
8
|
+
* Stores custom XML parts in a simple Map keyed by namespace.
|
|
9
|
+
* Does not perform XML validation - assumes well-formed XML.
|
|
10
|
+
*/
|
|
11
|
+
class InMemoryCustomXmlPartAdapter {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.parts = new Map();
|
|
14
|
+
}
|
|
15
|
+
getXml(namespace) {
|
|
16
|
+
var _a;
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return (_a = this.parts.get(namespace)) !== null && _a !== void 0 ? _a : null;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
setXml(namespace, xml) {
|
|
22
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
this.parts.set(namespace, xml);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
delete(namespace) {
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
this.parts.delete(namespace);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
ensurePart(namespace, rootTagName) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
if (!this.parts.has(namespace)) {
|
|
34
|
+
const xml = `<?xml version="1.0"?><${rootTagName} xmlns="${namespace}"></${rootTagName}>`;
|
|
35
|
+
this.parts.set(namespace, xml);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Test helper: clear all stored parts.
|
|
41
|
+
*/
|
|
42
|
+
clear() {
|
|
43
|
+
this.parts.clear();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Test helper: get all stored parts.
|
|
47
|
+
*/
|
|
48
|
+
getAllParts() {
|
|
49
|
+
return new Map(this.parts);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.InMemoryCustomXmlPartAdapter = InMemoryCustomXmlPartAdapter;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CustomXmlPartPort } from '../custom-xml-part.port';
|
|
2
|
+
/**
|
|
3
|
+
* Word adapter implementing CustomXmlPartPort.
|
|
4
|
+
*
|
|
5
|
+
* Uses Office.js Word APIs to read/write custom XML parts.
|
|
6
|
+
* Delegates to existing custom-xml-part.service logic where applicable.
|
|
7
|
+
*/
|
|
8
|
+
export declare class WordCustomXmlPartAdapter implements CustomXmlPartPort {
|
|
9
|
+
getXml(namespace: string): Promise<string | null>;
|
|
10
|
+
setXml(namespace: string, xml: string): Promise<void>;
|
|
11
|
+
delete(namespace: string): Promise<void>;
|
|
12
|
+
ensurePart(namespace: string, rootTagName: string): Promise<void>;
|
|
13
|
+
private getCustomXmlPartsByNamespace;
|
|
14
|
+
private getCustomXmlPartByNamespace;
|
|
15
|
+
private deletePart;
|
|
16
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="office-js" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.WordCustomXmlPartAdapter = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const helpers_1 = require("../../functions/helpers");
|
|
7
|
+
/**
|
|
8
|
+
* Word adapter implementing CustomXmlPartPort.
|
|
9
|
+
*
|
|
10
|
+
* Uses Office.js Word APIs to read/write custom XML parts.
|
|
11
|
+
* Delegates to existing custom-xml-part.service logic where applicable.
|
|
12
|
+
*/
|
|
13
|
+
class WordCustomXmlPartAdapter {
|
|
14
|
+
getXml(namespace) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const officeDocument = Office.context.document;
|
|
17
|
+
if (!officeDocument) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const customXmlPart = yield this.getCustomXmlPartByNamespace(namespace);
|
|
22
|
+
if (!customXmlPart) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const getXmlAsync = (0, helpers_1.promisifyAsync)(customXmlPart.getXmlAsync.bind(customXmlPart));
|
|
26
|
+
const xml = yield getXmlAsync({});
|
|
27
|
+
return xml;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(error, `[WordCustomXmlPartAdapter] Failed to get XML for namespace ${namespace}`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
setXml(namespace, xml) {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const officeDocument = Office.context.document;
|
|
38
|
+
if (!officeDocument) {
|
|
39
|
+
throw new Error('Office document not available');
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const existingPart = yield this.getCustomXmlPartByNamespace(namespace);
|
|
43
|
+
if (existingPart) {
|
|
44
|
+
// Replace existing part by deleting and recreating
|
|
45
|
+
yield this.deletePart(existingPart);
|
|
46
|
+
}
|
|
47
|
+
// Add new part
|
|
48
|
+
const officeCustomXmlParts = officeDocument.customXmlParts;
|
|
49
|
+
const add = (0, helpers_1.promisifyAsync)(officeCustomXmlParts.addAsync.bind(officeCustomXmlParts));
|
|
50
|
+
yield add(xml, {});
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error(error, `[WordCustomXmlPartAdapter] Failed to set XML for namespace ${namespace}`);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
delete(namespace) {
|
|
59
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
const parts = yield this.getCustomXmlPartsByNamespace(namespace);
|
|
62
|
+
if (!parts || parts.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
for (const part of parts) {
|
|
66
|
+
yield this.deletePart(part);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(error, `[WordCustomXmlPartAdapter] Failed to delete parts for namespace ${namespace}`);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
ensurePart(namespace, rootTagName) {
|
|
76
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const existing = yield this.getCustomXmlPartByNamespace(namespace);
|
|
78
|
+
if (existing) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Create minimal XML part
|
|
82
|
+
const xml = `<?xml version="1.0"?><${rootTagName} xmlns="${namespace}"></${rootTagName}>`;
|
|
83
|
+
yield this.setXml(namespace, xml);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getCustomXmlPartsByNamespace(namespace) {
|
|
87
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const officeDocument = Office.context.document;
|
|
89
|
+
if (!officeDocument) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const officeCustomXmlParts = officeDocument.customXmlParts;
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
officeCustomXmlParts.getByNamespaceAsync(namespace, (result) => {
|
|
95
|
+
resolve(result.value);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getCustomXmlPartByNamespace(namespace) {
|
|
101
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const customXmlParts = yield this.getCustomXmlPartsByNamespace(namespace);
|
|
103
|
+
if (customXmlParts != null &&
|
|
104
|
+
Array.isArray(customXmlParts) &&
|
|
105
|
+
customXmlParts.length > 0) {
|
|
106
|
+
return customXmlParts[0];
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
deletePart(part) {
|
|
112
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const deleteAsync = (0, helpers_1.promisifyAsync)(part.deleteAsync.bind(part));
|
|
114
|
+
yield deleteAsync({});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.WordCustomXmlPartAdapter = WordCustomXmlPartAdapter;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port (interface) for Custom XML Part operations.
|
|
3
|
+
*
|
|
4
|
+
* Domains depend on this abstraction for reading/writing whole custom XML parts.
|
|
5
|
+
* Word and Excel adapters implement this port to provide host-specific XML access.
|
|
6
|
+
*
|
|
7
|
+
* All operations work at the whole-part level (not node-level).
|
|
8
|
+
* Item-level CRUD is built in domain services: read → mutate → serialize → setXml.
|
|
9
|
+
*/
|
|
10
|
+
export interface CustomXmlPartPort {
|
|
11
|
+
/**
|
|
12
|
+
* Get the XML content of a custom XML part by namespace.
|
|
13
|
+
*
|
|
14
|
+
* @param namespace - The namespace URI identifying the custom XML part
|
|
15
|
+
* @returns The XML string content, or null if not found
|
|
16
|
+
*/
|
|
17
|
+
getXml(namespace: string): Promise<string | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Set (replace or create) the XML content for a custom XML part by namespace.
|
|
20
|
+
*
|
|
21
|
+
* If a part with the given namespace exists, it is replaced.
|
|
22
|
+
* If no part exists, a new one is created.
|
|
23
|
+
*
|
|
24
|
+
* @param namespace - The namespace URI identifying the custom XML part
|
|
25
|
+
* @param xml - The complete XML content to set
|
|
26
|
+
*/
|
|
27
|
+
setXml(namespace: string, xml: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Delete all custom XML parts with the given namespace.
|
|
30
|
+
*
|
|
31
|
+
* @param namespace - The namespace URI identifying the custom XML part(s) to delete
|
|
32
|
+
*/
|
|
33
|
+
delete(namespace: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Ensure a custom XML part exists for the given namespace.
|
|
36
|
+
*
|
|
37
|
+
* If a part already exists, this is a no-op.
|
|
38
|
+
* If no part exists, an empty part with the given root element is created.
|
|
39
|
+
*
|
|
40
|
+
* @param namespace - The namespace URI
|
|
41
|
+
* @param rootTagName - The root element name for the XML part
|
|
42
|
+
*/
|
|
43
|
+
ensurePart(namespace: string, rootTagName: string): Promise<void>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export for ports and adapters.
|
|
3
|
+
*/
|
|
4
|
+
export * from './custom-xml-part.port';
|
|
5
|
+
export * from './adapters/word-custom-xml-part.adapter';
|
|
6
|
+
export * from './adapters/excel-custom-xml-part.adapter';
|
|
7
|
+
export * from './adapters/in-memory-custom-xml-part.adapter';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/**
|
|
5
|
+
* Barrel export for ports and adapters.
|
|
6
|
+
*/
|
|
7
|
+
tslib_1.__exportStar(require("./custom-xml-part.port"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./adapters/word-custom-xml-part.adapter"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./adapters/excel-custom-xml-part.adapter"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./adapters/in-memory-custom-xml-part.adapter"), exports);
|
|
@@ -10,4 +10,11 @@ export declare class SignalRService {
|
|
|
10
10
|
documentId: string;
|
|
11
11
|
matterId: string;
|
|
12
12
|
}): Promise<boolean>;
|
|
13
|
+
openMatter(params: {
|
|
14
|
+
matterId: string;
|
|
15
|
+
}): Promise<boolean>;
|
|
16
|
+
setBookmark(params: {
|
|
17
|
+
matterId: string;
|
|
18
|
+
tables: unknown[];
|
|
19
|
+
}): Promise<boolean>;
|
|
13
20
|
}
|