@useairfoil/connector-kit 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +201 -0
- package/METRICS.md +38 -42
- package/README.md +111 -444
- package/dist/annotations-vzSzXtr-.d.mts +34 -0
- package/dist/arrow-flight-DDQ0ktx9.mjs +251 -0
- package/dist/arrow-flight-DDQ0ktx9.mjs.map +1 -0
- package/dist/auth/index.d.mts +2 -0
- package/dist/{auth-DvU_CZ7C.js → auth/index.mjs} +6 -8
- package/dist/auth/index.mjs.map +1 -0
- package/dist/connector-app/index.d.mts +2 -0
- package/dist/connector-app/index.mjs +2 -0
- package/dist/connector-app-C6_dZnhE.mjs +256 -0
- package/dist/connector-app-C6_dZnhE.mjs.map +1 -0
- package/dist/{constants-D113Ut1x.js → constants-v3UX-hf6.mjs} +5 -5
- package/dist/constants-v3UX-hf6.mjs.map +1 -0
- package/dist/demo/index.d.mts +2 -0
- package/dist/demo/index.mjs +2 -0
- package/dist/demo-DqTJ7TWI.mjs +204 -0
- package/dist/demo-DqTJ7TWI.mjs.map +1 -0
- package/dist/errors/index.d.mts +2 -0
- package/dist/errors/index.mjs +2 -0
- package/dist/{errors-DHWylqRZ.js → errors-pT0YVJU5.mjs} +2 -3
- package/dist/errors-pT0YVJU5.mjs.map +1 -0
- package/dist/iceberg/index.d.mts +3 -0
- package/dist/iceberg/index.mjs +3 -0
- package/dist/iceberg-Cj2PwlNm.mjs +30 -0
- package/dist/iceberg-Cj2PwlNm.mjs.map +1 -0
- package/dist/index-BTAbexBp.d.mts +55 -0
- package/dist/{index-DXa26Ry5.d.ts → index-BX8G7d41.d.mts} +1 -2
- package/dist/{index-VpHaZXZw.d.ts → index-Byr8NTdG.d.mts} +11 -13
- package/dist/index-CV6V6fyx.d.mts +79 -0
- package/dist/{index-C5Ma7V7t.d.ts → index-CZKx2Yce.d.mts} +72 -37
- package/dist/{index-DYpEMJf-.d.ts → index-CgvFomO6.d.mts} +6 -7
- package/dist/{index-bfjH7Yb0.d.ts → index-DeTwIUKl.d.mts} +9 -10
- package/dist/{index-DKoRwyFn.d.ts → index-DkVNO6ks.d.mts} +2 -5
- package/dist/{index-BKw7jA2a.d.ts → index-dHS59EZl.d.mts} +10 -8
- package/dist/{index-CR9HJDdr.d.ts → index-eFuoMZZ3.d.mts} +18 -20
- package/dist/{index-ZSuiZX5H.d.ts → index-fHIJJoRe.d.mts} +25 -30
- package/dist/index-uFa2wwYo.d.mts +27 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +45 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ingestion/index.d.mts +2 -0
- package/dist/ingestion/index.mjs +2 -0
- package/dist/ingestion-DoCUwm5N.mjs +275 -0
- package/dist/ingestion-DoCUwm5N.mjs.map +1 -0
- package/dist/ingestor/index.d.mts +3 -0
- package/dist/ingestor/index.mjs +4 -0
- package/dist/ingestor-DjCEzBzZ.mjs +26 -0
- package/dist/ingestor-DjCEzBzZ.mjs.map +1 -0
- package/dist/instrumented-Bq1WX2L5.mjs +29 -0
- package/dist/instrumented-Bq1WX2L5.mjs.map +1 -0
- package/dist/manifest/index.d.mts +2 -0
- package/dist/manifest/{index.js → index.mjs} +2 -4
- package/dist/{manifest-P7kBnch9.js → manifest-CABeIhAG.mjs} +14 -19
- package/dist/manifest-CABeIhAG.mjs.map +1 -0
- package/dist/{telemetry-j_nxwYfh.js → metrics-C901IIYZ.mjs} +172 -26
- package/dist/metrics-C901IIYZ.mjs.map +1 -0
- package/dist/{metrics-C4V1pm6v.d.ts → metrics-DoJ0WeKu.d.mts} +18 -13
- package/dist/metrics.d.mts +2 -0
- package/dist/metrics.mjs +2 -0
- package/dist/{chunk-Bp6m_JJh.js → rolldown-runtime-D7D4PA-g.mjs} +4 -4
- package/dist/runtime-config/index.d.mts +2 -0
- package/dist/runtime-config/index.mjs +3 -0
- package/dist/runtime-config-Bn8Fivt1.mjs +100 -0
- package/dist/runtime-config-Bn8Fivt1.mjs.map +1 -0
- package/dist/server-D1TTN0_D.mjs +144 -0
- package/dist/server-D1TTN0_D.mjs.map +1 -0
- package/dist/service-BRoy_EId.d.mts +27 -0
- package/dist/service-jWxxfEht.mjs +7 -0
- package/dist/service-jWxxfEht.mjs.map +1 -0
- package/dist/state-store/index.d.mts +2 -0
- package/dist/state-store/index.mjs +2 -0
- package/dist/{state-store-BdYulQOY.js → state-store-DhSrKVEH.mjs} +15 -22
- package/dist/state-store-DhSrKVEH.mjs.map +1 -0
- package/dist/status/{index.d.ts → index.d.mts} +1 -4
- package/dist/status/{index.js → index.mjs} +2 -6
- package/dist/{status-BTTd7AUR.js → status-4h6Oxh-O.mjs} +14 -16
- package/dist/status-4h6Oxh-O.mjs.map +1 -0
- package/dist/table-CxM09xf7.mjs +307 -0
- package/dist/table-CxM09xf7.mjs.map +1 -0
- package/dist/types-NtSv6gwl.d.mts +220 -0
- package/dist/webhook/index.d.mts +3 -0
- package/dist/webhook/index.mjs +12 -0
- package/dist/webhook/index.mjs.map +1 -0
- package/package.json +72 -58
- package/src/catalog/retry.ts +25 -0
- package/src/catalog/table.ts +237 -0
- package/src/connector-app/create-table.ts +47 -0
- package/src/connector-app/demo.ts +47 -0
- package/src/connector-app/index.ts +3 -0
- package/src/connector-app/setup.ts +69 -0
- package/src/connector-app/start.ts +1 -1
- package/src/core/builder.ts +15 -23
- package/src/core/index.ts +11 -1
- package/src/core/types.ts +114 -39
- package/src/demo/definition.ts +68 -0
- package/src/demo/generate.ts +167 -0
- package/src/demo/index.ts +3 -0
- package/src/demo/run.ts +172 -0
- package/src/iceberg/annotations.ts +49 -0
- package/src/iceberg/error.ts +9 -0
- package/src/iceberg/index.ts +3 -0
- package/src/iceberg/table.ts +461 -0
- package/src/index.ts +3 -1
- package/src/ingestion/engine.ts +240 -60
- package/src/ingestor/arrow-flight.ts +141 -0
- package/src/ingestor/arrow.ts +248 -0
- package/src/ingestor/console.ts +13 -0
- package/src/ingestor/index.ts +13 -0
- package/src/ingestor/instrumented.ts +61 -0
- package/src/ingestor/service.ts +30 -0
- package/src/manifest/config.ts +3 -3
- package/src/metrics.ts +66 -20
- package/src/runtime-config/config.ts +11 -8
- package/src/runtime-config/constants.ts +3 -2
- package/src/runtime-config/index.ts +2 -7
- package/src/runtime-config/layer.ts +1 -1
- package/src/runtime-config/table-bindings.ts +50 -136
- package/src/state-store/layer-key-value-store.ts +8 -3
- package/src/state-store/layer-memory.ts +1 -1
- package/src/state-store/layer-sql.ts +4 -4
- package/src/state-store/schema.ts +2 -2
- package/src/state-store/state.ts +14 -2
- package/src/status/route.ts +2 -2
- package/src/telemetry.ts +20 -28
- package/src/webhook/server.ts +39 -40
- package/dist/auth/index.d.ts +0 -2
- package/dist/auth/index.js +0 -3
- package/dist/auth-DvU_CZ7C.js.map +0 -1
- package/dist/connector-app/index.d.ts +0 -14
- package/dist/connector-app/index.js +0 -12
- package/dist/connector-app-BljHd0Pe.js +0 -64
- package/dist/connector-app-BljHd0Pe.js.map +0 -1
- package/dist/constants-D113Ut1x.js.map +0 -1
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.js +0 -3
- package/dist/errors-DHWylqRZ.js.map +0 -1
- package/dist/index-BA8ASHKr.d.ts +0 -31
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -60
- package/dist/index.js.map +0 -1
- package/dist/ingestion/index.d.ts +0 -6
- package/dist/ingestion/index.js +0 -11
- package/dist/ingestion-QBGKrFr9.js +0 -200
- package/dist/ingestion-QBGKrFr9.js.map +0 -1
- package/dist/manifest/index.d.ts +0 -2
- package/dist/manifest-P7kBnch9.js.map +0 -1
- package/dist/metrics-inkCAxKq.js +0 -136
- package/dist/metrics-inkCAxKq.js.map +0 -1
- package/dist/metrics.d.ts +0 -4
- package/dist/metrics.js +0 -5
- package/dist/publisher/index.d.ts +0 -6
- package/dist/publisher/index.js +0 -8
- package/dist/publisher-BdWJOfer.js +0 -138
- package/dist/publisher-BdWJOfer.js.map +0 -1
- package/dist/runtime-config/index.d.ts +0 -4
- package/dist/runtime-config/index.js +0 -5
- package/dist/runtime-config-IbyCVpei.js +0 -60
- package/dist/runtime-config-IbyCVpei.js.map +0 -1
- package/dist/server-D-eLX3yN.js +0 -183
- package/dist/server-D-eLX3yN.js.map +0 -1
- package/dist/service-CUjGhe-7.d.ts +0 -32
- package/dist/service-DiP-XETo.js +0 -8
- package/dist/service-DiP-XETo.js.map +0 -1
- package/dist/state-store/index.d.ts +0 -3
- package/dist/state-store/index.js +0 -5
- package/dist/state-store-BdYulQOY.js.map +0 -1
- package/dist/status-BTTd7AUR.js.map +0 -1
- package/dist/table-bindings-Dp1DhTeS.js +0 -106
- package/dist/table-bindings-Dp1DhTeS.js.map +0 -1
- package/dist/telemetry-j_nxwYfh.js.map +0 -1
- package/dist/types-jVD5Ys43.d.ts +0 -174
- package/dist/webhook/index.d.ts +0 -7
- package/dist/webhook/index.js +0 -9
- package/dist/webhook-MhFcLW-o.js +0 -13
- package/dist/webhook-MhFcLW-o.js.map +0 -1
- package/src/publisher/console.ts +0 -18
- package/src/publisher/index.ts +0 -7
- package/src/publisher/instrumented.ts +0 -75
- package/src/publisher/service.ts +0 -37
- package/src/publisher/wings.ts +0 -204
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-CABeIhAG.mjs","names":["define"],"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;CAClE,IAAI,YAAY,SACd,OAAO,YAAY,YAAY,KAAA,IAC3B,OAAO,MACP,OAAO,IAAI,MAAM,OAAO,uBAAuB,YAAY,OAAO,CAAC;CAEzE,OAAO,YAAY,YAAY,KAAA,IAC3B,OAAO,SACP,OAAO,OAAO,MAAM,OAAO,uBAAuB,YAAY,OAAO,CAAC;AAC5E;;;ACsEA,MAAM,sBAAsB,OAAO,QAA6B,UAAU,MAAM,MAAM;AAoBtF,MAAM,eACJ,QACA,iBACI,iBAAiB,KAAA,IAAY,SAAS,OAAO,YAAY,QAAQ,YAAY;;AAGnF,MAAa,UAAU,aAAwD;CAC7E,QAAQ,YAAY,OAAO,eAAe,QAAQ,UAAU,GAAG,QAAQ,OAAO;CAC9E,MAAM;EACJ,YAAY,QAAQ;EACpB,MAAM;EACN,UAAU,QAAQ,YAAY;EAC9B,QAAQ;EACR,GAAI,QAAQ,gBAAgB,KAAA,IAAY,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;EAChF,GAAI,QAAQ,YAAY,KAAA,IAAY,EAAE,SAAS,QAAQ,QAAQ,IAAI,CAAC;CACtE;AACF;;AAGA,MAAa,UAAU,YAAqD;CAC1E,MAAM,SAAS,iBAAiB,OAAO;CACvC,MAAM,eACJ,QAAQ,YAAY,KAAA,IAAY,KAAA,IAAY,OAAO,kBAAkB,MAAM,CAAC,CAAC,QAAQ,OAAO;CAE9F,OAAO;EACL,QAAQ,YAAY,OAAO,OAAO,QAAQ,QAAQ,UAAU,GAAG,YAAY;EAC3E,MAAM;GACJ,YAAY,QAAQ;GACpB,MAAM;GACN,UAAU,QAAQ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,QAAQ,MAAM,IAAI;EACrD,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,SAAS,MAAM,cAAc;CAEjC;CACA,OAAO;AACT"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { n as PlatformRuntimeKey } from "./constants-
|
|
3
|
-
import { Cause, Config, Effect, Layer, Metric, Option } from "effect";
|
|
4
|
-
import { Headers } from "effect/
|
|
5
|
-
import * as Observability from "effect/
|
|
6
|
-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { n as PlatformRuntimeKey } from "./constants-v3UX-hf6.mjs";
|
|
3
|
+
import { Cause, Config, DateTime, Effect, Layer, Metric, Option, Predicate, Schedule, Schema } from "effect";
|
|
4
|
+
import { Headers, HttpClientError, HttpClientResponse } from "effect/http";
|
|
5
|
+
import * as Observability from "effect/observability";
|
|
7
6
|
//#region src/telemetry.ts
|
|
8
|
-
var telemetry_exports = /* @__PURE__ */
|
|
7
|
+
var telemetry_exports = /* @__PURE__ */ __exportAll({
|
|
9
8
|
Attr: () => Attr,
|
|
10
9
|
EventAttr: () => EventAttr,
|
|
11
10
|
EventName: () => EventName,
|
|
@@ -25,7 +24,7 @@ const SpanName = {
|
|
|
25
24
|
batchProcess: "connector.batch.process",
|
|
26
25
|
webhookDecode: "connector.webhook.decode",
|
|
27
26
|
webhookHandle: "connector.webhook.handle",
|
|
28
|
-
|
|
27
|
+
ingest: "connector.ingest",
|
|
29
28
|
stateSet: "connector.state.set",
|
|
30
29
|
apiFetch: "connector.api.fetch"
|
|
31
30
|
};
|
|
@@ -35,13 +34,13 @@ const Attr = {
|
|
|
35
34
|
connectorResourcesCount: "airfoil.connector.resources.count",
|
|
36
35
|
resourceName: "airfoil.resource.name",
|
|
37
36
|
resourceSource: "airfoil.resource.source",
|
|
38
|
-
|
|
37
|
+
batchRows: "airfoil.batch.rows",
|
|
39
38
|
batchOutcome: "airfoil.batch.outcome",
|
|
40
39
|
webhookPath: "airfoil.webhook.path",
|
|
41
40
|
webhookOutcome: "airfoil.webhook.outcome",
|
|
42
41
|
syncState: "airfoil.connector.sync.state",
|
|
43
42
|
apiRetryReason: "airfoil.connector.api.retry.reason",
|
|
44
|
-
|
|
43
|
+
ingestionSuccess: "airfoil.ingestion.success",
|
|
45
44
|
stateKey: "airfoil.state.key",
|
|
46
45
|
apiPath: "airfoil.api.path",
|
|
47
46
|
errorPhase: "airfoil.error.phase",
|
|
@@ -62,9 +61,9 @@ const EventAttr = { batchCursor: "airfoil.batch.cursor" };
|
|
|
62
61
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
63
62
|
const maxErrorMessageLength = 500;
|
|
64
63
|
const OtlpEnvConfig = Config.all({
|
|
65
|
-
enabled: Config.
|
|
66
|
-
baseUrl: Config.option(Config.
|
|
67
|
-
|
|
64
|
+
enabled: Config.Boolean(PlatformRuntimeKey.otelEnabled).pipe(Config.withDefault(false)),
|
|
65
|
+
baseUrl: Config.option(Config.String(PlatformRuntimeKey.otelExporterOtlpEndpoint)),
|
|
66
|
+
headers: Config.option(Config.Record(Schema.String, Schema.StringFromUriComponent, PlatformRuntimeKey.otelExporterOtlpHeaders, { trim: true }))
|
|
68
67
|
});
|
|
69
68
|
const defaultRedactedHeaders = [
|
|
70
69
|
"authorization",
|
|
@@ -76,11 +75,6 @@ const defaultRedactedHeaders = [
|
|
|
76
75
|
/signature/i,
|
|
77
76
|
/token/i
|
|
78
77
|
];
|
|
79
|
-
const parseOtelHeaders = (value) => Object.fromEntries(value.split(",").map((entry) => entry.trim()).filter(Boolean).flatMap((entry) => {
|
|
80
|
-
const separator = entry.indexOf("=");
|
|
81
|
-
if (separator < 1) return [];
|
|
82
|
-
return [[entry.slice(0, separator).trim(), entry.slice(separator + 1).trim()]];
|
|
83
|
-
}));
|
|
84
78
|
const appendPath = (baseUrl, path) => `${baseUrl.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
85
79
|
/**
|
|
86
80
|
* Best-effort stable error classifier for span metadata.
|
|
@@ -153,12 +147,13 @@ const layer = (config = {}, options = {}) => Layer.unwrap(buildOtlpTracingLayer(
|
|
|
153
147
|
*
|
|
154
148
|
* @example
|
|
155
149
|
* Telemetry.layerConfig({
|
|
156
|
-
* enabled: Config.
|
|
157
|
-
* endpoint: Config.
|
|
150
|
+
* enabled: Config.Boolean("MY_OTEL_ENABLED"),
|
|
151
|
+
* endpoint: Config.String("MY_COLLECTOR_URL"),
|
|
158
152
|
* })
|
|
159
153
|
*/
|
|
160
154
|
const layerConfig = (config, options = {}) => Layer.unwrap(Effect.gen(function* () {
|
|
161
|
-
|
|
155
|
+
const resolved = yield* Config.unwrap(config);
|
|
156
|
+
return yield* buildOtlpTracingLayer(resolved, options);
|
|
162
157
|
}));
|
|
163
158
|
/**
|
|
164
159
|
* Trace-only OTLP export with sensitive HTTP header redaction.
|
|
@@ -173,7 +168,7 @@ const layerOtlpTracing = (options = {}) => Layer.unwrap(Effect.gen(function* ()
|
|
|
173
168
|
return yield* buildOtlpTracingLayer({
|
|
174
169
|
enabled: raw.enabled,
|
|
175
170
|
endpoint: Option.getOrUndefined(raw.baseUrl),
|
|
176
|
-
headers: Option.
|
|
171
|
+
headers: Option.getOrUndefined(raw.headers)
|
|
177
172
|
}, options);
|
|
178
173
|
}));
|
|
179
174
|
/** Exports connector metrics over OTLP when telemetry is enabled. */
|
|
@@ -184,7 +179,7 @@ const layerOtlpMetrics = (options = {}) => Layer.unwrap(Effect.gen(function* ()
|
|
|
184
179
|
if (!endpoint) return yield* Effect.fail(/* @__PURE__ */ new Error("OTEL_ENABLED=true requires OTEL_EXPORTER_OTLP_ENDPOINT"));
|
|
185
180
|
return Observability.OtlpMetrics.layer({
|
|
186
181
|
url: appendPath(endpoint, "/v1/metrics"),
|
|
187
|
-
headers: Option.
|
|
182
|
+
headers: Option.getOrUndefined(raw.headers),
|
|
188
183
|
exportInterval: options.exportInterval,
|
|
189
184
|
temporality: "cumulative"
|
|
190
185
|
}).pipe(Layer.provide(Observability.OtlpSerialization.layerJson));
|
|
@@ -195,7 +190,158 @@ const layerOtlp = (options = {}) => Layer.mergeAll(layerOtlpTracing(options), la
|
|
|
195
190
|
const layerMetricsConsoleDump = (interval = "30 seconds") => Layer.effectDiscard(Effect.gen(function* () {
|
|
196
191
|
yield* Effect.forkScoped(Effect.forever(Metric.dump.pipe(Effect.flatMap((snapshot) => Effect.logInfo(snapshot)), Effect.andThen(Effect.sleep(interval)))));
|
|
197
192
|
}));
|
|
198
|
-
|
|
199
193
|
//#endregion
|
|
200
|
-
|
|
201
|
-
|
|
194
|
+
//#region src/metrics.ts
|
|
195
|
+
var metrics_exports = /* @__PURE__ */ __exportAll({
|
|
196
|
+
apiRetries: () => apiRetries,
|
|
197
|
+
batchSize: () => batchSize,
|
|
198
|
+
batches: () => batches,
|
|
199
|
+
ingestDuration: () => ingestDuration,
|
|
200
|
+
lastSuccessTimestamp: () => lastSuccessTimestamp,
|
|
201
|
+
recordApiRetry: () => recordApiRetry,
|
|
202
|
+
recordWebhookRequest: () => recordWebhookRequest,
|
|
203
|
+
retrySchedule: () => retrySchedule,
|
|
204
|
+
rowsIngested: () => rowsIngested,
|
|
205
|
+
setLastSuccessTimestamp: () => setLastSuccessTimestamp,
|
|
206
|
+
setSyncState: () => setSyncState,
|
|
207
|
+
setWebhookQueueDepth: () => setWebhookQueueDepth,
|
|
208
|
+
syncState: () => syncState,
|
|
209
|
+
webhookQueueDepth: () => webhookQueueDepth,
|
|
210
|
+
webhookRequests: () => webhookRequests,
|
|
211
|
+
withResourceAttributes: () => withResourceAttributes
|
|
212
|
+
});
|
|
213
|
+
const batches = Metric.counter("airfoil.connector.batches", {
|
|
214
|
+
description: "Total resource batches ingested by connector sources",
|
|
215
|
+
incremental: true,
|
|
216
|
+
attributes: { unit: "{batch}" }
|
|
217
|
+
});
|
|
218
|
+
const rowsIngested = Metric.counter("airfoil.connector.rows.ingested", {
|
|
219
|
+
description: "Total resource rows successfully ingested",
|
|
220
|
+
incremental: true,
|
|
221
|
+
attributes: { unit: "{row}" }
|
|
222
|
+
});
|
|
223
|
+
const batchSize = Metric.histogram("airfoil.connector.batch.size", {
|
|
224
|
+
description: "Distribution of resource row batch sizes",
|
|
225
|
+
boundaries: [
|
|
226
|
+
1,
|
|
227
|
+
5,
|
|
228
|
+
10,
|
|
229
|
+
25,
|
|
230
|
+
50,
|
|
231
|
+
100,
|
|
232
|
+
250,
|
|
233
|
+
500,
|
|
234
|
+
1e3
|
|
235
|
+
],
|
|
236
|
+
attributes: { unit: "{row}" }
|
|
237
|
+
});
|
|
238
|
+
const ingestDuration = Metric.timer("airfoil.connector.ingest.duration", {
|
|
239
|
+
description: "Ingestor call duration in milliseconds",
|
|
240
|
+
boundaries: [
|
|
241
|
+
1,
|
|
242
|
+
5,
|
|
243
|
+
10,
|
|
244
|
+
25,
|
|
245
|
+
50,
|
|
246
|
+
100,
|
|
247
|
+
250,
|
|
248
|
+
500,
|
|
249
|
+
1e3,
|
|
250
|
+
2500,
|
|
251
|
+
5e3,
|
|
252
|
+
1e4
|
|
253
|
+
],
|
|
254
|
+
attributes: { unit: "ms" }
|
|
255
|
+
});
|
|
256
|
+
const webhookRequests = Metric.counter("airfoil.connector.webhook.requests", {
|
|
257
|
+
description: "Total webhook HTTP requests handled by connector routes",
|
|
258
|
+
incremental: true,
|
|
259
|
+
attributes: { unit: "{request}" }
|
|
260
|
+
});
|
|
261
|
+
const webhookQueueDepth = Metric.gauge("airfoil.connector.webhook.queue.depth", {
|
|
262
|
+
description: "Current queued webhook batches waiting for ingestion",
|
|
263
|
+
attributes: { unit: "{batch}" }
|
|
264
|
+
});
|
|
265
|
+
const syncState = Metric.gauge("airfoil.connector.sync.state", {
|
|
266
|
+
description: "Connector resource sync state as a Prometheus state-set gauge",
|
|
267
|
+
attributes: { unit: "1" }
|
|
268
|
+
});
|
|
269
|
+
const lastSuccessTimestamp = Metric.gauge("airfoil.connector.last_success.timestamp", {
|
|
270
|
+
description: "Unix timestamp of the last successful durable source checkpoint",
|
|
271
|
+
attributes: { unit: "s" }
|
|
272
|
+
});
|
|
273
|
+
const apiRetries = Metric.counter("airfoil.connector.api.retries", {
|
|
274
|
+
description: "Total provider API retries performed by the connector",
|
|
275
|
+
incremental: true,
|
|
276
|
+
attributes: { unit: "{retry}" }
|
|
277
|
+
});
|
|
278
|
+
const resourceAttributes = (attrs) => ({
|
|
279
|
+
[Attr.connectorName]: attrs.connector,
|
|
280
|
+
[Attr.resourceName]: attrs.resource,
|
|
281
|
+
[Attr.resourceSource]: attrs.source
|
|
282
|
+
});
|
|
283
|
+
const syncAttributes = (attrs) => ({
|
|
284
|
+
[Attr.connectorName]: attrs.connector,
|
|
285
|
+
[Attr.resourceName]: attrs.resource
|
|
286
|
+
});
|
|
287
|
+
const recordWebhookRequest = (attrs) => Metric.update(Metric.withAttributes(webhookRequests, {
|
|
288
|
+
[Attr.connectorName]: attrs.connector,
|
|
289
|
+
[Attr.webhookPath]: attrs.path,
|
|
290
|
+
[Attr.webhookOutcome]: attrs.outcome
|
|
291
|
+
}), 1);
|
|
292
|
+
const setWebhookQueueDepth = (connector, depth) => Metric.update(Metric.withAttributes(webhookQueueDepth, { [Attr.connectorName]: connector }), depth);
|
|
293
|
+
const setLastSuccessTimestamp = (attrs, lastSuccessAt) => {
|
|
294
|
+
const timestamp = lastSuccessAt === void 0 ? 0 : DateTime.make(lastSuccessAt).pipe(Option.map((dateTime) => DateTime.toEpochMillis(dateTime) / 1e3), Option.getOrElse(() => 0));
|
|
295
|
+
return Metric.update(Metric.withAttributes(lastSuccessTimestamp, {
|
|
296
|
+
[Attr.connectorName]: attrs.connector,
|
|
297
|
+
[Attr.resourceName]: attrs.resource,
|
|
298
|
+
[Attr.resourceSource]: attrs.source
|
|
299
|
+
}), timestamp);
|
|
300
|
+
};
|
|
301
|
+
const recordApiRetry = (attrs) => Metric.update(Metric.withAttributes(apiRetries, {
|
|
302
|
+
[Attr.connectorName]: attrs.connector,
|
|
303
|
+
[Attr.apiRetryReason]: attrs.reason
|
|
304
|
+
}), 1);
|
|
305
|
+
const transientStatuses = /* @__PURE__ */ new Set([
|
|
306
|
+
408,
|
|
307
|
+
429,
|
|
308
|
+
500,
|
|
309
|
+
502,
|
|
310
|
+
503,
|
|
311
|
+
504
|
|
312
|
+
]);
|
|
313
|
+
const reasonForStatus = (status) => status === 408 ? "timeout" : status === 429 || status === 403 ? "rate_limit" : "server_error";
|
|
314
|
+
const isResponse = (value) => Predicate.hasProperty(value, HttpClientResponse.TypeId);
|
|
315
|
+
/** Why `HttpClient.retryTransient` retries. Undefined for a response it keeps. */
|
|
316
|
+
const retryReason = (value) => {
|
|
317
|
+
if (isResponse(value)) return transientStatuses.has(value.status) ? reasonForStatus(value.status) : void 0;
|
|
318
|
+
if (HttpClientError.isHttpClientError(value) && value.reason._tag === "StatusCodeError") return reasonForStatus(value.reason.response.status);
|
|
319
|
+
return Cause.isTimeoutError(value) ? "timeout" : "transport";
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* A jittered exponential schedule for `HttpClient.retryTransient` that records
|
|
323
|
+
* each retry with its reason.
|
|
324
|
+
*/
|
|
325
|
+
const retrySchedule = (options) => Schedule.exponential(options.baseDelay).pipe(Schedule.jittered, Schedule.upTo({ times: options.times }), Schedule.tap(({ input }) => {
|
|
326
|
+
const reason = retryReason(input);
|
|
327
|
+
return reason === void 0 ? Effect.void : recordApiRetry({
|
|
328
|
+
connector: options.connector,
|
|
329
|
+
reason
|
|
330
|
+
});
|
|
331
|
+
}));
|
|
332
|
+
const syncStates = [
|
|
333
|
+
"pending",
|
|
334
|
+
"backfilling",
|
|
335
|
+
"live",
|
|
336
|
+
"error"
|
|
337
|
+
];
|
|
338
|
+
const setSyncState = (attrs, current) => Effect.forEach(syncStates, (state) => Metric.update(Metric.withAttributes(syncState, {
|
|
339
|
+
...syncAttributes(attrs),
|
|
340
|
+
[Attr.syncState]: state
|
|
341
|
+
}), state === current ? 1 : 0), { discard: true });
|
|
342
|
+
/** @internal Converts the ergonomic SDK input to canonical OTel attributes. */
|
|
343
|
+
const withResourceAttributes = resourceAttributes;
|
|
344
|
+
//#endregion
|
|
345
|
+
export { annotateError as C, addCurrentSpanEvent as S, withResourceAttributes as _, lastSuccessTimestamp as a, EventName as b, recordWebhookRequest as c, setLastSuccessTimestamp as d, setSyncState as f, webhookRequests as g, webhookQueueDepth as h, ingestDuration as i, retrySchedule as l, syncState as m, batchSize as n, metrics_exports as o, setWebhookQueueDepth as p, batches as r, recordApiRetry as s, apiRetries as t, rowsIngested as u, Attr as v, telemetry_exports as w, SpanName as x, EventAttr as y };
|
|
346
|
+
|
|
347
|
+
//# sourceMappingURL=metrics-C901IIYZ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-C901IIYZ.mjs","names":[],"sources":["../src/telemetry.ts","../src/metrics.ts"],"sourcesContent":["import { Cause, Config, Effect, Layer, Metric, Option, Schema, type Duration } from \"effect\";\nimport { Headers } from \"effect/http\";\nimport * as Observability from \"effect/observability\";\n\nimport { PlatformRuntimeKey } from \"./runtime-config/constants\";\n\n/** Canonical span names emitted by connector-kit runtime instrumentation. */\nexport const SpanName = {\n batchProcess: \"connector.batch.process\",\n webhookDecode: \"connector.webhook.decode\",\n webhookHandle: \"connector.webhook.handle\",\n ingest: \"connector.ingest\",\n stateSet: \"connector.state.set\",\n apiFetch: \"connector.api.fetch\",\n} as const;\n\n/** Canonical span attribute names. Keep these stable for collector queries. */\nexport const Attr = {\n connectorName: \"airfoil.connector.name\",\n connectorResourcesCount: \"airfoil.connector.resources.count\",\n resourceName: \"airfoil.resource.name\",\n resourceSource: \"airfoil.resource.source\",\n batchRows: \"airfoil.batch.rows\",\n batchOutcome: \"airfoil.batch.outcome\",\n webhookPath: \"airfoil.webhook.path\",\n webhookOutcome: \"airfoil.webhook.outcome\",\n syncState: \"airfoil.connector.sync.state\",\n apiRetryReason: \"airfoil.connector.api.retry.reason\",\n ingestionSuccess: \"airfoil.ingestion.success\",\n stateKey: \"airfoil.state.key\",\n apiPath: \"airfoil.api.path\",\n errorPhase: \"airfoil.error.phase\",\n errorType: \"airfoil.error.type\",\n errorMessage: \"airfoil.error.message\",\n errorDetails: \"airfoil.error.details\",\n} as const;\n\n/** Resource attributes injected by the hosted operator through standard OTel environment keys. */\nexport const ResourceAttr = {\n serviceInstanceId: \"service.instance.id\",\n connectorRevision: \"airfoil.connector.revision\",\n teamId: \"airfoil.team.id\",\n} as const;\n\n/** Span event names for high-cardinality reproduction details. */\nexport const EventName = {\n batchCheckpoint: \"airfoil.batch.checkpoint\",\n} as const;\n\n/** Event-only attributes. These are intentionally not span attributes. */\nexport const EventAttr = {\n batchCursor: \"airfoil.batch.cursor\",\n} as const;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst maxErrorMessageLength = 500;\n\nconst OtlpEnvConfig = Config.all({\n enabled: Config.Boolean(PlatformRuntimeKey.otelEnabled).pipe(Config.withDefault(false)),\n baseUrl: Config.option(Config.String(PlatformRuntimeKey.otelExporterOtlpEndpoint)),\n headers: Config.option(\n Config.Record(\n Schema.String,\n Schema.StringFromUriComponent,\n PlatformRuntimeKey.otelExporterOtlpHeaders,\n { trim: true },\n ),\n ),\n});\n\nconst defaultRedactedHeaders: ReadonlyArray<string | RegExp> = [\n \"authorization\",\n \"cookie\",\n \"set-cookie\",\n \"x-api-key\",\n /api[-_]?key/i,\n /secret/i,\n /signature/i,\n /token/i,\n];\n\nconst appendPath = (baseUrl: string, path: string) =>\n `${baseUrl.replace(/\\/$/, \"\")}/${path.replace(/^\\//, \"\")}`;\n\n/**\n * Best-effort stable error classifier for span metadata.\n *\n * Effect/Data tagged errors expose `_tag`; that is the most useful value for\n * connector bugs (`ConnectorError`, `InvalidWebhookPayloadError`, etc.). For\n * non-tagged errors we fall back to the JS `Error.name`, then constructor name,\n * then the primitive type.\n */\nconst errorType = (error: unknown) => {\n if (isRecord(error) && typeof error._tag === \"string\") {\n return String(error._tag);\n }\n if (error instanceof Error) {\n return error.name;\n }\n if (isRecord(error) && typeof error.constructor?.name === \"string\") {\n return error.constructor.name;\n }\n return typeof error;\n};\n\n/**\n * Human-readable error summary for span metadata.\n *\n * Tagged errors in this package carry a `message` field, so this preserves the\n * important diagnostic text. Unknown object failures are intentionally reduced\n * to their type; full structured error payloads belong in logs, not span attrs.\n */\nconst errorMessage = (error: unknown) => {\n const message = (() => {\n if (isRecord(error) && typeof error.message === \"string\") {\n return error.message;\n }\n if (typeof error === \"string\") {\n return error;\n }\n return errorType(error);\n })();\n\n if (message.length > maxErrorMessageLength) {\n return `${message.slice(0, maxErrorMessageLength)}...`;\n }\n\n return message;\n};\n\nconst errorDetails = (error: unknown): string | undefined => {\n if (!isRecord(error) || error.cause === undefined) return undefined;\n return Cause.pretty(Cause.die(error.cause));\n};\n\n/** Annotates the active span with phase-aware error metadata before re-failing. */\nexport const annotateError = (phase: string, error: unknown) => {\n const details = errorDetails(error);\n return Effect.annotateCurrentSpan({\n [Attr.errorPhase]: phase,\n [Attr.errorType]: errorType(error),\n [Attr.errorMessage]: errorMessage(error),\n ...(details !== undefined ? { [Attr.errorDetails]: details } : {}),\n });\n};\n\n/** Adds an event to the active span, or no-ops when no span is active. */\nexport const addCurrentSpanEvent = (name: string, attributes?: Record<string, unknown>) =>\n Effect.currentSpan.pipe(\n Effect.flatMap((span) =>\n Effect.clockWith((clock) =>\n Effect.sync(() => span.event(name, clock.currentTimeNanosUnsafe(), attributes)),\n ),\n ),\n Effect.ignore,\n );\n\n/** Transport configuration for OTLP trace export. All fields are direct values. */\nexport type OtlpTracingConfig = {\n readonly enabled?: boolean;\n readonly endpoint?: string;\n readonly headers?: Record<string, string>;\n};\n\n/** Runtime options — not config-wrappable since RegExp cannot live in Config. */\nexport type OtlpTracingOptions = {\n /** Additional connector-specific header names or regexes to redact from HTTP logs/traces. */\n readonly redactedHeaders?: ReadonlyArray<string | RegExp>;\n};\n\n/** OTLP metric export settings. */\nexport type OtlpMetricsOptions = {\n readonly exportInterval?: Duration.Input;\n};\n\nconst buildOtlpTracingLayer = (config: OtlpTracingConfig, options: OtlpTracingOptions) =>\n Effect.gen(function* () {\n const allRedacted = [...defaultRedactedHeaders, ...(options.redactedHeaders ?? [])];\n const RedactionLayer = Layer.succeed(Headers.CurrentRedactedNames)(allRedacted);\n\n if (!config.enabled) {\n return RedactionLayer;\n }\n\n if (!config.endpoint) {\n return yield* Effect.fail(new Error(\"enabled=true requires endpoint\"));\n }\n\n yield* Effect.logInfo(\"telemetry enabled\").pipe(\n Effect.annotateLogs({\n endpoint: config.endpoint,\n headers: config.headers ? Object.keys(config.headers) : [],\n }),\n );\n\n return Layer.mergeAll(\n RedactionLayer,\n Observability.OtlpTracer.layer({\n url: appendPath(config.endpoint, \"/v1/traces\"),\n headers: config.headers,\n }).pipe(Layer.provide(Observability.OtlpSerialization.layerJson)),\n );\n });\n\n/**\n * Trace-only OTLP export with sensitive HTTP header redaction.\n * Takes direct config values — no `ConfigProvider` required.\n */\nexport const layer = (config: OtlpTracingConfig = {}, options: OtlpTracingOptions = {}) =>\n Layer.unwrap(buildOtlpTracingLayer(config, options));\n\n/**\n * Trace-only OTLP export with sensitive HTTP header redaction.\n * Takes Effect Config-wrapped values — reads from `ConfigProvider`.\n *\n * @example\n * Telemetry.layerConfig({\n * enabled: Config.Boolean(\"MY_OTEL_ENABLED\"),\n * endpoint: Config.String(\"MY_COLLECTOR_URL\"),\n * })\n */\nexport const layerConfig = (\n config: Config.Wrap<OtlpTracingConfig>,\n options: OtlpTracingOptions = {},\n) =>\n Layer.unwrap(\n Effect.gen(function* () {\n const resolved = yield* Config.unwrap(config);\n return yield* buildOtlpTracingLayer(resolved, options);\n }),\n );\n\n/**\n * Trace-only OTLP export with sensitive HTTP header redaction.\n * Zero-config shortcut that reads the standard `OTEL_*` env var names.\n *\n * Reads `OTEL_ENABLED`, `OTEL_EXPORTER_OTLP_ENDPOINT`, and\n * `OTEL_EXPORTER_OTLP_HEADERS`. Effect's OTLP resource handling reads\n * `OTEL_SERVICE_NAME`, `OTEL_SERVICE_VERSION`, and `OTEL_RESOURCE_ATTRIBUTES`.\n */\nexport const layerOtlpTracing = (options: OtlpTracingOptions = {}) =>\n Layer.unwrap(\n Effect.gen(function* () {\n const raw = yield* OtlpEnvConfig;\n return yield* buildOtlpTracingLayer(\n {\n enabled: raw.enabled,\n endpoint: Option.getOrUndefined(raw.baseUrl),\n headers: Option.getOrUndefined(raw.headers),\n },\n options,\n );\n }),\n );\n\n/** Exports connector metrics over OTLP when telemetry is enabled. */\nexport const layerOtlpMetrics = (options: OtlpMetricsOptions = {}) =>\n Layer.unwrap(\n Effect.gen(function* () {\n const raw = yield* OtlpEnvConfig;\n if (!raw.enabled) return Layer.empty;\n const endpoint = Option.getOrUndefined(raw.baseUrl);\n if (!endpoint)\n return yield* Effect.fail(\n new Error(\"OTEL_ENABLED=true requires OTEL_EXPORTER_OTLP_ENDPOINT\"),\n );\n return Observability.OtlpMetrics.layer({\n url: appendPath(endpoint, \"/v1/metrics\"),\n headers: Option.getOrUndefined(raw.headers),\n exportInterval: options.exportInterval,\n temporality: \"cumulative\",\n }).pipe(Layer.provide(Observability.OtlpSerialization.layerJson));\n }),\n );\n\n/** Enables OTLP traces and metrics with shared environment configuration. */\nexport const layerOtlp = (options: OtlpTracingOptions & OtlpMetricsOptions = {}) =>\n Layer.mergeAll(layerOtlpTracing(options), layerOtlpMetrics(options));\n\n/** Periodically logs the in-memory metric snapshot for local debugging. */\nexport const layerMetricsConsoleDump = (interval: Duration.Input = \"30 seconds\") =>\n Layer.effectDiscard(\n Effect.gen(function* () {\n yield* Effect.forkScoped(\n Effect.forever(\n Metric.dump.pipe(\n Effect.flatMap((snapshot) => Effect.logInfo(snapshot)),\n Effect.andThen(Effect.sleep(interval)),\n ),\n ),\n );\n }),\n );\n","import {\n Cause,\n DateTime,\n type Duration,\n Effect,\n Metric,\n Option,\n Predicate,\n Schedule,\n} from \"effect\";\nimport { HttpClientError, HttpClientResponse } from \"effect/http\";\n\nimport type { SyncState } from \"./core/types\";\n\nimport { Attr } from \"./telemetry\";\n\nexport type BatchSource = \"backfill\" | \"changes\" | \"webhook\" | \"demo\";\nexport type BatchOutcome = \"success\" | \"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 batches = Metric.counter(\"airfoil.connector.batches\", {\n description: \"Total resource batches ingested by connector sources\",\n incremental: true,\n attributes: { unit: \"{batch}\" },\n});\n\nexport const rowsIngested = Metric.counter(\"airfoil.connector.rows.ingested\", {\n description: \"Total resource rows successfully ingested\",\n incremental: true,\n attributes: { unit: \"{row}\" },\n});\n\nexport const batchSize = Metric.histogram(\"airfoil.connector.batch.size\", {\n description: \"Distribution of resource row batch sizes\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000],\n attributes: { unit: \"{row}\" },\n});\n\nexport const ingestDuration = Metric.timer(\"airfoil.connector.ingest.duration\", {\n description: \"Ingestor call duration in milliseconds\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n attributes: { unit: \"ms\" },\n});\n\nexport const webhookRequests = Metric.counter(\"airfoil.connector.webhook.requests\", {\n description: \"Total webhook HTTP requests handled by connector routes\",\n incremental: true,\n attributes: { unit: \"{request}\" },\n});\n\nexport const webhookQueueDepth = Metric.gauge(\"airfoil.connector.webhook.queue.depth\", {\n description: \"Current queued webhook batches waiting for ingestion\",\n attributes: { unit: \"{batch}\" },\n});\n\nexport const syncState = Metric.gauge(\"airfoil.connector.sync.state\", {\n description: \"Connector resource sync state as a Prometheus state-set gauge\",\n attributes: { unit: \"1\" },\n});\n\nexport const lastSuccessTimestamp = Metric.gauge(\"airfoil.connector.last_success.timestamp\", {\n description: \"Unix timestamp of the last successful durable source checkpoint\",\n attributes: { unit: \"s\" },\n});\n\nexport const apiRetries = Metric.counter(\"airfoil.connector.api.retries\", {\n description: \"Total provider API retries performed by the connector\",\n incremental: true,\n attributes: { unit: \"{retry}\" },\n});\n\nconst resourceAttributes = (attrs: ResourceMetricAttrs) => ({\n [Attr.connectorName]: attrs.connector,\n [Attr.resourceName]: attrs.resource,\n [Attr.resourceSource]: attrs.source,\n});\n\nconst syncAttributes = (attrs: SyncStateAttrs) => ({\n [Attr.connectorName]: attrs.connector,\n [Attr.resourceName]: attrs.resource,\n});\n\nexport const recordWebhookRequest = (attrs: WebhookMetricAttrs) =>\n Metric.update(\n Metric.withAttributes(webhookRequests, {\n [Attr.connectorName]: attrs.connector,\n [Attr.webhookPath]: attrs.path,\n [Attr.webhookOutcome]: attrs.outcome,\n }),\n 1,\n );\n\nexport const setWebhookQueueDepth = (connector: string, depth: number) =>\n Metric.update(\n Metric.withAttributes(webhookQueueDepth, { [Attr.connectorName]: connector }),\n depth,\n );\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(\n Metric.withAttributes(lastSuccessTimestamp, {\n [Attr.connectorName]: attrs.connector,\n [Attr.resourceName]: attrs.resource,\n [Attr.resourceSource]: attrs.source,\n }),\n timestamp,\n );\n};\n\nexport const recordApiRetry = (attrs: ApiRetryMetricAttrs) =>\n Metric.update(\n Metric.withAttributes(apiRetries, {\n [Attr.connectorName]: attrs.connector,\n [Attr.apiRetryReason]: attrs.reason,\n }),\n 1,\n );\n\n// Same statuses as `HttpClient.retryTransient`.\nconst transientStatuses = new Set([408, 429, 500, 502, 503, 504]);\n\n// A connector only retries a `403` when the provider uses it for rate limits.\nconst reasonForStatus = (status: number): ApiRetryReason =>\n status === 408 ? \"timeout\" : status === 429 || status === 403 ? \"rate_limit\" : \"server_error\";\n\n// Effect exports the response type ID, not a guard.\nconst isResponse = (value: unknown): value is HttpClientResponse.HttpClientResponse =>\n Predicate.hasProperty(value, HttpClientResponse.TypeId);\n\n/** Why `HttpClient.retryTransient` retries. Undefined for a response it keeps. */\nconst retryReason = (value: unknown): ApiRetryReason | undefined => {\n if (isResponse(value)) {\n return transientStatuses.has(value.status) ? reasonForStatus(value.status) : undefined;\n }\n if (HttpClientError.isHttpClientError(value) && value.reason._tag === \"StatusCodeError\") {\n return reasonForStatus(value.reason.response.status);\n }\n return Cause.isTimeoutError(value) ? \"timeout\" : \"transport\";\n};\n\n/**\n * A jittered exponential schedule for `HttpClient.retryTransient` that records\n * each retry with its reason.\n */\nexport const retrySchedule = (options: {\n readonly connector: string;\n readonly baseDelay: Duration.Input;\n readonly times: number;\n}) =>\n Schedule.exponential(options.baseDelay).pipe(\n Schedule.jittered,\n Schedule.upTo({ times: options.times }),\n Schedule.tap(({ input }) => {\n const reason = retryReason(input);\n return reason === undefined\n ? Effect.void\n : recordApiRetry({ connector: options.connector, reason });\n }),\n );\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 ...syncAttributes(attrs),\n [Attr.syncState]: state,\n }),\n state === current ? 1 : 0,\n ),\n { discard: true },\n );\n\n/** @internal Converts the ergonomic SDK input to canonical OTel attributes. */\nexport const withResourceAttributes = resourceAttributes;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAOA,MAAa,WAAW;CACtB,cAAc;CACd,eAAe;CACf,eAAe;CACf,QAAQ;CACR,UAAU;CACV,UAAU;AACZ;;AAGA,MAAa,OAAO;CAClB,eAAe;CACf,yBAAyB;CACzB,cAAc;CACd,gBAAgB;CAChB,WAAW;CACX,cAAc;CACd,aAAa;CACb,gBAAgB;CAChB,WAAW;CACX,gBAAgB;CAChB,kBAAkB;CAClB,UAAU;CACV,SAAS;CACT,YAAY;CACZ,WAAW;CACX,cAAc;CACd,cAAc;AAChB;;AAGA,MAAa,eAAe;CAC1B,mBAAmB;CACnB,mBAAmB;CACnB,QAAQ;AACV;;AAGA,MAAa,YAAY,EACvB,iBAAiB,2BACnB;;AAGA,MAAa,YAAY,EACvB,aAAa,uBACf;AAEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,MAAM,wBAAwB;AAE9B,MAAM,gBAAgB,OAAO,IAAI;CAC/B,SAAS,OAAO,QAAQ,mBAAmB,WAAW,CAAC,CAAC,KAAK,OAAO,YAAY,KAAK,CAAC;CACtF,SAAS,OAAO,OAAO,OAAO,OAAO,mBAAmB,wBAAwB,CAAC;CACjF,SAAS,OAAO,OACd,OAAO,OACL,OAAO,QACP,OAAO,wBACP,mBAAmB,yBACnB,EAAE,MAAM,KAAK,CACf,CACF;AACF,CAAC;AAED,MAAM,yBAAyD;CAC7D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,cAAc,SAAiB,SACnC,GAAG,QAAQ,QAAQ,OAAO,EAAE,EAAE,GAAG,KAAK,QAAQ,OAAO,EAAE;;;;;;;;;AAUzD,MAAM,aAAa,UAAmB;CACpC,IAAI,SAAS,KAAK,KAAK,OAAO,MAAM,SAAS,U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,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Effect, Metric } from "effect";
|
|
3
|
-
import * as effect_Duration0 from "effect/Duration";
|
|
4
|
-
|
|
5
|
-
//#region src/metrics.d.ts
|
|
1
|
+
import { w as SyncState } from "./types-NtSv6gwl.mjs";
|
|
2
|
+
import { Duration, Effect, Metric, Schedule } from "effect";
|
|
6
3
|
declare namespace metrics_d_exports {
|
|
7
|
-
export { ApiRetryMetricAttrs, ApiRetryReason, BatchOutcome, BatchSource, LastSuccessMetricAttrs, ResourceMetricAttrs, SyncStateAttrs, WebhookMetricAttrs, WebhookOutcome, apiRetries, batchSize, batches,
|
|
4
|
+
export { ApiRetryMetricAttrs, ApiRetryReason, BatchOutcome, BatchSource, LastSuccessMetricAttrs, ResourceMetricAttrs, SyncStateAttrs, WebhookMetricAttrs, WebhookOutcome, apiRetries, batchSize, batches, ingestDuration, lastSuccessTimestamp, recordApiRetry, recordWebhookRequest, retrySchedule, rowsIngested, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequests, withResourceAttributes };
|
|
8
5
|
}
|
|
9
|
-
type BatchSource = "backfill" | "changes" | "webhook";
|
|
10
|
-
type BatchOutcome = "
|
|
6
|
+
type BatchSource = "backfill" | "changes" | "webhook" | "demo";
|
|
7
|
+
type BatchOutcome = "success" | "error";
|
|
11
8
|
type ApiRetryReason = "transport" | "timeout" | "rate_limit" | "server_error";
|
|
12
9
|
type WebhookOutcome = "ok" | "read_error" | "invalid_json" | "invalid_payload" | "rejected" | "handler_error";
|
|
13
10
|
type ResourceMetricAttrs = {
|
|
@@ -33,11 +30,10 @@ type ApiRetryMetricAttrs = {
|
|
|
33
30
|
readonly connector: string;
|
|
34
31
|
readonly reason: ApiRetryReason;
|
|
35
32
|
};
|
|
36
|
-
declare const entitiesUpserted: Metric.Counter<number>;
|
|
37
|
-
declare const entitiesDeleted: Metric.Counter<number>;
|
|
38
33
|
declare const batches: Metric.Counter<number>;
|
|
34
|
+
declare const rowsIngested: Metric.Counter<number>;
|
|
39
35
|
declare const batchSize: Metric.Histogram<number>;
|
|
40
|
-
declare const
|
|
36
|
+
declare const ingestDuration: Metric.Histogram<Duration.Duration>;
|
|
41
37
|
declare const webhookRequests: Metric.Counter<number>;
|
|
42
38
|
declare const webhookQueueDepth: Metric.Gauge<number>;
|
|
43
39
|
declare const syncState: Metric.Gauge<number>;
|
|
@@ -47,6 +43,15 @@ declare const recordWebhookRequest: (attrs: WebhookMetricAttrs) => Effect.Effect
|
|
|
47
43
|
declare const setWebhookQueueDepth: (connector: string, depth: number) => Effect.Effect<void, never, never>;
|
|
48
44
|
declare const setLastSuccessTimestamp: (attrs: LastSuccessMetricAttrs, lastSuccessAt?: string) => Effect.Effect<void, never, never>;
|
|
49
45
|
declare const recordApiRetry: (attrs: ApiRetryMetricAttrs) => Effect.Effect<void, never, never>;
|
|
46
|
+
/**
|
|
47
|
+
* A jittered exponential schedule for `HttpClient.retryTransient` that records
|
|
48
|
+
* each retry with its reason.
|
|
49
|
+
*/
|
|
50
|
+
declare const retrySchedule: (options: {
|
|
51
|
+
readonly connector: string;
|
|
52
|
+
readonly baseDelay: Duration.Input;
|
|
53
|
+
readonly times: number;
|
|
54
|
+
}) => Schedule.Schedule<Duration.Duration, unknown, never, never>;
|
|
50
55
|
declare const setSyncState: (attrs: SyncStateAttrs, current: SyncState) => Effect.Effect<void, never, never>;
|
|
51
56
|
/** @internal Converts the ergonomic SDK input to canonical OTel attributes. */
|
|
52
57
|
declare const withResourceAttributes: (attrs: ResourceMetricAttrs) => {
|
|
@@ -55,5 +60,5 @@ declare const withResourceAttributes: (attrs: ResourceMetricAttrs) => {
|
|
|
55
60
|
"airfoil.resource.source": BatchSource;
|
|
56
61
|
};
|
|
57
62
|
//#endregion
|
|
58
|
-
export { syncState as C, withResourceAttributes as E, setWebhookQueueDepth as S, webhookRequests as T,
|
|
59
|
-
//# sourceMappingURL=metrics-
|
|
63
|
+
export { syncState as C, withResourceAttributes as E, setWebhookQueueDepth as S, webhookRequests as T, recordWebhookRequest as _, LastSuccessMetricAttrs as a, setLastSuccessTimestamp as b, WebhookMetricAttrs as c, batchSize as d, batches as f, recordApiRetry as g, metrics_d_exports as h, BatchSource as i, WebhookOutcome as l, lastSuccessTimestamp as m, ApiRetryReason as n, ResourceMetricAttrs as o, ingestDuration as p, BatchOutcome as r, SyncStateAttrs as s, ApiRetryMetricAttrs as t, apiRetries as u, retrySchedule as v, webhookQueueDepth as w, setSyncState as x, rowsIngested as y };
|
|
64
|
+
//# sourceMappingURL=metrics-DoJ0WeKu.d.mts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as syncState, E as withResourceAttributes, S as setWebhookQueueDepth, T as webhookRequests, _ as recordWebhookRequest, a as LastSuccessMetricAttrs, b as setLastSuccessTimestamp, c as WebhookMetricAttrs, d as batchSize, f as batches, g as recordApiRetry, i as BatchSource, l as WebhookOutcome, m as lastSuccessTimestamp, n as ApiRetryReason, o as ResourceMetricAttrs, p as ingestDuration, r as BatchOutcome, s as SyncStateAttrs, t as ApiRetryMetricAttrs, u as apiRetries, v as retrySchedule, w as webhookQueueDepth, x as setSyncState, y as rowsIngested } from "./metrics-DoJ0WeKu.mjs";
|
|
2
|
+
export { ApiRetryMetricAttrs, ApiRetryReason, BatchOutcome, BatchSource, LastSuccessMetricAttrs, ResourceMetricAttrs, SyncStateAttrs, WebhookMetricAttrs, WebhookOutcome, apiRetries, batchSize, batches, ingestDuration, lastSuccessTimestamp, recordApiRetry, recordWebhookRequest, retrySchedule, rowsIngested, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequests, withResourceAttributes };
|
package/dist/metrics.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as withResourceAttributes, a as lastSuccessTimestamp, c as recordWebhookRequest, d as setLastSuccessTimestamp, f as setSyncState, g as webhookRequests, h as webhookQueueDepth, i as ingestDuration, l as retrySchedule, m as syncState, n as batchSize, p as setWebhookQueueDepth, r as batches, s as recordApiRetry, t as apiRetries, u as rowsIngested } from "./metrics-C901IIYZ.mjs";
|
|
2
|
+
export { apiRetries, batchSize, batches, ingestDuration, lastSuccessTimestamp, recordApiRetry, recordWebhookRequest, retrySchedule, rowsIngested, setLastSuccessTimestamp, setSyncState, setWebhookQueueDepth, syncState, webhookQueueDepth, webhookRequests, withResourceAttributes };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
5
|
for (var name in all) __defProp(target, name, {
|
|
6
6
|
get: all[name],
|
|
7
7
|
enumerable: true
|
|
8
8
|
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
9
10
|
return target;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
12
|
//#endregion
|
|
13
|
-
export {
|
|
13
|
+
export { __exportAll as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as layerHosted, c as catalog, d as httpPort, f as RuntimeConfigError, i as loadTableBindings, l as engineUri, n as ResolvedTableBindings, o as PlatformRuntimeDefault, p as RuntimeConfigErrorCode, r as TableBinding, s as PlatformRuntimeKey, u as flightUri } from "../index-fHIJJoRe.mjs";
|
|
2
|
+
export { PlatformRuntimeDefault, PlatformRuntimeKey, type ResolvedTableBindings, RuntimeConfigError, type RuntimeConfigErrorCode, type TableBinding, catalog, engineUri, flightUri, httpPort, layerHosted, loadTableBindings };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as PlatformRuntimeKey, t as PlatformRuntimeDefault } from "../constants-v3UX-hf6.mjs";
|
|
2
|
+
import { a as catalog, c as httpPort, i as RuntimeConfigError, n as loadTableBindings, o as engineUri, r as layerHosted, s as flightUri } from "../runtime-config-Bn8Fivt1.mjs";
|
|
3
|
+
export { PlatformRuntimeDefault, PlatformRuntimeKey, RuntimeConfigError, catalog, engineUri, flightUri, httpPort, layerHosted, loadTableBindings };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { n as PlatformRuntimeKey, t as PlatformRuntimeDefault } from "./constants-v3UX-hf6.mjs";
|
|
3
|
+
import { Config, ConfigProvider, Data, Effect, FileSystem, Schema } from "effect";
|
|
4
|
+
//#region src/runtime-config/config.ts
|
|
5
|
+
/** Shared HTTP port used by hosted and sandbox connector entrypoints. */
|
|
6
|
+
const httpPort = Config.Port(PlatformRuntimeKey.httpPort).pipe(Config.withDefault(PlatformRuntimeDefault.httpPort));
|
|
7
|
+
/** Engine URL, including the protocol. */
|
|
8
|
+
const engineUri = Config.URL(PlatformRuntimeKey.engineUri);
|
|
9
|
+
/** Arrow Flight URL. Uses the engine URL when unset. */
|
|
10
|
+
const flightUri = engineUri.pipe(Config.flatMap((uri) => Config.URL(PlatformRuntimeKey.flightUri).pipe(Config.withDefault(uri))));
|
|
11
|
+
/** Catalog ID. */
|
|
12
|
+
const catalog = Config.NonEmptyString(PlatformRuntimeKey.catalog);
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/runtime-config/error.ts
|
|
15
|
+
/** Expected hosted-config failure with a stable code and diagnostic cause. */
|
|
16
|
+
var RuntimeConfigError = class extends Data.TaggedError("RuntimeConfigError") {};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/runtime-config/layer.ts
|
|
19
|
+
const providerFromFile = Effect.gen(function* () {
|
|
20
|
+
const configPath = yield* Config.NonEmptyString(PlatformRuntimeKey.configPath).pipe(Effect.mapError((error) => new RuntimeConfigError({
|
|
21
|
+
code: "CONFIG_PATH_MISSING",
|
|
22
|
+
message: `${PlatformRuntimeKey.configPath} is required in hosted mode`,
|
|
23
|
+
cause: error.cause
|
|
24
|
+
})));
|
|
25
|
+
const contents = yield* (yield* FileSystem.FileSystem).readFileString(configPath).pipe(Effect.mapError((cause) => new RuntimeConfigError({
|
|
26
|
+
code: "CONFIG_FILE_UNREADABLE",
|
|
27
|
+
message: "Connector config file could not be read",
|
|
28
|
+
cause
|
|
29
|
+
})));
|
|
30
|
+
const document = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(contents).pipe(Effect.mapError((error) => new RuntimeConfigError({
|
|
31
|
+
code: "CONFIG_JSON_INVALID",
|
|
32
|
+
message: "Connector config is not valid JSON",
|
|
33
|
+
cause: error
|
|
34
|
+
})));
|
|
35
|
+
return ConfigProvider.fromUnknown(document, { preserveEmptyStrings: true });
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Loads the required JSON file and lets environment values override it per key.
|
|
39
|
+
* Connector field validation remains in the connector's Effect Config.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* program.pipe(Effect.provide(layerHosted()));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const layerHosted = () => ConfigProvider.layerAdd(providerFromFile);
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/runtime-config/table-bindings.ts
|
|
49
|
+
const TableIdentifierSchema = Schema.Struct({
|
|
50
|
+
namespace: Schema.NonEmptyArray(Schema.NonEmptyString),
|
|
51
|
+
name: Schema.NonEmptyString,
|
|
52
|
+
location: Schema.optional(Schema.NonEmptyString)
|
|
53
|
+
});
|
|
54
|
+
const RawBindingsSchema = Schema.fromJsonString(Schema.Record(Schema.String, TableIdentifierSchema));
|
|
55
|
+
const asError = (cause) => cause instanceof Error ? cause : new Error(String(cause));
|
|
56
|
+
const fail = (code, message) => new RuntimeConfigError({
|
|
57
|
+
code,
|
|
58
|
+
message,
|
|
59
|
+
cause: new Error(message)
|
|
60
|
+
});
|
|
61
|
+
/** Reads hosted table bindings and checks they name resources of the connector. */
|
|
62
|
+
const loadTableBindings = (connector) => Effect.gen(function* () {
|
|
63
|
+
const raw = yield* Config.NonEmptyString(PlatformRuntimeKey.tableBindings).pipe(Effect.mapError((cause) => new RuntimeConfigError({
|
|
64
|
+
code: "TABLE_BINDINGS_MISSING",
|
|
65
|
+
message: `${PlatformRuntimeKey.tableBindings} is required in hosted mode`,
|
|
66
|
+
cause: asError(cause)
|
|
67
|
+
})));
|
|
68
|
+
const decoded = yield* Schema.decodeUnknownEffect(RawBindingsSchema)(raw, { onExcessProperty: "error" }).pipe(Effect.mapError((cause) => new RuntimeConfigError({
|
|
69
|
+
code: "TABLE_BINDINGS_INVALID",
|
|
70
|
+
message: "Hosted table bindings are invalid",
|
|
71
|
+
cause: asError(cause)
|
|
72
|
+
})));
|
|
73
|
+
const actual = Object.keys(decoded);
|
|
74
|
+
if (actual.length === 0) return yield* Effect.fail(fail("TABLE_BINDINGS_INVALID", "Hosted table bindings name no resources"));
|
|
75
|
+
const expected = new Set(connector.resources.map((resource) => resource.name));
|
|
76
|
+
const unknown = actual.filter((name) => !expected.has(name));
|
|
77
|
+
if (unknown.length > 0) return yield* Effect.fail(fail("TABLE_BINDINGS_MISMATCH", `Hosted table bindings name resources the connector doesn't have (${unknown.length})`));
|
|
78
|
+
return Object.fromEntries(Object.entries(decoded).map(([resource, identifier]) => [resource, {
|
|
79
|
+
namespace: Array.from(identifier.namespace),
|
|
80
|
+
name: identifier.name,
|
|
81
|
+
...identifier.location === void 0 ? {} : { location: identifier.location }
|
|
82
|
+
}]));
|
|
83
|
+
});
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/runtime-config/index.ts
|
|
86
|
+
var runtime_config_exports = /* @__PURE__ */ __exportAll({
|
|
87
|
+
PlatformRuntimeDefault: () => PlatformRuntimeDefault,
|
|
88
|
+
PlatformRuntimeKey: () => PlatformRuntimeKey,
|
|
89
|
+
RuntimeConfigError: () => RuntimeConfigError,
|
|
90
|
+
catalog: () => catalog,
|
|
91
|
+
engineUri: () => engineUri,
|
|
92
|
+
flightUri: () => flightUri,
|
|
93
|
+
httpPort: () => httpPort,
|
|
94
|
+
layerHosted: () => layerHosted,
|
|
95
|
+
loadTableBindings: () => loadTableBindings
|
|
96
|
+
});
|
|
97
|
+
//#endregion
|
|
98
|
+
export { catalog as a, httpPort as c, RuntimeConfigError as i, loadTableBindings as n, engineUri as o, layerHosted as r, flightUri as s, runtime_config_exports as t };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=runtime-config-Bn8Fivt1.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-config-Bn8Fivt1.mjs","names":[],"sources":["../src/runtime-config/config.ts","../src/runtime-config/error.ts","../src/runtime-config/layer.ts","../src/runtime-config/table-bindings.ts","../src/runtime-config/index.ts"],"sourcesContent":["import { Config } from \"effect\";\n\nimport { PlatformRuntimeDefault, PlatformRuntimeKey } from \"./constants\";\n\n/** Shared HTTP port used by hosted and sandbox connector entrypoints. */\nexport const httpPort = Config.Port(PlatformRuntimeKey.httpPort).pipe(\n Config.withDefault(PlatformRuntimeDefault.httpPort),\n);\n\n/** Engine URL, including the protocol. */\nexport const engineUri = Config.URL(PlatformRuntimeKey.engineUri);\n\n/** Arrow Flight URL. Uses the engine URL when unset. */\nexport const flightUri = engineUri.pipe(\n Config.flatMap((uri) => Config.URL(PlatformRuntimeKey.flightUri).pipe(Config.withDefault(uri))),\n);\n\n/** Catalog ID. */\nexport const catalog = Config.NonEmptyString(PlatformRuntimeKey.catalog);\n","import { Data } from \"effect\";\n\nexport type RuntimeConfigErrorCode =\n | \"CONFIG_PATH_MISSING\"\n | \"CONFIG_FILE_UNREADABLE\"\n | \"CONFIG_JSON_INVALID\"\n | \"TABLE_BINDINGS_MISSING\"\n | \"TABLE_BINDINGS_INVALID\"\n | \"TABLE_BINDINGS_MISMATCH\";\n\n/** Expected hosted-config failure with a stable code and diagnostic cause. */\nexport class RuntimeConfigError extends Data.TaggedError(\"RuntimeConfigError\")<{\n readonly code: RuntimeConfigErrorCode;\n readonly message: string;\n readonly cause: Error;\n}> {}\n","import { Config, ConfigProvider, Effect, FileSystem, Schema } from \"effect\";\n\nimport { PlatformRuntimeKey } from \"./constants\";\nimport { RuntimeConfigError } from \"./error\";\n\nconst providerFromFile: Effect.Effect<\n ConfigProvider.ConfigProvider,\n RuntimeConfigError,\n FileSystem.FileSystem\n> = Effect.gen(function* () {\n const configPath = yield* Config.NonEmptyString(PlatformRuntimeKey.configPath).pipe(\n Effect.mapError(\n (error) =>\n new RuntimeConfigError({\n code: \"CONFIG_PATH_MISSING\",\n message: `${PlatformRuntimeKey.configPath} is required in hosted mode`,\n cause: error.cause,\n }),\n ),\n );\n const fileSystem = yield* FileSystem.FileSystem;\n const contents = yield* fileSystem.readFileString(configPath).pipe(\n Effect.mapError(\n (cause) =>\n new RuntimeConfigError({\n code: \"CONFIG_FILE_UNREADABLE\",\n message: \"Connector config file could not be read\",\n cause,\n }),\n ),\n );\n const document = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(\n contents,\n ).pipe(\n Effect.mapError(\n (error) =>\n new RuntimeConfigError({\n code: \"CONFIG_JSON_INVALID\",\n message: \"Connector config is not valid JSON\",\n cause: error,\n }),\n ),\n );\n return ConfigProvider.fromUnknown(document, { preserveEmptyStrings: true });\n});\n\n/**\n * Loads the required JSON file and lets environment values override it per key.\n * Connector field validation remains in the connector's Effect Config.\n *\n * @example\n * ```ts\n * program.pipe(Effect.provide(layerHosted()));\n * ```\n */\nexport const layerHosted = () => ConfigProvider.layerAdd(providerFromFile);\n","import type { TableIdentifier } from \"iceberg-js\";\n\nimport { Config, Effect, Schema } from \"effect\";\n\nimport { PlatformRuntimeKey } from \"./constants\";\nimport { RuntimeConfigError } from \"./error\";\n\ntype BindingSource = {\n readonly resources: ReadonlyArray<{ readonly name: string }>;\n};\n\n/** An Iceberg table and its storage location for each connector resource. */\nexport type TableBinding = TableIdentifier & { readonly location?: string | undefined };\n\nexport type ResolvedTableBindings<Source extends BindingSource> = Readonly<\n Partial<Record<Source[\"resources\"][number][\"name\"], TableBinding>>\n>;\n\nconst TableIdentifierSchema = Schema.Struct({\n namespace: Schema.NonEmptyArray(Schema.NonEmptyString),\n name: Schema.NonEmptyString,\n location: Schema.optional(Schema.NonEmptyString),\n});\n\nconst RawBindingsSchema = Schema.fromJsonString(\n Schema.Record(Schema.String, TableIdentifierSchema),\n);\n\nconst asError = (cause: unknown): Error =>\n cause instanceof Error ? cause : new Error(String(cause));\n\nconst fail = (code: \"TABLE_BINDINGS_INVALID\" | \"TABLE_BINDINGS_MISMATCH\", message: string) =>\n new RuntimeConfigError({ code, message, cause: new Error(message) });\n\n/** Reads hosted table bindings and checks they name resources of the connector. */\nexport const loadTableBindings = <const Source extends BindingSource>(\n connector: Source,\n): Effect.Effect<ResolvedTableBindings<Source>, RuntimeConfigError> =>\n Effect.gen(function* () {\n const raw = yield* Config.NonEmptyString(PlatformRuntimeKey.tableBindings).pipe(\n Effect.mapError(\n (cause) =>\n new RuntimeConfigError({\n code: \"TABLE_BINDINGS_MISSING\",\n message: `${PlatformRuntimeKey.tableBindings} is required in hosted mode`,\n cause: asError(cause),\n }),\n ),\n );\n\n const decoded = yield* Schema.decodeUnknownEffect(RawBindingsSchema)(raw, {\n onExcessProperty: \"error\",\n }).pipe(\n Effect.mapError(\n (cause) =>\n new RuntimeConfigError({\n code: \"TABLE_BINDINGS_INVALID\",\n message: \"Hosted table bindings are invalid\",\n cause: asError(cause),\n }),\n ),\n );\n\n const actual = Object.keys(decoded);\n if (actual.length === 0) {\n return yield* Effect.fail(\n fail(\"TABLE_BINDINGS_INVALID\", \"Hosted table bindings name no resources\"),\n );\n }\n\n // Bindings come from the platform, resources from the connector. An unknown name\n // means one of them is out of date, and we could write to the wrong table.\n const expected = new Set(connector.resources.map((resource) => resource.name));\n const unknown = actual.filter((name) => !expected.has(name));\n if (unknown.length > 0) {\n return yield* Effect.fail(\n fail(\n \"TABLE_BINDINGS_MISMATCH\",\n `Hosted table bindings name resources the connector doesn't have (${unknown.length})`,\n ),\n );\n }\n\n return Object.fromEntries(\n Object.entries(decoded).map(([resource, identifier]) => [\n resource,\n {\n namespace: Array.from(identifier.namespace),\n name: identifier.name,\n ...(identifier.location === undefined ? {} : { location: identifier.location }),\n },\n ]),\n ) as ResolvedTableBindings<Source>;\n });\n","export { RuntimeConfigError, type RuntimeConfigErrorCode } from \"./error\";\nexport { catalog, engineUri, flightUri, httpPort } from \"./config\";\nexport { PlatformRuntimeDefault, PlatformRuntimeKey } from \"./constants\";\nexport { layerHosted } from \"./layer\";\nexport { type ResolvedTableBindings, type TableBinding, loadTableBindings } from \"./table-bindings\";\n"],"mappings":";;;;;AAKA,MAAa,WAAW,OAAO,KAAK,mBAAmB,QAAQ,CAAC,CAAC,KAC/D,OAAO,YAAY,uBAAuB,QAAQ,CACpD;;AAGA,MAAa,YAAY,OAAO,IAAI,mBAAmB,SAAS;;AAGhE,MAAa,YAAY,UAAU,KACjC,OAAO,SAAS,QAAQ,OAAO,IAAI,mBAAmB,SAAS,CAAC,CAAC,KAAK,OAAO,YAAY,GAAG,CAAC,CAAC,CAChG;;AAGA,MAAa,UAAU,OAAO,eAAe,mBAAmB,OAAO;;;;ACPvE,IAAa,qBAAb,cAAwC,KAAK,YAAY,oBAAoB,CAAC,CAI3E,CAAC;;;ACVJ,MAAM,mBAIF,OAAO,IAAI,aAAa;CAC1B,MAAM,aAAa,OAAO,OAAO,eAAe,mBAAmB,UAAU,CAAC,CAAC,KAC7E,OAAO,UACJ,UACC,IAAI,mBAAmB;EACrB,MAAM;EACN,SAAS,GAAG,mBAAmB,WAAW;EAC1C,OAAO,MAAM;CACf,CAAC,CACL,CACF;CAEA,MAAM,WAAW,QAAO,OADE,WAAW,WAAA,CACF,eAAe,UAAU,CAAC,CAAC,KAC5D,OAAO,UACJ,UACC,IAAI,mBAAmB;EACrB,MAAM;EACN,SAAS;EACT;CACF,CAAC,CACL,CACF;CACA,MAAM,WAAW,OAAO,OAAO,oBAAoB,OAAO,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