{"version":3,"file":"collector.mjs","names":["mapping","collectorKind.mapping","collectorKind.specification","collectorKind.source_type"],"sources":["../../contract/kinds/collector.json","../src/kinds/collector/definitions.ts","../src/kinds/collector/ports.ts","../src/kinds/collector/define.ts"],"sourcesContent":["","/**\n * What a collector package defines beside its runtime, for its records to mean\n * anything: the catalog entity specifications they become (`entities`), its\n * source type and the mappings every source of that type shares\n * (`sourceType.mappings`, by slug). Each is described as a component\n * (contract/kinds/collector.json places it), its body the API's create body as\n * its author wrote it, but whose it is: `platform: true` makes it\n * platform-owned. The kind checks only what publishing needs (a slug, a name,\n * a schema that is an object, each mapping's engine and expression, record\n * types that agree with the mappings'); it reads no schema and no expression,\n * and never writes one.\n */\n\nimport collectorKind from \"../../../../contract/kinds/collector.json\" with { type: \"json\" };\nimport { component, type Component, type ComponentOptions } from \"../../core/component\";\nimport { isJsonObject } from \"../../core/payload\";\nimport { repeatedOf, textOf } from \"../../core/text\";\nimport type { CollectorDefinition, TypeMapping } from \"./types\";\n\n/** Where one kind of definition lives on the API: its resource type, the path it is created at, the list it is found in, and the field that identifies it. */\ntype Placement = (typeof collectorKind)[keyof typeof collectorKind];\n\n/** What an entity, a source type and a mapping are, as a refusal of one says. */\nconst ENTITY_SHAPE = \"{ slug, name, description?, schema, platform? }\";\nconst SOURCE_TYPE_SHAPE = \"{ name, description?, runs?, mappings?, platform? }\";\nconst MAPPING_SHAPE = \"{ recordType?, engine, expression, platform? }\";\n\n/** The field that says whose a definition is, never a field of its body. */\nconst OWNERSHIP = \"platform\";\n\n/** What a source type's definition holds that is published apart from its body: its mappings. */\nconst TYPE_MAPPINGS = \"mappings\";\n\n/** What a mapping's definition names that its body names otherwise: its record type, published as `record_type`. */\nconst RECORD_TYPE = \"recordType\";\n\n/** What is wrong with the ownership `owned` says, named `named`: given, and not a boolean. */\nfunction ownershipProblemsOf(owned: Record<string, unknown>, named: string): string[] {\n  const platform = owned[OWNERSHIP];\n  return platform === undefined || typeof platform === \"boolean\" ? [] : [`${named}: platform must be a boolean`];\n}\n\n/** What is wrong with the entity at `index`: not an object, no slug, no name, a schema that is no object, its ownership. */\nfunction entityProblemsOf(entity: unknown, index: number): string[] {\n  if (!isJsonObject(entity)) {\n    return [`entities[${index}] must be an object: ${ENTITY_SHAPE}`];\n  }\n  if (textOf(entity.slug) === undefined) {\n    return [`entities[${index}] needs a slug`];\n  }\n  const named = `entity \"${entity.slug}\"`;\n  return [\n    ...(textOf(entity.name) === undefined ? [`${named} needs a name`] : []),\n    ...(isJsonObject(entity.schema) ? [] : [`${named} needs a schema, an object`]),\n    ...ownershipProblemsOf(entity, named),\n  ];\n}\n\n/** The slugs `entities` give, each that is text. */\nfunction slugsOf(entities: unknown[]): string[] {\n  return entities.flatMap((entity) => (isJsonObject(entity) && textOf(entity.slug) !== undefined ? [entity.slug as string] : []));\n}\n\n/** What is wrong with the entities: not a list, each one's problems, then each slug given twice. */\nfunction entitiesProblemsOf(entities: unknown): string[] {\n  if (entities === undefined) {\n    return [];\n  }\n  if (!Array.isArray(entities)) {\n    return [`entities must be an array of entity specifications: ${ENTITY_SHAPE}`];\n  }\n  const repeated = repeatedOf(slugsOf(entities)).map((slug) => `entity \"${slug}\" is given twice`);\n  return [...entities.flatMap(entityProblemsOf), ...repeated];\n}\n\n/** The record type the mapping `slug` maps: its `recordType` when it gives one as text, else its slug. */\nfunction recordTypeOf(slug: string, mapping: unknown): string {\n  return isJsonObject(mapping) && textOf(mapping.recordType) !== undefined ? (mapping.recordType as string) : slug;\n}\n\n/** The mappings a source type declares as an object, by slug; none when it declares none, or none that is an object. */\nfunction typeMappingsOf(sourceType: unknown): Record<string, unknown> | undefined {\n  return isJsonObject(sourceType) && isJsonObject(sourceType.mappings) ? sourceType.mappings : undefined;\n}\n\n/** What is wrong with the mapping `slug`: not `{ recordType?, engine, expression }` of text, its ownership. */\nfunction mappingProblemsOf(slug: string, mapping: unknown): string[] {\n  const named = `mapping \"${slug}\"`;\n  const shaped =\n    isJsonObject(mapping) &&\n    textOf(mapping.engine) !== undefined &&\n    textOf(mapping.expression) !== undefined &&\n    (mapping.recordType === undefined || textOf(mapping.recordType) !== undefined);\n  return shaped ? ownershipProblemsOf(mapping, named) : [`${named} must be { recordType?, engine, expression }: each non-empty text`];\n}\n\n/** What is wrong with a source type's mappings: not an object, then each one's problems. */\nfunction mappingsProblemsOf(mappings: unknown): string[] {\n  if (mappings === undefined) {\n    return [];\n  }\n  if (!isJsonObject(mappings)) {\n    return [`sourceType.mappings must be an object of mappings by slug: { <slug>: ${MAPPING_SHAPE} }`];\n  }\n  return Object.entries(mappings).flatMap(([slug, mapping]) => mappingProblemsOf(slug, mapping));\n}\n\n/** What is wrong with a slug a source type gives: one that is not the source's type, which is its slug. */\nfunction sourceTypeSlugProblemsOf(slug: unknown, type: unknown): string[] {\n  return slug === undefined || slug === type ? [] : [`sourceType's slug \"${slug}\" is not the source's type \"${type}\": a source type's slug is source.type`];\n}\n\n/** What is wrong with the source type: not an object, no name, a slug that is not the source's type `type`, its ownership, its mappings. */\nfunction sourceTypeProblemsOf(sourceType: unknown, type: unknown): string[] {\n  if (sourceType === undefined) {\n    return [];\n  }\n  if (!isJsonObject(sourceType)) {\n    return [`sourceType must be an object: ${SOURCE_TYPE_SHAPE}`];\n  }\n  return [\n    ...(textOf(sourceType.name) === undefined ? [\"sourceType needs a name\"] : []),\n    ...sourceTypeSlugProblemsOf(sourceType.slug, type),\n    ...ownershipProblemsOf(sourceType, \"sourceType\"),\n    ...mappingsProblemsOf(sourceType.mappings),\n  ];\n}\n\n/** What is wrong with the record types a collector gives, beside its source type's mappings: each mapping of one it does not name, then each it names that no mapping maps. Nothing when it gives none, for then they are the mappings'. */\nfunction agreementProblemsOf(recordTypes: unknown, sourceType: unknown): string[] {\n  const mappings = typeMappingsOf(sourceType);\n  if (!Array.isArray(recordTypes) || mappings === undefined) {\n    return [];\n  }\n  const mapped = Object.entries(mappings).filter(([, mapping]) => isJsonObject(mapping));\n  const mappedTypes = mapped.map(([slug, mapping]) => recordTypeOf(slug, mapping));\n  return [\n    ...mapped\n      .filter(([slug, mapping]) => !recordTypes.includes(recordTypeOf(slug, mapping)))\n      .map(([slug, mapping]) => `mapping \"${slug}\" maps record type \"${recordTypeOf(slug, mapping)}\", which recordTypes does not name`),\n    ...recordTypes.filter((recordType) => !mappedTypes.includes(recordType as string)).map((recordType) => `record type \"${recordType}\" has no mapping in sourceType.mappings`),\n  ];\n}\n\n/** Every problem of the definitions a collector declares: its entities', its source type's with its mappings', then its record types' disagreement with those mappings. */\nexport function definitionsProblemsOf(definition: CollectorDefinition): string[] {\n  return [\n    ...entitiesProblemsOf(definition.entities),\n    ...sourceTypeProblemsOf(definition.sourceType, definition.source?.type),\n    ...agreementProblemsOf(definition.recordTypes, definition.sourceType),\n  ];\n}\n\n/**\n * `definition` as ingest runs it: with its source type's mappings' record\n * types, each once in the order they first appear, when it gives none of its\n * own. Unchanged when it gives its own, or has no mappings to take them from.\n */\nexport function withRecordTypes(definition: CollectorDefinition): CollectorDefinition {\n  const mappings = typeMappingsOf(definition.sourceType);\n  if (definition.recordTypes !== undefined || mappings === undefined || Object.keys(mappings).length === 0) {\n    return definition;\n  }\n  const recordTypes = [...new Set(Object.entries(mappings).map(([slug, mapping]) => recordTypeOf(slug, mapping)))];\n  return { ...definition, recordTypes };\n}\n\n/** `written` without the fields `left` names: the body as its author wrote it. */\nfunction bodyOf(written: object, left: string[] = []): Record<string, unknown> {\n  return Object.fromEntries(Object.entries(written).filter(([field]) => field !== OWNERSHIP && !left.includes(field)));\n}\n\n/** Where the definition `slug`, placed at `placement` and owned as `owned` says, lives: its path, its list filtered by its identity, and its owner; under `parent` when it has one. */\nfunction placedAt(placement: Placement, slug: string, owned: { platform?: boolean }, parent?: Component): ComponentOptions {\n  const { path, list, identity } = placement;\n  const owner = owned.platform === true ? \"platform\" : undefined;\n  return { parent, path, list: `${list}?${identity}=${encodeURIComponent(slug)}`, identity, owner };\n}\n\n/** The mapping `slug` of the source type `sourceType`, a `mapping` under it named `<type slug>/<mapping slug>`, its body its slug, its record type, then the rest as written. */\nfunction mappingComponent(sourceType: Component, slug: string, mapping: TypeMapping): Component {\n  const body = { slug, record_type: recordTypeOf(slug, mapping), ...bodyOf(mapping, [RECORD_TYPE]) };\n  return component(collectorKind.mapping.resource_type, `${sourceType.name}/${slug}`, body, placedAt(collectorKind.mapping, slug, mapping, sourceType));\n}\n\n/** The components of the definitions a collector declares, each with its children: each entity, in the order given, then its source type, its mappings under it in key order. Built once its definition is refused for none of them (`definitionsProblemsOf`). */\nexport function definitionsComponentsOf(definition: CollectorDefinition): Component[] {\n  const placement = collectorKind.specification;\n  const entities = (definition.entities ?? []).map((entity) => component(placement.resource_type, entity.slug, bodyOf(entity), placedAt(placement, entity.slug, entity)));\n  if (definition.sourceType === undefined) {\n    return entities;\n  }\n  const slug = definition.source.type;\n  const body = { slug, ...bodyOf(definition.sourceType, [TYPE_MAPPINGS]) };\n  const sourceType = component(collectorKind.source_type.resource_type, slug, body, placedAt(collectorKind.source_type, slug, definition.sourceType));\n  Object.entries(definition.sourceType.mappings ?? {}).forEach(([mappingSlug, mapping]) => mappingComponent(sourceType, mappingSlug, mapping));\n  return [...entities, sourceType];\n}\n\n/** What describe's collector block lists of the definitions: the entities' slugs, and the source type's slug with its mappings' slugs. */\nexport function definitionsBlockOf(definition: CollectorDefinition): Record<string, unknown> {\n  const { sourceType } = definition;\n  return {\n    entities: (definition.entities ?? []).map((entity) => entity.slug),\n    sourceType: sourceType === undefined ? undefined : { slug: definition.source.type, mappings: Object.keys(sourceType.mappings ?? {}) },\n  };\n}\n","/**\n * What a collector's own ports default to when its caller gives none, in code:\n * the port to catalog-ingest-api, the source it feeds and the interval between\n * snapshots, which is checked whatever gives it. None is read from the environment: what the code does not give is\n * the default, and only the platform's credentials are the run's. A URL, a\n * token, a key and each field of the source are read as text (`textOf`): a\n * blank one says nothing.\n */\n\nimport { ClientIngest, type IngestPort, type RunSource } from \"@nullplatform/ingest\";\nimport type { Credentials } from \"../../core/api\";\nimport { messageOf } from \"../../core/errors\";\nimport { describeSetting } from \"../../core/settings\";\nimport { textOf } from \"../../core/text\";\nimport type { CollectorPorts } from \"./types\";\n\n/** A resync a day: a watch carries the changes; a snapshot catches what it missed while down. */\nexport const DEFAULT_INTERVAL_SECONDS = 86400;\n\n/** What a local catalog-ingest-api is reached with, as a refusal tells a person to give it. */\nconst LOCAL_INGEST = \"for a local catalog-ingest-api, give main or serve an ingestToken in code beside its ingestUrl\";\n\n/** The interval's port, as a refusal names it. */\nconst INTERVAL_PORT = \"the intervalSeconds port\";\n\n/** The schedule's interval, as a refusal names it. */\nconst SCHEDULED_INTERVAL = \"schedule.intervalSeconds\";\n\n/** An interval between snapshots as one place gives it: its seconds, how that place writes them, and the place, as a refusal names it. */\ninterface GivenInterval {\n  seconds: number;\n  written: string;\n  from: string;\n}\n\n/** What ingest's refusal to build its port, `error`, is: a want of credentials when neither a token nor a key was given, saying what to set; else ingest's own refusal, named as the port's. Ingest's refusal is its cause. */\nfunction connectRefusalOf(error: unknown, given: { apiKey?: string; token?: string }): Error {\n  if (given.apiKey === undefined && given.token === undefined) {\n    return new Error(`catalog-ingest-api needs credentials: set ${describeSetting(\"apiKey\")}; or, ${LOCAL_INGEST}`, { cause: error });\n  }\n  return new Error(`catalog-ingest-api's port could not be built: ${messageOf(error)}`, { cause: error });\n}\n\n/**\n * The port a run feeds: the `ingest` port given; else catalog-ingest-api at\n * `ingestUrl`, else the ingest library's own under the run's platform API\n * (`credentials.apiUrl`), authenticated by `ingestToken`, else by the run's\n * platform API key. What ingest refuses of them is refused as what it is\n * (`connectRefusalOf`), ingest's refusal its cause.\n */\nexport function ingestOf(ports: Pick<CollectorPorts, \"ingest\" | \"ingestUrl\" | \"ingestToken\">, credentials: Credentials): IngestPort {\n  if (ports.ingest !== undefined) {\n    return ports.ingest;\n  }\n  const given = { apiKey: textOf(credentials.apiKey), token: textOf(ports.ingestToken) };\n  try {\n    return ClientIngest.connect({ authBaseURL: textOf(credentials.apiUrl), baseURL: textOf(ports.ingestUrl), ...given });\n  } catch (error) {\n    throw connectRefusalOf(error, given);\n  }\n}\n\n/** The source a run of the package `packageSlug` feeds, each field of the source port as text: its slug, else the package's; its NRN and its name, else none, which ingest defaults (the organization's root, the definition's name). */\nexport function sourceOf(packageSlug: string, given: Partial<RunSource> = {}): RunSource {\n  return { slug: textOf(given.slug) ?? packageSlug, nrn: textOf(given.nrn), name: textOf(given.name) };\n}\n\n/** The interval as the first place that gives one gives it: the port (`given`), the schedule (`scheduled`), whose default is a day. */\nfunction givenInterval(given: number | undefined, scheduled: number | undefined): GivenInterval {\n  if (given !== undefined) {\n    return { seconds: given, written: String(given), from: INTERVAL_PORT };\n  }\n  const seconds = scheduled ?? DEFAULT_INTERVAL_SECONDS;\n  return { seconds, written: String(seconds), from: SCHEDULED_INTERVAL };\n}\n\n/**\n * Seconds between snapshots when served: the port's (`given`), else the\n * schedule's (`scheduled`), else a day, as it is given: `0` or less is the\n * backfill only, by ingest's own rule. One that is not a number of seconds is\n * refused, naming what gives it.\n */\nexport function intervalSecondsOf(given: number | undefined, scheduled: number | undefined): number {\n  const interval = givenInterval(given, scheduled);\n  if (!Number.isFinite(interval.seconds)) {\n    throw new Error(`${interval.from} must be a number of seconds, not \"${interval.written}\"`);\n  }\n  return interval.seconds;\n}\n","/**\n * defineCollector: a collector of its package, sugar on definePlugin over\n * @nullplatform/ingest, which owns everything that feeds catalog-ingest-api.\n *\n *   import { Engine } from \"@nullplatform/ingest\";\n *   import { defineCollector } from \"@nullplatform/plugin/collector\";\n *\n *   export default defineCollector({\n *     package: { name: \"example-inventory\", version: \"0.1.0\" },\n *     source: { type: \"inventory\", name: \"Inventory export\" },\n *     mappings: { service: { engine: Engine.JSONATA, endpoint: \"inventory-service\", expression: \"{ \\\"id\\\": id, \\\"data\\\": { \\\"name\\\": name } }\" } },\n *     schedule: { intervalSeconds: 3600 },\n *     async *snapshot(ctx) {\n *       for (const service of await listServices(ctx.signal)) {\n *         yield { type: \"service\", payload: service };\n *       }\n *     },\n *   });\n *\n * One `execute` route runs one snapshot (`runSnapshot`), the payload its\n * options (`{ finalize? }`); the plugin's own serve runs the schedule and the\n * watch (`runCollector`) until the signal aborts. Describe publishes what the\n * package defines for its records (its entities, its source type and that\n * type's mappings, `./definitions`) and carries the collector's block as\n * tooling. Ingest runs the definition with its record types, its source\n * type's mappings' unless it gives its own (`withRecordTypes`). A snapshot and a watch get\n * ingest's own context (`source`, `log`, `signal`; `observedAt` or `events`),\n * which carries no configuration: a collector's own configuration is the code\n * that builds it (a function of it returning the definition). The\n * collector's own ports (`ingest`, `ingestUrl`, `ingestToken`, `source`,\n * `intervalSeconds`) are given in code, else each its default (`./ports`), and\n * the default ingest reaches the platform with the run's credentials. A run names no NRN, so it is not\n * traced.\n */\n\nimport { runCollector, runSnapshot, validateDefinition, type IngestPort, type RunSnapshotOptions } from \"@nullplatform/ingest\";\nimport { ActionError, messageOf, refuseProblems } from \"../../core/errors\";\nimport { packageOf } from \"../../core/package\";\nimport { isJsonObject, type Payload } from \"../../core/payload\";\nimport { definePlugin, type Plugin, type ServeContext } from \"../../core/run/plugin\";\nimport { execute, type Route } from \"../../core/run/route\";\nimport { definitionsBlockOf, definitionsComponentsOf, definitionsProblemsOf, withRecordTypes } from \"./definitions\";\nimport { ingestOf, intervalSecondsOf, sourceOf } from \"./ports\";\nimport type { CollectorDefinition, CollectorPorts, SnapshotOptions } from \"./types\";\n\n/** Who refuses a definition, as its problems are named. */\nconst DEFINER = \"defineCollector\";\n\n/** The options a snapshot takes. */\nconst SNAPSHOT_OPTIONS = [\"finalize\"];\n\n/** A snapshot's options, as a refusal of them says what they are. */\nconst OPTIONS = \"a snapshot's options are { finalize? }\";\n\n/** A run of the collector: the port it feeds, and what ingest runs it with. */\ninterface Run {\n  port: IngestPort;\n  options: RunSnapshotOptions & { signal: AbortSignal };\n}\n\n/**\n * The snapshot's options `payload` is: refused unless `{ finalize? }`, its\n * finalize an object. An option it does not know (a `dryRun` beside\n * `finalize`) or a finalize it cannot read (`finalize: true`) would run a\n * real snapshot.\n */\nfunction snapshotOptionsOf(payload: Payload): SnapshotOptions {\n  const unknown = Object.keys(payload).filter((key) => !SNAPSHOT_OPTIONS.includes(key));\n  if (unknown.length > 0) {\n    const named = unknown.map((key) => `\"${key}\"`).join(\", \");\n    throw new ActionError(\"INVALID_OPTIONS\", `${OPTIONS}: ${named} ${unknown.length === 1 ? \"is not one\" : \"are not\"}`);\n  }\n  if (payload.finalize !== undefined && !isJsonObject(payload.finalize)) {\n    throw new ActionError(\"INVALID_OPTIONS\", `${OPTIONS}: \"finalize\" is not an object`);\n  }\n  return payload as SnapshotOptions;\n}\n\n/** A run of the collector of the package `packageSlug` in `context`, a snapshot's or the serve's: each of its ports the one given or its default, its platform credentials the run's, its log and its signal the context's. */\nfunction runOf(packageSlug: string, context: ServeContext<CollectorPorts>): Run {\n  const { ports } = context;\n  return {\n    port: ingestOf(ports, context.credentials),\n    options: { source: sourceOf(packageSlug, ports.source), log: context.log, signal: context.signal },\n  };\n}\n\n/** The route that answers any payload with one snapshot of `definition`, the payload its options (`snapshotOptionsOf`). */\nfunction snapshotRoute(definition: CollectorDefinition, packageSlug: string): Route {\n  return execute((payload, context) => {\n    const { finalize } = snapshotOptionsOf(payload);\n    const run = runOf(packageSlug, context);\n    return runSnapshot(definition, run.port, run.options, finalize);\n  });\n}\n\n/** How the collector serves itself: the schedule and the watch until the signal aborts, at the interval resolved once, from the port or the schedule, and checked. The interval is read only here: a snapshot never needs it. Each scheduled snapshot finalizes as the source's own guards (`source.runs`) say: ingest's finalize options are not given. */\nfunction served(definition: CollectorDefinition, packageSlug: string): (context: ServeContext<CollectorPorts>) => Promise<void> {\n  return async (context) => {\n    const run = runOf(packageSlug, context);\n    const intervalSeconds = intervalSecondsOf(context.ports.intervalSeconds, definition.schedule?.intervalSeconds);\n    return runCollector(definition, run.port, { ...run.options, intervalSeconds });\n  };\n}\n\n/** What describe says the collector is: its source, the record types and mappings it declares, the definitions it publishes, its schedule, and whether it watches. */\nfunction collectorBlockOf(definition: CollectorDefinition): Record<string, unknown> {\n  return {\n    source: definition.source,\n    recordTypes: definition.recordTypes ?? [],\n    mappings: definition.mappings ?? {},\n    ...definitionsBlockOf(definition),\n    schedule: definition.schedule,\n    watch: typeof definition.watch === \"function\",\n  };\n}\n\n/** What ingest refuses of `definition`: what makes it a collector ingest could never run. */\nfunction ingestProblemsOf(definition: CollectorDefinition): string[] {\n  try {\n    validateDefinition(definition);\n    return [];\n  } catch (error) {\n    return [messageOf(error)];\n  }\n}\n\n/** What is wrong with a schedule: given, and not `{ intervalSeconds }` of a number of seconds. */\nfunction scheduleProblemsOf(schedule: unknown): string[] {\n  if (schedule === undefined || (isJsonObject(schedule) && Number.isFinite(schedule.intervalSeconds))) {\n    return [];\n  }\n  return [\"schedule must be { intervalSeconds }: a number of seconds\"];\n}\n\n/** Every problem of a definition: what ingest refuses of it as it runs it (`collected`, with its record types), its schedule's, then its definitions'. */\nfunction problemsOf(definition: CollectorDefinition, collected: CollectorDefinition): string[] {\n  return [...ingestProblemsOf(collected), ...scheduleProblemsOf(definition.schedule), ...definitionsProblemsOf(definition)];\n}\n\n/**\n * A collector of its package: the components of its definitions, one route\n * that runs a snapshot, its own serve, and its block in describe. A definition with a problem is refused when it\n * is defined, never when it runs: its package first, then every other problem\n * at once.\n */\nexport function defineCollector(definition: CollectorDefinition): Plugin<CollectorPorts> {\n  const declared = packageOf(DEFINER, definition?.package);\n  const collected = withRecordTypes(definition);\n  refuseProblems(problemsOf(definition, collected), `${DEFINER}(${declared.name})`);\n  return definePlugin<CollectorPorts>({\n    package: definition.package,\n    components: definitionsComponentsOf(definition),\n    routes: [snapshotRoute(collected, declared.slug)],\n    serve: served(collected, declared.slug),\n    tooling: { collector: collectorBlockOf(collected) },\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACuBA,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAC1B,MAAM,gB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