@cmssy/cli 19.5.0 → 19.7.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 (2) hide show
  1. package/dist/index.js +49 -21
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2243,7 +2243,12 @@ function propertyKey(key) {
2243
2243
  return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
2244
2244
  }
2245
2245
  function stringUnion(options) {
2246
- return options.map((option) => JSON.stringify(option)).join(" | ");
2246
+ return options.map((option) => JSON.stringify(option.value)).join(" | ");
2247
+ }
2248
+ function textIn(text, language) {
2249
+ if (!text) return null;
2250
+ if (language && text[language]?.trim()) return text[language];
2251
+ return Object.values(text).find((entry) => entry.trim()) ?? null;
2247
2252
  }
2248
2253
  function scalarType(field) {
2249
2254
  if (TEXTUAL.has(field.type)) {
@@ -2273,13 +2278,13 @@ function scalarType(field) {
2273
2278
  return "unknown";
2274
2279
  }
2275
2280
  }
2276
- function fieldType(field, depth) {
2281
+ function fieldType(field, depth, language) {
2277
2282
  if (field.type === "object") {
2278
- return field.fields?.length ? objectType(field.fields, depth) : "Record<string, unknown>";
2283
+ return field.fields?.length ? objectType(field.fields, depth, language) : "Record<string, unknown>";
2279
2284
  }
2280
2285
  if (field.type === "repeater" || field.type === "list") {
2281
2286
  if (field.itemFields?.length) {
2282
- return `Array<${objectType(field.itemFields, depth)}>`;
2287
+ return `Array<${objectType(field.itemFields, depth, language)}>`;
2283
2288
  }
2284
2289
  if (field.itemType) {
2285
2290
  const item = scalarType({ key: field.key, type: field.itemType });
@@ -2289,10 +2294,12 @@ function fieldType(field, depth) {
2289
2294
  }
2290
2295
  return scalarType(field);
2291
2296
  }
2292
- function docComment(field, pad) {
2297
+ function docComment(field, pad, language) {
2293
2298
  const parts = [];
2294
- if (field.label && field.label !== field.key) parts.push(field.label);
2295
- if (field.description) parts.push(field.description);
2299
+ const label = textIn(field.label, language);
2300
+ const description = textIn(field.description, language);
2301
+ if (label && label !== field.key) parts.push(label);
2302
+ if (description) parts.push(description);
2296
2303
  if (field.type === "relation" && field.relationTo) {
2297
2304
  parts.push(
2298
2305
  `Record id(s) from \`${field.relationTo.replace(/^model:/, "")}\`.`
@@ -2301,21 +2308,21 @@ function docComment(field, pad) {
2301
2308
  if (!parts.length) return [];
2302
2309
  return [`${pad}/** ${parts.join(" - ")} */`];
2303
2310
  }
2304
- function members(fields, depth) {
2311
+ function members(fields, depth, language) {
2305
2312
  const pad = INDENT.repeat(depth + 1);
2306
2313
  const lines = [];
2307
2314
  for (const field of fields) {
2308
2315
  if (field.hidden) continue;
2309
- lines.push(...docComment(field, pad));
2316
+ lines.push(...docComment(field, pad, language));
2310
2317
  const optional = field.required ? "" : "?";
2311
2318
  lines.push(
2312
- `${pad}${propertyKey(field.key)}${optional}: ${fieldType(field, depth + 1)};`
2319
+ `${pad}${propertyKey(field.key)}${optional}: ${fieldType(field, depth + 1, language)};`
2313
2320
  );
2314
2321
  }
2315
2322
  return lines;
2316
2323
  }
2317
- function objectType(fields, depth) {
2318
- const body = members(fields, depth);
2324
+ function objectType(fields, depth, language) {
2325
+ const body = members(fields, depth, language);
2319
2326
  if (!body.length) return "Record<string, unknown>";
2320
2327
  return ["{", ...body, `${INDENT.repeat(depth)}}`].join("\n");
2321
2328
  }
@@ -2330,7 +2337,9 @@ export type { CmssyLocalized, CmssyMedia, CmssyFile, CmssyRecordOf };`;
2330
2337
  function preambleImports() {
2331
2338
  const clause = /import type \{([^}]*)\} from "@cmssy\/core";/.exec(PREAMBLE);
2332
2339
  if (!clause?.[1]) return [];
2333
- return clause[1].split(",").map((entry) => entry.trim().split(/\s+as\s+/)[0]?.trim() ?? "").filter((name) => name.length > 0);
2340
+ return clause[1].split(",").map(
2341
+ (entry) => entry.trim().split(/\s+as\s+/)[0]?.trim() ?? ""
2342
+ ).filter((name) => name.length > 0);
2334
2343
  }
2335
2344
  function generateModelTypes(models, options) {
2336
2345
  const command = options.command ?? "npx @cmssy/cli types";
@@ -2361,7 +2370,7 @@ function generateModelTypes(models, options) {
2361
2370
  blocks.push(
2362
2371
  "",
2363
2372
  doc.join("\n"),
2364
- `export interface ${name}Data ${objectType(model.fields, 0)}`,
2373
+ `export interface ${name}Data ${objectType(model.fields, 0, options.language)}`,
2365
2374
  "",
2366
2375
  `export type ${name}Record = CmssyRecordOf<${name}Data>;`
2367
2376
  );
@@ -2425,12 +2434,13 @@ ${documents}
2425
2434
  // src/types-command.ts
2426
2435
  var DEFAULT_OUT = "cmssy/models.ts";
2427
2436
  var SITE_CONFIG_QUERY = `query CliSiteConfig($workspaceSlug: String!) {
2428
- public { siteConfig(workspaceSlug: $workspaceSlug) { workspaceId } }
2437
+ public { siteConfig(workspaceSlug: $workspaceSlug) { workspaceId defaultLanguage } }
2429
2438
  }`;
2430
- var DEFINITIONS_QUERY = `query CliModelDefinitions($workspaceId: String!) {
2439
+ var DEFINITIONS_PAGE = 4;
2440
+ var DEFINITIONS_QUERY = `query CliModelDefinitions($workspaceId: String!, $limit: Int!, $offset: Int!) {
2431
2441
  public {
2432
2442
  model {
2433
- definitions(workspaceId: $workspaceId) {
2443
+ definitions(workspaceId: $workspaceId, limit: $limit, offset: $offset) {
2434
2444
  slug
2435
2445
  name
2436
2446
  description
@@ -2444,7 +2454,10 @@ var DEFINITIONS_QUERY = `query CliModelDefinitions($workspaceId: String!) {
2444
2454
  localized
2445
2455
  multiple
2446
2456
  hidden
2447
- options
2457
+ options {
2458
+ value
2459
+ label
2460
+ }
2448
2461
  relationTo
2449
2462
  relationType
2450
2463
  fields
@@ -2685,6 +2698,19 @@ function syncOperations(options, deps) {
2685
2698
  deps.log(` ${names.join(", ")}`);
2686
2699
  return 0;
2687
2700
  }
2701
+ async function readDefinitions(deps, endpoint, workspaceId) {
2702
+ const models = [];
2703
+ for (let offset = 0; ; offset += DEFINITIONS_PAGE) {
2704
+ const result = await request(deps, endpoint, DEFINITIONS_QUERY, {
2705
+ workspaceId,
2706
+ limit: DEFINITIONS_PAGE,
2707
+ offset
2708
+ });
2709
+ const page = result.public.model.definitions;
2710
+ models.push(...page);
2711
+ if (page.length < DEFINITIONS_PAGE) return models;
2712
+ }
2713
+ }
2688
2714
  async function runTypes(options, deps) {
2689
2715
  let operationsStatus = 0;
2690
2716
  try {
@@ -2705,8 +2731,7 @@ async function runTypes(options, deps) {
2705
2731
  "check the slugs under Settings \u2192 Headless"
2706
2732
  );
2707
2733
  }
2708
- const result = await request(deps, endpoint, DEFINITIONS_QUERY, { workspaceId });
2709
- const models = result.public.model.definitions;
2734
+ const models = await readDefinitions(deps, endpoint, workspaceId);
2710
2735
  if (models.length === 0) {
2711
2736
  deps.log(
2712
2737
  `cmssy: the "${workspace}" workspace has no models yet - nothing to generate`
@@ -2717,7 +2742,10 @@ async function runTypes(options, deps) {
2717
2742
  const outPath = resolvePath(deps.cwd, requested);
2718
2743
  const inside = relative(deps.cwd, outPath);
2719
2744
  const shown = inside && !inside.startsWith("..") ? inside : outPath;
2720
- const source = generateModelTypes(models, { workspace });
2745
+ const source = generateModelTypes(models, {
2746
+ workspace,
2747
+ language: site.public.siteConfig?.defaultLanguage
2748
+ });
2721
2749
  const gap = coreShapeGap(deps.cwd);
2722
2750
  if (gap) {
2723
2751
  deps.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/cli",
3
- "version": "19.5.0",
3
+ "version": "19.7.0",
4
4
  "description": "The cmssy CLI: `cmssy init` wires cmssy into an existing Next.js, Astro or React Router app; `cmssy link` connects it to a workspace and verifies the editor wiring.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "esbuild": "^0.27.7",
31
- "@cmssy/core": "19.5.0"
31
+ "@cmssy/core": "19.7.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.0.0",