pcific 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +50 -2
- package/dist/SKILL.md +127 -0
- package/dist/api/catalog.js +637 -0
- package/dist/api/run.js +960 -0
- package/dist/api/search.js +171 -0
- package/dist/api/shortcuts.js +799 -0
- package/dist/bin.js +648 -0
- package/dist/commands/auth.js +513 -0
- package/dist/commands/doctor.js +410 -0
- package/dist/commands/init.js +306 -0
- package/dist/commands/sync.js +214 -0
- package/dist/detect.js +214 -0
- package/dist/env.js +339 -0
- package/dist/goLive.js +629 -0
- package/dist/keyLink.js +305 -0
- package/dist/mcp/server.js +206 -0
- package/dist/mcp/tools.js +689 -0
- package/dist/python/template.js +793 -0
- package/dist/schema/discover.js +324 -0
- package/dist/schema/helpers.js +396 -0
- package/dist/schema/prismaToJsonSchema.js +197 -0
- package/dist/schema/push.js +570 -0
- package/dist/schema/tsToJsonSchema.js +405 -0
- package/dist/schema/zodToJsonSchema.js +442 -0
- package/dist/templates/openapi.json +1 -0
- package/dist/templates/sdk/auth.ts +139 -0
- package/dist/templates/sdk/client.ts +1059 -0
- package/dist/templates/sdk/errors.ts +76 -0
- package/dist/templates/sdk/generated-types.ts +5746 -0
- package/dist/templates/sdk/http.ts +359 -0
- package/dist/templates/sdk/index.ts +84 -0
- package/dist/templates/sdk/json.ts +24 -0
- package/dist/templates/sdk/kit.ts +516 -0
- package/dist/templates/sdk/multipart.ts +99 -0
- package/dist/templates/sdk/sse.ts +131 -0
- package/dist/templates/sdk/verify.ts +766 -0
- package/dist/templates/sdk-js/auth.d.ts +20 -0
- package/dist/templates/sdk-js/auth.js +85 -0
- package/dist/templates/sdk-js/client.d.ts +324 -0
- package/dist/templates/sdk-js/client.js +607 -0
- package/dist/templates/sdk-js/errors.d.ts +51 -0
- package/dist/templates/sdk-js/errors.js +48 -0
- package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
- package/dist/templates/sdk-js/generated-types.js +5 -0
- package/dist/templates/sdk-js/http.d.ts +50 -0
- package/dist/templates/sdk-js/http.js +263 -0
- package/dist/templates/sdk-js/index.d.ts +9 -0
- package/dist/templates/sdk-js/index.js +7 -0
- package/dist/templates/sdk-js/json.d.ts +11 -0
- package/dist/templates/sdk-js/json.js +16 -0
- package/dist/templates/sdk-js/kit.d.ts +220 -0
- package/dist/templates/sdk-js/kit.js +208 -0
- package/dist/templates/sdk-js/multipart.d.ts +23 -0
- package/dist/templates/sdk-js/multipart.js +61 -0
- package/dist/templates/sdk-js/sse.d.ts +12 -0
- package/dist/templates/sdk-js/sse.js +99 -0
- package/dist/templates/sdk-js/verify.d.ts +114 -0
- package/dist/templates/sdk-js/verify.js +506 -0
- package/dist/templates.js +925 -0
- package/dist/ui.js +399 -0
- package/dist/webhooks/events.js +171 -0
- package/dist/webhooks/listen.js +772 -0
- package/package.json +32 -4
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, extname, join, relative, resolve } from "node:path";
|
|
3
|
+
import { countSchemaFields, ensureDescriptions, inferCategoryName, isJsonObjectValue, parseJsonText, } from "./helpers.js";
|
|
4
|
+
import { extractPrismaSchemasFromSource } from "./prismaToJsonSchema.js";
|
|
5
|
+
import { extractTypeScriptSchemasFromSource } from "./tsToJsonSchema.js";
|
|
6
|
+
import { extractZodSchemasFromSource } from "./zodToJsonSchema.js";
|
|
7
|
+
const IGNORED_DIRS = new Set([
|
|
8
|
+
"node_modules",
|
|
9
|
+
".git",
|
|
10
|
+
"dist",
|
|
11
|
+
".next",
|
|
12
|
+
".astro",
|
|
13
|
+
"build",
|
|
14
|
+
"coverage",
|
|
15
|
+
".venv",
|
|
16
|
+
"__pycache__",
|
|
17
|
+
]);
|
|
18
|
+
const CODE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".mjs"]);
|
|
19
|
+
function isTestOrDeclarationFile(fileName) {
|
|
20
|
+
return (fileName.endsWith(".d.ts") ||
|
|
21
|
+
/\.(test|spec)\.(ts|tsx|js|mjs)$/u.test(fileName));
|
|
22
|
+
}
|
|
23
|
+
function isJsonSchemaCandidatePath(relPath) {
|
|
24
|
+
const normalized = relPath.replace(/\\/gu, "/");
|
|
25
|
+
if (normalized.endsWith(".pcific.schema.json"))
|
|
26
|
+
return true;
|
|
27
|
+
if (/^(?:pcific\/schemas|schemas)\/[^/]+\.json$/u.test(normalized)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function collectFiles(rootDir) {
|
|
33
|
+
const collected = [];
|
|
34
|
+
function walk(currentDir) {
|
|
35
|
+
let entries;
|
|
36
|
+
try {
|
|
37
|
+
entries = readdirSync(currentDir, { withFileTypes: true });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
if (entry.isDirectory()) {
|
|
44
|
+
if (IGNORED_DIRS.has(entry.name))
|
|
45
|
+
continue;
|
|
46
|
+
walk(join(currentDir, entry.name));
|
|
47
|
+
}
|
|
48
|
+
else if (entry.isFile()) {
|
|
49
|
+
collected.push(join(currentDir, entry.name));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
walk(rootDir);
|
|
54
|
+
return collected.sort();
|
|
55
|
+
}
|
|
56
|
+
function parseJsonSchemaFile(absPath, relPath, overrideCategory) {
|
|
57
|
+
let rawText;
|
|
58
|
+
try {
|
|
59
|
+
rawText = readFileSync(absPath, "utf8");
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
schema: null,
|
|
64
|
+
warning: `Could not read ${relPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = parseJsonText(rawText);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
schema: null,
|
|
74
|
+
warning: `Skipped invalid JSON file ${relPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!isJsonObjectValue(parsed) || !isJsonObjectValue(parsed.properties)) {
|
|
78
|
+
return { schema: null };
|
|
79
|
+
}
|
|
80
|
+
const fileName = basename(absPath);
|
|
81
|
+
const category = overrideCategory ?? inferCategoryName(fileName);
|
|
82
|
+
// SAFETY: Verified parsed is a plain JSON object with a plain-object `properties` map.
|
|
83
|
+
const rawSchema = parsed;
|
|
84
|
+
const { schema, inferredDescriptions } = ensureDescriptions(rawSchema, category);
|
|
85
|
+
const fieldCount = countSchemaFields(schema);
|
|
86
|
+
if (fieldCount === 0) {
|
|
87
|
+
return { schema: null };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
schema: {
|
|
91
|
+
category,
|
|
92
|
+
source: "json-schema",
|
|
93
|
+
filePath: relPath,
|
|
94
|
+
symbolName: fileName,
|
|
95
|
+
schema,
|
|
96
|
+
fieldCount,
|
|
97
|
+
inferredDescriptions,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function discoverFromSingleFile(absPath, relPath, options) {
|
|
102
|
+
const warnings = [];
|
|
103
|
+
const ext = extname(absPath).toLowerCase();
|
|
104
|
+
if (ext === ".json") {
|
|
105
|
+
const result = parseJsonSchemaFile(absPath, relPath, options.category);
|
|
106
|
+
if (result.warning)
|
|
107
|
+
warnings.push(result.warning);
|
|
108
|
+
return {
|
|
109
|
+
schemas: result.schema ? [result.schema] : [],
|
|
110
|
+
warnings,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
let source;
|
|
114
|
+
try {
|
|
115
|
+
source = readFileSync(absPath, "utf8");
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return {
|
|
119
|
+
schemas: [],
|
|
120
|
+
warnings: [
|
|
121
|
+
`Could not read ${relPath}: ${error instanceof Error ? error.message : String(error)}`,
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (ext === ".prisma") {
|
|
126
|
+
const candidates = extractPrismaSchemasFromSource(source, {
|
|
127
|
+
model: options.model,
|
|
128
|
+
includeAll: !options.model,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
schemas: candidates.map((candidate) => ({
|
|
132
|
+
category: options.category && candidates.length === 1
|
|
133
|
+
? options.category
|
|
134
|
+
: candidate.category,
|
|
135
|
+
source: "prisma",
|
|
136
|
+
filePath: relPath,
|
|
137
|
+
symbolName: candidate.symbolName,
|
|
138
|
+
schema: candidate.schema,
|
|
139
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
140
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
141
|
+
})),
|
|
142
|
+
warnings,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (CODE_EXTENSIONS.has(ext)) {
|
|
146
|
+
const schemas = [];
|
|
147
|
+
const zodCandidates = extractZodSchemasFromSource(source, {
|
|
148
|
+
filePath: relPath,
|
|
149
|
+
includeAll: true,
|
|
150
|
+
});
|
|
151
|
+
for (const candidate of zodCandidates) {
|
|
152
|
+
schemas.push({
|
|
153
|
+
category: options.category && zodCandidates.length === 1
|
|
154
|
+
? options.category
|
|
155
|
+
: candidate.category,
|
|
156
|
+
source: "zod",
|
|
157
|
+
filePath: relPath,
|
|
158
|
+
symbolName: candidate.symbolName,
|
|
159
|
+
schema: candidate.schema,
|
|
160
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
161
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (ext === ".ts" || ext === ".tsx") {
|
|
165
|
+
const tsCandidates = extractTypeScriptSchemasFromSource(source, {
|
|
166
|
+
filePath: relPath,
|
|
167
|
+
includeAll: true,
|
|
168
|
+
});
|
|
169
|
+
const seenSymbols = new Set(schemas.map((entry) => entry.symbolName.toLowerCase()));
|
|
170
|
+
for (const candidate of tsCandidates) {
|
|
171
|
+
if (seenSymbols.has(candidate.symbolName.toLowerCase()))
|
|
172
|
+
continue;
|
|
173
|
+
schemas.push({
|
|
174
|
+
category: options.category && schemas.length === 0 && tsCandidates.length === 1
|
|
175
|
+
? options.category
|
|
176
|
+
: candidate.category,
|
|
177
|
+
source: "typescript",
|
|
178
|
+
filePath: relPath,
|
|
179
|
+
symbolName: candidate.symbolName,
|
|
180
|
+
schema: candidate.schema,
|
|
181
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
182
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { schemas, warnings };
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
schemas: [],
|
|
190
|
+
warnings: [
|
|
191
|
+
`Unsupported schema file extension "${ext}" for ${relPath}. Supported formats: .json, .ts, .tsx, .js, .mjs, .prisma.`,
|
|
192
|
+
],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export function discoverSchemas(options) {
|
|
196
|
+
const rootDir = resolve(options.cwd);
|
|
197
|
+
if (options.file) {
|
|
198
|
+
const absPath = resolve(rootDir, options.file);
|
|
199
|
+
const relPath = relative(rootDir, absPath) || basename(absPath);
|
|
200
|
+
try {
|
|
201
|
+
const stat = statSync(absPath);
|
|
202
|
+
if (!stat.isFile()) {
|
|
203
|
+
return {
|
|
204
|
+
schemas: [],
|
|
205
|
+
warnings: [`"${options.file}" is not a file. Pass a path to a JSON Schema, TypeScript, Zod, or Prisma file.`],
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return {
|
|
211
|
+
schemas: [],
|
|
212
|
+
warnings: [`File not found: ${options.file}. Check the path and try again.`],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return discoverFromSingleFile(absPath, relPath, options);
|
|
216
|
+
}
|
|
217
|
+
const allFiles = collectFiles(rootDir);
|
|
218
|
+
const warnings = [];
|
|
219
|
+
const discovered = [];
|
|
220
|
+
// 1. Existing JSON Schema files first (highest precedence)
|
|
221
|
+
for (const absPath of allFiles) {
|
|
222
|
+
const relPath = relative(rootDir, absPath);
|
|
223
|
+
if (!isJsonSchemaCandidatePath(relPath))
|
|
224
|
+
continue;
|
|
225
|
+
const result = parseJsonSchemaFile(absPath, relPath);
|
|
226
|
+
if (result.warning)
|
|
227
|
+
warnings.push(result.warning);
|
|
228
|
+
if (result.schema)
|
|
229
|
+
discovered.push(result.schema);
|
|
230
|
+
}
|
|
231
|
+
// 2. Zod schemas and 3. TypeScript interfaces/types
|
|
232
|
+
for (const absPath of allFiles) {
|
|
233
|
+
const ext = extname(absPath).toLowerCase();
|
|
234
|
+
if (!CODE_EXTENSIONS.has(ext))
|
|
235
|
+
continue;
|
|
236
|
+
const fileName = basename(absPath);
|
|
237
|
+
if (isTestOrDeclarationFile(fileName))
|
|
238
|
+
continue;
|
|
239
|
+
const relPath = relative(rootDir, absPath);
|
|
240
|
+
let source;
|
|
241
|
+
try {
|
|
242
|
+
source = readFileSync(absPath, "utf8");
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const firstLine = source.split(/\r?\n/u, 1)[0] ?? "";
|
|
248
|
+
if (firstLine.includes("@pcific-generated"))
|
|
249
|
+
continue;
|
|
250
|
+
if (/(?:z|zod)\.(?:object|strictObject|looseObject)\s*\(/u.test(source)) {
|
|
251
|
+
const zodCandidates = extractZodSchemasFromSource(source, { filePath: relPath });
|
|
252
|
+
for (const candidate of zodCandidates) {
|
|
253
|
+
discovered.push({
|
|
254
|
+
category: candidate.category,
|
|
255
|
+
source: "zod",
|
|
256
|
+
filePath: relPath,
|
|
257
|
+
symbolName: candidate.symbolName,
|
|
258
|
+
schema: candidate.schema,
|
|
259
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
260
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (ext === ".ts" || ext === ".tsx") {
|
|
265
|
+
const tsCandidates = extractTypeScriptSchemasFromSource(source, { filePath: relPath });
|
|
266
|
+
for (const candidate of tsCandidates) {
|
|
267
|
+
discovered.push({
|
|
268
|
+
category: candidate.category,
|
|
269
|
+
source: "typescript",
|
|
270
|
+
filePath: relPath,
|
|
271
|
+
symbolName: candidate.symbolName,
|
|
272
|
+
schema: candidate.schema,
|
|
273
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
274
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// 4. Prisma schema
|
|
280
|
+
for (const absPath of allFiles) {
|
|
281
|
+
const relPath = relative(rootDir, absPath).replace(/\\/gu, "/");
|
|
282
|
+
if (relPath !== "prisma/schema.prisma" && !relPath.endsWith("/prisma/schema.prisma")) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
let source;
|
|
286
|
+
try {
|
|
287
|
+
source = readFileSync(absPath, "utf8");
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const firstLine = source.split(/\r?\n/u, 1)[0] ?? "";
|
|
293
|
+
if (firstLine.includes("@pcific-generated"))
|
|
294
|
+
continue;
|
|
295
|
+
const prismaCandidates = extractPrismaSchemasFromSource(source, {
|
|
296
|
+
model: options.model,
|
|
297
|
+
});
|
|
298
|
+
for (const candidate of prismaCandidates) {
|
|
299
|
+
discovered.push({
|
|
300
|
+
category: candidate.category,
|
|
301
|
+
source: "prisma",
|
|
302
|
+
filePath: relPath,
|
|
303
|
+
symbolName: candidate.symbolName,
|
|
304
|
+
schema: candidate.schema,
|
|
305
|
+
fieldCount: countSchemaFields(candidate.schema),
|
|
306
|
+
inferredDescriptions: candidate.inferredDescriptions,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Deduplicate by category (case-insensitive), preferring earlier sources (json-schema > zod > typescript > prisma)
|
|
311
|
+
const deduped = [];
|
|
312
|
+
const seenCategories = new Set();
|
|
313
|
+
for (const entry of discovered) {
|
|
314
|
+
const key = entry.category.toLowerCase();
|
|
315
|
+
if (seenCategories.has(key))
|
|
316
|
+
continue;
|
|
317
|
+
seenCategories.add(key);
|
|
318
|
+
deduped.push(entry);
|
|
319
|
+
}
|
|
320
|
+
if (options.category && deduped.length === 1) {
|
|
321
|
+
deduped[0] = { ...deduped[0], category: options.category };
|
|
322
|
+
}
|
|
323
|
+
return { schemas: deduped, warnings };
|
|
324
|
+
}
|