structured-context 0.20.0 → 0.21.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/dist/api.d.ts CHANGED
@@ -32,7 +32,7 @@ export { buildTargetIndex, formatWikilink, type ParsedWikilink, parseWikilink, w
32
32
  export { listSchemas } from './schema/list-schemas';
33
33
  export type { SharedEmbeddingFields } from './schema/metadata-contract';
34
34
  export { bundledSchemasDir, loadSchema, type PluginSchemaSource, setBundledSchemasDir } from './schema/schema';
35
- export { createSpaceContext, SpaceNotFoundError } from './space-context';
35
+ export { createSpaceContext } from './space-context';
36
36
  export { buildSpaceGraph } from './space-graph';
37
37
  export { exportSpaceGraph } from './space-graph-data';
38
38
  export type { BaseNode, ContentLink, EdgeDefinition, FileNotInSpaceResult, FileValidationIssue, FileValidationResult, Hierarchy, HierarchyLevel, ParseIssue, ReadSpaceResult, Relationship, ResolvedContentLink, RuleCategory, RuleSeverity, RuleViolation, SchemaMetadata, SchemaWithMetadata, SourceLocation, SpaceContext, UnresolvedRef, ValidateFileOutput, } from './types';
package/dist/api.js CHANGED
@@ -29,7 +29,7 @@ export { readSpace } from './read/read-space';
29
29
  export { buildTargetIndex, formatWikilink, parseWikilink, wikilinkToTarget, } from './read/wikilink-utils';
30
30
  export { listSchemas } from './schema/list-schemas';
31
31
  export { bundledSchemasDir, loadSchema, setBundledSchemasDir } from './schema/schema';
32
- export { createSpaceContext, SpaceNotFoundError } from './space-context';
32
+ export { createSpaceContext } from './space-context';
33
33
  export { buildSpaceGraph } from './space-graph';
34
34
  export { exportSpaceGraph } from './space-graph-data';
35
35
  export { validateFile, validateSpace } from './validate';
package/dist/errors.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Stable codes for configuration and environment problems. Hooks and agent skills map a code to a
3
3
  * fix, so the message wording can change without breaking them.
4
4
  */
5
- export type SctxErrorCode = 'E_CONFIG_NOT_FOUND' | 'E_CONFIG_INVALID' | 'E_INCLUDE_NOT_FOUND' | 'E_NO_SPACES' | 'E_SPACE_PATH_MISSING' | 'E_SCHEMA_MISSING' | 'E_SCHEMA_NOT_FOUND' | 'E_SCHEMA_INVALID' | 'E_SPACE_EXISTS' | 'E_TARGET_REQUIRED' | 'E_CONFIG_NEEDS_MANUAL_EDIT' | 'E_MODEL_PROVIDER_INVALID';
5
+ export type SctxErrorCode = 'E_CONFIG_NOT_FOUND' | 'E_CONFIG_INVALID' | 'E_INCLUDE_NOT_FOUND' | 'E_NO_SPACES' | 'E_SPACE_PATH_MISSING' | 'E_SCHEMA_MISSING' | 'E_SCHEMA_NOT_FOUND' | 'E_SCHEMA_INVALID' | 'E_SPACE_EXISTS' | 'E_SPACE_NOT_FOUND' | 'E_TARGET_REQUIRED' | 'E_CONFIG_NEEDS_MANUAL_EDIT' | 'E_MODEL_PROVIDER_INVALID';
6
6
  export declare class SctxError extends Error {
7
7
  readonly code: SctxErrorCode;
8
8
  constructor(code: SctxErrorCode, message: string);
package/dist/index.js CHANGED
@@ -17,23 +17,14 @@ import { validateFileCommand } from './commands/validate-file';
17
17
  import { loadConfig, setConfigPath } from './config';
18
18
  import { CLI_NAME } from './constants';
19
19
  import { SctxError } from './errors';
20
- import { createSpaceContext, SpaceNotFoundError } from './space-context';
20
+ import { createSpaceContext } from './space-context';
21
21
  // Once node:process is loaded (vfile, via unified, loads it), Bun's console.log drops piped output
22
22
  // past 64KB when the reader is slow. process.stdout.write delivers all of it before exit.
23
23
  console.log = (...args) => {
24
24
  process.stdout.write(`${format(...args)}\n`);
25
25
  };
26
26
  export function buildSpaceContext(spaceName) {
27
- try {
28
- return createSpaceContext(spaceName, loadConfig());
29
- }
30
- catch (err) {
31
- if (err instanceof SpaceNotFoundError) {
32
- console.error(`Error: ${err.message}`);
33
- process.exit(1);
34
- }
35
- throw err;
36
- }
27
+ return createSpaceContext(spaceName, loadConfig());
37
28
  }
38
29
  const require = createRequire(import.meta.url);
39
30
  const packageJson = require('../package.json');
@@ -1,10 +1,5 @@
1
1
  import { type Config } from './config';
2
2
  import type { SpaceContext } from './types';
3
- /** Thrown by createSpaceContext when no space matches the given name. */
4
- export declare class SpaceNotFoundError extends Error {
5
- readonly spaceName: string;
6
- constructor(spaceName: string);
7
- }
8
3
  export interface CreateSpaceContextOptions {
9
4
  /**
10
5
  * Directory to anchor relative plugin-config paths against. Defaults to the source
@@ -20,8 +15,7 @@ export interface CreateSpaceContextOptions {
20
15
  * Synchronously resolves schemas (including plugin-contributed schemas),
21
16
  * indexes partials into the registry, and compiles the schema validator.
22
17
  *
23
- * Library-safe: throws {@link SpaceNotFoundError} on an unknown space rather than
24
- * writing to the console or exiting the process. CLI callers that want the
25
- * exit-on-error behaviour should wrap this (see buildSpaceContext in index.ts).
18
+ * Library-safe: throws SctxError (E_SPACE_NOT_FOUND) on an unknown space rather than
19
+ * writing to the console or exiting the process.
26
20
  */
27
21
  export declare function createSpaceContext(spaceName: string, config: Config, options?: CreateSpaceContextOptions): SpaceContext;
@@ -2,29 +2,19 @@ import { resolveSchema } from './config';
2
2
  import { SctxError } from './errors';
3
3
  import { resolveSpacePluginSchemas } from './plugins/util';
4
4
  import { loadSchema } from './schema/schema';
5
- /** Thrown by createSpaceContext when no space matches the given name. */
6
- export class SpaceNotFoundError extends Error {
7
- spaceName;
8
- constructor(spaceName) {
9
- super(`Unknown space "${spaceName}"`);
10
- this.spaceName = spaceName;
11
- this.name = 'SpaceNotFoundError';
12
- }
13
- }
14
5
  /**
15
6
  * Build a SpaceContext for a named space from an already-loaded config.
16
7
  *
17
8
  * Synchronously resolves schemas (including plugin-contributed schemas),
18
9
  * indexes partials into the registry, and compiles the schema validator.
19
10
  *
20
- * Library-safe: throws {@link SpaceNotFoundError} on an unknown space rather than
21
- * writing to the console or exiting the process. CLI callers that want the
22
- * exit-on-error behaviour should wrap this (see buildSpaceContext in index.ts).
11
+ * Library-safe: throws SctxError (E_SPACE_NOT_FOUND) on an unknown space rather than
12
+ * writing to the console or exiting the process.
23
13
  */
24
14
  export function createSpaceContext(spaceName, config, options = {}) {
25
15
  const space = config.spaces.find((s) => s.name === spaceName);
26
16
  if (!space) {
27
- throw new SpaceNotFoundError(spaceName);
17
+ throw new SctxError('E_SPACE_NOT_FOUND', `Unknown space "${spaceName}"`);
28
18
  }
29
19
  const configDir = options.configDir ?? space.sourceDir;
30
20
  if (configDir === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "structured-context",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Keep your content clean and your thinking clear with assistive tools for structured knowledge",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",