@blue-labs/language 1.36.0 → 1.37.1
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 +109 -110
- package/dist/index.js +14 -14
- package/dist/index.mjs +1280 -1308
- package/dist/lib/Blue.d.ts.map +1 -1
- package/dist/lib/mapping/ComplexObjectConverter.d.ts.map +1 -1
- package/dist/lib/preprocess/Preprocessor.d.ts +1 -1
- package/dist/lib/provider/InMemoryNodeProvider.d.ts.map +1 -1
- package/dist/lib/utils/Base58Sha256Provider.d.ts.map +1 -1
- package/dist/lib/utils/InlineTypeRestorer.d.ts.map +1 -1
- package/dist/lib/utils/NodePatch/patch-utils.d.ts.map +1 -1
- package/dist/lib/utils/Properties.d.ts +8 -8
- package/dist/lib/utils/__tests__/calculateCID.d.ts.map +1 -1
- package/dist/schema/annotations/annotations.d.ts.map +1 -1
- package/dist/schema/annotations/blueDescription.d.ts +1 -1
- package/dist/schema/annotations/blueDescription.d.ts.map +1 -1
- package/dist/schema/annotations/blueId.d.ts +1 -1
- package/dist/schema/annotations/blueId.d.ts.map +1 -1
- package/dist/schema/annotations/blueName.d.ts +1 -1
- package/dist/schema/annotations/blueName.d.ts.map +1 -1
- package/dist/schema/annotations/blueNode.d.ts +1 -1
- package/dist/schema/annotations/blueNode.d.ts.map +1 -1
- package/dist/schema/annotations/extends.d.ts.map +1 -1
- package/dist/schema/annotations/typeBlueId/proxySchema.d.ts.map +1 -1
- package/dist/schema/annotations/typeBlueId/typeBlueId.d.ts +1 -1
- package/dist/schema/annotations/typeBlueId/typeBlueId.d.ts.map +1 -1
- package/dist/schema/blueObjectPredicates.d.ts +1 -1
- package/dist/schema/blueObjectPredicates.d.ts.map +1 -1
- package/dist/schema/jsonBlue.d.ts.map +1 -1
- package/dist/schema/utils.d.ts.map +1 -1
- package/dist/types/zod.d.ts.map +1 -1
- package/dist/utils/blueId/calculateBlueId.d.ts.map +1 -1
- package/dist/utils/blueObject/enrichWithBlueId.d.ts.map +1 -1
- package/dist/utils/blueObject/getBlueObjectProperties.d.ts.map +1 -1
- package/dist/utils/blueObject/getBlueObjectTypeLabel.d.ts.map +1 -1
- package/dist/utils/blueObject/getters.d.ts.map +1 -1
- package/dist/utils/blueObject/isBlueObjectResolved.d.ts.map +1 -1
- package/dist/utils/blueObject/normalizeToBlueObject.d.ts.map +1 -1
- package/dist/utils/blueObject/resolveBlueObjectItems.d.ts.map +1 -1
- package/dist/utils/bs58/bs58.d.ts.map +1 -1
- package/dist/utils/typeGuards/isBigNumber.d.ts.map +1 -1
- package/dist/utils/yamlBlue/dump.d.ts.map +1 -1
- package/dist/utils/yamlBlue/parse.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,124 +1,123 @@
|
|
|
1
1
|
# @blue-labs/language
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Small, fast TypeScript runtime for the Blue Language: parse YAML/JSON into BlueNode graphs, preprocess (directives & mappings), resolve/merge types and references, and compute stable Blue IDs (Base58-SHA256) with first-class Zod interop.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **BlueNode graph**: single, list, map, typed values, metadata (name/description), `contracts`, and references by `blueId`.
|
|
8
|
+
- **Preprocessing**: `blue:` directive (aliases, BlueId, or URL fetch with allow-list), inline-type mappings, implicit type inference for primitives.
|
|
9
|
+
- **Resolution/Merge**: deterministic resolver with a pluggable MergingProcessor pipeline (value propagation, type checking, list/dict validators, metadata propagation, basic-type guard).
|
|
10
|
+
- **BlueId**: canonical JSON → SHA-256 → Base58; sync/async, lists supported; CIDv1 conversion.
|
|
11
|
+
- **Providers**: resolve by BlueId from memory, repositories or built-in bootstrap content; sequential composition.
|
|
12
|
+
- **Zod mapping**: convert nodes to typed objects with schema extensions & Blue annotations; serialize objects back to Blue-shaped JSON.
|
|
13
|
+
- **Limits & paths**: restrict extension/merge by path or depth; compose limits.
|
|
14
|
+
- **Patching & transforms**: RFC-6902-style patch ops for BlueNode; recursive transform utilities.
|
|
15
|
+
- **URL fetching**: pluggable strategy + caching + domain allow-list (opt-in).
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
## Installation
|
|
8
18
|
|
|
9
19
|
```bash
|
|
10
|
-
npm
|
|
20
|
+
npm i @blue-labs/language zod
|
|
11
21
|
# or
|
|
12
|
-
yarn add @blue-labs/language
|
|
22
|
+
yarn add @blue-labs/language zod
|
|
13
23
|
```
|
|
14
24
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Checks if a BlueObject is fully resolved or if there is something apart from blueId.
|
|
49
|
-
|
|
50
|
-
### Predicates
|
|
51
|
-
|
|
52
|
-
- **hasBlueObjectBlueIdDefined**
|
|
53
|
-
- Predicate to check if blueId is defined.
|
|
54
|
-
- **hasBlueObjectItemsDefined**
|
|
55
|
-
- Predicate to check if items are defined.
|
|
56
|
-
- **hasBlueObjectNameDefined**
|
|
57
|
-
- Predicate to check if name is defined.
|
|
58
|
-
- **hasBlueObjectTypeDefined**
|
|
59
|
-
- Predicate to check if type is defined.
|
|
60
|
-
- **hasBlueObjectValueDefined**
|
|
61
|
-
- Predicate to check if value is defined.
|
|
62
|
-
- **isBlueObject**
|
|
63
|
-
- Predicate to check if a value is of type BlueObject.
|
|
64
|
-
|
|
65
|
-
### Normalization
|
|
66
|
-
|
|
67
|
-
- **normalizeToBlueObject**
|
|
68
|
-
- Normalizes a given JSON value to a BlueObject.
|
|
69
|
-
|
|
70
|
-
### Helpers
|
|
71
|
-
|
|
72
|
-
- **resolveBlueObjectItems**
|
|
73
|
-
- Resolves BlueObject items in order from last to first.
|
|
74
|
-
- **yamlBlueDump**
|
|
75
|
-
- Loads YAML.
|
|
76
|
-
- **yamlBlueParse**
|
|
77
|
-
- Parses YAML.
|
|
78
|
-
|
|
79
|
-
## Blue Language Overview
|
|
80
|
-
|
|
81
|
-
Blue language is a simple YAML-based language that supports inheritance. Below are some key aspects:
|
|
82
|
-
|
|
83
|
-
### Base Type
|
|
84
|
-
|
|
85
|
-
Every node in Blue is of this type. If any node does not specify a `type`, it is considered to be of this base type by default.
|
|
86
|
-
|
|
87
|
-
### Known Blue Types
|
|
88
|
-
|
|
89
|
-
- **Text**: A basic text type.
|
|
90
|
-
- **Integer**: A basic integer type.
|
|
91
|
-
- **Number**: A basic number type.
|
|
92
|
-
- **Boolean**: A basic boolean type. If value is not specified, it means false.
|
|
93
|
-
- **Type**: A type that can reference other types. To be used only for `type` attribute definition.
|
|
94
|
-
|
|
95
|
-
### Example
|
|
96
|
-
|
|
97
|
-
```yaml
|
|
98
|
-
name:
|
|
99
|
-
value: Pet
|
|
100
|
-
description: Name of the pet. Every pet must have a name.
|
|
101
|
-
description: A base type for all pets.
|
|
102
|
-
abstract: true
|
|
103
|
-
age:
|
|
104
|
-
description: The age of the pet in years.
|
|
105
|
-
type: Integer
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
name:
|
|
109
|
-
value: Dog
|
|
110
|
-
description: If we want to put more fields for Text, Integer, Number, Boolean, or Type elements, we can use `value` instead of inline approach like everywhere else here.
|
|
111
|
-
abstract: true
|
|
112
|
-
type: Pet
|
|
113
|
-
breed:
|
|
114
|
-
description: The breed of the dog.
|
|
115
|
-
type: Text
|
|
116
|
-
isTrained:
|
|
117
|
-
description: Indicates if the dog is trained.
|
|
118
|
-
type: Boolean
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Blue, BasicNodeProvider, PathLimits } from '@blue-labs/language';
|
|
29
|
+
import { z } from 'zod';
|
|
30
|
+
|
|
31
|
+
// 1) Construct runtime (uses bootstrap types + your provider chain)
|
|
32
|
+
const blue = new Blue({
|
|
33
|
+
nodeProvider: new BasicNodeProvider(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2) Parse YAML (or JSON) into a BlueNode
|
|
37
|
+
const yaml = `
|
|
38
|
+
name: Greeting
|
|
39
|
+
value: Hello, Blue!
|
|
40
|
+
`;
|
|
41
|
+
const node = blue.yamlToNode(yaml);
|
|
42
|
+
|
|
43
|
+
// 3) Resolve (merge types/references), optionally with limits
|
|
44
|
+
const resolved = blue.resolve(node, PathLimits.withMaxDepth(10));
|
|
45
|
+
|
|
46
|
+
// 4) Compute BlueId
|
|
47
|
+
const blueId = blue.calculateBlueIdSync(resolved);
|
|
48
|
+
|
|
49
|
+
// 5) Map to a Zod schema (with annotations supported)
|
|
50
|
+
const Greeting = z.object({
|
|
51
|
+
name: z.string().optional(),
|
|
52
|
+
value: z.string(),
|
|
53
|
+
});
|
|
54
|
+
const asObject = blue.nodeToSchemaOutput(resolved, Greeting);
|
|
55
|
+
|
|
56
|
+
// 6) Convert back to JSON (choose strategy)
|
|
57
|
+
const official = blue.nodeToJson(resolved, 'official');
|
|
119
58
|
```
|
|
120
59
|
|
|
121
|
-
|
|
60
|
+
## API Overview (essentials)
|
|
61
|
+
|
|
62
|
+
### Core graph
|
|
63
|
+
|
|
64
|
+
- `BlueNode` – node model (name, description, type, itemType, keyType, valueType, value, items, properties, blueId, blue directive).
|
|
65
|
+
- `ResolvedBlueNode` – wrapper for resolved nodes; includes `getMinimalNode()` and `getMinimalBlueId()`.
|
|
66
|
+
|
|
67
|
+
### Entry point
|
|
68
|
+
|
|
69
|
+
- `class Blue`
|
|
70
|
+
- Parsing: `yamlToNode(_)/jsonValueToNode(_)` (+ async variants).
|
|
71
|
+
- Preprocess: blue directive (`BlueDirectivePreprocessor`) + default pipeline (`Preprocessor`).
|
|
72
|
+
- Resolve: `resolve(node, limits)` → `ResolvedBlueNode`.
|
|
73
|
+
- IDs: `calculateBlueId(_)/calculateBlueIdSync(_)`.
|
|
74
|
+
- Mapping: `nodeToJson(node, 'official'|'simple'|'original')`, `nodeToSchemaOutput(node, zod)`.
|
|
75
|
+
- Type checks: `isTypeOf(node, zod)`, `isTypeOfNode(node, typeNode)`.
|
|
76
|
+
- Helpers: `extend(node, limits)`, `transform(node, fn)`, `reverse(node)`, `restoreInlineTypes(node)`.
|
|
77
|
+
- Config: URL fetch allow-list (`enablePreprocessingDirectivesFetchForDomains([...])`), global limits, repositories.
|
|
78
|
+
|
|
79
|
+
### Resolution & merge
|
|
80
|
+
|
|
81
|
+
- `Merger` + `MergingProcessor` pipeline: value → types → lists/dicts → metadata → basic checks.
|
|
82
|
+
- `createDefaultMergingProcessor()` exports the default pipeline.
|
|
83
|
+
|
|
84
|
+
### Providers
|
|
85
|
+
|
|
86
|
+
- `NodeProvider`, `SequentialNodeProvider`, `BootstrapProvider`, `InMemoryNodeProvider`, `BasicNodeProvider`, `RepositoryBasedNodeProvider`.
|
|
87
|
+
- `NodeProviderWrapper.wrap(...)` composes bootstrap, repositories, and your provider.
|
|
88
|
+
|
|
89
|
+
### Preprocessing
|
|
90
|
+
|
|
91
|
+
- `BlueDirectivePreprocessor`: resolves `blue:` directive (alias, BlueId, or URL).
|
|
92
|
+
- `Preprocessor`: runs transformations declared under `blue:` (replace inline type strings → BlueIds; infer basic types; validate inline types removed).
|
|
93
|
+
- `BlueIdsMappingGenerator`: accumulate BlueId mappings (repositories, custom, core).
|
|
94
|
+
|
|
95
|
+
### Mapping & Zod
|
|
96
|
+
|
|
97
|
+
- `NodeToObjectConverter` + converters for primitives/arrays/tuples/sets/maps/objects; supports schema extension resolution via `TypeSchemaResolver`.
|
|
98
|
+
- Schema annotations: `withTypeBlueId`, `withBlueId`, `withBlueName`, `withBlueDescription`, `blueIdField`, `blueNodeField`.
|
|
99
|
+
|
|
100
|
+
### Blue IDs & CIDs
|
|
101
|
+
|
|
102
|
+
- `BlueIdCalculator` (sync/async); `Base58Sha256Provider`.
|
|
103
|
+
- `BlueIds` validator; `BlueIdToCid` and `CidToBlueId` converters.
|
|
104
|
+
|
|
105
|
+
### Limits
|
|
106
|
+
|
|
107
|
+
- `PathLimits`, `CompositeLimits`, and `NO_LIMITS`. Build from node shape or explicit patterns.
|
|
108
|
+
|
|
109
|
+
### Utilities
|
|
110
|
+
|
|
111
|
+
- `Nodes`, `NodeTransformer`, `NodePathAccessor` (`/path` getter), patching via `applyBlueNodePatch(es)` implementing RFC-6902.
|
|
112
|
+
- URL fetching: `UrlContentFetcher` with pluggable `{ fetchUrl }` and domain allow-list.
|
|
113
|
+
|
|
114
|
+
## Docs
|
|
115
|
+
|
|
116
|
+
- `docs/resolve.md` – resolver & merging pipeline.
|
|
117
|
+
- `docs/preprocessor.md` – blue directive, inference & mappings.
|
|
118
|
+
- `docs/blue-id.md` – BlueId algorithm and APIs.
|
|
119
|
+
- `docs/mapping.md` – Zod mapping and serialization.
|
|
120
|
+
- `docs/architecture.md` – end-to-end architecture.
|
|
122
121
|
|
|
123
122
|
## Changelog
|
|
124
123
|
|