zinkee 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zinkee",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "CLI for Zinkee API v2",
5
5
  "type": "module",
6
6
  "bin": {
@@ -269,6 +269,95 @@ describe("schemas commands", () => {
269
269
  });
270
270
  });
271
271
 
272
+ it("creates fields with a default value flag", async () => {
273
+ const configPath = createApiConfig();
274
+ const output = createStdoutBuffer();
275
+ const fetchMock = createFetchMock();
276
+ mockSchemaLookup(fetchMock);
277
+ fetchMock.mockResolvedValueOnce(
278
+ jsonResponse({
279
+ id: "field-budget",
280
+ type: "NumberField",
281
+ slug: "budget",
282
+ label: "Budget",
283
+ required: true,
284
+ }),
285
+ );
286
+ const program = buildProgram({ configPath, stdout: output.stdout });
287
+
288
+ await program.parseAsync([
289
+ "node",
290
+ "zinkee",
291
+ "--json",
292
+ "schemas",
293
+ "fields",
294
+ "create",
295
+ "contacts",
296
+ "--type",
297
+ "number",
298
+ "--slug",
299
+ "budget",
300
+ "--label",
301
+ "Budget",
302
+ "--required",
303
+ "true",
304
+ "--default",
305
+ "0",
306
+ ]);
307
+
308
+ expect(JSON.parse(String(fetchMock.mock.calls[1]?.[1]?.body))).toEqual({
309
+ type: "NumberField",
310
+ slug: "budget",
311
+ label: "Budget",
312
+ required: true,
313
+ config: {
314
+ defaultValue: "0",
315
+ },
316
+ });
317
+ });
318
+
319
+ it("lets the default value flag override raw config defaults", async () => {
320
+ const configPath = createApiConfig();
321
+ const output = createStdoutBuffer();
322
+ const fetchMock = createFetchMock();
323
+ mockSchemaLookup(fetchMock);
324
+ fetchMock.mockResolvedValueOnce(
325
+ jsonResponse({
326
+ id: "field-budget",
327
+ type: "NumberField",
328
+ slug: "budget",
329
+ label: "Budget",
330
+ }),
331
+ );
332
+ const program = buildProgram({ configPath, stdout: output.stdout });
333
+
334
+ await program.parseAsync([
335
+ "node",
336
+ "zinkee",
337
+ "--json",
338
+ "schemas",
339
+ "fields",
340
+ "create",
341
+ "contacts",
342
+ "--raw",
343
+ '{"type":"number","slug":"budget","label":"Budget","config":{"defaultValue":"10","formatOptions":{"format":"number"}}}',
344
+ "--default",
345
+ "0",
346
+ ]);
347
+
348
+ expect(JSON.parse(String(fetchMock.mock.calls[1]?.[1]?.body))).toEqual({
349
+ type: "NumberField",
350
+ slug: "budget",
351
+ label: "Budget",
352
+ config: {
353
+ defaultValue: "0",
354
+ formatOptions: {
355
+ format: "number",
356
+ },
357
+ },
358
+ });
359
+ });
360
+
272
361
  it("updates fields from a raw file and normalizes field UUID selectors", async () => {
273
362
  const configPath = createApiConfig();
274
363
  const output = createStdoutBuffer();
@@ -342,6 +431,52 @@ describe("schemas commands", () => {
342
431
  });
343
432
  });
344
433
 
