@mark1russell7/ontology 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +100 -2
- package/build/generate-D6Vazln0.mjs +780 -0
- package/build/generate-D6Vazln0.mjs.map +1 -0
- package/build/header-nlcc_Vh2.d.mts +374 -0
- package/build/index.d.mts +173 -0
- package/build/index.mjs +303 -0
- package/build/index.mjs.map +1 -0
- package/build/node.d.mts +8 -0
- package/build/node.mjs +23 -0
- package/build/node.mjs.map +1 -0
- package/package.json +71 -3
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { A as Scope, B as relationId, C as NamedReference, D as RoleDef, E as RelationKindDef, F as envelopeSchema, H as scopeSchema, I as isRelationId, L as keyedRelationId, M as edgeSchema, N as entityIdSchema, O as RoleFillers, P as entitySchema, R as maxScope, S as NAME_PATTERN, T as RelationExtension, U as visibleTo, V as scopeRank, _ as Envelope, a as RegistryError, b as MODES, c as ValidationIssue, d as Deadline, f as ENTITY_ID_PATTERN, g as EntityInput, h as Entity, i as Registry, j as edgeRowSchema, k as SCOPES, l as composeRegistryInput, m as EdgeInput, n as GenerateOptions, o as RegistryInput, p as Edge, r as RELATION_ROOT, s as RelationLike, t as DEFAULT_HEADER, u as AttrShape, v as FacetDef, w as ParsedEdge, x as Mode, y as KindDef, z as nameOf } from "./header-nlcc_Vh2.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** The verdicts of a claim. */
|
|
4
|
+
export declare const CLAIM_VERDICTS: readonly ["supported", "equivalent", "disputed", "refuted", "speculative"];
|
|
5
|
+
/** The verdict of a claim. */
|
|
6
|
+
type ClaimVerdict = (typeof CLAIM_VERDICTS)[number];
|
|
7
|
+
/** The facets of the spine. */
|
|
8
|
+
export declare const spineFacets: readonly FacetDef[];
|
|
9
|
+
/** The kinds of the spine: the root, the abstract kinds, the claim, and the kinds of the grammar as data. */
|
|
10
|
+
export declare const spineKinds: readonly KindDef[];
|
|
11
|
+
/** The relation kinds of the spine: the grammar as data, the subject of a claim, and the classification. */
|
|
12
|
+
export declare const spineRelations: readonly RelationKindDef[];
|
|
13
|
+
/** The spine as the input of a registry. An add-on joins it with its own parts through `composeRegistryInput`. */
|
|
14
|
+
export declare const SPINE: RegistryInput;
|
|
15
|
+
/** This function gives the registry of the spine and of the add-ons that it gets. */
|
|
16
|
+
export declare const spineRegistry: (...addOns: readonly RegistryInput[]) => Registry;
|
|
17
|
+
/** The column shape of an attribute in a view of a store. */
|
|
18
|
+
type ColumnShape = {
|
|
19
|
+
readonly kind: "text";
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "number";
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: "boolean";
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "array";
|
|
26
|
+
readonly element: "text" | "number" | "json";
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "quantity";
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: "json";
|
|
31
|
+
};
|
|
32
|
+
/** This function gives the column shape of the schema of an attribute. */
|
|
33
|
+
export declare const columnShape: (schema: z.ZodType) => ColumnShape;
|
|
34
|
+
/**
|
|
35
|
+
* This function gives the DuckDB tables of a store of entities and edges, and one view for each kind. The view of a
|
|
36
|
+
* kind has a column for each attribute, and it shows the entities of the kind and of each of its subkinds.
|
|
37
|
+
*
|
|
38
|
+
* @throws RegistryError when an attribute has the name of a fixed column, or two attributes give the same column
|
|
39
|
+
*/
|
|
40
|
+
export declare const generateDuckDbDdl: (registry: Registry, options?: GenerateOptions) => string;
|
|
41
|
+
/**
|
|
42
|
+
* This function gives the SQLite tables of a store of entities and edges. The tables are the same for each
|
|
43
|
+
* registry: a kind is a value of the column `kind`, and the attributes are JSON.
|
|
44
|
+
*/
|
|
45
|
+
export declare const generateSqliteDdl: (_registry: Registry, options?: GenerateOptions) => string;
|
|
46
|
+
/** One kind as data: the JSON Schema of its attributes and of the attributes of its facets. */
|
|
47
|
+
interface KindJson {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
readonly parent: string | null;
|
|
50
|
+
readonly mode: string;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
/** The attributes of its facets, then its own attributes. The attributes of a parent come through `parent`. */
|
|
53
|
+
readonly attributes: Record<string, unknown>;
|
|
54
|
+
/** Its facets. Their attributes are in `attributes`. */
|
|
55
|
+
readonly facets?: string[];
|
|
56
|
+
readonly defaultScope?: string;
|
|
57
|
+
readonly staleAfterDays?: number;
|
|
58
|
+
}
|
|
59
|
+
/** One relation kind as data: the JSON Schema of its qualifiers, and its roles. */
|
|
60
|
+
interface RelationJson {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
/** The relation kind that it narrows. */
|
|
63
|
+
readonly parent?: string;
|
|
64
|
+
readonly description: string;
|
|
65
|
+
readonly from: string[];
|
|
66
|
+
readonly to: string[];
|
|
67
|
+
readonly qualifiers?: Record<string, unknown>;
|
|
68
|
+
readonly symmetric?: boolean;
|
|
69
|
+
readonly transitive?: boolean;
|
|
70
|
+
readonly abstract?: boolean;
|
|
71
|
+
readonly roles?: Readonly<Record<string, {
|
|
72
|
+
readonly description: string;
|
|
73
|
+
readonly kinds: string[];
|
|
74
|
+
readonly many?: boolean;
|
|
75
|
+
}>>;
|
|
76
|
+
readonly key?: string[];
|
|
77
|
+
}
|
|
78
|
+
/** A registry as data. */
|
|
79
|
+
interface RegistryJson {
|
|
80
|
+
readonly kinds: readonly KindJson[];
|
|
81
|
+
/** Each relation kind. Each relation kind is also in `kinds`, with the mode `relation`. */
|
|
82
|
+
readonly relations: readonly RelationJson[];
|
|
83
|
+
}
|
|
84
|
+
/** The JSON Schemas of a registry: an entity, an edge, and the attributes of each kind. */
|
|
85
|
+
interface JsonSchemas {
|
|
86
|
+
readonly entity: Record<string, unknown>;
|
|
87
|
+
readonly edge: Record<string, unknown>;
|
|
88
|
+
readonly kinds: Record<string, Record<string, unknown>>;
|
|
89
|
+
}
|
|
90
|
+
/** This function gives one kind as data. The schema includes the attributes of the facets of the kind. */
|
|
91
|
+
export declare const kindJson: (registry: Registry, kind: KindDef) => KindJson;
|
|
92
|
+
/** This function gives one relation kind as data. */
|
|
93
|
+
export declare const relationJson: (relation: RelationKindDef) => RelationJson;
|
|
94
|
+
/** This function gives a registry as data: each kind and each relation kind. */
|
|
95
|
+
export declare const registryJson: (registry: Registry) => RegistryJson;
|
|
96
|
+
/** This function gives the JSON Schemas of an entity, an edge, and the full attributes of each kind. */
|
|
97
|
+
export declare const generateJsonSchemas: (registry: Registry) => JsonSchemas;
|
|
98
|
+
/** The generated files of a registry, by file name. */
|
|
99
|
+
interface GeneratedFiles {
|
|
100
|
+
readonly "duckdb.sql": string;
|
|
101
|
+
readonly "sqlite.sql": string;
|
|
102
|
+
readonly "registry.json": string;
|
|
103
|
+
readonly "jsonschema.json": string;
|
|
104
|
+
}
|
|
105
|
+
/** This function gives each generated file of a registry: the SQL of two stores, the registry and the JSON Schemas. */
|
|
106
|
+
export declare const generateAll: (registry: Registry, options?: GenerateOptions) => GeneratedFiles;
|
|
107
|
+
/**
|
|
108
|
+
* Versions and version ranges, for the conditions of a claim: "the default is 15 on Linux >=2.6.12".
|
|
109
|
+
*
|
|
110
|
+
* A version starts with dotted numbers ("6.6.87.2"). The order ignores the text after the numbers, so
|
|
111
|
+
* "6.6.87.2-custom" has the order of 6.6.87.2. A range is a list of comparators with spaces between them
|
|
112
|
+
* (">=6.6 <6.7"). Each comparator must hold. Alternatives have "||" between them.
|
|
113
|
+
*
|
|
114
|
+
* A version with no operator names its series: "6.6" is each 6.6.x. "=6.6.87.2" names that release and its patches.
|
|
115
|
+
*/
|
|
116
|
+
/** A version: its dotted numbers. */
|
|
117
|
+
type Version = readonly number[];
|
|
118
|
+
/** One end of a span of versions. */
|
|
119
|
+
interface Bound {
|
|
120
|
+
readonly at: Version;
|
|
121
|
+
readonly inclusive: boolean;
|
|
122
|
+
}
|
|
123
|
+
/** A span of versions from `lo` to `hi`. An end with no bound is open. */
|
|
124
|
+
interface VersionSpan {
|
|
125
|
+
readonly lo?: Bound;
|
|
126
|
+
readonly hi?: Bound;
|
|
127
|
+
}
|
|
128
|
+
/** The error of a text that is not a version or a range. */
|
|
129
|
+
export declare class VersionError extends Error {
|
|
130
|
+
override readonly name = "VersionError";
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* This function gives the dotted numbers at the start of a version.
|
|
134
|
+
*
|
|
135
|
+
* @throws VersionError when the text does not start with a number
|
|
136
|
+
*/
|
|
137
|
+
export declare const parseVersion: (text: string) => Version;
|
|
138
|
+
/** This function gives -1, 0 or 1. It adds zeros to a shorter version, so 6.6 is 6.6.0. */
|
|
139
|
+
export declare const compareVersions: (a: Version, b: Version) => number;
|
|
140
|
+
/** This function gives a series as a span: 6.6 is from 6.6 up to 6.7, and 6.7 is not in it. */
|
|
141
|
+
export declare const seriesSpan: (series: Version) => VersionSpan;
|
|
142
|
+
/**
|
|
143
|
+
* This function gives the spans of a range: one span for each alternative.
|
|
144
|
+
*
|
|
145
|
+
* @throws VersionError when the range has an empty alternative or a comparator with no version
|
|
146
|
+
*/
|
|
147
|
+
export declare const parseRange: (range: string) => VersionSpan[];
|
|
148
|
+
/**
|
|
149
|
+
* This function tells how a range meets the series of a version. The result is `all` when the full series is in the
|
|
150
|
+
* range. It is `some` when a part of the series is in the range, and `none` when no part is in the range.
|
|
151
|
+
*
|
|
152
|
+
* @throws VersionError when the range or the version is not correct
|
|
153
|
+
*/
|
|
154
|
+
export declare const rangeMeets: (range: string, version: string) => "all" | "some" | "none";
|
|
155
|
+
/**
|
|
156
|
+
* One condition of a claim: a system at a range of versions, the hardware or the provider, an architecture, or
|
|
157
|
+
* the population of a study. A claim holds where each of its conditions holds.
|
|
158
|
+
*/
|
|
159
|
+
type Condition = {
|
|
160
|
+
readonly of: string;
|
|
161
|
+
readonly versions: string;
|
|
162
|
+
} | {
|
|
163
|
+
readonly on: string;
|
|
164
|
+
} | {
|
|
165
|
+
readonly architecture: string;
|
|
166
|
+
} | {
|
|
167
|
+
readonly population: string;
|
|
168
|
+
};
|
|
169
|
+
/** The schema of a version range of a condition: ">=6.6 <6.7", "=6.6.87.2" or "6.6". */
|
|
170
|
+
export declare const versionRangeSchema: z.ZodType<string, string>;
|
|
171
|
+
/** The schema of one condition of a claim. A system or a model is the id of an entity. */
|
|
172
|
+
export declare const conditionSchema: z.ZodType<Condition, Condition>;
|
|
173
|
+
export { type AttrShape, type ClaimVerdict, type ColumnShape, type Condition, DEFAULT_HEADER, type Deadline, ENTITY_ID_PATTERN, type Edge, type EdgeInput, type Entity, type EntityInput, type Envelope, type FacetDef, type GenerateOptions, type GeneratedFiles, type JsonSchemas, type KindDef, type KindJson, MODES, type Mode, NAME_PATTERN, type NamedReference, type ParsedEdge, RELATION_ROOT, Registry, RegistryError, type RegistryInput, type RegistryJson, type RelationExtension, type RelationJson, type RelationKindDef, type RelationLike, type RoleDef, type RoleFillers, SCOPES, type Scope, type ValidationIssue, type Version, type VersionSpan, composeRegistryInput, edgeRowSchema, edgeSchema, entityIdSchema, entitySchema, envelopeSchema, isRelationId, keyedRelationId, maxScope, nameOf, relationId, scopeRank, scopeSchema, visibleTo };
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { A as visibleTo, C as isRelationId, D as relationId, E as nameOf, O as scopeRank, S as envelopeSchema, T as maxScope, _ as SCOPES, a as relationJson, b as entityIdSchema, c as DEFAULT_HEADER, d as Registry, f as RegistryError, g as NAME_PATTERN, h as MODES, i as registryJson, k as scopeSchema, l as columnShape, m as ENTITY_ID_PATTERN, n as generateJsonSchemas, o as generateSqliteDdl, p as composeRegistryInput, r as kindJson, s as generateDuckDbDdl, t as generateAll, u as RELATION_ROOT, v as edgeRowSchema, w as keyedRelationId, x as entitySchema, y as edgeSchema } from "./generate-D6Vazln0.mjs";
|
|
2
|
+
import { extentSchema, statisticSchema, unknownSchema } from "@mark1russell7/quantity/schema";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/versions.ts
|
|
5
|
+
/** The error of a text that is not a version or a range. */
|
|
6
|
+
var VersionError = class extends Error {
|
|
7
|
+
name = "VersionError";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* This function gives the dotted numbers at the start of a version.
|
|
11
|
+
*
|
|
12
|
+
* @throws VersionError when the text does not start with a number
|
|
13
|
+
*/
|
|
14
|
+
const parseVersion = (text) => {
|
|
15
|
+
const match = /^v?(\d+(?:\.\d+)*)/.exec(text.trim());
|
|
16
|
+
if (match?.[1] === void 0) throw new VersionError(`not a version: ${text}`);
|
|
17
|
+
return match[1].split(".").map(Number);
|
|
18
|
+
};
|
|
19
|
+
/** This function gives -1, 0 or 1. It adds zeros to a shorter version, so 6.6 is 6.6.0. */
|
|
20
|
+
const compareVersions = (a, b) => {
|
|
21
|
+
for (let i = 0; i < Math.max(a.length, b.length); i += 1) {
|
|
22
|
+
const x = a[i] ?? 0;
|
|
23
|
+
const y = b[i] ?? 0;
|
|
24
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
};
|
|
28
|
+
/** This function gives the release after a series: 6.7 after 6.6, and 7 after 6. */
|
|
29
|
+
const next = (series) => [...series.slice(0, -1), (series[series.length - 1] ?? 0) + 1];
|
|
30
|
+
/** This function gives a series as a span: 6.6 is from 6.6 up to 6.7, and 6.7 is not in it. */
|
|
31
|
+
const seriesSpan = (series) => ({
|
|
32
|
+
lo: {
|
|
33
|
+
at: series,
|
|
34
|
+
inclusive: true
|
|
35
|
+
},
|
|
36
|
+
hi: {
|
|
37
|
+
at: next(series),
|
|
38
|
+
inclusive: false
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const tighterLo = (a, b) => {
|
|
42
|
+
if (a === void 0) return b;
|
|
43
|
+
if (b === void 0) return a;
|
|
44
|
+
const order = compareVersions(a.at, b.at);
|
|
45
|
+
return order > 0 ? a : order < 0 ? b : {
|
|
46
|
+
at: a.at,
|
|
47
|
+
inclusive: a.inclusive && b.inclusive
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const tighterHi = (a, b) => {
|
|
51
|
+
if (a === void 0) return b;
|
|
52
|
+
if (b === void 0) return a;
|
|
53
|
+
const order = compareVersions(a.at, b.at);
|
|
54
|
+
return order < 0 ? a : order > 0 ? b : {
|
|
55
|
+
at: a.at,
|
|
56
|
+
inclusive: a.inclusive && b.inclusive
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const intersect = (a, b) => {
|
|
60
|
+
const lo = tighterLo(a.lo, b.lo);
|
|
61
|
+
const hi = tighterHi(a.hi, b.hi);
|
|
62
|
+
return {
|
|
63
|
+
...lo !== void 0 ? { lo } : {},
|
|
64
|
+
...hi !== void 0 ? { hi } : {}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const isEmpty = (span) => {
|
|
68
|
+
if (span.lo === void 0 || span.hi === void 0) return false;
|
|
69
|
+
const order = compareVersions(span.lo.at, span.hi.at);
|
|
70
|
+
return order > 0 || order === 0 && !(span.lo.inclusive && span.hi.inclusive);
|
|
71
|
+
};
|
|
72
|
+
const comparator = (token, whole) => {
|
|
73
|
+
const [, operator, rest = ""] = /^(>=|<=|>|<|=)?\s*(.+)$/.exec(token) ?? [];
|
|
74
|
+
let at;
|
|
75
|
+
try {
|
|
76
|
+
at = parseVersion(rest);
|
|
77
|
+
} catch {
|
|
78
|
+
throw new VersionError(`version range ${whole}: ${token} names no version`);
|
|
79
|
+
}
|
|
80
|
+
switch (operator) {
|
|
81
|
+
case ">=": return { lo: {
|
|
82
|
+
at,
|
|
83
|
+
inclusive: true
|
|
84
|
+
} };
|
|
85
|
+
case ">": return { lo: {
|
|
86
|
+
at,
|
|
87
|
+
inclusive: false
|
|
88
|
+
} };
|
|
89
|
+
case "<=": return { hi: {
|
|
90
|
+
at,
|
|
91
|
+
inclusive: true
|
|
92
|
+
} };
|
|
93
|
+
case "<": return { hi: {
|
|
94
|
+
at,
|
|
95
|
+
inclusive: false
|
|
96
|
+
} };
|
|
97
|
+
default: return seriesSpan(at);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* This function gives the spans of a range: one span for each alternative.
|
|
102
|
+
*
|
|
103
|
+
* @throws VersionError when the range has an empty alternative or a comparator with no version
|
|
104
|
+
*/
|
|
105
|
+
const parseRange = (range) => {
|
|
106
|
+
const alternatives = range.split("||").map((part) => part.trim());
|
|
107
|
+
if (alternatives.some((part) => part === "")) throw new VersionError(`version range ${range}: an empty alternative`);
|
|
108
|
+
return alternatives.map((alternative) => alternative.replace(/(>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).map((token) => comparator(token, range)).reduce((span, part) => intersect(span, part), {}));
|
|
109
|
+
};
|
|
110
|
+
const contains = (outer, inner) => {
|
|
111
|
+
const lo = tighterLo(outer.lo, inner.lo);
|
|
112
|
+
const hi = tighterHi(outer.hi, inner.hi);
|
|
113
|
+
const same = (a, b) => a === void 0 && b === void 0 || a !== void 0 && b !== void 0 && compareVersions(a.at, b.at) === 0 && a.inclusive === b.inclusive;
|
|
114
|
+
return same(lo, inner.lo) && same(hi, inner.hi);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* This function tells how a range meets the series of a version. The result is `all` when the full series is in the
|
|
118
|
+
* range. It is `some` when a part of the series is in the range, and `none` when no part is in the range.
|
|
119
|
+
*
|
|
120
|
+
* @throws VersionError when the range or the version is not correct
|
|
121
|
+
*/
|
|
122
|
+
const rangeMeets = (range, version) => {
|
|
123
|
+
const asked = seriesSpan(parseVersion(version));
|
|
124
|
+
const spans = parseRange(range);
|
|
125
|
+
if (spans.some((span) => contains(span, asked))) return "all";
|
|
126
|
+
if (spans.some((span) => !isEmpty(intersect(span, asked)))) return "some";
|
|
127
|
+
return "none";
|
|
128
|
+
};
|
|
129
|
+
/** The schema of a version range of a condition: ">=6.6 <6.7", "=6.6.87.2" or "6.6". */
|
|
130
|
+
const versionRangeSchema = z.string().superRefine((range, ctx) => {
|
|
131
|
+
try {
|
|
132
|
+
if (parseRange(range).every(isEmpty)) ctx.addIssue({
|
|
133
|
+
code: "custom",
|
|
134
|
+
message: `version range ${range} allows no version at all`
|
|
135
|
+
});
|
|
136
|
+
} catch (error) {
|
|
137
|
+
ctx.addIssue({
|
|
138
|
+
code: "custom",
|
|
139
|
+
message: error instanceof Error ? error.message : String(error)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
/** The schema of one condition of a claim. A system or a model is the id of an entity. */
|
|
144
|
+
const conditionSchema = z.union([
|
|
145
|
+
z.strictObject({
|
|
146
|
+
of: entityIdSchema,
|
|
147
|
+
versions: versionRangeSchema
|
|
148
|
+
}),
|
|
149
|
+
z.strictObject({ on: entityIdSchema }),
|
|
150
|
+
z.strictObject({ architecture: z.string().min(1) }),
|
|
151
|
+
z.strictObject({ population: z.string().min(1) })
|
|
152
|
+
]);
|
|
153
|
+
// src/spine.ts
|
|
154
|
+
/** The verdicts of a claim. */
|
|
155
|
+
const CLAIM_VERDICTS = [
|
|
156
|
+
"supported",
|
|
157
|
+
"equivalent",
|
|
158
|
+
"disputed",
|
|
159
|
+
"refuted",
|
|
160
|
+
"speculative"
|
|
161
|
+
];
|
|
162
|
+
/** The facets of the spine. */
|
|
163
|
+
const spineFacets = [{
|
|
164
|
+
name: "evidenced",
|
|
165
|
+
description: "An evidence grade, an agreement score, the date of the last check, and the sources.",
|
|
166
|
+
attributes: {
|
|
167
|
+
evidence_grade: z.string().optional(),
|
|
168
|
+
agreement_score: z.number().optional(),
|
|
169
|
+
last_verified: z.string().optional(),
|
|
170
|
+
supporting_source_ids: z.array(z.string()).optional(),
|
|
171
|
+
contradicting_source_ids: z.array(z.string()).optional()
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
name: "quantified",
|
|
175
|
+
description: "An amount: the quantity, no bound, or unknown with the reason, and the statistic of its distribution.",
|
|
176
|
+
attributes: {
|
|
177
|
+
quantity: z.union([extentSchema(), unknownSchema]).optional(),
|
|
178
|
+
statistic: statisticSchema.optional()
|
|
179
|
+
}
|
|
180
|
+
}];
|
|
181
|
+
/** The kinds of the spine: the root, the abstract kinds, the claim, and the kinds of the grammar as data. */
|
|
182
|
+
const spineKinds = [
|
|
183
|
+
{
|
|
184
|
+
name: "entity",
|
|
185
|
+
parent: null,
|
|
186
|
+
mode: "top",
|
|
187
|
+
description: "The root kind. Each entity is an entity.",
|
|
188
|
+
attributes: {
|
|
189
|
+
name: z.string(),
|
|
190
|
+
notes: z.string().optional()
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "concept",
|
|
195
|
+
parent: "entity",
|
|
196
|
+
mode: "abstract",
|
|
197
|
+
description: "An abstract thing: a class, a topic, a category or a role.",
|
|
198
|
+
attributes: {}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "claim",
|
|
202
|
+
parent: "entity",
|
|
203
|
+
mode: "information",
|
|
204
|
+
description: "A statement with a verdict, its evidence and the conditions where it holds.",
|
|
205
|
+
attributes: {
|
|
206
|
+
statement: z.string(),
|
|
207
|
+
verdict: z.enum(CLAIM_VERDICTS).optional(),
|
|
208
|
+
category: z.string().optional(),
|
|
209
|
+
nuance: z.string().optional(),
|
|
210
|
+
conditions: z.array(conditionSchema).optional()
|
|
211
|
+
},
|
|
212
|
+
facets: ["evidenced", "quantified"]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "facet",
|
|
216
|
+
parent: "entity",
|
|
217
|
+
mode: "abstract",
|
|
218
|
+
description: "A set of attributes that kinds share with no common parent. A facet is data too.",
|
|
219
|
+
attributes: { description: z.string() }
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "kind",
|
|
223
|
+
parent: "entity",
|
|
224
|
+
mode: "abstract",
|
|
225
|
+
description: "A kind of the registry. The kinds are data too.",
|
|
226
|
+
attributes: {
|
|
227
|
+
mode: z.enum(MODES),
|
|
228
|
+
description: z.string(),
|
|
229
|
+
instances: z.number().int().min(0).optional(),
|
|
230
|
+
from_kinds: z.array(z.string()).optional(),
|
|
231
|
+
to_kinds: z.array(z.string()).optional(),
|
|
232
|
+
symmetric: z.boolean().optional(),
|
|
233
|
+
transitive: z.boolean().optional(),
|
|
234
|
+
roles: z.array(z.string()).optional(),
|
|
235
|
+
key: z.array(z.string()).optional()
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "relation",
|
|
240
|
+
parent: "entity",
|
|
241
|
+
mode: "relation",
|
|
242
|
+
description: "A relation instance: an edge with its own id. It can have attributes, and a claim can be about it. Each relation kind is a subkind.",
|
|
243
|
+
attributes: {
|
|
244
|
+
from: entityIdSchema,
|
|
245
|
+
to: entityIdSchema
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
];
|
|
249
|
+
/** The relation kinds of the spine: the grammar as data, the subject of a claim, and the classification. */
|
|
250
|
+
const spineRelations = [
|
|
251
|
+
{
|
|
252
|
+
name: "has-facet",
|
|
253
|
+
description: "A kind has a facet.",
|
|
254
|
+
from: ["kind"],
|
|
255
|
+
to: ["facet"]
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "subkind-of",
|
|
259
|
+
description: "A kind is a subkind of its parent kind.",
|
|
260
|
+
from: ["kind"],
|
|
261
|
+
to: ["kind"],
|
|
262
|
+
transitive: true
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: "about",
|
|
266
|
+
description: "A claim is about an entity. An add-on can add more kinds at the start.",
|
|
267
|
+
from: ["claim"],
|
|
268
|
+
to: ["entity"]
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "classified-as",
|
|
272
|
+
abstract: true,
|
|
273
|
+
description: "An entity is in a class. Two relation kinds narrow it: one instance-of, then zero or more subclass-of.",
|
|
274
|
+
from: ["concept"],
|
|
275
|
+
to: ["concept"]
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
name: "instance-of",
|
|
279
|
+
parent: "classified-as",
|
|
280
|
+
description: "A particular is in a class. The spine has no kind of particular: each add-on adds its kinds to this relation and to classified-as.",
|
|
281
|
+
from: [],
|
|
282
|
+
to: ["concept"]
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "subclass-of",
|
|
286
|
+
parent: "classified-as",
|
|
287
|
+
description: "A class is in a wider class. It is transitive: each member of the narrow class is in the wide class.",
|
|
288
|
+
from: ["concept"],
|
|
289
|
+
to: ["concept"],
|
|
290
|
+
transitive: true
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
/** The spine as the input of a registry. An add-on joins it with its own parts through `composeRegistryInput`. */
|
|
294
|
+
const SPINE = {
|
|
295
|
+
kinds: spineKinds,
|
|
296
|
+
relations: spineRelations,
|
|
297
|
+
facets: spineFacets
|
|
298
|
+
};
|
|
299
|
+
/** This function gives the registry of the spine and of the add-ons that it gets. */
|
|
300
|
+
const spineRegistry = (...addOns) => new Registry(composeRegistryInput(SPINE, ...addOns));
|
|
301
|
+
export { CLAIM_VERDICTS, DEFAULT_HEADER, ENTITY_ID_PATTERN, MODES, NAME_PATTERN, RELATION_ROOT, Registry, RegistryError, SCOPES, SPINE, VersionError, columnShape, compareVersions, composeRegistryInput, conditionSchema, edgeRowSchema, edgeSchema, entityIdSchema, entitySchema, envelopeSchema, generateAll, generateDuckDbDdl, generateJsonSchemas, generateSqliteDdl, isRelationId, keyedRelationId, kindJson, maxScope, nameOf, parseRange, parseVersion, rangeMeets, registryJson, relationId, relationJson, scopeRank, scopeSchema, seriesSpan, spineFacets, spineKinds, spineRegistry, spineRelations, versionRangeSchema, visibleTo };
|
|
302
|
+
|
|
303
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/versions.ts","../src/spine.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { entityIdSchema } from \"./grammar.ts\";\n\n/**\n * Versions and version ranges, for the conditions of a claim: \"the default is 15 on Linux >=2.6.12\".\n *\n * A version starts with dotted numbers (\"6.6.87.2\"). The order ignores the text after the numbers, so\n * \"6.6.87.2-custom\" has the order of 6.6.87.2. A range is a list of comparators with spaces between them\n * (\">=6.6 <6.7\"). Each comparator must hold. Alternatives have \"||\" between them.\n *\n * A version with no operator names its series: \"6.6\" is each 6.6.x. \"=6.6.87.2\" names that release and its patches.\n */\n\n/** A version: its dotted numbers. */\nexport type Version = readonly number[];\n\n/** One end of a span of versions. */\ninterface Bound {\n readonly at: Version;\n readonly inclusive: boolean;\n}\n\n/** A span of versions from `lo` to `hi`. An end with no bound is open. */\nexport interface VersionSpan {\n readonly lo?: Bound;\n readonly hi?: Bound;\n}\n\n/** The error of a text that is not a version or a range. */\nexport class VersionError extends Error {\n override readonly name = \"VersionError\";\n}\n\n/**\n * This function gives the dotted numbers at the start of a version.\n *\n * @throws VersionError when the text does not start with a number\n */\nexport const parseVersion = (text: string): Version => {\n const match = /^v?(\\d+(?:\\.\\d+)*)/.exec(text.trim());\n if (match?.[1] === undefined) throw new VersionError(`not a version: ${text}`);\n return match[1].split(\".\").map(Number);\n};\n\n/** This function gives -1, 0 or 1. It adds zeros to a shorter version, so 6.6 is 6.6.0. */\nexport const compareVersions = (a: Version, b: Version): number => {\n for (let i = 0; i < Math.max(a.length, b.length); i += 1) {\n const x = a[i] ?? 0;\n const y = b[i] ?? 0;\n if (x !== y) return x < y ? -1 : 1;\n }\n return 0;\n};\n\n/** This function gives the release after a series: 6.7 after 6.6, and 7 after 6. */\nconst next = (series: Version): Version => [...series.slice(0, -1), (series[series.length - 1] ?? 0) + 1];\n\n/** This function gives a series as a span: 6.6 is from 6.6 up to 6.7, and 6.7 is not in it. */\nexport const seriesSpan = (series: Version): VersionSpan => ({\n lo: { at: series, inclusive: true },\n hi: { at: next(series), inclusive: false },\n});\n\nconst tighterLo = (a: Bound | undefined, b: Bound | undefined): Bound | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n const order = compareVersions(a.at, b.at);\n return order > 0 ? a : order < 0 ? b : { at: a.at, inclusive: a.inclusive && b.inclusive };\n};\n\nconst tighterHi = (a: Bound | undefined, b: Bound | undefined): Bound | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n const order = compareVersions(a.at, b.at);\n return order < 0 ? a : order > 0 ? b : { at: a.at, inclusive: a.inclusive && b.inclusive };\n};\n\nconst intersect = (a: VersionSpan, b: VersionSpan): VersionSpan => {\n const lo = tighterLo(a.lo, b.lo);\n const hi = tighterHi(a.hi, b.hi);\n return { ...(lo !== undefined ? { lo } : {}), ...(hi !== undefined ? { hi } : {}) };\n};\n\nconst isEmpty = (span: VersionSpan): boolean => {\n if (span.lo === undefined || span.hi === undefined) return false;\n const order = compareVersions(span.lo.at, span.hi.at);\n return order > 0 || (order === 0 && !(span.lo.inclusive && span.hi.inclusive));\n};\n\nconst comparator = (token: string, whole: string): VersionSpan => {\n const match = /^(>=|<=|>|<|=)?\\s*(.+)$/.exec(token);\n const [, operator, rest = \"\"] = match ?? [];\n let at: Version;\n try {\n at = parseVersion(rest);\n } catch {\n throw new VersionError(`version range ${whole}: ${token} names no version`);\n }\n switch (operator) {\n case \">=\":\n return { lo: { at, inclusive: true } };\n case \">\":\n return { lo: { at, inclusive: false } };\n case \"<=\":\n return { hi: { at, inclusive: true } };\n case \"<\":\n return { hi: { at, inclusive: false } };\n // \"=6.6.87.2\" is that release: the series that it names\n case \"=\":\n default:\n return seriesSpan(at);\n }\n};\n\n/**\n * This function gives the spans of a range: one span for each alternative.\n *\n * @throws VersionError when the range has an empty alternative or a comparator with no version\n */\nexport const parseRange = (range: string): VersionSpan[] => {\n const alternatives = range.split(\"||\").map((part) => part.trim());\n if (alternatives.some((part) => part === \"\")) {\n throw new VersionError(`version range ${range}: an empty alternative`);\n }\n return alternatives.map((alternative) =>\n alternative\n .replace(/(>=|<=|>|<|=)\\s+/g, \"$1\")\n .split(/\\s+/)\n .map((token) => comparator(token, range))\n .reduce<VersionSpan>((span, part) => intersect(span, part), {}),\n );\n};\n\nconst contains = (outer: VersionSpan, inner: VersionSpan): boolean => {\n const lo = tighterLo(outer.lo, inner.lo);\n const hi = tighterHi(outer.hi, inner.hi);\n // The inner span is inside the outer span when the outer span does not make it tighter\n const same = (a: Bound | undefined, b: Bound | undefined): boolean =>\n (a === undefined && b === undefined) ||\n (a !== undefined && b !== undefined && compareVersions(a.at, b.at) === 0 && a.inclusive === b.inclusive);\n return same(lo, inner.lo) && same(hi, inner.hi);\n};\n\n/**\n * This function tells how a range meets the series of a version. The result is `all` when the full series is in the\n * range. It is `some` when a part of the series is in the range, and `none` when no part is in the range.\n *\n * @throws VersionError when the range or the version is not correct\n */\nexport const rangeMeets = (range: string, version: string): \"all\" | \"some\" | \"none\" => {\n const asked = seriesSpan(parseVersion(version));\n const spans = parseRange(range);\n if (spans.some((span) => contains(span, asked))) return \"all\";\n if (spans.some((span) => !isEmpty(intersect(span, asked)))) return \"some\";\n return \"none\";\n};\n\n/**\n * One condition of a claim: a system at a range of versions, the hardware or the provider, an architecture, or\n * the population of a study. A claim holds where each of its conditions holds.\n */\nexport type Condition =\n | { readonly of: string; readonly versions: string }\n | { readonly on: string }\n | { readonly architecture: string }\n | { readonly population: string };\n\n/** The schema of a version range of a condition: \">=6.6 <6.7\", \"=6.6.87.2\" or \"6.6\". */\nexport const versionRangeSchema: z.ZodType<string, string> = z.string().superRefine((range, ctx) => {\n try {\n if (parseRange(range).every(isEmpty)) {\n ctx.addIssue({ code: \"custom\", message: `version range ${range} allows no version at all` });\n }\n } catch (error) {\n ctx.addIssue({ code: \"custom\", message: error instanceof Error ? error.message : String(error) });\n }\n});\n\n/** The schema of one condition of a claim. A system or a model is the id of an entity. */\nexport const conditionSchema: z.ZodType<Condition, Condition> = z.union([\n // The system and its versions\n z.strictObject({ of: entityIdSchema, versions: versionRangeSchema }),\n // The hardware model or the provider\n z.strictObject({ on: entityIdSchema }),\n z.strictObject({ architecture: z.string().min(1) }),\n // The population of a study, in words\n z.strictObject({ population: z.string().min(1) }),\n]);\n","import { extentSchema, statisticSchema, unknownSchema } from \"@mark1russell7/quantity/schema\";\nimport { z } from \"zod\";\nimport type { FacetDef, KindDef, Mode, RelationKindDef } from \"./grammar.ts\";\nimport { MODES, entityIdSchema } from \"./grammar.ts\";\nimport type { RegistryInput } from \"./registry.ts\";\nimport { Registry, composeRegistryInput } from \"./registry.ts\";\nimport { conditionSchema } from \"./versions.ts\";\n\n/** The verdicts of a claim. */\nexport const CLAIM_VERDICTS = [\"supported\", \"equivalent\", \"disputed\", \"refuted\", \"speculative\"] as const;\n\n/** The verdict of a claim. */\nexport type ClaimVerdict = (typeof CLAIM_VERDICTS)[number];\n\n/** The facets of the spine. */\nexport const spineFacets: readonly FacetDef[] = [\n {\n name: \"evidenced\",\n description: \"An evidence grade, an agreement score, the date of the last check, and the sources.\",\n attributes: {\n // The name of a rung of the ladder that grades the kind\n evidence_grade: z.string().optional(),\n agreement_score: z.number().optional(),\n last_verified: z.string().optional(),\n // Each value names a source. A part after a \"#\" tells where in the source: a file and a line, or a section\n supporting_source_ids: z.array(z.string()).optional(),\n contradicting_source_ids: z.array(z.string()).optional(),\n },\n },\n {\n name: \"quantified\",\n description:\n \"An amount: the quantity, no bound, or unknown with the reason, and the statistic of its distribution.\",\n attributes: {\n quantity: z.union([extentSchema(), unknownSchema]).optional(),\n statistic: statisticSchema.optional(),\n },\n },\n];\n\n/** The kinds of the spine: the root, the abstract kinds, the claim, and the kinds of the grammar as data. */\nexport const spineKinds: readonly KindDef[] = [\n {\n name: \"entity\",\n parent: null,\n mode: \"top\",\n description: \"The root kind. Each entity is an entity.\",\n attributes: {\n name: z.string(),\n notes: z.string().optional(),\n },\n },\n {\n name: \"concept\",\n parent: \"entity\",\n mode: \"abstract\",\n description: \"An abstract thing: a class, a topic, a category or a role.\",\n attributes: {},\n },\n {\n name: \"claim\",\n parent: \"entity\",\n mode: \"information\",\n description: \"A statement with a verdict, its evidence and the conditions where it holds.\",\n attributes: {\n statement: z.string(),\n verdict: z.enum(CLAIM_VERDICTS).optional(),\n category: z.string().optional(),\n nuance: z.string().optional(),\n // The conditions where the claim holds: versions of a system, an architecture, a provider, a population\n conditions: z.array(conditionSchema).optional(),\n },\n facets: [\"evidenced\", \"quantified\"],\n },\n {\n name: \"facet\",\n parent: \"entity\",\n mode: \"abstract\",\n description: \"A set of attributes that kinds share with no common parent. A facet is data too.\",\n attributes: {\n description: z.string(),\n },\n },\n {\n name: \"kind\",\n parent: \"entity\",\n mode: \"abstract\",\n description: \"A kind of the registry. The kinds are data too.\",\n attributes: {\n mode: z.enum(MODES as [Mode, ...Mode[]]),\n description: z.string(),\n // The count of the entities of exactly this kind, from the last projection\n instances: z.number().int().min(0).optional(),\n // The ends, the symmetry, the transitivity, the roles and the key of a relation kind\n from_kinds: z.array(z.string()).optional(),\n to_kinds: z.array(z.string()).optional(),\n symmetric: z.boolean().optional(),\n transitive: z.boolean().optional(),\n roles: z.array(z.string()).optional(),\n key: z.array(z.string()).optional(),\n },\n },\n {\n name: \"relation\",\n parent: \"entity\",\n mode: \"relation\",\n description:\n \"A relation instance: an edge with its own id. It can have attributes, and a claim can be about it. Each relation kind is a subkind.\",\n attributes: {\n from: entityIdSchema,\n to: entityIdSchema,\n },\n },\n];\n\n/** The relation kinds of the spine: the grammar as data, the subject of a claim, and the classification. */\nexport const spineRelations: readonly RelationKindDef[] = [\n {\n name: \"has-facet\",\n description: \"A kind has a facet.\",\n from: [\"kind\"],\n to: [\"facet\"],\n },\n {\n name: \"subkind-of\",\n description: \"A kind is a subkind of its parent kind.\",\n from: [\"kind\"],\n to: [\"kind\"],\n transitive: true,\n },\n {\n name: \"about\",\n description: \"A claim is about an entity. An add-on can add more kinds at the start.\",\n from: [\"claim\"],\n to: [\"entity\"],\n },\n {\n name: \"classified-as\",\n abstract: true,\n description:\n \"An entity is in a class. Two relation kinds narrow it: one instance-of, then zero or more subclass-of.\",\n from: [\"concept\"],\n to: [\"concept\"],\n },\n {\n name: \"instance-of\",\n parent: \"classified-as\",\n description:\n \"A particular is in a class. The spine has no kind of particular: each add-on adds its kinds to this relation and to classified-as.\",\n from: [],\n to: [\"concept\"],\n },\n {\n name: \"subclass-of\",\n parent: \"classified-as\",\n description: \"A class is in a wider class. It is transitive: each member of the narrow class is in the wide class.\",\n from: [\"concept\"],\n to: [\"concept\"],\n transitive: true,\n },\n];\n\n/** The spine as the input of a registry. An add-on joins it with its own parts through `composeRegistryInput`. */\nexport const SPINE: RegistryInput = {\n kinds: spineKinds,\n relations: spineRelations,\n facets: spineFacets,\n};\n\n/** This function gives the registry of the spine and of the add-ons that it gets. */\nexport const spineRegistry = (...addOns: readonly RegistryInput[]): Registry =>\n new Registry(composeRegistryInput(SPINE, ...addOns));\n"],"mappings":";;;;;AA6BA,IAAa,eAAb,cAAkC,MAAM;CACpB,OAAO;AAC3B;;;;;;AAOA,MAAa,gBAAgB,SAA0B;CACrD,MAAM,QAAQ,qBAAqB,KAAK,KAAK,KAAK,CAAC;CACnD,IAAI,QAAQ,OAAO,KAAA,GAAW,MAAM,IAAI,aAAa,kBAAkB,MAAM;CAC7E,OAAO,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;AACvC;;AAGA,MAAa,mBAAmB,GAAY,MAAuB;CACjE,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG;EACxD,MAAM,IAAI,EAAE,MAAM;EAClB,MAAM,IAAI,EAAE,MAAM;EAClB,IAAI,MAAM,GAAG,OAAO,IAAI,IAAI,KAAK;CACnC;CACA,OAAO;AACT;;AAGA,MAAM,QAAQ,WAA6B,CAAC,GAAG,OAAO,MAAM,GAAG,EAAE,IAAI,OAAO,OAAO,SAAS,MAAM,KAAK,CAAC;;AAGxG,MAAa,cAAc,YAAkC;CAC3D,IAAI;EAAE,IAAI;EAAQ,WAA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,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;GACpC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS;EACpC;CACF;CACA;EACE,MAAM;EACN,QAAQ;EACR,MAAM;EACN,aACE;EACF,YAAY;GACV,MAAM;GACN,IAAI;EACN;CACF;AACF;;AAGA,MAAa,iBAA6C;CACxD;EACE,MAAM;EACN,aAAa;EACb,MAAM,CAAC,MAAM;EACb,IAAI,CAAC,OAAO;CACd;CACA;EACE,MAAM;EACN,aAAa;EACb,MAAM,CAAC,MAAM;EACb,IAAI,CAAC,MAAM;EACX,YAAY;CACd;CACA;EACE,MAAM;EACN,aAAa;EACb,MAAM,CAAC,OAAO;EACd,IAAI,CAAC,QAAQ;CACf;CACA;EACE,MAAM;EACN,UAAU;EACV,aACE;EACF,MAAM,CAAC,SAAS;EAChB,IAAI,CAAC,SAAS;CAChB;CACA;EACE,MAAM;EACN,QAAQ;EACR,aACE;EACF,MAAM,CAAC;EACP,IAAI,CAAC,SAAS;CAChB;CACA;EACE,MAAM;EACN,QAAQ;EACR,aAAa;EACb,MAAM,CAAC,SAAS;EAChB,IAAI,CAAC,SAAS;EACd,YAAY;CACd;AACF;;AAGA,MAAa,QAAuB;CAClC,OAAO;CACP,WAAW;CACX,QAAQ;AACV;;AAGA,MAAa,iBAAiB,GAAG,WAC/B,IAAI,SAAS,qBAAqB,OAAO,GAAG,MAAM,CAAC"}
|
package/build/node.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { i as Registry, n as GenerateOptions } from "./header-nlcc_Vh2.mjs";
|
|
2
|
+
/** This function writes each generated file of a registry into a folder, and gives the names of the files. */
|
|
3
|
+
export declare const writeGenerated: (registry: Registry, dir: string, options?: GenerateOptions) => Promise<readonly string[]>;
|
|
4
|
+
/**
|
|
5
|
+
* This function gives the names of the generated files in a folder that are not the same as a new generation. A
|
|
6
|
+
* missing file is in the list. The check ignores the difference between CRLF and LF.
|
|
7
|
+
*/
|
|
8
|
+
export declare const staleGenerated: (registry: Registry, dir: string, options?: GenerateOptions) => Promise<readonly string[]>;
|
package/build/node.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { t as generateAll } from "./generate-D6Vazln0.mjs";
|
|
4
|
+
// src/node.ts
|
|
5
|
+
/** This function writes each generated file of a registry into a folder, and gives the names of the files. */
|
|
6
|
+
const writeGenerated = async (registry, dir, options) => {
|
|
7
|
+
await mkdir(dir, { recursive: true });
|
|
8
|
+
const files = generateAll(registry, options);
|
|
9
|
+
for (const [name, content] of Object.entries(files)) await writeFile(join(dir, name), content, "utf8");
|
|
10
|
+
return Object.keys(files);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* This function gives the names of the generated files in a folder that are not the same as a new generation. A
|
|
14
|
+
* missing file is in the list. The check ignores the difference between CRLF and LF.
|
|
15
|
+
*/
|
|
16
|
+
const staleGenerated = async (registry, dir, options) => {
|
|
17
|
+
const stale = [];
|
|
18
|
+
for (const [name, expected] of Object.entries(generateAll(registry, options))) if ((await readFile(join(dir, name), "utf8").catch(() => void 0))?.replaceAll("\r\n", "\n") !== expected) stale.push(name);
|
|
19
|
+
return stale;
|
|
20
|
+
};
|
|
21
|
+
export { staleGenerated, writeGenerated };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../src/node.ts"],"sourcesContent":["import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { GenerateOptions } from \"./codegen/header.ts\";\nimport { generateAll } from \"./generate.ts\";\nimport type { Registry } from \"./registry.ts\";\n\n/** This function writes each generated file of a registry into a folder, and gives the names of the files. */\nexport const writeGenerated = async (\n registry: Registry,\n dir: string,\n options?: GenerateOptions,\n): Promise<readonly string[]> => {\n await mkdir(dir, { recursive: true });\n const files = generateAll(registry, options);\n for (const [name, content] of Object.entries(files)) {\n await writeFile(join(dir, name), content, \"utf8\");\n }\n return Object.keys(files);\n};\n\n/**\n * This function gives the names of the generated files in a folder that are not the same as a new generation. A\n * missing file is in the list. The check ignores the difference between CRLF and LF.\n */\nexport const staleGenerated = async (\n registry: Registry,\n dir: string,\n options?: GenerateOptions,\n): Promise<readonly string[]> => {\n const stale: string[] = [];\n for (const [name, expected] of Object.entries(generateAll(registry, options))) {\n const onDisk = await readFile(join(dir, name), \"utf8\").catch(() => undefined);\n if (onDisk?.replaceAll(\"\\r\\n\", \"\\n\") !== expected) stale.push(name);\n }\n return stale;\n};\n"],"mappings":";;;;;AAOA,MAAa,iBAAiB,OAC5B,UACA,KACA,YAC+B;CAC/B,MAAM,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CACpC,MAAM,QAAQ,YAAY,UAAU,OAAO;CAC3C,KAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,KAAK,GAChD,MAAM,UAAU,KAAK,KAAK,IAAI,GAAG,SAAS,MAAM;CAElD,OAAO,OAAO,KAAK,KAAK;AAC1B;;;;;AAMA,MAAa,iBAAiB,OAC5B,UACA,KACA,YAC+B;CAC/B,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,YAAY,UAAU,OAAO,CAAC,GAE1E,KAAI,MADiB,SAAS,KAAK,KAAK,IAAI,GAAG,MAAM,CAAC,CAAC,YAAY,KAAA,CAAS,EAAA,EAChE,WAAW,QAAQ,IAAI,MAAM,UAAU,MAAM,KAAK,IAAI;CAEpE,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package",
|
|
2
3
|
"name": "@mark1russell7/ontology",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "A grammar of kinds and relations, a registry, claims under conditions, and the SQLite, DuckDB and JSON Schema of the kinds.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"ontology",
|
|
8
|
+
"knowledge-graph",
|
|
9
|
+
"schema",
|
|
10
|
+
"registry",
|
|
11
|
+
"claims",
|
|
12
|
+
"zod",
|
|
13
|
+
"duckdb",
|
|
14
|
+
"sqlite",
|
|
15
|
+
"json-schema",
|
|
16
|
+
"codegen"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/metrograph-labs/ontology/tree/main/packages/ontology#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/metrograph-labs/ontology/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/metrograph-labs/ontology.git",
|
|
25
|
+
"directory": "packages/ontology"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "Mark Russell (https://github.com/mark1russell7)",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./build/index.mjs",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./build/index.d.mts",
|
|
34
|
+
"default": "./build/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./node": {
|
|
37
|
+
"types": "./build/node.d.mts",
|
|
38
|
+
"default": "./build/node.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"build",
|
|
44
|
+
"README.md"
|
|
45
|
+
],
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@mark1russell7/quantity": "^0.4.8 || ^0.5.3",
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@mark1russell7/cue": "^2.0.0",
|
|
58
|
+
"@mark1russell7/quantity": "^0.5.3",
|
|
59
|
+
"@types/node": "^26.6.5",
|
|
60
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
61
|
+
"tsdown": "^0.23.8",
|
|
62
|
+
"typescript": "^7.0.2",
|
|
63
|
+
"vitest": "^5.0.3",
|
|
64
|
+
"zod": "^4.6.7"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsdown",
|
|
68
|
+
"generate": "node src/generate.main.ts",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"test:watch": "vitest",
|
|
71
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
|
|
72
|
+
},
|
|
73
|
+
"types": "./build/index.d.mts"
|
|
6
74
|
}
|