@intijs/cli 0.1.0 → 0.1.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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@intijs/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Victor Antinori Broce",
7
7
  "homepage": "https://github.com/intijs/inti/tree/main/packages/cli#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/intijs/inti.git",
10
+ "url": "git+https://github.com/intijs/inti.git",
11
11
  "directory": "packages/cli"
12
12
  },
13
13
  "bugs": {
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "description": "CLI for Inti.js — reads your CMS schema and generates TypeScript types for its blocks",
17
17
  "bin": {
18
- "inti": "./bin/inti.js"
18
+ "inti": "bin/inti.js"
19
19
  },
20
20
  "main": "./dist/index.js",
21
21
  "types": "./dist/index.d.ts",
@@ -1,7 +0,0 @@
1
- import type { SchemaDefinition } from '@inti/core/adapters';
2
- /**
3
- * Generate SDK functions from schema
4
- * Creates typed functions for data access
5
- */
6
- export declare function generateSDK(schema: SchemaDefinition): string;
7
- //# sourceMappingURL=sdk-generator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sdk-generator.d.ts","sourceRoot":"","sources":["../../src/generator/sdk-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,qBAAqB,CAAC;AAE3F;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CA+D5D"}
@@ -1,114 +0,0 @@
1
- /**
2
- * Generate SDK functions from schema
3
- * Creates typed functions for data access
4
- */
5
- export function generateSDK(schema) {
6
- const collectionFunctions = schema.collections.map(collection => generateCollectionFunctions(collection));
7
- return `// AUTO-GENERATED BY INTI SYNC - DO NOT EDIT
8
- // Source: ${schema.source}
9
- // Version: ${schema.version}
10
- // Generated at: ${new Date().toISOString()}
11
-
12
- import type { ${schema.collections.map(c => c.name).join(', ')} } from './inti.types';
13
-
14
- // ============================================
15
- // SDK Configuration
16
- // ============================================
17
-
18
- interface SDKConfig {
19
- endpoint: string;
20
- token?: string;
21
- }
22
-
23
- let config: SDKConfig = {
24
- endpoint: process.env.INTI_ENDPOINT || '',
25
- token: process.env.INTI_TOKEN
26
- };
27
-
28
- export function configureSDK(userConfig: SDKConfig) {
29
- config = { ...config, ...userConfig };
30
- }
31
-
32
- // ============================================
33
- // Base Request Helper
34
- // ============================================
35
-
36
- async function request<T>(path: string, options?: RequestInit): Promise<T> {
37
- const url = \`\${config.endpoint}\${path}\`;
38
- const headers: Record<string, string> = {
39
- 'Content-Type': 'application/json',
40
- ...options?.headers as Record<string, string>
41
- };
42
-
43
- if (config.token) {
44
- headers['Authorization'] = \`Bearer \${config.token}\`;
45
- }
46
-
47
- const response = await fetch(url, {
48
- ...options,
49
- headers
50
- });
51
-
52
- if (!response.ok) {
53
- throw new Error(\`API Error: \${response.status} \${response.statusText}\`);
54
- }
55
-
56
- return response.json();
57
- }
58
-
59
- // ============================================
60
- // Collection SDK Functions
61
- // ============================================
62
-
63
- ${collectionFunctions.join('\n\n')}
64
- `;
65
- }
66
- function generateCollectionFunctions(collection) {
67
- const name = collection.name;
68
- const lowerName = name.toLowerCase();
69
- const pluralName = pluralize(name);
70
- const idField = collection.fields.find(f => f.name === 'id');
71
- const slugField = collection.fields.find(f => f.name === 'slug');
72
- let functions = [];
73
- // getAll function
74
- functions.push(`/**
75
- * Get all ${pluralName}
76
- */
77
- export async function get${pluralName}(): Promise<${name}[]> {
78
- return request<${name}[]>('/api/${lowerName}');
79
- }`);
80
- // getById function (if id field exists)
81
- if (idField) {
82
- functions.push(`/**
83
- * Get ${name} by ID
84
- */
85
- export async function get${name}ById(id: string): Promise<${name} | null> {
86
- return request<${name} | null>(\`/api/${lowerName}/\${id}\`);
87
- }`);
88
- }
89
- // getBySlug function (if slug field exists)
90
- if (slugField) {
91
- functions.push(`/**
92
- * Get ${name} by slug
93
- */
94
- export async function get${name}BySlug(slug: string): Promise<${name} | null> {
95
- return request<${name} | null>(\`/api/${lowerName}/slug/\${slug}\`);
96
- }`);
97
- }
98
- return functions.join('\n\n');
99
- }
100
- /**
101
- * Simple pluralization (handles basic cases)
102
- */
103
- function pluralize(word) {
104
- // Handle words ending in y -> ies
105
- if (word.endsWith('y') && !word.endsWith('ay') && !word.endsWith('ey') && !word.endsWith('iy') && !word.endsWith('oy') && !word.endsWith('uy')) {
106
- return word.slice(0, -1) + 'ies';
107
- }
108
- // Handle words ending in s, x, z, ch, sh -> es
109
- if (word.endsWith('s') || word.endsWith('x') || word.endsWith('z') || word.endsWith('ch') || word.endsWith('sh')) {
110
- return word + 'es';
111
- }
112
- // Default: add s
113
- return word + 's';
114
- }