@donotdev/cli 0.2.3 → 0.3.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/dependencies-matrix.json +27 -26
- package/dist/bin/commands/build.js +64 -2
- package/dist/bin/commands/bump.js +98 -13
- package/dist/bin/commands/db-check.js +192804 -0
- package/dist/bin/commands/db.js +16 -1
- package/dist/bin/commands/make-admin.js +22 -6
- package/dist/bin/commands/seed.js +313 -236
- package/dist/bin/commands/setup.js +549 -97
- package/dist/bin/dndev.js +23 -7
- package/dist/index.js +64 -2
- package/package.json +1 -1
- package/templates/app-demo/index.html.example +1 -1
- package/templates/app-dndev/index.html.example +1 -1
- package/templates/app-dndev/src/globals.css.example +1 -1
- package/templates/app-next/src/app/AppDocument.tsx.example +3 -2
- package/templates/app-next/src/globals.css.example +1 -1
- package/templates/app-vite/csp.example.json +1 -1
- package/templates/app-vite/index.html.example +1 -1
- package/templates/app-vite/src/globals.css.example +1 -1
- package/templates/deploy-config/vercel.json.example +2 -2
- package/templates/functions-supabase/supabase/migrations/20250101000006_crud_bulk_status_guard.sql +258 -0
- package/templates/functions-supabase/supabase/migrations/20250101000007_rate_limit_check.sql +76 -0
- package/templates/root-consumer/.claude/hooks/guard-bash.sh.example +3 -3
- package/templates/root-consumer/.claude/hooks/typecheck-stop.sh.example +2 -2
- package/templates/root-consumer/.claude/rules/definition-of-done.md.example +2 -2
- package/templates/root-consumer/.claude/rules/framework.md.example +1 -1
- package/templates/root-consumer/.claude/skills/build/SKILL.md.example +1 -1
- package/templates/root-consumer/.claude/skills/polish/SKILL.md.example +1 -1
- package/templates/root-consumer/AGENTS.md.example +25 -2
- package/templates/root-consumer/README.md.example +1 -1
|
@@ -2292,7 +2292,7 @@ var require_fill_range = __commonJS({
|
|
|
2292
2292
|
}
|
|
2293
2293
|
return options.stringify === true;
|
|
2294
2294
|
};
|
|
2295
|
-
var
|
|
2295
|
+
var pad2 = (input, maxLength, toNumber2) => {
|
|
2296
2296
|
if (maxLength > 0) {
|
|
2297
2297
|
let dash = input[0] === "-" ? "-" : "";
|
|
2298
2298
|
if (dash) input = input.slice(1);
|
|
@@ -2394,7 +2394,7 @@ var require_fill_range = __commonJS({
|
|
|
2394
2394
|
if (options.toRegex === true && step > 1) {
|
|
2395
2395
|
push(a2);
|
|
2396
2396
|
} else {
|
|
2397
|
-
range.push(
|
|
2397
|
+
range.push(pad2(format(a2, index), maxLen, toNumber2));
|
|
2398
2398
|
}
|
|
2399
2399
|
a2 = descending ? a2 - step : a2 + step;
|
|
2400
2400
|
index++;
|
|
@@ -9084,6 +9084,9 @@ var init_typed_file_operations = __esm({
|
|
|
9084
9084
|
});
|
|
9085
9085
|
|
|
9086
9086
|
// packages/tooling/src/utils/type-guards.ts
|
|
9087
|
+
function isRecord(value) {
|
|
9088
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9089
|
+
}
|
|
9087
9090
|
function isObjectLike(value) {
|
|
9088
9091
|
return typeof value === "object" && value !== null;
|
|
9089
9092
|
}
|
|
@@ -55598,7 +55601,7 @@ var require_client = __commonJS({
|
|
|
55598
55601
|
var INTERCEPTOR_SYMBOL = /* @__PURE__ */ Symbol();
|
|
55599
55602
|
var INTERCEPTOR_PROVIDER_SYMBOL = /* @__PURE__ */ Symbol();
|
|
55600
55603
|
var CALL_INVOCATION_TRANSFORMER_SYMBOL = /* @__PURE__ */ Symbol();
|
|
55601
|
-
function
|
|
55604
|
+
function isFunction2(arg) {
|
|
55602
55605
|
return typeof arg === "function";
|
|
55603
55606
|
}
|
|
55604
55607
|
function getErrorStackString(error2) {
|
|
@@ -55660,16 +55663,16 @@ var require_client = __commonJS({
|
|
|
55660
55663
|
setImmediate(checkState);
|
|
55661
55664
|
}
|
|
55662
55665
|
checkOptionalUnaryResponseArguments(arg1, arg2, arg3) {
|
|
55663
|
-
if (
|
|
55666
|
+
if (isFunction2(arg1)) {
|
|
55664
55667
|
return { metadata: new metadata_1.Metadata(), options: {}, callback: arg1 };
|
|
55665
|
-
} else if (
|
|
55668
|
+
} else if (isFunction2(arg2)) {
|
|
55666
55669
|
if (arg1 instanceof metadata_1.Metadata) {
|
|
55667
55670
|
return { metadata: arg1, options: {}, callback: arg2 };
|
|
55668
55671
|
} else {
|
|
55669
55672
|
return { metadata: new metadata_1.Metadata(), options: arg1, callback: arg2 };
|
|
55670
55673
|
}
|
|
55671
55674
|
} else {
|
|
55672
|
-
if (!(arg1 instanceof metadata_1.Metadata && arg2 instanceof Object &&
|
|
55675
|
+
if (!(arg1 instanceof metadata_1.Metadata && arg2 instanceof Object && isFunction2(arg3))) {
|
|
55673
55676
|
throw new Error("Incorrect arguments passed");
|
|
55674
55677
|
}
|
|
55675
55678
|
return { metadata: arg1, options: arg2, callback: arg3 };
|
|
@@ -169265,7 +169268,7 @@ var require_util12 = __commonJS({
|
|
|
169265
169268
|
exports.isObject = isObject;
|
|
169266
169269
|
exports.isPlainObject = isPlainObject2;
|
|
169267
169270
|
exports.isEmpty = isEmpty;
|
|
169268
|
-
exports.isFunction =
|
|
169271
|
+
exports.isFunction = isFunction2;
|
|
169269
169272
|
exports.isPermanentRpcError = isPermanentRpcError;
|
|
169270
169273
|
exports.getRetryCodes = getRetryCodes;
|
|
169271
169274
|
exports.getTotalTimeout = getTotalTimeout;
|
|
@@ -169321,7 +169324,7 @@ var require_util12 = __commonJS({
|
|
|
169321
169324
|
function isEmpty(value) {
|
|
169322
169325
|
return Object.keys(value).length === 0;
|
|
169323
169326
|
}
|
|
169324
|
-
function
|
|
169327
|
+
function isFunction2(value) {
|
|
169325
169328
|
return typeof value === "function";
|
|
169326
169329
|
}
|
|
169327
169330
|
function isPermanentRpcError(err, methodName) {
|
|
@@ -191673,6 +191676,65 @@ var init_firestore = __esm({
|
|
|
191673
191676
|
}
|
|
191674
191677
|
});
|
|
191675
191678
|
|
|
191679
|
+
// packages/tooling/src/utils/coreSemantics.ts
|
|
191680
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
191681
|
+
import { pathToFileURL } from "node:url";
|
|
191682
|
+
function isFunction(value) {
|
|
191683
|
+
return typeof value === "function";
|
|
191684
|
+
}
|
|
191685
|
+
async function loadCoreSemantics(fromFile2) {
|
|
191686
|
+
let resolved;
|
|
191687
|
+
try {
|
|
191688
|
+
resolved = createRequire4(fromFile2).resolve("@donotdev/core/server");
|
|
191689
|
+
} catch (error2) {
|
|
191690
|
+
throw new DoNotDevError(
|
|
191691
|
+
`Cannot resolve @donotdev/core from ${fromFile2}: install it in the app (entities import it).`,
|
|
191692
|
+
DO_NOT_DEV_ERROR_CODES.CONFIGURATION_ERROR,
|
|
191693
|
+
{ originalError: error2 instanceof Error ? error2 : void 0 }
|
|
191694
|
+
);
|
|
191695
|
+
}
|
|
191696
|
+
const mod3 = await import(pathToFileURL(resolved).href);
|
|
191697
|
+
if (!isRecord(mod3) || !isFunction(mod3.describeEntity) || !isFunction(mod3.createSchemas) || !Array.isArray(mod3.HIDDEN_STATUSES) || typeof mod3.DEFAULT_STATUS_VALUE !== "string") {
|
|
191698
|
+
throw new DoNotDevError(
|
|
191699
|
+
`@donotdev/core at ${resolved} has no describeEntity / createSchemas / HIDDEN_STATUSES / DEFAULT_STATUS_VALUE: upgrade @donotdev/core.`,
|
|
191700
|
+
DO_NOT_DEV_ERROR_CODES.CONFIGURATION_ERROR
|
|
191701
|
+
);
|
|
191702
|
+
}
|
|
191703
|
+
const describeEntity = mod3.describeEntity;
|
|
191704
|
+
const createSchemas = mod3.createSchemas;
|
|
191705
|
+
return {
|
|
191706
|
+
// why: the shapes are the core exports' (see the interfaces above); checked as functions
|
|
191707
|
+
describeEntity: (entity) => describeEntity(entity),
|
|
191708
|
+
createSchemas: (entity) => createSchemas(entity),
|
|
191709
|
+
hiddenStatuses: mod3.HIDDEN_STATUSES.map(String),
|
|
191710
|
+
defaultStatus: mod3.DEFAULT_STATUS_VALUE
|
|
191711
|
+
};
|
|
191712
|
+
}
|
|
191713
|
+
function schemaIssues(schema, value) {
|
|
191714
|
+
const standard = isObjectLike(schema) ? schema["~standard"] : void 0;
|
|
191715
|
+
if (!isRecord(standard) || !isFunction(standard.validate)) {
|
|
191716
|
+
throw new DoNotDevError("Not a Valibot schema", DO_NOT_DEV_ERROR_CODES.VALIDATION_ERROR);
|
|
191717
|
+
}
|
|
191718
|
+
const result = standard.validate(value);
|
|
191719
|
+
if (result instanceof Promise) {
|
|
191720
|
+
throw new DoNotDevError("Async schemas are not supported", DO_NOT_DEV_ERROR_CODES.VALIDATION_ERROR);
|
|
191721
|
+
}
|
|
191722
|
+
const issues = isRecord(result) && Array.isArray(result.issues) ? result.issues : [];
|
|
191723
|
+
return issues.map((issue) => {
|
|
191724
|
+
const message = isRecord(issue) && typeof issue.message === "string" ? issue.message : "Invalid value";
|
|
191725
|
+
const path = isRecord(issue) && Array.isArray(issue.path) ? issue.path.map((p) => isRecord(p) ? String(p.key) : String(p)).join(".") : void 0;
|
|
191726
|
+
return { message, ...path && { path } };
|
|
191727
|
+
});
|
|
191728
|
+
}
|
|
191729
|
+
var init_coreSemantics = __esm({
|
|
191730
|
+
"packages/tooling/src/utils/coreSemantics.ts"() {
|
|
191731
|
+
"use strict";
|
|
191732
|
+
init_utils2();
|
|
191733
|
+
init_errors();
|
|
191734
|
+
init_type_guards();
|
|
191735
|
+
}
|
|
191736
|
+
});
|
|
191737
|
+
|
|
191676
191738
|
// packages/cli/src/bin/commands/seed.ts
|
|
191677
191739
|
init_utils2();
|
|
191678
191740
|
|
|
@@ -191769,7 +191831,7 @@ async function createSupabaseContext(projectRoot, appDir, framework, entities) {
|
|
|
191769
191831
|
const { extractProjectRef: extractProjectRef2 } = await Promise.resolve().then(() => (init_supabase_management(), supabase_management_exports));
|
|
191770
191832
|
const supabaseUrl = config.url;
|
|
191771
191833
|
const projectRef = extractProjectRef2(supabaseUrl);
|
|
191772
|
-
async function
|
|
191834
|
+
async function postQuery(sql) {
|
|
191773
191835
|
const mgmtUrl = `https://api.supabase.com/v1/projects/${projectRef}/database/query`;
|
|
191774
191836
|
const response = await fetch(mgmtUrl, {
|
|
191775
191837
|
method: "POST",
|
|
@@ -191784,6 +191846,17 @@ async function createSupabaseContext(projectRoot, appDir, framework, entities) {
|
|
|
191784
191846
|
const safe = body.replace(/sbp_[^\s"']*/g, "***").replace(/sb_secret_[^\s"']*/g, "***");
|
|
191785
191847
|
throw new Error(`Supabase API error (HTTP ${response.status}): ${safe}`);
|
|
191786
191848
|
}
|
|
191849
|
+
return response;
|
|
191850
|
+
}
|
|
191851
|
+
async function executeSQL(sql) {
|
|
191852
|
+
await postQuery(sql);
|
|
191853
|
+
}
|
|
191854
|
+
async function querySQL(sql) {
|
|
191855
|
+
const rows = await (await postQuery(sql)).json();
|
|
191856
|
+
if (!Array.isArray(rows)) {
|
|
191857
|
+
throw new Error("Supabase API error: the query did not return rows");
|
|
191858
|
+
}
|
|
191859
|
+
return rows.filter(isObjectLike);
|
|
191787
191860
|
}
|
|
191788
191861
|
return {
|
|
191789
191862
|
provider: "supabase",
|
|
@@ -191792,6 +191865,7 @@ async function createSupabaseContext(projectRoot, appDir, framework, entities) {
|
|
|
191792
191865
|
framework,
|
|
191793
191866
|
entities,
|
|
191794
191867
|
executeSQL,
|
|
191868
|
+
querySQL,
|
|
191795
191869
|
async insertRows(collection, rows) {
|
|
191796
191870
|
if (rows.length === 0) return 0;
|
|
191797
191871
|
const snakeRows = rows.map((row) => {
|
|
@@ -191853,6 +191927,9 @@ async function createFirebaseContext(projectRoot, appDir, framework, entities) {
|
|
|
191853
191927
|
"executeSQL is not supported for Firebase. Use insertRows() or write custom scripts."
|
|
191854
191928
|
);
|
|
191855
191929
|
},
|
|
191930
|
+
async querySQL(_sql) {
|
|
191931
|
+
throw new Error("querySQL is not supported for Firebase (no SQL).");
|
|
191932
|
+
},
|
|
191856
191933
|
async insertRows(collection, rows) {
|
|
191857
191934
|
if (rows.length === 0) return 0;
|
|
191858
191935
|
const BATCH_SIZE = 500;
|
|
@@ -191927,6 +192004,176 @@ async function createDbContext(options = {}) {
|
|
|
191927
192004
|
|
|
191928
192005
|
// packages/tooling/src/db/seed-generator.ts
|
|
191929
192006
|
init_utils2();
|
|
192007
|
+
|
|
192008
|
+
// packages/testing/src/common/sampleValues.ts
|
|
192009
|
+
init_utils2();
|
|
192010
|
+
function isRecord2(value) {
|
|
192011
|
+
return typeof value === "object" && value !== null;
|
|
192012
|
+
}
|
|
192013
|
+
function isStandardSchema(value) {
|
|
192014
|
+
if (!isRecord2(value)) return false;
|
|
192015
|
+
const standard = value["~standard"];
|
|
192016
|
+
return isRecord2(standard) && typeof standard.validate === "function";
|
|
192017
|
+
}
|
|
192018
|
+
function schemaAccepts(schema, value) {
|
|
192019
|
+
if (!isStandardSchema(schema)) {
|
|
192020
|
+
throw new Error("schemaAccepts: not a Valibot (Standard Schema) schema");
|
|
192021
|
+
}
|
|
192022
|
+
const result = schema["~standard"].validate(value);
|
|
192023
|
+
if (result instanceof Promise) {
|
|
192024
|
+
throw new Error("schemaAccepts: async schemas are not supported");
|
|
192025
|
+
}
|
|
192026
|
+
return !result.issues || result.issues.length === 0;
|
|
192027
|
+
}
|
|
192028
|
+
var WRAPPERS = /* @__PURE__ */ new Set([
|
|
192029
|
+
"optional",
|
|
192030
|
+
"exact_optional",
|
|
192031
|
+
"nullable",
|
|
192032
|
+
"nullish",
|
|
192033
|
+
"undefinedable",
|
|
192034
|
+
"non_nullable",
|
|
192035
|
+
"non_nullish",
|
|
192036
|
+
"non_optional"
|
|
192037
|
+
]);
|
|
192038
|
+
var OPTIONAL_WRAPPERS = /* @__PURE__ */ new Set(["optional", "exact_optional", "nullish", "undefinedable"]);
|
|
192039
|
+
var pad = (n3, width = 2) => String(n3).padStart(width, "0");
|
|
192040
|
+
function optionValues(options) {
|
|
192041
|
+
if (!Array.isArray(options)) return [];
|
|
192042
|
+
return options.map((opt) => isRecord2(opt) && "value" in opt ? opt.value : opt);
|
|
192043
|
+
}
|
|
192044
|
+
function pipeRequirement(schema, type) {
|
|
192045
|
+
const pipe = schema.pipe;
|
|
192046
|
+
if (!Array.isArray(pipe)) return void 0;
|
|
192047
|
+
for (const action of pipe) {
|
|
192048
|
+
if (isRecord2(action) && action.type === type) return action.requirement;
|
|
192049
|
+
}
|
|
192050
|
+
return void 0;
|
|
192051
|
+
}
|
|
192052
|
+
function stringCandidates(input, ctx, schema) {
|
|
192053
|
+
const day = new Date(Date.UTC(2026, ctx.index % 12, 1 + ctx.index % 28, 10, 30));
|
|
192054
|
+
const isoDate = day.toISOString().slice(0, 10);
|
|
192055
|
+
switch (input.value.kind) {
|
|
192056
|
+
case "date":
|
|
192057
|
+
return [isoDate, day.toISOString()];
|
|
192058
|
+
case "timestamp":
|
|
192059
|
+
return [day.toISOString(), isoDate];
|
|
192060
|
+
case "time":
|
|
192061
|
+
return [`${pad(8 + ctx.index % 10)}:30`, `${pad(8 + ctx.index % 10)}:30:00`];
|
|
192062
|
+
default:
|
|
192063
|
+
break;
|
|
192064
|
+
}
|
|
192065
|
+
const n3 = ctx.index + 1;
|
|
192066
|
+
const label = input.label ?? input.name;
|
|
192067
|
+
const text = `${input.entity} ${label} ${n3}`;
|
|
192068
|
+
const minLength = Number(pipeRequirement(schema, "min_length") ?? input.validation?.minLength ?? 0);
|
|
192069
|
+
const maxLength = Number(pipeRequirement(schema, "max_length") ?? input.validation?.maxLength ?? Infinity);
|
|
192070
|
+
const sized = text.padEnd(minLength, " lorem ipsum").slice(0, maxLength);
|
|
192071
|
+
return [
|
|
192072
|
+
sized,
|
|
192073
|
+
text,
|
|
192074
|
+
`user${n3}@example.com`,
|
|
192075
|
+
`https://example.com/${input.entity.toLowerCase()}/${n3}`,
|
|
192076
|
+
`+33 6 12 34 ${pad(10 + ctx.index % 90)} 78`,
|
|
192077
|
+
`#${(3368601 + ctx.index).toString(16).padStart(6, "0").slice(-6)}`,
|
|
192078
|
+
"FR7630006000011234567890189",
|
|
192079
|
+
`2026-W${pad(1 + ctx.index % 52)}`,
|
|
192080
|
+
`2026-${pad(1 + ctx.index % 12)}`,
|
|
192081
|
+
isoDate,
|
|
192082
|
+
`${pad(8 + ctx.index % 10)}:30`,
|
|
192083
|
+
`Sample${n3}Pass!word`,
|
|
192084
|
+
String(n3)
|
|
192085
|
+
];
|
|
192086
|
+
}
|
|
192087
|
+
function numberCandidates(input, ctx, schema) {
|
|
192088
|
+
const min = Number(pipeRequirement(schema, "min_value") ?? input.validation?.min ?? 1);
|
|
192089
|
+
const max = Number(pipeRequirement(schema, "max_value") ?? input.validation?.max ?? Math.max(min, 1) * 100);
|
|
192090
|
+
const value = min + ctx.rand() * (max - min);
|
|
192091
|
+
const rounded = Math.round(value);
|
|
192092
|
+
return [
|
|
192093
|
+
input.value.kind === "integer" ? rounded : Math.round(value * 100) / 100,
|
|
192094
|
+
rounded,
|
|
192095
|
+
min,
|
|
192096
|
+
max,
|
|
192097
|
+
0
|
|
192098
|
+
];
|
|
192099
|
+
}
|
|
192100
|
+
function candidates(schema, input, ctx, depth) {
|
|
192101
|
+
if (!isRecord2(schema) || depth > 8) return [];
|
|
192102
|
+
const type = schema.type;
|
|
192103
|
+
if (typeof type !== "string") return [];
|
|
192104
|
+
if (WRAPPERS.has(type)) return candidates(schema.wrapped, input, ctx, depth + 1);
|
|
192105
|
+
switch (type) {
|
|
192106
|
+
case "string":
|
|
192107
|
+
return stringCandidates(input, ctx, schema);
|
|
192108
|
+
case "number":
|
|
192109
|
+
return numberCandidates(input, ctx, schema);
|
|
192110
|
+
case "boolean":
|
|
192111
|
+
return [ctx.index % 2 === 0, ctx.index % 2 !== 0];
|
|
192112
|
+
case "literal":
|
|
192113
|
+
return [schema.literal];
|
|
192114
|
+
case "picklist": {
|
|
192115
|
+
const options = Array.isArray(schema.options) ? schema.options : [];
|
|
192116
|
+
return options.length > 0 ? [options[ctx.index % options.length], ...options] : [];
|
|
192117
|
+
}
|
|
192118
|
+
case "enum":
|
|
192119
|
+
return isRecord2(schema.enum) ? Object.values(schema.enum) : [];
|
|
192120
|
+
case "union":
|
|
192121
|
+
case "variant": {
|
|
192122
|
+
const options = Array.isArray(schema.options) ? schema.options : [];
|
|
192123
|
+
return options.flatMap((option) => candidates(option, input, ctx, depth + 1));
|
|
192124
|
+
}
|
|
192125
|
+
case "array": {
|
|
192126
|
+
const item = firstAccepted(schema.item, candidates(schema.item, input, ctx, depth + 1));
|
|
192127
|
+
return item === NONE ? [[]] : [[item], []];
|
|
192128
|
+
}
|
|
192129
|
+
case "record":
|
|
192130
|
+
return [{}];
|
|
192131
|
+
case "object":
|
|
192132
|
+
case "loose_object":
|
|
192133
|
+
case "strict_object": {
|
|
192134
|
+
if (!isRecord2(schema.entries)) return [];
|
|
192135
|
+
const out = {};
|
|
192136
|
+
for (const [key, entry] of Object.entries(schema.entries)) {
|
|
192137
|
+
if (isRecord2(entry) && typeof entry.type === "string" && OPTIONAL_WRAPPERS.has(entry.type)) continue;
|
|
192138
|
+
const value = firstAccepted(entry, candidates(entry, input, ctx, depth + 1));
|
|
192139
|
+
if (value === NONE) return [];
|
|
192140
|
+
out[key] = value;
|
|
192141
|
+
}
|
|
192142
|
+
return [out];
|
|
192143
|
+
}
|
|
192144
|
+
case "unknown":
|
|
192145
|
+
case "any":
|
|
192146
|
+
return [`${input.entity} ${input.name} ${ctx.index + 1}`];
|
|
192147
|
+
default:
|
|
192148
|
+
return [];
|
|
192149
|
+
}
|
|
192150
|
+
}
|
|
192151
|
+
var NONE = /* @__PURE__ */ Symbol("none");
|
|
192152
|
+
function firstAccepted(schema, values) {
|
|
192153
|
+
for (const value of values) {
|
|
192154
|
+
if (schemaAccepts(schema, value)) return value;
|
|
192155
|
+
}
|
|
192156
|
+
return NONE;
|
|
192157
|
+
}
|
|
192158
|
+
function sampleValue(input, ctx) {
|
|
192159
|
+
const { kind, schema } = input.value;
|
|
192160
|
+
if (kind === "ref") {
|
|
192161
|
+
throw new Error(`${input.entity}.${input.name}: a reference has no sample value; link it to a row id`);
|
|
192162
|
+
}
|
|
192163
|
+
const options = optionValues(input.validation?.options);
|
|
192164
|
+
const rotated = options.length > 0 ? [options[ctx.index % options.length], ...options] : [];
|
|
192165
|
+
const value = firstAccepted(schema, [...rotated, ...candidates(schema, input, ctx, 0)]);
|
|
192166
|
+
if (value === NONE) {
|
|
192167
|
+
throw new Error(
|
|
192168
|
+
`${input.entity}.${input.name}: cannot generate a sample ${kind} value accepted by its schema; pass the value explicitly`
|
|
192169
|
+
);
|
|
192170
|
+
}
|
|
192171
|
+
return value;
|
|
192172
|
+
}
|
|
192173
|
+
|
|
192174
|
+
// packages/tooling/src/db/seed-generator.ts
|
|
192175
|
+
init_coreSemantics();
|
|
192176
|
+
init_type_guards();
|
|
191930
192177
|
function mulberry32(seed) {
|
|
191931
192178
|
let s2 = seed | 0;
|
|
191932
192179
|
return () => {
|
|
@@ -191936,227 +192183,41 @@ function mulberry32(seed) {
|
|
|
191936
192183
|
return ((t3 ^ t3 >>> 14) >>> 0) / 4294967296;
|
|
191937
192184
|
};
|
|
191938
192185
|
}
|
|
191939
|
-
var TECHNICAL_KEYS = /* @__PURE__ */ new Set([
|
|
191940
|
-
"id",
|
|
191941
|
-
"createdAt",
|
|
191942
|
-
"updatedAt",
|
|
191943
|
-
"createdById",
|
|
191944
|
-
"updatedById",
|
|
191945
|
-
"status"
|
|
191946
|
-
]);
|
|
191947
|
-
var LOREM_WORDS = [
|
|
191948
|
-
"lorem",
|
|
191949
|
-
"ipsum",
|
|
191950
|
-
"dolor",
|
|
191951
|
-
"sit",
|
|
191952
|
-
"amet",
|
|
191953
|
-
"consectetur",
|
|
191954
|
-
"adipiscing",
|
|
191955
|
-
"elit",
|
|
191956
|
-
"sed",
|
|
191957
|
-
"do",
|
|
191958
|
-
"eiusmod",
|
|
191959
|
-
"tempor",
|
|
191960
|
-
"incididunt",
|
|
191961
|
-
"ut",
|
|
191962
|
-
"labore",
|
|
191963
|
-
"et",
|
|
191964
|
-
"dolore",
|
|
191965
|
-
"magna",
|
|
191966
|
-
"aliqua",
|
|
191967
|
-
"enim",
|
|
191968
|
-
"ad",
|
|
191969
|
-
"minim",
|
|
191970
|
-
"veniam",
|
|
191971
|
-
"quis",
|
|
191972
|
-
"nostrud",
|
|
191973
|
-
"exercitation",
|
|
191974
|
-
"ullamco",
|
|
191975
|
-
"laboris",
|
|
191976
|
-
"nisi",
|
|
191977
|
-
"aliquip",
|
|
191978
|
-
"ex",
|
|
191979
|
-
"ea",
|
|
191980
|
-
"commodo",
|
|
191981
|
-
"consequat"
|
|
191982
|
-
];
|
|
191983
|
-
function loremSentence(rand, wordCount) {
|
|
191984
|
-
const words = [];
|
|
191985
|
-
for (let i3 = 0; i3 < wordCount; i3++) {
|
|
191986
|
-
words.push(LOREM_WORDS[Math.floor(rand() * LOREM_WORDS.length)]);
|
|
191987
|
-
}
|
|
191988
|
-
const s2 = words.join(" ");
|
|
191989
|
-
return s2.charAt(0).toUpperCase() + s2.slice(1) + ".";
|
|
191990
|
-
}
|
|
191991
|
-
function randomDate(rand, daysBack = 365) {
|
|
191992
|
-
const now = Date.now();
|
|
191993
|
-
const offset = Math.floor(rand() * daysBack * 24 * 60 * 60 * 1e3);
|
|
191994
|
-
return new Date(now - offset);
|
|
191995
|
-
}
|
|
191996
192186
|
function randomInt(rand, min, max) {
|
|
191997
192187
|
return Math.floor(rand() * (max - min + 1)) + min;
|
|
191998
192188
|
}
|
|
191999
|
-
function
|
|
192000
|
-
|
|
192001
|
-
const factor = Math.pow(10, decimals);
|
|
192002
|
-
return Math.round(val * factor) / factor;
|
|
192189
|
+
function validationOf(field) {
|
|
192190
|
+
return isObjectLike(field) && isObjectLike(field.validation) ? field.validation : void 0;
|
|
192003
192191
|
}
|
|
192004
|
-
function
|
|
192005
|
-
const
|
|
192006
|
-
|
|
192007
|
-
// ── Text types ──
|
|
192008
|
-
case "text":
|
|
192009
|
-
return `${entityName} ${field.label ?? field.name} ${index + 1}`;
|
|
192010
|
-
case "textarea":
|
|
192011
|
-
case "richtext":
|
|
192012
|
-
return loremSentence(rand, randomInt(rand, 8, 20));
|
|
192013
|
-
case "email":
|
|
192014
|
-
return `user${index + 1}@example.com`;
|
|
192015
|
-
case "tel":
|
|
192016
|
-
return `+1555${String(index + 1).padStart(7, "0")}`;
|
|
192017
|
-
case "url":
|
|
192018
|
-
return `https://example.com/${entityName.toLowerCase()}/${index + 1}`;
|
|
192019
|
-
case "password":
|
|
192020
|
-
return null;
|
|
192021
|
-
// Never seed passwords
|
|
192022
|
-
// ── Number types ──
|
|
192023
|
-
case "number": {
|
|
192024
|
-
const min = v?.min ?? 1;
|
|
192025
|
-
const max = v?.max ?? 1e3;
|
|
192026
|
-
return randomInt(rand, min, max);
|
|
192027
|
-
}
|
|
192028
|
-
case "currency":
|
|
192029
|
-
case "price": {
|
|
192030
|
-
const min = v?.min ?? 1;
|
|
192031
|
-
const max = v?.max ?? 500;
|
|
192032
|
-
if (field.type === "price") {
|
|
192033
|
-
return { amount: randomFloat(rand, min, max), currency: "USD" };
|
|
192034
|
-
}
|
|
192035
|
-
return randomFloat(rand, min, max);
|
|
192036
|
-
}
|
|
192037
|
-
case "rating": {
|
|
192038
|
-
const max = v?.max ?? 5;
|
|
192039
|
-
return randomInt(rand, 1, max);
|
|
192040
|
-
}
|
|
192041
|
-
case "duration":
|
|
192042
|
-
return randomInt(rand, 60, 7200);
|
|
192043
|
-
// seconds
|
|
192044
|
-
case "range":
|
|
192045
|
-
return randomInt(rand, v?.min ?? 0, v?.max ?? 100);
|
|
192046
|
-
// ── Boolean types ──
|
|
192047
|
-
case "boolean":
|
|
192048
|
-
case "checkbox":
|
|
192049
|
-
case "switch":
|
|
192050
|
-
return index % 2 === 0;
|
|
192051
|
-
case "gdprConsent":
|
|
192052
|
-
return true;
|
|
192053
|
-
// ── Date types ──
|
|
192054
|
-
case "date":
|
|
192055
|
-
case "month":
|
|
192056
|
-
case "week":
|
|
192057
|
-
return randomDate(rand).toISOString().split("T")[0];
|
|
192058
|
-
case "timestamp":
|
|
192059
|
-
case "datetime-local":
|
|
192060
|
-
return randomDate(rand).toISOString();
|
|
192061
|
-
case "time":
|
|
192062
|
-
return `${String(randomInt(rand, 0, 23)).padStart(2, "0")}:${String(randomInt(rand, 0, 59)).padStart(2, "0")}`;
|
|
192063
|
-
case "year":
|
|
192064
|
-
return randomInt(rand, 2020, 2026);
|
|
192065
|
-
// ── Selection types ──
|
|
192066
|
-
case "select":
|
|
192067
|
-
case "radio":
|
|
192068
|
-
case "status": {
|
|
192069
|
-
const options = extractOptions(v?.options);
|
|
192070
|
-
if (options.length > 0) {
|
|
192071
|
-
return options[index % options.length];
|
|
192072
|
-
}
|
|
192073
|
-
return `option_${index % 3 + 1}`;
|
|
192074
|
-
}
|
|
192075
|
-
case "multiselect": {
|
|
192076
|
-
const options = extractOptions(v?.options);
|
|
192077
|
-
if (options.length > 0) {
|
|
192078
|
-
const count = randomInt(rand, 1, Math.min(3, options.length));
|
|
192079
|
-
const shuffled = [...options].sort(() => rand() - 0.5);
|
|
192080
|
-
return shuffled.slice(0, count);
|
|
192081
|
-
}
|
|
192082
|
-
return [`option_${index % 3 + 1}`];
|
|
192083
|
-
}
|
|
192084
|
-
// ── File types ──
|
|
192085
|
-
case "image":
|
|
192086
|
-
case "avatar":
|
|
192087
|
-
return `https://picsum.photos/seed/${entityName.toLowerCase()}${index}/400/300`;
|
|
192088
|
-
case "images":
|
|
192089
|
-
return [
|
|
192090
|
-
`https://picsum.photos/seed/${entityName.toLowerCase()}${index}a/400/300`,
|
|
192091
|
-
`https://picsum.photos/seed/${entityName.toLowerCase()}${index}b/400/300`
|
|
192092
|
-
];
|
|
192093
|
-
case "file":
|
|
192094
|
-
case "document":
|
|
192095
|
-
return `uploads/${entityName.toLowerCase()}/sample-${index + 1}.pdf`;
|
|
192096
|
-
case "files":
|
|
192097
|
-
case "documents":
|
|
192098
|
-
return [
|
|
192099
|
-
`uploads/${entityName.toLowerCase()}/sample-${index + 1}a.pdf`,
|
|
192100
|
-
`uploads/${entityName.toLowerCase()}/sample-${index + 1}b.pdf`
|
|
192101
|
-
];
|
|
192102
|
-
// ── Complex types ──
|
|
192103
|
-
case "geopoint":
|
|
192104
|
-
return {
|
|
192105
|
-
lat: randomFloat(rand, -90, 90, 6),
|
|
192106
|
-
lng: randomFloat(rand, -180, 180, 6)
|
|
192107
|
-
};
|
|
192108
|
-
case "address":
|
|
192109
|
-
return {
|
|
192110
|
-
street: `${randomInt(rand, 1, 9999)} Main St`,
|
|
192111
|
-
city: "Springfield",
|
|
192112
|
-
state: "IL",
|
|
192113
|
-
zip: String(randomInt(rand, 1e4, 99999)),
|
|
192114
|
-
country: "US"
|
|
192115
|
-
};
|
|
192116
|
-
case "color":
|
|
192117
|
-
return `#${randomInt(rand, 0, 16777215).toString(16).padStart(6, "0")}`;
|
|
192118
|
-
case "iban":
|
|
192119
|
-
return `DE${randomInt(rand, 10, 99)}${String(randomInt(rand, 1e8, 999999999))}${String(randomInt(rand, 1e8, 999999999))}`;
|
|
192120
|
-
case "reference":
|
|
192121
|
-
return null;
|
|
192122
|
-
// ── Map / Array / Object ──
|
|
192123
|
-
case "map":
|
|
192124
|
-
case "array":
|
|
192125
|
-
return {};
|
|
192126
|
-
case "combobox":
|
|
192127
|
-
case "badge":
|
|
192128
|
-
return `${field.label ?? field.name} ${index + 1}`;
|
|
192129
|
-
default:
|
|
192130
|
-
return `${entityName} ${field.name} ${index + 1}`;
|
|
192131
|
-
}
|
|
192192
|
+
function referenceOf(core, entity, key) {
|
|
192193
|
+
const value = core.describeEntity(entity).fields[key]?.value;
|
|
192194
|
+
return value?.kind === "ref" ? value.ref : void 0;
|
|
192132
192195
|
}
|
|
192133
|
-
function
|
|
192134
|
-
|
|
192135
|
-
return options.map((opt) => {
|
|
192136
|
-
if (typeof opt === "string") return opt;
|
|
192137
|
-
if (opt && typeof opt === "object" && "value" in opt)
|
|
192138
|
-
return String(opt.value);
|
|
192139
|
-
return String(opt);
|
|
192140
|
-
});
|
|
192141
|
-
}
|
|
192142
|
-
function generateRows(entity, count, rand) {
|
|
192196
|
+
function generateRows(entity, count, rand, core) {
|
|
192197
|
+
const descriptor = core.describeEntity(entity);
|
|
192143
192198
|
const rows = [];
|
|
192144
192199
|
for (let i3 = 0; i3 < count; i3++) {
|
|
192145
|
-
const row = {};
|
|
192146
|
-
row.status = "available";
|
|
192200
|
+
const row = { status: core.defaultStatus };
|
|
192147
192201
|
for (const [key, field] of Object.entries(entity.fields)) {
|
|
192148
|
-
|
|
192149
|
-
if (!
|
|
192150
|
-
|
|
192151
|
-
|
|
192152
|
-
|
|
192153
|
-
|
|
192202
|
+
const d = descriptor.fields[key];
|
|
192203
|
+
if (!d || key === "status" || d.write === "never") continue;
|
|
192204
|
+
if (d.value.kind === "ref") continue;
|
|
192205
|
+
row[key] = sampleValue(
|
|
192206
|
+
{
|
|
192207
|
+
entity: entity.name,
|
|
192208
|
+
name: key,
|
|
192209
|
+
label: typeof field.label === "string" ? field.label : void 0,
|
|
192210
|
+
value: { kind: d.value.kind, schema: d.value.schema },
|
|
192211
|
+
validation: validationOf(field)
|
|
192212
|
+
},
|
|
192213
|
+
{ index: i3, rand }
|
|
192214
|
+
);
|
|
192154
192215
|
}
|
|
192155
192216
|
rows.push(row);
|
|
192156
192217
|
}
|
|
192157
192218
|
return rows;
|
|
192158
192219
|
}
|
|
192159
|
-
function topologicalSort(entities) {
|
|
192220
|
+
function topologicalSort(entities, core) {
|
|
192160
192221
|
const byCollection = /* @__PURE__ */ new Map();
|
|
192161
192222
|
for (const e2 of entities) {
|
|
192162
192223
|
byCollection.set(e2.collection, e2);
|
|
@@ -192164,13 +192225,9 @@ function topologicalSort(entities) {
|
|
|
192164
192225
|
const deps = /* @__PURE__ */ new Map();
|
|
192165
192226
|
for (const e2 of entities) {
|
|
192166
192227
|
const entityDeps = /* @__PURE__ */ new Set();
|
|
192167
|
-
for (const
|
|
192168
|
-
|
|
192169
|
-
|
|
192170
|
-
if (refCollection !== e2.collection) {
|
|
192171
|
-
entityDeps.add(refCollection);
|
|
192172
|
-
}
|
|
192173
|
-
}
|
|
192228
|
+
for (const key of Object.keys(e2.fields)) {
|
|
192229
|
+
const ref = referenceOf(core, e2, key);
|
|
192230
|
+
if (ref && ref !== e2.collection) entityDeps.add(ref);
|
|
192174
192231
|
}
|
|
192175
192232
|
deps.set(e2.collection, entityDeps);
|
|
192176
192233
|
}
|
|
@@ -192197,14 +192254,14 @@ function topologicalSort(entities) {
|
|
|
192197
192254
|
}
|
|
192198
192255
|
return sorted;
|
|
192199
192256
|
}
|
|
192200
|
-
function generateSeedData(entities, options = {}) {
|
|
192257
|
+
function generateSeedData(entities, core, options = {}) {
|
|
192201
192258
|
const count = options.count ?? 10;
|
|
192202
192259
|
const rand = mulberry32(options.seed ?? 42);
|
|
192203
|
-
const sorted = topologicalSort(entities);
|
|
192260
|
+
const sorted = topologicalSort(entities, core);
|
|
192204
192261
|
const result = /* @__PURE__ */ new Map();
|
|
192205
192262
|
const generatedIds = /* @__PURE__ */ new Map();
|
|
192206
192263
|
for (const entity of sorted) {
|
|
192207
|
-
const rows = generateRows(entity, count, rand);
|
|
192264
|
+
const rows = generateRows(entity, count, rand, core);
|
|
192208
192265
|
const ids = [];
|
|
192209
192266
|
for (let i3 = 0; i3 < rows.length; i3++) {
|
|
192210
192267
|
const id = [
|
|
@@ -192218,17 +192275,24 @@ function generateSeedData(entities, options = {}) {
|
|
|
192218
192275
|
rows[i3].id = id;
|
|
192219
192276
|
}
|
|
192220
192277
|
generatedIds.set(entity.collection, ids);
|
|
192221
|
-
for (const
|
|
192222
|
-
|
|
192223
|
-
|
|
192224
|
-
|
|
192225
|
-
|
|
192226
|
-
|
|
192227
|
-
|
|
192228
|
-
}
|
|
192278
|
+
for (const key of Object.keys(entity.fields)) {
|
|
192279
|
+
const ref = referenceOf(core, entity, key);
|
|
192280
|
+
if (!ref) continue;
|
|
192281
|
+
const refIds = generatedIds.get(ref);
|
|
192282
|
+
if (refIds && refIds.length > 0) {
|
|
192283
|
+
for (let i3 = 0; i3 < rows.length; i3++) {
|
|
192284
|
+
rows[i3][key] = refIds[i3 % refIds.length];
|
|
192229
192285
|
}
|
|
192230
192286
|
}
|
|
192231
192287
|
}
|
|
192288
|
+
const createSchema = core.createSchemas(entity).create;
|
|
192289
|
+
rows.forEach((row, i3) => {
|
|
192290
|
+
const issues = schemaIssues(createSchema, row);
|
|
192291
|
+
if (issues.length > 0) {
|
|
192292
|
+
const detail = issues.map((issue) => `${issue.path ?? "root"}: ${issue.message}`).join("; ");
|
|
192293
|
+
throw new Error(`${entity.name}: seed row ${i3 + 1} fails the create schema: ${detail}`);
|
|
192294
|
+
}
|
|
192295
|
+
});
|
|
192232
192296
|
result.set(entity.collection, rows);
|
|
192233
192297
|
}
|
|
192234
192298
|
return result;
|
|
@@ -192236,6 +192300,8 @@ function generateSeedData(entities, options = {}) {
|
|
|
192236
192300
|
|
|
192237
192301
|
// packages/tooling/src/cli/seed/seed.ts
|
|
192238
192302
|
init_cli_output();
|
|
192303
|
+
init_coreSemantics();
|
|
192304
|
+
init_pathResolver();
|
|
192239
192305
|
async function main(options = {}, appArg) {
|
|
192240
192306
|
intro("Seed Database");
|
|
192241
192307
|
if (appArg && !options.app) options.app = appArg;
|
|
@@ -192274,7 +192340,18 @@ async function main(options = {}, appArg) {
|
|
|
192274
192340
|
log2.info(`Entities: ${entities.map((e2) => e2.name).join(", ")}`);
|
|
192275
192341
|
log2.info(`Rows per entity: ${count}`);
|
|
192276
192342
|
s2.start("Generating seed data...");
|
|
192277
|
-
|
|
192343
|
+
let seedData;
|
|
192344
|
+
try {
|
|
192345
|
+
const core = await loadCoreSemantics(
|
|
192346
|
+
joinPath(ctx.projectRoot, "entities", "index.ts")
|
|
192347
|
+
);
|
|
192348
|
+
seedData = generateSeedData(entities, core, { count, seed: seedValue });
|
|
192349
|
+
} catch (error2) {
|
|
192350
|
+
s2.stop("Generation failed");
|
|
192351
|
+
log2.error(error2 instanceof Error ? error2.message : String(error2));
|
|
192352
|
+
outro("Seed aborted.");
|
|
192353
|
+
return;
|
|
192354
|
+
}
|
|
192278
192355
|
s2.stop(`Generated data for ${seedData.size} entities`);
|
|
192279
192356
|
if (options.dryRun) {
|
|
192280
192357
|
note(
|