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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/SKILL.md +127 -0
  4. package/dist/api/catalog.js +637 -0
  5. package/dist/api/run.js +960 -0
  6. package/dist/api/search.js +171 -0
  7. package/dist/api/shortcuts.js +799 -0
  8. package/dist/bin.js +648 -0
  9. package/dist/commands/auth.js +513 -0
  10. package/dist/commands/doctor.js +410 -0
  11. package/dist/commands/init.js +306 -0
  12. package/dist/commands/sync.js +214 -0
  13. package/dist/detect.js +214 -0
  14. package/dist/env.js +339 -0
  15. package/dist/goLive.js +629 -0
  16. package/dist/keyLink.js +305 -0
  17. package/dist/mcp/server.js +206 -0
  18. package/dist/mcp/tools.js +689 -0
  19. package/dist/python/template.js +793 -0
  20. package/dist/schema/discover.js +324 -0
  21. package/dist/schema/helpers.js +396 -0
  22. package/dist/schema/prismaToJsonSchema.js +197 -0
  23. package/dist/schema/push.js +570 -0
  24. package/dist/schema/tsToJsonSchema.js +405 -0
  25. package/dist/schema/zodToJsonSchema.js +442 -0
  26. package/dist/templates/openapi.json +1 -0
  27. package/dist/templates/sdk/auth.ts +139 -0
  28. package/dist/templates/sdk/client.ts +1059 -0
  29. package/dist/templates/sdk/errors.ts +76 -0
  30. package/dist/templates/sdk/generated-types.ts +5746 -0
  31. package/dist/templates/sdk/http.ts +359 -0
  32. package/dist/templates/sdk/index.ts +84 -0
  33. package/dist/templates/sdk/json.ts +24 -0
  34. package/dist/templates/sdk/kit.ts +516 -0
  35. package/dist/templates/sdk/multipart.ts +99 -0
  36. package/dist/templates/sdk/sse.ts +131 -0
  37. package/dist/templates/sdk/verify.ts +766 -0
  38. package/dist/templates/sdk-js/auth.d.ts +20 -0
  39. package/dist/templates/sdk-js/auth.js +85 -0
  40. package/dist/templates/sdk-js/client.d.ts +324 -0
  41. package/dist/templates/sdk-js/client.js +607 -0
  42. package/dist/templates/sdk-js/errors.d.ts +51 -0
  43. package/dist/templates/sdk-js/errors.js +48 -0
  44. package/dist/templates/sdk-js/generated-types.d.ts +5736 -0
  45. package/dist/templates/sdk-js/generated-types.js +5 -0
  46. package/dist/templates/sdk-js/http.d.ts +50 -0
  47. package/dist/templates/sdk-js/http.js +263 -0
  48. package/dist/templates/sdk-js/index.d.ts +9 -0
  49. package/dist/templates/sdk-js/index.js +7 -0
  50. package/dist/templates/sdk-js/json.d.ts +11 -0
  51. package/dist/templates/sdk-js/json.js +16 -0
  52. package/dist/templates/sdk-js/kit.d.ts +220 -0
  53. package/dist/templates/sdk-js/kit.js +208 -0
  54. package/dist/templates/sdk-js/multipart.d.ts +23 -0
  55. package/dist/templates/sdk-js/multipart.js +61 -0
  56. package/dist/templates/sdk-js/sse.d.ts +12 -0
  57. package/dist/templates/sdk-js/sse.js +99 -0
  58. package/dist/templates/sdk-js/verify.d.ts +114 -0
  59. package/dist/templates/sdk-js/verify.js +506 -0
  60. package/dist/templates.js +925 -0
  61. package/dist/ui.js +399 -0
  62. package/dist/webhooks/events.js +171 -0
  63. package/dist/webhooks/listen.js +772 -0
  64. package/package.json +32 -4
