@inox-tools/content-utils
Version:
Utilities to work with content collections on an Astro project from an integration or library.
40 lines (38 loc) • 1.58 kB
JavaScript
import { defineCollection as defineCollection$1, z } from 'astro:content';
// src/runtime/fancyContent.ts
function defineCollection(config) {
const definedConfig = defineCollection$1(config);
const fn = (options) => {
const fancyMarker = {
[FANCY_COLLECTION_MARKER]: fn
};
if (options?.extends === void 0)
return Object.assign(definedConfig, fancyMarker);
const { extends: extendSchema } = options;
const config2 = {
...definedConfig,
schema: (context) => {
const userSchema = typeof extendSchema === "function" ? extendSchema(context) : extendSchema;
const baseSchema = typeof definedConfig.schema === "function" ? definedConfig.schema(context) : definedConfig.schema;
return baseSchema === void 0 ? userSchema : z.intersection(baseSchema, userSchema);
}
};
return Object.assign(config2, fancyMarker);
};
return Object.assign(fn, {
[FANCY_COLLECTION_MARKER]: true
});
}
var FANCY_COLLECTION_MARKER = /* @__PURE__ */ Symbol("@inox-tools/content-utils/fancyCollection");
function isDerivedCollection(something) {
return typeof something[FANCY_COLLECTION_MARKER] === "function";
}
function isFancyCollection(something) {
return something[FANCY_COLLECTION_MARKER] === true;
}
function tryGetOriginalFancyCollection(something) {
return isDerivedCollection(something) ? something[FANCY_COLLECTION_MARKER] : null;
}
export { defineCollection, isFancyCollection, tryGetOriginalFancyCollection };
//# sourceMappingURL=chunk-CWY7WJU5.js.map
//# sourceMappingURL=chunk-CWY7WJU5.js.map