@carthooks/arcubase-cli 0.1.24 → 0.1.25
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/bundle/arcubase-admin.mjs +57 -54
- package/bundle/arcubase.mjs +57 -54
- package/dist/runtime/dev_sdk_gen.d.ts +2 -7
- package/dist/runtime/dev_sdk_gen.d.ts.map +1 -1
- package/dist/runtime/dev_sdk_gen.js +8 -314
- package/dist/runtime/execute.d.ts.map +1 -1
- package/dist/runtime/execute.js +25 -43
- package/package.json +2 -1
- package/sdk-dist/docs/runtime-reference/dev-sdk-gen.md +14 -3
- package/src/runtime/dev_sdk_gen.ts +14 -354
- package/src/runtime/execute.ts +26 -50
- package/src/tests/dev_sdk_gen.test.ts +12 -28
|
@@ -18689,7 +18689,15 @@ function renderCommandHelpExamples(scope, command) {
|
|
|
18689
18689
|
].join("\n").trimEnd();
|
|
18690
18690
|
}
|
|
18691
18691
|
|
|
18692
|
-
//
|
|
18692
|
+
// node_modules/@arcubase/code-gen/dist/index.js
|
|
18693
|
+
var ArcubaseCodeGenError = class extends Error {
|
|
18694
|
+
code;
|
|
18695
|
+
constructor(code, message) {
|
|
18696
|
+
super(message);
|
|
18697
|
+
this.code = code;
|
|
18698
|
+
this.name = "ArcubaseCodeGenError";
|
|
18699
|
+
}
|
|
18700
|
+
};
|
|
18693
18701
|
function isRecord3(value) {
|
|
18694
18702
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
18695
18703
|
}
|
|
@@ -18698,7 +18706,8 @@ function unwrapData(payload) {
|
|
|
18698
18706
|
}
|
|
18699
18707
|
function toPascalCase(value) {
|
|
18700
18708
|
const words = value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
18701
|
-
if (words.length === 0)
|
|
18709
|
+
if (words.length === 0)
|
|
18710
|
+
return "Entity";
|
|
18702
18711
|
return words.map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join("");
|
|
18703
18712
|
}
|
|
18704
18713
|
function toCamelCase(value) {
|
|
@@ -18738,11 +18747,11 @@ function normalizeFieldType(type) {
|
|
|
18738
18747
|
function normalizeEntities(payload) {
|
|
18739
18748
|
const root = unwrapData(payload);
|
|
18740
18749
|
if (!isRecord3(root)) {
|
|
18741
|
-
throw new
|
|
18750
|
+
throw new ArcubaseCodeGenError("SDK_GEN_INVALID_SCHEMA", "sdk-gen expected an app detail object");
|
|
18742
18751
|
}
|
|
18743
18752
|
const appId = typeof root.id === "number" ? root.id : typeof root.app_id === "number" ? root.app_id : void 0;
|
|
18744
18753
|
if (!appId) {
|
|
18745
|
-
throw new
|
|
18754
|
+
throw new ArcubaseCodeGenError("SDK_GEN_APP_ID_REQUIRED", "sdk-gen expected app id in app detail response");
|
|
18746
18755
|
}
|
|
18747
18756
|
const sourceEntities = Array.isArray(root.entities) ? root.entities : Array.isArray(root.tables) ? root.tables : Array.isArray(root.entitys) ? root.entitys : [];
|
|
18748
18757
|
const entities = sourceEntities.filter((item) => isRecord3(item)).filter((item) => typeof item.id === "number" && typeof item.name === "string").map((item) => {
|
|
@@ -18765,7 +18774,7 @@ function normalizeEntities(payload) {
|
|
|
18765
18774
|
return entity;
|
|
18766
18775
|
});
|
|
18767
18776
|
if (entities.length === 0) {
|
|
18768
|
-
throw new
|
|
18777
|
+
throw new ArcubaseCodeGenError("SDK_GEN_NO_ENTITIES", "sdk-gen could not find entities in app detail response");
|
|
18769
18778
|
}
|
|
18770
18779
|
validateEntities(entities);
|
|
18771
18780
|
return entities;
|
|
@@ -18774,19 +18783,19 @@ function validateEntities(entities) {
|
|
|
18774
18783
|
const entityKeys = /* @__PURE__ */ new Set();
|
|
18775
18784
|
for (const entity of entities) {
|
|
18776
18785
|
if (entityKeys.has(entity.sdkName)) {
|
|
18777
|
-
throw new
|
|
18786
|
+
throw new ArcubaseCodeGenError("SDK_GEN_DUPLICATE_ENTITY_KEY", `duplicate generated entity key: ${entity.sdkName}`);
|
|
18778
18787
|
}
|
|
18779
18788
|
entityKeys.add(entity.sdkName);
|
|
18780
18789
|
const fieldKeys = /* @__PURE__ */ new Set();
|
|
18781
18790
|
for (const field of entity.fields) {
|
|
18782
18791
|
if (!field.key) {
|
|
18783
|
-
throw new
|
|
18792
|
+
throw new ArcubaseCodeGenError("SDK_GEN_FIELD_KEY_REQUIRED", `field.key is required for ${entity.name}.${field.label} (${field.id})`);
|
|
18784
18793
|
}
|
|
18785
18794
|
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(field.key)) {
|
|
18786
|
-
throw new
|
|
18795
|
+
throw new ArcubaseCodeGenError("SDK_GEN_INVALID_FIELD_KEY", `field.key must be a TypeScript identifier: ${entity.name}.${field.key}`);
|
|
18787
18796
|
}
|
|
18788
18797
|
if (fieldKeys.has(field.key)) {
|
|
18789
|
-
throw new
|
|
18798
|
+
throw new ArcubaseCodeGenError("SDK_GEN_DUPLICATE_FIELD_KEY", `duplicate field.key in ${entity.name}: ${field.key}`);
|
|
18790
18799
|
}
|
|
18791
18800
|
fieldKeys.add(field.key);
|
|
18792
18801
|
}
|
|
@@ -18991,6 +19000,18 @@ function generateArcubaseProjectSDK(payload) {
|
|
|
18991
19000
|
};
|
|
18992
19001
|
}
|
|
18993
19002
|
|
|
19003
|
+
// src/runtime/dev_sdk_gen.ts
|
|
19004
|
+
function generateArcubaseProjectSDK2(payload) {
|
|
19005
|
+
try {
|
|
19006
|
+
return generateArcubaseProjectSDK(payload);
|
|
19007
|
+
} catch (error51) {
|
|
19008
|
+
if (error51 instanceof ArcubaseCodeGenError) {
|
|
19009
|
+
throw new CLIError(error51.code, error51.message, 2);
|
|
19010
|
+
}
|
|
19011
|
+
throw error51;
|
|
19012
|
+
}
|
|
19013
|
+
}
|
|
19014
|
+
|
|
18994
19015
|
// src/runtime/execute.ts
|
|
18995
19016
|
function renderRootHelp(scope) {
|
|
18996
19017
|
const binary = scope === "admin" ? "arcubase-admin" : "arcubase";
|
|
@@ -19222,7 +19243,7 @@ function renderDevSDKGenHelp() {
|
|
|
19222
19243
|
" - arcubase-admin dev sdk-gen --app-id <app_id> --out src/arcubase",
|
|
19223
19244
|
"",
|
|
19224
19245
|
"requirements:",
|
|
19225
|
-
" -
|
|
19246
|
+
" - every generated field must have a configured field.key; sdk-gen fails fast when keys are missing",
|
|
19226
19247
|
" - existing field.key values must be stable unique TypeScript identifiers",
|
|
19227
19248
|
" - entity property names use entity.key when available, otherwise a stable entity<id> fallback",
|
|
19228
19249
|
" - generated code accepts createArcubaseSdk({ baseURL, accessToken, refreshToken })"
|
|
@@ -20735,45 +20756,37 @@ function walkSDKGenFields(fields, visit) {
|
|
|
20735
20756
|
walkSDKGenFields(field.children, visit);
|
|
20736
20757
|
}
|
|
20737
20758
|
}
|
|
20738
|
-
function
|
|
20739
|
-
const
|
|
20740
|
-
walkSDKGenFields(entity.fields, (field) => {
|
|
20741
|
-
if (typeof field.key === "string" && field.key.trim() !== "") {
|
|
20742
|
-
keys.add(field.key.trim());
|
|
20743
|
-
}
|
|
20744
|
-
});
|
|
20745
|
-
return keys;
|
|
20746
|
-
}
|
|
20747
|
-
function nextSDKGenFallbackFieldKey(fieldId, usedKeys) {
|
|
20748
|
-
const base = `field${fieldId}`;
|
|
20749
|
-
if (!usedKeys.has(base)) {
|
|
20750
|
-
usedKeys.add(base);
|
|
20751
|
-
return base;
|
|
20752
|
-
}
|
|
20753
|
-
let index = 2;
|
|
20754
|
-
while (usedKeys.has(`${base}_${index}`)) {
|
|
20755
|
-
index++;
|
|
20756
|
-
}
|
|
20757
|
-
const key = `${base}_${index}`;
|
|
20758
|
-
usedKeys.add(key);
|
|
20759
|
-
return key;
|
|
20760
|
-
}
|
|
20761
|
-
function initializeMissingSDKGenFieldKeys(entity) {
|
|
20762
|
-
const usedKeys = collectExistingSDKGenFieldKeys(entity);
|
|
20763
|
-
const updates = [];
|
|
20759
|
+
function assertSDKGenFieldKeysPresent(entity) {
|
|
20760
|
+
const missing = [];
|
|
20764
20761
|
walkSDKGenFields(entity.fields, (field) => {
|
|
20765
20762
|
if (typeof field.id !== "number") {
|
|
20766
20763
|
return;
|
|
20767
20764
|
}
|
|
20768
20765
|
if (typeof field.key === "string" && field.key.trim() !== "") {
|
|
20769
|
-
field.key = field.key.trim();
|
|
20770
20766
|
return;
|
|
20771
20767
|
}
|
|
20772
|
-
|
|
20773
|
-
|
|
20774
|
-
|
|
20768
|
+
missing.push({
|
|
20769
|
+
id: field.id,
|
|
20770
|
+
label: typeof field.label === "string" && field.label.trim() ? field.label.trim() : `field ${field.id}`
|
|
20771
|
+
});
|
|
20772
|
+
});
|
|
20773
|
+
if (missing.length === 0) {
|
|
20774
|
+
return;
|
|
20775
|
+
}
|
|
20776
|
+
const entityName = typeof entity.name === "string" && entity.name.trim() ? entity.name.trim() : `entity ${String(entity.id ?? "")}`.trim();
|
|
20777
|
+
const preview = missing.slice(0, 8).map((field) => `${entityName}.${field.label} (${field.id})`);
|
|
20778
|
+
const suffix = missing.length > preview.length ? `, and ${missing.length - preview.length} more` : "";
|
|
20779
|
+
throw new CLIError("SDK_GEN_FIELD_KEY_REQUIRED", `missing field.key values: ${preview.join(", ")}${suffix}`, 2, {
|
|
20780
|
+
operation: "dev sdk-gen",
|
|
20781
|
+
issues: missing.map((field) => ({
|
|
20782
|
+
path: `entity.${String(entity.id ?? "unknown")}.field.${field.id}.key`,
|
|
20783
|
+
message: `field.key is required for ${entityName}.${field.label}`
|
|
20784
|
+
})),
|
|
20785
|
+
suggestions: [
|
|
20786
|
+
"set stable field.key values in Arcubase admin before running sdk-gen",
|
|
20787
|
+
"rerun arcubase-admin dev sdk-gen after the schema keys are complete"
|
|
20788
|
+
]
|
|
20775
20789
|
});
|
|
20776
|
-
return updates;
|
|
20777
20790
|
}
|
|
20778
20791
|
async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
20779
20792
|
validateDevSDKGenFlags(flags);
|
|
@@ -20802,7 +20815,6 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20802
20815
|
throw new CLIError("SDK_GEN_NO_ENTITIES", "sdk-gen could not find entities in app detail response", 2);
|
|
20803
20816
|
}
|
|
20804
20817
|
const entities = [];
|
|
20805
|
-
const initializedFieldKeys = [];
|
|
20806
20818
|
for (const entityRef of entityRefs) {
|
|
20807
20819
|
const entityEndpoint = `/api/apps/${encodeURIComponent(appId)}/entity/${encodeURIComponent(entityRef.id)}`;
|
|
20808
20820
|
const entityDetail = await requestJSON(runtimeEnv, "GET", entityEndpoint, void 0, fetchImpl);
|
|
@@ -20810,18 +20822,10 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20810
20822
|
if (!isRecord4(entityPayload)) {
|
|
20811
20823
|
throw new CLIError("SDK_GEN_INVALID_SCHEMA", "sdk-gen expected entity detail response data", 2);
|
|
20812
20824
|
}
|
|
20813
|
-
|
|
20814
|
-
if (customKeyUpdates.length > 0) {
|
|
20815
|
-
const customKeysEndpoint = `/api/apps/${encodeURIComponent(appId)}/entity/${encodeURIComponent(entityRef.id)}/custom-keys`;
|
|
20816
|
-
await requestJSON(runtimeEnv, "PUT", customKeysEndpoint, customKeyUpdates, fetchImpl);
|
|
20817
|
-
initializedFieldKeys.push({
|
|
20818
|
-
entityId: typeof entityPayload.id === "number" ? entityPayload.id : Number(entityRef.id),
|
|
20819
|
-
fields: customKeyUpdates.map((item) => item.key)
|
|
20820
|
-
});
|
|
20821
|
-
}
|
|
20825
|
+
assertSDKGenFieldKeysPresent(entityPayload);
|
|
20822
20826
|
entities.push(entityPayload);
|
|
20823
20827
|
}
|
|
20824
|
-
const generated =
|
|
20828
|
+
const generated = generateArcubaseProjectSDK2({
|
|
20825
20829
|
id: resolveSDKGenAppId(appId, appPayload),
|
|
20826
20830
|
name: typeof appPayload.name === "string" ? appPayload.name : void 0,
|
|
20827
20831
|
entities
|
|
@@ -20841,8 +20845,7 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20841
20845
|
status: appDetail.status,
|
|
20842
20846
|
data: {
|
|
20843
20847
|
out: absoluteOutDir,
|
|
20844
|
-
files: generated.files.map((file2) => file2.path)
|
|
20845
|
-
initializedFieldKeys
|
|
20848
|
+
files: generated.files.map((file2) => file2.path)
|
|
20846
20849
|
}
|
|
20847
20850
|
};
|
|
20848
20851
|
}
|
package/bundle/arcubase.mjs
CHANGED
|
@@ -18689,7 +18689,15 @@ function renderCommandHelpExamples(scope, command) {
|
|
|
18689
18689
|
].join("\n").trimEnd();
|
|
18690
18690
|
}
|
|
18691
18691
|
|
|
18692
|
-
//
|
|
18692
|
+
// node_modules/@arcubase/code-gen/dist/index.js
|
|
18693
|
+
var ArcubaseCodeGenError = class extends Error {
|
|
18694
|
+
code;
|
|
18695
|
+
constructor(code, message) {
|
|
18696
|
+
super(message);
|
|
18697
|
+
this.code = code;
|
|
18698
|
+
this.name = "ArcubaseCodeGenError";
|
|
18699
|
+
}
|
|
18700
|
+
};
|
|
18693
18701
|
function isRecord3(value) {
|
|
18694
18702
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
18695
18703
|
}
|
|
@@ -18698,7 +18706,8 @@ function unwrapData(payload) {
|
|
|
18698
18706
|
}
|
|
18699
18707
|
function toPascalCase(value) {
|
|
18700
18708
|
const words = value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean);
|
|
18701
|
-
if (words.length === 0)
|
|
18709
|
+
if (words.length === 0)
|
|
18710
|
+
return "Entity";
|
|
18702
18711
|
return words.map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join("");
|
|
18703
18712
|
}
|
|
18704
18713
|
function toCamelCase(value) {
|
|
@@ -18738,11 +18747,11 @@ function normalizeFieldType(type) {
|
|
|
18738
18747
|
function normalizeEntities(payload) {
|
|
18739
18748
|
const root = unwrapData(payload);
|
|
18740
18749
|
if (!isRecord3(root)) {
|
|
18741
|
-
throw new
|
|
18750
|
+
throw new ArcubaseCodeGenError("SDK_GEN_INVALID_SCHEMA", "sdk-gen expected an app detail object");
|
|
18742
18751
|
}
|
|
18743
18752
|
const appId = typeof root.id === "number" ? root.id : typeof root.app_id === "number" ? root.app_id : void 0;
|
|
18744
18753
|
if (!appId) {
|
|
18745
|
-
throw new
|
|
18754
|
+
throw new ArcubaseCodeGenError("SDK_GEN_APP_ID_REQUIRED", "sdk-gen expected app id in app detail response");
|
|
18746
18755
|
}
|
|
18747
18756
|
const sourceEntities = Array.isArray(root.entities) ? root.entities : Array.isArray(root.tables) ? root.tables : Array.isArray(root.entitys) ? root.entitys : [];
|
|
18748
18757
|
const entities = sourceEntities.filter((item) => isRecord3(item)).filter((item) => typeof item.id === "number" && typeof item.name === "string").map((item) => {
|
|
@@ -18765,7 +18774,7 @@ function normalizeEntities(payload) {
|
|
|
18765
18774
|
return entity;
|
|
18766
18775
|
});
|
|
18767
18776
|
if (entities.length === 0) {
|
|
18768
|
-
throw new
|
|
18777
|
+
throw new ArcubaseCodeGenError("SDK_GEN_NO_ENTITIES", "sdk-gen could not find entities in app detail response");
|
|
18769
18778
|
}
|
|
18770
18779
|
validateEntities(entities);
|
|
18771
18780
|
return entities;
|
|
@@ -18774,19 +18783,19 @@ function validateEntities(entities) {
|
|
|
18774
18783
|
const entityKeys = /* @__PURE__ */ new Set();
|
|
18775
18784
|
for (const entity of entities) {
|
|
18776
18785
|
if (entityKeys.has(entity.sdkName)) {
|
|
18777
|
-
throw new
|
|
18786
|
+
throw new ArcubaseCodeGenError("SDK_GEN_DUPLICATE_ENTITY_KEY", `duplicate generated entity key: ${entity.sdkName}`);
|
|
18778
18787
|
}
|
|
18779
18788
|
entityKeys.add(entity.sdkName);
|
|
18780
18789
|
const fieldKeys = /* @__PURE__ */ new Set();
|
|
18781
18790
|
for (const field of entity.fields) {
|
|
18782
18791
|
if (!field.key) {
|
|
18783
|
-
throw new
|
|
18792
|
+
throw new ArcubaseCodeGenError("SDK_GEN_FIELD_KEY_REQUIRED", `field.key is required for ${entity.name}.${field.label} (${field.id})`);
|
|
18784
18793
|
}
|
|
18785
18794
|
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(field.key)) {
|
|
18786
|
-
throw new
|
|
18795
|
+
throw new ArcubaseCodeGenError("SDK_GEN_INVALID_FIELD_KEY", `field.key must be a TypeScript identifier: ${entity.name}.${field.key}`);
|
|
18787
18796
|
}
|
|
18788
18797
|
if (fieldKeys.has(field.key)) {
|
|
18789
|
-
throw new
|
|
18798
|
+
throw new ArcubaseCodeGenError("SDK_GEN_DUPLICATE_FIELD_KEY", `duplicate field.key in ${entity.name}: ${field.key}`);
|
|
18790
18799
|
}
|
|
18791
18800
|
fieldKeys.add(field.key);
|
|
18792
18801
|
}
|
|
@@ -18991,6 +19000,18 @@ function generateArcubaseProjectSDK(payload) {
|
|
|
18991
19000
|
};
|
|
18992
19001
|
}
|
|
18993
19002
|
|
|
19003
|
+
// src/runtime/dev_sdk_gen.ts
|
|
19004
|
+
function generateArcubaseProjectSDK2(payload) {
|
|
19005
|
+
try {
|
|
19006
|
+
return generateArcubaseProjectSDK(payload);
|
|
19007
|
+
} catch (error51) {
|
|
19008
|
+
if (error51 instanceof ArcubaseCodeGenError) {
|
|
19009
|
+
throw new CLIError(error51.code, error51.message, 2);
|
|
19010
|
+
}
|
|
19011
|
+
throw error51;
|
|
19012
|
+
}
|
|
19013
|
+
}
|
|
19014
|
+
|
|
18994
19015
|
// src/runtime/execute.ts
|
|
18995
19016
|
function renderRootHelp(scope) {
|
|
18996
19017
|
const binary = scope === "admin" ? "arcubase-admin" : "arcubase";
|
|
@@ -19222,7 +19243,7 @@ function renderDevSDKGenHelp() {
|
|
|
19222
19243
|
" - arcubase-admin dev sdk-gen --app-id <app_id> --out src/arcubase",
|
|
19223
19244
|
"",
|
|
19224
19245
|
"requirements:",
|
|
19225
|
-
" -
|
|
19246
|
+
" - every generated field must have a configured field.key; sdk-gen fails fast when keys are missing",
|
|
19226
19247
|
" - existing field.key values must be stable unique TypeScript identifiers",
|
|
19227
19248
|
" - entity property names use entity.key when available, otherwise a stable entity<id> fallback",
|
|
19228
19249
|
" - generated code accepts createArcubaseSdk({ baseURL, accessToken, refreshToken })"
|
|
@@ -20735,45 +20756,37 @@ function walkSDKGenFields(fields, visit) {
|
|
|
20735
20756
|
walkSDKGenFields(field.children, visit);
|
|
20736
20757
|
}
|
|
20737
20758
|
}
|
|
20738
|
-
function
|
|
20739
|
-
const
|
|
20740
|
-
walkSDKGenFields(entity.fields, (field) => {
|
|
20741
|
-
if (typeof field.key === "string" && field.key.trim() !== "") {
|
|
20742
|
-
keys.add(field.key.trim());
|
|
20743
|
-
}
|
|
20744
|
-
});
|
|
20745
|
-
return keys;
|
|
20746
|
-
}
|
|
20747
|
-
function nextSDKGenFallbackFieldKey(fieldId, usedKeys) {
|
|
20748
|
-
const base = `field${fieldId}`;
|
|
20749
|
-
if (!usedKeys.has(base)) {
|
|
20750
|
-
usedKeys.add(base);
|
|
20751
|
-
return base;
|
|
20752
|
-
}
|
|
20753
|
-
let index = 2;
|
|
20754
|
-
while (usedKeys.has(`${base}_${index}`)) {
|
|
20755
|
-
index++;
|
|
20756
|
-
}
|
|
20757
|
-
const key = `${base}_${index}`;
|
|
20758
|
-
usedKeys.add(key);
|
|
20759
|
-
return key;
|
|
20760
|
-
}
|
|
20761
|
-
function initializeMissingSDKGenFieldKeys(entity) {
|
|
20762
|
-
const usedKeys = collectExistingSDKGenFieldKeys(entity);
|
|
20763
|
-
const updates = [];
|
|
20759
|
+
function assertSDKGenFieldKeysPresent(entity) {
|
|
20760
|
+
const missing = [];
|
|
20764
20761
|
walkSDKGenFields(entity.fields, (field) => {
|
|
20765
20762
|
if (typeof field.id !== "number") {
|
|
20766
20763
|
return;
|
|
20767
20764
|
}
|
|
20768
20765
|
if (typeof field.key === "string" && field.key.trim() !== "") {
|
|
20769
|
-
field.key = field.key.trim();
|
|
20770
20766
|
return;
|
|
20771
20767
|
}
|
|
20772
|
-
|
|
20773
|
-
|
|
20774
|
-
|
|
20768
|
+
missing.push({
|
|
20769
|
+
id: field.id,
|
|
20770
|
+
label: typeof field.label === "string" && field.label.trim() ? field.label.trim() : `field ${field.id}`
|
|
20771
|
+
});
|
|
20772
|
+
});
|
|
20773
|
+
if (missing.length === 0) {
|
|
20774
|
+
return;
|
|
20775
|
+
}
|
|
20776
|
+
const entityName = typeof entity.name === "string" && entity.name.trim() ? entity.name.trim() : `entity ${String(entity.id ?? "")}`.trim();
|
|
20777
|
+
const preview = missing.slice(0, 8).map((field) => `${entityName}.${field.label} (${field.id})`);
|
|
20778
|
+
const suffix = missing.length > preview.length ? `, and ${missing.length - preview.length} more` : "";
|
|
20779
|
+
throw new CLIError("SDK_GEN_FIELD_KEY_REQUIRED", `missing field.key values: ${preview.join(", ")}${suffix}`, 2, {
|
|
20780
|
+
operation: "dev sdk-gen",
|
|
20781
|
+
issues: missing.map((field) => ({
|
|
20782
|
+
path: `entity.${String(entity.id ?? "unknown")}.field.${field.id}.key`,
|
|
20783
|
+
message: `field.key is required for ${entityName}.${field.label}`
|
|
20784
|
+
})),
|
|
20785
|
+
suggestions: [
|
|
20786
|
+
"set stable field.key values in Arcubase admin before running sdk-gen",
|
|
20787
|
+
"rerun arcubase-admin dev sdk-gen after the schema keys are complete"
|
|
20788
|
+
]
|
|
20775
20789
|
});
|
|
20776
|
-
return updates;
|
|
20777
20790
|
}
|
|
20778
20791
|
async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
20779
20792
|
validateDevSDKGenFlags(flags);
|
|
@@ -20802,7 +20815,6 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20802
20815
|
throw new CLIError("SDK_GEN_NO_ENTITIES", "sdk-gen could not find entities in app detail response", 2);
|
|
20803
20816
|
}
|
|
20804
20817
|
const entities = [];
|
|
20805
|
-
const initializedFieldKeys = [];
|
|
20806
20818
|
for (const entityRef of entityRefs) {
|
|
20807
20819
|
const entityEndpoint = `/api/apps/${encodeURIComponent(appId)}/entity/${encodeURIComponent(entityRef.id)}`;
|
|
20808
20820
|
const entityDetail = await requestJSON(runtimeEnv, "GET", entityEndpoint, void 0, fetchImpl);
|
|
@@ -20810,18 +20822,10 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20810
20822
|
if (!isRecord4(entityPayload)) {
|
|
20811
20823
|
throw new CLIError("SDK_GEN_INVALID_SCHEMA", "sdk-gen expected entity detail response data", 2);
|
|
20812
20824
|
}
|
|
20813
|
-
|
|
20814
|
-
if (customKeyUpdates.length > 0) {
|
|
20815
|
-
const customKeysEndpoint = `/api/apps/${encodeURIComponent(appId)}/entity/${encodeURIComponent(entityRef.id)}/custom-keys`;
|
|
20816
|
-
await requestJSON(runtimeEnv, "PUT", customKeysEndpoint, customKeyUpdates, fetchImpl);
|
|
20817
|
-
initializedFieldKeys.push({
|
|
20818
|
-
entityId: typeof entityPayload.id === "number" ? entityPayload.id : Number(entityRef.id),
|
|
20819
|
-
fields: customKeyUpdates.map((item) => item.key)
|
|
20820
|
-
});
|
|
20821
|
-
}
|
|
20825
|
+
assertSDKGenFieldKeysPresent(entityPayload);
|
|
20822
20826
|
entities.push(entityPayload);
|
|
20823
20827
|
}
|
|
20824
|
-
const generated =
|
|
20828
|
+
const generated = generateArcubaseProjectSDK2({
|
|
20825
20829
|
id: resolveSDKGenAppId(appId, appPayload),
|
|
20826
20830
|
name: typeof appPayload.name === "string" ? appPayload.name : void 0,
|
|
20827
20831
|
entities
|
|
@@ -20841,8 +20845,7 @@ async function executeDevSDKGen(runtimeEnv, flags, fetchImpl) {
|
|
|
20841
20845
|
status: appDetail.status,
|
|
20842
20846
|
data: {
|
|
20843
20847
|
out: absoluteOutDir,
|
|
20844
|
-
files: generated.files.map((file2) => file2.path)
|
|
20845
|
-
initializedFieldKeys
|
|
20848
|
+
files: generated.files.map((file2) => file2.path)
|
|
20846
20849
|
}
|
|
20847
20850
|
};
|
|
20848
20851
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
contents: string;
|
|
4
|
-
};
|
|
5
|
-
export type GeneratedSDK = {
|
|
6
|
-
files: GeneratedSDKFile[];
|
|
7
|
-
};
|
|
1
|
+
import { type GeneratedSDK } from '@arcubase/code-gen';
|
|
2
|
+
export type { GeneratedSDK, GeneratedSDKFile } from '@arcubase/code-gen';
|
|
8
3
|
export declare function generateArcubaseProjectSDK(payload: unknown): GeneratedSDK;
|
|
9
4
|
//# sourceMappingURL=dev_sdk_gen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev_sdk_gen.d.ts","sourceRoot":"","sources":["../../src/runtime/dev_sdk_gen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev_sdk_gen.d.ts","sourceRoot":"","sources":["../../src/runtime/dev_sdk_gen.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAA;AAI3B,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAExE,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,CASzE"}
|