434
+ it("updates fields with a default value flag", async () => {
435
+ const configPath = createApiConfig();
436
+ const output = createStdoutBuffer();
437
+ const fetchMock = createFetchMock();
438
+ mockSchemaLookup(fetchMock);
439
+ fetchMock.mockResolvedValueOnce(
440
+ jsonResponse({
441
+ id: "field-budget",
442
+ type: "NumberField",
443
+ slug: "budget",
444
+ label: "Budget",
445
+ required: false,
446
+ }),
447
+ );
448
+ fetchMock.mockResolvedValueOnce(
449
+ jsonResponse({
450
+ id: "field-budget",
451
+ type: "NumberField",
452
+ slug: "budget",
453
+ label: "Budget",
454
+ required: false,
455
+ }),
456
+ );
457
+ const program = buildProgram({ configPath, stdout: output.stdout });
458
+
459
+ await program.parseAsync([
460
+ "node",
461
+ "zinkee",
462
+ "--json",
463
+ "schemas",
464
+ "fields",
465
+ "update",
466
+ "contacts",
467
+ "550E8400-E29B-41D4-A716-446655440002",
468
+ "--default",
469
+ "0",
470
+ ]);
471
+
472
+ expect(JSON.parse(String(fetchMock.mock.calls[2]?.[1]?.body))).toEqual({
473
+ type: "NumberField",
474
+ config: {
475
+ defaultValue: "0",
476
+ },
477
+ });
478
+ });
479
+
345
480
  it("strips formula status from update payloads", async () => {
346
481
  const configPath = createApiConfig();
347
482
  const output = createStdoutBuffer();
@@ -714,6 +849,7 @@ describe("schemas commands", () => {
714
849
  const help = create?.helpInformation() ?? "";
715
850
 
716
851
  expect(help).toContain("--type <type>");
852
+ expect(help).toContain("--default <value>");
717
853
  expect(help).toContain("member");
718
854
  expect(help).toContain("autoincremental");
719
855
  expect(help).toContain("Raw payload shapes by type:");
@@ -63,6 +63,7 @@ interface FieldCreateCommandOptions {
63
63
  slug?: string;
64
64
  label?: string;
65
65
  required?: boolean;
66
+ default?: string;
66
67
  raw?: string;
67
68
  rawFile?: string;
68
69
  }
@@ -70,6 +71,7 @@ interface FieldCreateCommandOptions {
70
71
  interface FieldUpdateCommandOptions {
71
72
  label?: string;
72
73
  required?: boolean;
74
+ default?: string;
73
75
  raw?: string;
74
76
  rawFile?: string;
75
77
  }
@@ -301,6 +303,29 @@ function buildSchemaUpdateInput(options: SchemaUpdateCommandOptions): UpdateSche
301
303
  return input;
302
304
  }
303
305
 
306
+ function applyFieldDefaultValue(
307
+ input: CreateSchemaFieldInput | UpdateSchemaFieldInput,
308
+ defaultValue: string | undefined,
309
+ ): void {
310
+ if (defaultValue === undefined) {
311
+ return;
312
+ }
313
+
314
+ const config = input.config;
315
+
316
+ if (config !== undefined && !isJsonObject(config)) {
317
+ throw new CliError(
318
+ "invalid_cli_usage",
319
+ 'Expected field "config" to be a JSON object when using "--default".',
320
+ );
321
+ }
322
+
323
+ input.config = {
324
+ ...(config ?? {}),
325
+ defaultValue,
326
+ };
327
+ }
328
+
304
329
  function buildFieldCreateInput(
305
330
  options: FieldCreateCommandOptions,
306
331
  ): CreateSchemaFieldInput {
@@ -337,6 +362,8 @@ function buildFieldCreateInput(
337
362
  input.required = options.required;
338
363
  }
339
364
 
365
+ applyFieldDefaultValue(input, options.default);
366
+
340
367
  if ("config" in input && isJsonObject(input.config) && isEmptyObject(input.config)) {
341
368
  delete input.config;
342
369
  }
@@ -411,6 +438,8 @@ function buildFieldUpdateInput(
411
438
  input.required = options.required;
412
439
  }
413
440
 
441
+ applyFieldDefaultValue(input, options.default);
442
+
414
443
  return input;
415
444
  }
416
445
 
@@ -640,6 +669,7 @@ export function registerSchemasCommands(
640
669
  .option("--slug <slug>", "field slug")
641
670
  .option("--label <label>", "field label")
642
671
  .option("--required <bool>", "required flag", parseBooleanFlag)
672
+ .option("--default <value>", "default field value")
643
673
  .option("--raw <json>", 'raw JSON object payload (see type-specific shapes in --help)')
644
674
  .option("--raw-file <path>", "path to a raw JSON object payload")
645
675
  .action(async function action(
@@ -673,6 +703,7 @@ export function registerSchemasCommands(
673
703
  .argument("<field>", "field uuid or slug", parseUuidOrSlugSelector)
674
704
  .option("--label <label>", "field label")
675
705
  .option("--required <bool>", "required flag", parseBooleanFlag)
706
+ .option("--default <value>", "default field value")
676
707
  .option("--raw <json>", "raw JSON object payload")
677
708
  .option("--raw-file <path>", "path to a raw JSON object payload")
678
709
  .action(async function action(
package/src/index.test.ts CHANGED
@@ -108,6 +108,7 @@ describe("project bootstrap", () => {
108
108
  expect(output).toContain('"slug":"quantity"');
109
109
  expect(output).toContain('"slug":"amount-eur"');
110
110
  expect(output).toContain('"slug":"amount-usd"');
111
+ expect(output).toContain('"defaultValue":"0"');
111
112
  expect(output).toContain('"symbolEnabled":true');
112
113
  expect(output).toContain('"symbolPosition":"before"');
113
114
  expect(output).toContain('"symbolPosition":"right"');
@@ -1,16 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm test *)",
5
- "Bash(npm run *)",
6
- "Bash(pnpm typecheck *)",
7
- "Bash(pnpm test *)",
8
- "Bash(npx tsc *)",
9
- "Read(//home/guillermo/dev/z2-backend/api/src/main/java/com/zinkee/api/domain/model/v2/log/**)",
10
- "Read(//home/guillermo/dev/z2-backend/**)",
11
- "Bash(grep *)",
12
- "Bash(npx vitest *)",
13
- "Bash(npx tsx *)"
14
- ]
15
- }
16
- }