Skip to content

Commit a38c977

Browse files
Copilothotlong
andcommitted
Convert basic examples to proper package with typecheck support
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 81ec69e commit a38c977

10 files changed

Lines changed: 123 additions & 41 deletions

examples/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ pnpm --filter @objectstack/example-todo typecheck
6060

6161
### Use Basic Examples
6262

63-
The [basic/](./basic/) examples are TypeScript files that demonstrate protocols:
63+
The [basic/](./basic/) examples are now a proper package for type checking:
6464

6565
```bash
66-
# Type check a basic example (requires @objectstack/spec built)
66+
# Type check basic examples
67+
pnpm --filter @objectstack/example-basic typecheck
68+
69+
# Run a specific example with tsx
6770
npx tsx examples/basic/stack-definition-example.ts
6871
```
6972

examples/basic/README.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
# Basic Protocol Examples
22

3-
This directory contains standalone examples demonstrating core ObjectStack protocols and features.
3+
A standalone package containing comprehensive examples demonstrating core ObjectStack protocols and features.
4+
5+
## 📦 Package Information
6+
7+
- **Package**: `@objectstack/example-basic`
8+
- **Type**: Demonstration/Reference
9+
- **Status**: Standalone examples with type checking
10+
11+
## 🚀 Usage
12+
13+
### Build and Type Check
14+
15+
```bash
16+
# From monorepo root
17+
pnpm install
18+
19+
# Build the spec package first
20+
pnpm --filter @objectstack/spec build
21+
22+
# Type check the examples
23+
pnpm --filter @objectstack/example-basic typecheck
24+
25+
# Or run directly with tsx
26+
npx tsx examples/basic/stack-definition-example.ts
27+
```
28+
29+
### Running Examples
30+
31+
Each example file can be run independently with `tsx`:
32+
33+
```bash
34+
# Run a specific example
35+
npx tsx examples/basic/ai-rag-example.ts
36+
37+
# Or uncomment the demonstration function calls at the end of each file
38+
```
439

540
## 📚 Examples
641

@@ -110,20 +145,20 @@ Shows automation capabilities in ObjectStack:
110145

111146
## 🎯 Usage
112147

113-
These examples are TypeScript files that can be:
148+
These examples are TypeScript files in a proper package that can be:
114149

115-
1. **Imported as references:**
116-
```typescript
117-
import { taskManagementStack } from './examples/basic/stack-definition-example';
150+
1. **Type checked:**
151+
```bash
152+
pnpm --filter @objectstack/example-basic typecheck
118153
```
119154

120-
2. **Run directly (if configured):**
155+
2. **Run directly:**
121156
```bash
122-
tsx examples/basic/stack-definition-example.ts
157+
npx tsx examples/basic/stack-definition-example.ts
123158
```
124159

125-
3. **Used as templates:**
126-
Copy and modify for your own projects
160+
3. **Used as references:**
161+
Import types and patterns in your own projects
127162

128163
## 🔗 Related Resources
129164

examples/basic/ai-rag-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ export const advancedRAGPatterns = {
379379
// Usage
380380
// ============================================================================
381381

382-
// Demonstrate RAG usage
383-
demonstrateRAGUsage();
382+
// Demonstrate RAG usage (uncomment to run)
383+
// demonstrateRAGUsage();
384384

385385
// Export all examples
386386
export default {

examples/basic/api-discovery-example.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,15 +439,13 @@ When helping users, respect these capabilities and limits.`;
439439
// Usage Examples
440440
// ============================================================================
441441

442-
// Example: Initialize adaptive client
443-
const client = new AdaptiveClient();
442+
// Example: Initialize adaptive client (uncomment to run)
443+
// const client = new AdaptiveClient();
444444
// await client.initialize('https://api.example.com');
445+
// if (client.hasFeature('data', 'vectorSearch')) {
446+
// console.log('✅ Vector search is available - AI/RAG features enabled');
447+
// }
445448

446-
// Example: Check features before using them
447-
if (client.hasFeature('data', 'vectorSearch')) {
448-
console.log('✅ Vector search is available - AI/RAG features enabled');
449-
}
450-
451-
// Example: Generate AI prompt
452-
const systemPrompt = generateSystemPromptFromDiscovery(fullDiscoveryResponse);
453-
console.log('AI System Prompt:\n', systemPrompt);
449+
// Example: Generate AI prompt (uncomment to run)
450+
// const systemPrompt = generateSystemPromptFromDiscovery(fullDiscoveryResponse);
451+
// console.log('AI System Prompt:\n', systemPrompt);

