@3sixty/data-processing-service 0.0.0-stage → 0.20.0-next.1
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/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/dataProcessingRoutes.js +384 -0
- package/dist/es/dataProcessingRoutes.js.map +1 -0
- package/dist/es/dataProcessingService.js +175 -0
- package/dist/es/dataProcessingService.js.map +1 -0
- package/dist/es/entities/extractionRule.js +43 -0
- package/dist/es/entities/extractionRule.js.map +1 -0
- package/dist/es/entities/extractionRuleGroup.js +37 -0
- package/dist/es/entities/extractionRuleGroup.js.map +1 -0
- package/dist/es/index.js +10 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IDataProcessingServiceConstructorOptions.js +4 -0
- package/dist/es/models/IDataProcessingServiceConstructorOptions.js.map +1 -0
- package/dist/es/restEntryPoints.js +13 -0
- package/dist/es/restEntryPoints.js.map +1 -0
- package/dist/es/schema.js +13 -0
- package/dist/es/schema.js.map +1 -0
- package/dist/types/dataProcessingRoutes.d.ts +61 -0
- package/dist/types/dataProcessingService.d.ts +73 -0
- package/dist/types/entities/extractionRule.d.ts +22 -0
- package/dist/types/entities/extractionRuleGroup.d.ts +18 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/models/IDataProcessingServiceConstructorOptions.d.ts +14 -0
- package/dist/types/restEntryPoints.d.ts +5 -0
- package/dist/types/schema.d.ts +4 -0
- package/docs/changelog.md +19 -0
- package/docs/examples.md +112 -0
- package/docs/open-api/spec.json +894 -0
- package/docs/reference/classes/DataProcessingService.md +244 -0
- package/docs/reference/classes/ExtractionRule.md +45 -0
- package/docs/reference/classes/ExtractionRuleGroup.md +37 -0
- package/docs/reference/functions/dataProcessingConvert.md +31 -0
- package/docs/reference/functions/dataProcessingExtract.md +31 -0
- package/docs/reference/functions/dataProcessingGetRuleGroup.md +31 -0
- package/docs/reference/functions/dataProcessingRemoveRuleGroup.md +31 -0
- package/docs/reference/functions/dataProcessingSetRuleGroup.md +31 -0
- package/docs/reference/functions/generateRestRoutesDataProcessing.md +25 -0
- package/docs/reference/functions/initSchema.md +9 -0
- package/docs/reference/functions/ruleGroupList.md +31 -0
- package/docs/reference/index.md +27 -0
- package/docs/reference/interfaces/IDataProcessingServiceConstructorOptions.md +25 -0
- package/docs/reference/variables/restEntryPoints.md +5 -0
- package/docs/reference/variables/tagsDataProcessing.md +5 -0
- package/locales/en.json +10 -0
- package/package.json +59 -5
package/docs/examples.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Data Processing Service Examples
|
|
2
|
+
|
|
3
|
+
These examples show how to configure the service, manage rule groups, and process bytes into structured extraction results.
|
|
4
|
+
|
|
5
|
+
## DataProcessingService
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { JsonConverterConnector } from '@3sixty/data-processing-converters';
|
|
9
|
+
import { JsonPathExtractorConnector } from '@3sixty/data-processing-extractors';
|
|
10
|
+
import {
|
|
11
|
+
DataConverterConnectorFactory,
|
|
12
|
+
DataExtractorConnectorFactory,
|
|
13
|
+
type IRuleGroup
|
|
14
|
+
} from '@3sixty/data-processing-models';
|
|
15
|
+
import { MemoryEntityStorageConnector } from '@3sixty/entity-storage-connector-memory';
|
|
16
|
+
import { EntityStorageConnectorFactory } from '@3sixty/entity-storage-models';
|
|
17
|
+
import { nameof } from '@3sixty/nameof';
|
|
18
|
+
import {
|
|
19
|
+
DataProcessingService,
|
|
20
|
+
type ExtractionRuleGroup,
|
|
21
|
+
initSchema
|
|
22
|
+
} from '@3sixty/data-processing-service';
|
|
23
|
+
|
|
24
|
+
initSchema();
|
|
25
|
+
|
|
26
|
+
const storage = new MemoryEntityStorageConnector<ExtractionRuleGroup>({
|
|
27
|
+
entitySchema: nameof<ExtractionRuleGroup>()
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
EntityStorageConnectorFactory.register('extraction-rule-group', () => storage);
|
|
31
|
+
DataExtractorConnectorFactory.register('JSONPath', () => new JsonPathExtractorConnector());
|
|
32
|
+
DataConverterConnectorFactory.register('json', () => new JsonConverterConnector());
|
|
33
|
+
|
|
34
|
+
const service = new DataProcessingService({ defaultExtractorType: 'JSONPath' });
|
|
35
|
+
|
|
36
|
+
console.log(service.className()); // dataProcessingService
|
|
37
|
+
|
|
38
|
+
const ruleGroup: IRuleGroup = {
|
|
39
|
+
id: 'customer-overview',
|
|
40
|
+
label: 'Customer Overview',
|
|
41
|
+
rules: [
|
|
42
|
+
{ source: '$.customer.name', target: 'profile.name' },
|
|
43
|
+
{ source: '$.orders[*].total', target: 'profile.orderTotals' }
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
await service.ruleGroupSet(ruleGroup);
|
|
48
|
+
|
|
49
|
+
const loaded = await service.ruleGroupGet('customer-overview');
|
|
50
|
+
console.log(loaded.label); // Customer Overview
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { ObjectHelper } from '@3sixty/core';
|
|
55
|
+
import { DataProcessingService } from '@3sixty/data-processing-service';
|
|
56
|
+
|
|
57
|
+
const service = new DataProcessingService({ defaultExtractorType: 'JSONPath' });
|
|
58
|
+
|
|
59
|
+
const payload = ObjectHelper.toBytes({
|
|
60
|
+
customer: { name: 'Asha' },
|
|
61
|
+
orders: [{ total: 19.99 }, { total: 24.5 }]
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const converted = await service.convert(payload, 'application/json');
|
|
65
|
+
console.log(converted); // { customer: { name: 'Asha' }, orders: [ { total: 19.99 }, { total: 24.5 } ] }
|
|
66
|
+
|
|
67
|
+
const extracted = await service.extract('customer-overview', payload);
|
|
68
|
+
console.log(extracted); // { profile: { name: 'Asha', orderTotals: [19.99, 24.5] } }
|
|
69
|
+
|
|
70
|
+
const queryResult = await service.query(undefined, 10);
|
|
71
|
+
console.log(queryResult.entities.length); // 1
|
|
72
|
+
console.log(queryResult.cursor); // undefined
|
|
73
|
+
|
|
74
|
+
await service.ruleGroupRemove('customer-overview');
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## ExtractionRuleGroup
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { CoerceType } from '@3sixty/core';
|
|
81
|
+
import { ExtractionRuleGroup } from '@3sixty/data-processing-service';
|
|
82
|
+
|
|
83
|
+
const group = new ExtractionRuleGroup();
|
|
84
|
+
group.id = 'analytics-group';
|
|
85
|
+
group.label = 'Analytics Group';
|
|
86
|
+
group.rules = [
|
|
87
|
+
{
|
|
88
|
+
source: '$.metrics.count',
|
|
89
|
+
target: 'stats.count',
|
|
90
|
+
coerce: CoerceType.Integer
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
console.log(group.id); // analytics-group
|
|
95
|
+
console.log(group.label); // Analytics Group
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## ExtractionRule
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { CoerceType } from '@3sixty/core';
|
|
102
|
+
import { ExtractionRule } from '@3sixty/data-processing-service';
|
|
103
|
+
|
|
104
|
+
const rule = new ExtractionRule();
|
|
105
|
+
rule.source = '$.orders[*].id';
|
|
106
|
+
rule.target = 'orderIds';
|
|
107
|
+
rule.retainPathDepth = 0;
|
|
108
|
+
rule.coerce = CoerceType.String;
|
|
109
|
+
|
|
110
|
+
console.log(rule.source); // $.orders[*].id
|
|
111
|
+
console.log(rule.target); // orderIds
|
|
112
|
+
```
|