alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
58 lines (56 loc) • 1.37 kB
JavaScript
import "../chunks/chunk-U5RRZUYZ.js";
// src/core/Schema.ts
import { Hint } from "./Hint.js";
import { Type } from "./Type.js";
import { entries, fromEntries } from "./util/Objects.js";
var shapesCache = /* @__PURE__ */ new WeakMap();
var hintCache = /* @__PURE__ */ new WeakMap();
var Schema;
((Schema2) => {
function shapes(schema2) {
if (!shapesCache.has(schema2))
shapesCache.set(
schema2,
fromEntries(
entries(schema2).map(([key, type]) => {
return [key, Type.shape(type)];
})
)
);
return shapesCache.get(schema2);
}
Schema2.shapes = shapes;
function hint(schema2) {
if (!hintCache.has(schema2)) {
hintCache.set(
schema2,
Hint.Union(
entries(schema2).map(([key, type]) => {
return Type.hint(type);
})
)
);
}
return hintCache.get(schema2);
}
Schema2.hint = hint;
function targets(schema2) {
return new Map(
entries(schema2).map(([key, type]) => {
return [Type.target(type), key];
})
);
}
Schema2.targets = targets;
function typeNames(schema2) {
return new Map(entries(schema2).map(([key, type]) => [type, key]));
}
Schema2.typeNames = typeNames;
})(Schema || (Schema = {}));
function schema(types) {
return types;
}
export {
Schema,
schema
};