@lunora/values 1.0.0-alpha.3 → 1.0.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,82 +0,0 @@
1
- const jsonSchemaFromNode = (node, reader) => {
2
- const base = (() => {
3
- switch (reader.kind(node)) {
4
- case "any": {
5
- return {};
6
- }
7
- case "array": {
8
- const inner = reader.inner(node);
9
- return { items: inner === void 0 ? {} : jsonSchemaFromNode(inner, reader), type: "array" };
10
- }
11
- case "bigint": {
12
- return { format: "int64", type: "integer" };
13
- }
14
- case "boolean": {
15
- return { type: "boolean" };
16
- }
17
- case "bytes": {
18
- return { contentEncoding: "base64", description: "binary (ArrayBuffer)", type: "string" };
19
- }
20
- case "date": {
21
- return { description: "epoch milliseconds (date)", type: "integer" };
22
- }
23
- case "id": {
24
- return { description: `Id<"${String(reader.tableName(node))}">`, type: "string", "x-lunora-table": reader.tableName(node) };
25
- }
26
- case "literal": {
27
- return reader.literalSchema(node);
28
- }
29
- case "null": {
30
- return { type: "null" };
31
- }
32
- case "number": {
33
- return { type: "number" };
34
- }
35
- case "object": {
36
- return objectSchemaFromNodes(reader.shape(node), reader);
37
- }
38
- case "optional": {
39
- const inner = reader.inner(node);
40
- return inner === void 0 ? {} : jsonSchemaFromNode(inner, reader);
41
- }
42
- case "record": {
43
- const value = reader.valueChild(node);
44
- return { additionalProperties: value === void 0 ? {} : jsonSchemaFromNode(value, reader), type: "object" };
45
- }
46
- case "storage": {
47
- return { description: "storage object key", type: "string", "x-lunora-storage": true };
48
- }
49
- case "string": {
50
- return { type: "string" };
51
- }
52
- case "timestamp": {
53
- return { description: "epoch milliseconds (timestamp)", type: "integer" };
54
- }
55
- case "union": {
56
- return { anyOf: reader.members(node).map((member) => jsonSchemaFromNode(member, reader)) };
57
- }
58
- default: {
59
- return {};
60
- }
61
- }
62
- })();
63
- const constraints = reader.constraints(node);
64
- const withConstraints = constraints === void 0 ? base : { ...base, ...constraints };
65
- if (reader.isNullable(node)) {
66
- return { anyOf: [withConstraints, { type: "null" }] };
67
- }
68
- return withConstraints;
69
- };
70
- const objectSchemaFromNodes = (shape, reader) => {
71
- const properties = {};
72
- const required = [];
73
- for (const [key, child] of Object.entries(shape)) {
74
- properties[key] = jsonSchemaFromNode(child, reader);
75
- if (reader.kind(child) !== "optional") {
76
- required.push(key);
77
- }
78
- }
79
- return { additionalProperties: false, properties, required, type: "object" };
80
- };
81
-
82
- export { jsonSchemaFromNode, objectSchemaFromNodes };