@okfit/core 0.1.0 → 0.3.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/README.md CHANGED
@@ -10,9 +10,20 @@ Spec-level [Open Knowledge Format (OKF)](https://github.com/GoogleCloudPlatform/
10
10
  pnpm add @okfit/core effect
11
11
  ```
12
12
 
13
- ## Status
13
+ ## Usage
14
14
 
15
- Skeleton. The public surface is `OKF_SPEC_VERSION` only.
15
+ ```ts
16
+ import { Bundle, OkfitConfig, Validate } from "@okfit/core";
17
+ import { Effect } from "effect";
18
+
19
+ const program = Effect.gen(function* () {
20
+ const config = OkfitConfig.merge(OkfitConfig.DEFAULTS, yield* OkfitConfig.read("/repo/.config/okfit.toml"));
21
+ const bundle = yield* Bundle.load({ root: "/repo/okf" });
22
+ return Validate.all(bundle, config);
23
+ });
24
+ ```
25
+
26
+ `Bundle.load` needs `FileSystem` and `Path`; `OkfitConfig.read` needs `FileSystem`. Loading never fails on content: bad files become `Diagnostic`s. `Graph.fromBundle` treats a path-valued field or link whose target, resolved from its concept's directory, lands outside the bundle root as an external reference: no graph node and no `broken-links` diagnostic, exactly like a URL. `OkfitConfig` decodes the spec 4.2 TOML shape; unknown top-level keys are kept in `extensions` and reported by `Validate.lint` as `config-unknown-key`. `lifecycle.default_stale_after` accepts `90d`, `12h`, `2w`, or `"90 days"`. `OkfitConfig.merge` deep-merges tables; arrays and scalars in `override` replace wholesale. Apply `DEFAULTS < profile < file` yourself. `OkfitConfigFile` is the service tag; the CLI provides its layer. `okfitConfigDocumentFields` is `okfitConfigFields` minus `extensions` (wire bookkeeping no human writes), with an open rest so unknown top-level keys stay permitted while every declared table stays closed; it is the single source `lib/scripts/generate-schema.ts` builds the published JSON Schema (`schemas/config/okfit-1.0.0.json`) from, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The `[lint]` table's sixteen keys include `generated_at_drift` (default `"warn"`), which fires when a committed concept's `generated.at` no longer matches the instant its body was last changed AND is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge) — computed by `okfit sync`/`okfit validate`, never by core itself.
16
27
 
17
28
  ## License
18
29
 
package/Source.js ADDED
@@ -0,0 +1,29 @@
1
+ import { Actor } from "./Actor.js";
2
+ import { Timestamp } from "./Timestamp.js";
3
+ import { Schema } from "effect";
4
+
5
+ //#region src/Source.ts
6
+ /**
7
+ * A closed interval of use, on a concept or on one of its sources.
8
+ * @public
9
+ */
10
+ var UsageWindow = class extends Schema.Class("UsageWindow")({
11
+ from: Timestamp,
12
+ to: Timestamp
13
+ }) {};
14
+ /**
15
+ * One provenance entry. `resource` is a URL, a bundle path or a scope descriptor (D-24); never resolved here.
16
+ * @public
17
+ */
18
+ var Source = class extends Schema.Class("Source")({
19
+ resource: Schema.String,
20
+ id: Schema.optionalKey(Schema.String),
21
+ title: Schema.optionalKey(Schema.String),
22
+ author: Schema.optionalKey(Actor),
23
+ usage_count: Schema.optionalKey(Schema.Union([Schema.Number, Schema.FiniteFromString])),
24
+ last_modified: Schema.optionalKey(Timestamp),
25
+ usage_window: Schema.optionalKey(UsageWindow)
26
+ }) {};
27
+
28
+ //#endregion
29
+ export { Source, UsageWindow };
package/Status.js ADDED
@@ -0,0 +1,15 @@
1
+ import { Schema } from "effect";
2
+
3
+ //#region src/Status.ts
4
+ /**
5
+ * Concept lifecycle status. Absent on a concept means `stable` (`Derive.status`).
6
+ * @public
7
+ */
8
+ const Status = Schema.Literals([
9
+ "draft",
10
+ "stable",
11
+ "deprecated"
12
+ ]);
13
+
14
+ //#endregion
15
+ export { Status };
package/Timestamp.js ADDED
@@ -0,0 +1,18 @@
1
+ import { Function, Schema, SchemaTransformation } from "effect";
2
+
3
+ //#region src/Timestamp.ts
4
+ const OFFSET_RE = /(?:Z|[+-]\d{2}:\d{2})$/;
5
+ const ZERO_MILLIS = /\.000(?=Z$)/;
6
+ /**
7
+ * ISO 8601 string with an explicit offset (`Z`, `+hh:mm` or `-hh:mm`) to `DateTime.Utc`.
8
+ * Offset-less input fails before parsing so its family surfaces as `family-invalid` (D-15/D-16).
9
+ * Encoding writes `2026-03-01T08:00:00Z` for a whole second and keeps non-zero milliseconds.
10
+ * @public
11
+ */
12
+ const Timestamp = Schema.String.pipe(Schema.check(Schema.isPattern(OFFSET_RE, { message: "Expected an ISO 8601 timestamp with an explicit offset (Z, +hh:mm or -hh:mm)" })), Schema.decodeTo(Schema.String, SchemaTransformation.transform({
13
+ decode: Function.identity,
14
+ encode: (iso) => iso.replace(ZERO_MILLIS, "")
15
+ })), Schema.decodeTo(Schema.DateTimeUtcFromString));
16
+
17
+ //#endregion
18
+ export { Timestamp };
package/Validate.js ADDED
@@ -0,0 +1,44 @@
1
+ import { Diagnostic, LintCode } from "./Diagnostic.js";
2
+ import { Graph as Graph$1 } from "./Graph.js";
3
+ import { OkfitConfig } from "./OkfitConfig.js";
4
+ import { LINT_RULES } from "./internal/lintRules.js";
5
+ import { Schema } from "effect";
6
+
7
+ //#region src/Validate.ts
8
+ const isLintCode = Schema.is(LintCode);
9
+ /** Conformance and lint tiers over a {@link LoadedBundle}; pure (D-35). @public */
10
+ var Validate = class Validate {
11
+ constructor() {}
12
+ /** The conformance-coded entries of `bundle.diagnostics`; always severity `error` (D-33). */
13
+ static conformance = (bundle) => bundle.diagnostics.filter(Diagnostic.isConformance);
14
+ /** Load-time lint diagnostics re-severitied via `OkfitConfig.severityFor` (`off` drops), then every rule (D-34). */
15
+ static lint = (bundle, config, options = {}) => {
16
+ const severity = (code) => OkfitConfig.severityFor(config, code);
17
+ const loadTime = [];
18
+ for (const entry of bundle.diagnostics) {
19
+ if (!isLintCode(entry.code)) continue;
20
+ const resolved = severity(entry.code);
21
+ if (resolved === "off") continue;
22
+ loadTime.push(resolved === entry.severity ? entry : Diagnostic.make({
23
+ ...entry,
24
+ severity: resolved
25
+ }));
26
+ }
27
+ const context = {
28
+ bundle,
29
+ config,
30
+ graph: Graph$1.fromBundle(bundle),
31
+ now: options.now,
32
+ severity
33
+ };
34
+ return [...loadTime, ...LINT_RULES.flatMap((rule) => rule(context))];
35
+ };
36
+ /** Runs both tiers (D-35). */
37
+ static all = (bundle, config, options) => ({
38
+ conformance: Validate.conformance(bundle),
39
+ lint: Validate.lint(bundle, config, options)
40
+ });
41
+ };
42
+
43
+ //#endregion
44
+ export { Validate };
@@ -0,0 +1,29 @@
1
+ import { Actor } from "./Actor.js";
2
+ import { Timestamp } from "./Timestamp.js";
3
+ import { Array, Function, Schema, SchemaTransformation } from "effect";
4
+
5
+ //#region src/Verification.ts
6
+ /**
7
+ * One verification attestation: who verified and when.
8
+ * @public
9
+ */
10
+ var Verification = class Verification extends Schema.Class("Verification")({
11
+ by: Actor,
12
+ at: Timestamp
13
+ }) {
14
+ /**
15
+ * Bare mapping or list in; always a list out on decode AND encode (D-17):
16
+ * this transform's encode is `Fn.identity`, so a concept that arrived as a
17
+ * bare mapping is list-shaped on disk from the first re-encode onward. Not
18
+ * `Schema.ArrayEnsure`, whose encode returns the single element for a
19
+ * one-element array (`Schema.ts:4738-4746`) and would round-trip a
20
+ * one-entry list back to a bare mapping.
21
+ */
22
+ static List = Schema.Union([Verification, Schema.Array(Verification)]).pipe(Schema.decodeTo(Schema.Array(Schema.toType(Verification)), SchemaTransformation.transform({
23
+ decode: Array.ensure,
24
+ encode: Function.identity
25
+ })));
26
+ };
27
+
28
+ //#endregion
29
+ export { Verification };