@useairfoil/connector-kit 0.3.0 → 0.5.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 +279 -90
- package/dist/chunk-Bp6m_JJh.js +13 -0
- package/dist/connector-app/index.d.ts +9 -0
- package/dist/connector-app/index.js +8 -0
- package/dist/connector-app-CvqbfN6R.js +32 -0
- package/dist/connector-app-CvqbfN6R.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors-DHWylqRZ.js +8 -0
- package/dist/errors-DHWylqRZ.js.map +1 -0
- package/dist/index-8KnVpoZp.d.ts +32 -0
- package/dist/index-BlhJCpEk.d.ts +124 -0
- package/dist/index-CQJsFJs3.d.ts +23 -0
- package/dist/index-DK9YcR6W.d.ts +25 -0
- package/dist/index-DaNW63Mv.d.ts +21 -0
- package/dist/index-DyuT2jzP.d.ts +14 -0
- package/dist/index.d.ts +9 -166
- package/dist/index.js +44 -229
- package/dist/index.js.map +1 -1
- package/dist/ingestion/index.d.ts +6 -0
- package/dist/ingestion/index.js +7 -0
- package/dist/ingestion-CMCroK7Y.js +171 -0
- package/dist/ingestion-CMCroK7Y.js.map +1 -0
- package/dist/publisher/index.d.ts +5 -0
- package/dist/publisher/index.js +5 -0
- package/dist/publisher-DusgYvaV.js +131 -0
- package/dist/publisher-DusgYvaV.js.map +1 -0
- package/dist/server-DAeFWT4o.js +113 -0
- package/dist/server-DAeFWT4o.js.map +1 -0
- package/dist/service-B7g_lHMI.d.ts +32 -0
- package/dist/state-store/index.d.ts +4 -0
- package/dist/state-store/index.js +3 -0
- package/dist/state-store-DG_4QpWG.js +31 -0
- package/dist/state-store-DG_4QpWG.js.map +1 -0
- package/dist/telemetry-p0dE5Mdu.js +171 -0
- package/dist/telemetry-p0dE5Mdu.js.map +1 -0
- package/dist/types-ZNrA-Dn0.d.ts +160 -0
- package/dist/webhook/index.d.ts +5 -0
- package/dist/webhook/index.js +6 -0
- package/dist/webhook-BSA-tXtU.js +13 -0
- package/dist/webhook-BSA-tXtU.js.map +1 -0
- package/package.json +41 -14
- package/src/connector-app/index.ts +1 -0
- package/src/connector-app/start.ts +38 -0
- package/src/core/builder.ts +73 -15
- package/src/core/index.ts +22 -0
- package/src/core/types.ts +186 -78
- package/src/errors/index.ts +1 -0
- package/src/index.ts +8 -28
- package/src/ingestion/engine.ts +302 -206
- package/src/ingestion/index.ts +1 -0
- package/src/publisher/console.ts +18 -0
- package/src/publisher/index.ts +7 -0
- package/src/publisher/service.ts +33 -14
- package/src/publisher/wings.ts +162 -82
- package/src/runtime/context.ts +15 -0
- package/src/state-store/index.ts +2 -0
- package/src/state-store/memory.ts +25 -0
- package/src/state-store/service.ts +18 -0
- package/src/telemetry.ts +246 -0
- package/src/webhook/index.ts +8 -0
- package/src/webhook/server.ts +177 -54
- package/src/webhook/types.ts +6 -16
- package/src/ingestion/state-store.ts +0 -36
- package/src/streams/pull-stream.ts +0 -55
- package/src/streams/webhook-queue.ts +0 -15
- /package/src/{core/errors.ts → errors/connector-error.ts} +0 -0
package/src/core/types.ts
CHANGED
|
@@ -1,102 +1,210 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Duration, Effect, Schema } from "effect";
|
|
2
|
+
import type { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import type { ConnectorError } from "../errors";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export namespace Cursor {
|
|
7
|
+
export type Value = string | number | Date;
|
|
8
|
+
|
|
9
|
+
export type Kind = "string" | "number" | "isoDateTime";
|
|
10
|
+
|
|
11
|
+
export type Definition<T extends Value = Value> = {
|
|
12
|
+
readonly kind: Kind;
|
|
13
|
+
readonly decode: (value: unknown) => Effect.Effect<T, ConnectorError>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type DeleteValue = string | number | boolean | Date;
|
|
10
18
|
|
|
11
|
-
export type
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
export type ResourceMutation<Row extends object = object> =
|
|
20
|
+
| {
|
|
21
|
+
readonly op: "upsert";
|
|
22
|
+
readonly row: Row;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
readonly op: "delete";
|
|
26
|
+
readonly key: DeleteValue;
|
|
27
|
+
readonly version: DeleteValue;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ResourceBatch<Row extends object = object> = {
|
|
31
|
+
readonly cursor?: Cursor.Value;
|
|
32
|
+
readonly mutations: ReadonlyArray<ResourceMutation<Row>>;
|
|
14
33
|
};
|
|
15
34
|
|
|
16
|
-
export type
|
|
17
|
-
readonly backfill
|
|
18
|
-
|
|
35
|
+
export type ResourceState = {
|
|
36
|
+
readonly backfill?: {
|
|
37
|
+
readonly cutoff: Cursor.Value;
|
|
38
|
+
readonly pageCursor?: Cursor.Value;
|
|
39
|
+
readonly completed: boolean;
|
|
40
|
+
};
|
|
41
|
+
readonly changes?: {
|
|
42
|
+
readonly cursor: Cursor.Value;
|
|
43
|
+
};
|
|
19
44
|
};
|
|
20
45
|
|
|
21
|
-
export type
|
|
46
|
+
export type ResourceSchema = Schema.Decoder<object>;
|
|
22
47
|
|
|
23
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Takes a resource schema and returns its decoded row object type.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const ProductSchema = Schema.Struct({ id: Schema.String, updatedAt: Schema.String });
|
|
54
|
+
* type Product = ResourceRow<typeof ProductSchema>;
|
|
55
|
+
* // Result:
|
|
56
|
+
* // type Product = { readonly id: string; readonly updatedAt: string }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export type ResourceRow<S extends ResourceSchema> = Schema.Schema.Type<S>;
|
|
24
60
|
|
|
25
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Takes a resource schema and returns the string keys available on its row type.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const ProductSchema = Schema.Struct({ id: Schema.String, updatedAt: Schema.String });
|
|
67
|
+
* type ProductField = ResourceField<typeof ProductSchema>;
|
|
68
|
+
* // Result:
|
|
69
|
+
* // type ProductField = "id" | "updatedAt"
|
|
70
|
+
*
|
|
71
|
+
* const key: ResourceField<typeof ProductSchema> = "id";
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type ResourceField<S extends ResourceSchema> = keyof ResourceRow<S> & string;
|
|
26
75
|
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
readonly queue: Queue.Queue<Batch<T>>;
|
|
32
|
-
/**
|
|
33
|
-
* The stream is used to process the batches that are received from the webhook.
|
|
34
|
-
*/
|
|
35
|
-
readonly stream: Stream.Stream<Batch<T>, ConnectorError>;
|
|
76
|
+
export type FetchPageResult<Row extends object> = {
|
|
77
|
+
readonly mutations: ReadonlyArray<ResourceMutation<Row>>;
|
|
78
|
+
readonly nextPageCursor?: Cursor.Value;
|
|
79
|
+
readonly hasMore: boolean;
|
|
36
80
|
};
|
|
37
81
|
|
|
38
|
-
export type
|
|
82
|
+
export type PageFetch<Row extends object, R = never> = {
|
|
83
|
+
readonly pageCursor: Cursor.Definition;
|
|
84
|
+
readonly cutoff: Cursor.Definition;
|
|
85
|
+
readonly fetch: (input: {
|
|
86
|
+
readonly pageCursor?: Cursor.Value;
|
|
87
|
+
readonly cutoff: Cursor.Value;
|
|
88
|
+
}) => Effect.Effect<FetchPageResult<Row>, ConnectorError, R>;
|
|
89
|
+
};
|
|
39
90
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/** Primary key type derived from the decoded schema shape. */
|
|
45
|
-
export type EntityKey<S extends EntitySchema> =
|
|
46
|
-
EntityType<S> extends Record<string, unknown>
|
|
47
|
-
? keyof EntityType<S> & string
|
|
48
|
-
: never;
|
|
49
|
-
/** Row type constrained to object-like shapes for ingestion. */
|
|
50
|
-
export type EntityRow<S extends EntitySchema> = EntityType<S> &
|
|
51
|
-
Record<string, unknown>;
|
|
91
|
+
export type FetchChangesResult<Row extends object> = {
|
|
92
|
+
readonly mutations: ReadonlyArray<ResourceMutation<Row>>;
|
|
93
|
+
readonly cursor: Cursor.Value;
|
|
94
|
+
};
|
|
52
95
|
|
|
53
|
-
export type
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readonly primaryKey: EntityKey<S>;
|
|
60
|
-
/**
|
|
61
|
-
* The live source is used to stream the live data from the database.
|
|
62
|
-
*/
|
|
63
|
-
readonly live: LiveSource<EntityRow<S>>;
|
|
64
|
-
/**
|
|
65
|
-
* The backfill stream is used to stream the backfill data from the database.
|
|
66
|
-
*/
|
|
67
|
-
readonly backfill: BackfillStream<EntityRow<S>>;
|
|
68
|
-
/**
|
|
69
|
-
* The transform is used to transform the rows before they are published.
|
|
70
|
-
*/
|
|
71
|
-
readonly transform?: Transform<EntityRow<S>>;
|
|
96
|
+
export type ChangesFetch<Row extends object, R = never> = {
|
|
97
|
+
readonly cursor: Cursor.Definition;
|
|
98
|
+
readonly interval?: Duration.Input;
|
|
99
|
+
readonly fetch: (input: {
|
|
100
|
+
readonly cursor: Cursor.Value;
|
|
101
|
+
}) => Effect.Effect<FetchChangesResult<Row>, ConnectorError, R>;
|
|
72
102
|
};
|
|
73
103
|
|
|
74
|
-
export type
|
|
104
|
+
export type WebhookHandler<Row extends object, Payload> = {
|
|
105
|
+
readonly schema: Schema.Decoder<Payload>;
|
|
106
|
+
handler(input: {
|
|
107
|
+
readonly payload: Payload;
|
|
108
|
+
}): Effect.Effect<ReadonlyArray<ResourceMutation<Row>>, ConnectorError>;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type ResourceDefinition<
|
|
112
|
+
S extends ResourceSchema = ResourceSchema,
|
|
113
|
+
Payload = unknown,
|
|
114
|
+
R = never,
|
|
115
|
+
> = {
|
|
75
116
|
readonly name: string;
|
|
76
117
|
readonly schema: S;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
readonly
|
|
85
|
-
/**
|
|
86
|
-
* The transform is used to transform the rows before they are published.
|
|
87
|
-
*/
|
|
88
|
-
readonly transform?: Transform<EntityRow<S>>;
|
|
118
|
+
readonly key: ResourceField<NoInfer<S>>;
|
|
119
|
+
readonly version: ResourceField<NoInfer<S>>;
|
|
120
|
+
readonly partition?: {
|
|
121
|
+
readonly required: boolean;
|
|
122
|
+
};
|
|
123
|
+
readonly backfill?: PageFetch<ResourceRow<NoInfer<S>>, R>;
|
|
124
|
+
readonly changes?: ChangesFetch<ResourceRow<NoInfer<S>>, R>;
|
|
125
|
+
readonly webhook?: WebhookHandler<ResourceRow<NoInfer<S>>, Payload>;
|
|
89
126
|
};
|
|
90
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Takes a connector resource tuple and returns a `{ [resourceName]: rowType }`
|
|
130
|
+
* map.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* type Rows = ResourceRows<[typeof Products, typeof Orders]>;
|
|
135
|
+
* // Result:
|
|
136
|
+
* // type Rows = {
|
|
137
|
+
* // readonly products: Product;
|
|
138
|
+
* // readonly orders: Order;
|
|
139
|
+
* // }
|
|
140
|
+
*
|
|
141
|
+
* type ProductRow = Rows["products"];
|
|
142
|
+
* // Result:
|
|
143
|
+
* // type ProductRow = Product
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export type ResourceRows<Resources extends ReadonlyArray<ResourceDefinition>> = {
|
|
147
|
+
readonly [Resource in Resources[number] as Resource["name"]]: Resource extends ResourceDefinition<
|
|
148
|
+
infer S,
|
|
149
|
+
unknown,
|
|
150
|
+
unknown
|
|
151
|
+
>
|
|
152
|
+
? ResourceRow<S>
|
|
153
|
+
: never;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Takes a resource definition and returns the payload type accepted by
|
|
158
|
+
* `to(resource, payload)`.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* type ProductPayload = ResourcePayload<typeof Products>;
|
|
163
|
+
* // Result, if Products was defined with a ProductEvent webhook schema:
|
|
164
|
+
* // type ProductPayload = ProductEvent
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export type ResourcePayload<R> =
|
|
168
|
+
R extends ResourceDefinition<ResourceSchema, infer Payload, unknown> ? Payload : never;
|
|
169
|
+
|
|
170
|
+
export type WebhookAckMode = "after-enqueue" | "after-publish";
|
|
171
|
+
|
|
172
|
+
export type WebhookRouteContext<
|
|
173
|
+
Resources extends ReadonlyArray<ResourceDefinition> = ReadonlyArray<ResourceDefinition>,
|
|
174
|
+
Payload = unknown,
|
|
175
|
+
> = {
|
|
176
|
+
readonly request: HttpServerRequest.HttpServerRequest;
|
|
177
|
+
readonly rawBody: Uint8Array;
|
|
178
|
+
readonly payload: Payload;
|
|
179
|
+
/** Decodes and collects mutations for a resource-owned webhook handler. */
|
|
180
|
+
readonly to: <Resource extends Resources[number]>(
|
|
181
|
+
resource: Resource,
|
|
182
|
+
payload: ResourcePayload<Resource>,
|
|
183
|
+
) => Effect.Effect<void, ConnectorError>;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type WebhookRoute<
|
|
187
|
+
Resources extends ReadonlyArray<ResourceDefinition> = ReadonlyArray<ResourceDefinition>,
|
|
188
|
+
Payload = unknown,
|
|
189
|
+
> = {
|
|
190
|
+
readonly path: HttpRouter.PathInput;
|
|
191
|
+
readonly ackMode: WebhookAckMode;
|
|
192
|
+
readonly schema: Schema.Decoder<Payload>;
|
|
193
|
+
handler(
|
|
194
|
+
context: WebhookRouteContext<Resources, Payload>,
|
|
195
|
+
): Effect.Effect<HttpServerResponse.HttpServerResponse, unknown>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export type WebhookRouteInput<
|
|
199
|
+
Resources extends ReadonlyArray<ResourceDefinition>,
|
|
200
|
+
Payload,
|
|
201
|
+
> = WebhookRoute<Resources, Payload>;
|
|
202
|
+
|
|
91
203
|
export type ConnectorDefinition<
|
|
92
|
-
|
|
93
|
-
EntityDefinition<EntitySchema>
|
|
94
|
-
> = ReadonlyArray<EntityDefinition<EntitySchema>>,
|
|
95
|
-
Events extends ReadonlyArray<EventDefinition<EntitySchema>> = ReadonlyArray<
|
|
96
|
-
EventDefinition<EntitySchema>
|
|
97
|
-
>,
|
|
204
|
+
Resources extends ReadonlyArray<ResourceDefinition> = ReadonlyArray<ResourceDefinition>,
|
|
98
205
|
> = {
|
|
99
206
|
readonly name: string;
|
|
100
|
-
readonly
|
|
101
|
-
readonly
|
|
207
|
+
readonly title?: string;
|
|
208
|
+
readonly resources: Resources;
|
|
209
|
+
readonly webhooks?: ReadonlyArray<WebhookRoute>;
|
|
102
210
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ConnectorError } from "./connector-error";
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
EntityKey,
|
|
10
|
-
EntityRow,
|
|
11
|
-
EntitySchema,
|
|
12
|
-
EntityType,
|
|
13
|
-
EventDefinition,
|
|
14
|
-
IngestionState,
|
|
15
|
-
LiveSource,
|
|
16
|
-
LiveStream,
|
|
17
|
-
StreamState,
|
|
18
|
-
Transform,
|
|
19
|
-
WebhookStream,
|
|
20
|
-
} from "./core/types";
|
|
21
|
-
export { runConnector } from "./ingestion/engine";
|
|
22
|
-
export { StateStore, StateStoreInMemory } from "./ingestion/state-store";
|
|
23
|
-
export { Publisher } from "./publisher/service";
|
|
24
|
-
export { WingsPublisherLayer } from "./publisher/wings";
|
|
25
|
-
export { makePullStream } from "./streams/pull-stream";
|
|
26
|
-
export { makeWebhookQueue } from "./streams/webhook-queue";
|
|
27
|
-
export { buildWebhookRouter } from "./webhook/server";
|
|
28
|
-
export type { WebhookRoute } from "./webhook/types";
|
|
1
|
+
export * from "./core";
|
|
2
|
+
export * as ConnectorApp from "./connector-app";
|
|
3
|
+
export * as Ingestion from "./ingestion";
|
|
4
|
+
export * as Publisher from "./publisher";
|
|
5
|
+
export * as StateStore from "./state-store";
|
|
6
|
+
export * as Telemetry from "./telemetry";
|
|
7
|
+
export * as Webhook from "./webhook";
|
|
8
|
+
export * from "./errors";
|