@useairfoil/connector-kit 0.5.3 → 0.6.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.
Files changed (178) hide show
  1. package/METRICS.md +20 -19
  2. package/README.md +127 -430
  3. package/dist/annotations-BE74YmAO.d.mts +39 -0
  4. package/dist/auth/index.d.mts +2 -0
  5. package/dist/{auth-DvU_CZ7C.js → auth/index.mjs} +6 -8
  6. package/dist/auth/index.mjs.map +1 -0
  7. package/dist/connector-app/index.d.mts +2 -0
  8. package/dist/connector-app/index.mjs +2 -0
  9. package/dist/connector-app-C-L4QqG6.mjs +123 -0
  10. package/dist/connector-app-C-L4QqG6.mjs.map +1 -0
  11. package/dist/{constants-BRhIX_rz.js → constants-D-GQzpHZ.mjs} +10 -6
  12. package/dist/constants-D-GQzpHZ.mjs.map +1 -0
  13. package/dist/demo/index.d.mts +2 -0
  14. package/dist/demo/index.mjs +2 -0
  15. package/dist/demo-B30Vlkk2.mjs +191 -0
  16. package/dist/demo-B30Vlkk2.mjs.map +1 -0
  17. package/dist/errors/index.d.mts +2 -0
  18. package/dist/errors/index.mjs +2 -0
  19. package/dist/{errors-DHWylqRZ.js → errors-pT0YVJU5.mjs} +2 -3
  20. package/dist/errors-pT0YVJU5.mjs.map +1 -0
  21. package/dist/iceberg/index.d.mts +3 -0
  22. package/dist/iceberg/index.mjs +3 -0
  23. package/dist/iceberg-D6L8I6vA.mjs +39 -0
  24. package/dist/iceberg-D6L8I6vA.mjs.map +1 -0
  25. package/dist/{index-Cq2IzY7T.d.ts → index-BUHSGm9Q.d.mts} +11 -13
  26. package/dist/{index-CTHVudvQ.d.ts → index-BX8G7d41.d.mts} +1 -2
  27. package/dist/{index-J42AZaXU.d.ts → index-BfXpgxk9.d.mts} +9 -10
  28. package/dist/{index-DKWIh6M1.d.ts → index-CRVAwJ5-.d.mts} +10 -8
  29. package/dist/index-CUPP2A_m.d.mts +27 -0
  30. package/dist/{index-Coh_SkBs.d.ts → index-CgvFomO6.d.mts} +6 -7
  31. package/dist/index-DJhDp4Xc.d.mts +58 -0
  32. package/dist/index-Dk7urvpF.d.mts +76 -0
  33. package/dist/{index-D54ySAKn.d.ts → index-DkVNO6ks.d.mts} +2 -5
  34. package/dist/{index-DtJX_tic.d.ts → index-NnCutIqM.d.mts} +77 -38
  35. package/dist/{index-CBT-JX-T.d.ts → index-eFuoMZZ3.d.mts} +18 -20
  36. package/dist/index-ygpml2kC.d.mts +73 -0
  37. package/dist/index.d.mts +16 -0
  38. package/dist/index.mjs +45 -0
  39. package/dist/index.mjs.map +1 -0
  40. package/dist/ingestion/index.d.mts +2 -0
  41. package/dist/ingestion/index.mjs +2 -0
  42. package/dist/ingestion-q0WwqUSt.mjs +275 -0
  43. package/dist/ingestion-q0WwqUSt.mjs.map +1 -0
  44. package/dist/ingestor/index.d.mts +3 -0
  45. package/dist/ingestor/index.mjs +4 -0
  46. package/dist/ingestor-D4L-HPkg.mjs +26 -0
  47. package/dist/ingestor-D4L-HPkg.mjs.map +1 -0
  48. package/dist/instrumented-Bhp7fyvh.mjs +29 -0
  49. package/dist/instrumented-Bhp7fyvh.mjs.map +1 -0
  50. package/dist/manifest/index.d.mts +2 -0
  51. package/dist/manifest/{index.js → index.mjs} +2 -4
  52. package/dist/{manifest-ByE6YPG0.js → manifest-BGKxmKLy.mjs} +14 -19
  53. package/dist/manifest-BGKxmKLy.mjs.map +1 -0
  54. package/dist/metrics-BaEX__MN.mjs +352 -0
  55. package/dist/metrics-BaEX__MN.mjs.map +1 -0
  56. package/dist/metrics-CVXFL7YT.d.mts +64 -0
  57. package/dist/metrics.d.mts +2 -0
  58. package/dist/metrics.mjs +2 -0
  59. package/dist/{chunk-Bp6m_JJh.js → rolldown-runtime-D7D4PA-g.mjs} +4 -4
  60. package/dist/runtime-config/index.d.mts +2 -0
  61. package/dist/runtime-config/index.mjs +3 -0
  62. package/dist/runtime-config-Oa55gAew.mjs +97 -0
  63. package/dist/runtime-config-Oa55gAew.mjs.map +1 -0
  64. package/dist/{server-CXTQ7odl.js → server-CMnxz3h0.mjs} +21 -60
  65. package/dist/server-CMnxz3h0.mjs.map +1 -0
  66. package/dist/service-DLkhuxYl.d.mts +27 -0
  67. package/dist/service-jWxxfEht.mjs +7 -0
  68. package/dist/service-jWxxfEht.mjs.map +1 -0
  69. package/dist/state-store/index.d.mts +2 -0
  70. package/dist/state-store/index.mjs +2 -0
  71. package/dist/{state-store-yl6LiTQ0.js → state-store-uFvHY7Ax.mjs} +15 -22
  72. package/dist/state-store-uFvHY7Ax.mjs.map +1 -0
  73. package/dist/status/{index.d.ts → index.d.mts} +1 -4
  74. package/dist/status/{index.js → index.mjs} +2 -6
  75. package/dist/{status-B-oZBc33.js → status-CKb9IhQ9.mjs} +14 -16
  76. package/dist/status-CKb9IhQ9.mjs.map +1 -0
  77. package/dist/table-V0tgUC5i.mjs +370 -0
  78. package/dist/table-V0tgUC5i.mjs.map +1 -0
  79. package/dist/types-xZtSmrGA.d.mts +220 -0
  80. package/dist/webhook/index.d.mts +3 -0
  81. package/dist/webhook/index.mjs +12 -0
  82. package/dist/webhook/index.mjs.map +1 -0
  83. package/dist/wings-I56hGtNv.mjs +325 -0
  84. package/dist/wings-I56hGtNv.mjs.map +1 -0
  85. package/package.json +64 -51
  86. package/src/catalog/table.ts +201 -0
  87. package/src/connector-app/create-table.ts +47 -0
  88. package/src/connector-app/demo.ts +42 -0
  89. package/src/connector-app/index.ts +2 -0
  90. package/src/connector-app/start.ts +1 -1
  91. package/src/core/builder.ts +15 -23
  92. package/src/core/index.ts +11 -1
  93. package/src/core/types.ts +114 -39
  94. package/src/demo/definition.ts +68 -0
  95. package/src/demo/generate.ts +167 -0
  96. package/src/demo/index.ts +3 -0
  97. package/src/demo/run.ts +142 -0
  98. package/src/iceberg/annotations.ts +62 -0
  99. package/src/iceberg/error.ts +9 -0
  100. package/src/iceberg/index.ts +3 -0
  101. package/src/iceberg/table.ts +511 -0
  102. package/src/index.ts +3 -1
  103. package/src/ingestion/engine.ts +240 -60
  104. package/src/ingestor/arrow.ts +248 -0
  105. package/src/ingestor/console.ts +13 -0
  106. package/src/ingestor/index.ts +9 -0
  107. package/src/ingestor/instrumented.ts +61 -0
  108. package/src/ingestor/service.ts +30 -0
  109. package/src/ingestor/wings.ts +143 -0
  110. package/src/manifest/config.ts +3 -3
  111. package/src/metrics.ts +125 -33
  112. package/src/runtime-config/config.ts +14 -0
  113. package/src/runtime-config/constants.ts +5 -2
  114. package/src/runtime-config/error.ts +4 -1
  115. package/src/runtime-config/index.ts +2 -0
  116. package/src/runtime-config/layer.ts +1 -1
  117. package/src/runtime-config/table-bindings.ts +92 -0
  118. package/src/state-store/layer-key-value-store.ts +8 -3
  119. package/src/state-store/layer-memory.ts +1 -1
  120. package/src/state-store/layer-sql.ts +4 -4
  121. package/src/state-store/schema.ts +2 -2
  122. package/src/state-store/state.ts +14 -2
  123. package/src/status/route.ts +2 -2
  124. package/src/telemetry.ts +25 -10
  125. package/src/webhook/server.ts +39 -40
  126. package/dist/auth/index.d.ts +0 -2
  127. package/dist/auth/index.js +0 -3
  128. package/dist/auth-DvU_CZ7C.js.map +0 -1
  129. package/dist/connector-app/index.d.ts +0 -14
  130. package/dist/connector-app/index.js +0 -11
  131. package/dist/connector-app-d7Z-SZLQ.js +0 -64
  132. package/dist/connector-app-d7Z-SZLQ.js.map +0 -1
  133. package/dist/constants-BRhIX_rz.js.map +0 -1
  134. package/dist/errors/index.d.ts +0 -2
  135. package/dist/errors/index.js +0 -3
  136. package/dist/errors-DHWylqRZ.js.map +0 -1
  137. package/dist/index-Byr0Lf0C.d.ts +0 -25
  138. package/dist/index-o1-Z3n7V.d.ts +0 -55
  139. package/dist/index.d.ts +0 -14
  140. package/dist/index.js +0 -58
  141. package/dist/index.js.map +0 -1
  142. package/dist/ingestion/index.d.ts +0 -6
  143. package/dist/ingestion/index.js +0 -10
  144. package/dist/ingestion-BQo4cbGw.js +0 -200
  145. package/dist/ingestion-BQo4cbGw.js.map +0 -1
  146. package/dist/manifest/index.d.ts +0 -2
  147. package/dist/manifest-ByE6YPG0.js.map +0 -1
  148. package/dist/metrics-CVAk1ALR.d.ts +0 -53
  149. package/dist/metrics-CWPy2Aqc.js +0 -96
  150. package/dist/metrics-CWPy2Aqc.js.map +0 -1
  151. package/dist/metrics.d.ts +0 -4
  152. package/dist/metrics.js +0 -3
  153. package/dist/publisher/index.d.ts +0 -5
  154. package/dist/publisher/index.js +0 -6
  155. package/dist/publisher-BYT3RLVO.js +0 -131
  156. package/dist/publisher-BYT3RLVO.js.map +0 -1
  157. package/dist/runtime-config/index.d.ts +0 -2
  158. package/dist/runtime-config/index.js +0 -4
  159. package/dist/runtime-config-BpB-d_bF.js +0 -51
  160. package/dist/runtime-config-BpB-d_bF.js.map +0 -1
  161. package/dist/server-CXTQ7odl.js.map +0 -1
  162. package/dist/service-DuFiQwid.js +0 -191
  163. package/dist/service-DuFiQwid.js.map +0 -1
  164. package/dist/service-IE5qaf9x.d.ts +0 -32
  165. package/dist/state-store/index.d.ts +0 -3
  166. package/dist/state-store/index.js +0 -5
  167. package/dist/state-store-yl6LiTQ0.js.map +0 -1
  168. package/dist/status-B-oZBc33.js.map +0 -1
  169. package/dist/types-B35J5YPu.d.ts +0 -174
  170. package/dist/webhook/index.d.ts +0 -6
  171. package/dist/webhook/index.js +0 -8
  172. package/dist/webhook-DI-Afxkg.js +0 -13
  173. package/dist/webhook-DI-Afxkg.js.map +0 -1
  174. package/src/publisher/console.ts +0 -18
  175. package/src/publisher/index.ts +0 -7
  176. package/src/publisher/instrumented.ts +0 -68
  177. package/src/publisher/service.ts +0 -37
  178. package/src/publisher/wings.ts +0 -204