examples/basic/auth-permission-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ export function demonstratePermissions() {
552552
console.log('- Can access own opportunity:', checker.canAccessRecord(user, 'opportunity', opportunity));
553553
}
554554

555-
// Run demonstration
556-
demonstratePermissions();
555+
// Run demonstration (uncomment to run)
556+
// demonstratePermissions();
557557

558558
// Export all examples
559559
export default {

examples/basic/automation-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ export function demonstrateAutomation() {
704704
console.log(` - Source: ${dailyLeadImportETL.extract?.source.type}`);
705705
}
706706

707-
// Run demonstration
708-
demonstrateAutomation();
707+
// Run demonstration (uncomment to run)
708+
// demonstrateAutomation();
709709

710710
// Export all examples
711711
export default {

examples/basic/capabilities-example.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,24 +393,24 @@ export function getEnabledCapabilities(
393393
}
394394

395395
// ============================================================================
396-
// Usage Examples
396+
// Usage Examples (uncomment to run)
397397
// ============================================================================
398398

399399
// Example: Check if vector search is available
400-
if (hasCapability(productionCapabilities, 'data', 'vectorSearch')) {
401-
console.log('✅ Vector search is available for RAG workflows');
402-
}
400+
// if (hasCapability(productionCapabilities, 'data', 'vectorSearch')) {
401+
// console.log('✅ Vector search is available for RAG workflows');
402+
// }
403403

404404
// Example: Get all enabled ObjectUI capabilities
405-
const uiFeatures = getEnabledCapabilities(productionCapabilities, 'ui');
406-
console.log('Enabled UI features:', uiFeatures);
405+
// const uiFeatures = getEnabledCapabilities(productionCapabilities, 'ui');
406+
// console.log('Enabled UI features:', uiFeatures);
407407

408408
// Example: Compare capabilities between environments
409-
console.log(
410-
'Production has GraphQL?',
411-
hasCapability(productionCapabilities, 'system', 'graphqlApi')
412-
);
413-
console.log(
414-
'Development has GraphQL?',
415-
hasCapability(developmentCapabilities, 'system', 'graphqlApi')
416-
);
409+
// console.log(
410+
// 'Production has GraphQL?',
411+
// hasCapability(productionCapabilities, 'system', 'graphqlApi')
412+
// );
413+
// console.log(
414+
// 'Development has GraphQL?',
415+
// hasCapability(developmentCapabilities, 'system', 'graphqlApi')
416+
// );

examples/basic/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@objectstack/example-basic",
3+
"version": "0.6.1",
4+
"description": "Basic protocol examples demonstrating ObjectStack core features",
5+
"private": true,
6+
"type": "module",
7+
"scripts": {
8+
"build": "tsc --noEmit",
9+
"typecheck": "tsc --noEmit"
10+
},
11+
"dependencies": {
12+
"@objectstack/spec": "workspace:*"
13+
},
14+
"devDependencies": {
15+
"typescript": "^5.0.0",
16+
"tsx": "^4.21.0"
17+
}
18+
}

examples/basic/stack-definition-example.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ export function demonstrateStackUsage() {
489489
}
490490
}
491491

492+
// Run demonstration (uncomment to run)
493+
// demonstrateStackUsage();
494+
492495
// ============================================================================
493496
// Export for use
494497
// ============================================================================

examples/basic/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist",
5+
"rootDir": ".",
6+
"module": "ESNext",
7+
"moduleResolution": "bundler",
8+
"target": "ES2022",
9+
"lib": ["ES2022"],
10+
"strict": true,
11+
"esModuleInterop": true,
12+
"skipLibCheck": true,
13+
"forceConsistentCasingInFileNames": true,
14+
"resolveJsonModule": true,
15+
"declaration": false,
16+
"noEmit": true
17+
},
18+
"include": [
19+
"*.ts"
20+
],
21+
"exclude": [
22+
"node_modules",
23+
"dist"
24+
]
25+
}

0 commit comments

Comments
 (0)