schemock 0.0.4-alpha.13 → 0.0.4-alpha.14
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/dist/adapters/index.d.mts +4 -4
- package/dist/adapters/index.d.ts +4 -4
- package/dist/cli/index.d.mts +18 -3
- package/dist/cli/index.d.ts +18 -3
- package/dist/cli/index.js +230 -21
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +230 -21
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli.js +256 -43
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/middleware/index.d.mts +4 -4
- package/dist/middleware/index.d.ts +4 -4
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/runtime/index.d.mts +2 -2
- package/dist/runtime/index.d.ts +2 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/schema/index.d.mts +2 -2
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/index.mjs.map +1 -1
- package/dist/{types-vPJ91BuY.d.mts → types-BBeKlEd1.d.mts} +1 -1
- package/dist/{types-CWZQ6vqt.d.mts → types-BCLdZDSF.d.mts} +3 -3
- package/dist/{types-CWZQ6vqt.d.ts → types-BCLdZDSF.d.ts} +3 -3
- package/dist/{types-4EDTne0h.d.ts → types-CVeLQjhD.d.ts} +1 -1
- package/dist/{types-Ku_ykMzx.d.ts → types-CZdze7Tl.d.ts} +1 -1
- package/dist/{types-D-u5uw1E.d.mts → types-DKrOkBcu.d.mts} +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1510,6 +1510,140 @@ var init_analyze = __esm({
|
|
|
1510
1510
|
});
|
|
1511
1511
|
|
|
1512
1512
|
// src/cli/analyze-endpoints.ts
|
|
1513
|
+
function parseImportsFromFile(filePath) {
|
|
1514
|
+
if (importCache.has(filePath)) {
|
|
1515
|
+
return importCache.get(filePath);
|
|
1516
|
+
}
|
|
1517
|
+
const imports = /* @__PURE__ */ new Map();
|
|
1518
|
+
try {
|
|
1519
|
+
const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
|
|
1520
|
+
const importRegex = /import\s+(?:(?:(\w+)(?:\s*,\s*)?)?(?:\{([^}]+)\})?\s+from\s+)?['"]([^'"]+)['"]/g;
|
|
1521
|
+
let match;
|
|
1522
|
+
while ((match = importRegex.exec(content)) !== null) {
|
|
1523
|
+
const [, defaultImport, namedImports, modulePath] = match;
|
|
1524
|
+
if (defaultImport) {
|
|
1525
|
+
imports.set(defaultImport, modulePath);
|
|
1526
|
+
}
|
|
1527
|
+
if (namedImports) {
|
|
1528
|
+
const names = namedImports.split(",").map((s) => s.trim());
|
|
1529
|
+
for (const name of names) {
|
|
1530
|
+
const asMatch = name.match(/(\w+)\s+as\s+(\w+)/);
|
|
1531
|
+
if (asMatch) {
|
|
1532
|
+
imports.set(asMatch[2], modulePath);
|
|
1533
|
+
} else if (name && /^\w+$/.test(name)) {
|
|
1534
|
+
imports.set(name, modulePath);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
console.warn(`Warning: Could not parse imports from ${filePath}`);
|
|
1541
|
+
}
|
|
1542
|
+
importCache.set(filePath, imports);
|
|
1543
|
+
return imports;
|
|
1544
|
+
}
|
|
1545
|
+
function detectUsedIdentifiers(functionSource) {
|
|
1546
|
+
const withoutStrings = functionSource.replace(/'[^']*'/g, "").replace(/"[^"]*"/g, "").replace(/`[^`]*`/g, "");
|
|
1547
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
1548
|
+
const callRegex = /\b([A-Z][a-zA-Z0-9]*|[a-z][a-zA-Z0-9]*)\s*\(/g;
|
|
1549
|
+
let match;
|
|
1550
|
+
while ((match = callRegex.exec(withoutStrings)) !== null) {
|
|
1551
|
+
const name = match[1];
|
|
1552
|
+
if (!isBuiltIn(name) && !isContextProperty(name)) {
|
|
1553
|
+
identifiers.add(name);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
const newRegex = /\bnew\s+([A-Z][a-zA-Z0-9]*)/g;
|
|
1557
|
+
while ((match = newRegex.exec(withoutStrings)) !== null) {
|
|
1558
|
+
const name = match[1];
|
|
1559
|
+
if (!isBuiltIn(name)) {
|
|
1560
|
+
identifiers.add(name);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
const throwRegex = /\bthrow\s+new\s+([A-Z][a-zA-Z0-9]*)/g;
|
|
1564
|
+
while ((match = throwRegex.exec(withoutStrings)) !== null) {
|
|
1565
|
+
identifiers.add(match[1]);
|
|
1566
|
+
}
|
|
1567
|
+
return Array.from(identifiers);
|
|
1568
|
+
}
|
|
1569
|
+
function isBuiltIn(name) {
|
|
1570
|
+
const builtIns = /* @__PURE__ */ new Set([
|
|
1571
|
+
// Functions
|
|
1572
|
+
"console",
|
|
1573
|
+
"JSON",
|
|
1574
|
+
"Object",
|
|
1575
|
+
"Array",
|
|
1576
|
+
"String",
|
|
1577
|
+
"Number",
|
|
1578
|
+
"Boolean",
|
|
1579
|
+
"Date",
|
|
1580
|
+
"Math",
|
|
1581
|
+
"Promise",
|
|
1582
|
+
"Map",
|
|
1583
|
+
"Set",
|
|
1584
|
+
"WeakMap",
|
|
1585
|
+
"WeakSet",
|
|
1586
|
+
"parseInt",
|
|
1587
|
+
"parseFloat",
|
|
1588
|
+
"isNaN",
|
|
1589
|
+
"isFinite",
|
|
1590
|
+
"fetch",
|
|
1591
|
+
"setTimeout",
|
|
1592
|
+
"setInterval",
|
|
1593
|
+
"clearTimeout",
|
|
1594
|
+
"clearInterval",
|
|
1595
|
+
// Errors
|
|
1596
|
+
"Error",
|
|
1597
|
+
"TypeError",
|
|
1598
|
+
"ReferenceError",
|
|
1599
|
+
"SyntaxError",
|
|
1600
|
+
"RangeError",
|
|
1601
|
+
// Common methods that look like function calls
|
|
1602
|
+
"toString",
|
|
1603
|
+
"valueOf",
|
|
1604
|
+
"hasOwnProperty",
|
|
1605
|
+
"length",
|
|
1606
|
+
"push",
|
|
1607
|
+
"pop",
|
|
1608
|
+
"map",
|
|
1609
|
+
"filter",
|
|
1610
|
+
"reduce",
|
|
1611
|
+
"find",
|
|
1612
|
+
"findIndex",
|
|
1613
|
+
"some",
|
|
1614
|
+
"every",
|
|
1615
|
+
"includes",
|
|
1616
|
+
"indexOf",
|
|
1617
|
+
"slice",
|
|
1618
|
+
"splice",
|
|
1619
|
+
"concat",
|
|
1620
|
+
"join",
|
|
1621
|
+
"split"
|
|
1622
|
+
]);
|
|
1623
|
+
return builtIns.has(name);
|
|
1624
|
+
}
|
|
1625
|
+
function isContextProperty(name) {
|
|
1626
|
+
const contextProps = /* @__PURE__ */ new Set([
|
|
1627
|
+
"params",
|
|
1628
|
+
"body",
|
|
1629
|
+
"db",
|
|
1630
|
+
"headers",
|
|
1631
|
+
"ctx",
|
|
1632
|
+
// Common db methods
|
|
1633
|
+
"findMany",
|
|
1634
|
+
"findFirst",
|
|
1635
|
+
"findUnique",
|
|
1636
|
+
"create",
|
|
1637
|
+
"update",
|
|
1638
|
+
"delete",
|
|
1639
|
+
"count",
|
|
1640
|
+
"getAll",
|
|
1641
|
+
"deleteMany",
|
|
1642
|
+
"updateMany",
|
|
1643
|
+
"upsert"
|
|
1644
|
+
]);
|
|
1645
|
+
return contextProps.has(name);
|
|
1646
|
+
}
|
|
1513
1647
|
function analyzeEndpoints(endpoints, endpointFiles) {
|
|
1514
1648
|
return endpoints.map((endpoint) => analyzeEndpoint(endpoint, endpointFiles));
|
|
1515
1649
|
}
|
|
@@ -1521,16 +1655,32 @@ function analyzeEndpoint(endpoint, endpointFiles) {
|
|
|
1521
1655
|
const body = analyzeFields(endpoint.body);
|
|
1522
1656
|
const response = analyzeFields(endpoint.response);
|
|
1523
1657
|
const mockResolverSource = serializeMockResolver(endpoint.mockResolver);
|
|
1658
|
+
const sourceFile = endpointFiles?.get(endpoint.path);
|
|
1524
1659
|
const resolverName = endpoint.mockResolver.name;
|
|
1525
1660
|
const isNamedFunction = resolverName && !resolverName.startsWith("bound ") && resolverName !== "mockResolver";
|
|
1526
1661
|
let mockResolverName;
|
|
1527
1662
|
let mockResolverImportPath;
|
|
1663
|
+
let resolverDependencies;
|
|
1528
1664
|
if (isNamedFunction) {
|
|
1529
1665
|
mockResolverName = resolverName;
|
|
1530
|
-
const sourceFile = endpointFiles?.get(endpoint.path);
|
|
1531
1666
|
if (sourceFile) {
|
|
1532
1667
|
mockResolverImportPath = sourceFile;
|
|
1533
1668
|
}
|
|
1669
|
+
} else if (sourceFile) {
|
|
1670
|
+
const usedIdentifiers = detectUsedIdentifiers(mockResolverSource);
|
|
1671
|
+
if (usedIdentifiers.length > 0) {
|
|
1672
|
+
const fileImports = parseImportsFromFile(sourceFile);
|
|
1673
|
+
const deps = [];
|
|
1674
|
+
for (const identifier of usedIdentifiers) {
|
|
1675
|
+
const importPath = fileImports.get(identifier);
|
|
1676
|
+
if (importPath) {
|
|
1677
|
+
deps.push({ name: identifier, from: importPath });
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
if (deps.length > 0) {
|
|
1681
|
+
resolverDependencies = deps;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1534
1684
|
}
|
|
1535
1685
|
return {
|
|
1536
1686
|
path: endpoint.path,
|
|
@@ -1544,6 +1694,8 @@ function analyzeEndpoint(endpoint, endpointFiles) {
|
|
|
1544
1694
|
mockResolverSource,
|
|
1545
1695
|
mockResolverName,
|
|
1546
1696
|
mockResolverImportPath,
|
|
1697
|
+
sourceFile,
|
|
1698
|
+
resolverDependencies,
|
|
1547
1699
|
description: endpoint.description
|
|
1548
1700
|
};
|
|
1549
1701
|
}
|
|
@@ -1661,9 +1813,12 @@ function serializeMockResolver(resolver) {
|
|
|
1661
1813
|
}
|
|
1662
1814
|
return source;
|
|
1663
1815
|
}
|
|
1816
|
+
var import_node_fs2, importCache;
|
|
1664
1817
|
var init_analyze_endpoints = __esm({
|
|
1665
1818
|
"src/cli/analyze-endpoints.ts"() {
|
|
1666
1819
|
"use strict";
|
|
1820
|
+
import_node_fs2 = require("fs");
|
|
1821
|
+
importCache = /* @__PURE__ */ new Map();
|
|
1667
1822
|
}
|
|
1668
1823
|
});
|
|
1669
1824
|
|
|
@@ -3379,9 +3534,35 @@ function generateEndpointResolvers(endpoints, outputDir) {
|
|
|
3379
3534
|
code.comment("");
|
|
3380
3535
|
code.comment("These resolvers are copied from your defineEndpoint() calls.");
|
|
3381
3536
|
code.comment("They receive { params, body, db, headers } and return the response.");
|
|
3537
|
+
code.comment("");
|
|
3538
|
+
code.comment("NOTE: If your inline resolvers use external functions (e.g., hashPassword, generateToken),");
|
|
3539
|
+
code.comment("consider using named exported functions instead - they will be automatically imported.");
|
|
3540
|
+
code.line();
|
|
3541
|
+
code.line("import type { Database } from './db';");
|
|
3542
|
+
code.line();
|
|
3543
|
+
code.comment("Resolver context with typed database access");
|
|
3544
|
+
code.block("export interface ResolverContext {", () => {
|
|
3545
|
+
code.line("params: Record<string, unknown>;");
|
|
3546
|
+
code.line("body: Record<string, unknown>;");
|
|
3547
|
+
code.line("db: Database;");
|
|
3548
|
+
code.line("headers: Record<string, string>;");
|
|
3549
|
+
});
|
|
3550
|
+
code.line();
|
|
3551
|
+
code.comment("Error class for HTTP errors in resolvers");
|
|
3552
|
+
code.block("export class HttpError extends Error {", () => {
|
|
3553
|
+
code.line("readonly status: number;");
|
|
3554
|
+
code.line("readonly code?: string;");
|
|
3555
|
+
code.line();
|
|
3556
|
+
code.block("constructor(message: string, status: number, code?: string) {", () => {
|
|
3557
|
+
code.line("super(message);");
|
|
3558
|
+
code.line('this.name = "HttpError";');
|
|
3559
|
+
code.line("this.status = status;");
|
|
3560
|
+
code.line("this.code = code;");
|
|
3561
|
+
});
|
|
3562
|
+
});
|
|
3382
3563
|
code.line();
|
|
3383
|
-
code.line("import type { MockResolverContext } from 'schemock/schema';");
|
|
3384
3564
|
const externalResolvers = /* @__PURE__ */ new Map();
|
|
3565
|
+
const inlineDependencies = /* @__PURE__ */ new Map();
|
|
3385
3566
|
for (const endpoint of endpoints) {
|
|
3386
3567
|
if (endpoint.mockResolverName && endpoint.mockResolverImportPath) {
|
|
3387
3568
|
const key = `${endpoint.mockResolverImportPath}:${endpoint.mockResolverName}`;
|
|
@@ -3392,7 +3573,37 @@ function generateEndpointResolvers(endpoints, outputDir) {
|
|
|
3392
3573
|
});
|
|
3393
3574
|
}
|
|
3394
3575
|
}
|
|
3576
|
+
if (endpoint.resolverDependencies) {
|
|
3577
|
+
for (const dep of endpoint.resolverDependencies) {
|
|
3578
|
+
const key = `${dep.from}:${dep.name}`;
|
|
3579
|
+
if (!inlineDependencies.has(key)) {
|
|
3580
|
+
inlineDependencies.set(key, {
|
|
3581
|
+
name: dep.name,
|
|
3582
|
+
importPath: dep.from
|
|
3583
|
+
});
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3395
3587
|
}
|
|
3588
|
+
const calculateRelativePath = (importPath) => {
|
|
3589
|
+
let relativePath = importPath;
|
|
3590
|
+
if (outputDir) {
|
|
3591
|
+
const toPosix = (p) => p.replace(/\\/g, "/");
|
|
3592
|
+
const from = toPosix(outputDir);
|
|
3593
|
+
const to = toPosix(importPath);
|
|
3594
|
+
const fromParts = from.split("/").filter(Boolean);
|
|
3595
|
+
const toParts = to.split("/").filter(Boolean);
|
|
3596
|
+
while (fromParts.length && toParts.length && fromParts[0] === toParts[0]) {
|
|
3597
|
+
fromParts.shift();
|
|
3598
|
+
toParts.shift();
|
|
3599
|
+
}
|
|
3600
|
+
let rel = "../".repeat(fromParts.length) + toParts.join("/");
|
|
3601
|
+
if (!rel.startsWith(".") && rel !== "") rel = "./" + rel;
|
|
3602
|
+
rel = rel.replace(/\.(ts|js)$/, "");
|
|
3603
|
+
relativePath = rel;
|
|
3604
|
+
}
|
|
3605
|
+
return relativePath;
|
|
3606
|
+
};
|
|
3396
3607
|
if (externalResolvers.size > 0) {
|
|
3397
3608
|
code.line();
|
|
3398
3609
|
code.comment("External resolver imports");
|
|
@@ -3404,27 +3615,29 @@ function generateEndpointResolvers(endpoints, outputDir) {
|
|
|
3404
3615
|
importsByPath.get(importPath).push(name);
|
|
3405
3616
|
}
|
|
3406
3617
|
for (const [importPath, names] of importsByPath) {
|
|
3407
|
-
|
|
3408
|
-
if (outputDir) {
|
|
3409
|
-
const toPosix = (p) => p.replace(/\\/g, "/");
|
|
3410
|
-
const from = toPosix(outputDir);
|
|
3411
|
-
const to = toPosix(importPath);
|
|
3412
|
-
const fromParts = from.split("/").filter(Boolean);
|
|
3413
|
-
const toParts = to.split("/").filter(Boolean);
|
|
3414
|
-
while (fromParts.length && toParts.length && fromParts[0] === toParts[0]) {
|
|
3415
|
-
fromParts.shift();
|
|
3416
|
-
toParts.shift();
|
|
3417
|
-
}
|
|
3418
|
-
let rel = "../".repeat(fromParts.length) + toParts.join("/");
|
|
3419
|
-
if (!rel.startsWith(".") && rel !== "") rel = "./" + rel;
|
|
3420
|
-
rel = rel.replace(/\.(ts|js)$/, "");
|
|
3421
|
-
relativePath = rel;
|
|
3422
|
-
}
|
|
3618
|
+
const relativePath = calculateRelativePath(importPath);
|
|
3423
3619
|
code.line(`import { ${names.join(", ")} } from '${relativePath}';`);
|
|
3424
3620
|
}
|
|
3425
3621
|
}
|
|
3622
|
+
if (inlineDependencies.size > 0) {
|
|
3623
|
+
code.line();
|
|
3624
|
+
code.comment("Dependencies used by inline resolvers");
|
|
3625
|
+
const importsByPath = /* @__PURE__ */ new Map();
|
|
3626
|
+
for (const { name, importPath } of inlineDependencies.values()) {
|
|
3627
|
+
if (!importsByPath.has(importPath)) {
|
|
3628
|
+
importsByPath.set(importPath, []);
|
|
3629
|
+
}
|
|
3630
|
+
const names = importsByPath.get(importPath);
|
|
3631
|
+
if (!names.includes(name)) {
|
|
3632
|
+
names.push(name);
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
for (const [importPath, names] of importsByPath) {
|
|
3636
|
+
code.line(`import { ${names.join(", ")} } from '${importPath}';`);
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3426
3639
|
code.line();
|
|
3427
|
-
code.line("type ResolverFn = (ctx:
|
|
3640
|
+
code.line("type ResolverFn = (ctx: ResolverContext) => unknown | Promise<unknown>;");
|
|
3428
3641
|
code.line();
|
|
3429
3642
|
code.block("export const endpointResolvers: Record<string, ResolverFn> = {", () => {
|
|
3430
3643
|
for (const endpoint of endpoints) {
|
|
@@ -9535,9 +9748,9 @@ async function setupAI(options = {}) {
|
|
|
9535
9748
|
const outputDir = options.output || process.cwd();
|
|
9536
9749
|
const claudeMdPath = (0, import_node_path8.resolve)(outputDir, "CLAUDE.md");
|
|
9537
9750
|
let existingContent = "";
|
|
9538
|
-
if ((0,
|
|
9751
|
+
if ((0, import_node_fs3.existsSync)(claudeMdPath)) {
|
|
9539
9752
|
console.log("\u{1F4C4} Found existing CLAUDE.md");
|
|
9540
|
-
existingContent = (0,
|
|
9753
|
+
existingContent = (0, import_node_fs3.readFileSync)(claudeMdPath, "utf-8");
|
|
9541
9754
|
} else {
|
|
9542
9755
|
console.log("\u{1F4C4} No existing CLAUDE.md found - will create new file");
|
|
9543
9756
|
}
|
|
@@ -9559,7 +9772,7 @@ async function setupAI(options = {}) {
|
|
|
9559
9772
|
}
|
|
9560
9773
|
console.log("\u2500".repeat(60));
|
|
9561
9774
|
} else if (claudeMdResult.modified || claudeMdResult.created) {
|
|
9562
|
-
(0,
|
|
9775
|
+
(0, import_node_fs3.writeFileSync)(claudeMdPath, claudeMdResult.content, "utf-8");
|
|
9563
9776
|
if (claudeMdResult.created) {
|
|
9564
9777
|
console.log(` \u2713 Created ${claudeMdPath}`);
|
|
9565
9778
|
} else {
|
|
@@ -9571,7 +9784,7 @@ async function setupAI(options = {}) {
|
|
|
9571
9784
|
let cursorResult;
|
|
9572
9785
|
if (options.cursor) {
|
|
9573
9786
|
const cursorPath = (0, import_node_path8.resolve)(outputDir, ".cursorrules");
|
|
9574
|
-
const cursorExists = (0,
|
|
9787
|
+
const cursorExists = (0, import_node_fs3.existsSync)(cursorPath);
|
|
9575
9788
|
console.log("\n\u{1F4C4} Generating .cursorrules for Cursor IDE...");
|
|
9576
9789
|
const cursorContent = generateCursorRules(config);
|
|
9577
9790
|
if (options.dryRun) {
|
|
@@ -9583,7 +9796,7 @@ async function setupAI(options = {}) {
|
|
|
9583
9796
|
} else {
|
|
9584
9797
|
let shouldWrite = true;
|
|
9585
9798
|
if (cursorExists && !options.force) {
|
|
9586
|
-
const existingCursor = (0,
|
|
9799
|
+
const existingCursor = (0, import_node_fs3.readFileSync)(cursorPath, "utf-8");
|
|
9587
9800
|
if (!existingCursor.includes("Schemock Rules for Cursor")) {
|
|
9588
9801
|
console.log(" \u26A0\uFE0F Existing .cursorrules was not created by Schemock");
|
|
9589
9802
|
console.log(" Use --force to overwrite, or manually add Schemock rules");
|
|
@@ -9594,7 +9807,7 @@ async function setupAI(options = {}) {
|
|
|
9594
9807
|
}
|
|
9595
9808
|
}
|
|
9596
9809
|
if (shouldWrite) {
|
|
9597
|
-
(0,
|
|
9810
|
+
(0, import_node_fs3.writeFileSync)(cursorPath, cursorContent, "utf-8");
|
|
9598
9811
|
console.log(` \u2713 ${cursorExists ? "Updated" : "Created"} ${cursorPath}`);
|
|
9599
9812
|
}
|
|
9600
9813
|
cursorResult = { created: !cursorExists, modified: shouldWrite, path: cursorPath };
|
|
@@ -9617,11 +9830,11 @@ async function setupAI(options = {}) {
|
|
|
9617
9830
|
cursorRules: cursorResult
|
|
9618
9831
|
};
|
|
9619
9832
|
}
|
|
9620
|
-
var
|
|
9833
|
+
var import_node_fs3, import_node_path8;
|
|
9621
9834
|
var init_setup_ai = __esm({
|
|
9622
9835
|
"src/cli/commands/setup-ai.ts"() {
|
|
9623
9836
|
"use strict";
|
|
9624
|
-
|
|
9837
|
+
import_node_fs3 = require("fs");
|
|
9625
9838
|
import_node_path8 = require("path");
|
|
9626
9839
|
init_config();
|
|
9627
9840
|
init_claude_md();
|
|
@@ -9629,7 +9842,7 @@ var init_setup_ai = __esm({
|
|
|
9629
9842
|
});
|
|
9630
9843
|
|
|
9631
9844
|
// src/cli.ts
|
|
9632
|
-
var
|
|
9845
|
+
var import_node_fs4 = require("fs");
|
|
9633
9846
|
var import_node_path9 = require("path");
|
|
9634
9847
|
function parseArgs(args) {
|
|
9635
9848
|
const options = {};
|
|
@@ -9762,8 +9975,8 @@ Entity Filtering (in config):
|
|
|
9762
9975
|
function showVersion() {
|
|
9763
9976
|
try {
|
|
9764
9977
|
const pkgPath = (0, import_node_path9.resolve)(__dirname, "../package.json");
|
|
9765
|
-
if ((0,
|
|
9766
|
-
const pkg = JSON.parse((0,
|
|
9978
|
+
if ((0, import_node_fs4.existsSync)(pkgPath)) {
|
|
9979
|
+
const pkg = JSON.parse((0, import_node_fs4.readFileSync)(pkgPath, "utf-8"));
|
|
9767
9980
|
console.log(`schemock v${pkg.version}`);
|
|
9768
9981
|
return;
|
|
9769
9982
|
}
|
|
@@ -9778,13 +9991,13 @@ Initializing Schemock project with template: ${template}
|
|
|
9778
9991
|
`);
|
|
9779
9992
|
const dirs = ["src/schemas"];
|
|
9780
9993
|
for (const dir of dirs) {
|
|
9781
|
-
if (!(0,
|
|
9782
|
-
(0,
|
|
9994
|
+
if (!(0, import_node_fs4.existsSync)(dir)) {
|
|
9995
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
9783
9996
|
console.log(` Created ${dir}/`);
|
|
9784
9997
|
}
|
|
9785
9998
|
}
|
|
9786
9999
|
const schemaPath = "src/schemas/user.ts";
|
|
9787
|
-
if (!(0,
|
|
10000
|
+
if (!(0, import_node_fs4.existsSync)(schemaPath)) {
|
|
9788
10001
|
const schemaContent = `import { defineData, field, hasMany, belongsTo } from 'schemock/schema';
|
|
9789
10002
|
|
|
9790
10003
|
/**
|
|
@@ -9828,7 +10041,7 @@ export const commentSchema = defineData('comment', {
|
|
|
9828
10041
|
},
|
|
9829
10042
|
});
|
|
9830
10043
|
`;
|
|
9831
|
-
(0,
|
|
10044
|
+
(0, import_node_fs4.writeFileSync)(schemaPath, schemaContent);
|
|
9832
10045
|
console.log(` Created ${schemaPath}`);
|
|
9833
10046
|
}
|
|
9834
10047
|
const configPath = "schemock.config.ts";
|
|
@@ -9838,7 +10051,7 @@ export const commentSchema = defineData('comment', {
|
|
|
9838
10051
|
adapter: "mock",
|
|
9839
10052
|
apiPrefix: "/api"
|
|
9840
10053
|
};
|
|
9841
|
-
if (!(0,
|
|
10054
|
+
if (!(0, import_node_fs4.existsSync)(configPath)) {
|
|
9842
10055
|
const configContent = `import { defineConfig } from 'schemock/cli';
|
|
9843
10056
|
|
|
9844
10057
|
export default defineConfig({
|
|
@@ -9875,19 +10088,19 @@ export default defineConfig({
|
|
|
9875
10088
|
},
|
|
9876
10089
|
});
|
|
9877
10090
|
`;
|
|
9878
|
-
(0,
|
|
10091
|
+
(0, import_node_fs4.writeFileSync)(configPath, configContent);
|
|
9879
10092
|
console.log(` Created ${configPath}`);
|
|
9880
10093
|
}
|
|
9881
10094
|
console.log("\n\u{1F916} Setting up AI configuration...");
|
|
9882
10095
|
const { generateClaudeMd: generateClaudeMd2 } = await Promise.resolve().then(() => (init_claude_md(), claude_md_exports));
|
|
9883
10096
|
const claudeMdPath = (0, import_node_path9.resolve)("CLAUDE.md");
|
|
9884
10097
|
let existingClaudeMd = "";
|
|
9885
|
-
if ((0,
|
|
9886
|
-
existingClaudeMd = (0,
|
|
10098
|
+
if ((0, import_node_fs4.existsSync)(claudeMdPath)) {
|
|
10099
|
+
existingClaudeMd = (0, import_node_fs4.readFileSync)(claudeMdPath, "utf-8");
|
|
9887
10100
|
}
|
|
9888
10101
|
const claudeResult = generateClaudeMd2(defaultConfig, existingClaudeMd);
|
|
9889
10102
|
if (claudeResult.modified || claudeResult.created) {
|
|
9890
|
-
(0,
|
|
10103
|
+
(0, import_node_fs4.writeFileSync)(claudeMdPath, claudeResult.content, "utf-8");
|
|
9891
10104
|
if (claudeResult.created) {
|
|
9892
10105
|
console.log(" Created CLAUDE.md");
|
|
9893
10106
|
} else {
|
|
@@ -9962,8 +10175,8 @@ async function generateOpenAPICommand(options) {
|
|
|
9962
10175
|
description: "Generated by Schemock"
|
|
9963
10176
|
});
|
|
9964
10177
|
const output = format === "yaml" ? toYAML(spec) : JSON.stringify(spec, null, 2);
|
|
9965
|
-
(0,
|
|
9966
|
-
(0,
|
|
10178
|
+
(0, import_node_fs4.mkdirSync)((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
10179
|
+
(0, import_node_fs4.writeFileSync)(outputPath, output);
|
|
9967
10180
|
console.log(` Generated: ${outputPath}`);
|
|
9968
10181
|
console.log("\n\u2713 OpenAPI specification generated successfully!\n");
|
|
9969
10182
|
}
|
|
@@ -10002,8 +10215,8 @@ async function generatePostmanCommand(options) {
|
|
|
10002
10215
|
baseUrl: "http://localhost:3000",
|
|
10003
10216
|
description: "Generated by Schemock"
|
|
10004
10217
|
});
|
|
10005
|
-
(0,
|
|
10006
|
-
(0,
|
|
10218
|
+
(0, import_node_fs4.mkdirSync)((0, import_node_path9.dirname)(outputPath), { recursive: true });
|
|
10219
|
+
(0, import_node_fs4.writeFileSync)(outputPath, JSON.stringify(collection, null, 2));
|
|
10007
10220
|
console.log(` Generated: ${outputPath}`);
|
|
10008
10221
|
console.log("\n\u2713 Postman collection generated successfully!\n");
|
|
10009
10222
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { A as ArrayFieldBuilder, C as ComputedFieldDefinition, D as DateFieldBuilder, p as EmbedConfig, u as EndpointConfig, t as EndpointMethod, v as EndpointSchema, e as EntityApiConfig, h as EntityOptions, o as EntitySchema, E as EnumFieldBuilder, F as FieldBuilder, a as FieldConstraints, b as FieldDefinition, I as IndexConfig, z as InferCreate, y as InferEntity, x as InferFieldType, B as InferUpdate, M as MockResolverContext, N as NumberFieldBuilder, O as ObjectFieldBuilder, m as RLSBypass, n as RLSConfig, j as RLSContext, k as RLSFilter, l as RLSScopeMapping, f as RPCArgument, g as RPCConfig, R as RefFieldBuilder, c as RelationDefinition, S as StringFieldBuilder, V as ViewFieldValue, q as ViewFields, r as ViewOptions, s as ViewSchema, i as isComputedField, w as isEndpointSchema, d as isRelation } from './types-
|
|
1
|
+
export { A as ArrayFieldBuilder, C as ComputedFieldDefinition, D as DateFieldBuilder, p as EmbedConfig, u as EndpointConfig, t as EndpointMethod, v as EndpointSchema, e as EntityApiConfig, h as EntityOptions, o as EntitySchema, E as EnumFieldBuilder, F as FieldBuilder, a as FieldConstraints, b as FieldDefinition, I as IndexConfig, z as InferCreate, y as InferEntity, x as InferFieldType, B as InferUpdate, M as MockResolverContext, N as NumberFieldBuilder, O as ObjectFieldBuilder, m as RLSBypass, n as RLSConfig, j as RLSContext, k as RLSFilter, l as RLSScopeMapping, f as RPCArgument, g as RPCConfig, R as RefFieldBuilder, c as RelationDefinition, S as StringFieldBuilder, V as ViewFieldValue, q as ViewFields, r as ViewOptions, s as ViewSchema, i as isComputedField, w as isEndpointSchema, d as isRelation } from './types-BCLdZDSF.mjs';
|
|
2
2
|
export { BelongsToOptions, EmbedMarker, FieldDefinitions, HasManyOptions, HasOneOptions, ViewFieldDefinitions, belongsTo, defineData, defineEndpoint, defineView, embed, field, hasMany, hasOne, isEmbedMarker, omit, pick } from './schema/index.mjs';
|
|
3
3
|
export { DataGenerator, FetchAdapter, FirebaseAdapter, GraphQLAdapter, LocalStorageDriver, LocalStorageDriverConfig, MemoryStorageDriver, MockAdapter, MockAdapterConfig, MswStorageDriver, QueryMeta, QueryOptions, StorageDriver, StorageDriverConfig, SupabaseAdapter, createFetchAdapter, createFirebaseAdapter, createGraphQLAdapter, createMockAdapter, createSupabaseAdapter, dataGenerator, generateFactories, generateFactory } from './adapters/index.mjs';
|
|
4
|
-
export { A as Adapter, a as AdapterContext, b as AdapterResponse, c as AdapterResponseMeta, F as FetchAdapterOptions, M as MockAdapterOptions, d as MswjsDataFactory } from './types-
|
|
5
|
-
export { M as Middleware, b as MiddlewareContext, a as MiddlewareFunction, c as MiddlewareResult } from './types-
|
|
4
|
+
export { A as Adapter, a as AdapterContext, b as AdapterResponse, c as AdapterResponseMeta, F as FetchAdapterOptions, M as MockAdapterOptions, d as MswjsDataFactory } from './types-BBeKlEd1.mjs';
|
|
5
|
+
export { M as Middleware, b as MiddlewareContext, a as MiddlewareFunction, c as MiddlewareResult } from './types-DKrOkBcu.mjs';
|
|
6
6
|
export { AuthMiddlewareConfig, CacheEntry, CacheMiddlewareConfig, CacheStorage, ContextMiddlewareConfig, DEFAULT_MIDDLEWARE_ORDER, LogLevel, LoggerMiddlewareConfig, MOCK_MIDDLEWARE_PRESET, MemoryCacheStorage, MiddlewareChain, PRODUCTION_MIDDLEWARE_PRESET, RLSError, RLSFilters, RLSMiddlewareConfig, RetryMiddlewareConfig, TEST_MIDDLEWARE_PRESET, createAuthMiddleware, createBypassCheck, createCacheInvalidator, createCacheMiddleware, createContextMiddleware, createLoggerMiddleware, createMiddlewareChain, createMockJwt, createRLSMiddleware, createRetryMiddleware, createSilentLogger, createVerboseLogger, filterMiddleware, orderMiddleware } from './middleware/index.mjs';
|
|
7
7
|
export { CountOptions, CreateInput, EntityQueryOptions, HandlerOptions, ListQueryOptions, ResolveRelationOptions, Resolver, ResolverContext, SetupOptions, UpdateInput, ViewResolveOptions, ViewResolver, clearComputeCache, createHandlers, createResolver, createViewResolver, eagerLoadRelations, getAdapter, isInitialized, reset, resolveComputedField, resolveComputedFields, resolveComputedFieldsSync, resolveRelation, resolveRelations, seed, seedWithRelations, setAdapter, setup, teardown, topologicalSort } from './runtime/index.mjs';
|
|
8
8
|
import 'msw';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { A as ArrayFieldBuilder, C as ComputedFieldDefinition, D as DateFieldBuilder, p as EmbedConfig, u as EndpointConfig, t as EndpointMethod, v as EndpointSchema, e as EntityApiConfig, h as EntityOptions, o as EntitySchema, E as EnumFieldBuilder, F as FieldBuilder, a as FieldConstraints, b as FieldDefinition, I as IndexConfig, z as InferCreate, y as InferEntity, x as InferFieldType, B as InferUpdate, M as MockResolverContext, N as NumberFieldBuilder, O as ObjectFieldBuilder, m as RLSBypass, n as RLSConfig, j as RLSContext, k as RLSFilter, l as RLSScopeMapping, f as RPCArgument, g as RPCConfig, R as RefFieldBuilder, c as RelationDefinition, S as StringFieldBuilder, V as ViewFieldValue, q as ViewFields, r as ViewOptions, s as ViewSchema, i as isComputedField, w as isEndpointSchema, d as isRelation } from './types-
|
|
1
|
+
export { A as ArrayFieldBuilder, C as ComputedFieldDefinition, D as DateFieldBuilder, p as EmbedConfig, u as EndpointConfig, t as EndpointMethod, v as EndpointSchema, e as EntityApiConfig, h as EntityOptions, o as EntitySchema, E as EnumFieldBuilder, F as FieldBuilder, a as FieldConstraints, b as FieldDefinition, I as IndexConfig, z as InferCreate, y as InferEntity, x as InferFieldType, B as InferUpdate, M as MockResolverContext, N as NumberFieldBuilder, O as ObjectFieldBuilder, m as RLSBypass, n as RLSConfig, j as RLSContext, k as RLSFilter, l as RLSScopeMapping, f as RPCArgument, g as RPCConfig, R as RefFieldBuilder, c as RelationDefinition, S as StringFieldBuilder, V as ViewFieldValue, q as ViewFields, r as ViewOptions, s as ViewSchema, i as isComputedField, w as isEndpointSchema, d as isRelation } from './types-BCLdZDSF.js';
|
|
2
2
|
export { BelongsToOptions, EmbedMarker, FieldDefinitions, HasManyOptions, HasOneOptions, ViewFieldDefinitions, belongsTo, defineData, defineEndpoint, defineView, embed, field, hasMany, hasOne, isEmbedMarker, omit, pick } from './schema/index.js';
|
|
3
3
|
export { DataGenerator, FetchAdapter, FirebaseAdapter, GraphQLAdapter, LocalStorageDriver, LocalStorageDriverConfig, MemoryStorageDriver, MockAdapter, MockAdapterConfig, MswStorageDriver, QueryMeta, QueryOptions, StorageDriver, StorageDriverConfig, SupabaseAdapter, createFetchAdapter, createFirebaseAdapter, createGraphQLAdapter, createMockAdapter, createSupabaseAdapter, dataGenerator, generateFactories, generateFactory } from './adapters/index.js';
|
|
4
|
-
export { A as Adapter, a as AdapterContext, b as AdapterResponse, c as AdapterResponseMeta, F as FetchAdapterOptions, M as MockAdapterOptions, d as MswjsDataFactory } from './types-
|
|
5
|
-
export { M as Middleware, b as MiddlewareContext, a as MiddlewareFunction, c as MiddlewareResult } from './types-
|
|
4
|
+
export { A as Adapter, a as AdapterContext, b as AdapterResponse, c as AdapterResponseMeta, F as FetchAdapterOptions, M as MockAdapterOptions, d as MswjsDataFactory } from './types-CVeLQjhD.js';
|
|
5
|
+
export { M as Middleware, b as MiddlewareContext, a as MiddlewareFunction, c as MiddlewareResult } from './types-CZdze7Tl.js';
|
|
6
6
|
export { AuthMiddlewareConfig, CacheEntry, CacheMiddlewareConfig, CacheStorage, ContextMiddlewareConfig, DEFAULT_MIDDLEWARE_ORDER, LogLevel, LoggerMiddlewareConfig, MOCK_MIDDLEWARE_PRESET, MemoryCacheStorage, MiddlewareChain, PRODUCTION_MIDDLEWARE_PRESET, RLSError, RLSFilters, RLSMiddlewareConfig, RetryMiddlewareConfig, TEST_MIDDLEWARE_PRESET, createAuthMiddleware, createBypassCheck, createCacheInvalidator, createCacheMiddleware, createContextMiddleware, createLoggerMiddleware, createMiddlewareChain, createMockJwt, createRLSMiddleware, createRetryMiddleware, createSilentLogger, createVerboseLogger, filterMiddleware, orderMiddleware } from './middleware/index.js';
|
|
7
7
|
export { CountOptions, CreateInput, EntityQueryOptions, HandlerOptions, ListQueryOptions, ResolveRelationOptions, Resolver, ResolverContext, SetupOptions, UpdateInput, ViewResolveOptions, ViewResolver, clearComputeCache, createHandlers, createResolver, createViewResolver, eagerLoadRelations, getAdapter, isInitialized, reset, resolveComputedField, resolveComputedFields, resolveComputedFieldsSync, resolveRelation, resolveRelations, seed, seedWithRelations, setAdapter, setup, teardown, topologicalSort } from './runtime/index.js';
|
|
8
8
|
import 'msw';
|