@okfit/core 0.15.0 → 0.17.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/Bundle.js +29 -5
- package/Concept.js +10 -0
- package/ConfinedRead.js +113 -0
- package/Derive.js +3 -3
- package/Diagnostic.js +23 -2
- package/GeneratedAtFuture.js +9 -1
- package/IndexDocument.js +3 -1
- package/LintTable.js +292 -0
- package/LogDocument.js +3 -1
- package/OkfVersion.js +4 -1
- package/OkfitConfig.js +215 -250
- package/README.md +1 -1
- package/Reference.js +65 -0
- package/RepoIdentity.js +46 -0
- package/index.d.ts +337 -50
- package/index.js +7 -3
- package/internal/conceptDecode.js +36 -21
- package/internal/frontmatter.js +2 -2
- package/internal/linkScan.js +57 -0
- package/internal/lintRules.js +35 -14
- package/internal/position.js +2 -2
- package/internal/reserved.js +21 -4
- package/internal/walk.js +1 -0
- package/internal/yamlPathSpan.js +82 -4
- package/package.json +9 -7
- package/tsdoc-metadata.json +1 -1
package/OkfVersion.js
CHANGED
|
@@ -23,7 +23,10 @@ var OkfVersion = class OkfVersion {
|
|
|
23
23
|
};
|
|
24
24
|
/** Compares numerically, major first, so `0.10` sorts after `0.9`. */
|
|
25
25
|
static compare = (a, b) => a.major !== b.major ? a.major < b.major ? -1 : 1 : a.minor === b.minor ? 0 : a.minor < b.minor ? -1 : 1;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* The version the bundle-root `index.md` declares, as written; `None` when there is no root index or no `okf_version`.
|
|
28
|
+
* An unquoted number is its source text (`0.10`, not `0.1`).
|
|
29
|
+
*/
|
|
27
30
|
static declared = (bundle) => Option.fromNullishOr(bundle.indexes.get("")?.okfVersion);
|
|
28
31
|
/** True when nothing is declared or the declared version parses and is 0.2 or earlier; an unparsable version reads as current. */
|
|
29
32
|
static allowsLegacyFallbacks = (declared) => Option.match(declared, {
|
package/OkfitConfig.js
CHANGED
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
import { ConfigFile, ConfigMerge } from "@effected/config-file";
|
|
2
2
|
import { TomlCodec } from "@effected/config-file/toml";
|
|
3
|
+
import { GitRef } from "@effected/git";
|
|
3
4
|
import { GlobPattern } from "@effected/glob";
|
|
4
5
|
import { HostedSchema } from "@effected/schemastore";
|
|
5
6
|
import { Duration, Effect, Option, Result, Schema, SchemaGetter, SchemaIssue, SchemaTransformation } from "effect";
|
|
6
7
|
import { Actor, ActorPattern } from "./Actor.js";
|
|
7
|
-
import {
|
|
8
|
+
import { LintLevel, LintTable } from "./LintTable.js";
|
|
9
|
+
import { Reference } from "./Reference.js";
|
|
10
|
+
import { RepoIdentity } from "./RepoIdentity.js";
|
|
8
11
|
|
|
9
12
|
// src/OkfitConfig.ts
|
|
10
|
-
/**
|
|
11
|
-
* Severity a lint rule is configured to. `"info"` extends spec 4.2's
|
|
12
|
-
* `off | warn | error` so the D-34 `info` defaults are expressible.
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
const LintLevel = Schema.Literals([
|
|
17
|
-
"off",
|
|
18
|
-
"info",
|
|
19
|
-
"warn",
|
|
20
|
-
"error"
|
|
21
|
-
]).annotate({
|
|
22
|
-
title: "Lint severity",
|
|
23
|
-
description: "off — never reported; info, warn, error — the diagnostic's rendered severity.",
|
|
24
|
-
"x-taplo": { docs: { enumValues: [
|
|
25
|
-
"Never reported.",
|
|
26
|
-
"Reported as information.",
|
|
27
|
-
"Reported as a warning.",
|
|
28
|
-
"Reported as an error."
|
|
29
|
-
] } }
|
|
30
|
-
});
|
|
31
13
|
const SHORT_DURATION_RE = /^(\d+)(h|d|w)$/;
|
|
32
14
|
const LONG_DURATION_RE = /^\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/;
|
|
33
15
|
const STALE_AFTER_PATTERN_RE = /^(?:\d+[hdw]|\d+(?:\.\d+)?\s+(?:nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?))$/u;
|
|
@@ -125,230 +107,6 @@ const TagDeclaration = Schema.Struct({ description: Schema.optionalKey(Schema.St
|
|
|
125
107
|
description: "One `[tags.<name>]` declaration."
|
|
126
108
|
});
|
|
127
109
|
/**
|
|
128
|
-
* The `[lint]` table: one optional `LintLevel` per lint code, snake_case (D-34).
|
|
129
|
-
* @public
|
|
130
|
-
*/
|
|
131
|
-
const LintTable = Schema.Struct({
|
|
132
|
-
broken_links: Schema.optionalKey(LintLevel.annotate({
|
|
133
|
-
title: "broken-links",
|
|
134
|
-
description: "A link in a concept's body or frontmatter does not resolve. Default \"warn\".",
|
|
135
|
-
default: "warn"
|
|
136
|
-
})),
|
|
137
|
-
missing_index: Schema.optionalKey(LintLevel.annotate({
|
|
138
|
-
title: "missing-index",
|
|
139
|
-
description: "A concept-holding directory has no index.md. Default \"warn\".",
|
|
140
|
-
default: "warn"
|
|
141
|
-
})),
|
|
142
|
-
unknown_type: Schema.optionalKey(LintLevel.annotate({
|
|
143
|
-
title: "unknown-type",
|
|
144
|
-
description: "A concept's type is not one of the config's declared [types.<Name>]. Default \"error\", off when no types are declared.",
|
|
145
|
-
default: "error"
|
|
146
|
-
})),
|
|
147
|
-
required_key_missing: Schema.optionalKey(LintLevel.annotate({
|
|
148
|
-
title: "required-key-missing",
|
|
149
|
-
description: "A concept is missing a frontmatter key its type or concepts.required requires. Default \"error\".",
|
|
150
|
-
default: "error"
|
|
151
|
-
})),
|
|
152
|
-
field_value_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
153
|
-
title: "field-value-unknown",
|
|
154
|
-
description: "A frontmatter field's value is not one of its declared values. Default \"error\".",
|
|
155
|
-
default: "error"
|
|
156
|
-
})),
|
|
157
|
-
require_verified_unmet: Schema.optionalKey(LintLevel.annotate({
|
|
158
|
-
title: "require-verified-unmet",
|
|
159
|
-
description: "A concept whose type sets require_verified = true carries no verified entry and is not a draft. Default \"error\".",
|
|
160
|
-
default: "error"
|
|
161
|
-
})),
|
|
162
|
-
verified_before_change: Schema.optionalKey(LintLevel.annotate({
|
|
163
|
-
title: "verified-before-change",
|
|
164
|
-
description: "A concept has verification events, but the ones at or after generated.at give a lower trust tier than all of them would: the content changed after it was verified (OKF 0.3 §5.3, \"verified before the last change\"). Draft, deprecated and unknown-status concepts are exempt. Default \"warn\".",
|
|
165
|
-
default: "warn"
|
|
166
|
-
})),
|
|
167
|
-
family_invalid: Schema.optionalKey(LintLevel.annotate({
|
|
168
|
-
title: "family-invalid",
|
|
169
|
-
description: `okfit's own ${INTEGRITY_KEY} family does not match its shape. Default "error".`,
|
|
170
|
-
default: "error"
|
|
171
|
-
})),
|
|
172
|
-
computation_runtime_missing: Schema.optionalKey(LintLevel.annotate({
|
|
173
|
-
title: "computation-runtime-missing",
|
|
174
|
-
description: "A referenced computation's runtime is not available. Default \"error\".",
|
|
175
|
-
default: "error"
|
|
176
|
-
})),
|
|
177
|
-
footnote_source_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
178
|
-
title: "footnote-source-unknown",
|
|
179
|
-
description: "A footnote's source does not resolve. Default \"warn\".",
|
|
180
|
-
default: "warn"
|
|
181
|
-
})),
|
|
182
|
-
footnote_undefined: Schema.optionalKey(LintLevel.annotate({
|
|
183
|
-
title: "footnote-undefined",
|
|
184
|
-
description: "A footnote reference has no matching definition line in the body. Default \"warn\".",
|
|
185
|
-
default: "warn"
|
|
186
|
-
})),
|
|
187
|
-
log_frontmatter: Schema.optionalKey(LintLevel.annotate({
|
|
188
|
-
title: "log-frontmatter",
|
|
189
|
-
description: "log.md carries frontmatter, which the spec reserves against. Default \"warn\".",
|
|
190
|
-
default: "warn"
|
|
191
|
-
})),
|
|
192
|
-
actor_prefix_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
193
|
-
title: "actor-prefix-unknown",
|
|
194
|
-
description: "An actor in generated.by, verified[].by or sources[].author uses a scheme other than human, team, process or a producer shape; it is accepted and read as non-human. Default \"info\".",
|
|
195
|
-
default: "info"
|
|
196
|
-
})),
|
|
197
|
-
actor_email: Schema.optionalKey(LintLevel.annotate({
|
|
198
|
-
title: "actor-email",
|
|
199
|
-
description: `An actor in generated.by, verified[].by, ${INTEGRITY_KEY}.verified.by or [actors].humans contains "@", so an email address or domain is stored in the bundle or its config. Use a human:<id> without the domain. Default "warn".`,
|
|
200
|
-
default: "warn"
|
|
201
|
-
})),
|
|
202
|
-
verified_actor_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
203
|
-
title: "verified-actor-unknown",
|
|
204
|
-
description: `A human verified[].by or ${INTEGRITY_KEY}.verified.by matches no entry of a non-empty [actors].humans. Silent when the list is empty. Default "warn".`,
|
|
205
|
-
default: "warn"
|
|
206
|
-
})),
|
|
207
|
-
legacy_timestamp: Schema.optionalKey(LintLevel.annotate({
|
|
208
|
-
title: "legacy-timestamp",
|
|
209
|
-
description: "A concept uses the legacy timestamp field instead of generated.at. Default \"info\".",
|
|
210
|
-
default: "info"
|
|
211
|
-
})),
|
|
212
|
-
config_unknown_key: Schema.optionalKey(LintLevel.annotate({
|
|
213
|
-
title: "config-unknown-key",
|
|
214
|
-
description: "The config file declares a top-level key the schema does not recognize. Default \"warn\".",
|
|
215
|
-
default: "warn"
|
|
216
|
-
})),
|
|
217
|
-
config_okf_version_stale: Schema.optionalKey(LintLevel.annotate({
|
|
218
|
-
title: "config-okf-version-stale",
|
|
219
|
-
description: "The config sets okf_version and the bundle-root index.md declares a different one; the index decides how the bundle reads, so the config value is stale. Default \"warn\".",
|
|
220
|
-
default: "warn"
|
|
221
|
-
})),
|
|
222
|
-
stale: Schema.optionalKey(LintLevel.annotate({
|
|
223
|
-
title: "stale",
|
|
224
|
-
description: "A concept is past its stale_after instant. Default \"info\".",
|
|
225
|
-
default: "info"
|
|
226
|
-
})),
|
|
227
|
-
walk_unreadable: Schema.optionalKey(LintLevel.annotate({
|
|
228
|
-
title: "walk-unreadable",
|
|
229
|
-
description: "A directory in the bundle could not be read while walking. Default \"warn\".",
|
|
230
|
-
default: "warn"
|
|
231
|
-
})),
|
|
232
|
-
frontmatter_missing: Schema.optionalKey(LintLevel.annotate({
|
|
233
|
-
title: "frontmatter-missing",
|
|
234
|
-
description: "A .md file other than index.md or log.md has no frontmatter, so it is not a concept and is skipped (OKF 0.3 §3.2). Default \"warn\".",
|
|
235
|
-
default: "warn"
|
|
236
|
-
})),
|
|
237
|
-
type_missing: Schema.optionalKey(LintLevel.annotate({
|
|
238
|
-
title: "type-missing",
|
|
239
|
-
description: "A .md file's frontmatter has no non-empty string type, so it is not a concept and is skipped (OKF 0.3 §3.2). Default \"warn\".",
|
|
240
|
-
default: "warn"
|
|
241
|
-
})),
|
|
242
|
-
symlink_escape: Schema.optionalKey(LintLevel.annotate({
|
|
243
|
-
title: "symlink-escape",
|
|
244
|
-
description: "A file in the bundle is a symbolic link whose target lies outside the bundle root; it is not read and not part of the bundle (OKF 0.3 §3.2). Default \"warn\".",
|
|
245
|
-
default: "warn"
|
|
246
|
-
})),
|
|
247
|
-
generated_at_drift: Schema.optionalKey(LintLevel.annotate({
|
|
248
|
-
title: "generated-at-drift",
|
|
249
|
-
description: "A committed concept's generated.at is missing or does not match its last body-changing commit, and is not otherwise authoritative (issue #19: a stamp recorded during the unchanged-body run survives a squash/rebase merge). Default \"warn\".",
|
|
250
|
-
default: "warn"
|
|
251
|
-
})),
|
|
252
|
-
verified_drift: Schema.optionalKey(LintLevel.annotate({
|
|
253
|
-
title: "verified-drift",
|
|
254
|
-
description: `A concept's latest human verification no longer covers its current content: the body or authored frontmatter changed since, the binding (${INTEGRITY_KEY}.verified) is missing, a later human entry is unbound, or the bound verifier is not in a non-empty [actors].humans. Draft and deprecated concepts are exempt, since okfit verify refuses them. A signal to re-verify, not a gate. Default "warn".`,
|
|
255
|
-
default: "warn"
|
|
256
|
-
})),
|
|
257
|
-
status_missing: Schema.optionalKey(LintLevel.annotate({
|
|
258
|
-
title: "status-missing",
|
|
259
|
-
description: "A concept carries neither status nor verified, so it silently reads as stable (issue #110). Off by default because the spec reads an absent status as stable; the software-project profile raises it to \"warn\".",
|
|
260
|
-
default: "off"
|
|
261
|
-
})),
|
|
262
|
-
source_resource_missing: Schema.optionalKey(LintLevel.annotate({
|
|
263
|
-
title: "source-resource-missing",
|
|
264
|
-
description: "A resource or sources[].resource path resolves neither in the bundle nor on disk relative to the concept (issue #106). Default \"warn\".",
|
|
265
|
-
default: "warn"
|
|
266
|
-
})),
|
|
267
|
-
resource_ignored: Schema.optionalKey(LintLevel.annotate({
|
|
268
|
-
title: "resource-ignored",
|
|
269
|
-
description: "A resource or sources[].resource path names a file that exists locally but is gitignored, so every other checkout sees it missing (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"error\".",
|
|
270
|
-
default: "error"
|
|
271
|
-
})),
|
|
272
|
-
resource_untracked: Schema.optionalKey(LintLevel.annotate({
|
|
273
|
-
title: "resource-untracked",
|
|
274
|
-
description: "A resource or sources[].resource path names a file that exists locally but git does not track yet; not raised once the file is staged (issue #279). Skipped outside a git repository and under --skip-provenance. Default \"warn\".",
|
|
275
|
-
default: "warn"
|
|
276
|
-
})),
|
|
277
|
-
resource_outside_project: Schema.optionalKey(LintLevel.annotate({
|
|
278
|
-
title: "resource-outside-project",
|
|
279
|
-
description: "A resource value resolves outside the project root, directly or through a symlink, so okfit never reads, stats or asks git about the target (okfit's repository check, not OKF). Default \"info\".",
|
|
280
|
-
default: "info"
|
|
281
|
-
})),
|
|
282
|
-
superseded_by_orphan: Schema.optionalKey(LintLevel.annotate({
|
|
283
|
-
title: "superseded-by-orphan",
|
|
284
|
-
description: "A concept carries superseded_by but its status is not deprecated; superseded_by has a meaning only with status: deprecated (OKF 0.3 §5.4). Default \"warn\".",
|
|
285
|
-
default: "warn"
|
|
286
|
-
})),
|
|
287
|
-
superseded_by_unresolved: Schema.optionalKey(LintLevel.annotate({
|
|
288
|
-
title: "superseded-by-unresolved",
|
|
289
|
-
description: "A deprecated concept's superseded_by resolves to an asset, an external value or the concept itself rather than a replacement concept (OKF 0.3 §5.4). A missing target is reported by broken-links. Default \"warn\".",
|
|
290
|
-
default: "warn"
|
|
291
|
-
})),
|
|
292
|
-
generated_missing: Schema.optionalKey(LintLevel.annotate({
|
|
293
|
-
title: "generated-missing",
|
|
294
|
-
description: "A concept has no generated block while actors.agent is configured, so okfit sync cannot stamp generated.at until the block exists (issue #73). Default \"warn\"; silent when actors.agent is unset.",
|
|
295
|
-
default: "warn"
|
|
296
|
-
})),
|
|
297
|
-
computation_missing: Schema.optionalKey(LintLevel.annotate({
|
|
298
|
-
title: "computation-missing",
|
|
299
|
-
description: "An Attested Computation has no computation: no computation key, and nothing in its Computation section that the bundle's OKF version reads as one (under 0.3 the first fenced block, §10.3; under 0.2 the text of a top-level section), so it is not attestable. Default \"warn\".",
|
|
300
|
-
default: "warn"
|
|
301
|
-
})),
|
|
302
|
-
generated_at_future: Schema.optionalKey(LintLevel.annotate({
|
|
303
|
-
title: "generated-at-future",
|
|
304
|
-
description: "A concept's generated.at is more than 5 minutes later than now, so no verification can count yet (OKF 0.3 §5.3) and okfit verify refuses it; okfit sync re-stamps it. Default \"warn\".",
|
|
305
|
-
default: "warn"
|
|
306
|
-
})),
|
|
307
|
-
publication_drift: Schema.optionalKey(LintLevel.annotate({
|
|
308
|
-
title: "publication-drift",
|
|
309
|
-
description: `A Publication's ${OKFIT_KEY_PREFIX}renders[].body is missing or no longer matches the current body of the concept it names, so the published page may restate stale facts. Default "warn".`,
|
|
310
|
-
default: "warn"
|
|
311
|
-
})),
|
|
312
|
-
publication_orphan: Schema.optionalKey(LintLevel.annotate({
|
|
313
|
-
title: "publication-orphan",
|
|
314
|
-
description: `A Publication's ${OKFIT_KEY_PREFIX}surface or ${OKFIT_KEY_PREFIX}renders[].path does not resolve to a concept, or ${OKFIT_KEY_PREFIX}renders is not a list of { path, body } entries. Default "error".`,
|
|
315
|
-
default: "error"
|
|
316
|
-
})),
|
|
317
|
-
surface_unmatched: Schema.optionalKey(LintLevel.annotate({
|
|
318
|
-
title: "surface-unmatched",
|
|
319
|
-
description: "A Surface's resource glob matches no file or directory; legitimate in a brand-new monorepo, so it only warns. Default \"warn\".",
|
|
320
|
-
default: "warn"
|
|
321
|
-
})),
|
|
322
|
-
index_metadata_invalid: Schema.optionalKey(LintLevel.annotate({
|
|
323
|
-
title: "index-metadata-invalid",
|
|
324
|
-
description: "The bundle-root index.md frontmatter carries an okf_version that is not a quoted <major>.<minor> string, or a title, description or license that is not a string; the value is read best-effort. Default \"warn\".",
|
|
325
|
-
default: "warn"
|
|
326
|
-
})),
|
|
327
|
-
entry_ignored: Schema.optionalKey(LintLevel.annotate({
|
|
328
|
-
title: "entry-ignored",
|
|
329
|
-
description: "An entry or mapping the spec defines (a sources, verified or parameters entry, generated) lacks a REQUIRED key or has one okfit cannot read, so it is ignored (OKF 0.3 §11.2 rule 3). Default \"warn\".",
|
|
330
|
-
default: "warn"
|
|
331
|
-
})),
|
|
332
|
-
value_malformed: Schema.optionalKey(LintLevel.annotate({
|
|
333
|
-
title: "value-malformed",
|
|
334
|
-
description: "A defined value okfit cannot read in its defined shape (wrong type, unparsable timestamp, malformed optional key) is read as absent; a malformed stale_after reads as malformed, never fresh (OKF 0.3 §5.5, §11.2). Default \"warn\".",
|
|
335
|
-
default: "warn"
|
|
336
|
-
})),
|
|
337
|
-
value_unknown: Schema.optionalKey(LintLevel.annotate({
|
|
338
|
-
title: "value-unknown",
|
|
339
|
-
description: "A defined key carries a value outside its vocabulary (today: status); the value is kept and the concept is not read as current knowledge (OKF 0.3 §5.4, §11.2 rule 4). Default \"warn\".",
|
|
340
|
-
default: "warn"
|
|
341
|
-
})),
|
|
342
|
-
non_concept_unlisted: Schema.optionalKey(LintLevel.annotate({
|
|
343
|
-
title: "non-concept-unlisted",
|
|
344
|
-
description: "A .md file is not a concept (no frontmatter, or no type) and matches no glob in [bundle] non_concepts. An okfit opinion, not OKF conformance (§3.2 allows such files). Silent when non_concepts is absent. Default \"warn\".",
|
|
345
|
-
default: "warn"
|
|
346
|
-
}))
|
|
347
|
-
}).annotate({
|
|
348
|
-
title: "Lint severities",
|
|
349
|
-
description: "Per-code severity overrides. Any key omitted keeps its default."
|
|
350
|
-
});
|
|
351
|
-
/**
|
|
352
110
|
* Scan a glob once, left to right, for a `[` or `{` that never closes; the
|
|
353
111
|
* result is the rejection message tail naming the opener, or `undefined` when
|
|
354
112
|
* none is left open. A backslash escapes the next character; a class closes at
|
|
@@ -379,6 +137,59 @@ const unclosedGlobMessage = (glob) => {
|
|
|
379
137
|
if (classStart >= 0) return `"[" opens a character class that never closes; to match a literal bracket write '\\[' in single quotes or "\\\\[" in double quotes`;
|
|
380
138
|
return depth > 0 ? `"{" opens a brace group that never closes; to match a literal brace write '\\{' in single quotes or "\\\\{" in double quotes` : void 0;
|
|
381
139
|
};
|
|
140
|
+
const nameSchema = (annotations) => Schema.String.annotate(annotations).check(Schema.isPattern(Reference.NAME_PATTERN)).check(Schema.makeFilter((value) => Reference.isValidName(value) || `Expected a name that is not a reserved URL scheme, got ${JSON.stringify(value)}`));
|
|
141
|
+
const NAME_DESCRIPTION = "a lower-case letter, then lower-case letters, digits or hyphens, two to 32 characters in all. A URL scheme such as http, https, git or file is reserved.";
|
|
142
|
+
const ReferenceName = nameSchema({
|
|
143
|
+
title: "Name",
|
|
144
|
+
description: `A bundle, checkout or reference name: ${NAME_DESCRIPTION}`,
|
|
145
|
+
examples: ["company", "kit"]
|
|
146
|
+
});
|
|
147
|
+
/**
|
|
148
|
+
* What an agent may do with a bundle or checkout.
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
const Access = Schema.Literals(["read", "read-write"]).annotate({
|
|
153
|
+
title: "Access",
|
|
154
|
+
description: "\"read\" lets an agent read the bundle; \"read-write\" also lets it write. A checkout may narrow what the repository allows, never widen it.",
|
|
155
|
+
examples: ["read", "read-write"]
|
|
156
|
+
});
|
|
157
|
+
const repoField = (title, description) => Schema.String.annotate({
|
|
158
|
+
title,
|
|
159
|
+
description,
|
|
160
|
+
examples: ["savvy-web/okf-sandbox", "https://github.com/savvy-web/company.git"]
|
|
161
|
+
}).check(Schema.makeFilter((value) => Option.isSome(RepoIdentity.normalize(value)) || `Expected a repository as "owner/name" (GitHub), "host/owner/name", or an https, ssh or scp URL (an owner containing a dot needs its host, as in gitlab.com/my.group/proj), got ${JSON.stringify(value)}`));
|
|
162
|
+
/**
|
|
163
|
+
* Why `value` holds a control character, or `undefined` when it holds none: a C0 character (newline, ESC and NUL
|
|
164
|
+
* included), DEL, a C1 character, or the line and paragraph separators U+2028 and U+2029. A path with one is never a
|
|
165
|
+
* real directory name here, and the agent plugin tells paths to a model, so a config must not carry one.
|
|
166
|
+
*/
|
|
167
|
+
const controlCharacterProblem = (value) => {
|
|
168
|
+
for (const char of value) {
|
|
169
|
+
const code = char.codePointAt(0);
|
|
170
|
+
if (code < 32 || code >= 127 && code <= 159 || code === 8232 || code === 8233) return `contains a control character (U+${code.toString(16).toUpperCase().padStart(4, "0")})`;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/** A string check refusing control characters, for a path key. */
|
|
174
|
+
const noControlCharacters = Schema.makeFilter((value) => {
|
|
175
|
+
const problem = controlCharacterProblem(value);
|
|
176
|
+
return problem === void 0 ? true : `Expected a path with no control characters, but ${JSON.stringify(value)} ${problem}`;
|
|
177
|
+
});
|
|
178
|
+
/** Why `value` cannot be where git fetches a checkout from, or `undefined`: everything else git accepts is allowed. */
|
|
179
|
+
const fetchUrlProblem = (value) => {
|
|
180
|
+
if (value.trim() === "") return "is empty";
|
|
181
|
+
if (value.startsWith("-")) return "starts with \"-\", which git would read as an option";
|
|
182
|
+
if (/^(ext|fd)::/i.test(value.trim())) return "uses a transport that runs a command (ext:: or fd::)";
|
|
183
|
+
};
|
|
184
|
+
/** Why `value` is not a directory inside a repository, or `undefined` when it is one. */
|
|
185
|
+
const repositoryPathProblem = (value) => {
|
|
186
|
+
if (value.trim() === "") return "is empty";
|
|
187
|
+
const control = controlCharacterProblem(value);
|
|
188
|
+
if (control !== void 0) return control;
|
|
189
|
+
if (value.includes("\\")) return "contains a backslash";
|
|
190
|
+
if (value.startsWith("/") || /^[A-Za-z]:/.test(value)) return "is absolute";
|
|
191
|
+
if (value.split("/").some((segment) => segment === ".." || segment === ".")) return "has a \".\" or \"..\" segment";
|
|
192
|
+
};
|
|
382
193
|
/**
|
|
383
194
|
* The `OkfitConfig` struct schema. Exported only so the `OkfitConfigFields`
|
|
384
195
|
* type below is reachable from the rollup; the barrel never re-exports this
|
|
@@ -391,13 +202,19 @@ const okfitConfigFields = Schema.Struct({
|
|
|
391
202
|
description: "The okf_version okfit writes into a bundle-root index.md that declares none (okfit init, okfit sync). The bundle's own declaration decides how it is read. When the root index.md declares a different version, the lint config-okf-version-stale reports this value as stale.",
|
|
392
203
|
examples: ["0.3"]
|
|
393
204
|
})),
|
|
205
|
+
repo: Schema.optionalKey(repoField("This repository", "The consumer's own repository as \"owner/name\" (GitHub) or a git URL. Falls back to the origin remote of the project root. Lets a reference to this repository resolve to the project root.")),
|
|
394
206
|
bundle: Schema.optionalKey(Schema.Struct({
|
|
207
|
+
name: Schema.optionalKey(nameSchema({
|
|
208
|
+
title: "Bundle name",
|
|
209
|
+
description: `The bundle's name, defaulting to the base name of the bundle directory: ${NAME_DESCRIPTION}`,
|
|
210
|
+
examples: ["patterns"]
|
|
211
|
+
})),
|
|
395
212
|
path: Schema.optionalKey(Schema.String.annotate({
|
|
396
213
|
title: "Bundle directory",
|
|
397
214
|
description: "The OKF bundle's root directory, relative to the project root.",
|
|
398
215
|
default: "okf",
|
|
399
216
|
examples: ["okf"]
|
|
400
|
-
})),
|
|
217
|
+
}).check(noControlCharacters)),
|
|
401
218
|
profile: Schema.optionalKey(Schema.String.annotate({
|
|
402
219
|
title: "Profile name",
|
|
403
220
|
description: "The named profile merged under `DEFAULTS < profile < file`, or \"none\" to disable profile merging.",
|
|
@@ -461,6 +278,132 @@ const okfitConfigFields = Schema.Struct({
|
|
|
461
278
|
title: "Tag declarations",
|
|
462
279
|
description: "One entry per tag, keyed by tag name."
|
|
463
280
|
})),
|
|
281
|
+
bundle_set: Schema.optionalKey(Schema.Struct({ discover: Schema.Array(Schema.String).annotate({
|
|
282
|
+
title: "Discovery globs",
|
|
283
|
+
description: "Globs, relative to the project root (the directory of this config file, or for a config at .config/okfit.toml the directory that holds .config, not .config itself), that name the okfit.toml of each bundle the repository holds.",
|
|
284
|
+
examples: [["*/okfit.toml"]]
|
|
285
|
+
}) }).annotate({
|
|
286
|
+
title: "Bundle set",
|
|
287
|
+
description: "How a knowledge repository finds the bundles it holds."
|
|
288
|
+
})),
|
|
289
|
+
bundles: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
|
|
290
|
+
path: Schema.String.annotate({
|
|
291
|
+
title: "Bundle path",
|
|
292
|
+
description: "The bundle's root directory, relative to this config file's directory.",
|
|
293
|
+
examples: ["../shared/okf"]
|
|
294
|
+
}).check(noControlCharacters),
|
|
295
|
+
access: Schema.optionalKey(Access)
|
|
296
|
+
}).annotate({
|
|
297
|
+
title: "Bundle",
|
|
298
|
+
description: "A bundle declared directly, with no checkout."
|
|
299
|
+
})).check(Schema.isPropertyNames(ReferenceName)).annotate({
|
|
300
|
+
title: "Bundles",
|
|
301
|
+
description: "Bundles declared directly, keyed by bundle name. Each carries its own okfit.toml."
|
|
302
|
+
})),
|
|
303
|
+
checkouts: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
|
|
304
|
+
repo: repoField("Checkout repository", "The repository this checkout holds."),
|
|
305
|
+
path: Schema.String.annotate({
|
|
306
|
+
title: "Checkout path",
|
|
307
|
+
description: "Where the checkout sits, relative to this config file's directory.",
|
|
308
|
+
examples: [".repos/company"]
|
|
309
|
+
}).check(noControlCharacters),
|
|
310
|
+
kind: Schema.optionalKey(Schema.Literals([
|
|
311
|
+
"submodule",
|
|
312
|
+
"clone",
|
|
313
|
+
"path"
|
|
314
|
+
]).annotate({
|
|
315
|
+
title: "Checkout kind",
|
|
316
|
+
description: "How the checkout is present: a git submodule, a separate clone, or a plain path.",
|
|
317
|
+
examples: ["submodule"]
|
|
318
|
+
})),
|
|
319
|
+
branch: Schema.optionalKey(Schema.String.annotate({
|
|
320
|
+
title: "Checkout branch",
|
|
321
|
+
description: "The remote branch a managed checkout follows. Absent: the remote's default branch. A git branch name, as `git check-ref-format --branch` accepts it: no ASCII space or control characters, no \"..\", no leading \"-\", none of ~ ^ : ? * [ \\, no leading or trailing \"/\", no trailing \".\" or \".lock\", no \"@{\"; \"HEAD\" is refused.",
|
|
322
|
+
examples: ["main", "release/1.x"]
|
|
323
|
+
}).check(GitRef.branchNameCheck)),
|
|
324
|
+
url: Schema.optionalKey(Schema.String.annotate({
|
|
325
|
+
title: "Checkout URL",
|
|
326
|
+
description: "Where to fetch the repository from, when that is not the https URL derived from `repo`: an ssh or scp address, a mirror, GitHub Enterprise, a local path or a file:// URL. `repo` stays the identity references resolve against. May not be empty, hold a control character, start with `-` or use the ext:: or fd:: transports. Not allowed on a submodule from the local config file.",
|
|
327
|
+
examples: ["git@github.com:owner/name.git"]
|
|
328
|
+
}).check(noControlCharacters).check(Schema.makeFilter((value) => {
|
|
329
|
+
const problem = fetchUrlProblem(value);
|
|
330
|
+
return problem === void 0 ? true : `Expected a fetch URL, but ${JSON.stringify(value)} ${problem}`;
|
|
331
|
+
}))),
|
|
332
|
+
bundles: Schema.optionalKey(Schema.Array(ReferenceName).annotate({
|
|
333
|
+
title: "Selected bundles",
|
|
334
|
+
description: "Which of the repository's bundles to take. Absent: every bundle its root config discovers.",
|
|
335
|
+
examples: [["patterns", "kit"]]
|
|
336
|
+
})),
|
|
337
|
+
access: Schema.optionalKey(Access),
|
|
338
|
+
purpose: Schema.optionalKey(Schema.String.annotate({
|
|
339
|
+
title: "Purpose",
|
|
340
|
+
description: "What this checkout is for, told to an agent at session start."
|
|
341
|
+
})),
|
|
342
|
+
layout: Schema.optionalKey(Schema.String.annotate({
|
|
343
|
+
title: "Layout",
|
|
344
|
+
description: "How the checkout is organised, told to an agent at session start."
|
|
345
|
+
})),
|
|
346
|
+
start_here: Schema.optionalKey(Schema.String.annotate({
|
|
347
|
+
title: "Start here",
|
|
348
|
+
description: "The first path an agent should read in this checkout."
|
|
349
|
+
}))
|
|
350
|
+
}).annotate({
|
|
351
|
+
title: "Checkout",
|
|
352
|
+
description: "A repository checkout that is present here."
|
|
353
|
+
})).check(Schema.isPropertyNames(ReferenceName)).annotate({
|
|
354
|
+
title: "Checkouts",
|
|
355
|
+
description: "Repository checkouts present here, keyed by name. A checkout states where a repository is."
|
|
356
|
+
})),
|
|
357
|
+
references: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
|
|
358
|
+
repo: repoField("Reference repository", "The repository the name stands for."),
|
|
359
|
+
path: Schema.optionalKey(Schema.String.annotate({
|
|
360
|
+
title: "Reference path",
|
|
361
|
+
description: "A relative directory inside that repository the name is rooted at: no leading \"/\", drive letter, backslash, \".\" or \"..\" segment.",
|
|
362
|
+
examples: ["kit"]
|
|
363
|
+
}).check(Schema.makeFilter((value) => {
|
|
364
|
+
const problem = repositoryPathProblem(value);
|
|
365
|
+
return problem === void 0 ? true : `Expected a relative directory inside the repository, but ${JSON.stringify(value)} ${problem}`;
|
|
366
|
+
})))
|
|
367
|
+
}).annotate({
|
|
368
|
+
title: "Reference",
|
|
369
|
+
description: "What a name: prefix means in this bundle."
|
|
370
|
+
})).check(Schema.isPropertyNames(ReferenceName)).annotate({
|
|
371
|
+
title: "Named references",
|
|
372
|
+
description: "Names a link or resource may use as name:path, keyed by name."
|
|
373
|
+
})),
|
|
374
|
+
contribute: Schema.optionalKey(Schema.Struct({
|
|
375
|
+
flow: Schema.optionalKey(Schema.Literals(["pull-request", "push"]).annotate({
|
|
376
|
+
title: "Contribution flow",
|
|
377
|
+
description: "How a change reaches this repository.",
|
|
378
|
+
examples: ["pull-request"]
|
|
379
|
+
})),
|
|
380
|
+
branch: Schema.optionalKey(Schema.String.annotate({
|
|
381
|
+
title: "Branch pattern",
|
|
382
|
+
description: "The branch a change is made on; {topic} stands for the change's topic.",
|
|
383
|
+
examples: ["okf/{topic}"]
|
|
384
|
+
})),
|
|
385
|
+
merge: Schema.optionalKey(Schema.Literals([
|
|
386
|
+
"auto-squash",
|
|
387
|
+
"squash",
|
|
388
|
+
"none"
|
|
389
|
+
]).annotate({
|
|
390
|
+
title: "Merge policy",
|
|
391
|
+
description: "How an accepted change is merged.",
|
|
392
|
+
examples: ["auto-squash"]
|
|
393
|
+
})),
|
|
394
|
+
signed: Schema.optionalKey(Schema.Boolean.annotate({
|
|
395
|
+
title: "Signed commits",
|
|
396
|
+
description: "Whether commits must be signed."
|
|
397
|
+
})),
|
|
398
|
+
needs_approval: Schema.optionalKey(Schema.Array(Schema.String).annotate({
|
|
399
|
+
title: "Approval globs",
|
|
400
|
+
description: "Globs of paths whose change needs human approval.",
|
|
401
|
+
examples: [[".github/**", "**/okfit.toml"]]
|
|
402
|
+
}))
|
|
403
|
+
}).annotate({
|
|
404
|
+
title: "Contribution policy",
|
|
405
|
+
description: "How to contribute to this knowledge repository."
|
|
406
|
+
})),
|
|
464
407
|
extensions: Schema.Record(Schema.String, Schema.Unknown)
|
|
465
408
|
});
|
|
466
409
|
/**
|
|
@@ -514,7 +457,13 @@ const SCHEMA_DIRECTIVE = `#:schema ${okfitConfigSchemaHost.$id}\n\n`;
|
|
|
514
457
|
*/
|
|
515
458
|
const okfitConfigDocumentFields = Schema.StructWithRest(Schema.Struct({
|
|
516
459
|
okf_version: okfitConfigFields.fields.okf_version,
|
|
460
|
+
repo: okfitConfigFields.fields.repo,
|
|
517
461
|
bundle: okfitConfigFields.fields.bundle,
|
|
462
|
+
bundle_set: okfitConfigFields.fields.bundle_set,
|
|
463
|
+
bundles: okfitConfigFields.fields.bundles,
|
|
464
|
+
checkouts: okfitConfigFields.fields.checkouts,
|
|
465
|
+
references: okfitConfigFields.fields.references,
|
|
466
|
+
contribute: okfitConfigFields.fields.contribute,
|
|
518
467
|
concepts: okfitConfigFields.fields.concepts,
|
|
519
468
|
lifecycle: okfitConfigFields.fields.lifecycle,
|
|
520
469
|
actors: okfitConfigFields.fields.actors,
|
|
@@ -569,6 +518,7 @@ const LINT_KEY = {
|
|
|
569
518
|
"config-okf-version-stale": "config_okf_version_stale",
|
|
570
519
|
stale: "stale",
|
|
571
520
|
"walk-unreadable": "walk_unreadable",
|
|
521
|
+
"read-changed": "read_changed",
|
|
572
522
|
"generated-at-drift": "generated_at_drift",
|
|
573
523
|
"verified-drift": "verified_drift",
|
|
574
524
|
"status-missing": "status_missing",
|
|
@@ -591,7 +541,14 @@ const LINT_KEY = {
|
|
|
591
541
|
"frontmatter-missing": "frontmatter_missing",
|
|
592
542
|
"type-missing": "type_missing",
|
|
593
543
|
"symlink-escape": "symlink_escape",
|
|
594
|
-
"non-concept-unlisted": "non_concept_unlisted"
|
|
544
|
+
"non-concept-unlisted": "non_concept_unlisted",
|
|
545
|
+
"reference-not-mounted": "reference_not_mounted",
|
|
546
|
+
"reference-missing": "reference_missing",
|
|
547
|
+
"reference-undeclared": "reference_undeclared",
|
|
548
|
+
"reference-local-only": "reference_local_only",
|
|
549
|
+
"config-misplaced-key": "config_misplaced_key",
|
|
550
|
+
"config-local-tracked": "config_local_tracked",
|
|
551
|
+
"bundle-config-invalid": "bundle_config_invalid"
|
|
595
552
|
};
|
|
596
553
|
const DEFAULT_LINT = {
|
|
597
554
|
broken_links: "warn",
|
|
@@ -614,6 +571,7 @@ const DEFAULT_LINT = {
|
|
|
614
571
|
config_okf_version_stale: "warn",
|
|
615
572
|
stale: "info",
|
|
616
573
|
walk_unreadable: "warn",
|
|
574
|
+
read_changed: "warn",
|
|
617
575
|
generated_at_drift: "warn",
|
|
618
576
|
verified_drift: "warn",
|
|
619
577
|
status_missing: "off",
|
|
@@ -636,7 +594,14 @@ const DEFAULT_LINT = {
|
|
|
636
594
|
frontmatter_missing: "warn",
|
|
637
595
|
type_missing: "warn",
|
|
638
596
|
symlink_escape: "warn",
|
|
639
|
-
non_concept_unlisted: "warn"
|
|
597
|
+
non_concept_unlisted: "warn",
|
|
598
|
+
reference_not_mounted: "info",
|
|
599
|
+
reference_missing: "warn",
|
|
600
|
+
reference_undeclared: "warn",
|
|
601
|
+
reference_local_only: "info",
|
|
602
|
+
config_misplaced_key: "warn",
|
|
603
|
+
config_local_tracked: "warn",
|
|
604
|
+
bundle_config_invalid: "error"
|
|
640
605
|
};
|
|
641
606
|
const toSeverity = (level) => level === "warn" ? "warning" : level;
|
|
642
607
|
const severityFor = (config, code) => {
|
|
@@ -711,4 +676,4 @@ const OkfitConfig = Object.assign(OkfitConfigWire, {
|
|
|
711
676
|
*/
|
|
712
677
|
var OkfitConfigFile = class extends ConfigFile.Service()("@okfit/core/OkfitConfigFile") {};
|
|
713
678
|
|
|
714
|
-
export { CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigFields, okfitConfigSchemaHost };
|
|
679
|
+
export { Access, CONFIG_SCHEMA_VERSION, FieldDeclaration, LintLevel, LintTable, OkfitConfig, OkfitConfigFile, SCHEMA_DIRECTIVE, StaleAfterDuration, TagDeclaration, TypeDeclaration, okfitConfigDocumentFields, okfitConfigFields, okfitConfigSchemaHost };
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ const program = Effect.gen(function* () {
|
|
|
25
25
|
|
|
26
26
|
`Derive.trustTier` follows OKF 0.3 §5.3 and §7: only current verification events count (`at` equal to or later than `generated.at`, or any event when `generated` or `generated.at` is absent), and only a `human:` verifier gives `human-reviewed`; `team:` and other schemes give `machine-confirmed`. This holds for every bundle whatever `okf_version` it declares. `Derive.isCurrent` and `Derive.currentVerifications` expose the rule, and the `verified-before-change` lint (default `warn`) reports a concept that has a `generated.at` and whose tier dropped because its verification predates it (draft, deprecated and unknown-status concepts are exempt).
|
|
27
27
|
|
|
28
|
-
`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`. `[bundle] non_concepts` globs must compile, and a `[` or `{` that never closes is rejected at decode (to match the character write '\[' in single quotes or "\\[" in double quotes). `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 `@okfit/engine`'s `lib/configs/schemastore.config.ts` builds the published JSON Schema (`schemas/1.0/config.json`) from via `effected schema`, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The document's `HostedSchema` identity (`okfitConfigSchemaHost`, the same `$id` `okfit init` stamps into a fresh config's `#:schema` directive) lives in `@okfit/engine`, not here — core stays free of a runtime `@effected/schemastore` dependency. The `[lint]` table's forty-
|
|
28
|
+
`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`. `[bundle] non_concepts` globs must compile, and a `[` or `{` that never closes is rejected at decode (to match the character write '\[' in single quotes or "\\[" in double quotes). `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 `@okfit/engine`'s `lib/configs/schemastore.config.ts` builds the published JSON Schema (`schemas/1.0/config.json`) from via `effected schema`, and carries no annotations of its own beyond what each field already declares in `OkfitConfig.ts`. The document's `HostedSchema` identity (`okfitConfigSchemaHost`, the same `$id` `okfit init` stamps into a fresh config's `#:schema` directive) lives in `@okfit/engine`, not here — core stays free of a runtime `@effected/schemastore` dependency. The `[lint]` table's forty-four 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.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/Reference.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
|
|
3
|
+
// src/Reference.ts
|
|
4
|
+
/**
|
|
5
|
+
* Named-reference parsing: `name:path` where `name` is a declared reference root.
|
|
6
|
+
* URL schemes are reserved so a link such as `https://x.dev` is never read as a reference. @public
|
|
7
|
+
*/
|
|
8
|
+
var Reference = class Reference {
|
|
9
|
+
constructor() {}
|
|
10
|
+
/** URL schemes a reference name may not take. */
|
|
11
|
+
static RESERVED_SCHEMES = /* @__PURE__ */ new Set([
|
|
12
|
+
"http",
|
|
13
|
+
"https",
|
|
14
|
+
"ftp",
|
|
15
|
+
"file",
|
|
16
|
+
"mailto",
|
|
17
|
+
"git",
|
|
18
|
+
"ssh",
|
|
19
|
+
"data",
|
|
20
|
+
"urn",
|
|
21
|
+
"tel",
|
|
22
|
+
"ws",
|
|
23
|
+
"wss",
|
|
24
|
+
"about",
|
|
25
|
+
"javascript",
|
|
26
|
+
"magnet",
|
|
27
|
+
"sms",
|
|
28
|
+
"geo",
|
|
29
|
+
"npm",
|
|
30
|
+
"doi",
|
|
31
|
+
"blob",
|
|
32
|
+
"chrome",
|
|
33
|
+
"vscode",
|
|
34
|
+
"slack",
|
|
35
|
+
"irc",
|
|
36
|
+
"xmpp",
|
|
37
|
+
"sip",
|
|
38
|
+
"news",
|
|
39
|
+
"ldap",
|
|
40
|
+
"s3",
|
|
41
|
+
"gs",
|
|
42
|
+
"jar",
|
|
43
|
+
"view-source"
|
|
44
|
+
]);
|
|
45
|
+
/**
|
|
46
|
+
* The shape of a valid name, as a Unicode-mode RegExp so a JSON Schema `pattern` can be derived from it.
|
|
47
|
+
* The reserved schemes are excluded separately, by {@link Reference.isValidName}.
|
|
48
|
+
*/
|
|
49
|
+
static NAME_PATTERN = /^[a-z][a-z0-9-]{1,31}$/u;
|
|
50
|
+
/** Lower-case letter first, then letters, digits or hyphens, two to 32 characters, not reserved; two characters minimum so a drive letter is never a name. */
|
|
51
|
+
static isValidName = (name) => Reference.NAME_PATTERN.test(name) && !Reference.RESERVED_SCHEMES.has(name);
|
|
52
|
+
/** `Some` only when the text before the first `:` is a declared name and the rest does not start with `//`. */
|
|
53
|
+
static parse = (value, names) => {
|
|
54
|
+
const colon = value.indexOf(":");
|
|
55
|
+
if (colon < 0) return Option.none();
|
|
56
|
+
const name = value.slice(0, colon);
|
|
57
|
+
const path = value.slice(colon + 1);
|
|
58
|
+
return names.has(name) && !path.startsWith("//") ? Option.some({
|
|
59
|
+
name,
|
|
60
|
+
path
|
|
61
|
+
}) : Option.none();
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { Reference };
|