@butinapp/sdk 0.1.0 → 0.1.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/dist/plugin/capability.d.ts +24 -9
- package/dist/plugin/capability.js +21 -17
- package/package.json +1 -1
|
@@ -16,13 +16,14 @@ export type CollectContext<TConfig = Record<string, unknown>> = {
|
|
|
16
16
|
export type IncrementalSpec = {
|
|
17
17
|
id: string;
|
|
18
18
|
timestamp: string;
|
|
19
|
+
listKey?: string;
|
|
19
20
|
window?: {
|
|
20
21
|
days: number;
|
|
21
22
|
};
|
|
22
23
|
};
|
|
23
24
|
export type IncrementalCapability = IncrementalSpec & {
|
|
24
|
-
fetch: (ctx: CollectContext) => Promise<
|
|
25
|
-
build: (
|
|
25
|
+
fetch: (ctx: CollectContext) => Promise<unknown>;
|
|
26
|
+
build: (raw: unknown) => CapabilityResult;
|
|
26
27
|
};
|
|
27
28
|
export type Capability<TConfig = Record<string, unknown>> = {
|
|
28
29
|
id: string;
|
|
@@ -36,6 +37,26 @@ export type Capability<TConfig = Record<string, unknown>> = {
|
|
|
36
37
|
fetchFile?: (ctx: CollectContext<TConfig>, row: Record<string, unknown>) => Promise<DocumentBytes>;
|
|
37
38
|
};
|
|
38
39
|
type RowOf<TRaw> = TRaw extends readonly (infer R)[] ? R : never;
|
|
40
|
+
type ListKeys<T> = {
|
|
41
|
+
[K in keyof T]: T[K] extends readonly unknown[] ? K : never;
|
|
42
|
+
}[keyof T];
|
|
43
|
+
type FieldOf<A> = keyof RowOf<A> & string;
|
|
44
|
+
type IncrementalDecl<TRaw> = TRaw extends readonly unknown[] ? {
|
|
45
|
+
id: FieldOf<TRaw>;
|
|
46
|
+
timestamp: FieldOf<TRaw>;
|
|
47
|
+
window?: {
|
|
48
|
+
days: number;
|
|
49
|
+
};
|
|
50
|
+
} : {
|
|
51
|
+
[K in ListKeys<TRaw>]: {
|
|
52
|
+
listKey: K;
|
|
53
|
+
id: FieldOf<TRaw[K]>;
|
|
54
|
+
timestamp: FieldOf<TRaw[K]>;
|
|
55
|
+
window?: {
|
|
56
|
+
days: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}[ListKeys<TRaw>];
|
|
39
60
|
export declare const defineCapability: <TRaw, TConfig = Record<string, unknown>>(spec: {
|
|
40
61
|
id: string;
|
|
41
62
|
label: string;
|
|
@@ -43,12 +64,6 @@ export declare const defineCapability: <TRaw, TConfig = Record<string, unknown>>
|
|
|
43
64
|
build: (raw: TRaw) => CapabilityResult;
|
|
44
65
|
sample: SampleGenerator<TRaw>;
|
|
45
66
|
fetchFile?: (ctx: CollectContext<TConfig>, row: Record<string, unknown>) => Promise<DocumentBytes>;
|
|
46
|
-
incremental?:
|
|
47
|
-
id: keyof RowOf<TRaw> & string;
|
|
48
|
-
timestamp: keyof RowOf<TRaw> & string;
|
|
49
|
-
window?: {
|
|
50
|
-
days: number;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
67
|
+
incremental?: IncrementalDecl<TRaw>;
|
|
53
68
|
}) => Capability<TConfig>;
|
|
54
69
|
export {};
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { createSampleGen, resolveSampleConfig } from '../testing/synthetic.js';
|
|
2
|
-
export const defineCapability = (spec) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
? {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
export const defineCapability = (spec) => {
|
|
3
|
+
const inc = spec.incremental;
|
|
4
|
+
return {
|
|
5
|
+
id: spec.id,
|
|
6
|
+
label: spec.label,
|
|
7
|
+
collect: async (ctx) => spec.build(await spec.fetch(ctx)),
|
|
8
|
+
sample: (opts) => spec.build(spec.sample(createSampleGen(opts?.seed ?? spec.id), resolveSampleConfig(opts?.config))),
|
|
9
|
+
...(spec.fetchFile ? { fetchFile: spec.fetchFile } : {}),
|
|
10
|
+
...(spec.incremental
|
|
11
|
+
? {
|
|
12
|
+
incremental: {
|
|
13
|
+
id: inc.id,
|
|
14
|
+
timestamp: inc.timestamp,
|
|
15
|
+
...(inc.listKey ? { listKey: inc.listKey } : {}),
|
|
16
|
+
...(inc.window ? { window: inc.window } : {}),
|
|
17
|
+
fetch: spec.fetch,
|
|
18
|
+
build: spec.build
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
21
|
+
: {})
|
|
22
|
+
};
|
|
23
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@butinapp/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The Butin plugin-authoring contract: descriptor types, the data-view result contract, presets, and edge utilities.",
|
|
5
5
|
"homepage": "https://butin.app",
|
|
6
6
|
"bugs": "https://github.com/butinapp/butin/issues",
|