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,442 @@
1
+ import { cleanJsDocComment, ensureDescriptions, findMatchingDelimiter, inferCategoryName, isListingHint, isStringValue, maybeAnnotateMoney, parseStringLiteral, skipStringLiteral, splitTopLevel, } from "./helpers.js";
2
+ function stripLeadingComments(input) {
3
+ let index = 0;
4
+ let lastDoc;
5
+ while (index < input.length) {
6
+ while (index < input.length && /\s/u.test(input[index])) {
7
+ index += 1;
8
+ }
9
+ if (input[index] === "/" && input[index + 1] === "*") {
10
+ const end = input.indexOf("*/", index + 2);
11
+ if (end === -1)
12
+ break;
13
+ const comment = input.slice(index, end + 2);
14
+ if (comment.startsWith("/**")) {
15
+ lastDoc = cleanJsDocComment(comment);
16
+ }
17
+ index = end + 2;
18
+ continue;
19
+ }
20
+ if (input[index] === "/" && input[index + 1] === "/") {
21
+ const nl = input.indexOf("\n", index + 2);
22
+ const end = nl === -1 ? input.length : nl;
23
+ const line = input.slice(index + 2, end).trim();
24
+ if (line.length > 0 && !lastDoc) {
25
+ lastDoc = line;
26
+ }
27
+ index = nl === -1 ? input.length : nl + 1;
28
+ continue;
29
+ }
30
+ break;
31
+ }
32
+ return { rest: input.slice(index), doc: lastDoc };
33
+ }
34
+ function parseChainedCalls(expr) {
35
+ const trimmed = expr.trim();
36
+ const calls = [];
37
+ // Parse the root expression (e.g. z.object({...}), z.string(), Identifier)
38
+ let index = 0;
39
+ while (index < trimmed.length) {
40
+ const ch = trimmed[index];
41
+ if (ch === "'" || ch === '"' || ch === "`") {
42
+ index = skipStringLiteral(trimmed, index);
43
+ continue;
44
+ }
45
+ if (ch === "(") {
46
+ const close = findMatchingDelimiter(trimmed, index, "(", ")");
47
+ if (close === -1)
48
+ break;
49
+ index = close + 1;
50
+ break;
51
+ }
52
+ if (ch === "." && index > 0) {
53
+ // Allow `z.string`, `z.object`, etc. before the first `(`
54
+ const prefix = trimmed.slice(0, index).trim();
55
+ if (prefix !== "z" && prefix !== "zod") {
56
+ break;
57
+ }
58
+ }
59
+ index += 1;
60
+ }
61
+ const base = trimmed.slice(0, index).trim();
62
+ while (index < trimmed.length) {
63
+ while (index < trimmed.length && /\s/u.test(trimmed[index])) {
64
+ index += 1;
65
+ }
66
+ if (trimmed[index] !== ".")
67
+ break;
68
+ index += 1;
69
+ const methodStart = index;
70
+ while (index < trimmed.length && /[A-Za-z0-9_$]/u.test(trimmed[index])) {
71
+ index += 1;
72
+ }
73
+ const method = trimmed.slice(methodStart, index);
74
+ while (index < trimmed.length && /\s/u.test(trimmed[index])) {
75
+ index += 1;
76
+ }
77
+ if (trimmed[index] !== "(")
78
+ break;
79
+ const close = findMatchingDelimiter(trimmed, index, "(", ")");
80
+ if (close === -1)
81
+ break;
82
+ calls.push({ method, args: trimmed.slice(index + 1, close).trim() });
83
+ index = close + 1;
84
+ }
85
+ return { base, calls };
86
+ }
87
+ function extractCallArg(callExpr, prefixPattern) {
88
+ const match = prefixPattern.exec(callExpr);
89
+ if (!match)
90
+ return null;
91
+ const openIndex = match.index + match[0].length - 1;
92
+ const closeIndex = findMatchingDelimiter(callExpr, openIndex, "(", ")");
93
+ if (closeIndex === -1)
94
+ return null;
95
+ return callExpr.slice(openIndex + 1, closeIndex).trim();
96
+ }
97
+ function parseArrayOfStrings(raw) {
98
+ const trimmed = raw.trim();
99
+ if (!trimmed.startsWith("[") || !trimmed.endsWith("]"))
100
+ return null;
101
+ const inner = trimmed.slice(1, -1).trim();
102
+ if (inner.length === 0)
103
+ return [];
104
+ const values = [];
105
+ for (const part of splitTopLevel(inner, ",")) {
106
+ const clean = stripLeadingComments(part).rest.trim();
107
+ if (clean.length === 0)
108
+ continue;
109
+ const parsed = parseStringLiteral(clean);
110
+ if (parsed === null)
111
+ return null;
112
+ values.push(parsed);
113
+ }
114
+ return values;
115
+ }
116
+ function parseFirstNumberArg(args) {
117
+ const first = splitTopLevel(args, ",")[0]?.trim();
118
+ if (!first)
119
+ return null;
120
+ const num = Number(first);
121
+ return Number.isFinite(num) ? num : null;
122
+ }
123
+ function parseZodObjectBody(body, symbols) {
124
+ const properties = {};
125
+ const required = [];
126
+ const entries = splitTopLevel(body, ",");
127
+ for (const rawEntry of entries) {
128
+ const { rest, doc } = stripLeadingComments(rawEntry);
129
+ const trimmed = rest.trim();
130
+ if (trimmed.length === 0)
131
+ continue;
132
+ // Split key : value at top-level colon
133
+ let colonIndex = -1;
134
+ let index = 0;
135
+ while (index < trimmed.length) {
136
+ const ch = trimmed[index];
137
+ if (ch === "'" || ch === '"' || ch === "`") {
138
+ index = skipStringLiteral(trimmed, index);
139
+ continue;
140
+ }
141
+ if (ch === ":") {
142
+ colonIndex = index;
143
+ break;
144
+ }
145
+ index += 1;
146
+ }
147
+ if (colonIndex === -1)
148
+ continue;
149
+ const rawKey = trimmed.slice(0, colonIndex).trim();
150
+ const key = parseStringLiteral(rawKey) ?? rawKey;
151
+ const valueExpr = trimmed.slice(colonIndex + 1).trim();
152
+ if (key.length === 0 || valueExpr.length === 0)
153
+ continue;
154
+ const parsed = parseZodExpression(valueExpr, symbols);
155
+ let propSchema = parsed.schema;
156
+ if (!propSchema.description && doc) {
157
+ propSchema = { ...propSchema, description: doc };
158
+ }
159
+ propSchema = maybeAnnotateMoney(propSchema);
160
+ properties[key] = propSchema;
161
+ if (!parsed.optional) {
162
+ required.push(key);
163
+ }
164
+ }
165
+ const obj = {
166
+ type: "object",
167
+ properties,
168
+ };
169
+ if (required.length > 0) {
170
+ obj.required = required;
171
+ }
172
+ return maybeAnnotateMoney(obj);
173
+ }
174
+ function makeNullable(schema) {
175
+ if (isStringValue(schema.type)) {
176
+ return { ...schema, type: [schema.type, "null"] };
177
+ }
178
+ if (Array.isArray(schema.type)) {
179
+ return schema.type.includes("null")
180
+ ? schema
181
+ : { ...schema, type: [...schema.type, "null"] };
182
+ }
183
+ return schema;
184
+ }
185
+ export function parseZodExpression(expr, symbols = new Map()) {
186
+ const { rest, doc } = stripLeadingComments(expr);
187
+ const { base, calls } = parseChainedCalls(rest);
188
+ let schema = { type: "string" };
189
+ let optional = false;
190
+ if (/^(?:z|zod)\.string\s*\(/u.test(base)) {
191
+ schema = { type: "string" };
192
+ }
193
+ else if (/^(?:z|zod)\.number\s*\(/u.test(base)) {
194
+ schema = { type: "number" };
195
+ }
196
+ else if (/^(?:z|zod)\.boolean\s*\(/u.test(base)) {
197
+ schema = { type: "boolean" };
198
+ }
199
+ else if (/^(?:z|zod)\.date\s*\(/u.test(base)) {
200
+ schema = { type: "string", format: "date-time" };
201
+ }
202
+ else if (/^(?:z|zod)\.enum\s*\(/u.test(base)) {
203
+ const arg = extractCallArg(base, /^(?:z|zod)\.enum\s*\(/u);
204
+ const values = arg ? parseArrayOfStrings(arg) : null;
205
+ schema = values && values.length > 0 ? { type: "string", enum: values } : { type: "string" };
206
+ }
207
+ else if (/^(?:z|zod)\.literal\s*\(/u.test(base)) {
208
+ const arg = extractCallArg(base, /^(?:z|zod)\.literal\s*\(/u);
209
+ const str = arg ? parseStringLiteral(arg) : null;
210
+ if (str !== null) {
211
+ schema = { type: "string", const: str };
212
+ }
213
+ else if (arg === "true" || arg === "false") {
214
+ schema = { type: "boolean", const: arg === "true" };
215
+ }
216
+ else if (arg && Number.isFinite(Number(arg))) {
217
+ schema = { type: "number", const: Number(arg) };
218
+ }
219
+ else {
220
+ schema = { type: "string" };
221
+ }
222
+ }
223
+ else if (/^(?:z|zod)\.array\s*\(/u.test(base)) {
224
+ const arg = extractCallArg(base, /^(?:z|zod)\.array\s*\(/u);
225
+ const inner = arg ? parseZodExpression(arg, symbols).schema : { type: "string" };
226
+ schema = { type: "array", items: inner };
227
+ }
228
+ else if (/^(?:z|zod)\.(?:object|strictObject|looseObject)\s*\(/u.test(base)) {
229
+ const arg = extractCallArg(base, /^(?:z|zod)\.(?:object|strictObject|looseObject)\s*\(/u);
230
+ if (arg && arg.startsWith("{") && arg.endsWith("}")) {
231
+ schema = parseZodObjectBody(arg.slice(1, -1), symbols);
232
+ if (/^(?:z|zod)\.strictObject\s*\(/u.test(base)) {
233
+ schema.additionalProperties = false;
234
+ }
235
+ }
236
+ else {
237
+ schema = { type: "object", properties: {} };
238
+ }
239
+ }
240
+ else if (/^(?:z|zod)\.union\s*\(/u.test(base)) {
241
+ const arg = extractCallArg(base, /^(?:z|zod)\.union\s*\(/u);
242
+ if (arg && arg.startsWith("[") && arg.endsWith("]")) {
243
+ const branches = splitTopLevel(arg.slice(1, -1), ",")
244
+ .map((part) => part.trim())
245
+ .filter((part) => part.length > 0)
246
+ .map((part) => parseZodExpression(part, symbols).schema);
247
+ const allStringConsts = branches.length > 0 &&
248
+ branches.every((branch) => branch.type === "string" && isStringValue(branch.const));
249
+ if (allStringConsts) {
250
+ schema = {
251
+ type: "string",
252
+ enum: branches.map((branch) => String(branch.const)),
253
+ };
254
+ }
255
+ else if (branches.length > 0) {
256
+ schema = { anyOf: branches };
257
+ }
258
+ }
259
+ }
260
+ else if (/^(?:z|zod)\.record\s*\(/u.test(base)) {
261
+ schema = { type: "object" };
262
+ }
263
+ else if (symbols.has(base)) {
264
+ const resolved = symbols.get(base);
265
+ schema = structuredClone(resolved.schema);
266
+ optional = resolved.optional;
267
+ }
268
+ for (const call of calls) {
269
+ switch (call.method) {
270
+ case "int":
271
+ if (schema.type === "number")
272
+ schema.type = "integer";
273
+ break;
274
+ case "optional":
275
+ optional = true;
276
+ break;
277
+ case "default":
278
+ optional = true;
279
+ break;
280
+ case "nullable":
281
+ schema = makeNullable(schema);
282
+ break;
283
+ case "nullish":
284
+ optional = true;
285
+ schema = makeNullable(schema);
286
+ break;
287
+ case "describe": {
288
+ const text = parseStringLiteral(call.args);
289
+ if (text !== null && text.trim().length > 0) {
290
+ schema.description = text.trim();
291
+ }
292
+ break;
293
+ }
294
+ case "min": {
295
+ const value = parseFirstNumberArg(call.args);
296
+ if (value !== null) {
297
+ if (schema.type === "string")
298
+ schema.minLength = value;
299
+ else if (schema.type === "number" || schema.type === "integer")
300
+ schema.minimum = value;
301
+ else if (schema.type === "array")
302
+ schema.minItems = value;
303
+ }
304
+ break;
305
+ }
306
+ case "max": {
307
+ const value = parseFirstNumberArg(call.args);
308
+ if (value !== null) {
309
+ if (schema.type === "string")
310
+ schema.maxLength = value;
311
+ else if (schema.type === "number" || schema.type === "integer")
312
+ schema.maximum = value;
313
+ else if (schema.type === "array")
314
+ schema.maxItems = value;
315
+ }
316
+ break;
317
+ }
318
+ case "positive":
319
+ if (schema.type === "number" || schema.type === "integer")
320
+ schema.minimum = 0;
321
+ break;
322
+ case "nonnegative":
323
+ if (schema.type === "number" || schema.type === "integer")
324
+ schema.minimum = 0;
325
+ break;
326
+ case "email":
327
+ if (schema.type === "string")
328
+ schema.format = "email";
329
+ break;
330
+ case "url":
331
+ if (schema.type === "string")
332
+ schema.format = "uri";
333
+ break;
334
+ case "uuid":
335
+ if (schema.type === "string")
336
+ schema.format = "uuid";
337
+ break;
338
+ case "strict":
339
+ if (schema.type === "object")
340
+ schema.additionalProperties = false;
341
+ break;
342
+ case "array":
343
+ schema = { type: "array", items: schema };
344
+ break;
345
+ default:
346
+ break;
347
+ }
348
+ }
349
+ if (!schema.description && doc) {
350
+ schema.description = doc;
351
+ }
352
+ return { schema, optional };
353
+ }
354
+ function extractTopLevelZodDeclarations(source) {
355
+ const decls = [];
356
+ const pattern = /(?:(\/\*\*[\s\S]*?\*\/)\s*)?(export\s+)?const\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?::[^=]+)?=\s*(?=(?:z|zod)\.)/gu;
357
+ let match;
358
+ while ((match = pattern.exec(source)) !== null) {
359
+ const doc = match[1] ? cleanJsDocComment(match[1]) : undefined;
360
+ const exported = Boolean(match[2]);
361
+ const name = match[3];
362
+ const exprStart = match.index + match[0].length;
363
+ // Walk forward to find end of the chained expression
364
+ let index = exprStart;
365
+ while (index < source.length) {
366
+ const ch = source[index];
367
+ if (ch === "'" || ch === '"' || ch === "`") {
368
+ index = skipStringLiteral(source, index);
369
+ continue;
370
+ }
371
+ if (ch === "(") {
372
+ const close = findMatchingDelimiter(source, index, "(", ")");
373
+ if (close === -1)
374
+ break;
375
+ index = close + 1;
376
+ continue;
377
+ }
378
+ if (ch === "{") {
379
+ const close = findMatchingDelimiter(source, index, "{", "}");
380
+ if (close === -1)
381
+ break;
382
+ index = close + 1;
383
+ continue;
384
+ }
385
+ if (ch === "[") {
386
+ const close = findMatchingDelimiter(source, index, "[", "]");
387
+ if (close === -1)
388
+ break;
389
+ index = close + 1;
390
+ continue;
391
+ }
392
+ if (ch === ";") {
393
+ break;
394
+ }
395
+ if (ch === "\n") {
396
+ const nextSlice = source.slice(index + 1).trimStart();
397
+ if (!nextSlice.startsWith(".")) {
398
+ break;
399
+ }
400
+ }
401
+ index += 1;
402
+ }
403
+ const expr = source.slice(exprStart, index).trim();
404
+ if (expr.length > 0) {
405
+ decls.push({ name, exported, expr, doc });
406
+ }
407
+ pattern.lastIndex = Math.max(pattern.lastIndex, index);
408
+ }
409
+ return decls;
410
+ }
411
+ export function extractZodSchemasFromSource(source, options = {}) {
412
+ const decls = extractTopLevelZodDeclarations(source);
413
+ const symbols = new Map();
414
+ const results = [];
415
+ const fileMatchesHint = options.filePath ? isListingHint(options.filePath) : false;
416
+ for (const decl of decls) {
417
+ const parsed = parseZodExpression(decl.expr, symbols);
418
+ if (decl.doc && !parsed.schema.description) {
419
+ parsed.schema.description = decl.doc;
420
+ }
421
+ symbols.set(decl.name, parsed);
422
+ const isObject = parsed.schema.type === "object" &&
423
+ parsed.schema.properties &&
424
+ Object.keys(parsed.schema.properties).length > 0;
425
+ if (!isObject)
426
+ continue;
427
+ const shouldInclude = options.includeAll ||
428
+ (decl.exported && (isListingHint(decl.name) || fileMatchesHint)) ||
429
+ (!decl.exported && isListingHint(decl.name) && fileMatchesHint);
430
+ if (!shouldInclude)
431
+ continue;
432
+ const category = inferCategoryName(decl.name);
433
+ const { schema, inferredDescriptions } = ensureDescriptions(parsed.schema, category);
434
+ results.push({
435
+ symbolName: decl.name,
436
+ category,
437
+ schema,
438
+ inferredDescriptions,
439
+ });
440
+ }
441
+ return results;
442
+ }