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,396 @@
1
+ import { parseDotEnv, readMergedEnv } from "../api/run.js";
2
+ export function isStringValue(value) {
3
+ return typeof value === "string";
4
+ }
5
+ export function isJsonObjectValue(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ export function parseJsonText(text) {
9
+ // SAFETY: JSON.parse returns only JSON primitives, arrays, or plain objects matching JsonSchemaValue.
10
+ return JSON.parse(text);
11
+ }
12
+ export const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
13
+ const UNIT_MAP = new Map([
14
+ ["pence", "in pence"],
15
+ ["cents", "in cents"],
16
+ ["gbp", "in GBP"],
17
+ ["usd", "in USD"],
18
+ ["eur", "in EUR"],
19
+ ["gb", "in GB"],
20
+ ["mb", "in MB"],
21
+ ["tb", "in TB"],
22
+ ["km", "in km"],
23
+ ["mi", "in miles"],
24
+ ["cm", "in cm"],
25
+ ["mm", "in mm"],
26
+ ["kg", "in kg"],
27
+ ["grams", "in grams"],
28
+ ["oz", "in oz"],
29
+ ["lbs", "in lbs"],
30
+ ["pct", "as a percentage"],
31
+ ["percent", "as a percentage"],
32
+ ["ms", "in milliseconds"],
33
+ ["secs", "in seconds"],
34
+ ["seconds", "in seconds"],
35
+ ["mins", "in minutes"],
36
+ ["hours", "in hours"],
37
+ ["days", "in days"],
38
+ ["years", "in years"],
39
+ ]);
40
+ const KNOWN_FIELD_DESCRIPTIONS = new Map([
41
+ ["title", "Title of the item"],
42
+ ["name", "Name of the item"],
43
+ ["description", "Description of the item"],
44
+ ["brand", "Brand of the item"],
45
+ ["make", "Make of the item"],
46
+ ["model", "Model of the item"],
47
+ ["condition", "Condition of the item"],
48
+ ["colour", "Colour of the item"],
49
+ ["color", "Color of the item"],
50
+ ["size", "Size of the item"],
51
+ ["sku", "Stock keeping unit identifier for the item"],
52
+ ["ean", "EAN barcode number for the item"],
53
+ ["upc", "UPC barcode number for the item"],
54
+ ["imei", "IMEI number of the device"],
55
+ ["serial", "Serial number of the item"],
56
+ ["currency", "Three-letter ISO currency code"],
57
+ ["amount", "Price amount in the smallest currency unit"],
58
+ ["price", "Asking price of the item"],
59
+ ["mileage", "Mileage recorded on the item"],
60
+ ["year", "Manufacture year of the item"],
61
+ ["quantity", "Available quantity of the item"],
62
+ ["location", "Location of the item"],
63
+ ["postcode", "Postal code where the item is located"],
64
+ ["notes", "Additional seller notes about the item"],
65
+ ["tags", "Tags describing the item"],
66
+ ["images", "Photo URLs or identifiers for the item"],
67
+ ]);
68
+ const ACRONYMS = new Set(["gb", "mb", "tb", "gbp", "usd", "eur", "sku", "ean", "upc", "imei", "vin", "url", "id", "vat", "uk", "eu", "us", "ram", "cpu", "gpu", "ssd", "hdd", "led", "oled", "sim", "nfc", "gps", "usb", "hdmi"]);
69
+ export function splitIdentifierWords(name) {
70
+ const spaced = name
71
+ .replace(/([a-z0-9])([A-Z])/gu, "$1 $2")
72
+ .replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2")
73
+ .replace(/[_\-./]+/gu, " ")
74
+ .trim();
75
+ if (spaced.length === 0)
76
+ return [];
77
+ return spaced.split(/\s+/u).filter((part) => part.length > 0);
78
+ }
79
+ export function inferFieldDescription(fieldName) {
80
+ const lower = fieldName.toLowerCase();
81
+ const known = KNOWN_FIELD_DESCRIPTIONS.get(lower);
82
+ if (known) {
83
+ return known;
84
+ }
85
+ const words = splitIdentifierWords(fieldName);
86
+ if (words.length === 0) {
87
+ return "Field value for the item";
88
+ }
89
+ const lastLower = words[words.length - 1].toLowerCase();
90
+ const unitText = UNIT_MAP.get(lastLower);
91
+ if (words.length >= 2 && unitText) {
92
+ const head = words
93
+ .slice(0, -1)
94
+ .map((word, index) => formatWord(word, index === 0))
95
+ .join(" ");
96
+ return `${head} ${unitText}`;
97
+ }
98
+ if (words.length === 1) {
99
+ return `${formatWord(words[0], true)} of the item`;
100
+ }
101
+ return words.map((word, index) => formatWord(word, index === 0)).join(" ");
102
+ }
103
+ function formatWord(word, capitalize) {
104
+ const lower = word.toLowerCase();
105
+ if (ACRONYMS.has(lower)) {
106
+ return lower.toUpperCase();
107
+ }
108
+ if (capitalize) {
109
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
110
+ }
111
+ return lower;
112
+ }
113
+ export function inferCategoryName(symbolOrFileName) {
114
+ const stripped = symbolOrFileName
115
+ .replace(/\.pcific\.schema\.json$/iu, "")
116
+ .replace(/\.schema\.json$/iu, "")
117
+ .replace(/\.json$/iu, "")
118
+ .replace(/\.(ts|tsx|js|mjs|cjs|prisma)$/iu, "")
119
+ .replace(/(?:Listing|Product|Item)?Schema$/u, "")
120
+ .replace(/(?:Listing|Product|Item)Input$/u, "")
121
+ .trim();
122
+ const base = stripped.length > 0 ? stripped : symbolOrFileName;
123
+ const words = splitIdentifierWords(base);
124
+ if (words.length === 0)
125
+ return "Listings";
126
+ return words
127
+ .map((word) => {
128
+ const lower = word.toLowerCase();
129
+ if (ACRONYMS.has(lower))
130
+ return lower.toUpperCase();
131
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
132
+ })
133
+ .join(" ");
134
+ }
135
+ export function inferCategoryDescription(category) {
136
+ return `Listing fields for ${category}`;
137
+ }
138
+ export function isListingHint(name) {
139
+ return /(listing|product|item|catalogue|catalog|inventory|offer|vehicle|phone|watch|sneaker|garment|book|device|category)/iu.test(name);
140
+ }
141
+ /**
142
+ * Adds `"x-pcific-money": true` ONLY when the object strictly matches
143
+ * the PCIFIC API server's money rule: integer `amount`, string `currency`
144
+ * (optional 3-letter uppercase enum/const), both listed in `required`.
145
+ */
146
+ export function maybeAnnotateMoney(schema) {
147
+ if (schema["x-pcific-money"] !== undefined)
148
+ return schema;
149
+ if (schema.type !== "object" || !schema.properties)
150
+ return schema;
151
+ const amount = schema.properties.amount;
152
+ const currency = schema.properties.currency;
153
+ if (!amount || !currency)
154
+ return schema;
155
+ const required = Array.isArray(schema.required) ? schema.required : [];
156
+ if (!required.includes("amount") || !required.includes("currency")) {
157
+ return schema;
158
+ }
159
+ if (amount.type !== "integer" || currency.type !== "string") {
160
+ return schema;
161
+ }
162
+ if (Array.isArray(currency.enum)) {
163
+ const validCodes = currency.enum.every((value) => isStringValue(value) && /^[A-Z]{3}$/u.test(value));
164
+ if (!validCodes)
165
+ return schema;
166
+ }
167
+ if (currency.const !== undefined) {
168
+ if (!isStringValue(currency.const) || !/^[A-Z]{3}$/u.test(currency.const)) {
169
+ return schema;
170
+ }
171
+ }
172
+ return {
173
+ ...schema,
174
+ "x-pcific-money": true,
175
+ };
176
+ }
177
+ export function countSchemaFields(schema) {
178
+ let count = 0;
179
+ function walk(node) {
180
+ if (node.properties) {
181
+ for (const prop of Object.values(node.properties)) {
182
+ count += 1;
183
+ walk(prop);
184
+ }
185
+ }
186
+ if (node.items) {
187
+ walk(node.items);
188
+ }
189
+ if (Array.isArray(node.anyOf)) {
190
+ for (const branch of node.anyOf) {
191
+ walk(branch);
192
+ }
193
+ }
194
+ }
195
+ walk(schema);
196
+ return count;
197
+ }
198
+ /**
199
+ * Ensures every property at every depth has a non-empty plain-words description
200
+ * and tracks every auto-generated description path without renaming any field.
201
+ */
202
+ export function ensureDescriptions(schema, category) {
203
+ const inferredDescriptions = [];
204
+ function walkObject(node, pointerPrefix, isRoot) {
205
+ const copy = { ...node };
206
+ if (isRoot) {
207
+ if (!copy.$schema)
208
+ copy.$schema = JSON_SCHEMA_DRAFT;
209
+ if (!copy.type)
210
+ copy.type = "object";
211
+ if (!isStringValue(copy.description) || copy.description.trim().length === 0) {
212
+ copy.description = inferCategoryDescription(category);
213
+ inferredDescriptions.push("/description");
214
+ }
215
+ }
216
+ if (copy.properties) {
217
+ const nextProps = {};
218
+ for (const [fieldName, rawProp] of Object.entries(copy.properties)) {
219
+ const escaped = fieldName.replace(/~/gu, "~0").replace(/\//gu, "~1");
220
+ const propPointer = `${pointerPrefix}/properties/${escaped}`;
221
+ let prop = walkObject(rawProp, propPointer, false);
222
+ if (!isStringValue(prop.description) || prop.description.trim().length === 0) {
223
+ prop = {
224
+ ...prop,
225
+ description: inferFieldDescription(fieldName),
226
+ };
227
+ inferredDescriptions.push(propPointer);
228
+ }
229
+ prop = maybeAnnotateMoney(prop);
230
+ nextProps[fieldName] = prop;
231
+ }
232
+ copy.properties = nextProps;
233
+ }
234
+ if (copy.items) {
235
+ copy.items = walkObject(copy.items, `${pointerPrefix}/items`, false);
236
+ }
237
+ if (Array.isArray(copy.anyOf)) {
238
+ copy.anyOf = copy.anyOf.map((branch, index) => walkObject(branch, `${pointerPrefix}/anyOf/${index}`, false));
239
+ }
240
+ return copy;
241
+ }
242
+ const normalized = walkObject(schema, "", true);
243
+ return { schema: normalized, inferredDescriptions };
244
+ }
245
+ export function cleanJsDocComment(raw) {
246
+ const lines = raw
247
+ .replace(/^\/\*\*?/u, "")
248
+ .replace(/\*\/$/u, "")
249
+ .split(/\r?\n/u)
250
+ .map((line) => line.replace(/^\s*\*?\s?/u, "").trim())
251
+ .filter((line) => line.length > 0 && !line.startsWith("@"));
252
+ return lines.join(" ").replace(/\s+/gu, " ").trim();
253
+ }
254
+ export function parseEnvFile(content) {
255
+ return parseDotEnv(content);
256
+ }
257
+ export function loadLocalEnv(cwd, env) {
258
+ return readMergedEnv(cwd, env);
259
+ }
260
+ export function findMatchingDelimiter(source, openIndex, openChar, closeChar) {
261
+ let depth = 0;
262
+ let index = openIndex;
263
+ while (index < source.length) {
264
+ const ch = source[index];
265
+ if (ch === "'" || ch === '"' || ch === "`") {
266
+ index = skipStringLiteral(source, index);
267
+ continue;
268
+ }
269
+ if (ch === "/" && source[index + 1] === "/") {
270
+ const nl = source.indexOf("\n", index + 2);
271
+ index = nl === -1 ? source.length : nl + 1;
272
+ continue;
273
+ }
274
+ if (ch === "/" && source[index + 1] === "*") {
275
+ const end = source.indexOf("*/", index + 2);
276
+ index = end === -1 ? source.length : end + 2;
277
+ continue;
278
+ }
279
+ if (ch === openChar) {
280
+ depth += 1;
281
+ }
282
+ else if (ch === closeChar) {
283
+ depth -= 1;
284
+ if (depth === 0)
285
+ return index;
286
+ }
287
+ index += 1;
288
+ }
289
+ return -1;
290
+ }
291
+ export function skipStringLiteral(source, start) {
292
+ const quote = source[start];
293
+ let index = start + 1;
294
+ while (index < source.length) {
295
+ const ch = source[index];
296
+ if (ch === "\\") {
297
+ index += 2;
298
+ continue;
299
+ }
300
+ if (quote === "`" && ch === "$" && source[index + 1] === "{") {
301
+ const endExpr = findMatchingDelimiter(source, index + 1, "{", "}");
302
+ if (endExpr === -1)
303
+ return source.length;
304
+ index = endExpr + 1;
305
+ continue;
306
+ }
307
+ if (ch === quote) {
308
+ return index + 1;
309
+ }
310
+ index += 1;
311
+ }
312
+ return source.length;
313
+ }
314
+ export function parseStringLiteral(raw) {
315
+ const trimmed = raw.trim();
316
+ if (trimmed.length < 2)
317
+ return null;
318
+ const quote = trimmed[0];
319
+ if ((quote !== '"' && quote !== "'" && quote !== "`") || trimmed[trimmed.length - 1] !== quote) {
320
+ return null;
321
+ }
322
+ let out = "";
323
+ let index = 1;
324
+ while (index < trimmed.length - 1) {
325
+ const ch = trimmed[index];
326
+ if (ch === "\\" && index + 1 < trimmed.length - 1) {
327
+ const next = trimmed[index + 1];
328
+ if (next === "n")
329
+ out += "\n";
330
+ else if (next === "r")
331
+ out += "\r";
332
+ else if (next === "t")
333
+ out += "\t";
334
+ else
335
+ out += next;
336
+ index += 2;
337
+ continue;
338
+ }
339
+ out += ch;
340
+ index += 1;
341
+ }
342
+ return out;
343
+ }
344
+ export function splitTopLevel(input, separator) {
345
+ const parts = [];
346
+ let start = 0;
347
+ let braceDepth = 0;
348
+ let parenDepth = 0;
349
+ let bracketDepth = 0;
350
+ let angleDepth = 0;
351
+ let index = 0;
352
+ while (index < input.length) {
353
+ const ch = input[index];
354
+ if (ch === "'" || ch === '"' || ch === "`") {
355
+ index = skipStringLiteral(input, index);
356
+ continue;
357
+ }
358
+ if (ch === "/" && input[index + 1] === "/") {
359
+ const nl = input.indexOf("\n", index + 2);
360
+ index = nl === -1 ? input.length : nl + 1;
361
+ continue;
362
+ }
363
+ if (ch === "/" && input[index + 1] === "*") {
364
+ const end = input.indexOf("*/", index + 2);
365
+ index = end === -1 ? input.length : end + 2;
366
+ continue;
367
+ }
368
+ if (ch === "{")
369
+ braceDepth += 1;
370
+ else if (ch === "}")
371
+ braceDepth -= 1;
372
+ else if (ch === "(")
373
+ parenDepth += 1;
374
+ else if (ch === ")")
375
+ parenDepth -= 1;
376
+ else if (ch === "[")
377
+ bracketDepth += 1;
378
+ else if (ch === "]")
379
+ bracketDepth -= 1;
380
+ else if (ch === "<")
381
+ angleDepth += 1;
382
+ else if (ch === ">" && input[index - 1] !== "=")
383
+ angleDepth = Math.max(0, angleDepth - 1);
384
+ else if (ch === separator &&
385
+ braceDepth === 0 &&
386
+ parenDepth === 0 &&
387
+ bracketDepth === 0 &&
388
+ angleDepth === 0) {
389
+ parts.push(input.slice(start, index));
390
+ start = index + 1;
391
+ }
392
+ index += 1;
393
+ }
394
+ parts.push(input.slice(start));
395
+ return parts;
396
+ }
@@ -0,0 +1,197 @@
1
+ import { ensureDescriptions, findMatchingDelimiter, inferCategoryName, isListingHint, } from "./helpers.js";
2
+ const DEFAULT_INTERNAL_FIELDS = new Set([
3
+ "id",
4
+ "createdAt",
5
+ "updatedAt",
6
+ "deletedAt",
7
+ "created_at",
8
+ "updated_at",
9
+ "deleted_at",
10
+ ]);
11
+ function extractPrismaBlocks(source) {
12
+ const blocks = [];
13
+ const lines = source.split(/\r?\n/u);
14
+ let pendingDoc = [];
15
+ let offset = 0;
16
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx += 1) {
17
+ const line = lines[lineIdx];
18
+ const trimmed = line.trim();
19
+ if (trimmed.startsWith("///")) {
20
+ pendingDoc.push(trimmed.slice(3).trim());
21
+ offset += line.length + 1;
22
+ continue;
23
+ }
24
+ const match = /^(model|enum)\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{/u.exec(trimmed);
25
+ if (match) {
26
+ const openBrace = source.indexOf("{", offset);
27
+ const closeBrace = findMatchingDelimiter(source, openBrace, "{", "}");
28
+ if (closeBrace !== -1) {
29
+ blocks.push({
30
+ kind: match[1] === "enum" ? "enum" : "model",
31
+ name: match[2],
32
+ body: source.slice(openBrace + 1, closeBrace),
33
+ doc: pendingDoc.length > 0 ? pendingDoc.join(" ") : undefined,
34
+ });
35
+ // Advance lineIdx past closeBrace
36
+ const beforeClose = source.slice(offset, closeBrace + 1);
37
+ const newlines = (beforeClose.match(/\n/gu) ?? []).length;
38
+ lineIdx += newlines;
39
+ offset = closeBrace + 2;
40
+ pendingDoc = [];
41
+ continue;
42
+ }
43
+ }
44
+ if (trimmed.length > 0 && !trimmed.startsWith("//")) {
45
+ pendingDoc = [];
46
+ }
47
+ offset += line.length + 1;
48
+ }
49
+ return blocks;
50
+ }
51
+ function parsePrismaEnumValues(body) {
52
+ const values = [];
53
+ for (const rawLine of body.split(/\r?\n/u)) {
54
+ const trimmed = rawLine.trim();
55
+ if (trimmed.length === 0 ||
56
+ trimmed.startsWith("//") ||
57
+ trimmed.startsWith("@@")) {
58
+ continue;
59
+ }
60
+ const token = trimmed.split(/\s+/u)[0];
61
+ if (token && /^[A-Za-z_][A-Za-z0-9_]*$/u.test(token)) {
62
+ values.push(token);
63
+ }
64
+ }
65
+ return values;
66
+ }
67
+ function mapPrismaScalarType(rawType, enums) {
68
+ if (enums.has(rawType)) {
69
+ return { type: "string", enum: enums.get(rawType) };
70
+ }
71
+ switch (rawType) {
72
+ case "String":
73
+ return { type: "string" };
74
+ case "Int":
75
+ case "BigInt":
76
+ return { type: "integer" };
77
+ case "Float":
78
+ case "Decimal":
79
+ return { type: "number" };
80
+ case "Boolean":
81
+ return { type: "boolean" };
82
+ case "DateTime":
83
+ return { type: "string", format: "date-time" };
84
+ case "Json":
85
+ return { type: "object" };
86
+ case "Bytes":
87
+ return { type: "string" };
88
+ default:
89
+ return null;
90
+ }
91
+ }
92
+ export function extractPrismaSchemasFromSource(source, options = {}) {
93
+ const blocks = extractPrismaBlocks(source);
94
+ const enums = new Map();
95
+ const modelNames = new Set();
96
+ for (const block of blocks) {
97
+ if (block.kind === "enum") {
98
+ enums.set(block.name, parsePrismaEnumValues(block.body));
99
+ }
100
+ else {
101
+ modelNames.add(block.name);
102
+ }
103
+ }
104
+ const allModels = blocks.filter((block) => block.kind === "model");
105
+ let selectedModels = allModels.filter((model) => {
106
+ if (options.model) {
107
+ return model.name.toLowerCase() === options.model.toLowerCase();
108
+ }
109
+ if (options.includeAll)
110
+ return true;
111
+ return isListingHint(model.name);
112
+ });
113
+ if (selectedModels.length === 0 && options.includeAll && !options.model) {
114
+ selectedModels = allModels;
115
+ }
116
+ const results = [];
117
+ for (const model of selectedModels) {
118
+ const properties = {};
119
+ const required = [];
120
+ let pendingDoc = [];
121
+ for (const rawLine of model.body.split(/\r?\n/u)) {
122
+ const trimmed = rawLine.trim();
123
+ if (trimmed.length === 0)
124
+ continue;
125
+ if (trimmed.startsWith("///")) {
126
+ pendingDoc.push(trimmed.slice(3).trim());
127
+ continue;
128
+ }
129
+ if (trimmed.startsWith("//") || trimmed.startsWith("@@")) {
130
+ pendingDoc = [];
131
+ continue;
132
+ }
133
+ // Remove trailing inline comment
134
+ const commentIdx = trimmed.indexOf("//");
135
+ const codePart = commentIdx === -1 ? trimmed : trimmed.slice(0, commentIdx).trim();
136
+ const inlineComment = commentIdx !== -1 && trimmed.slice(commentIdx).startsWith("///")
137
+ ? trimmed.slice(commentIdx + 3).trim()
138
+ : undefined;
139
+ const fieldMatch = /^([A-Za-z_][A-Za-z0-9_]*)\s+([A-Za-z_][A-Za-z0-9_]*)(\[\]|\?)?(.*)$/u.exec(codePart);
140
+ if (!fieldMatch) {
141
+ pendingDoc = [];
142
+ continue;
143
+ }
144
+ const [, fieldName, baseType, modifier, restAttrs] = fieldMatch;
145
+ const docText = pendingDoc.length > 0
146
+ ? pendingDoc.join(" ")
147
+ : inlineComment && inlineComment.length > 0
148
+ ? inlineComment
149
+ : undefined;
150
+ pendingDoc = [];
151
+ // Skip Prisma relations
152
+ if (restAttrs.includes("@relation") || modelNames.has(baseType)) {
153
+ continue;
154
+ }
155
+ // Skip internal/housekeeping columns unless opted in
156
+ if (!options.includeInternal &&
157
+ (DEFAULT_INTERNAL_FIELDS.has(fieldName) ||
158
+ restAttrs.includes("@id") ||
159
+ restAttrs.includes("@updatedAt"))) {
160
+ continue;
161
+ }
162
+ const mapped = mapPrismaScalarType(baseType, enums);
163
+ if (!mapped)
164
+ continue;
165
+ let fieldSchema = modifier === "[]" ? { type: "array", items: mapped } : mapped;
166
+ if (docText) {
167
+ fieldSchema = { ...fieldSchema, description: docText };
168
+ }
169
+ properties[fieldName] = fieldSchema;
170
+ const isOptional = modifier === "?" || restAttrs.includes("@default(");
171
+ if (!isOptional) {
172
+ required.push(fieldName);
173
+ }
174
+ }
175
+ if (Object.keys(properties).length === 0)
176
+ continue;
177
+ const category = inferCategoryName(model.name);
178
+ const rootSchema = {
179
+ type: "object",
180
+ properties,
181
+ };
182
+ if (model.doc) {
183
+ rootSchema.description = model.doc;
184
+ }
185
+ if (required.length > 0) {
186
+ rootSchema.required = required;
187
+ }
188
+ const { schema, inferredDescriptions } = ensureDescriptions(rootSchema, category);
189
+ results.push({
190
+ symbolName: model.name,
191
+ category,
192
+ schema,
193
+ inferredDescriptions,
194
+ });
195
+ }
196
+ return results;
197
+ }