meadow-integration 1.0.1 → 1.0.4
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/CONTRIBUTING.md +50 -0
- package/README.md +223 -7
- package/docs/README.md +107 -7
- package/docs/_sidebar.md +38 -0
- package/docs/_topbar.md +7 -0
- package/docs/cli-reference.md +242 -0
- package/docs/comprehensions.md +98 -0
- package/docs/cover.md +11 -0
- package/docs/css/docuserve.css +73 -0
- package/docs/examples-walkthrough.md +138 -0
- package/docs/index.html +37 -20
- package/docs/integration-adapter.md +109 -0
- package/docs/mapping-files.md +140 -0
- package/docs/programmatic-api.md +173 -0
- package/docs/rest-api-reference.md +731 -0
- package/docs/retold-catalog.json +153 -0
- package/docs/retold-keyword-index.json +4828 -0
- package/examples/Example-001-CSV-Check.sh +29 -0
- package/examples/Example-002-CSV-Transform-Implicit.sh +31 -0
- package/examples/Example-003-CSV-Transform-CLI-Options.sh +39 -0
- package/examples/Example-004-CSV-Transform-Mapping-File.sh +41 -0
- package/examples/Example-005-Multi-Entity-Bookstore.sh +60 -0
- package/examples/Example-006-Multi-CSV-Intersect.sh +74 -0
- package/examples/Example-007-Comprehension-To-Array.sh +41 -0
- package/examples/Example-008-Comprehension-To-CSV.sh +51 -0
- package/examples/Example-009-JSON-Array-Transform.sh +46 -0
- package/examples/Example-010-Programmatic-API.js +138 -0
- package/examples/README.md +44 -0
- package/examples/output/.gitignore +2 -0
- package/package.json +7 -4
- package/source/Meadow-Integration.js +3 -1
- package/source/cli/Meadow-Integration-CLI-Program.js +4 -1
- package/source/cli/commands/Meadow-Integration-Command-ObjectArrayToCSV.js +49 -32
- package/source/cli/commands/Meadow-Integration-Command-Serve.js +51 -0
- package/source/restserver/Meadow-Integration-Server-Endpoints.js +83 -0
- package/source/restserver/Meadow-Integration-Server.js +86 -0
- package/source/restserver/endpoints/Endpoint-CSVCheck.js +91 -0
- package/source/restserver/endpoints/Endpoint-CSVTransform.js +189 -0
- package/source/restserver/endpoints/Endpoint-ComprehensionArray.js +121 -0
- package/source/restserver/endpoints/Endpoint-ComprehensionIntersect.js +166 -0
- package/source/restserver/endpoints/Endpoint-ComprehensionPush.js +209 -0
- package/source/restserver/endpoints/Endpoint-EntityFromTabularFolder.js +252 -0
- package/source/restserver/endpoints/Endpoint-JSONArrayTransform.js +238 -0
- package/source/restserver/endpoints/Endpoint-ObjectArrayToCSV.js +231 -0
- package/source/restserver/endpoints/Endpoint-TSVCheck.js +93 -0
- package/source/restserver/endpoints/Endpoint-TSVTransform.js +191 -0
- package/test/Meadow-Integration-Server_test.js +1170 -0
- package/test/data/test-comprehension-secondary.json +8 -0
- package/test/data/test-comprehension.json +8 -0
- package/test/data/test-small.csv +6 -0
- package/test/data/test-small.json +7 -0
- package/test/data/test-small.tsv +6 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Programmatic API
|
|
2
|
+
|
|
3
|
+
Meadow Integration services can be used directly in your Node.js code without the CLI. This is useful when integrating data transformation into larger applications or custom workflows.
|
|
4
|
+
|
|
5
|
+
## Services Overview
|
|
6
|
+
|
|
7
|
+
| Service | Purpose |
|
|
8
|
+
|---------|---------|
|
|
9
|
+
| `MeadowIntegrationTabularCheck` | Collect statistics on tabular data |
|
|
10
|
+
| `MeadowIntegrationTabularTransform` | Transform records into comprehensions |
|
|
11
|
+
| `MeadowGUIDMap` | Track bidirectional GUID-to-ID mappings |
|
|
12
|
+
| `IntegrationAdapter` | Marshal and push records to Meadow REST APIs |
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
|
|
16
|
+
All services are registered with a Pict/Fable instance. Use `pict` (not `fable`) when you need template parsing:
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
const libPict = require('pict');
|
|
20
|
+
|
|
21
|
+
let _Pict = new libPict({ LogLevel: 3 });
|
|
22
|
+
|
|
23
|
+
// CSV parsing
|
|
24
|
+
_Pict.instantiateServiceProvider('CSVParser');
|
|
25
|
+
|
|
26
|
+
// Statistics service
|
|
27
|
+
const libTabularCheck = require('meadow-integration/source/services/tabular/Service-TabularCheck.js');
|
|
28
|
+
_Pict.addAndInstantiateServiceType('MeadowIntegrationTabularCheck', libTabularCheck);
|
|
29
|
+
|
|
30
|
+
// Transform service
|
|
31
|
+
const libTabularTransform = require('meadow-integration/source/services/tabular/Service-TabularTransform.js');
|
|
32
|
+
_Pict.addAndInstantiateServiceType('MeadowIntegrationTabularTransform', libTabularTransform);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## TabularCheck: Collecting Statistics
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// Create a statistics container
|
|
39
|
+
let tmpStats = _Pict.MeadowIntegrationTabularCheck.newStatisticsObject('MyDataSet');
|
|
40
|
+
|
|
41
|
+
// Feed records through
|
|
42
|
+
for (let tmpRecord of myRecords)
|
|
43
|
+
{
|
|
44
|
+
_Pict.MeadowIntegrationTabularCheck.collectStatistics(tmpRecord, tmpStats);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Inspect results
|
|
48
|
+
console.log(`${tmpStats.RowCount} rows, ${tmpStats.ColumnCount} columns`);
|
|
49
|
+
console.log('Headers:', tmpStats.Headers);
|
|
50
|
+
|
|
51
|
+
// Per-column statistics
|
|
52
|
+
for (let tmpKey of Object.keys(tmpStats.ColumnStatistics))
|
|
53
|
+
{
|
|
54
|
+
let tmpCol = tmpStats.ColumnStatistics[tmpKey];
|
|
55
|
+
console.log(` ${tmpKey}: ${tmpCol.Count} values, ${tmpCol.EmptyCount} empty`);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Statistics Object Shape
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
{
|
|
63
|
+
DataSet: 'MyDataSet',
|
|
64
|
+
RowCount: 1000,
|
|
65
|
+
ColumnCount: 5,
|
|
66
|
+
Headers: ['id', 'name', 'email', 'age', 'city'],
|
|
67
|
+
FirstRow: { id: '1', name: 'Alice', ... },
|
|
68
|
+
LastRow: { id: '1000', name: 'Zach', ... },
|
|
69
|
+
ColumnStatistics: {
|
|
70
|
+
'id': { Count: 1000, EmptyCount: 0, NumericCount: 1000, FirstValue: '1', LastValue: '1000' },
|
|
71
|
+
'name': { Count: 1000, EmptyCount: 5, NumericCount: 0, FirstValue: 'Alice', LastValue: 'Zach' }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## TabularTransform: Building Comprehensions
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// Create a mapping outcome (holds state for the transform)
|
|
80
|
+
let tmpOutcome = _Pict.MeadowIntegrationTabularTransform.newMappingOutcomeObject();
|
|
81
|
+
|
|
82
|
+
// Set explicit configuration (equivalent to a mapping file)
|
|
83
|
+
tmpOutcome.ExplicitConfiguration = {
|
|
84
|
+
Entity: 'User',
|
|
85
|
+
GUIDTemplate: 'User_{~D:Record.id~}',
|
|
86
|
+
Mappings: {
|
|
87
|
+
DisplayName: '{~D:Record.name~}',
|
|
88
|
+
Email: '{~D:Record.email~}'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Auto-detect implicit configuration from first record
|
|
93
|
+
tmpOutcome.ImplicitConfiguration =
|
|
94
|
+
_Pict.MeadowIntegrationTabularTransform.generateMappingConfigurationPrototype(
|
|
95
|
+
'users.csv', myRecords[0]);
|
|
96
|
+
|
|
97
|
+
// Merge configuration layers
|
|
98
|
+
tmpOutcome.Configuration = Object.assign({},
|
|
99
|
+
tmpOutcome.ImplicitConfiguration,
|
|
100
|
+
tmpOutcome.ExplicitConfiguration);
|
|
101
|
+
tmpOutcome.Configuration.GUIDName = `GUID${tmpOutcome.Configuration.Entity}`;
|
|
102
|
+
tmpOutcome.Comprehension[tmpOutcome.Configuration.Entity] = {};
|
|
103
|
+
|
|
104
|
+
// Transform each record
|
|
105
|
+
for (let tmpRecord of myRecords)
|
|
106
|
+
{
|
|
107
|
+
_Pict.MeadowIntegrationTabularTransform.addRecordToComprehension(
|
|
108
|
+
tmpRecord, tmpOutcome);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Access results
|
|
112
|
+
let tmpUsers = tmpOutcome.Comprehension.User;
|
|
113
|
+
console.log(`Created ${Object.keys(tmpUsers).length} user records`);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## GUIDMap: Tracking External System IDs
|
|
117
|
+
|
|
118
|
+
The GUIDMap service maintains bidirectional mappings between external system identifiers and Meadow internal IDs.
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
const libGUIDMap = require('meadow-integration/source/Meadow-Service-Integration-GUIDMap.js');
|
|
122
|
+
_Pict.addAndInstantiateServiceType('MeadowGUIDMap', libGUIDMap);
|
|
123
|
+
|
|
124
|
+
// Map Meadow GUIDs to numeric IDs
|
|
125
|
+
_Pict.MeadowGUIDMap.mapGUIDToID('Book', 'Book_1', 101);
|
|
126
|
+
|
|
127
|
+
// Look up in both directions
|
|
128
|
+
_Pict.MeadowGUIDMap.getIDFromGUID('Book', 'Book_1'); // 101
|
|
129
|
+
_Pict.MeadowGUIDMap.getGUIDFromID('Book', 101); // 'Book_1'
|
|
130
|
+
|
|
131
|
+
// Track external system GUIDs
|
|
132
|
+
_Pict.MeadowGUIDMap.mapExternalGUIDtoMeadowGUID('Book', 'LEGACY-123', 'Book_1');
|
|
133
|
+
_Pict.MeadowGUIDMap.getMeadowGUIDFromExternalGUID('Book', 'LEGACY-123'); // 'Book_1'
|
|
134
|
+
_Pict.MeadowGUIDMap.getMeadowIDFromExternalGUID('Book', 'LEGACY-123'); // 101
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Integration Adapter: Pushing to Meadow APIs
|
|
138
|
+
|
|
139
|
+
The Integration Adapter marshals comprehension records into Meadow entity format and pushes them to a REST API.
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
const libAdapter = require('meadow-integration/source/Meadow-Service-Integration-Adapter.js');
|
|
143
|
+
|
|
144
|
+
_Pict.addServiceType('IntegrationAdapter', libAdapter);
|
|
145
|
+
let tmpAdapter = _Pict.instantiateServiceProvider('IntegrationAdapter',
|
|
146
|
+
{ Entity: 'Book', ApiURLPrefix: '/1.0/' }, 'Book');
|
|
147
|
+
|
|
148
|
+
// Add source records (must have a GUID{Entity} field)
|
|
149
|
+
tmpAdapter.addSourceRecord({ GUIDBook: 'Book_1', Title: 'Example', ISBN: '1234' });
|
|
150
|
+
tmpAdapter.addSourceRecord({ GUIDBook: 'Book_2', Title: 'Another', ISBN: '5678' });
|
|
151
|
+
|
|
152
|
+
// Run the full integration pipeline
|
|
153
|
+
tmpAdapter.integrateRecords(
|
|
154
|
+
(pError) =>
|
|
155
|
+
{
|
|
156
|
+
if (pError) console.error('Integration failed:', pError);
|
|
157
|
+
else console.log('Records pushed successfully');
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Adapter Options
|
|
162
|
+
|
|
163
|
+
| Option | Default | Description |
|
|
164
|
+
|--------|---------|-------------|
|
|
165
|
+
| `Entity` | `'DefaultEntity'` | Entity name |
|
|
166
|
+
| `PerformUpserts` | `true` | Enable upsert operations |
|
|
167
|
+
| `PerformDeletes` | `true` | Enable delete operations |
|
|
168
|
+
| `RecordPushRetryThreshold` | `5` | Max retries per record |
|
|
169
|
+
| `RecordThresholdForBulkUpsert` | `1000` | Records threshold for bulk mode |
|
|
170
|
+
| `BulkUpsertBatchSize` | `100` | Batch size for bulk upserts |
|
|
171
|
+
| `ApiURLPrefix` | `'/1.0/'` | API URL prefix |
|
|
172
|
+
|
|
173
|
+
See `examples/Example-010-Programmatic-API.js` for a complete runnable example.
|