slimlake 0.0.0-stage → 0.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 -0
- package/README.md +257 -2
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +238 -0
- package/dist/cli.js.map +1 -0
- package/dist/core.d.ts +93 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +7 -0
- package/dist/core.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/lineage.d.ts +105 -0
- package/dist/lineage.d.ts.map +1 -0
- package/dist/lineage.js +126 -0
- package/dist/lineage.js.map +1 -0
- package/dist/publish.d.ts +47 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +129 -0
- package/dist/publish.js.map +1 -0
- package/dist/runtime.d.ts +40 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +232 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +69 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +231 -0
- package/dist/schema.js.map +1 -0
- package/dist/store.d.ts +52 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +248 -0
- package/dist/store.js.map +1 -0
- package/dist/uri.d.ts +26 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +49 -0
- package/dist/uri.js.map +1 -0
- package/dist/validate.d.ts +13 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +37 -0
- package/dist/validate.js.map +1 -0
- package/dist/workers/event.d.ts +29 -0
- package/dist/workers/event.d.ts.map +1 -0
- package/dist/workers/event.js +34 -0
- package/dist/workers/event.js.map +1 -0
- package/dist/workers/runner.d.ts +25 -0
- package/dist/workers/runner.d.ts.map +1 -0
- package/dist/workers/runner.js +83 -0
- package/dist/workers/runner.js.map +1 -0
- package/dist/workers/web.d.ts +23 -0
- package/dist/workers/web.d.ts.map +1 -0
- package/dist/workers/web.js +79 -0
- package/dist/workers/web.js.map +1 -0
- package/package.json +43 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 slimlake contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,258 @@
|
|
|
1
|
-
#
|
|
1
|
+
# slimlake
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lean, opinionated framework for lake pipelines. Slim to use (a handful of
|
|
4
|
+
types), real machinery underneath:
|
|
5
|
+
|
|
6
|
+
- **typed assets** — every input and output carries a schema;
|
|
7
|
+
- **schema validation** — rows are checked before they enter and before they
|
|
8
|
+
leave a transformation;
|
|
9
|
+
- **additive-only evolution** — the only legal schema change is adding a
|
|
10
|
+
nullable column;
|
|
11
|
+
- **materialization records** — rows, bytes, digest, schema version, partition;
|
|
12
|
+
- **run / parent-run ids** — every execution and event is attributable;
|
|
13
|
+
- **OpenLineage lineage** — spec `2-0-2` `RunEvent` JSON to S3;
|
|
14
|
+
- **idempotent S3 publish** — the key is a pure function of coordinates,
|
|
15
|
+
partition and content digest, so a re-run is a no-op;
|
|
16
|
+
- **retry** — fixed or exponential backoff around the transformation body;
|
|
17
|
+
- **data-quality assertions** — `ctx.assert` throws and stops the publish.
|
|
18
|
+
|
|
19
|
+
Workers are AWS Lambda **Event Functions** (W1) and **Web Functions**; the same
|
|
20
|
+
transformation code runs in both.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install slimlake
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Node.js 20+.
|
|
29
|
+
|
|
30
|
+
## Worked example
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createRunContext, createStore, NoopTransport, runDag, schema } from 'slimlake';
|
|
34
|
+
import type { Asset, Dag, Transformation } from 'slimlake';
|
|
35
|
+
|
|
36
|
+
const raw = schema({
|
|
37
|
+
version: '1',
|
|
38
|
+
columns: [
|
|
39
|
+
{ name: 'id', type: 'number' },
|
|
40
|
+
{ name: 'amount', type: 'number' },
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Adding a nullable column is additive; removing or retyping is rejected.
|
|
45
|
+
const curated = schema({
|
|
46
|
+
version: '2',
|
|
47
|
+
columns: [
|
|
48
|
+
{ name: 'id', type: 'number' },
|
|
49
|
+
{ name: 'amount', type: 'number' },
|
|
50
|
+
{ name: 'currency', type: 'string', nullable: true },
|
|
51
|
+
// Partition columns live in the rows; the framework reads them to build
|
|
52
|
+
// the object key (`.../dt=2026-12-06/part-<digest>.jsonl`).
|
|
53
|
+
{ name: 'dt', type: 'string', nullable: true },
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
type RawRow = { id: number; amount: number };
|
|
58
|
+
type CuratedRow = RawRow & { currency: string; dt: string };
|
|
59
|
+
|
|
60
|
+
const rawAsset: Asset = {
|
|
61
|
+
id: 'raw',
|
|
62
|
+
uri: 's3://my-bucket/lake/raw',
|
|
63
|
+
format: 'jsonl',
|
|
64
|
+
location: 'lake',
|
|
65
|
+
schema: raw,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const curatedAsset: Asset = {
|
|
69
|
+
id: 'curated',
|
|
70
|
+
uri: 's3://my-bucket/lake/curated',
|
|
71
|
+
format: 'jsonl',
|
|
72
|
+
location: 'lake',
|
|
73
|
+
partition: ['dt'],
|
|
74
|
+
schema: curated,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const enrich: Transformation<RawRow[], CuratedRow[]> = {
|
|
78
|
+
id: 'enrich',
|
|
79
|
+
inputs: [rawAsset],
|
|
80
|
+
output: curatedAsset,
|
|
81
|
+
retry: { attempts: 3, backoff: 'exp', delayMs: 100 },
|
|
82
|
+
async execute(rows, ctx) {
|
|
83
|
+
ctx.assert({ id: 'non-empty', ok: rows.length > 0, detail: 'no rows' });
|
|
84
|
+
return rows.map((row) => ({ ...row, currency: 'EUR', dt: '2026-12-06' }));
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const dag: Dag = { id: 'enrich-dag', steps: [enrich] };
|
|
89
|
+
|
|
90
|
+
const store = createStore(); // in-memory; pass { dynamoTable: 'slimlake-runs' } in prod
|
|
91
|
+
const runId = 'run-2026-12-06-0001';
|
|
92
|
+
const startedAt = new Date().toISOString();
|
|
93
|
+
await store.recordRun({ runId, jobId: dag.id, status: 'RUNNING', startedAt, attempt: 1 });
|
|
94
|
+
|
|
95
|
+
const ctx = createRunContext({
|
|
96
|
+
runId,
|
|
97
|
+
attempt: 1,
|
|
98
|
+
startedAt,
|
|
99
|
+
transport: new NoopTransport(), // or new S3LineageTransport({ bucket })
|
|
100
|
+
recordMaterialization: (m) => store.recordMaterialization(m),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const result = await runDag(dag, [{ id: 1, amount: 10 }], ctx);
|
|
104
|
+
await store.recordRun({ runId, jobId: dag.id, status: 'COMPLETE', startedAt, attempt: 1 });
|
|
105
|
+
console.log(result); // [{ id: 1, amount: 10, currency: 'EUR', dt: '2026-12-06' }]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
With no `publish` dependency injected, `runDag` publishes through
|
|
109
|
+
`@aws-sdk/client-s3` and therefore needs AWS credentials and a real `s3://`
|
|
110
|
+
URI. Tests and local scripts inject a fake port (see
|
|
111
|
+
[Testing](#testing-with-fakes)).
|
|
112
|
+
|
|
113
|
+
## Public API
|
|
114
|
+
|
|
115
|
+
### Types (`core.ts`)
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
interface Column { name: string; type: string; nullable: boolean; description?: string }
|
|
119
|
+
interface Schema { version: string; columns: Column[]; compatibility: 'additive' }
|
|
120
|
+
interface Asset<T = unknown> {
|
|
121
|
+
id: string; uri: string; schema?: Schema;
|
|
122
|
+
format: 'jsonl' | 'parquet' | 'iceberg';
|
|
123
|
+
partition?: string[]; location: 'lake' | 'staging' | 'external';
|
|
124
|
+
}
|
|
125
|
+
interface Materialization {
|
|
126
|
+
runId: string; assetId: string; schemaVersion: string; partition?: string;
|
|
127
|
+
rows: number; bytes: number; digest: string; publishedAt: string;
|
|
128
|
+
}
|
|
129
|
+
interface RunContext {
|
|
130
|
+
runId: string; parentRunId?: string; attempt: number; startedAt: string;
|
|
131
|
+
emit(event: RunEventInput): Promise<void>;
|
|
132
|
+
recordMaterialization(m: Materialization): Promise<void>;
|
|
133
|
+
assert(check: DataQualityCheck): void; // throws AssertionError on failure
|
|
134
|
+
}
|
|
135
|
+
interface RetryPolicy { attempts: number; backoff: 'fixed' | 'exp'; delayMs?: number }
|
|
136
|
+
interface Transformation<I = unknown, O = unknown> {
|
|
137
|
+
id: string; inputs: Asset[]; output: Asset<O>;
|
|
138
|
+
worker?: 'event' | 'web'; retry?: RetryPolicy;
|
|
139
|
+
execute(input: I, ctx: RunContext): Promise<O>;
|
|
140
|
+
}
|
|
141
|
+
interface Dag { id: string; steps: Transformation[] }
|
|
142
|
+
interface DataQualityCheck { id: string; ok: boolean; detail?: string }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Schemas (`schema.ts`)
|
|
146
|
+
|
|
147
|
+
- `schema({ version, columns })` — DSL; `nullable` defaults to `false`.
|
|
148
|
+
- `validateRows(schema, rows)` — returns `{ ok: true }` or
|
|
149
|
+
`{ ok: false, errors }`. Unknown columns, missing/null values in
|
|
150
|
+
non-nullable columns and type mismatches are all reported.
|
|
151
|
+
- `checkCompatibility(prev, next)` — additive-only: adding a nullable column
|
|
152
|
+
is `ok`; remove, rename, type change and nullability change are errors.
|
|
153
|
+
- `toGlueDdl(asset)` — `CREATE EXTERNAL TABLE` DDL.
|
|
154
|
+
- `toParquetSchema(asset)` — `{ type: 'struct', fields: [...] }`.
|
|
155
|
+
|
|
156
|
+
### Publishing (`publish.ts`)
|
|
157
|
+
|
|
158
|
+
`publishRows(asset, rows, ctx, deps?)` writes to the asset URI and returns a
|
|
159
|
+
`Materialization`. The key is deterministic:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
<s3 prefix>/<partition values>/part-<sha256>.jsonl
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The digest is the sha256 of the canonical rows (object keys sorted). A
|
|
166
|
+
repeat publish of the same rows finds the existing object with `HeadObject` and
|
|
167
|
+
skips the write.
|
|
168
|
+
|
|
169
|
+
### Lineage (`lineage.ts`)
|
|
170
|
+
|
|
171
|
+
- `buildRunEvent(input)` — a spec `2-0-2` `RunEvent` object:
|
|
172
|
+
`eventTime`, `producer`, `schemaURL`, `run.runId`, `run.facets.parent`
|
|
173
|
+
(when `parentRunId` is set), `job.namespace/name`, `job.facets.jobType`,
|
|
174
|
+
and `inputs`/`outputs` datasets (`namespace: s3://<bucket>`, `name: <prefix>`).
|
|
175
|
+
- `S3LineageTransport` — writes
|
|
176
|
+
`s3://<bucket>/lake/lineage/dt=<date>/<runId>-<eventType>.json`.
|
|
177
|
+
- `NoopTransport`, `CompositeTransport`.
|
|
178
|
+
|
|
179
|
+
### Store (`store.ts`)
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const store = createStore(); // in-memory
|
|
183
|
+
const store = createStore({ dynamoTable: 'slimlake-runs' }); // DynamoDB
|
|
184
|
+
const store = createStore({ s3Bucket: 'my-bucket' }); // + S3 lineage
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`recordRun`, `recordMaterialization`, `listRuns({ status?, jobId?, limit? })`,
|
|
188
|
+
`getRun(runId)`. The DynamoDB layout is `pk RUN#<runId>` / `sk META` for run
|
|
189
|
+
metadata and `sk MAT#<assetId>#<partition>` for materializations, with
|
|
190
|
+
`GSI1 JOB#<jobId>` and `GSI2 STATUS#<status>` (both sorted by `startedAt`).
|
|
191
|
+
|
|
192
|
+
### Runtime (`runtime.ts`)
|
|
193
|
+
|
|
194
|
+
- `runTransformation(t, input, ctx, deps?)` — validate input → execute with
|
|
195
|
+
retry → validate output → publish → record materialization → emit
|
|
196
|
+
`COMPLETE`/`FAIL`.
|
|
197
|
+
- `runDag(dag, input, ctx, deps?)` — topological order over `dag.steps`,
|
|
198
|
+
feeding outputs to downstream inputs.
|
|
199
|
+
- `createRunContext(...)` — build a `RunContext`.
|
|
200
|
+
- `topologicalOrder(dag)` — exposed for the CLI and tests.
|
|
201
|
+
|
|
202
|
+
### Workers (`workers/`)
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { toLambdaHandler } from 'slimlake';
|
|
206
|
+
export const handler = toLambdaHandler(dag, store);
|
|
207
|
+
|
|
208
|
+
import { toWebHandler, startWebServer } from 'slimlake';
|
|
209
|
+
// Lambda Web Function: bind to AWS_LAMBDA_HTTP_ENDPOINT
|
|
210
|
+
startWebServer(dag, store);
|
|
211
|
+
// or use the listener directly
|
|
212
|
+
const server = http.createServer(toWebHandler(dag, store));
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`POST /run` with `{ "input": ..., "runId"?: ..., "parentRunId"?: ... }` runs the
|
|
216
|
+
DAG; `GET /health` reports the endpoint. The Lambda adapter accepts an API
|
|
217
|
+
Gateway v2 / Function URL event and returns `{ statusCode, body }`.
|
|
218
|
+
|
|
219
|
+
### Errors (`errors.ts`)
|
|
220
|
+
|
|
221
|
+
`SchemaError`, `AssertionError`, `LineageError`.
|
|
222
|
+
|
|
223
|
+
## CLI
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
slimlake validate <fixture.json> --schema <schema.json>
|
|
227
|
+
slimlake plan <dag.module>
|
|
228
|
+
slimlake run <dag.module> --input <json>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
`plan` prints the topological order; `run` executes the DAG and prints the
|
|
232
|
+
output plus materializations. `validate` exits `1` and prints every row error
|
|
233
|
+
when the fixture does not match.
|
|
234
|
+
|
|
235
|
+
## Testing with fakes
|
|
236
|
+
|
|
237
|
+
No AWS calls are needed in tests: inject an `S3ObjectPort` and a
|
|
238
|
+
`LineageTransport`, and use the in-memory store.
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
const s3: S3ObjectPort = {
|
|
242
|
+
async headObject({ bucket, key }) { return { found: false }; },
|
|
243
|
+
async putObject({ bucket, key, body }) { /* record */ },
|
|
244
|
+
};
|
|
245
|
+
await runTransformation(t, input, ctx, { publish: { s3 }, sleep: async () => {} });
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## W1 limitations
|
|
249
|
+
|
|
250
|
+
- Every format is written as JSONL. `parquet` assets use the `.parquet`
|
|
251
|
+
extension so readers can route on it, but the bytes are JSONL until a real
|
|
252
|
+
Parquet writer lands; `iceberg` assets are written as JSONL staging files.
|
|
253
|
+
- `toParquetSchema` is a schema description, not a writer.
|
|
254
|
+
- No CDK/infra and no npm publish yet; this is the library surface only.
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT — see [LICENSE](./LICENSE).
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Hand-rolled CLI (no dependencies):
|
|
4
|
+
* slimlake validate <fixture.json> --schema <schema.json>
|
|
5
|
+
* slimlake plan <dag.module>
|
|
6
|
+
* slimlake run <dag.module> --input <json>
|
|
7
|
+
*/
|
|
8
|
+
/** Entry point. Returns the process exit code; never throws. */
|
|
9
|
+
export declare function main(argv?: readonly string[]): Promise<number>;
|
|
10
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAwMH,gEAAgE;AAChE,wBAAsB,IAAI,CAAC,IAAI,GAAE,SAAS,MAAM,EAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CAwB3F"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Hand-rolled CLI (no dependencies):
|
|
4
|
+
* slimlake validate <fixture.json> --schema <schema.json>
|
|
5
|
+
* slimlake plan <dag.module>
|
|
6
|
+
* slimlake run <dag.module> --input <json>
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from 'node:crypto';
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import { resolve } from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { createRunContext, errorMessage, runDag, topologicalOrder } from './runtime.js';
|
|
13
|
+
import { schema, validateRows } from './schema.js';
|
|
14
|
+
import { createStore } from './store.js';
|
|
15
|
+
class CliError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'CliError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function printUsage() {
|
|
22
|
+
console.log(`slimlake — lean lake pipeline framework
|
|
23
|
+
|
|
24
|
+
Usage:
|
|
25
|
+
slimlake validate <fixture.json> --schema <schema.json>
|
|
26
|
+
slimlake plan <dag.module>
|
|
27
|
+
slimlake run <dag.module> --input <json>
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
function asRecord(value) {
|
|
31
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
32
|
+
return undefined;
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function parseArgs(args) {
|
|
36
|
+
const positionals = [];
|
|
37
|
+
const options = new Map();
|
|
38
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
39
|
+
const arg = args[index];
|
|
40
|
+
if (arg === undefined)
|
|
41
|
+
continue;
|
|
42
|
+
if (arg.startsWith('--')) {
|
|
43
|
+
const value = args[index + 1];
|
|
44
|
+
if (value === undefined || value.startsWith('--')) {
|
|
45
|
+
throw new CliError(`missing value for ${arg}`);
|
|
46
|
+
}
|
|
47
|
+
options.set(arg, value);
|
|
48
|
+
index += 1;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
positionals.push(arg);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { positionals, options };
|
|
55
|
+
}
|
|
56
|
+
async function readJsonFile(path) {
|
|
57
|
+
const text = await readFile(path, 'utf8');
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(text);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw new CliError(`${path}: invalid JSON (${errorMessage(error)})`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function toSchema(value) {
|
|
66
|
+
const record = asRecord(value);
|
|
67
|
+
if (record === undefined)
|
|
68
|
+
throw new CliError('schema must be a JSON object');
|
|
69
|
+
const version = record['version'];
|
|
70
|
+
const columns = record['columns'];
|
|
71
|
+
if (typeof version !== 'string')
|
|
72
|
+
throw new CliError('schema.version must be a string');
|
|
73
|
+
if (!Array.isArray(columns))
|
|
74
|
+
throw new CliError('schema.columns must be an array');
|
|
75
|
+
const definitions = columns.map((column) => {
|
|
76
|
+
const columnRecord = asRecord(column);
|
|
77
|
+
if (columnRecord === undefined)
|
|
78
|
+
throw new CliError('each schema column must be an object');
|
|
79
|
+
const name = columnRecord['name'];
|
|
80
|
+
const type = columnRecord['type'];
|
|
81
|
+
if (typeof name !== 'string' || typeof type !== 'string') {
|
|
82
|
+
throw new CliError('each schema column needs name:string and type:string');
|
|
83
|
+
}
|
|
84
|
+
const nullable = columnRecord['nullable'];
|
|
85
|
+
const description = columnRecord['description'];
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
type,
|
|
89
|
+
...(typeof nullable === 'boolean' ? { nullable } : {}),
|
|
90
|
+
...(typeof description === 'string' ? { description } : {}),
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const definition = { version, columns: definitions };
|
|
94
|
+
return schema(definition);
|
|
95
|
+
}
|
|
96
|
+
function isDag(value) {
|
|
97
|
+
const record = asRecord(value);
|
|
98
|
+
if (record === undefined)
|
|
99
|
+
return false;
|
|
100
|
+
if (typeof record['id'] !== 'string' || !Array.isArray(record['steps']))
|
|
101
|
+
return false;
|
|
102
|
+
return record['steps'].every((step) => asRecord(step) !== undefined);
|
|
103
|
+
}
|
|
104
|
+
async function loadDag(modulePath) {
|
|
105
|
+
const url = pathToFileURL(resolve(modulePath)).href;
|
|
106
|
+
let mod;
|
|
107
|
+
try {
|
|
108
|
+
mod = await import(url);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new CliError(`cannot import ${modulePath}: ${errorMessage(error)}`);
|
|
112
|
+
}
|
|
113
|
+
const record = asRecord(mod);
|
|
114
|
+
const candidate = record?.['dag'] ??
|
|
115
|
+
asRecord(record?.['default'])?.['dag'] ??
|
|
116
|
+
record?.['default'];
|
|
117
|
+
if (!isDag(candidate)) {
|
|
118
|
+
throw new CliError(`${modulePath} does not export a dag`);
|
|
119
|
+
}
|
|
120
|
+
return candidate;
|
|
121
|
+
}
|
|
122
|
+
async function cmdValidate(args) {
|
|
123
|
+
const { positionals, options } = parseArgs(args);
|
|
124
|
+
const fixturePath = positionals[0];
|
|
125
|
+
const schemaPath = options.get('--schema');
|
|
126
|
+
if (fixturePath === undefined || schemaPath === undefined) {
|
|
127
|
+
throw new CliError('usage: slimlake validate <fixture.json> --schema <schema.json>');
|
|
128
|
+
}
|
|
129
|
+
const schema = toSchema(await readJsonFile(schemaPath));
|
|
130
|
+
const fixture = await readJsonFile(fixturePath);
|
|
131
|
+
if (!Array.isArray(fixture))
|
|
132
|
+
throw new CliError('fixture must be a JSON array of rows');
|
|
133
|
+
const result = validateRows(schema, fixture);
|
|
134
|
+
if (result.ok) {
|
|
135
|
+
console.log(`OK: ${fixture.length} rows match schema ${schema.version}`);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
for (const error of result.errors)
|
|
139
|
+
console.error(error);
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
async function cmdPlan(args) {
|
|
143
|
+
const { positionals } = parseArgs(args);
|
|
144
|
+
const modulePath = positionals[0];
|
|
145
|
+
if (modulePath === undefined)
|
|
146
|
+
throw new CliError('usage: slimlake plan <dag.module>');
|
|
147
|
+
const dag = await loadDag(modulePath);
|
|
148
|
+
console.log(`dag ${dag.id}:`);
|
|
149
|
+
for (const step of topologicalOrder(dag)) {
|
|
150
|
+
const inputs = step.inputs.map((asset) => `${asset.id} (${asset.uri})`).join(', ') || '(none)';
|
|
151
|
+
const partition = step.output.partition === undefined ? '' : ` partition=${step.output.partition.join('/')}`;
|
|
152
|
+
console.log(` ${step.id}: ${inputs} -> ${step.output.id} (${step.output.uri}) [${step.output.format}]${partition}`);
|
|
153
|
+
}
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
async function cmdRun(args) {
|
|
157
|
+
const { positionals, options } = parseArgs(args);
|
|
158
|
+
const modulePath = positionals[0];
|
|
159
|
+
const inputJson = options.get('--input');
|
|
160
|
+
if (modulePath === undefined || inputJson === undefined) {
|
|
161
|
+
throw new CliError('usage: slimlake run <dag.module> --input <json>');
|
|
162
|
+
}
|
|
163
|
+
let input;
|
|
164
|
+
try {
|
|
165
|
+
input = JSON.parse(inputJson);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
throw new CliError(`--input is not valid JSON: ${errorMessage(error)}`);
|
|
169
|
+
}
|
|
170
|
+
const dag = await loadDag(modulePath);
|
|
171
|
+
const store = createStore();
|
|
172
|
+
const runId = randomUUID();
|
|
173
|
+
const startedAt = new Date().toISOString();
|
|
174
|
+
const ctx = createRunContext({
|
|
175
|
+
runId,
|
|
176
|
+
attempt: 1,
|
|
177
|
+
startedAt,
|
|
178
|
+
transport: store.transport,
|
|
179
|
+
recordMaterialization: (m) => store.recordMaterialization(m),
|
|
180
|
+
});
|
|
181
|
+
await store.recordRun({ runId, jobId: dag.id, status: 'RUNNING', startedAt, attempt: 1 });
|
|
182
|
+
const output = await runDag(dag, input, ctx);
|
|
183
|
+
await store.recordRun({
|
|
184
|
+
runId,
|
|
185
|
+
jobId: dag.id,
|
|
186
|
+
status: 'COMPLETE',
|
|
187
|
+
startedAt,
|
|
188
|
+
endedAt: new Date().toISOString(),
|
|
189
|
+
attempt: 1,
|
|
190
|
+
});
|
|
191
|
+
const run = await store.getRun(runId);
|
|
192
|
+
console.log(JSON.stringify({ runId, output, materializations: run?.materializations ?? [] }, null, 2));
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
/** Entry point. Returns the process exit code; never throws. */
|
|
196
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
197
|
+
const command = argv[0];
|
|
198
|
+
const rest = argv.slice(1);
|
|
199
|
+
try {
|
|
200
|
+
switch (command) {
|
|
201
|
+
case 'validate':
|
|
202
|
+
return await cmdValidate(rest);
|
|
203
|
+
case 'plan':
|
|
204
|
+
return await cmdPlan(rest);
|
|
205
|
+
case 'run':
|
|
206
|
+
return await cmdRun(rest);
|
|
207
|
+
case 'help':
|
|
208
|
+
case '--help':
|
|
209
|
+
case '-h':
|
|
210
|
+
printUsage();
|
|
211
|
+
return 0;
|
|
212
|
+
default:
|
|
213
|
+
printUsage();
|
|
214
|
+
return 1;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const invokedDirectly = (() => {
|
|
223
|
+
const entry = process.argv[1];
|
|
224
|
+
if (entry === undefined)
|
|
225
|
+
return false;
|
|
226
|
+
try {
|
|
227
|
+
return import.meta.url === pathToFileURL(entry).href;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
if (invokedDirectly) {
|
|
234
|
+
void main().then((code) => {
|
|
235
|
+
process.exitCode = code;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAA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|
1
|
+
/**
|
|
2
|
+
* The wire types of slimlake. These are deliberately small: an asset is a
|
|
3
|
+
* typed pointer at a URI, a transformation is a typed function over assets,
|
|
4
|
+
* and a run context is the only thing a transformation sees of the world.
|
|
5
|
+
*/
|
|
6
|
+
export interface Column {
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
nullable: boolean;
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Schema {
|
|
13
|
+
version: string;
|
|
14
|
+
columns: Column[];
|
|
15
|
+
compatibility: 'additive';
|
|
16
|
+
}
|
|
17
|
+
export interface Asset<T = unknown> {
|
|
18
|
+
id: string;
|
|
19
|
+
uri: string;
|
|
20
|
+
schema?: Schema;
|
|
21
|
+
format: 'jsonl' | 'parquet' | 'iceberg';
|
|
22
|
+
partition?: string[];
|
|
23
|
+
location: 'lake' | 'staging' | 'external';
|
|
24
|
+
}
|
|
25
|
+
export interface Materialization {
|
|
26
|
+
runId: string;
|
|
27
|
+
assetId: string;
|
|
28
|
+
schemaVersion: string;
|
|
29
|
+
partition?: string;
|
|
30
|
+
rows: number;
|
|
31
|
+
bytes: number;
|
|
32
|
+
digest: string;
|
|
33
|
+
publishedAt: string;
|
|
34
|
+
}
|
|
35
|
+
export type RunEventType = 'START' | 'RUNNING' | 'COMPLETE' | 'FAIL' | 'ABORT';
|
|
36
|
+
/**
|
|
37
|
+
* A dataset reference in an OpenLineage event. Give `uri` (an `s3://` URI) or
|
|
38
|
+
* an explicit `namespace`/`name` pair; `uri` wins because it carries both.
|
|
39
|
+
*/
|
|
40
|
+
export interface DatasetSpec {
|
|
41
|
+
uri?: string;
|
|
42
|
+
namespace?: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
facets?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/** The slimlake-shaped input to {@link import('./lineage.js').buildRunEvent}. */
|
|
47
|
+
export interface RunEventInput {
|
|
48
|
+
eventType: RunEventType;
|
|
49
|
+
runId: string;
|
|
50
|
+
parentRunId?: string;
|
|
51
|
+
job: {
|
|
52
|
+
namespace: string;
|
|
53
|
+
name: string;
|
|
54
|
+
type?: 'BATCH' | 'STREAM';
|
|
55
|
+
};
|
|
56
|
+
inputs?: DatasetSpec[];
|
|
57
|
+
outputs?: DatasetSpec[];
|
|
58
|
+
eventTime?: string;
|
|
59
|
+
producer?: string;
|
|
60
|
+
errorMessage?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface RunContext {
|
|
63
|
+
runId: string;
|
|
64
|
+
parentRunId?: string;
|
|
65
|
+
attempt: number;
|
|
66
|
+
startedAt: string;
|
|
67
|
+
emit(event: RunEventInput): Promise<void>;
|
|
68
|
+
recordMaterialization(m: Materialization): Promise<void>;
|
|
69
|
+
assert(check: DataQualityCheck): void;
|
|
70
|
+
}
|
|
71
|
+
export interface RetryPolicy {
|
|
72
|
+
attempts: number;
|
|
73
|
+
backoff: 'fixed' | 'exp';
|
|
74
|
+
delayMs?: number;
|
|
75
|
+
}
|
|
76
|
+
export interface Transformation<I = unknown, O = unknown> {
|
|
77
|
+
id: string;
|
|
78
|
+
inputs: Asset[];
|
|
79
|
+
output: Asset<O>;
|
|
80
|
+
worker?: 'event' | 'web';
|
|
81
|
+
retry?: RetryPolicy;
|
|
82
|
+
execute(input: I, ctx: RunContext): Promise<O>;
|
|
83
|
+
}
|
|
84
|
+
export interface Dag {
|
|
85
|
+
id: string;
|
|
86
|
+
steps: Transformation[];
|
|
87
|
+
}
|
|
88
|
+
export interface DataQualityCheck {
|
|
89
|
+
id: string;
|
|
90
|
+
ok: boolean;
|
|
91
|
+
detail?: string;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAA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EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire types of slimlake. These are deliberately small: an asset is a
|
|
3
|
+
* typed pointer at a URI, a transformation is a typed function over assets,
|
|
4
|
+
* and a run context is the only thing a transformation sees of the world.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Errors raised by slimlake. Every exported error carries a stable `name` so
|
|
3
|
+
* callers can branch on it without string matching.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SchemaError extends Error {
|
|
6
|
+
readonly errors: string[];
|
|
7
|
+
constructor(message: string, errors?: readonly string[]);
|
|
8
|
+
}
|
|
9
|
+
export declare class AssertionError extends Error {
|
|
10
|
+
readonly checkId: string;
|
|
11
|
+
readonly detail: string | undefined;
|
|
12
|
+
constructor(checkId: string, detail?: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class LineageError extends Error {
|
|
15
|
+
constructor(message: string, options?: {
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|