@cavelang/core 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/README.md +76 -0
- package/dist/src/claim.d.ts +108 -0
- package/dist/src/claim.d.ts.map +1 -0
- package/dist/src/claim.js +65 -0
- package/dist/src/claim.js.map +1 -0
- package/dist/src/confidence.d.ts +26 -0
- package/dist/src/confidence.d.ts.map +1 -0
- package/dist/src/confidence.js +34 -0
- package/dist/src/confidence.js.map +1 -0
- package/dist/src/context.d.ts +26 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/context.js +31 -0
- package/dist/src/context.js.map +1 -0
- package/dist/src/entity.d.ts +26 -0
- package/dist/src/entity.d.ts.map +1 -0
- package/dist/src/entity.js +41 -0
- package/dist/src/entity.js.map +1 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/key.d.ts +28 -0
- package/dist/src/key.d.ts.map +1 -0
- package/dist/src/key.js +49 -0
- package/dist/src/key.js.map +1 -0
- package/dist/src/multiplier.d.ts +17 -0
- package/dist/src/multiplier.d.ts.map +1 -0
- package/dist/src/multiplier.js +19 -0
- package/dist/src/multiplier.js.map +1 -0
- package/dist/src/tag.d.ts +29 -0
- package/dist/src/tag.d.ts.map +1 -0
- package/dist/src/tag.js +28 -0
- package/dist/src/tag.js.map +1 -0
- package/dist/src/uncertainty.d.ts +21 -0
- package/dist/src/uncertainty.d.ts.map +1 -0
- package/dist/src/uncertainty.js +26 -0
- package/dist/src/uncertainty.js.map +1 -0
- package/dist/src/uuidv7.d.ts +28 -0
- package/dist/src/uuidv7.d.ts.map +1 -0
- package/dist/src/uuidv7.js +69 -0
- package/dist/src/uuidv7.js.map +1 -0
- package/dist/src/value.d.ts +57 -0
- package/dist/src/value.d.ts.map +1 -0
- package/dist/src/value.js +104 -0
- package/dist/src/value.js.map +1 -0
- package/dist/src/verb.d.ts +47 -0
- package/dist/src/verb.d.ts.map +1 -0
- package/dist/src/verb.js +55 -0
- package/dist/src/verb.js.map +1 -0
- package/package.json +39 -0
- package/src/claim.ts +148 -0
- package/src/confidence.ts +42 -0
- package/src/context.ts +43 -0
- package/src/entity.ts +49 -0
- package/src/index.ts +23 -0
- package/src/key.ts +55 -0
- package/src/multiplier.ts +28 -0
- package/src/tag.ts +42 -0
- package/src/uncertainty.ts +29 -0
- package/src/uuidv7.ts +76 -0
- package/src/value.ts +138 -0
- package/src/verb.ts +78 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric multipliers (spec §7.1).
|
|
3
|
+
*
|
|
4
|
+
* A multiplier is a single uppercase letter glued to a number: `20B`, `900M`,
|
|
5
|
+
* `1.5T`, `10K`. It scales the numeric value during canonicalization
|
|
6
|
+
* (spec §13.4 step 8: `20B` → `20000000000`); the raw text is preserved.
|
|
7
|
+
*/
|
|
8
|
+
/** Scale factor per multiplier letter. */
|
|
9
|
+
export const factors = {
|
|
10
|
+
T: 1e12,
|
|
11
|
+
B: 1e9,
|
|
12
|
+
M: 1e6,
|
|
13
|
+
K: 1e3
|
|
14
|
+
};
|
|
15
|
+
/** @returns `true` if `s` is exactly one multiplier letter. */
|
|
16
|
+
export const is = (s) => s === 'T' || s === 'B' || s === 'M' || s === 'K';
|
|
17
|
+
/** @returns scale factor of multiplier. */
|
|
18
|
+
export const factor = (m) => factors[m];
|
|
19
|
+
//# sourceMappingURL=multiplier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplier.js","sourceRoot":"","sources":["../../src/multiplier.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,OAAO,GAAyC;IAC3D,CAAC,EAAE,IAAI;IACP,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;CACP,CAAA;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAS,EAAmB,EAAE,CAC/C,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAA;AAElD,2CAA2C;AAC3C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAa,EAAU,EAAE,CAC9C,OAAO,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags — flat `#tag` and scoped `#key:value` (spec §6.2).
|
|
3
|
+
*
|
|
4
|
+
* A flat `#security` is `key=security, value=undefined`; a scoped
|
|
5
|
+
* `#topic:auth-security` splits on the first `:`. Scoped tags subsume flat
|
|
6
|
+
* tags — a flat `#tag` is simply a tag with null value.
|
|
7
|
+
*
|
|
8
|
+
* Tags classify the claim, not the entity, and carry no independent belief
|
|
9
|
+
* history (the two-lane rule, spec §11.1).
|
|
10
|
+
*/
|
|
11
|
+
export type Tag = {
|
|
12
|
+
readonly key: string;
|
|
13
|
+
/** `undefined` for flat tags; spec stores NULL (spec §13.2). */
|
|
14
|
+
readonly value?: string;
|
|
15
|
+
};
|
|
16
|
+
export type t = Tag;
|
|
17
|
+
/** @returns tag from key and optional scoped value. */
|
|
18
|
+
export declare const of: (key: string, value?: string) => Tag;
|
|
19
|
+
/**
|
|
20
|
+
* Splits a tag body (without the leading `#`) on the first `:`
|
|
21
|
+
* (spec §6.2 disambiguation): `topic:auth-security` → scoped,
|
|
22
|
+
* `security` → flat.
|
|
23
|
+
*/
|
|
24
|
+
export declare const parse: (body: string) => Tag;
|
|
25
|
+
/** @returns canonical `#key[:value]` text. */
|
|
26
|
+
export declare const format: (tag: Tag) => string;
|
|
27
|
+
/** @returns `true` when both tags have the same key and value. */
|
|
28
|
+
export declare const equals: (a: Tag, b: Tag) => boolean;
|
|
29
|
+
//# sourceMappingURL=tag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../src/tag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,GAAG,GAAG;IAChB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,CAAC,GAAG,GAAG,CAAA;AAEnB,uDAAuD;AACvD,eAAO,MAAM,EAAE,GAAI,KAAK,MAAM,EAAE,QAAQ,MAAM,KAAG,GACD,CAAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,KAAG,GAKpC,CAAA;AAED,8CAA8C;AAC9C,eAAO,MAAM,MAAM,GAAI,KAAK,GAAG,KAAG,MACoC,CAAA;AAEtE,kEAAkE;AAClE,eAAO,MAAM,MAAM,GAAI,GAAG,GAAG,EAAE,GAAG,GAAG,KAAG,OACA,CAAA"}
|
package/dist/src/tag.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags — flat `#tag` and scoped `#key:value` (spec §6.2).
|
|
3
|
+
*
|
|
4
|
+
* A flat `#security` is `key=security, value=undefined`; a scoped
|
|
5
|
+
* `#topic:auth-security` splits on the first `:`. Scoped tags subsume flat
|
|
6
|
+
* tags — a flat `#tag` is simply a tag with null value.
|
|
7
|
+
*
|
|
8
|
+
* Tags classify the claim, not the entity, and carry no independent belief
|
|
9
|
+
* history (the two-lane rule, spec §11.1).
|
|
10
|
+
*/
|
|
11
|
+
/** @returns tag from key and optional scoped value. */
|
|
12
|
+
export const of = (key, value) => value === undefined ? { key } : { key, value };
|
|
13
|
+
/**
|
|
14
|
+
* Splits a tag body (without the leading `#`) on the first `:`
|
|
15
|
+
* (spec §6.2 disambiguation): `topic:auth-security` → scoped,
|
|
16
|
+
* `security` → flat.
|
|
17
|
+
*/
|
|
18
|
+
export const parse = (body) => {
|
|
19
|
+
const colonAt = body.indexOf(':');
|
|
20
|
+
return colonAt === -1 ?
|
|
21
|
+
{ key: body } :
|
|
22
|
+
{ key: body.slice(0, colonAt), value: body.slice(colonAt + 1) };
|
|
23
|
+
};
|
|
24
|
+
/** @returns canonical `#key[:value]` text. */
|
|
25
|
+
export const format = (tag) => tag.value === undefined ? `#${tag.key}` : `#${tag.key}:${tag.value}`;
|
|
26
|
+
/** @returns `true` when both tags have the same key and value. */
|
|
27
|
+
export const equals = (a, b) => a.key === b.key && a.value === b.value;
|
|
28
|
+
//# sourceMappingURL=tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../src/tag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,uDAAuD;AACvD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAW,EAAE,KAAc,EAAO,EAAE,CACrD,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAO,EAAE;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QACf,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,CAAA;AACnE,CAAC,CAAA;AAED,8CAA8C;AAC9C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAQ,EAAU,EAAE,CACzC,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,CAAA;AAEtE,kEAAkE;AAClE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAM,EAAE,CAAM,EAAW,EAAE,CAChD,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value uncertainty — `+/- delta [(Nσ)]` (spec §7.2).
|
|
3
|
+
*
|
|
4
|
+
* `+/-` defines a symmetric interval around the value; the default
|
|
5
|
+
* interpretation is 2σ (≈95% interval). If the interval is Δ at kσ then
|
|
6
|
+
* σ = Δ / k:
|
|
7
|
+
*
|
|
8
|
+
* - `20B +/- 2B` → σ = 1B (default 2σ)
|
|
9
|
+
* - `20B +/- 2B (1σ)` → σ = 2B (wider)
|
|
10
|
+
* - `20B +/- 2B (3σ)` → σ ≈ 0.67B (tighter)
|
|
11
|
+
*
|
|
12
|
+
* Value uncertainty is aleatory (the quantity itself is imprecise) and is
|
|
13
|
+
* independent of epistemic claim confidence `@ N%` (spec §7.3).
|
|
14
|
+
*/
|
|
15
|
+
/** Default σ level when `(Nσ)` is omitted (spec §7.2). */
|
|
16
|
+
export declare const defaultSigmaLevel = 2;
|
|
17
|
+
/** @returns σ from an interval `delta` given at `level`σ: σ = Δ / k. */
|
|
18
|
+
export declare const sigma: (delta: number, level?: number) => number;
|
|
19
|
+
/** @returns symmetric `[low, high]` interval around `mean`. */
|
|
20
|
+
export declare const interval: (mean: number, delta: number) => [number, number];
|
|
21
|
+
//# sourceMappingURL=uncertainty.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertainty.d.ts","sourceRoot":"","sources":["../../src/uncertainty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAElC,wEAAwE;AACxE,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,EAAE,QAAO,MAA0B,KAAG,MAKxE,CAAA;AAED,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CACxC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value uncertainty — `+/- delta [(Nσ)]` (spec §7.2).
|
|
3
|
+
*
|
|
4
|
+
* `+/-` defines a symmetric interval around the value; the default
|
|
5
|
+
* interpretation is 2σ (≈95% interval). If the interval is Δ at kσ then
|
|
6
|
+
* σ = Δ / k:
|
|
7
|
+
*
|
|
8
|
+
* - `20B +/- 2B` → σ = 1B (default 2σ)
|
|
9
|
+
* - `20B +/- 2B (1σ)` → σ = 2B (wider)
|
|
10
|
+
* - `20B +/- 2B (3σ)` → σ ≈ 0.67B (tighter)
|
|
11
|
+
*
|
|
12
|
+
* Value uncertainty is aleatory (the quantity itself is imprecise) and is
|
|
13
|
+
* independent of epistemic claim confidence `@ N%` (spec §7.3).
|
|
14
|
+
*/
|
|
15
|
+
/** Default σ level when `(Nσ)` is omitted (spec §7.2). */
|
|
16
|
+
export const defaultSigmaLevel = 2;
|
|
17
|
+
/** @returns σ from an interval `delta` given at `level`σ: σ = Δ / k. */
|
|
18
|
+
export const sigma = (delta, level = defaultSigmaLevel) => {
|
|
19
|
+
if (!(level > 0)) {
|
|
20
|
+
throw new Error(`Expected positive sigma level, got ${level}.`);
|
|
21
|
+
}
|
|
22
|
+
return delta / level;
|
|
23
|
+
};
|
|
24
|
+
/** @returns symmetric `[low, high]` interval around `mean`. */
|
|
25
|
+
export const interval = (mean, delta) => [mean - delta, mean + delta];
|
|
26
|
+
//# sourceMappingURL=uncertainty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uncertainty.js","sourceRoot":"","sources":["../../src/uncertainty.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAElC,wEAAwE;AACxE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,QAAgB,iBAAiB,EAAU,EAAE;IAChF,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,GAAG,CAAC,CAAA;IACjE,CAAC;IACD,OAAO,KAAK,GAAG,KAAK,CAAA;AACtB,CAAC,CAAA;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,KAAa,EAAoB,EAAE,CACxE,CAAC,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUIDv7 transaction identifiers (spec §9.1).
|
|
3
|
+
*
|
|
4
|
+
* CAVE storage is append-only; each appended claim carries a transaction id.
|
|
5
|
+
* UUIDv7 is recommended because it encodes timestamp and ordering — ids sort
|
|
6
|
+
* lexicographically by creation time, so `MAX(tx)` resolves current belief.
|
|
7
|
+
*
|
|
8
|
+
* {@link next} is strictly monotonic within a process: same-millisecond calls
|
|
9
|
+
* increment a 12-bit sequence in the `rand_a` field, and a backwards system
|
|
10
|
+
* clock never produces a smaller id.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Formats a UUIDv7 from parts — pure, for tests and deterministic imports.
|
|
14
|
+
*
|
|
15
|
+
* @param ms unix timestamp in milliseconds (48 bits)
|
|
16
|
+
* @param seq 12-bit sequence placed in `rand_a`
|
|
17
|
+
* @param rand 62 bits of randomness for `rand_b` as 8 bytes (top 2 bits are
|
|
18
|
+
* overwritten by the variant)
|
|
19
|
+
*/
|
|
20
|
+
export declare const at: (ms: number, seq: number, rand: Uint8Array) => string;
|
|
21
|
+
/**
|
|
22
|
+
* @returns next monotonic UUIDv7. Strictly increasing (lexicographically)
|
|
23
|
+
* within the process even across same-millisecond calls and clock skew.
|
|
24
|
+
*/
|
|
25
|
+
export declare const next: (now?: () => number) => string;
|
|
26
|
+
/** @returns `true` if `s` is a well-formed UUIDv7 string. */
|
|
27
|
+
export declare const is: (s: string) => boolean;
|
|
28
|
+
//# sourceMappingURL=uuidv7.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuidv7.d.ts","sourceRoot":"","sources":["../../src/uuidv7.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH;;;;;;;GAOG;AACH,eAAO,MAAM,EAAE,GAAI,IAAI,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,KAAG,MAmB9D,CAAA;AAKD;;;GAGG;AACH,eAAO,MAAM,IAAI,GAAI,MAAK,MAAM,MAAiB,KAAG,MAgBnD,CAAA;AAID,6DAA6D;AAC7D,eAAO,MAAM,EAAE,GAAI,GAAG,MAAM,KAAG,OACf,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUIDv7 transaction identifiers (spec §9.1).
|
|
3
|
+
*
|
|
4
|
+
* CAVE storage is append-only; each appended claim carries a transaction id.
|
|
5
|
+
* UUIDv7 is recommended because it encodes timestamp and ordering — ids sort
|
|
6
|
+
* lexicographically by creation time, so `MAX(tx)` resolves current belief.
|
|
7
|
+
*
|
|
8
|
+
* {@link next} is strictly monotonic within a process: same-millisecond calls
|
|
9
|
+
* increment a 12-bit sequence in the `rand_a` field, and a backwards system
|
|
10
|
+
* clock never produces a smaller id.
|
|
11
|
+
*/
|
|
12
|
+
import { randomFillSync } from 'node:crypto';
|
|
13
|
+
const hex = (n, digits) => n.toString(16).padStart(digits, '0');
|
|
14
|
+
/**
|
|
15
|
+
* Formats a UUIDv7 from parts — pure, for tests and deterministic imports.
|
|
16
|
+
*
|
|
17
|
+
* @param ms unix timestamp in milliseconds (48 bits)
|
|
18
|
+
* @param seq 12-bit sequence placed in `rand_a`
|
|
19
|
+
* @param rand 62 bits of randomness for `rand_b` as 8 bytes (top 2 bits are
|
|
20
|
+
* overwritten by the variant)
|
|
21
|
+
*/
|
|
22
|
+
export const at = (ms, seq, rand) => {
|
|
23
|
+
if (!Number.isInteger(ms) || ms < 0 || ms > 0xffff_ffff_ffff) {
|
|
24
|
+
throw new Error(`Expected 48-bit millisecond timestamp, got ${ms}.`);
|
|
25
|
+
}
|
|
26
|
+
if (!Number.isInteger(seq) || seq < 0 || seq > 0xfff) {
|
|
27
|
+
throw new Error(`Expected 12-bit sequence, got ${seq}.`);
|
|
28
|
+
}
|
|
29
|
+
if (rand.length < 8) {
|
|
30
|
+
throw new Error(`Expected 8 random bytes, got ${rand.length}.`);
|
|
31
|
+
}
|
|
32
|
+
const time = hex(ms, 12);
|
|
33
|
+
const variantByte = (rand[0] & 0x3f) | 0x80;
|
|
34
|
+
return [
|
|
35
|
+
time.slice(0, 8),
|
|
36
|
+
time.slice(8, 12),
|
|
37
|
+
`7${hex(seq, 3)}`,
|
|
38
|
+
hex(variantByte, 2) + hex(rand[1], 2),
|
|
39
|
+
[...rand.slice(2, 8)].map(byte => hex(byte, 2)).join('')
|
|
40
|
+
].join('-');
|
|
41
|
+
};
|
|
42
|
+
let lastMs = -1;
|
|
43
|
+
let lastSeq = 0;
|
|
44
|
+
/**
|
|
45
|
+
* @returns next monotonic UUIDv7. Strictly increasing (lexicographically)
|
|
46
|
+
* within the process even across same-millisecond calls and clock skew.
|
|
47
|
+
*/
|
|
48
|
+
export const next = (now = Date.now) => {
|
|
49
|
+
let ms = now();
|
|
50
|
+
if (ms <= lastMs) {
|
|
51
|
+
ms = lastMs;
|
|
52
|
+
lastSeq += 1;
|
|
53
|
+
if (lastSeq > 0xfff) {
|
|
54
|
+
ms += 1;
|
|
55
|
+
lastSeq = 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
lastSeq = 0;
|
|
60
|
+
}
|
|
61
|
+
lastMs = ms;
|
|
62
|
+
const rand = new Uint8Array(8);
|
|
63
|
+
randomFillSync(rand);
|
|
64
|
+
return at(ms, lastSeq, rand);
|
|
65
|
+
};
|
|
66
|
+
const uuidRe = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
67
|
+
/** @returns `true` if `s` is a well-formed UUIDv7 string. */
|
|
68
|
+
export const is = (s) => uuidRe.test(s);
|
|
69
|
+
//# sourceMappingURL=uuidv7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuidv7.js","sourceRoot":"","sources":["../../src/uuidv7.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,MAAc,EAAU,EAAE,CAChD,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAU,EAAE,GAAW,EAAE,IAAgB,EAAU,EAAE;IACtE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,gBAAgB,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,8CAA8C,EAAE,GAAG,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,KAAK,EAAE,CAAC;QACrD,MAAM,IAAI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pB,EAAE,IAAI,CAAC,CAAA;YACP,OAAO,GAAG,CAAC,CAAA;QACb,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,CAAC,CAAA;IACb,CAAC;IACD,MAAM,GAAG,EAAE,CAAA;IACX,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;IAC9B,cAAc,CAAC,IAAI,CAAC,CAAA;IACpB,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AAC9B,CAAC,CAAA;AAED,MAAM,MAAM,GAAG,uEAAuE,CAAA;AAEtF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAS,EAAW,EAAE,CACvC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values, units and multipliers (spec §7.1).
|
|
3
|
+
*
|
|
4
|
+
* A value is the payload of an attribute claim (`HAS attr: value`), a metric
|
|
5
|
+
* claim (`metric IS value`), or a `+/-` uncertainty delta. Parsing keeps the
|
|
6
|
+
* raw text verbatim and additionally extracts a normalized numeric value and
|
|
7
|
+
* unit when possible (spec §13.4 steps 7–9):
|
|
8
|
+
*
|
|
9
|
+
* - `30ms` → num 30, unit `ms`
|
|
10
|
+
* - `20B USD/yr` → num 20000000000, unit `USD/yr`
|
|
11
|
+
* - `~20B USD/yr` → the same, `approx` set
|
|
12
|
+
* - `94.5%` → num 94.5, unit `%`
|
|
13
|
+
* - `20 conn` → num 20, unit `conn`
|
|
14
|
+
* - `2026-H2` → date-like, kept textual
|
|
15
|
+
* - `token-expiry` → atom, kept textual
|
|
16
|
+
*
|
|
17
|
+
* Quoted (`"..."`) and backticked (`` `...` ``) values arrive from the parser
|
|
18
|
+
* with their kind already known; use {@link ofText} / {@link ofCode}.
|
|
19
|
+
*/
|
|
20
|
+
/** How the value text was classified. */
|
|
21
|
+
export type Kind = 'number' | 'date' | 'atom' | 'text' | 'code';
|
|
22
|
+
export type Value = {
|
|
23
|
+
/** Exactly as written, including `~` and multiplier letter. */
|
|
24
|
+
readonly raw: string;
|
|
25
|
+
readonly kind: Kind;
|
|
26
|
+
/** `~` prefix (spec §7.1): the value is approximate. */
|
|
27
|
+
readonly approx: boolean;
|
|
28
|
+
/** Normalized numeric value with multiplier expanded, when parseable. */
|
|
29
|
+
readonly num?: number;
|
|
30
|
+
/** Normalized unit expression (`USD/yr`, `ms`, `%`), when present. */
|
|
31
|
+
readonly unit?: string;
|
|
32
|
+
};
|
|
33
|
+
export type t = Value;
|
|
34
|
+
/** @returns `true` if `s` is a valid unit expression (`USD/yr`, `ms`, `%`). */
|
|
35
|
+
export declare const isUnit: (s: string) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @returns `true` if `s` is date-like (spec §16 `date_like`): `2026-H2`,
|
|
38
|
+
* `2026-Q1`, `2026-04`, `2026-04-10`. A bare year parses as a number instead.
|
|
39
|
+
*/
|
|
40
|
+
export declare const isDateLike: (s: string) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Parses an unquoted value string (spec §16 `value`), classifying it as
|
|
43
|
+
* number, date or atom. The raw text (including `~` and multiplier letters)
|
|
44
|
+
* is preserved verbatim.
|
|
45
|
+
*/
|
|
46
|
+
export declare const parse: (raw: string) => Value;
|
|
47
|
+
/** @returns value for a double-quoted natural-language literal (spec §4.2). */
|
|
48
|
+
export declare const ofText: (text: string) => Value;
|
|
49
|
+
/** @returns value for a backticked exact code literal (spec §4.2). */
|
|
50
|
+
export declare const ofCode: (code: string) => Value;
|
|
51
|
+
/**
|
|
52
|
+
* @returns canonical text of the value for emission. Raw text is already
|
|
53
|
+
* canonical (spec normalizes multipliers only in storage, never in text);
|
|
54
|
+
* quoted kinds are re-wrapped in their delimiters.
|
|
55
|
+
*/
|
|
56
|
+
export declare const format: (value: Value) => string;
|
|
57
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,yCAAyC;AACzC,MAAM,MAAM,IAAI,GACZ,QAAQ,GACR,MAAM,GACN,MAAM,GACN,MAAM,GACN,MAAM,CAAA;AAEV,MAAM,MAAM,KAAK,GAAG;IAClB,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,yEAAyE;IACzE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,sEAAsE;IACtE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,CAAC,GAAG,KAAK,CAAA;AAMrB,+EAA+E;AAC/E,eAAO,MAAM,MAAM,GAAI,GAAG,MAAM,KAAG,OACnB,CAAA;AAEhB;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,MAAM,KAAG,OACvB,CAAA;AAsChB;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,MAAM,KAAG,KAanC,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,KAAG,KACQ,CAAA;AAE9C,sEAAsE;AACtE,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,KAAG,KACQ,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,KAAK,KAAG,MASrC,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values, units and multipliers (spec §7.1).
|
|
3
|
+
*
|
|
4
|
+
* A value is the payload of an attribute claim (`HAS attr: value`), a metric
|
|
5
|
+
* claim (`metric IS value`), or a `+/-` uncertainty delta. Parsing keeps the
|
|
6
|
+
* raw text verbatim and additionally extracts a normalized numeric value and
|
|
7
|
+
* unit when possible (spec §13.4 steps 7–9):
|
|
8
|
+
*
|
|
9
|
+
* - `30ms` → num 30, unit `ms`
|
|
10
|
+
* - `20B USD/yr` → num 20000000000, unit `USD/yr`
|
|
11
|
+
* - `~20B USD/yr` → the same, `approx` set
|
|
12
|
+
* - `94.5%` → num 94.5, unit `%`
|
|
13
|
+
* - `20 conn` → num 20, unit `conn`
|
|
14
|
+
* - `2026-H2` → date-like, kept textual
|
|
15
|
+
* - `token-expiry` → atom, kept textual
|
|
16
|
+
*
|
|
17
|
+
* Quoted (`"..."`) and backticked (`` `...` ``) values arrive from the parser
|
|
18
|
+
* with their kind already known; use {@link ofText} / {@link ofCode}.
|
|
19
|
+
*/
|
|
20
|
+
import * as Multiplier from "./multiplier.js";
|
|
21
|
+
const numberRe = /^(-?\d+(?:\.\d+)?)([A-Za-z%]*)$/;
|
|
22
|
+
const unitRe = /^[A-Za-z%$][A-Za-z0-9%$]*(?:\/[A-Za-z0-9%$]+)*$/;
|
|
23
|
+
const dateRe = /^\d{4}-(?:H[1-2]|Q[1-4]|W\d{1,2}|\d{2})(?:-\d{2})?$/;
|
|
24
|
+
/** @returns `true` if `s` is a valid unit expression (`USD/yr`, `ms`, `%`). */
|
|
25
|
+
export const isUnit = (s) => unitRe.test(s);
|
|
26
|
+
/**
|
|
27
|
+
* @returns `true` if `s` is date-like (spec §16 `date_like`): `2026-H2`,
|
|
28
|
+
* `2026-Q1`, `2026-04`, `2026-04-10`. A bare year parses as a number instead.
|
|
29
|
+
*/
|
|
30
|
+
export const isDateLike = (s) => dateRe.test(s);
|
|
31
|
+
/**
|
|
32
|
+
* Parses `body` as number [multiplier] [unit] where the unit is either glued
|
|
33
|
+
* (`30ms`, `94.5%`) or space-separated (`20B USD/yr`, `20 conn`).
|
|
34
|
+
* @returns `undefined` when `body` is not numeric.
|
|
35
|
+
*/
|
|
36
|
+
const parseNumeric = (body) => {
|
|
37
|
+
const spaceAt = body.indexOf(' ');
|
|
38
|
+
const head = spaceAt === -1 ? body : body.slice(0, spaceAt);
|
|
39
|
+
const tail = spaceAt === -1 ? undefined : body.slice(spaceAt + 1).trim();
|
|
40
|
+
const match = numberRe.exec(head);
|
|
41
|
+
if (!match) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const [, digits, glued] = match;
|
|
45
|
+
let num = Number(digits);
|
|
46
|
+
let unit;
|
|
47
|
+
if (glued !== undefined && glued !== '') {
|
|
48
|
+
if (Multiplier.is(glued)) {
|
|
49
|
+
num *= Multiplier.factor(glued);
|
|
50
|
+
}
|
|
51
|
+
else if (isUnit(glued)) {
|
|
52
|
+
unit = glued;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (tail !== undefined) {
|
|
59
|
+
if (unit !== undefined || !isUnit(tail)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
unit = tail;
|
|
63
|
+
}
|
|
64
|
+
return unit === undefined ? { num } : { num, unit };
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Parses an unquoted value string (spec §16 `value`), classifying it as
|
|
68
|
+
* number, date or atom. The raw text (including `~` and multiplier letters)
|
|
69
|
+
* is preserved verbatim.
|
|
70
|
+
*/
|
|
71
|
+
export const parse = (raw) => {
|
|
72
|
+
const approx = raw.startsWith('~');
|
|
73
|
+
const body = approx ? raw.slice(1) : raw;
|
|
74
|
+
const numeric = parseNumeric(body);
|
|
75
|
+
if (numeric !== undefined) {
|
|
76
|
+
return numeric.unit === undefined ?
|
|
77
|
+
{ raw, kind: 'number', approx, num: numeric.num } :
|
|
78
|
+
{ raw, kind: 'number', approx, num: numeric.num, unit: numeric.unit };
|
|
79
|
+
}
|
|
80
|
+
if (isDateLike(body)) {
|
|
81
|
+
return { raw, kind: 'date', approx };
|
|
82
|
+
}
|
|
83
|
+
return { raw, kind: 'atom', approx };
|
|
84
|
+
};
|
|
85
|
+
/** @returns value for a double-quoted natural-language literal (spec §4.2). */
|
|
86
|
+
export const ofText = (text) => ({ raw: text, kind: 'text', approx: false });
|
|
87
|
+
/** @returns value for a backticked exact code literal (spec §4.2). */
|
|
88
|
+
export const ofCode = (code) => ({ raw: code, kind: 'code', approx: false });
|
|
89
|
+
/**
|
|
90
|
+
* @returns canonical text of the value for emission. Raw text is already
|
|
91
|
+
* canonical (spec normalizes multipliers only in storage, never in text);
|
|
92
|
+
* quoted kinds are re-wrapped in their delimiters.
|
|
93
|
+
*/
|
|
94
|
+
export const format = (value) => {
|
|
95
|
+
switch (value.kind) {
|
|
96
|
+
case 'text':
|
|
97
|
+
return `"${value.raw}"`;
|
|
98
|
+
case 'code':
|
|
99
|
+
return `\`${value.raw}\``;
|
|
100
|
+
default:
|
|
101
|
+
return value.raw;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAwB7C,MAAM,QAAQ,GAAG,iCAAiC,CAAA;AAClD,MAAM,MAAM,GAAG,iDAAiD,CAAA;AAChE,MAAM,MAAM,GAAG,qDAAqD,CAAA;AAEpE,+EAA+E;AAC/E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAW,EAAE,CAC3C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAEhB;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAS,EAAW,EAAE,CAC/C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAIhB;;;;GAIG;AACH,MAAM,YAAY,GAAG,CAAC,IAAY,EAAuB,EAAE;IACzD,MAAM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AE,CAC5C,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAY,EAAU,EAAE;IAC7C,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM;YACT,OAAO,IAAI,KAAK,CAAC,GAAG,GAAG,CAAA;QACzB,KAAK,MAAM;YACT,OAAO,KAAK,KAAK,CAAC,GAAG,IAAI,CAAA;QAC3B;YACE,OAAO,KAAK,CAAC,GAAG,CAAA;IACpB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verbs (spec §5).
|
|
3
|
+
*
|
|
4
|
+
* Verbs are uppercase atoms. Two bootstrap verbs (`IS`, `HAS`) can define
|
|
5
|
+
* everything else in-band; the standard set below exists for graph quality.
|
|
6
|
+
* Extension verbs (spec §5.4) and inverse declarations (spec §5.5 `REVERSE`)
|
|
7
|
+
* are ordinary claims, not syntax — this module only knows the lexical shape
|
|
8
|
+
* and the standard vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
export type Verb = string;
|
|
11
|
+
export type t = Verb;
|
|
12
|
+
/** Bootstrap verbs (spec §5.1). */
|
|
13
|
+
export declare const bootstrap: readonly ["IS", "HAS"];
|
|
14
|
+
/** Identity and taxonomy (spec §5.2). */
|
|
15
|
+
export declare const identity: readonly ["IS", "EXTENDS", "ALIAS", "LIKE", "EXISTS"];
|
|
16
|
+
/** Causation and change (spec §5.2). */
|
|
17
|
+
export declare const causation: readonly ["CAUSE", "FIX", "BECOMES"];
|
|
18
|
+
/** Dependency and production (spec §5.2). */
|
|
19
|
+
export declare const dependency: readonly ["NEEDS", "USES", "YIELDS", "ENABLES", "BLOCKS"];
|
|
20
|
+
/** Structure and ordering (spec §5.2). */
|
|
21
|
+
export declare const structure: readonly ["CONTAINS", "PRECEDES", "EXCEEDS", "VS"];
|
|
22
|
+
/** Qualifier verbs — appear indented under another claim (spec §5.2, §8.2). */
|
|
23
|
+
export declare const qualifiers: readonly ["WHEN", "UNLESS", "VIA", "BECAUSE"];
|
|
24
|
+
export type Qualifier = (typeof qualifiers)[number];
|
|
25
|
+
/** The inverse-declaration verb (spec §5.5). */
|
|
26
|
+
export declare const REVERSE = "REVERSE";
|
|
27
|
+
/** The standard inverse names (spec §5.5's declaration block). */
|
|
28
|
+
export declare const standardInverses: readonly ["PART-OF", "CAUSED-BY", "FOLLOWS", "USED-BY", "NEEDED-BY", "ENABLED-BY", "BLOCKED-BY", "EXTENDED-BY"];
|
|
29
|
+
/** All standard relational verbs (qualifiers excluded). */
|
|
30
|
+
export declare const standard: readonly Verb[];
|
|
31
|
+
/**
|
|
32
|
+
* @returns `true` if `s` has the lexical shape of a verb — an uppercase atom:
|
|
33
|
+
* uppercase letters and internal `-` (spec §16 `uppercase_atom`).
|
|
34
|
+
*/
|
|
35
|
+
export declare const isVerbToken: (s: string) => boolean;
|
|
36
|
+
/** @returns `true` if `v` is one of the standard relational verbs. */
|
|
37
|
+
export declare const isStandard: (v: string) => boolean;
|
|
38
|
+
/** @returns `true` if `v` is a qualifier verb (`WHEN`, `UNLESS`, `VIA`, `BECAUSE`). */
|
|
39
|
+
export declare const isQualifier: (v: string) => v is Qualifier;
|
|
40
|
+
/**
|
|
41
|
+
* @returns `true` if `v` belongs to the known standard vocabulary —
|
|
42
|
+
* standard verbs, `HAS`, `REVERSE`, and the standard §5.5 inverse names.
|
|
43
|
+
* Used by the parser's indentation tiebreak: `USES JWT` is a continuation
|
|
44
|
+
* (JWT is not a known verb) while `API NEEDS auth` is a full triple.
|
|
45
|
+
*/
|
|
46
|
+
export declare const isKnown: (v: string) => boolean;
|
|
47
|
+
//# sourceMappingURL=verb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verb.d.ts","sourceRoot":"","sources":["../../src/verb.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAA;AAEzB,MAAM,MAAM,CAAC,GAAG,IAAI,CAAA;AAEpB,mCAAmC;AACnC,eAAO,MAAM,SAAS,wBAAyB,CAAA;AAE/C,yCAAyC;AACzC,eAAO,MAAM,QAAQ,uDAAwD,CAAA;AAE7E,wCAAwC;AACxC,eAAO,MAAM,SAAS,sCAAuC,CAAA;AAE7D,6CAA6C;AAC7C,eAAO,MAAM,UAAU,2DAA4D,CAAA;AAEnF,0CAA0C;AAC1C,eAAO,MAAM,SAAS,oDAAqD,CAAA;AAE3E,+EAA+E;AAC/E,eAAO,MAAM,UAAU,+CAAgD,CAAA;AAEvE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AAEnD,gDAAgD;AAChD,eAAO,MAAM,OAAO,YAAY,CAAA;AAEhC,kEAAkE;AAClE,eAAO,MAAM,gBAAgB,iHAGnB,CAAA;AAEV,2DAA2D;AAC3D,eAAO,MAAM,QAAQ,EAAE,SAAS,IAAI,EAKnC,CAAA;AAMD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,KAAG,OACJ,CAAA;AAEpC,sEAAsE;AACtE,eAAO,MAAM,UAAU,GAAI,GAAG,MAAM,KAAG,OACnB,CAAA;AAEpB,uFAAuF;AACvF,eAAO,MAAM,WAAW,GAAI,GAAG,MAAM,KAAG,CAAC,IAAI,SACxB,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,KAAG,OACnB,CAAA"}
|
package/dist/src/verb.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verbs (spec §5).
|
|
3
|
+
*
|
|
4
|
+
* Verbs are uppercase atoms. Two bootstrap verbs (`IS`, `HAS`) can define
|
|
5
|
+
* everything else in-band; the standard set below exists for graph quality.
|
|
6
|
+
* Extension verbs (spec §5.4) and inverse declarations (spec §5.5 `REVERSE`)
|
|
7
|
+
* are ordinary claims, not syntax — this module only knows the lexical shape
|
|
8
|
+
* and the standard vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
/** Bootstrap verbs (spec §5.1). */
|
|
11
|
+
export const bootstrap = ['IS', 'HAS'];
|
|
12
|
+
/** Identity and taxonomy (spec §5.2). */
|
|
13
|
+
export const identity = ['IS', 'EXTENDS', 'ALIAS', 'LIKE', 'EXISTS'];
|
|
14
|
+
/** Causation and change (spec §5.2). */
|
|
15
|
+
export const causation = ['CAUSE', 'FIX', 'BECOMES'];
|
|
16
|
+
/** Dependency and production (spec §5.2). */
|
|
17
|
+
export const dependency = ['NEEDS', 'USES', 'YIELDS', 'ENABLES', 'BLOCKS'];
|
|
18
|
+
/** Structure and ordering (spec §5.2). */
|
|
19
|
+
export const structure = ['CONTAINS', 'PRECEDES', 'EXCEEDS', 'VS'];
|
|
20
|
+
/** Qualifier verbs — appear indented under another claim (spec §5.2, §8.2). */
|
|
21
|
+
export const qualifiers = ['WHEN', 'UNLESS', 'VIA', 'BECAUSE'];
|
|
22
|
+
/** The inverse-declaration verb (spec §5.5). */
|
|
23
|
+
export const REVERSE = 'REVERSE';
|
|
24
|
+
/** The standard inverse names (spec §5.5's declaration block). */
|
|
25
|
+
export const standardInverses = [
|
|
26
|
+
'PART-OF', 'CAUSED-BY', 'FOLLOWS', 'USED-BY',
|
|
27
|
+
'NEEDED-BY', 'ENABLED-BY', 'BLOCKED-BY', 'EXTENDED-BY'
|
|
28
|
+
];
|
|
29
|
+
/** All standard relational verbs (qualifiers excluded). */
|
|
30
|
+
export const standard = [
|
|
31
|
+
...identity,
|
|
32
|
+
...causation,
|
|
33
|
+
...dependency,
|
|
34
|
+
...structure
|
|
35
|
+
];
|
|
36
|
+
const standardSet = new Set(standard);
|
|
37
|
+
const qualifierSet = new Set(qualifiers);
|
|
38
|
+
const knownSet = new Set([...standard, 'HAS', REVERSE, ...standardInverses]);
|
|
39
|
+
/**
|
|
40
|
+
* @returns `true` if `s` has the lexical shape of a verb — an uppercase atom:
|
|
41
|
+
* uppercase letters and internal `-` (spec §16 `uppercase_atom`).
|
|
42
|
+
*/
|
|
43
|
+
export const isVerbToken = (s) => /^[A-Z](?:[A-Z-]*[A-Z])?$/.test(s);
|
|
44
|
+
/** @returns `true` if `v` is one of the standard relational verbs. */
|
|
45
|
+
export const isStandard = (v) => standardSet.has(v);
|
|
46
|
+
/** @returns `true` if `v` is a qualifier verb (`WHEN`, `UNLESS`, `VIA`, `BECAUSE`). */
|
|
47
|
+
export const isQualifier = (v) => qualifierSet.has(v);
|
|
48
|
+
/**
|
|
49
|
+
* @returns `true` if `v` belongs to the known standard vocabulary —
|
|
50
|
+
* standard verbs, `HAS`, `REVERSE`, and the standard §5.5 inverse names.
|
|
51
|
+
* Used by the parser's indentation tiebreak: `USES JWT` is a continuation
|
|
52
|
+
* (JWT is not a known verb) while `API NEEDS auth` is a full triple.
|
|
53
|
+
*/
|
|
54
|
+
export const isKnown = (v) => knownSet.has(v);
|
|
55
|
+
//# sourceMappingURL=verb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verb.js","sourceRoot":"","sources":["../../src/verb.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,mCAAmC;AACnC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,KAAK,CAAU,CAAA;AAE/C,yCAAyC;AACzC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAA;AAE7E,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAU,CAAA;AAE7D,6CAA6C;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ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AAC,CAAC,CAAC,CAAA;AAErB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAW,EAAE,CAC5C,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cavelang/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "CAVE domain model — claims, values, units, uncertainty, claim keys, UUIDv7 transactions.",
|
|
6
|
+
"license": "CC0-1.0",
|
|
7
|
+
"author": "Mirek Rusin (https://github.com/mirek)",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/mirek/cave.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.18"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/src/index.d.ts",
|
|
19
|
+
"default": "./dist/src/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"!dist/test",
|
|
25
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
26
|
+
"src",
|
|
27
|
+
"!src/**/*.test.ts",
|
|
28
|
+
"README.md",
|
|
29
|
+
"License.md"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -b",
|
|
36
|
+
"test": "node --disable-warning=ExperimentalWarning --test 'test/*.test.ts'",
|
|
37
|
+
"typecheck": "tsc -b"
|
|
38
|
+
}
|
|
39
|
+
}
|