package/dist/index.js DELETED
@@ -1,58 +0,0 @@
1
- import { t as ConnectorError } from "./errors-DHWylqRZ.js";
2
- import { t as auth_exports } from "./auth-DvU_CZ7C.js";
3
- import { t as connector_app_exports } from "./connector-app-d7Z-SZLQ.js";
4
- import { s as metrics_exports } from "./metrics-CWPy2Aqc.js";
5
- import "./constants-BRhIX_rz.js";
6
- import { c as telemetry_exports } from "./service-DuFiQwid.js";
7
- import "./server-CXTQ7odl.js";
8
- import { t as state_store_exports } from "./state-store-yl6LiTQ0.js";
9
- import { t as status_exports } from "./status-B-oZBc33.js";
10
- import { t as ingestion_exports } from "./ingestion-BQo4cbGw.js";
11
- import { t as manifest_exports } from "./manifest-ByE6YPG0.js";
12
- import { t as publisher_exports } from "./publisher-BYT3RLVO.js";
13
- import { t as runtime_config_exports } from "./runtime-config-BpB-d_bF.js";
14
- import { n as webhook_exports } from "./webhook-DI-Afxkg.js";
15
- import { DateTime, Effect } from "effect";
16
-
17
- //#region src/core/builder.ts
18
- const Connector = { define: (definition) => definition };
19
- const Resource = {
20
- entity: (definition) => definition,
21
- webhook: (definition) => definition,
22
- upsert: (row) => ({
23
- op: "upsert",
24
- row
25
- }),
26
- delete: (options) => ({
27
- op: "delete",
28
- key: options.key,
29
- version: options.version
30
- })
31
- };
32
- const Fetch = {
33
- page: (definition) => definition,
34
- changes: (definition) => definition
35
- };
36
- const decodeFailure = (kind, value) => new ConnectorError({ message: `Invalid ${kind} cursor value: ${String(value)}` });
37
- const Cursor = {
38
- string: () => ({
39
- kind: "string",
40
- decode: (value) => typeof value === "string" ? Effect.succeed(value) : Effect.fail(decodeFailure("string", value))
41
- }),
42
- number: () => ({
43
- kind: "number",
44
- decode: (value) => typeof value === "number" && Number.isFinite(value) ? Effect.succeed(value) : Effect.fail(decodeFailure("number", value))
45
- }),
46
- isoDateTime: () => ({
47
- kind: "isoDateTime",
48
- decode: (value) => {
49
- if (typeof value !== "string" || Number.isNaN(Date.parse(value))) return Effect.fail(decodeFailure("ISO datetime", value));
50
- return Effect.succeed(value);
51
- }
52
- }),
53
- nowIsoDateTime: Effect.map(DateTime.now, DateTime.formatIso)
54
- };
55
-
56
- //#endregion
57
- export { auth_exports as Auth, Connector, connector_app_exports as ConnectorApp, ConnectorError, Cursor, Fetch, ingestion_exports as Ingestion, manifest_exports as Manifest, metrics_exports as Metrics, publisher_exports as Publisher, Resource, runtime_config_exports as RuntimeConfig, state_store_exports as StateStore, status_exports as Status, telemetry_exports as Telemetry, webhook_exports as Webhook };
58
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/core/builder.ts"],"sourcesContent":["import { DateTime, Effect } from \"effect\";\n\nimport type {\n ChangesFetch,\n ConnectorDefinition,\n Cursor as CursorType,\n DeleteValue,\n PageFetch,\n ResourceDefinition,\n ResourceMutation,\n ResourceSchema,\n WebhookHandler,\n} from \"./types\";\n\nimport { ConnectorError } from \"../errors\";\n\nexport const Connector = {\n define: <const Resources extends ReadonlyArray<ResourceDefinition>>(\n definition: ConnectorDefinition<Resources>,\n ) => definition,\n};\n\nexport const Resource = {\n entity: <\n S extends ResourceSchema,\n Payload = never,\n R = never,\n const Name extends string = string,\n >(\n definition: ResourceDefinition<S, Payload, R, Name>,\n ): ResourceDefinition<S, Payload, R, Name> => definition,\n\n webhook: <Payload, Row extends object = never>(definition: WebhookHandler<Row, Payload>) =>\n definition,\n\n upsert: <Row extends object>(row: Row): ResourceMutation<Row> => ({ op: \"upsert\", row }),\n\n delete: (options: {\n readonly key: DeleteValue;\n readonly version: DeleteValue;\n }): ResourceMutation<never> => ({\n op: \"delete\",\n key: options.key,\n version: options.version,\n }),\n};\n\nexport const Fetch = {\n page: <Row extends object = never, R = never>(definition: PageFetch<Row, R>) => definition,\n changes: <Row extends object = never, R = never>(definition: ChangesFetch<Row, R>) => definition,\n};\n\nconst decodeFailure = (kind: string, value: unknown) =>\n new ConnectorError({ message: `Invalid ${kind} cursor value: ${String(value)}` });\n\nexport const Cursor = {\n string: (): CursorType.Definition<string> => ({\n kind: \"string\",\n decode: (value) =>\n typeof value === \"string\"\n ? Effect.succeed(value)\n : Effect.fail(decodeFailure(\"string\", value)),\n }),\n\n number: (): CursorType.Definition<number> => ({\n kind: \"number\",\n decode: (value) =>\n typeof value === \"number\" && Number.isFinite(value)\n ? Effect.succeed(value)\n : Effect.fail(decodeFailure(\"number\", value)),\n }),\n\n isoDateTime: (): CursorType.Definition<string> => ({\n kind: \"isoDateTime\",\n decode: (value) => {\n if (typeof value !== \"string\" || Number.isNaN(Date.parse(value))) {\n return Effect.fail(decodeFailure(\"ISO datetime\", value));\n }\n return Effect.succeed(value);\n },\n }),\n\n nowIsoDateTime: Effect.map(DateTime.now, DateTime.formatIso),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAa,YAAY,EACvB,SACE,eACG,YACN;AAED,MAAa,WAAW;CACtB,SAME,eAC4C;CAE9C,UAA+C,eAC7C;CAEF,SAA6B,SAAqC;EAAE,IAAI;EAAU;EAAK;CAEvF,SAAS,aAGuB;EAC9B,IAAI;EACJ,KAAK,QAAQ;EACb,SAAS,QAAQ;EAClB;CACF;AAED,MAAa,QAAQ;CACnB,OAA8C,eAAkC;CAChF,UAAiD,eAAqC;CACvF;AAED,MAAM,iBAAiB,MAAc,UACnC,IAAI,eAAe,EAAE,SAAS,WAAW,KAAK,iBAAiB,OAAO,MAAM,IAAI,CAAC;AAEnF,MAAa,SAAS;CACpB,eAA8C;EAC5C,MAAM;EACN,SAAS,UACP,OAAO,UAAU,WACb,OAAO,QAAQ,MAAM,GACrB,OAAO,KAAK,cAAc,UAAU,MAAM,CAAC;EAClD;CAED,eAA8C;EAC5C,MAAM;EACN,SAAS,UACP,OAAO,UAAU,YAAY,OAAO,SAAS,MAAM,GAC/C,OAAO,QAAQ,MAAM,GACrB,OAAO,KAAK,cAAc,UAAU,MAAM,CAAC;EAClD;CAED,oBAAmD;EACjD,MAAM;EACN,SAAS,UAAU;AACjB,OAAI,OAAO,UAAU,YAAY,OAAO,MAAM,KAAK,MAAM,MAAM,CAAC,CAC9D,QAAO,OAAO,KAAK,cAAc,gBAAgB,MAAM,CAAC;AAE1D,UAAO,OAAO,QAAQ,MAAM;;EAE/B;CAED,gBAAgB,OAAO,IAAI,SAAS,KAAK,SAAS,UAAU;CAC7D"}
@@ -1,6 +0,0 @@
1
- import "../index-D54ySAKn.js";
2
- import "../types-B35J5YPu.js";
3
- import "../service-IE5qaf9x.js";
4
- import "../index-Coh_SkBs.js";
5
- import { n as RunOptions, r as run } from "../index-J42AZaXU.js";
6
- export { RunOptions, run };
@@ -1,10 +0,0 @@
1
- import "../errors-DHWylqRZ.js";
2
- import "../metrics-CWPy2Aqc.js";
3
- import "../constants-BRhIX_rz.js";
4
- import "../service-DuFiQwid.js";
5
- import "../server-CXTQ7odl.js";
6
- import "../state-store-yl6LiTQ0.js";
7
- import "../status-B-oZBc33.js";
8
- import { n as run } from "../ingestion-BQo4cbGw.js";
9
-
10
- export { run };
@@ -1,200 +0,0 @@
1
- import { t as __export } from "./chunk-Bp6m_JJh.js";
2
- import { d as setLastSuccessTimestamp, f as setSyncState, p as setWebhookQueueDepth } from "./metrics-CWPy2Aqc.js";
3
- import { a as SpanName, n as Attr, s as annotateError } from "./service-DuFiQwid.js";
4
- import { n as router, r as publishBatch, t as WebhookQueue } from "./server-CXTQ7odl.js";
5
- import { o as StateStore } from "./state-store-yl6LiTQ0.js";
6
- import { c as deriveSyncState, l as normalizeCursor, s as statusRoute } from "./status-B-oZBc33.js";
7
- import { DateTime, Effect, Layer, Queue } from "effect";
8
- import { HttpRouter, HttpServerResponse } from "effect/unstable/http";
9
- import * as Observability from "effect/unstable/observability";
10
-
11
- //#region src/ingestion/engine.ts
12
- function run(connector, options) {
13
- const queueLayer = makeWebhookQueueLayer(connector.name);
14
- const runtimeLayer = options?.webhook ? Layer.mergeAll(queueLayer, makeWebhookServerLayer(connector, options.webhook).pipe(Layer.provide(queueLayer))) : Layer.empty;
15
- return Effect.gen(function* () {
16
- const initialCutoff = options?.initialCutoff ?? (yield* DateTime.now.pipe(Effect.map(DateTime.formatIso)));
17
- yield* Effect.logInfo("Connector started").pipe(Effect.annotateLogs({
18
- [Attr.connectorName]: connector.name,
19
- resources: connector.resources.length
20
- }));
21
- const sourceRun = runIngestion(connector, initialCutoff);
22
- const webhookRun = options?.webhook ? runWebhookRuntime(connector, options.webhook.routes) : Effect.void;
23
- return yield* Effect.all([sourceRun, webhookRun], { concurrency: "unbounded" }).pipe(Effect.asVoid);
24
- }).pipe(Effect.provide(runtimeLayer));
25
- }
26
- const makeWebhookQueueLayer = (connector) => Layer.effect(WebhookQueue)(Effect.gen(function* () {
27
- const queue = yield* Queue.bounded(1024);
28
- yield* setWebhookQueueDepth(connector, 0);
29
- return WebhookQueue.of({ queue });
30
- }));
31
- const runWebhookRuntime = (connector, routes) => {
32
- const hasAfterEnqueue = routes.some((route) => route.ackMode === "after-enqueue");
33
- return Effect.all([hasAfterEnqueue ? runWebhookQueueConsumer(connector) : Effect.void, Effect.never], { concurrency: "unbounded" }).pipe(Effect.asVoid);
34
- };
35
- const runWebhookQueueConsumer = (connector) => Effect.gen(function* () {
36
- const queue = yield* WebhookQueue;
37
- while (true) {
38
- const batch = yield* Queue.take(queue.queue);
39
- const depth = yield* Queue.size(queue.queue);
40
- yield* setWebhookQueueDepth(connector.name, depth);
41
- yield* publishBatch({
42
- connector: connector.name,
43
- resource: batch.resource,
44
- source: "webhook",
45
- batch: batch.batch
46
- });
47
- }
48
- });
49
- const makeWebhookServerLayer = (connector, options) => {
50
- const healthPath = options.healthPath ?? "/health";
51
- const metricsPath = options.metricsPath === void 0 ? "/metrics" : options.metricsPath;
52
- const statusPath = options.statusPath === void 0 ? "/status" : options.statusPath;
53
- const app = Layer.mergeAll(router(options.routes, { connectorName: connector.name }), HttpRouter.add("GET", healthPath, Effect.succeed(HttpServerResponse.text("ok"))), ...metricsPath === false ? [] : [Observability.PrometheusMetrics.layerHttp({ path: metricsPath })], ...statusPath === false ? [] : [statusRoute(connector, statusPath)]);
54
- return HttpRouter.serve(app, { disableLogger: options.disableHttpLogger ?? true });
55
- };
56
- const runIngestion = (connector, initialCutoff) => Effect.forEach(connector.resources, (resource) => runResourceSources(connector, resource, initialCutoff), { concurrency: "unbounded" }).pipe(Effect.asVoid);
57
- const initializeResourceState = (existing, initialCutoff) => ({
58
- ...existing,
59
- changes: existing?.changes ?? { cursor: initialCutoff },
60
- backfill: existing?.backfill ?? {
61
- cutoff: initialCutoff,
62
- completed: false
63
- }
64
- });
65
- const getInitializedState = Effect.fnUntraced(function* (resource, initialCutoff) {
66
- return initializeResourceState(yield* (yield* StateStore).getResourceState(resource), initialCutoff);
67
- });
68
- const runResourceSources = (connector, resource, initialCutoff) => {
69
- const runs = [resource.backfill ? isolateSourceFailure(runBackfill(connector, resource, initialCutoff), connector, resource, "backfill") : Effect.void, resource.changes ? isolateSourceFailure(runChanges(connector, resource, initialCutoff), connector, resource, "changes") : Effect.void];
70
- return initializeRuntimeStatus(connector, resource, initialCutoff).pipe(Effect.andThen(Effect.all(runs, { concurrency: "unbounded" })), Effect.asVoid, Effect.catch(() => setSyncState({
71
- connector: connector.name,
72
- resource: resource.name
73
- }, "error").pipe(Effect.andThen(Effect.logError("Connector resource initialization failed")), Effect.annotateLogs({
74
- [Attr.connectorName]: connector.name,
75
- resource: resource.name
76
- }), Effect.andThen(Effect.never))));
77
- };
78
- const recordResourceError = (connector, resource, source, operation) => (effect) => effect.pipe(Effect.tapError(() => setSyncState({
79
- connector: connector.name,
80
- resource: resource.name
81
- }, "error").pipe(Effect.andThen(StateStore.pipe(Effect.flatMap((store) => store.setResourceError(resource.name, source, operation)))))));
82
- const isolateSourceFailure = (effect, connector, resource, source) => effect.pipe(Effect.catch(() => Effect.logError("Connector source parked").pipe(Effect.annotateLogs({
83
- [Attr.connectorName]: connector.name,
84
- resource: resource.name,
85
- source
86
- }), Effect.andThen(Effect.never))));
87
- const refreshRuntimeStatus = Effect.fnUntraced(function* (connector, resource, initialCutoff) {
88
- const state = yield* getInitializedState(resource.name, initialCutoff);
89
- yield* setSyncState({
90
- connector: connector.name,
91
- resource: resource.name
92
- }, deriveSyncState(resource, state));
93
- return state;
94
- });
95
- const initializeRuntimeStatus = Effect.fnUntraced(function* (connector, resource, initialCutoff) {
96
- const state = yield* getInitializedState(resource.name, initialCutoff);
97
- yield* setSyncState({
98
- connector: connector.name,
99
- resource: resource.name
100
- }, deriveSyncState(resource, state));
101
- if (resource.backfill) yield* setLastSuccessTimestamp({
102
- connector: connector.name,
103
- resource: resource.name,
104
- source: "backfill"
105
- }, state.backfill?.lastSuccessAt);
106
- if (resource.changes) yield* setLastSuccessTimestamp({
107
- connector: connector.name,
108
- resource: resource.name,
109
- source: "changes"
110
- }, state.changes?.lastSuccessAt);
111
- });
112
- const runBackfill = Effect.fnUntraced(function* (connector, resource, initialCutoff) {
113
- if (!resource.backfill) return;
114
- const store = yield* StateStore;
115
- let state = yield* getInitializedState(resource.name, initialCutoff);
116
- if (state.backfill?.completed === true) {
117
- yield* store.clearResourceError(resource.name, "backfill").pipe(recordResourceError(connector, resource, "backfill", "checkpoint"));
118
- yield* refreshRuntimeStatus(connector, resource, initialCutoff);
119
- return;
120
- }
121
- while (state.backfill?.completed !== true) {
122
- const backfill = state.backfill ?? {
123
- cutoff: initialCutoff,
124
- completed: false
125
- };
126
- const clearsVisibleError = state.lastError?.source === "backfill";
127
- const page = yield* resource.backfill.fetch({
128
- pageCursor: backfill.pageCursor,
129
- cutoff: backfill.cutoff
130
- }).pipe(recordResourceError(connector, resource, "backfill", "fetch"));
131
- yield* publishBatch({
132
- connector: connector.name,
133
- resource: resource.name,
134
- source: "backfill",
135
- batch: {
136
- cursor: page.nextPageCursor ?? backfill.cutoff,
137
- mutations: page.mutations
138
- }
139
- }).pipe(recordResourceError(connector, resource, "backfill", "publish"));
140
- const lastSuccessAt = yield* DateTime.now.pipe(Effect.map(DateTime.formatIso));
141
- state = {
142
- ...state,
143
- backfill: {
144
- cutoff: backfill.cutoff,
145
- pageCursor: page.nextPageCursor,
146
- completed: !page.hasMore,
147
- lastSuccessAt
148
- }
149
- };
150
- yield* Effect.withSpan(store.setBackfillState(resource.name, {
151
- cutoff: normalizeCursor(backfill.cutoff),
152
- pageCursor: page.nextPageCursor === void 0 ? void 0 : normalizeCursor(page.nextPageCursor),
153
- completed: !page.hasMore,
154
- lastSuccessAt
155
- }).pipe(Effect.andThen(setLastSuccessTimestamp({
156
- connector: connector.name,
157
- resource: resource.name,
158
- source: "backfill"
159
- }, lastSuccessAt)), Effect.andThen(store.clearResourceError(resource.name, "backfill")), Effect.tapError((error) => annotateError("state_set", error))), SpanName.stateSet, { attributes: { [Attr.stateKey]: resource.name } }).pipe(recordResourceError(connector, resource, "backfill", "checkpoint"));
160
- if (clearsVisibleError || !page.hasMore) state = yield* refreshRuntimeStatus(connector, resource, initialCutoff);
161
- }
162
- });
163
- const runChanges = Effect.fnUntraced(function* (connector, resource, initialCutoff) {
164
- if (!resource.changes) return;
165
- const store = yield* StateStore;
166
- while (true) {
167
- const state = yield* getInitializedState(resource.name, initialCutoff);
168
- const cursor = state.changes?.cursor ?? initialCutoff;
169
- const clearsVisibleError = state.lastError?.source === "changes";
170
- const page = yield* resource.changes.fetch({ cursor }).pipe(recordResourceError(connector, resource, "changes", "fetch"));
171
- yield* publishBatch({
172
- connector: connector.name,
173
- resource: resource.name,
174
- source: "changes",
175
- batch: {
176
- cursor: page.cursor,
177
- mutations: page.mutations
178
- }
179
- }).pipe(recordResourceError(connector, resource, "changes", "publish"));
180
- const lastSuccessAt = yield* DateTime.now.pipe(Effect.map(DateTime.formatIso));
181
- yield* Effect.withSpan(store.setChangesState(resource.name, {
182
- cursor: normalizeCursor(page.cursor),
183
- lastSuccessAt
184
- }).pipe(Effect.andThen(setLastSuccessTimestamp({
185
- connector: connector.name,
186
- resource: resource.name,
187
- source: "changes"
188
- }, lastSuccessAt)), Effect.andThen(store.clearResourceError(resource.name, "changes")), Effect.tapError((error) => annotateError("state_set", error))), SpanName.stateSet, { attributes: { [Attr.stateKey]: resource.name } }).pipe(recordResourceError(connector, resource, "changes", "checkpoint"));
189
- if (clearsVisibleError) yield* refreshRuntimeStatus(connector, resource, initialCutoff);
190
- yield* Effect.sleep(resource.changes.interval ?? "1 minute");
191
- }
192
- });
193
-
194
- //#endregion
195
- //#region src/ingestion/index.ts
196
- var ingestion_exports = /* @__PURE__ */ __export({ run: () => run });
197
-
198
- //#endregion
199
- export { run as n, ingestion_exports as t };
200
- //# sourceMappingURL=ingestion-BQo4cbGw.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ingestion-BQo4cbGw.js","names":["Metrics.setWebhookQueueDepth","healthPath: HttpRouter.PathInput","Metrics.setSyncState","Metrics.setLastSuccessTimestamp"],"sources":["../src/ingestion/engine.ts","../src/ingestion/index.ts"],"sourcesContent":["import { DateTime, Effect, Layer, Queue } from \"effect\";\nimport { HttpRouter, type HttpServer, HttpServerResponse } from \"effect/unstable/http\";\nimport * as Observability from \"effect/unstable/observability\";\n\nimport type {\n ConnectorDefinition,\n Cursor,\n ResourceDefinition,\n ResourceState,\n WebhookRoute,\n} from \"../core/types\";\nimport type { StateOperation, StateSource } from \"../state-store/schema\";\n\nimport { ConnectorError } from \"../errors\";\nimport * as Metrics from \"../metrics\";\nimport { publishBatch } from \"../publisher/instrumented\";\nimport { Publisher } from \"../publisher/service\";\nimport { StateStore } from \"../state-store\";\nimport { deriveSyncState, normalizeCursor } from \"../state-store/state\";\nimport { statusRoute } from \"../status\";\nimport { Attr, SpanName, annotateError } from \"../telemetry\";\nimport { router, WebhookQueue, type QueuedWebhookBatch } from \"../webhook/server\";\n\ntype RunBaseOptions = {\n readonly initialCutoff?: Cursor.Value;\n};\n\nexport type RunOptions = RunBaseOptions & {\n readonly webhook?: {\n readonly routes: ReadonlyArray<WebhookRoute>;\n readonly healthPath?: HttpRouter.PathInput;\n readonly metricsPath?: HttpRouter.PathInput | false;\n readonly statusPath?: HttpRouter.PathInput | false;\n readonly disableHttpLogger?: boolean;\n };\n};\n\ntype RunNoWebhookOptions = RunBaseOptions & {\n readonly webhook?: undefined;\n};\n\ntype RunWebhookOptions = RunOptions & {\n readonly webhook: NonNullable<RunOptions[\"webhook\"]>;\n};\n\n/**\n * Runs all connector ingestion loops. Callers provide the Publisher and\n * StateStore layers; webhook mode additionally requires an HttpServer layer.\n */\nexport function run<const Resources extends ReadonlyArray<ResourceDefinition>>(\n connector: ConnectorDefinition<Resources>,\n options?: RunNoWebhookOptions,\n): Effect.Effect<void, ConnectorError, StateStore | Publisher>;\nexport function run<const Resources extends ReadonlyArray<ResourceDefinition>>(\n connector: ConnectorDefinition<Resources>,\n options: RunWebhookOptions,\n): Effect.Effect<void, ConnectorError, StateStore | Publisher | HttpServer.HttpServer>;\nexport function run(connector: ConnectorDefinition, options?: RunOptions) {\n const queueLayer = makeWebhookQueueLayer(connector.name);\n const runtimeLayer = options?.webhook\n ? Layer.mergeAll(\n queueLayer,\n makeWebhookServerLayer(connector, options.webhook).pipe(Layer.provide(queueLayer)),\n )\n : Layer.empty;\n\n return Effect.gen(function* () {\n const initialCutoff =\n options?.initialCutoff ?? (yield* DateTime.now.pipe(Effect.map(DateTime.formatIso)));\n yield* Effect.logInfo(\"Connector started\").pipe(\n Effect.annotateLogs({\n [Attr.connectorName]: connector.name,\n resources: connector.resources.length,\n }),\n );\n\n const sourceRun = runIngestion(connector, initialCutoff);\n const webhookRun = options?.webhook\n ? runWebhookRuntime(connector, options.webhook.routes)\n : Effect.void;\n\n return yield* Effect.all([sourceRun, webhookRun], { concurrency: \"unbounded\" }).pipe(\n Effect.asVoid,\n );\n }).pipe(Effect.provide(runtimeLayer));\n}\n\nconst makeWebhookQueueLayer = (connector: string): Layer.Layer<WebhookQueue> =>\n Layer.effect(WebhookQueue)(\n Effect.gen(function* () {\n const queue = yield* Queue.bounded<QueuedWebhookBatch>(1024);\n yield* Metrics.setWebhookQueueDepth(connector, 0);\n return WebhookQueue.of({ queue });\n }),\n );\n\nconst runWebhookRuntime = (connector: ConnectorDefinition, routes: ReadonlyArray<WebhookRoute>) => {\n const hasAfterEnqueue = routes.some((route) => route.ackMode === \"after-enqueue\");\n return Effect.all(\n [hasAfterEnqueue ? runWebhookQueueConsumer(connector) : Effect.void, Effect.never],\n {\n concurrency: \"unbounded\",\n },\n ).pipe(Effect.asVoid);\n};\n\nconst runWebhookQueueConsumer = (connector: ConnectorDefinition) =>\n Effect.gen(function* () {\n const queue = yield* WebhookQueue;\n while (true) {\n const batch = yield* Queue.take(queue.queue);\n const depth = yield* Queue.size(queue.queue);\n yield* Metrics.setWebhookQueueDepth(connector.name, depth);\n yield* publishBatch({\n connector: connector.name,\n resource: batch.resource,\n source: \"webhook\",\n batch: batch.batch,\n });\n }\n });\n\nconst makeWebhookServerLayer = (\n connector: ConnectorDefinition,\n options: {\n readonly routes: ReadonlyArray<WebhookRoute>;\n readonly healthPath?: HttpRouter.PathInput;\n readonly metricsPath?: HttpRouter.PathInput | false;\n readonly statusPath?: HttpRouter.PathInput | false;\n readonly disableHttpLogger?: boolean;\n },\n): Layer.Layer<never, never, HttpServer.HttpServer> => {\n const healthPath: HttpRouter.PathInput = options.healthPath ?? \"/health\";\n const metricsPath = options.metricsPath === undefined ? \"/metrics\" : options.metricsPath;\n const statusPath = options.statusPath === undefined ? \"/status\" : options.statusPath;\n const app = Layer.mergeAll(\n router(options.routes, { connectorName: connector.name }),\n HttpRouter.add(\"GET\", healthPath, Effect.succeed(HttpServerResponse.text(\"ok\"))),\n ...(metricsPath === false\n ? []\n : [Observability.PrometheusMetrics.layerHttp({ path: metricsPath })]),\n ...(statusPath === false ? [] : [statusRoute(connector, statusPath)]),\n );\n\n return HttpRouter.serve(app, {\n disableLogger: options.disableHttpLogger ?? true,\n });\n};\n\nconst runIngestion = (\n connector: ConnectorDefinition,\n initialCutoff: Cursor.Value,\n): Effect.Effect<void, ConnectorError, StateStore | Publisher> =>\n Effect.forEach(\n connector.resources,\n (resource) => runResourceSources(connector, resource, initialCutoff),\n {\n concurrency: \"unbounded\",\n },\n ).pipe(Effect.asVoid);\n\nconst initializeResourceState = (\n existing: ResourceState | undefined,\n initialCutoff: Cursor.Value,\n): ResourceState => ({\n ...existing,\n changes: existing?.changes ?? { cursor: initialCutoff },\n backfill: existing?.backfill ?? {\n cutoff: initialCutoff,\n completed: false,\n },\n});\n\nconst getInitializedState = Effect.fnUntraced(function* (\n resource: string,\n initialCutoff: Cursor.Value,\n) {\n const store = yield* StateStore;\n const existing = yield* store.getResourceState(resource);\n return initializeResourceState(existing, initialCutoff);\n});\n\nconst runResourceSources = (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n initialCutoff: Cursor.Value,\n) => {\n const runs = [\n resource.backfill\n ? isolateSourceFailure(\n runBackfill(connector, resource, initialCutoff),\n connector,\n resource,\n \"backfill\",\n )\n : Effect.void,\n resource.changes\n ? isolateSourceFailure(\n runChanges(connector, resource, initialCutoff),\n connector,\n resource,\n \"changes\",\n )\n : Effect.void,\n ];\n\n return initializeRuntimeStatus(connector, resource, initialCutoff).pipe(\n Effect.andThen(Effect.all(runs, { concurrency: \"unbounded\" })),\n Effect.asVoid,\n Effect.catch(() =>\n Metrics.setSyncState({ connector: connector.name, resource: resource.name }, \"error\").pipe(\n Effect.andThen(Effect.logError(\"Connector resource initialization failed\")),\n Effect.annotateLogs({\n [Attr.connectorName]: connector.name,\n resource: resource.name,\n }),\n Effect.andThen(Effect.never),\n ),\n ),\n );\n};\n\nconst recordResourceError =\n (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n source: StateSource,\n operation: StateOperation,\n ) =>\n <A, R>(\n effect: Effect.Effect<A, ConnectorError, R>,\n ): Effect.Effect<A, ConnectorError, R | StateStore> =>\n effect.pipe(\n Effect.tapError(() =>\n Metrics.setSyncState({ connector: connector.name, resource: resource.name }, \"error\").pipe(\n Effect.andThen(\n StateStore.pipe(\n Effect.flatMap((store) => store.setResourceError(resource.name, source, operation)),\n ),\n ),\n ),\n ),\n );\n\nconst isolateSourceFailure = <A, R>(\n effect: Effect.Effect<A, ConnectorError, R>,\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n source: StateSource,\n): Effect.Effect<A, never, R> =>\n // Only typed source errors are isolated. Defects and interruption still stop the runtime.\n effect.pipe(\n Effect.catch(() =>\n Effect.logError(\"Connector source parked\").pipe(\n Effect.annotateLogs({\n [Attr.connectorName]: connector.name,\n resource: resource.name,\n source,\n }),\n Effect.andThen(Effect.never),\n ),\n ),\n );\n\nconst refreshRuntimeStatus = Effect.fnUntraced(function* (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n initialCutoff: Cursor.Value,\n) {\n const state = yield* getInitializedState(resource.name, initialCutoff);\n yield* Metrics.setSyncState(\n { connector: connector.name, resource: resource.name },\n deriveSyncState(resource, state),\n );\n return state;\n});\n\nconst initializeRuntimeStatus = Effect.fnUntraced(function* (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n initialCutoff: Cursor.Value,\n) {\n const state = yield* getInitializedState(resource.name, initialCutoff);\n yield* Metrics.setSyncState(\n { connector: connector.name, resource: resource.name },\n deriveSyncState(resource, state),\n );\n if (resource.backfill) {\n yield* Metrics.setLastSuccessTimestamp(\n { connector: connector.name, resource: resource.name, source: \"backfill\" },\n state.backfill?.lastSuccessAt,\n );\n }\n if (resource.changes) {\n yield* Metrics.setLastSuccessTimestamp(\n { connector: connector.name, resource: resource.name, source: \"changes\" },\n state.changes?.lastSuccessAt,\n );\n }\n});\n\nconst runBackfill = Effect.fnUntraced(function* (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n initialCutoff: Cursor.Value,\n) {\n if (!resource.backfill) return;\n const store = yield* StateStore;\n let state = yield* getInitializedState(resource.name, initialCutoff);\n\n if (state.backfill?.completed === true) {\n // The checkpoint may have committed before the previous process cleared\n // its error marker. It may also be hidden by a newer changes error.\n yield* store\n .clearResourceError(resource.name, \"backfill\")\n .pipe(recordResourceError(connector, resource, \"backfill\", \"checkpoint\"));\n yield* refreshRuntimeStatus(connector, resource, initialCutoff);\n return;\n }\n\n while (state.backfill?.completed !== true) {\n const backfill = state.backfill ?? { cutoff: initialCutoff, completed: false };\n const clearsVisibleError = state.lastError?.source === \"backfill\";\n const page = yield* resource.backfill\n .fetch({\n pageCursor: backfill.pageCursor,\n cutoff: backfill.cutoff,\n })\n .pipe(recordResourceError(connector, resource, \"backfill\", \"fetch\"));\n\n yield* publishBatch({\n connector: connector.name,\n resource: resource.name,\n source: \"backfill\",\n batch: {\n cursor: page.nextPageCursor ?? backfill.cutoff,\n mutations: page.mutations,\n },\n }).pipe(recordResourceError(connector, resource, \"backfill\", \"publish\"));\n\n const lastSuccessAt = yield* DateTime.now.pipe(Effect.map(DateTime.formatIso));\n state = {\n ...state,\n backfill: {\n cutoff: backfill.cutoff,\n pageCursor: page.nextPageCursor,\n completed: !page.hasMore,\n lastSuccessAt,\n },\n };\n\n // Checkpoint only after publish succeeds so a crash cannot skip an\n // unacknowledged page; replay therefore remains at-least-once.\n yield* Effect.withSpan(\n store\n .setBackfillState(resource.name, {\n cutoff: normalizeCursor(backfill.cutoff),\n pageCursor:\n page.nextPageCursor === undefined ? undefined : normalizeCursor(page.nextPageCursor),\n completed: !page.hasMore,\n lastSuccessAt,\n })\n .pipe(\n Effect.andThen(\n Metrics.setLastSuccessTimestamp(\n { connector: connector.name, resource: resource.name, source: \"backfill\" },\n lastSuccessAt,\n ),\n ),\n Effect.andThen(store.clearResourceError(resource.name, \"backfill\")),\n Effect.tapError((error) => annotateError(\"state_set\", error)),\n ),\n SpanName.stateSet,\n { attributes: { [Attr.stateKey]: resource.name } },\n ).pipe(recordResourceError(connector, resource, \"backfill\", \"checkpoint\"));\n\n // Completion or clearing an error can change the resource-wide sync state.\n if (clearsVisibleError || !page.hasMore) {\n state = yield* refreshRuntimeStatus(connector, resource, initialCutoff);\n }\n }\n});\n\nconst runChanges = Effect.fnUntraced(function* (\n connector: ConnectorDefinition,\n resource: ResourceDefinition,\n initialCutoff: Cursor.Value,\n) {\n if (!resource.changes) return;\n const store = yield* StateStore;\n\n while (true) {\n const state = yield* getInitializedState(resource.name, initialCutoff);\n const cursor = state.changes?.cursor ?? initialCutoff;\n const clearsVisibleError = state.lastError?.source === \"changes\";\n const page = yield* resource.changes\n .fetch({ cursor })\n .pipe(recordResourceError(connector, resource, \"changes\", \"fetch\"));\n\n yield* publishBatch({\n connector: connector.name,\n resource: resource.name,\n source: \"changes\",\n batch: {\n cursor: page.cursor,\n mutations: page.mutations,\n },\n }).pipe(recordResourceError(connector, resource, \"changes\", \"publish\"));\n\n const lastSuccessAt = yield* DateTime.now.pipe(Effect.map(DateTime.formatIso));\n // Advance the durable cursor only after Wings accepts the page.\n yield* Effect.withSpan(\n store\n .setChangesState(resource.name, {\n cursor: normalizeCursor(page.cursor),\n lastSuccessAt,\n })\n .pipe(\n Effect.andThen(\n Metrics.setLastSuccessTimestamp(\n { connector: connector.name, resource: resource.name, source: \"changes\" },\n lastSuccessAt,\n ),\n ),\n Effect.andThen(store.clearResourceError(resource.name, \"changes\")),\n Effect.tapError((error) => annotateError(\"state_set\", error)),\n ),\n SpanName.stateSet,\n { attributes: { [Attr.stateKey]: resource.name } },\n ).pipe(recordResourceError(connector, resource, \"changes\", \"checkpoint\"));\n\n if (clearsVisibleError) {\n yield* refreshRuntimeStatus(connector, resource, initialCutoff);\n }\n\n yield* Effect.sleep(resource.changes.interval ?? \"1 minute\");\n }\n});\n","export { run, type RunOptions } from \"./engine\";\n"],"mappings":";;;;;;;;;;;AAyDA,SAAgB,IAAI,WAAgC,SAAsB;CACxE,MAAM,aAAa,sBAAsB,UAAU,KAAK;CACxD,MAAM,eAAe,SAAS,UAC1B,MAAM,SACJ,YACA,uBAAuB,WAAW,QAAQ,QAAQ,CAAC,KAAK,MAAM,QAAQ,WAAW,CAAC,CACnF,GACD,MAAM;AAEV,QAAO,OAAO,IAAI,aAAa;EAC7B,MAAM,gBACJ,SAAS,kBAAkB,OAAO,SAAS,IAAI,KAAK,OAAO,IAAI,SAAS,UAAU,CAAC;AACrF,SAAO,OAAO,QAAQ,oBAAoB,CAAC,KACzC,OAAO,aAAa;IACjB,KAAK,gBAAgB,UAAU;GAChC,WAAW,UAAU,UAAU;GAChC,CAAC,CACH;EAED,MAAM,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,CAAC,EAClE,OAAO,UAAU,UAAU,cAAc,aAAa,MAAM,CAAC,CAC9D,EACH,SAAS,UACT,EAAE,YAAY,GAAG,KAAK,WAAW,SAAS,MAAM,EAAE,CACnD,CAAC,KAAK,oBAAoB,WAAW,UAAU,WAAW,aAAa,CAAC;AAEzE,MAAI,mBACF,QAAO,qBAAqB,WAAW,UAAU,cAAc;AAGjE,SAAO,OAAO,MAAM,SAAS,QAAQ,YAAY,WAAW;;EAE9D"}
@@ -1,2 +0,0 @@
1
- import { _ as number, a as configSchema, b as select, c as ConnectorManifest, d as ConfigField, f as ConfigFieldSpec, g as define$1, h as boolean, i as RuntimeConfigDocument, l as ResourceCapability, m as ConnectorConfigDef, n as ConnectorConfigSchema, o as decodeConfig, p as ConfigValuesOf, r as ConnectorConfigValues, s as toRuntimeDocument, u as define, v as optional, x as string, y as secret } from "../index-CBT-JX-T.js";
2
- export { ConfigField, ConfigFieldSpec, ConfigValuesOf, ConnectorConfigDef, ConnectorConfigSchema, ConnectorConfigValues, ConnectorManifest, ResourceCapability, RuntimeConfigDocument, boolean, configSchema, decodeConfig, define, define$1 as defineConfig, number, optional, secret, select, string, toRuntimeDocument };
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest-ByE6YPG0.js","names":["define","document: Record<string, string | number | boolean>","value: unknown"],"sources":["../src/manifest/number-schema.ts","../src/manifest/config.ts","../src/manifest/manifest.ts","../src/manifest/schema.ts","../src/manifest/index.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport type NumberConstraints = {\n readonly integer?: boolean;\n readonly minimum?: number;\n};\n\nexport const makeNumberSchema = (constraints: NumberConstraints) => {\n if (constraints.integer) {\n return constraints.minimum === undefined\n ? Schema.Int\n : Schema.Int.check(Schema.isGreaterThanOrEqualTo(constraints.minimum));\n }\n return constraints.minimum === undefined\n ? Schema.Finite\n : Schema.Finite.check(Schema.isGreaterThanOrEqualTo(constraints.minimum));\n};\n","import { Config, Option, Redacted, Schema, Struct } from \"effect\";\n\nimport { isPlatformRuntimeKey } from \"../runtime-config/constants\";\nimport { makeNumberSchema, type NumberConstraints } from \"./number-schema\";\n\ntype ConfigFieldSpecBase = {\n readonly runtimeKey: string;\n readonly required: boolean;\n readonly description?: string;\n};\n\ntype ConfigFieldDefinition = ConfigFieldSpecBase &\n (\n | {\n readonly type: \"string\";\n readonly secret: false;\n readonly default?: string;\n readonly values?: never;\n }\n | {\n readonly type: \"string\";\n readonly secret: true;\n readonly default?: never;\n readonly values?: never;\n }\n | {\n readonly type: \"number\";\n readonly secret: false;\n readonly default?: number;\n readonly values?: never;\n readonly integer?: boolean;\n readonly minimum?: number;\n }\n | {\n readonly type: \"boolean\";\n readonly secret: false;\n readonly default?: boolean;\n readonly values?: never;\n }\n | {\n readonly type: \"select\";\n readonly secret: false;\n readonly default?: string;\n readonly values: readonly [string, ...Array<string>];\n }\n );\n\n/** Serializable, browser-safe metadata for one user-provided connector setting. */\nexport type ConfigFieldSpec = ConfigFieldDefinition & { readonly name: string };\n\n/** Pairs an Effect runtime config with the metadata used to generate its form field. */\nexport type ConfigField<A> = {\n readonly config: Config.Config<A>;\n readonly spec: ConfigFieldDefinition;\n};\n\ntype FieldBaseOptions = {\n readonly runtimeKey: string;\n readonly description?: string;\n};\n\ntype FieldOptions<A extends string | number | boolean = string | number | boolean> =\n FieldBaseOptions &\n (\n | {\n readonly required?: true;\n readonly default?: A;\n }\n | {\n readonly required: false;\n readonly default: A;\n }\n );\n\ntype NumberFieldOptions = FieldOptions<number> & NumberConstraints;\n\ntype FieldsRecord = Record<string, ConfigField<unknown>>;\n\n/** Preserves each field's value type while `Struct.map` extracts its Effect Config. */\ninterface ConfigFieldToConfig extends Struct.Lambda {\n <A>(field: ConfigField<A>): Config.Config<A>;\n readonly \"~lambda.out\": this[\"~lambda.in\"] extends ConfigField<infer A>\n ? Config.Config<A>\n : never;\n}\n\nconst configFieldToConfig = Struct.lambda<ConfigFieldToConfig>((field) => field.config);\n\ntype ConfigOf<Fields extends FieldsRecord> = {\n readonly [Key in keyof Fields]: Fields[Key] extends ConfigField<infer A> ? A : never;\n};\n\n/** Effect config and serializable manifest metadata produced from one field definition. */\nexport type ConnectorConfigDef<Fields extends FieldsRecord> = {\n readonly fields: {\n readonly [Key in keyof Fields]: Fields[Key] extends ConfigField<infer A>\n ? Config.Config<A>\n : never;\n };\n readonly config: Config.Config<ConfigOf<Fields>>;\n readonly spec: ReadonlyArray<ConfigFieldSpec>;\n};\n\nexport type ConfigValuesOf<Def extends ConnectorConfigDef<FieldsRecord>> =\n Def extends ConnectorConfigDef<infer Fields> ? ConfigOf<Fields> : never;\n\nconst withDefault = <A extends string | number | boolean>(\n config: Config.Config<A>,\n defaultValue: A | undefined,\n) => (defaultValue === undefined ? config : Config.withDefault(config, defaultValue));\n\n/** Defines a required non-empty string, optionally with a default. */\nexport const string = (options: FieldOptions<string>): ConfigField<string> => ({\n config: withDefault(Config.nonEmptyString(options.runtimeKey), options.default),\n spec: {\n runtimeKey: options.runtimeKey,\n type: \"string\",\n required: options.required ?? true,\n secret: false,\n ...(options.description !== undefined ? { description: options.description } : {}),\n ...(options.default !== undefined ? { default: options.default } : {}),\n },\n});\n\n/** Defines a finite number with optional integer, minimum, and default constraints. */\nexport const number = (options: NumberFieldOptions): ConfigField<number> => {\n const schema = makeNumberSchema(options);\n const defaultValue =\n options.default === undefined ? undefined : Schema.decodeUnknownSync(schema)(options.default);\n\n return {\n config: withDefault(Config.schema(schema, options.runtimeKey), defaultValue),\n spec: {\n runtimeKey: options.runtimeKey,\n type: \"number\",\n required: options.required ?? true,\n secret: false,\n ...(options.description !== undefined ? { description: options.description } : {}),\n ...(defaultValue !== undefined ? { default: defaultValue } : {}),\n ...(options.integer !== undefined ? { integer: options.integer } : {}),\n ...(options.minimum !== undefined ? { minimum: options.minimum } : {}),\n },\n };\n};\n\n/** Defines a boolean, optionally with a default. */\nexport const boolean = (options: FieldOptions<boolean>): ConfigField<boolean> => ({\n config: withDefault(Config.boolean(options.runtimeKey), options.default),\n spec: {\n runtimeKey: options.runtimeKey,\n type: \"boolean\",\n required: options.required ?? true,\n secret: false,\n ...(options.description !== undefined ? { description: options.description } : {}),\n ...(options.default !== undefined ? { default: options.default } : {}),\n },\n});\n\n/** Defines a string literal choice whose values are preserved in the inferred type. */\nexport const select = <const Values extends readonly [string, ...Array<string>]>(\n options: FieldOptions<Values[number]> & { readonly values: Values },\n): ConfigField<Values[number]> => ({\n config: withDefault(Config.literals(options.values, options.runtimeKey), options.default),\n spec: {\n runtimeKey: options.runtimeKey,\n type: \"select\",\n required: options.required ?? true,\n secret: false,\n values: options.values,\n ...(options.description !== undefined ? { description: options.description } : {}),\n ...(options.default !== undefined ? { default: options.default } : {}),\n },\n});\n\n/** Defines a required, non-empty secret decoded as `Redacted<string>`. */\nexport const secret = (\n options: FieldBaseOptions & { readonly required?: true },\n): ConfigField<Redacted.Redacted<string>> => ({\n config: Config.schema(Schema.Redacted(Schema.NonEmptyString), options.runtimeKey),\n spec: {\n runtimeKey: options.runtimeKey,\n type: \"string\",\n required: options.required ?? true,\n secret: true,\n ...(options.description !== undefined ? { description: options.description } : {}),\n },\n});\n\n/** Makes an existing field optional and represents a missing value as `Option.none()`. */\nexport const optional = <A>(field: ConfigField<A>): ConfigField<Option.Option<A>> => ({\n config: Config.option(field.config),\n spec: {\n ...field.spec,\n required: false,\n },\n});\n\n/**\n * Defines user-facing connector config once for both Effect runtime loading and\n * frontend form generation. The object keys become logical form/API field names;\n * `runtimeKey` remains the key read by Effect Config.\n *\n * @example\n * ```ts\n * const config = define({\n * apiUrl: string({ runtimeKey: \"API_URL\" }),\n * token: secret({ runtimeKey: \"API_TOKEN\" }),\n * });\n *\n * const RuntimeConfig = config.config;\n * const formFields = config.spec;\n * ```\n */\nexport const define = <const Fields extends FieldsRecord>(\n fields: Fields,\n): ConnectorConfigDef<Fields> => {\n const spec = Object.entries(fields).map(([name, field]) => ({ name, ...field.spec }));\n const platformField = spec.find((field) => isPlatformRuntimeKey(field.runtimeKey));\n if (platformField !== undefined) {\n throw new Error(`Connector runtime key is platform-owned: ${platformField.runtimeKey}`);\n }\n\n const configFields = Struct.map(fields, configFieldToConfig);\n\n return {\n fields: configFields,\n // Effect's recursive Config.Wrap cannot reduce this generic mapped type,\n // although ConfigFieldToConfig preserves the value type of every property.\n config: Config.unwrap(configFields as Config.Wrap<ConfigOf<Fields>>),\n spec,\n };\n};\n","import type { ConfigFieldSpec } from \"./config\";\n\nexport type ResourceCapability = \"backfill\" | \"changes\" | \"webhook\";\n\n/** Browser-safe connector metadata consumed by the platform and runtime adapters. */\nexport type ConnectorManifest = {\n readonly name: string;\n readonly title: string;\n readonly description?: string;\n readonly config: ReadonlyArray<ConfigFieldSpec>;\n readonly resources: ReadonlyArray<{\n readonly name: string;\n readonly capabilities: ReadonlyArray<ResourceCapability>;\n }>;\n};\n\n/**\n * Defines browser-safe connector metadata while preserving literal names and capabilities.\n *\n * @example\n * ```ts\n * const manifest = define({\n * name: \"producer-example\",\n * title: \"Example\",\n * config: ExampleConfig.spec,\n * resources: [{ name: \"orders\", capabilities: [\"backfill\"] }],\n * });\n * ```\n */\nexport const define = <const Manifest extends ConnectorManifest>(manifest: Manifest): Manifest =>\n manifest;\n","import { Predicate, Schema, SchemaTransformation, type Types } from \"effect\";\n\nimport type { ConfigFieldSpec } from \"./config\";\nimport type { ConnectorManifest } from \"./manifest\";\n\nimport { makeNumberSchema } from \"./number-schema\";\n\ntype FieldValueOf<Field extends ConfigFieldSpec> = Field[\"type\"] extends \"number\"\n ? number\n : Field[\"type\"] extends \"boolean\"\n ? boolean\n : Field[\"values\"] extends ReadonlyArray<string>\n ? Field[\"values\"][number]\n : string;\n\nexport type ConnectorConfigValues<Manifest extends ConnectorManifest> = Types.Simplify<\n {\n readonly [Field in Manifest[\"config\"][number] as Field[\"required\"] extends true\n ? Field[\"name\"]\n : never]: FieldValueOf<Field>;\n } & {\n readonly [Field in Manifest[\"config\"][number] as Field[\"required\"] extends true\n ? never\n : Field[\"name\"]]?: FieldValueOf<Field> | undefined;\n }\n> &\n object;\n\nexport type ConnectorConfigSchema<Manifest extends ConnectorManifest> = Schema.Codec<\n ConnectorConfigValues<Manifest>,\n unknown\n>;\n\n/** Flat primitive document keyed by the runtime keys consumed by Effect Config. */\nexport type RuntimeConfigDocument = Readonly<Record<string, string | number | boolean>>;\n\n// Browser forms submit numbers and booleans as strings, while API callers may\n// already send their canonical JSON representations. These schemas accept both.\nconst numberFromForm = (field: Extract<ConfigFieldSpec, { readonly type: \"number\" }>) => {\n const numberSchema = makeNumberSchema(field);\n return Schema.Union([\n numberSchema,\n Schema.NonEmptyString.pipe(\n Schema.decodeTo(numberSchema, SchemaTransformation.numberFromString),\n ),\n ]);\n};\n\nconst BooleanFromForm = Schema.Union([\n Schema.Boolean,\n Schema.Literals([\"true\", \"false\"]).pipe(\n Schema.decodeTo(\n Schema.Boolean,\n SchemaTransformation.transform({\n decode: (value) => value === \"true\",\n encode: (value) => (value ? \"true\" : \"false\"),\n }),\n ),\n ),\n]);\n\n// An empty optional form control means \"not supplied\", not an empty config value.\nconst EmptyStringAsUndefined = Schema.Literal(\"\").pipe(\n Schema.decodeTo(\n Schema.Undefined,\n SchemaTransformation.transform({ decode: () => undefined, encode: () => \"\" }),\n ),\n);\n\nconst baseFieldSchema = (field: ConfigFieldSpec): Schema.Codec<unknown, unknown> => {\n switch (field.type) {\n case \"number\":\n return numberFromForm(field);\n case \"boolean\":\n return BooleanFromForm;\n case \"select\":\n return Schema.Literals(field.values);\n case \"string\":\n return Schema.NonEmptyString;\n }\n};\n\nconst fieldSchema = (field: ConfigFieldSpec) =>\n field.required\n ? baseFieldSchema(field)\n : Schema.optional(Schema.Union([EmptyStringAsUndefined, baseFieldSchema(field)]));\n\n/**\n * Builds an Effect Schema for logical form/API values from a connector manifest.\n *\n * @example\n * ```ts\n * const decode = Schema.decodeUnknownEffect(configSchema(manifest));\n * const values = decode({\n * apiUrl: \"https://example.com\",\n * retries: \"3\",\n * });\n * ```\n */\nexport const configSchema = <const Manifest extends ConnectorManifest>(\n manifest: Manifest,\n): ConnectorConfigSchema<Manifest> => {\n const fields = Object.fromEntries(\n manifest.config.map((field) => [field.name, fieldSchema(field)]),\n );\n // Object.fromEntries cannot retain keys discovered from the runtime manifest;\n // the public mapped type restores the same relationship for callers.\n return Schema.Struct(fields) as unknown as ConnectorConfigSchema<Manifest>;\n};\n\n/** Decodes browser/API config, applies manifest defaults, and rejects undeclared fields. */\nexport const decodeConfig = <const Manifest extends ConnectorManifest>(\n manifest: Manifest,\n input: unknown,\n) => {\n const defaults = Object.fromEntries(\n manifest.config.flatMap((field) =>\n field.default === undefined ? [] : [[field.name, field.default]],\n ),\n );\n const optionalFields = new Set(\n manifest.config.flatMap((field) => (field.required ? [] : [field.name])),\n );\n const normalizedInput = Predicate.isObject(input)\n ? Object.fromEntries(\n Object.entries(input).filter(([name, value]) => value !== \"\" || !optionalFields.has(name)),\n )\n : input;\n const inputWithDefaults = Predicate.isObject(normalizedInput)\n ? Object.assign({}, defaults, normalizedInput)\n : normalizedInput;\n\n return Schema.decodeUnknownEffect(configSchema(manifest))(inputWithDefaults, {\n onExcessProperty: \"error\",\n });\n};\n\n/**\n * Maps validated logical values to the flat runtime-key document mounted in a pod.\n * Missing optional values are omitted.\n *\n * @example\n * ```ts\n * toRuntimeDocument(manifest, { apiUrl: \"https://example.com\" });\n * // { API_URL: \"https://example.com\" }\n * ```\n */\nexport const toRuntimeDocument = <const Manifest extends ConnectorManifest>(\n manifest: Manifest,\n values: ConnectorConfigValues<Manifest>,\n): RuntimeConfigDocument => {\n const document: Record<string, string | number | boolean> = {};\n for (const field of manifest.config) {\n const value: unknown = Reflect.get(values, field.name);\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n document[field.runtimeKey] = value;\n }\n }\n return document;\n};\n","export {\n boolean,\n define as defineConfig,\n number,\n optional,\n secret,\n select,\n string,\n} from \"./config\";\nexport type { ConfigField, ConfigFieldSpec, ConfigValuesOf, ConnectorConfigDef } from \"./config\";\nexport { define } from \"./manifest\";\nexport type { ConnectorManifest, ResourceCapability } from \"./manifest\";\nexport { configSchema, decodeConfig, toRuntimeDocument } from \"./schema\";\nexport type { ConnectorConfigSchema, ConnectorConfigValues, RuntimeConfigDocument } from \"./schema\";\n"],"mappings":";;;;;AAOA,MAAa,oBAAoB,gBAAmC;AAClE,KAAI,YAAY,QACd,QAAO,YAAY,YAAY,SAC3B,OAAO,MACP,OAAO,IAAI,MAAM,OAAO,uBAAuB,YAAY,QAAQ,CAAC;AAE1E,QAAO,YAAY,YAAY,SAC3B,OAAO,SACP,OAAO,OAAO,MAAM,OAAO,uBAAuB,YAAY,QAAQ,CAAC;;;;;ACuE7E,MAAM,sBAAsB,OAAO,QAA6B,UAAU,MAAM,OAAO;AAoBvF,MAAM,eACJ,QACA,iBACI,iBAAiB,SAAY,SAAS,OAAO,YAAY,QAAQ,aAAa;;AAGpF,MAAa,UAAU,aAAwD;CAC7E,QAAQ,YAAY,OAAO,eAAe,QAAQ,WAAW,EAAE,QAAQ,QAAQ;CAC/E,MAAM;EACJ,YAAY,QAAQ;EACpB,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,QAAQ;EACR,GAAI,QAAQ,gBAAgB,SAAY,EAAE,aAAa,QAAQ,aAAa,GAAG,EAAE;EACjF,GAAI,QAAQ,YAAY,SAAY,EAAE,SAAS,QAAQ,SAAS,GAAG,EAAE;EACtE;CACF;;AAGD,MAAa,UAAU,YAAqD;CAC1E,MAAM,SAAS,iBAAiB,QAAQ;CACxC,MAAM,eACJ,QAAQ,YAAY,SAAY,SAAY,OAAO,kBAAkB,OAAO,CAAC,QAAQ,QAAQ;AAE/F,QAAO;EACL,QAAQ,YAAY,OAAO,OAAO,QAAQ,QAAQ,WAAW,EAAE,aAAa;EAC5E,MAAM;GACJ,YAAY,QAAQ;GACpB,MAAM;GACN,UAAU,QAAQ,YAAY;GAC9B,QAAQ;GACR,GAAI,QAAQ,gBAAgB,SAAY,EAAE,aA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ect, Metric } from "effect";
3
- import * as effect_Duration0 from "effect/Duration";
4
-
5
- //#region src/metrics.d.ts
6
- declare namespace metrics_d_exports {
7
- export { ApiRetryMetricAttrs, ApiRetryReason, BatchOutcome, BatchSource, LastSuccessMetricAttrs, ResourceMetricAttrs, SyncStateAttrs, WebhookMetricAttrs, WebhookOutcome, apiRetriesTotal, batchSize, batchesTotal, entitiesDeletedTotal, entitiesUpsertedTotal, lastSuccessTimestamp, publishDuration, recordApiRetry, recordWebhookRequest, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequestsTotal };
8
- }
9
- type BatchSource = "backfill" | "changes" | "webhook";
10
- type BatchOutcome = "accepted" | "rejected" | "error";
11
- type ApiRetryReason = "transport" | "timeout" | "rate_limit" | "server_error";
12
- type WebhookOutcome = "ok" | "read_error" | "invalid_json" | "invalid_payload" | "rejected" | "handler_error";
13
- type ResourceMetricAttrs = {
14
- readonly connector: string;
15
- readonly resource: string;
16
- readonly source: BatchSource;
17
- };
18
- type WebhookMetricAttrs = {
19
- readonly connector: string;
20
- readonly path: string;
21
- readonly outcome: WebhookOutcome;
22
- };
23
- type SyncStateAttrs = {
24
- readonly connector: string;
25
- readonly resource: string;
26
- };
27
- type LastSuccessMetricAttrs = {
28
- readonly connector: string;
29
- readonly resource: string;
30
- readonly source: "backfill" | "changes";
31
- };
32
- type ApiRetryMetricAttrs = {
33
- readonly connector: string;
34
- readonly reason: ApiRetryReason;
35
- };
36
- declare const entitiesUpsertedTotal: Metric.Counter<number>;
37
- declare const entitiesDeletedTotal: Metric.Counter<number>;
38
- declare const batchesTotal: Metric.Counter<number>;
39
- declare const batchSize: Metric.Histogram<number>;
40
- declare const publishDuration: Metric.Histogram<effect_Duration0.Duration>;
41
- declare const webhookRequestsTotal: Metric.Counter<number>;
42
- declare const webhookQueueDepth: Metric.Gauge<number>;
43
- declare const syncState: Metric.Gauge<number>;
44
- declare const lastSuccessTimestamp: Metric.Gauge<number>;
45
- declare const apiRetriesTotal: Metric.Counter<number>;
46
- declare const recordWebhookRequest: (attrs: WebhookMetricAttrs) => Effect.Effect<void, never, never>;
47
- declare const setWebhookQueueDepth: (connector: string, depth: number) => Effect.Effect<void, never, never>;
48
- declare const setLastSuccessTimestamp: (attrs: LastSuccessMetricAttrs, lastSuccessAt?: string) => Effect.Effect<void, never, never>;
49
- declare const recordApiRetry: (attrs: ApiRetryMetricAttrs) => Effect.Effect<void, never, never>;
50
- declare const setSyncState: (attrs: SyncStateAttrs, current: SyncState) => Effect.Effect<void, never, never>;
51
- //#endregion
52
- export { syncState as C, setWebhookQueueDepth as S, webhookRequestsTotal as T, publishDuration as _, LastSuccessMetricAttrs as a, setLastSuccessTimestamp as b, WebhookMetricAttrs as c, batchSize as d, batchesTotal as f, metrics_d_exports as g, lastSuccessTimestamp as h, BatchSource as i, WebhookOutcome as l, entitiesUpsertedTotal as m, ApiRetryReason as n, ResourceMetricAttrs as o, entitiesDeletedTotal as p, BatchOutcome as r, SyncStateAttrs as s, ApiRetryMetricAttrs as t, apiRetriesTotal as u, recordApiRetry as v, webhookQueueDepth as w, setSyncState as x, recordWebhookRequest as y };
53
- //# sourceMappingURL=metrics-CVAk1ALR.d.ts.map
@@ -1,96 +0,0 @@
1
- import { t as __export } from "./chunk-Bp6m_JJh.js";
2
- import { DateTime, Effect, Metric, Option } from "effect";
3
-
4
- //#region src/metrics.ts
5
- var metrics_exports = /* @__PURE__ */ __export({
6
- apiRetriesTotal: () => apiRetriesTotal,
7
- batchSize: () => batchSize,
8
- batchesTotal: () => batchesTotal,
9
- entitiesDeletedTotal: () => entitiesDeletedTotal,
10
- entitiesUpsertedTotal: () => entitiesUpsertedTotal,
11
- lastSuccessTimestamp: () => lastSuccessTimestamp,
12
- publishDuration: () => publishDuration,
13
- recordApiRetry: () => recordApiRetry,
14
- recordWebhookRequest: () => recordWebhookRequest,
15
- setLastSuccessTimestamp: () => setLastSuccessTimestamp,
16
- setSyncState: () => setSyncState,
17
- setWebhookQueueDepth: () => setWebhookQueueDepth,
18
- syncState: () => syncState,
19
- webhookQueueDepth: () => webhookQueueDepth,
20
- webhookRequestsTotal: () => webhookRequestsTotal
21
- });
22
- const entitiesUpsertedTotal = Metric.counter("airfoil_connector_entities_upserted_total", {
23
- description: "Total entity upsert mutations published by connector sources",
24
- incremental: true
25
- });
26
- const entitiesDeletedTotal = Metric.counter("airfoil_connector_entities_deleted_total", {
27
- description: "Total entity delete mutations published by connector sources",
28
- incremental: true
29
- });
30
- const batchesTotal = Metric.counter("airfoil_connector_batches_total", {
31
- description: "Total resource batches published by connector sources",
32
- incremental: true
33
- });
34
- const batchSize = Metric.histogram("airfoil_connector_batch_size", {
35
- description: "Distribution of resource mutation batch sizes",
36
- boundaries: [
37
- 1,
38
- 5,
39
- 10,
40
- 25,
41
- 50,
42
- 100,
43
- 250,
44
- 500,
45
- 1e3
46
- ]
47
- });
48
- const publishDuration = Metric.timer("airfoil_connector_publish_duration_ms", {
49
- description: "Publisher call duration in milliseconds",
50
- boundaries: [
51
- 1,
52
- 5,
53
- 10,
54
- 25,
55
- 50,
56
- 100,
57
- 250,
58
- 500,
59
- 1e3,
60
- 2500,
61
- 5e3,
62
- 1e4
63
- ]
64
- });
65
- const webhookRequestsTotal = Metric.counter("airfoil_connector_webhook_requests_total", {
66
- description: "Total webhook HTTP requests handled by connector routes",
67
- incremental: true
68
- });
69
- const webhookQueueDepth = Metric.gauge("airfoil_connector_webhook_queue_depth", { description: "Current queued webhook batches waiting for publish" });
70
- const syncState = Metric.gauge("airfoil_connector_sync_state", { description: "Connector resource sync state as a Prometheus state-set gauge" });
71
- const lastSuccessTimestamp = Metric.gauge("airfoil_connector_last_success_timestamp_seconds", { description: "Unix timestamp of the last successful durable source checkpoint" });
72
- const apiRetriesTotal = Metric.counter("airfoil_connector_api_retries_total", {
73
- description: "Total provider API retries performed by the connector",
74
- incremental: true
75
- });
76
- const recordWebhookRequest = (attrs) => Metric.update(Metric.withAttributes(webhookRequestsTotal, attrs), 1);
77
- const setWebhookQueueDepth = (connector, depth) => Metric.update(Metric.withAttributes(webhookQueueDepth, { connector }), depth);
78
- const setLastSuccessTimestamp = (attrs, lastSuccessAt) => {
79
- const timestamp = lastSuccessAt === void 0 ? 0 : DateTime.make(lastSuccessAt).pipe(Option.map((dateTime) => DateTime.toEpochMillis(dateTime) / 1e3), Option.getOrElse(() => 0));
80
- return Metric.update(Metric.withAttributes(lastSuccessTimestamp, attrs), timestamp);
81
- };
82
- const recordApiRetry = (attrs) => Metric.update(Metric.withAttributes(apiRetriesTotal, attrs), 1);
83
- const syncStates = [
84
- "pending",
85
- "backfilling",
86
- "live",
87
- "error"
88
- ];
89
- const setSyncState = (attrs, current) => Effect.forEach(syncStates, (state) => Metric.update(Metric.withAttributes(syncState, {
90
- ...attrs,
91
- state
92
- }), state === current ? 1 : 0), { discard: true });
93
-
94
- //#endregion
95
- export { entitiesUpsertedTotal as a, publishDuration as c, setLastSuccessTimestamp as d, setSyncState as f, webhookRequestsTotal as g, webhookQueueDepth as h, entitiesDeletedTotal as i, recordApiRetry as l, syncState as m, batchSize as n, lastSuccessTimestamp as o, setWebhookQueueDepth as p, batchesTotal as r, metrics_exports as s, apiRetriesTotal as t, recordWebhookRequest as u };
96
- //# sourceMappingURL=metrics-CWPy2Aqc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"metrics-CWPy2Aqc.js","names":[],"sources":["../src/metrics.ts"],"sourcesContent":["import { DateTime, Effect, Metric, Option } from \"effect\";\n\nimport type { SyncState } from \"./core/types\";\n\nexport type BatchSource = \"backfill\" | \"changes\" | \"webhook\";\nexport type BatchOutcome = \"accepted\" | \"rejected\" | \"error\";\nexport type ApiRetryReason = \"transport\" | \"timeout\" | \"rate_limit\" | \"server_error\";\nexport type WebhookOutcome =\n | \"ok\"\n | \"read_error\"\n | \"invalid_json\"\n | \"invalid_payload\"\n | \"rejected\"\n | \"handler_error\";\n\nexport type ResourceMetricAttrs = {\n readonly connector: string;\n readonly resource: string;\n readonly source: BatchSource;\n};\n\nexport type WebhookMetricAttrs = {\n readonly connector: string;\n readonly path: string;\n readonly outcome: WebhookOutcome;\n};\n\nexport type SyncStateAttrs = {\n readonly connector: string;\n readonly resource: string;\n};\n\nexport type LastSuccessMetricAttrs = {\n readonly connector: string;\n readonly resource: string;\n readonly source: \"backfill\" | \"changes\";\n};\n\nexport type ApiRetryMetricAttrs = {\n readonly connector: string;\n readonly reason: ApiRetryReason;\n};\n\nexport const entitiesUpsertedTotal = Metric.counter(\"airfoil_connector_entities_upserted_total\", {\n description: \"Total entity upsert mutations published by connector sources\",\n incremental: true,\n});\n\nexport const entitiesDeletedTotal = Metric.counter(\"airfoil_connector_entities_deleted_total\", {\n description: \"Total entity delete mutations published by connector sources\",\n incremental: true,\n});\n\nexport const batchesTotal = Metric.counter(\"airfoil_connector_batches_total\", {\n description: \"Total resource batches published by connector sources\",\n incremental: true,\n});\n\nexport const batchSize = Metric.histogram(\"airfoil_connector_batch_size\", {\n description: \"Distribution of resource mutation batch sizes\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000],\n});\n\nexport const publishDuration = Metric.timer(\"airfoil_connector_publish_duration_ms\", {\n description: \"Publisher call duration in milliseconds\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n});\n\nexport const webhookRequestsTotal = Metric.counter(\"airfoil_connector_webhook_requests_total\", {\n description: \"Total webhook HTTP requests handled by connector routes\",\n incremental: true,\n});\n\nexport const webhookQueueDepth = Metric.gauge(\"airfoil_connector_webhook_queue_depth\", {\n description: \"Current queued webhook batches waiting for publish\",\n});\n\nexport const syncState = Metric.gauge(\"airfoil_connector_sync_state\", {\n description: \"Connector resource sync state as a Prometheus state-set gauge\",\n});\n\nexport const lastSuccessTimestamp = Metric.gauge(\n \"airfoil_connector_last_success_timestamp_seconds\",\n {\n description: \"Unix timestamp of the last successful durable source checkpoint\",\n },\n);\n\nexport const apiRetriesTotal = Metric.counter(\"airfoil_connector_api_retries_total\", {\n description: \"Total provider API retries performed by the connector\",\n incremental: true,\n});\n\nexport const recordWebhookRequest = (attrs: WebhookMetricAttrs) =>\n Metric.update(Metric.withAttributes(webhookRequestsTotal, attrs), 1);\n\nexport const setWebhookQueueDepth = (connector: string, depth: number) =>\n Metric.update(Metric.withAttributes(webhookQueueDepth, { connector }), depth);\n\nexport const setLastSuccessTimestamp = (attrs: LastSuccessMetricAttrs, lastSuccessAt?: string) => {\n const timestamp =\n lastSuccessAt === undefined\n ? 0\n : DateTime.make(lastSuccessAt).pipe(\n Option.map((dateTime) => DateTime.toEpochMillis(dateTime) / 1000),\n Option.getOrElse(() => 0),\n );\n return Metric.update(Metric.withAttributes(lastSuccessTimestamp, attrs), timestamp);\n};\n\nexport const recordApiRetry = (attrs: ApiRetryMetricAttrs) =>\n Metric.update(Metric.withAttributes(apiRetriesTotal, attrs), 1);\n\nconst syncStates = [\"pending\", \"backfilling\", \"live\", \"error\"] as const;\n\nexport const setSyncState = (attrs: SyncStateAttrs, current: SyncState) =>\n Effect.forEach(\n syncStates,\n (state) =>\n Metric.update(\n Metric.withAttributes(syncState, {\n ...attrs,\n state,\n }),\n state === current ? 1 : 0,\n ),\n { discard: true },\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,wBAAwB,OAAO,QAAQ,6CAA6C;CAC/F,aAAa;CACb,aAAa;CACd,CAAC;AAEF,MAAa,uBAAuB,OAAO,QAAQ,4CAA4C;CAC7F,aAAa;CACb,aAAa;CACd,CAAC;AAEF,MAAa,eAAe,OAAO,QAAQ,mCAAmC;CAC5E,aAAa;CACb,aAAa;CACd,CAAC;AAEF,MAAa,YAAY,OAAO,UAAU,gCAAgC;CACxE,aAAa;CACb,YAAY;EAAC;EAAG;EAAG;EAAI;EAAI;EAAI;EAAK;EAAK;EAAK;EAAK;CACpD,CAAC;AAEF,MAAa,kBAAkB,OAAO,MAAM,yCAAyC;CACnF,aAAa;CACb,YAAY;EAAC;EAAG;EAA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import { C as syncState, S as setWebhookQueueDepth, T as webhookRequestsTotal, _ as publishDuration, a as LastSuccessMetricAttrs, b as setLastSuccessTimestamp, c as WebhookMetricAttrs, d as batchSize, f as batchesTotal, h as lastSuccessTimestamp, i as BatchSource, l as WebhookOutcome, m as entitiesUpsertedTotal, n as ApiRetryReason, o as ResourceMetricAttrs, p as entitiesDeletedTotal, r as BatchOutcome, s as SyncStateAttrs, t as ApiRetryMetricAttrs, u as apiRetriesTotal, v as recordApiRetry, w as webhookQueueDepth, x as setSyncState, y as recordWebhookRequest } from "./metrics-CVAk1ALR.js";
4
- export { ApiRetryMetricAttrs, ApiRetryReason, BatchOutcome, BatchSource, LastSuccessMetricAttrs, ResourceMetricAttrs, SyncStateAttrs, WebhookMetricAttrs, WebhookOutcome, apiRetriesTotal, batchSize, batchesTotal, entitiesDeletedTotal, entitiesUpsertedTotal, lastSuccessTimestamp, publishDuration, recordApiRetry, recordWebhookRequest, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequestsTotal };
package/dist/metrics.js DELETED
@@ -1,3 +0,0 @@
1
- import { a as entitiesUpsertedTotal, c as publishDuration, d as setLastSuccessTimestamp, f as setSyncState, g as webhookRequestsTotal, h as webhookQueueDepth, i as entitiesDeletedTotal, l as recordApiRetry, m as syncState, n as batchSize, o as lastSuccessTimestamp, p as setWebhookQueueDepth, r as batchesTotal, t as apiRetriesTotal, u as recordWebhookRequest } from "./metrics-CWPy2Aqc.js";
2
-
3
- export { apiRetriesTotal, batchSize, batchesTotal, entitiesDeletedTotal, entitiesUpsertedTotal, lastSuccessTimestamp, publishDuration, recordApiRetry, recordWebhookRequest, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequestsTotal };
@@ -1,5 +0,0 @@
1
- import "../index-D54ySAKn.js";
2
- import { c as ResourceBatch } from "../types-B35J5YPu.js";
3
- import { a as PublisherService, i as Publisher, n as PublishOptions, r as PublishSource, t as PublishAck } from "../service-IE5qaf9x.js";
4
- import { i as layerWings, n as layerConsole, r as WingsPublisherConfig } from "../index-Byr0Lf0C.js";
5
- export { PublishAck, PublishOptions, PublishSource, Publisher, PublisherService, ResourceBatch, WingsPublisherConfig, layerConsole, layerWings };
@@ -1,6 +0,0 @@
1
- import "../errors-DHWylqRZ.js";
2
- import "../constants-BRhIX_rz.js";
3
- import { t as Publisher } from "../service-DuFiQwid.js";
4
- import { n as layerWings, r as layerConsole } from "../publisher-BYT3RLVO.js";
5
-
6
- export { Publisher, layerConsole, layerWings };