lt-open-data-sdk 1.0.0 → 1.1.0
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 +21 -21
- package/README.md +371 -366
- package/dist/builder/FilterBuilder.d.ts.map +1 -1
- package/dist/builder/FilterBuilder.js +22 -0
- package/dist/builder/FilterBuilder.js.map +1 -1
- package/dist/builder/types.d.ts +15 -3
- package/dist/builder/types.d.ts.map +1 -1
- package/dist/cli/crawler.d.ts.map +1 -1
- package/dist/cli/crawler.js +23 -0
- package/dist/cli/crawler.js.map +1 -1
- package/dist/cli/generator.js +1 -1
- package/dist/cli/generator.js.map +1 -1
- package/dist/cli/index.js +27 -19
- package/dist/cli/index.js.map +1 -1
- package/dist/client/SpintaClient.d.ts +61 -2
- package/dist/client/SpintaClient.d.ts.map +1 -1
- package/dist/client/SpintaClient.js +92 -1
- package/dist/client/SpintaClient.js.map +1 -1
- package/dist/client/types.d.ts +26 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,366 +1,371 @@
|
|
|
1
|
-
# lt-open-data-sdk
|
|
2
|
-
|
|
3
|
-
TypeScript SDK for
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
1
|
+
# lt-open-data-sdk
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for accessing **Lithuania's Open Data Portal** ([data.gov.lt](https://data.gov.lt)).
|
|
4
|
+
|
|
5
|
+
## What is this?
|
|
6
|
+
|
|
7
|
+
Lithuania publishes thousands of government datasets through its Open Data Portal, powered by the [Spinta](https://docs.data.gov.lt/projects/atviriduomenys/latest/api/) API engine. This SDK makes it easy to:
|
|
8
|
+
|
|
9
|
+
- **Query data** with a fluent, type-safe API instead of crafting raw URL parameters
|
|
10
|
+
- **Generate TypeScript types** from live datasets for full autocomplete support
|
|
11
|
+
- **Paginate automatically** through large datasets with async iterators
|
|
12
|
+
- **Track changes** for incremental data synchronization
|
|
13
|
+
|
|
14
|
+
### Quick Links
|
|
15
|
+
|
|
16
|
+
- [📡 API Reference](#api) - Client methods and query builder
|
|
17
|
+
- [⌨️ CLI Reference](#cli) - Type generation commands
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install lt-open-data-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires Node.js ≥18.
|
|
28
|
+
|
|
29
|
+
## Quick Example
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { SpintaClient, QueryBuilder } from "lt-open-data-sdk";
|
|
33
|
+
|
|
34
|
+
const client = new SpintaClient();
|
|
35
|
+
|
|
36
|
+
// Find municipalities with code greater than 30
|
|
37
|
+
const query = new QueryBuilder()
|
|
38
|
+
.filter((f) => f.field("sav_kodas").gt(30))
|
|
39
|
+
.sort("pavadinimas")
|
|
40
|
+
.limit(10);
|
|
41
|
+
|
|
42
|
+
const municipalities = await client.getAll(
|
|
43
|
+
"datasets/gov/rc/ar/savivaldybe/Savivaldybe",
|
|
44
|
+
query
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
console.log(municipalities);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
|
|
54
|
+
The SDK provides a `SpintaClient` for making requests and a `QueryBuilder` for constructing queries.
|
|
55
|
+
|
|
56
|
+
### Client Setup
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { SpintaClient } from "lt-open-data-sdk";
|
|
60
|
+
|
|
61
|
+
const client = new SpintaClient();
|
|
62
|
+
// Connects to https://get.data.gov.lt by default
|
|
63
|
+
|
|
64
|
+
// Or specify a custom base URL:
|
|
65
|
+
const client = new SpintaClient({
|
|
66
|
+
baseUrl: "https://get-test.data.gov.lt",
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Data Retrieval
|
|
71
|
+
|
|
72
|
+
#### `getAll(model, query?)` — Fetch records
|
|
73
|
+
|
|
74
|
+
Returns an array of records from a dataset. Use with `QueryBuilder` to filter, sort, and limit.
|
|
75
|
+
|
|
76
|
+
````typescript
|
|
77
|
+
const localities = await client.getAll(
|
|
78
|
+
"datasets/gov/rc/ar/gyvenamojivietove/GyvenamojiVietove"
|
|
79
|
+
);
|
|
80
|
+
// Returns: [{ _id, _type, pavadinimas, tipas, ... }, ...]
|
|
81
|
+
|
|
82
|
+
> ⚠️ Returns one page only (default 100 items). Use `stream()` for all records.
|
|
83
|
+
|
|
84
|
+
#### `getOne(model, id)` — Fetch by ID
|
|
85
|
+
|
|
86
|
+
Returns a single record by its UUID.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const locality = await client.getOne(
|
|
90
|
+
"datasets/gov/rc/ar/gyvenamojivietove/GyvenamojiVietove",
|
|
91
|
+
"b19e801d-95d9-401f-8b00-b70b5f971f0e"
|
|
92
|
+
);
|
|
93
|
+
````
|
|
94
|
+
|
|
95
|
+
#### `getAllRaw(model, query?)` — Fetch with metadata
|
|
96
|
+
|
|
97
|
+
Returns the full API response including pagination info.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const response = await client.getAllRaw("datasets/gov/rc/ar/miestas/Miestas");
|
|
101
|
+
// Returns: { _type, _data: [...], _page: { next: "token" } }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### `count(model, query?)` — Count records
|
|
105
|
+
|
|
106
|
+
Returns the total number of records matching the query.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
const total = await client.count("datasets/gov/rc/ar/savivaldybe/Savivaldybe");
|
|
110
|
+
|
|
111
|
+
const filtered = await client.count(
|
|
112
|
+
"datasets/gov/rc/ar/savivaldybe/Savivaldybe",
|
|
113
|
+
new QueryBuilder().filter((f) => f.field("pavadinimas").contains("Vilni"))
|
|
114
|
+
);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### `stream(model, query?)` — Iterate all records
|
|
118
|
+
|
|
119
|
+
Async iterator that automatically handles pagination.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
for await (const municipality of client.stream(
|
|
123
|
+
"datasets/gov/rc/ar/savivaldybe/Savivaldybe"
|
|
124
|
+
)) {
|
|
125
|
+
console.log(municipality.pavadinimas);
|
|
126
|
+
// Automatically fetches next pages
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Discovery
|
|
131
|
+
|
|
132
|
+
#### `listNamespace(namespace)` — Browse datasets
|
|
133
|
+
|
|
134
|
+
Lists namespaces and models within a path.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const items = await client.listNamespace("datasets/gov/rc");
|
|
138
|
+
// Returns: [{ _id: "datasets/gov/rc/ar", _type: "ns" }, ...]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### `discoverModels(namespace)` — Find all models
|
|
142
|
+
|
|
143
|
+
Recursively discovers all data models in a namespace.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const models = await client.discoverModels("datasets/gov/rc/ar");
|
|
147
|
+
console.log(`Found ${models.length} models`);
|
|
148
|
+
// Returns: [{ path, title, namespace }, ...]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Changes API
|
|
152
|
+
|
|
153
|
+
Track data modifications for incremental sync.
|
|
154
|
+
|
|
155
|
+
#### `getLatestChange(model)` — Get most recent change
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
const latest = await client.getLatestChange("datasets/gov/uzt/ldv/Vieta");
|
|
159
|
+
if (latest) {
|
|
160
|
+
console.log(`Last change: ${latest._op} at ${latest._created}`);
|
|
161
|
+
console.log(`Change ID: ${latest._cid}`);
|
|
162
|
+
}
|
|
163
|
+
// Returns: ChangeEntry | null
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### `getChanges(model, sinceId?, limit?)` — Fetch changes
|
|
167
|
+
|
|
168
|
+
Returns changes since a given change ID.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const changes = await client.getChanges(
|
|
172
|
+
"datasets/gov/uzt/ldv/Vieta",
|
|
173
|
+
0, // Start from beginning
|
|
174
|
+
100 // Max 100 changes
|
|
175
|
+
);
|
|
176
|
+
// Returns: [{ _cid, _created, _op, _id, _data }, ...]
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### `streamChanges(model, sinceId?, pageSize?)` — Stream all changes
|
|
180
|
+
|
|
181
|
+
Async iterator for processing all changes with automatic pagination.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
for await (const change of client.streamChanges(
|
|
185
|
+
"datasets/gov/uzt/ldv/Vieta",
|
|
186
|
+
lastKnownCid
|
|
187
|
+
)) {
|
|
188
|
+
console.log(`${change._op}: ${change._id}`);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### QueryBuilder
|
|
195
|
+
|
|
196
|
+
Build queries with a fluent API.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { QueryBuilder } from "lt-open-data-sdk";
|
|
200
|
+
|
|
201
|
+
const query = new QueryBuilder()
|
|
202
|
+
.select("_id", "pavadinimas", "gyventoju_skaicius")
|
|
203
|
+
.filter((f) => f.field("gyventoju_skaicius").gt(10000))
|
|
204
|
+
.sort("pavadinimas")
|
|
205
|
+
.limit(50);
|
|
206
|
+
|
|
207
|
+
const data = await client.getAll("datasets/gov/example/Model", query);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Filter Operators
|
|
211
|
+
|
|
212
|
+
| Method | Query | Description |
|
|
213
|
+
| ------------------ | ------------------------- | --------------------- |
|
|
214
|
+
| `.eq(value)` | `field=value` | Equals |
|
|
215
|
+
| `.ne(value)` | `field!=value` | Not equals |
|
|
216
|
+
| `.lt(value)` | `field<value` | Less than |
|
|
217
|
+
| `.le(value)` | `field<=value` | Less than or equal |
|
|
218
|
+
| `.gt(value)` | `field>value` | Greater than |
|
|
219
|
+
| `.ge(value)` | `field>=value` | Greater than or equal |
|
|
220
|
+
| `.contains(str)` | `field.contains("str")` | Contains substring |
|
|
221
|
+
| `.startswith(str)` | `field.startswith("str")` | Starts with |
|
|
222
|
+
| `.endswith(str)` | `field.endswith("str")` | Ends with ⚠️ |
|
|
223
|
+
| `.in([...])` | `field.in(a,b,c)` | Value in list ⚠️ |
|
|
224
|
+
| `.notin([...])` | `field.notin(a,b,c)` | Value not in list ⚠️ |
|
|
225
|
+
|
|
226
|
+
> ⚠️ `endswith`, `in`, `notin` are in the Spinta spec but not yet supported by the live API.
|
|
227
|
+
|
|
228
|
+
#### Combining Filters
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
// AND - both conditions must match
|
|
232
|
+
.filter(f => f.field('a').gt(10).and(f.field('b').lt(100)))
|
|
233
|
+
// Output: a>10&b<100
|
|
234
|
+
|
|
235
|
+
// OR - either condition matches
|
|
236
|
+
.filter(f => f.field('status').eq('active').or(f.field('status').eq('pending')))
|
|
237
|
+
// Output: status="active"|status="pending"
|
|
238
|
+
|
|
239
|
+
// Complex - parentheses added automatically
|
|
240
|
+
.filter(f => f.field('a').gt(10).and(
|
|
241
|
+
f.field('b').eq(1).or(f.field('b').eq(2))
|
|
242
|
+
))
|
|
243
|
+
// Output: a>10&(b=1|b=2)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
#### Sorting
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
new QueryBuilder()
|
|
250
|
+
.sort("name") // Ascending
|
|
251
|
+
.sortDesc("created_at"); // Descending
|
|
252
|
+
// Output: ?sort(name,-created_at)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## CLI
|
|
258
|
+
|
|
259
|
+
Generate TypeScript interfaces from live API data.
|
|
260
|
+
|
|
261
|
+
### Basic Usage
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Generate types for a dataset (prints to stdout)
|
|
265
|
+
npx lt-gen datasets/gov/rc/ar/savivaldybe
|
|
266
|
+
|
|
267
|
+
# Save to a file
|
|
268
|
+
npx lt-gen datasets/gov/rc/ar/savivaldybe -o ./types/savivaldybe.d.ts
|
|
269
|
+
|
|
270
|
+
# Use a different API endpoint
|
|
271
|
+
npx lt-gen datasets/gov/rc/ar/savivaldybe --base-url https://get-test.data.gov.lt
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Options
|
|
275
|
+
|
|
276
|
+
| Option | Description |
|
|
277
|
+
| --------------------- | -------------------- |
|
|
278
|
+
| `-o, --output <file>` | Write output to file |
|
|
279
|
+
| `--base-url <url>` | Custom API base URL |
|
|
280
|
+
| `-h, --help` | Show help |
|
|
281
|
+
|
|
282
|
+
### Generated Output
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
// Generated from datasets/gov/rc/ar/savivaldybe/Savivaldybe
|
|
286
|
+
|
|
287
|
+
export interface GovRcArSavivaldybe_Savivaldybe {
|
|
288
|
+
_id: string;
|
|
289
|
+
_type: string;
|
|
290
|
+
_revision?: string;
|
|
291
|
+
sav_kodas?: number;
|
|
292
|
+
pavadinimas?: string;
|
|
293
|
+
apskritis?: string | { _id: string };
|
|
294
|
+
sav_nuo?: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface ModelMap {
|
|
298
|
+
"datasets/gov/rc/ar/savivaldybe/Savivaldybe": GovRcArSavivaldybe_Savivaldybe;
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Using Generated Types
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { SpintaClient } from "lt-open-data-sdk";
|
|
306
|
+
import type { GovRcArSavivaldybe_Savivaldybe } from "./types/savivaldybe";
|
|
307
|
+
|
|
308
|
+
const client = new SpintaClient();
|
|
309
|
+
|
|
310
|
+
// Full autocomplete on fields!
|
|
311
|
+
const data = await client.getAll<GovRcArSavivaldybe_Savivaldybe>(
|
|
312
|
+
"datasets/gov/rc/ar/savivaldybe/Savivaldybe"
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
console.log(data[0].pavadinimas); // TypeScript knows this is string
|
|
316
|
+
console.log(data[0].sav_kodas); // TypeScript knows this is number
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## Error Handling
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import {
|
|
325
|
+
SpintaError,
|
|
326
|
+
NotFoundError,
|
|
327
|
+
AuthenticationError,
|
|
328
|
+
ValidationError,
|
|
329
|
+
} from "lt-open-data-sdk";
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
const data = await client.getOne("datasets/example", "invalid-id");
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (error instanceof NotFoundError) {
|
|
335
|
+
console.log("Record not found");
|
|
336
|
+
} else if (error instanceof ValidationError) {
|
|
337
|
+
console.log("Invalid query:", error.message);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## Authentication
|
|
345
|
+
|
|
346
|
+
For write operations or private datasets, provide OAuth credentials:
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
const client = new SpintaClient({
|
|
350
|
+
clientId: "your-client-id",
|
|
351
|
+
clientSecret: "your-client-secret",
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
The SDK handles token caching and automatic refresh.
|
|
356
|
+
|
|
357
|
+
> ⚠️ Authentication is implemented but untested against the live auth server.
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Known Limitations
|
|
362
|
+
|
|
363
|
+
- **Boolean filtering** may not work on some datasets due to inconsistent data formats in the source
|
|
364
|
+
- **`in()`, `notin()`, `endswith()`** operators are implemented but not yet supported by the live API
|
|
365
|
+
- **Type inference** is based on data sampling, not schema (schema endpoints require auth)
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## License
|
|
370
|
+
|
|
371
|
+
MIT
|