@@ -0,0 +1,405 @@
1
+ import { cleanJsDocComment, ensureDescriptions, findMatchingDelimiter, inferCategoryName, isListingHint, isStringValue, maybeAnnotateMoney, parseStringLiteral, skipStringLiteral, splitTopLevel, } from "./helpers.js";
2
+ function parseTsTypeExpression(rawType, resolvedTypes) {
3
+ const trimmed = rawType.trim();
4
+ if (trimmed.startsWith("(") && trimmed.endsWith(")")) {
5
+ const matchEnd = findMatchingDelimiter(trimmed, 0, "(", ")");
6
+ if (matchEnd === trimmed.length - 1) {
7
+ return parseTsTypeExpression(trimmed.slice(1, -1), resolvedTypes);
8
+ }
9
+ }
10
+ // Union types: split top-level `|`
11
+ const unionParts = splitTopLevel(trimmed, "|")
12
+ .map((part) => part.trim())
13
+ .filter((part) => part.length > 0);
14
+ if (unionParts.length > 1) {
15
+ let hasUndefined = false;
16
+ let hasNull = false;
17
+ const concrete = [];
18
+ for (const part of unionParts) {
19
+ if (part === "undefined") {
20
+ hasUndefined = true;
21
+ }
22
+ else if (part === "null") {
23
+ hasNull = true;
24
+ }
25
+ else {
26
+ concrete.push(part);
27
+ }
28
+ }
29
+ if (concrete.length === 1) {
30
+ const inner = parseTsTypeExpression(concrete[0], resolvedTypes);
31
+ let schema = inner.schema;
32
+ if (hasNull && isStringValue(schema.type)) {
33
+ schema = { ...schema, type: [schema.type, "null"] };
34
+ }
35
+ return { schema, optionalFromUnion: hasUndefined || inner.optionalFromUnion };
36
+ }
37
+ const literalStrings = [];
38
+ let allStringLiterals = concrete.length > 0;
39
+ for (const part of concrete) {
40
+ const literal = parseStringLiteral(part);
41
+ if (literal === null) {
42
+ allStringLiterals = false;
43
+ break;
44
+ }
45
+ literalStrings.push(literal);
46
+ }
47
+ if (allStringLiterals) {
48
+ const schema = {
49
+ type: hasNull ? ["string", "null"] : "string",
50
+ enum: literalStrings,
51
+ };
52
+ return { schema, optionalFromUnion: hasUndefined };
53
+ }
54
+ const literalNumbers = [];
55
+ let allNumberLiterals = concrete.length > 0;
56
+ for (const part of concrete) {
57
+ if (!/^-?\d+(?:\.\d+)?$/u.test(part)) {
58
+ allNumberLiterals = false;
59
+ break;
60
+ }
61
+ literalNumbers.push(Number(part));
62
+ }
63
+ if (allNumberLiterals) {
64
+ return {
65
+ schema: { type: "number", enum: literalNumbers },
66
+ optionalFromUnion: hasUndefined,
67
+ };
68
+ }
69
+ const branches = concrete.map((part) => parseTsTypeExpression(part, resolvedTypes).schema);
70
+ if (hasNull) {
71
+ branches.push({ type: "null" });
72
+ }
73
+ return {
74
+ schema: { anyOf: branches },
75
+ optionalFromUnion: hasUndefined,
76
+ };
77
+ }
78
+ // Array shorthand: `T[]` or `readonly T[]`
79
+ const withoutReadonly = trimmed.startsWith("readonly ")
80
+ ? trimmed.slice("readonly ".length).trim()
81
+ : trimmed;
82
+ if (withoutReadonly.endsWith("[]")) {
83
+ const innerType = withoutReadonly.slice(0, -2).trim();
84
+ const items = parseTsTypeExpression(innerType, resolvedTypes).schema;
85
+ return { schema: { type: "array", items }, optionalFromUnion: false };
86
+ }
87
+ // `Array<T>` or `ReadonlyArray<T>`
88
+ const arrayMatch = /^(?:Readonly)?Array<([\s\S]+)>$/u.exec(withoutReadonly);
89
+ if (arrayMatch) {
90
+ const items = parseTsTypeExpression(arrayMatch[1], resolvedTypes).schema;
91
+ return { schema: { type: "array", items }, optionalFromUnion: false };
92
+ }
93
+ // Inline object literal: `{ ... }`
94
+ if (withoutReadonly.startsWith("{") && withoutReadonly.endsWith("}")) {
95
+ const obj = parseTsObjectBody(withoutReadonly.slice(1, -1), resolvedTypes);
96
+ return { schema: obj, optionalFromUnion: false };
97
+ }
98
+ // `Record<K, V>`
99
+ if (/^Record<[\s\S]+>$/u.test(withoutReadonly)) {
100
+ return { schema: { type: "object" }, optionalFromUnion: false };
101
+ }
102
+ // String literal
103
+ const singleStringLiteral = parseStringLiteral(withoutReadonly);
104
+ if (singleStringLiteral !== null) {
105
+ return { schema: { type: "string", const: singleStringLiteral }, optionalFromUnion: false };
106
+ }
107
+ // Primitives
108
+ switch (withoutReadonly) {
109
+ case "string":
110
+ return { schema: { type: "string" }, optionalFromUnion: false };
111
+ case "number":
112
+ return { schema: { type: "number" }, optionalFromUnion: false };
113
+ case "bigint":
114
+ return { schema: { type: "integer" }, optionalFromUnion: false };
115
+ case "boolean":
116
+ return { schema: { type: "boolean" }, optionalFromUnion: false };
117
+ case "Date":
118
+ return { schema: { type: "string", format: "date-time" }, optionalFromUnion: false };
119
+ case "null":
120
+ return { schema: { type: "null" }, optionalFromUnion: false };
121
+ default:
122
+ break;
123
+ }
124
+ if (resolvedTypes.has(withoutReadonly)) {
125
+ return {
126
+ schema: structuredClone(resolvedTypes.get(withoutReadonly)),
127
+ optionalFromUnion: false,
128
+ };
129
+ }
130
+ return { schema: { type: "string" }, optionalFromUnion: false };
131
+ }
132
+ function parseTsObjectBody(body, resolvedTypes) {
133
+ const properties = {};
134
+ const required = [];
135
+ let index = 0;
136
+ while (index < body.length) {
137
+ let doc;
138
+ // Skip whitespace and capture doc comments
139
+ while (index < body.length) {
140
+ while (index < body.length && /[\s;,]/u.test(body[index])) {
141
+ index += 1;
142
+ }
143
+ if (body[index] === "/" && body[index + 1] === "*") {
144
+ const end = body.indexOf("*/", index + 2);
145
+ if (end === -1) {
146
+ index = body.length;
147
+ break;
148
+ }
149
+ const rawComment = body.slice(index, end + 2);
150
+ if (rawComment.startsWith("/**")) {
151
+ doc = cleanJsDocComment(rawComment);
152
+ }
153
+ index = end + 2;
154
+ continue;
155
+ }
156
+ if (body[index] === "/" && body[index + 1] === "/") {
157
+ const nl = body.indexOf("\n", index + 2);
158
+ const end = nl === -1 ? body.length : nl;
159
+ const text = body.slice(index + 2, end).trim();
160
+ if (text.length > 0 && !doc) {
161
+ doc = text;
162
+ }
163
+ index = nl === -1 ? body.length : nl + 1;
164
+ continue;
165
+ }
166
+ break;
167
+ }
168
+ if (index >= body.length)
169
+ break;
170
+ // Skip optional `readonly` modifier
171
+ if (body.slice(index).startsWith("readonly ")) {
172
+ index += "readonly ".length;
173
+ }
174
+ // Read property name (identifier or quoted string)
175
+ let propName = "";
176
+ if (body[index] === "'" || body[index] === '"') {
177
+ const endQuote = skipStringLiteral(body, index);
178
+ propName = parseStringLiteral(body.slice(index, endQuote)) ?? "";
179
+ index = endQuote;
180
+ }
181
+ else if (body[index] === "[") {
182
+ // Index signature like `[key: string]: unknown;` — skip to next `;` or newline
183
+ const closeBracket = findMatchingDelimiter(body, index, "[", "]");
184
+ if (closeBracket === -1)
185
+ break;
186
+ index = closeBracket + 1;
187
+ const sep = findMemberEnd(body, index);
188
+ index = sep + 1;
189
+ continue;
190
+ }
191
+ else {
192
+ const nameStart = index;
193
+ while (index < body.length && /[A-Za-z0-9_$]/u.test(body[index])) {
194
+ index += 1;
195
+ }
196
+ propName = body.slice(nameStart, index);
197
+ }
198
+ if (propName.length === 0) {
199
+ index += 1;
200
+ continue;
201
+ }
202
+ while (index < body.length && /\s/u.test(body[index])) {
203
+ index += 1;
204
+ }
205
+ let optional = false;
206
+ if (body[index] === "?") {
207
+ optional = true;
208
+ index += 1;
209
+ }
210
+ while (index < body.length && /\s/u.test(body[index])) {
211
+ index += 1;
212
+ }
213
+ if (body[index] !== ":") {
214
+ // Method signature or unrecognised syntax; skip to end of member
215
+ const sep = findMemberEnd(body, index);
216
+ index = sep + 1;
217
+ continue;
218
+ }
219
+ index += 1;
220
+ const typeStart = index;
221
+ const typeEnd = findMemberEnd(body, typeStart);
222
+ const typeExpr = body.slice(typeStart, typeEnd).trim();
223
+ index = typeEnd + 1;
224
+ if (typeExpr.length === 0)
225
+ continue;
226
+ const { schema: propSchemaRaw, optionalFromUnion } = parseTsTypeExpression(typeExpr, resolvedTypes);
227
+ let propSchema = propSchemaRaw;
228
+ if (doc && !propSchema.description) {
229
+ propSchema = { ...propSchema, description: doc };
230
+ }
231
+ propSchema = maybeAnnotateMoney(propSchema);
232
+ properties[propName] = propSchema;
233
+ if (!optional && !optionalFromUnion) {
234
+ required.push(propName);
235
+ }
236
+ }
237
+ const obj = {
238
+ type: "object",
239
+ properties,
240
+ };
241
+ if (required.length > 0) {
242
+ obj.required = required;
243
+ }
244
+ return maybeAnnotateMoney(obj);
245
+ }
246
+ function findMemberEnd(body, start) {
247
+ let index = start;
248
+ let braceDepth = 0;
249
+ let parenDepth = 0;
250
+ let bracketDepth = 0;
251
+ let angleDepth = 0;
252
+ while (index < body.length) {
253
+ const ch = body[index];
254
+ if (ch === "'" || ch === '"' || ch === "`") {
255
+ index = skipStringLiteral(body, index);
256
+ continue;
257
+ }
258
+ if (ch === "/" && body[index + 1] === "/") {
259
+ const nl = body.indexOf("\n", index + 2);
260
+ if (braceDepth === 0 && parenDepth === 0 && bracketDepth === 0 && angleDepth === 0) {
261
+ return index;
262
+ }
263
+ index = nl === -1 ? body.length : nl + 1;
264
+ continue;
265
+ }
266
+ if (ch === "/" && body[index + 1] === "*") {
267
+ const end = body.indexOf("*/", index + 2);
268
+ index = end === -1 ? body.length : end + 2;
269
+ continue;
270
+ }
271
+ if (ch === "{")
272
+ braceDepth += 1;
273
+ else if (ch === "}")
274
+ braceDepth -= 1;
275
+ else if (ch === "(")
276
+ parenDepth += 1;
277
+ else if (ch === ")")
278
+ parenDepth -= 1;
279
+ else if (ch === "[")
280
+ bracketDepth += 1;
281
+ else if (ch === "]")
282
+ bracketDepth -= 1;
283
+ else if (ch === "<")
284
+ angleDepth += 1;
285
+ else if (ch === ">" && body[index - 1] !== "=")
286
+ angleDepth = Math.max(0, angleDepth - 1);
287
+ else if ((ch === ";" || ch === "\n") &&
288
+ braceDepth === 0 &&
289
+ parenDepth === 0 &&
290
+ bracketDepth === 0 &&
291
+ angleDepth === 0) {
292
+ // If it's a newline, check whether the next non-space token continues a union/intersection
293
+ if (ch === "\n") {
294
+ const after = body.slice(index + 1).trimStart();
295
+ if (after.startsWith("|") || after.startsWith("&")) {
296
+ index += 1;
297
+ continue;
298
+ }
299
+ }
300
+ return index;
301
+ }
302
+ index += 1;
303
+ }
304
+ return body.length;
305
+ }
306
+ function extractTsDeclarations(source) {
307
+ const declarations = [];
308
+ const pattern = /(?:(\/\*\*[\s\S]*?\*\/)\s*)?(export\s+)?(?:(interface)\s+([A-Za-z_$][A-Za-z0-9_$]*)(?:\s+extends\s+[^{]+)?\s*\{|(type)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*)/gu;
309
+ let match;
310
+ while ((match = pattern.exec(source)) !== null) {
311
+ const doc = match[1] ? cleanJsDocComment(match[1]) : undefined;
312
+ const exported = Boolean(match[2]);
313
+ if (match[3] === "interface") {
314
+ const name = match[4];
315
+ const openBrace = match.index + match[0].length - 1;
316
+ const closeBrace = findMatchingDelimiter(source, openBrace, "{", "}");
317
+ if (closeBrace === -1)
318
+ continue;
319
+ declarations.push({
320
+ name,
321
+ exported,
322
+ kind: "interface",
323
+ body: source.slice(openBrace, closeBrace + 1),
324
+ doc,
325
+ });
326
+ pattern.lastIndex = closeBrace + 1;
327
+ }
328
+ else if (match[5] === "type") {
329
+ const name = match[6];
330
+ const rhsStart = match.index + match[0].length;
331
+ let index = rhsStart;
332
+ while (index < source.length && /\s/u.test(source[index])) {
333
+ index += 1;
334
+ }
335
+ if (source[index] === "{") {
336
+ const closeBrace = findMatchingDelimiter(source, index, "{", "}");
337
+ if (closeBrace === -1)
338
+ continue;
339
+ declarations.push({
340
+ name,
341
+ exported,
342
+ kind: "type",
343
+ body: source.slice(index, closeBrace + 1),
344
+ doc,
345
+ });
346
+ pattern.lastIndex = closeBrace + 1;
347
+ }
348
+ else {
349
+ const end = findMemberEnd(source, index);
350
+ declarations.push({
351
+ name,
352
+ exported,
353
+ kind: "type",
354
+ body: source.slice(index, end).trim(),
355
+ doc,
356
+ });
357
+ pattern.lastIndex = Math.min(source.length, end + 1);
358
+ }
359
+ }
360
+ }
361
+ return declarations;
362
+ }
363
+ export function extractTypeScriptSchemasFromSource(source, options = {}) {
364
+ const decls = extractTsDeclarations(source);
365
+ const resolvedTypes = new Map();
366
+ const results = [];
367
+ const fileMatchesHint = options.filePath ? isListingHint(options.filePath) : false;
368
+ // First pass: resolve helper type aliases (enums, unions, nested types)
369
+ for (const decl of decls) {
370
+ const parsed = parseTsTypeExpression(decl.body, resolvedTypes).schema;
371
+ if (decl.doc && !parsed.description) {
372
+ parsed.description = decl.doc;
373
+ }
374
+ resolvedTypes.set(decl.name, parsed);
375
+ }
376
+ // Second pass: re-parse object declarations with full symbol table so forward references work
377
+ for (const decl of decls) {
378
+ if (!decl.body.trim().startsWith("{"))
379
+ continue;
380
+ const parsed = parseTsTypeExpression(decl.body, resolvedTypes).schema;
381
+ if (decl.doc && !parsed.description) {
382
+ parsed.description = decl.doc;
383
+ }
384
+ resolvedTypes.set(decl.name, parsed);
385
+ const hasProperties = parsed.type === "object" &&
386
+ parsed.properties &&
387
+ Object.keys(parsed.properties).length > 0;
388
+ if (!hasProperties)
389
+ continue;
390
+ const shouldInclude = options.includeAll ||
391
+ (decl.exported && (isListingHint(decl.name) || fileMatchesHint)) ||
392
+ (!decl.exported && isListingHint(decl.name) && fileMatchesHint);
393
+ if (!shouldInclude)
394
+ continue;
395
+ const category = inferCategoryName(decl.name);
396
+ const { schema, inferredDescriptions } = ensureDescriptions(parsed, category);
397
+ results.push({
398
+ symbolName: decl.name,
399
+ category,
400
+ schema,
401
+ inferredDescriptions,
402
+ });
403
+ }
404
+ return results;
405
+ }