import { defineEventHandler, useQuery, createError } from 'h3';
import { u as useApiQuery, q as queryContent } from '../storage.mjs';
import 'unstorage';
import 'ohash';
import 'destr';
import '../index.mjs';
import 'pathe';
import 'defu';
import 'remark-emoji';
import 'rehype-slug';
import 'remark-squeeze-paragraphs';
import 'rehype-external-links';
import 'remark-gfm';
import 'rehype-sort-attribute-values';
import 'rehype-sort-attributes';
import 'rehype-raw';
import 'gray-matter';
import 'flat';
import 'unified';
import 'remark-parse';
import 'remark-rehype';
import 'scule';
import 'unist-util-visit';
import 'stringify-entities';
import 'parse-entities';
import 'micromark-util-character';
import 'micromark-factory-space';
import 'micromark-factory-whitespace';
import 'micromark-core-commonmark';
import 'mdast-util-to-hast';
import 'detab';
import 'unist-builder';
import 'mdurl';
import 'unist-util-position';
import 'html-tags';
import '../nitro/node-server.mjs';
import 'unenv/runtime/polyfill/fetch.node';
import 'http';
import 'https';
import 'ohmyfetch';
import 'radix3';
import 'unenv/runtime/fetch/index';
import 'hookable';
import 'unstorage/drivers/overlay';
import 'unstorage/drivers/memory';
import 'ufo';
import 'slugify';

const query = defineEventHandler(async (event) => {
  const { query: qid } = event.context.params;
  const query = useApiQuery(qid, useQuery(event)?.params || void 0);
  const contents = await queryContent(query).find();
  if (query.first && Array.isArray(contents) && contents.length === 0) {
    throw createError({
      statusMessage: "Document not found!",
      statusCode: 404,
      data: {
        description: "Could not find document for the given query.",
        query
      }
    });
  }
  return contents;
});

export { query as default };
//# sourceMappingURL=query.mjs.map
