UNPKG

@softr/sdk

Version:

The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.

31 lines (29 loc) • 1.13 kB
import { panic } from "../assertions.js"; //#region src/codegen/doc-file-names.ts function docFileNames(datasources) { const bases = /* @__PURE__ */ new Map(); const seen = /* @__PURE__ */ new Map(); for (const datasource of datasources) { const base = slug(datasource.name) || slug(datasource.id); if (base === "") panic(`Datasource ${datasource.id} has no usable name`); bases.set(datasource.id, base); const key = base.toLowerCase(); seen.set(key, (seen.get(key) ?? 0) + 1); } const names = /* @__PURE__ */ new Map(); /** The index the docs route the agent through, which a datasource must not overwrite. */ const taken = new Set(["readme"]); for (const [id, base] of bases) { const candidate = seen.get(base.toLowerCase()) === 1 ? base : `${base}-${id}`; let name = candidate; for (let attempt = 2; taken.has(name.toLowerCase()); attempt++) name = `${candidate}-${attempt}`; taken.add(name.toLowerCase()); names.set(id, `${name}.md`); } return names; } function slug(value) { return value.split(/[^A-Za-z0-9]+/).filter((word) => word.length > 0).join("-"); } //#endregion export { docFileNames };