{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/schema/collections/index.ts"],"sourcesContent":["/**\n * Schema collections list and create endpoints\n *\n * GET  /_emdash/api/schema/collections - List collections\n * POST /_emdash/api/schema/collections - Create collection\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { requireDb, unwrapResult } from \"#api/error.js\";\nimport { handleSchemaCollectionList, handleSchemaCollectionCreate } from \"#api/index.js\";\nimport { parseBody, isParseError } from \"#api/parse.js\";\nimport { createCollectionBody } from \"#api/schemas.js\";\nimport type { CreateCollectionInput } from \"#schema/types.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst dbErr = requireDb(emdash?.db);\n\tif (dbErr) return dbErr;\n\n\tconst denied = requirePerm(user, \"schema:read\");\n\tif (denied) return denied;\n\n\tconst result = await handleSchemaCollectionList(emdash.db);\n\treturn unwrapResult(result);\n};\n\nexport const POST: APIRoute = async ({ request, locals }) => {\n\tconst { emdash, user } = locals;\n\n\tconst dbErr = requireDb(emdash?.db);\n\tif (dbErr) return dbErr;\n\n\tconst denied = requirePerm(user, \"schema:manage\");\n\tif (denied) return denied;\n\n\tconst body = await parseBody(request, createCollectionBody);\n\tif (isParseError(body)) return body;\n\n\t// eslint-disable-next-line typescript/no-unsafe-type-assertion -- Zod schema output narrowed to CreateCollectionInput\n\tconst result = await handleSchemaCollectionCreate(emdash.db, body as CreateCollectionInput);\n\temdash.invalidateUrlPatternCache();\n\treturn unwrapResult(result, 201);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,QAAQ,UAAU,QAAQ,GAAG;AACnC,KAAI,MAAO,QAAO;CAElB,MAAM,SAAS,YAAY,MAAM,cAAc;AAC/C,KAAI,OAAQ,QAAO;AAGnB,QAAO,aADQ,MAAM,2BAA2B,OAAO,GAAG,CAC/B;;AAG5B,MAAa,OAAiB,OAAO,EAAE,SAAS,aAAa;CAC5D,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,QAAQ,UAAU,QAAQ,GAAG;AACnC,KAAI,MAAO,QAAO;CAElB,MAAM,SAAS,YAAY,MAAM,gBAAgB;AACjD,KAAI,OAAQ,QAAO;CAEnB,MAAM,OAAO,MAAM,UAAU,SAAS,qBAAqB;AAC3D,KAAI,aAAa,KAAK,CAAE,QAAO;CAG/B,MAAM,SAAS,MAAM,6BAA6B,OAAO,IAAI,KAA8B;AAC3F,QAAO,2BAA2B;AAClC,QAAO,aAAa,QAAQ,IAAI"}