busy-cli 0.1.2
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 +129 -0
- package/dist/builders/context.d.ts +50 -0
- package/dist/builders/context.d.ts.map +1 -0
- package/dist/builders/context.js +190 -0
- package/dist/cache/index.d.ts +100 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +270 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +463 -0
- package/dist/commands/package.d.ts +96 -0
- package/dist/commands/package.d.ts.map +1 -0
- package/dist/commands/package.js +285 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +361 -0
- package/dist/merge.d.ts +16 -0
- package/dist/merge.d.ts.map +1 -0
- package/dist/merge.js +102 -0
- package/dist/package/manifest.d.ts +59 -0
- package/dist/package/manifest.d.ts.map +1 -0
- package/dist/package/manifest.js +265 -0
- package/dist/parser.d.ts +28 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +220 -0
- package/dist/parsers/frontmatter.d.ts +14 -0
- package/dist/parsers/frontmatter.d.ts.map +1 -0
- package/dist/parsers/frontmatter.js +110 -0
- package/dist/parsers/imports.d.ts +48 -0
- package/dist/parsers/imports.d.ts.map +1 -0
- package/dist/parsers/imports.js +147 -0
- package/dist/parsers/links.d.ts +12 -0
- package/dist/parsers/links.d.ts.map +1 -0
- package/dist/parsers/links.js +79 -0
- package/dist/parsers/localdefs.d.ts +6 -0
- package/dist/parsers/localdefs.d.ts.map +1 -0
- package/dist/parsers/localdefs.js +132 -0
- package/dist/parsers/operations.d.ts +32 -0
- package/dist/parsers/operations.d.ts.map +1 -0
- package/dist/parsers/operations.js +313 -0
- package/dist/parsers/sections.d.ts +15 -0
- package/dist/parsers/sections.d.ts.map +1 -0
- package/dist/parsers/sections.js +173 -0
- package/dist/parsers/tools.d.ts +30 -0
- package/dist/parsers/tools.d.ts.map +1 -0
- package/dist/parsers/tools.js +178 -0
- package/dist/parsers/triggers.d.ts +35 -0
- package/dist/parsers/triggers.d.ts.map +1 -0
- package/dist/parsers/triggers.js +219 -0
- package/dist/providers/base.d.ts +60 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +34 -0
- package/dist/providers/github.d.ts +18 -0
- package/dist/providers/github.d.ts.map +1 -0
- package/dist/providers/github.js +109 -0
- package/dist/providers/gitlab.d.ts +18 -0
- package/dist/providers/gitlab.d.ts.map +1 -0
- package/dist/providers/gitlab.js +101 -0
- package/dist/providers/index.d.ts +13 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +17 -0
- package/dist/providers/local.d.ts +31 -0
- package/dist/providers/local.d.ts.map +1 -0
- package/dist/providers/local.js +116 -0
- package/dist/providers/url.d.ts +16 -0
- package/dist/providers/url.d.ts.map +1 -0
- package/dist/providers/url.js +45 -0
- package/dist/registry/index.d.ts +99 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +320 -0
- package/dist/types/schema.d.ts +3259 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +258 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +23 -0
- package/dist/utils/slugify.d.ts +14 -0
- package/dist/utils/slugify.d.ts.map +1 -0
- package/dist/utils/slugify.js +28 -0
- package/package.json +61 -0
- package/src/__tests__/cache.test.ts +393 -0
- package/src/__tests__/cli-package.test.ts +667 -0
- package/src/__tests__/fixtures/automated-workflow.busy.md +84 -0
- package/src/__tests__/fixtures/concept.busy.md +30 -0
- package/src/__tests__/fixtures/document.busy.md +44 -0
- package/src/__tests__/fixtures/simple-operation.busy.md +45 -0
- package/src/__tests__/fixtures/tool-document.busy.md +71 -0
- package/src/__tests__/fixtures/tool.busy.md +54 -0
- package/src/__tests__/imports.test.ts +244 -0
- package/src/__tests__/integration.test.ts +432 -0
- package/src/__tests__/operations.test.ts +408 -0
- package/src/__tests__/package-manifest.test.ts +455 -0
- package/src/__tests__/providers.test.ts +672 -0
- package/src/__tests__/registry.test.ts +402 -0
- package/src/__tests__/schema.test.ts +467 -0
- package/src/__tests__/tools.test.ts +376 -0
- package/src/__tests__/triggers.test.ts +312 -0
- package/src/builders/context.ts +294 -0
- package/src/cache/index.ts +312 -0
- package/src/cli/index.ts +514 -0
- package/src/commands/package.ts +392 -0
- package/src/index.ts +46 -0
- package/src/loader.ts +474 -0
- package/src/merge.ts +126 -0
- package/src/package/manifest.ts +349 -0
- package/src/parser.ts +278 -0
- package/src/parsers/frontmatter.ts +135 -0
- package/src/parsers/imports.ts +196 -0
- package/src/parsers/links.ts +108 -0
- package/src/parsers/localdefs.ts +166 -0
- package/src/parsers/operations.ts +404 -0
- package/src/parsers/sections.ts +230 -0
- package/src/parsers/tools.ts +215 -0
- package/src/parsers/triggers.ts +252 -0
- package/src/providers/base.ts +77 -0
- package/src/providers/github.ts +129 -0
- package/src/providers/gitlab.ts +121 -0
- package/src/providers/index.ts +25 -0
- package/src/providers/local.ts +129 -0
- package/src/providers/url.ts +56 -0
- package/src/registry/index.ts +408 -0
- package/src/types/schema.ts +369 -0
- package/src/utils/logger.ts +25 -0
- package/src/utils/slugify.ts +31 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// NEW SCHEMAS - Matching busy-python models (source of truth)
|
|
5
|
+
// =============================================================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Metadata schema - matches busy-python Metadata model
|
|
9
|
+
* Required: name, type, description
|
|
10
|
+
* Optional: provider (for tool documents)
|
|
11
|
+
* NOTE: Extends and Tags have been removed (not in busy-python)
|
|
12
|
+
*/
|
|
13
|
+
export const MetadataSchema = z.object({
|
|
14
|
+
name: z.string().min(1),
|
|
15
|
+
type: z.string().min(1),
|
|
16
|
+
description: z.string().min(1),
|
|
17
|
+
provider: z.string().optional(),
|
|
18
|
+
}).strict(); // Use strict to reject extra fields like extends/tags
|
|
19
|
+
|
|
20
|
+
export type Metadata = z.infer<typeof MetadataSchema>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Import schema - matches busy-python Import model
|
|
24
|
+
* Reference-style links: [ConceptName]: path/to/file.md[#anchor]
|
|
25
|
+
*/
|
|
26
|
+
export const ImportSchema = z.object({
|
|
27
|
+
conceptName: z.string().min(1),
|
|
28
|
+
path: z.string().min(1),
|
|
29
|
+
anchor: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type Import = z.infer<typeof ImportSchema>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* LocalDefinition schema - matches busy-python LocalDefinition model
|
|
36
|
+
*/
|
|
37
|
+
export const LocalDefinitionSchema = z.object({
|
|
38
|
+
name: z.string().min(1),
|
|
39
|
+
content: z.string(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type LocalDefinition = z.infer<typeof LocalDefinitionSchema>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Step schema - matches busy-python Step model
|
|
46
|
+
* Steps have stepNumber, instruction, and optional operationReferences
|
|
47
|
+
*/
|
|
48
|
+
export const StepSchema = z.object({
|
|
49
|
+
stepNumber: z.number().int().min(1),
|
|
50
|
+
instruction: z.string().min(1),
|
|
51
|
+
operationReferences: z.array(z.string()).optional(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export type Step = z.infer<typeof StepSchema>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Checklist schema - matches busy-python Checklist model
|
|
58
|
+
*/
|
|
59
|
+
export const ChecklistSchema = z.object({
|
|
60
|
+
items: z.array(z.string()),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export type Checklist = z.infer<typeof ChecklistSchema>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Trigger schema - matches busy-python Trigger model
|
|
67
|
+
* Supports both time-based (alarm) and event-based triggers
|
|
68
|
+
*/
|
|
69
|
+
export const TriggerSchema = z.object({
|
|
70
|
+
rawText: z.string(),
|
|
71
|
+
triggerType: z.enum(['alarm', 'event']),
|
|
72
|
+
schedule: z.string().optional(), // cron expression for alarms
|
|
73
|
+
eventType: z.string().optional(), // event type for event triggers
|
|
74
|
+
filter: z.record(z.string()).optional(), // filter criteria
|
|
75
|
+
operation: z.string(), // operation to run
|
|
76
|
+
queueWhenPaused: z.boolean().default(true),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export type Trigger = z.infer<typeof TriggerSchema>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Operation schema (NEW) - matches busy-python Operation model
|
|
83
|
+
* Different from the old graph-based OperationSchema
|
|
84
|
+
*/
|
|
85
|
+
export const NewOperationSchema = z.object({
|
|
86
|
+
name: z.string().min(1),
|
|
87
|
+
inputs: z.array(z.string()).default([]),
|
|
88
|
+
outputs: z.array(z.string()).default([]),
|
|
89
|
+
steps: z.array(StepSchema).default([]),
|
|
90
|
+
checklist: ChecklistSchema.optional(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export type NewOperation = z.infer<typeof NewOperationSchema>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Tool schema - matches busy-python Tool model
|
|
97
|
+
* Tools have provider mappings for external integrations
|
|
98
|
+
*/
|
|
99
|
+
export const ToolSchema = z.object({
|
|
100
|
+
name: z.string().min(1),
|
|
101
|
+
description: z.string(),
|
|
102
|
+
inputs: z.array(z.string()),
|
|
103
|
+
outputs: z.array(z.string()),
|
|
104
|
+
examples: z.array(z.string()).optional(),
|
|
105
|
+
providers: z.record(z.object({
|
|
106
|
+
action: z.string(),
|
|
107
|
+
parameters: z.record(z.any()).optional(),
|
|
108
|
+
})).optional(),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export type Tool = z.infer<typeof ToolSchema>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* BusyDocument schema (NEW) - matches busy-python BusyDocument model
|
|
115
|
+
* This is the new document-centric schema, different from the graph-based one
|
|
116
|
+
*/
|
|
117
|
+
export const NewBusyDocumentSchema = z.object({
|
|
118
|
+
metadata: MetadataSchema,
|
|
119
|
+
imports: z.array(ImportSchema).default([]),
|
|
120
|
+
definitions: z.array(LocalDefinitionSchema).default([]),
|
|
121
|
+
setup: z.string().optional(),
|
|
122
|
+
operations: z.array(NewOperationSchema).default([]),
|
|
123
|
+
triggers: z.array(TriggerSchema).default([]),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export type NewBusyDocument = z.infer<typeof NewBusyDocumentSchema>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* ToolDocument schema - extends BusyDocument with tools array
|
|
130
|
+
*/
|
|
131
|
+
export const ToolDocumentSchema = NewBusyDocumentSchema.extend({
|
|
132
|
+
tools: z.array(ToolSchema).default([]),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export type ToolDocument = z.infer<typeof ToolDocumentSchema>;
|
|
136
|
+
|
|
137
|
+
// =============================================================================
|
|
138
|
+
// LEGACY SCHEMAS - Kept for graph functionality (may be refactored later)
|
|
139
|
+
// =============================================================================
|
|
140
|
+
|
|
141
|
+
// Base types
|
|
142
|
+
export const DocIdSchema = z.string();
|
|
143
|
+
export const SlugSchema = z.string();
|
|
144
|
+
export const SectionIdSchema = z.string(); //unique id in the parsed documents hierarchy.
|
|
145
|
+
export const ConceptIdSchema = z.string(); //conceptual reference, where it is in the object model eg: document.operations.evaluateDocument
|
|
146
|
+
|
|
147
|
+
// Define recursive types first to avoid circular reference errors
|
|
148
|
+
type Section = {
|
|
149
|
+
kind: 'section';
|
|
150
|
+
id: string;
|
|
151
|
+
docId: string;
|
|
152
|
+
slug: string;
|
|
153
|
+
title: string;
|
|
154
|
+
depth: number;
|
|
155
|
+
path: string;
|
|
156
|
+
lineStart: number;
|
|
157
|
+
lineEnd: number;
|
|
158
|
+
content: string;
|
|
159
|
+
children: Section[];
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
type ConceptBase = {
|
|
163
|
+
kind: 'concept' | 'document' | 'operation' | 'checklist' | 'tool' | 'playbook' | 'localdef' | 'importdef' | 'setup';
|
|
164
|
+
id: string;
|
|
165
|
+
docId: string;
|
|
166
|
+
slug: string;
|
|
167
|
+
name: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
types: string[];
|
|
170
|
+
extends: string[];
|
|
171
|
+
sectionRef: string;
|
|
172
|
+
children: ConceptBase[];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// Section schema
|
|
176
|
+
export const SectionSchema: z.ZodType<Section> = z.lazy(() =>
|
|
177
|
+
z.object({
|
|
178
|
+
kind: z.literal('section'),
|
|
179
|
+
id: SectionIdSchema,
|
|
180
|
+
docId: DocIdSchema,
|
|
181
|
+
slug: SlugSchema,
|
|
182
|
+
title: z.string(),
|
|
183
|
+
depth: z.number().int().min(1).max(6),
|
|
184
|
+
path: z.string(),
|
|
185
|
+
lineStart: z.number(),
|
|
186
|
+
lineEnd: z.number(),
|
|
187
|
+
content: z.string(),
|
|
188
|
+
children: z.array(SectionSchema),
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Export Section type
|
|
193
|
+
export type { Section };
|
|
194
|
+
|
|
195
|
+
// ConceptBase schema - need to keep as regular object schema to allow .extend()
|
|
196
|
+
const ConceptBaseSchemaObject = z.object({
|
|
197
|
+
kind: z.enum(['concept', 'document', 'operation', 'checklist', 'tool', 'playbook', 'localdef', 'importdef', 'setup']),
|
|
198
|
+
id: ConceptIdSchema,
|
|
199
|
+
docId: DocIdSchema,
|
|
200
|
+
slug: z.string(),
|
|
201
|
+
name: z.string(),
|
|
202
|
+
content: z.string(),
|
|
203
|
+
types: z.array(ConceptIdSchema),
|
|
204
|
+
extends: z.array(ConceptIdSchema),
|
|
205
|
+
sectionRef: SectionIdSchema,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
export const ConceptBaseSchema: z.ZodType<ConceptBase> = z.lazy(() =>
|
|
209
|
+
ConceptBaseSchemaObject.extend({
|
|
210
|
+
children: z.array(ConceptBaseSchema),
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Export ConceptBase type
|
|
215
|
+
export type { ConceptBase };
|
|
216
|
+
|
|
217
|
+
// LocalDef schema - extends ConceptBase (leaf node, no children)
|
|
218
|
+
export const LocalDefSchema = ConceptBaseSchemaObject.extend({
|
|
219
|
+
kind: z.literal('localdef'),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Setup schema - extends ConceptBase (leaf node, no children)
|
|
223
|
+
export const SetupSchema = ConceptBaseSchemaObject.extend({
|
|
224
|
+
kind: z.literal('setup'),
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Operation schema (LEGACY) - extends ConceptBase (leaf node, no children)
|
|
228
|
+
// Used for graph-based representation
|
|
229
|
+
export const LegacyOperationSchema = ConceptBaseSchemaObject.extend({
|
|
230
|
+
kind: z.literal('operation'),
|
|
231
|
+
steps: z.array(z.string()), // Parsed step items (legacy: strings only)
|
|
232
|
+
checklist: z.array(z.string()), // Parsed checklist items
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Keep OperationSchema as the legacy schema for backward compatibility with loader
|
|
236
|
+
export const OperationSchema = LegacyOperationSchema;
|
|
237
|
+
|
|
238
|
+
// ImportDef schema - extends ConceptBase (leaf node, no children)
|
|
239
|
+
export const ImportDefSchema = ConceptBaseSchemaObject.extend({
|
|
240
|
+
kind: z.literal('importdef'),
|
|
241
|
+
label: z.string(),
|
|
242
|
+
target: SectionIdSchema,
|
|
243
|
+
resolved: ConceptIdSchema.optional(),
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// BusyDocument schema (LEGACY) - graph-based representation
|
|
247
|
+
export const LegacyBusyDocumentSchema = ConceptBaseSchemaObject.extend({
|
|
248
|
+
kind: z.literal('document'),
|
|
249
|
+
imports: z.array(ImportDefSchema),
|
|
250
|
+
localdefs: z.array(LocalDefSchema),
|
|
251
|
+
setup: SetupSchema,
|
|
252
|
+
operations: z.array(LegacyOperationSchema)
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// Keep BusyDocumentSchema as the legacy schema for backward compatibility with loader
|
|
256
|
+
export const BusyDocumentSchema = LegacyBusyDocumentSchema;
|
|
257
|
+
|
|
258
|
+
// Playbook schema - extends LegacyBusyDocument with ordered sequence of operations
|
|
259
|
+
export const PlaybookSchema = LegacyBusyDocumentSchema.extend({
|
|
260
|
+
kind: z.literal('playbook'),
|
|
261
|
+
sequence: z.array(ConceptIdSchema), // Ordered array of operation references
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
// Edge schema
|
|
265
|
+
export const EdgeRoleSchema = z.enum(['ref', 'calls', 'extends', 'imports']);
|
|
266
|
+
export const EdgeSchema = z.object({
|
|
267
|
+
from: z.string(),
|
|
268
|
+
to: z.string(),
|
|
269
|
+
role: EdgeRoleSchema,
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// File schema - represents a parsed markdown file with its sections
|
|
273
|
+
export const FileSchema = z.object({
|
|
274
|
+
docId: DocIdSchema,
|
|
275
|
+
path: z.string(),
|
|
276
|
+
name: z.string(),
|
|
277
|
+
sections: z.array(SectionSchema),
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Repo schema (uses legacy schemas for graph functionality)
|
|
281
|
+
export const RepoSchema = z.object({
|
|
282
|
+
files: z.array(FileSchema), // Parsed files with their sections
|
|
283
|
+
concepts: z.array(ConceptBaseSchema), // All concepts (BusyDocuments, Playbooks, etc.)
|
|
284
|
+
localdefs: z.record(LocalDefSchema),
|
|
285
|
+
operations: z.record(LegacyOperationSchema),
|
|
286
|
+
imports: z.array(ImportDefSchema),
|
|
287
|
+
byId: z.record(z.union([SectionSchema, LocalDefSchema, LegacyOperationSchema, ConceptBaseSchema])),
|
|
288
|
+
byFile: z.record( // Renamed from byDoc for clarity
|
|
289
|
+
z.object({
|
|
290
|
+
concept: z.union([LegacyBusyDocumentSchema, PlaybookSchema]), // The concept defined in this file
|
|
291
|
+
bySlug: z.record(SectionSchema),
|
|
292
|
+
})
|
|
293
|
+
),
|
|
294
|
+
edges: z.array(EdgeSchema),
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// ContextPayload schema (uses legacy operation schema)
|
|
298
|
+
export const ContextPayloadSchema = z.object({
|
|
299
|
+
operation: LegacyOperationSchema,
|
|
300
|
+
calls: z.array(ConceptIdSchema),
|
|
301
|
+
symbols: z.record(
|
|
302
|
+
z.object({
|
|
303
|
+
docId: DocIdSchema.optional(),
|
|
304
|
+
slug: SlugSchema.optional(),
|
|
305
|
+
})
|
|
306
|
+
),
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// TypeScript types inferred from schemas
|
|
310
|
+
|
|
311
|
+
// New types (busy-python compatible) - exported at top of file:
|
|
312
|
+
// Metadata, Import, LocalDefinition, Step, Checklist, Trigger,
|
|
313
|
+
// NewOperation (aliased as Operation), Tool, NewBusyDocument (aliased as BusyDocument),
|
|
314
|
+
// ToolDocument
|
|
315
|
+
|
|
316
|
+
// Legacy graph-based types
|
|
317
|
+
export type DocId = z.infer<typeof DocIdSchema>;
|
|
318
|
+
export type Slug = z.infer<typeof SlugSchema>;
|
|
319
|
+
// Section and ConceptBase types defined above to avoid circular references
|
|
320
|
+
export type LegacyBusyDocument = z.infer<typeof LegacyBusyDocumentSchema>;
|
|
321
|
+
export type Playbook = z.infer<typeof PlaybookSchema>;
|
|
322
|
+
export type LocalDef = z.infer<typeof LocalDefSchema>;
|
|
323
|
+
export type LegacyOperation = z.infer<typeof LegacyOperationSchema>;
|
|
324
|
+
export type ImportDef = z.infer<typeof ImportDefSchema>;
|
|
325
|
+
export type EdgeRole = z.infer<typeof EdgeRoleSchema>;
|
|
326
|
+
export type Edge = z.infer<typeof EdgeSchema>;
|
|
327
|
+
export type File = z.infer<typeof FileSchema>;
|
|
328
|
+
export type Repo = z.infer<typeof RepoSchema>;
|
|
329
|
+
export type ContextPayload = z.infer<typeof ContextPayloadSchema>;
|
|
330
|
+
|
|
331
|
+
// Keep legacy types as default for backward compatibility with loader
|
|
332
|
+
export type BusyDocument = LegacyBusyDocument;
|
|
333
|
+
export type Operation = LegacyOperation;
|
|
334
|
+
|
|
335
|
+
// Front-matter schema
|
|
336
|
+
// Type can be:
|
|
337
|
+
// - array of strings (plain): ["Document", "Concept"]
|
|
338
|
+
// - array with markdown links: ["[Document]", "[Concept]"]
|
|
339
|
+
// - single string (we'll normalize to array)
|
|
340
|
+
export const FrontMatterSchema = z.object({
|
|
341
|
+
Name: z.string(),
|
|
342
|
+
Type: z
|
|
343
|
+
.union([z.string(), z.array(z.string())])
|
|
344
|
+
.optional()
|
|
345
|
+
.transform((val) => {
|
|
346
|
+
if (!val) return [];
|
|
347
|
+
if (typeof val === 'string') return [val];
|
|
348
|
+
return val;
|
|
349
|
+
}),
|
|
350
|
+
Extends: z
|
|
351
|
+
.union([z.string(), z.array(z.string())])
|
|
352
|
+
.optional()
|
|
353
|
+
.transform((val) => {
|
|
354
|
+
if (!val) return [];
|
|
355
|
+
if (typeof val === 'string') return [val];
|
|
356
|
+
return val;
|
|
357
|
+
}),
|
|
358
|
+
Description: z.string().optional(),
|
|
359
|
+
Tags: z
|
|
360
|
+
.union([z.string(), z.array(z.string())])
|
|
361
|
+
.optional()
|
|
362
|
+
.transform((val) => {
|
|
363
|
+
if (!val) return [];
|
|
364
|
+
if (typeof val === 'string') return [val];
|
|
365
|
+
return val;
|
|
366
|
+
}),
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
export type FrontMatter = z.infer<typeof FrontMatterSchema>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import createDebug from 'debug';
|
|
2
|
+
|
|
3
|
+
export const debug = {
|
|
4
|
+
parser: createDebug('busy:parser'),
|
|
5
|
+
frontmatter: createDebug('busy:frontmatter'),
|
|
6
|
+
sections: createDebug('busy:sections'),
|
|
7
|
+
localdefs: createDebug('busy:localdefs'),
|
|
8
|
+
imports: createDebug('busy:imports'),
|
|
9
|
+
links: createDebug('busy:links'),
|
|
10
|
+
context: createDebug('busy:context'),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function warn(message: string, context?: { file?: string; line?: number }) {
|
|
14
|
+
const location = context?.file
|
|
15
|
+
? `${context.file}${context.line ? `:${context.line}` : ''}`
|
|
16
|
+
: '';
|
|
17
|
+
console.warn(`[WARN] ${location ? `${location}: ` : ''}${message}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function error(message: string, context?: { file?: string; line?: number }) {
|
|
21
|
+
const location = context?.file
|
|
22
|
+
? `${context.file}${context.line ? `:${context.line}` : ''}`
|
|
23
|
+
: '';
|
|
24
|
+
console.error(`[ERROR] ${location ? `${location}: ` : ''}${message}`);
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import GithubSlugger from 'github-slugger';
|
|
2
|
+
|
|
3
|
+
const slugger = new GithubSlugger();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a Name into a DocId
|
|
7
|
+
* Replaces spaces with underscores and removes dashes
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeDocId(name: string): string {
|
|
10
|
+
return name
|
|
11
|
+
.toLowerCase()
|
|
12
|
+
.replace(/\s+/g, '_')
|
|
13
|
+
.replace(/-/g, '_');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Create a slug from heading text using github-slugger
|
|
18
|
+
*/
|
|
19
|
+
export function createSlug(text: string): string {
|
|
20
|
+
slugger.reset();
|
|
21
|
+
return slugger.slug(text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get basename of a file path without extension
|
|
26
|
+
*/
|
|
27
|
+
export function getBasename(filePath: string): string {
|
|
28
|
+
const parts = filePath.split('/');
|
|
29
|
+
const fileName = parts[parts.length - 1];
|
|
30
|
+
return fileName.replace(/\.md$/, '');
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"declarationMap": true,
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"allowSyntheticDefaultImports": true
|
|
18
|
+
},
|
|
19
|
+
"include": ["src/**/*"],
|
|
20
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
21
|
+
}
|