@burojs/config 0.2.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,10 +3,13 @@
3
3
  Inert JSON and YAML declaration sources for [buro](https://github.com/buro/buro).
4
4
 
5
5
  Parses a raw JSON or YAML string against a host-owned `SourcePolicy` and
6
- produces a portable declaration layer — or a list of diagnostics if the
7
- source is malformed, oversized, or requests something its policy doesn't
8
- allow. The output can only ever be data: no functions, components, schemas,
9
- credentials, or provider/action/mapper bindings survive the parse.
6
+ produces a portable declaration layer that carries the policy's grants — or a
7
+ list of diagnostics if the source is malformed, oversized, or requests
8
+ something its policy doesn't allow. *Source* here is a configuration source — a
9
+ JSON or YAML document a host loads into a layer runtime — not a screen's `with`
10
+ source. The output can only ever be data: no
11
+ functions, components, schemas, credentials, or provider/action/mapper bindings
12
+ survive the parse.
10
13
 
11
14
  ## Install
12
15
 
@@ -20,12 +23,24 @@ pnpm add @burojs/config
20
23
  import { parseJsonLayer, type SourcePolicy } from '@burojs/config';
21
24
 
22
25
  const policy: SourcePolicy = {
23
- allowedKinds: ['resource'],
24
- allowedNamespaces: ['crm'],
25
- allowedTransformOps: [],
26
- maxTransformScope: 'layer',
26
+ grants: {
27
+ allowedKinds: ['resource'],
28
+ allowedNamespaces: ['crm'],
29
+ allowedTransformOps: [],
30
+ maxTransformScope: 'layer',
31
+ writePaths: {},
32
+ allowedResources: [],
33
+ allowedQueries: [],
34
+ allowedFlows: [],
35
+ allowedBackends: ['company'],
36
+ allowedBlocks: [],
37
+ allowedFrames: [],
38
+ allowedInlineFlows: [],
39
+ allowedFieldImplementations: [],
40
+ priority: { min: 0, max: 0 },
41
+ },
27
42
  allowedCapabilities: {},
28
- limits: { maxBytes: 16_000, maxDeclarations: 12, maxDepth: 16, maxStringLength: 1_000, maxDiagnostics: 8 },
43
+ limits: { maxBytes: 16_000, maxDeclarations: 12, maxDepth: 16, maxNodes: 1_000, maxStringLength: 1_000, maxDiagnostics: 8 },
29
44
  };
30
45
 
31
46
  const source = JSON.stringify({
@@ -34,25 +49,45 @@ const source = JSON.stringify({
34
49
  defaultNamespace: 'crm',
35
50
  revision: 'r1',
36
51
  declarations: [
37
- { kind: 'resource', ref: 'company', schemaVersion: 1, value: { name: 'company' } },
52
+ { kind: 'resource', ref: 'company', schemaVersion: 2, value: { name: 'company' } },
38
53
  ],
39
54
  });
40
55
 
41
56
  const result = parseJsonLayer(source, policy);
42
57
  if (!result.ok) throw new Error(result.diagnostics.map((d) => d.code).join(', '));
43
- // result.value is a LayerInput, ready for runtime.publishLayer(...)
58
+ // result.value is a ParsedLayer carrying the grants of `policy`:
59
+ await runtime.publishLayer(result.value);
44
60
  ```
45
61
 
46
- To load a source lazily instead of publishing it up front, wrap the parser in
47
- `createConfigRuntimeSource` and hand the result to a core `LayerRuntime` via
48
- `registerSource`/`loadSource`.
62
+ To load a source lazily instead of publishing it up front, give
63
+ `createConfigRuntimeSource` the policy and a `load` that returns the document's
64
+ text; it parses each load under the policy, and returns the runtime source with
65
+ the trust to register it under:
66
+
67
+ ```ts
68
+ const configured = createConfigRuntimeSource('catalog', {
69
+ policy,
70
+ load: async () => ({ format: 'json', text: await fetch('/config/catalog.json').then((r) => r.text()) }),
71
+ });
72
+ runtime.registerSource(configured.source, configured.trust);
73
+ ```
74
+
75
+ The parser checks keys (it refuses `action`, `component`, `validator` and the
76
+ other code-bearing keys), the trusted-attachment capabilities in
77
+ `allowedCapabilities`, and the `limits`; those checks are parser-only. The
78
+ compiler enforces the `grants` — the kinds, namespaces and transform operations
79
+ a layer uses, the paths a transform may write (`writePaths`, no default), its
80
+ targets, its references (`allowedResources`, `allowedQueries`,
81
+ `allowedFlows`), its backend bindings (`allowedBackends`) and its priority
82
+ band. Use a band strictly away from your code's priorities to fix whether a
83
+ parsed layer applies before or after your code. See the "Grants and trust"
84
+ section of the guide linked below.
49
85
 
50
86
  ## Main exports
51
87
 
52
88
  - **`parseJsonLayer` / `parseYamlLayer`** — parse a source string against a `SourcePolicy`, returning a `ParseResult`.
53
- - **`createConfigRuntimeSource`** — builds a core `RuntimeSource` that fetches, parses, and adapts a source on demand.
54
- - **`adaptRawConfig` / `parseResultAdapter`** — the pure adapter boundary between a raw source shape and the layer the runtime commits.
55
- - **`SourcePolicy` / `SourceLimits`** — the allow-list and resource limits a host defines for one untrusted source.
89
+ - **`createConfigRuntimeSource(id, { policy, load })`** — returns `{ source, trust }`: a core `RuntimeSource` that loads and parses a document on demand, and the policy's grants to register it with.
90
+ - **`SourcePolicy` / `SourceLimits`** — `{ grants, allowedCapabilities, limits }`, what a host allows one untrusted source: `grants` (the core `LayerGrants`) is what its parsed layers carry; `SCREEN_SOURCE_LIMITS` is a preset for sources that carry whole screen trees.
56
91
 
57
92
  See [`docs/raw-config-manifests.md`](../../docs/raw-config-manifests.md) for the full source-policy boundary and how it composes with a `LayerRuntime`.
58
93