@dataworks-technology/data 0.2.0 → 0.3.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/README.md +88 -3
- package/dist/index.cjs +48922 -222
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -36
- package/dist/index.d.ts +92 -36
- package/dist/index.js +48946 -212
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +72 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +42 -0
- package/dist/schema.js.map +1 -0
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -9,12 +9,14 @@ Official SDK for the Dataworks Data Engine — authenticate, ingest live athlete
|
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
- **
|
|
12
|
+
- **Self-contained bundle** — Apollo Client and AppSync subscription link are bundled in; consumers install nothing extra
|
|
13
13
|
- **Dual format** — ESM and CommonJS bundles included
|
|
14
14
|
- **TypeScript-first** — complete type declarations shipped with the package
|
|
15
15
|
- **Built-in validation** — metrics are validated before ingestion
|
|
16
|
-
- **Real-time subscriptions** — WebSocket-based live data streaming
|
|
17
|
-
- **
|
|
16
|
+
- **Real-time subscriptions** — WebSocket-based live data streaming via AppSync Events API
|
|
17
|
+
- **Typed GraphQL API client** — execute any query, mutation, or subscription against the Data Engine schema
|
|
18
|
+
- **Schema type exports** — full codegen types available via `@dataworks-technology/data/schema`
|
|
19
|
+
- **Cognito authentication** — secure login with automatic token refresh
|
|
18
20
|
|
|
19
21
|
## Prerequisites
|
|
20
22
|
|
|
@@ -27,6 +29,7 @@ You need a Dataworks developer account. Contact your Dataworks administrator to
|
|
|
27
29
|
| `ingestUrl` | API Gateway endpoint for metric ingestion |
|
|
28
30
|
| `errorUrl` | API Gateway endpoint for error reporting |
|
|
29
31
|
| `realtimeUrl` | AppSync Events API endpoint for subscriptions |
|
|
32
|
+
| `graphqlUrl` (optional) | AppSync GraphQL HTTP endpoint |
|
|
30
33
|
| Username + password | Your developer login credentials |
|
|
31
34
|
| `apiKey` (optional) | AppSync Events API key for subscription-only access |
|
|
32
35
|
|
|
@@ -93,6 +96,7 @@ const dataworks = new DataClient({
|
|
|
93
96
|
ingestUrl: "https://ingest.dataworks.live",
|
|
94
97
|
errorUrl: "https://errors.dataworks.live",
|
|
95
98
|
realtimeUrl: "https://realtime.dataworks.live",
|
|
99
|
+
graphqlUrl: "https://api-id.appsync-api.eu-west-1.amazonaws.com/graphql",
|
|
96
100
|
});
|
|
97
101
|
```
|
|
98
102
|
|
|
@@ -239,6 +243,87 @@ interface SubscriptionError {
|
|
|
239
243
|
| `RECONNECT_FAILED` | Token refresh failed after auth expiry |
|
|
240
244
|
| `UNKNOWN` | Unexpected error |
|
|
241
245
|
|
|
246
|
+
### `dataworks.query(query, variables?, options?)`
|
|
247
|
+
|
|
248
|
+
Execute a typed GraphQL query against the Data AppSync schema.
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
const result = await dataworks.query<{
|
|
252
|
+
listEvents: { items: Array<{ id: number; name: string }> };
|
|
253
|
+
}>(
|
|
254
|
+
`query ListEvents($tenant: String!) {
|
|
255
|
+
listEvents(tenant: $tenant) {
|
|
256
|
+
items { id name }
|
|
257
|
+
}
|
|
258
|
+
}`,
|
|
259
|
+
{ tenant: "demo-tenant" },
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
console.log(result.listEvents.items);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `dataworks.mutate(mutation, variables?, options?)`
|
|
266
|
+
|
|
267
|
+
Execute a typed GraphQL mutation.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const result = await dataworks.mutate<{
|
|
271
|
+
startEvent: { id: number; name: string };
|
|
272
|
+
}>(
|
|
273
|
+
`mutation StartEvent($id: Int!, $tenant: String!) {
|
|
274
|
+
startEvent(id: $id, tenant: $tenant) { id name }
|
|
275
|
+
}`,
|
|
276
|
+
{ id: 42, tenant: "demo-tenant" },
|
|
277
|
+
);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### `dataworks.subscribeGraphQL(subscription, onEvent, onError?, variables?)`
|
|
281
|
+
|
|
282
|
+
Subscribe to schema-level GraphQL subscriptions. Backed by Apollo Client + `aws-appsync-subscription-link` internally — AppSync Cognito auth and WebSocket protocol are handled automatically.
|
|
283
|
+
|
|
284
|
+
The Apollo client is lazily created on the first `subscribeGraphQL()` call and reused for all subsequent subscriptions on the same `DataClient` instance.
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import type { Dataset, Maybe } from "@dataworks-technology/data/schema";
|
|
288
|
+
|
|
289
|
+
const sub = dataworks.subscribeGraphQL<{ onUpdateDataset: Maybe<Dataset> }>(
|
|
290
|
+
`subscription OnUpdateDataset {
|
|
291
|
+
onUpdateDataset {
|
|
292
|
+
id publicId clientId name
|
|
293
|
+
eventId eventName eventLocation eventType eventStartsAt
|
|
294
|
+
createdAt updatedAt
|
|
295
|
+
}
|
|
296
|
+
}`,
|
|
297
|
+
(payload) => {
|
|
298
|
+
console.log(payload.onUpdateDataset);
|
|
299
|
+
},
|
|
300
|
+
(error) => {
|
|
301
|
+
console.error(error.message);
|
|
302
|
+
},
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
sub.close();
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Schema Types
|
|
309
|
+
|
|
310
|
+
All Data Engine GraphQL types are exported from the `schema` subpath. Use these instead of hand-rolling your own:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
import type {
|
|
314
|
+
Dataset,
|
|
315
|
+
DatasetConnection,
|
|
316
|
+
Maybe,
|
|
317
|
+
CreateDatasetInput,
|
|
318
|
+
UpdateDatasetInput,
|
|
319
|
+
DatasetConditionInput,
|
|
320
|
+
Athlete,
|
|
321
|
+
Participant,
|
|
322
|
+
Datasource,
|
|
323
|
+
// ... all entity, connection, filter, and input types
|
|
324
|
+
} from "@dataworks-technology/data/schema";
|
|
325
|
+
```
|
|
326
|
+
|
|
242
327
|
### `dataworks.reportError(error)`
|
|
243
328
|
|
|
244
329
|
Report an error to the Data Engine for monitoring and alerting.
|