zinkee 0.1.28 → 0.1.29
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/.claude/settings.local.json +12 -1
- package/dist/index.js +4 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/records.ts +0 -1
- package/src/commands/records.test.ts +79 -14
- package/src/commands/records.ts +5 -39
package/package.json
CHANGED
package/src/api/records.ts
CHANGED
|
@@ -412,7 +412,7 @@ describe("records commands", () => {
|
|
|
412
412
|
});
|
|
413
413
|
});
|
|
414
414
|
|
|
415
|
-
it("
|
|
415
|
+
it("wraps raw-file fields into the set payload", async () => {
|
|
416
416
|
const configPath = createApiConfig();
|
|
417
417
|
const output = createStdoutBuffer();
|
|
418
418
|
const fetchMock = createFetchMock();
|
|
@@ -423,15 +423,9 @@ describe("records commands", () => {
|
|
|
423
423
|
writeFileSync(
|
|
424
424
|
rawFile,
|
|
425
425
|
JSON.stringify({
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
imported: true,
|
|
430
|
-
},
|
|
431
|
-
},
|
|
432
|
-
unset: ["legacyCode"],
|
|
433
|
-
audit: {
|
|
434
|
-
reason: "sync",
|
|
426
|
+
status: "inactive",
|
|
427
|
+
metadata: {
|
|
428
|
+
imported: true,
|
|
435
429
|
},
|
|
436
430
|
}),
|
|
437
431
|
"utf8",
|
|
@@ -472,9 +466,6 @@ describe("records commands", () => {
|
|
|
472
466
|
);
|
|
473
467
|
expect(init?.method).toBe("PATCH");
|
|
474
468
|
expect(JSON.parse(String(init?.body))).toEqual({
|
|
475
|
-
audit: {
|
|
476
|
-
reason: "sync",
|
|
477
|
-
},
|
|
478
469
|
set: {
|
|
479
470
|
status: "active",
|
|
480
471
|
metadata: {
|
|
@@ -484,7 +475,81 @@ describe("records commands", () => {
|
|
|
484
475
|
tier: "gold",
|
|
485
476
|
},
|
|
486
477
|
},
|
|
487
|
-
unset: ["
|
|
478
|
+
unset: ["tempField"],
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
it("wraps bare raw fields into the set payload", async () => {
|
|
483
|
+
const configPath = createApiConfig();
|
|
484
|
+
const output = createStdoutBuffer();
|
|
485
|
+
const fetchMock = createFetchMock();
|
|
486
|
+
mockSchemaLookup(fetchMock);
|
|
487
|
+
fetchMock.mockResolvedValueOnce(
|
|
488
|
+
jsonResponse({
|
|
489
|
+
id: "550e8400-e29b-41d4-a716-446655440001",
|
|
490
|
+
uno: "prueba mod",
|
|
491
|
+
}),
|
|
492
|
+
);
|
|
493
|
+
const program = buildProgram({ configPath, stdout: output.stdout });
|
|
494
|
+
|
|
495
|
+
await program.parseAsync([
|
|
496
|
+
"node",
|
|
497
|
+
"zinkee",
|
|
498
|
+
"--json",
|
|
499
|
+
"records",
|
|
500
|
+
"update",
|
|
501
|
+
"contacts",
|
|
502
|
+
"550E8400-E29B-41D4-A716-446655440001",
|
|
503
|
+
"--raw",
|
|
504
|
+
'{"uno":"prueba mod"}',
|
|
505
|
+
]);
|
|
506
|
+
|
|
507
|
+
const init = fetchMock.mock.calls[1]?.[1];
|
|
508
|
+
|
|
509
|
+
expect(fetchMock.mock.calls[1]?.[0]).toBe(
|
|
510
|
+
"https://api.zinkee.test/api/v2/schemas/schema-1/records/550e8400-e29b-41d4-a716-446655440001",
|
|
511
|
+
);
|
|
512
|
+
expect(init?.method).toBe("PATCH");
|
|
513
|
+
expect(JSON.parse(String(init?.body))).toEqual({
|
|
514
|
+
set: {
|
|
515
|
+
uno: "prueba mod",
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it("lets --set override raw fields with the same key", async () => {
|
|
521
|
+
const configPath = createApiConfig();
|
|
522
|
+
const output = createStdoutBuffer();
|
|
523
|
+
const fetchMock = createFetchMock();
|
|
524
|
+
mockSchemaLookup(fetchMock);
|
|
525
|
+
fetchMock.mockResolvedValueOnce(
|
|
526
|
+
jsonResponse({
|
|
527
|
+
id: "550e8400-e29b-41d4-a716-446655440001",
|
|
528
|
+
}),
|
|
529
|
+
);
|
|
530
|
+
const program = buildProgram({ configPath, stdout: output.stdout });
|
|
531
|
+
|
|
532
|
+
await program.parseAsync([
|
|
533
|
+
"node",
|
|
534
|
+
"zinkee",
|
|
535
|
+
"--json",
|
|
536
|
+
"records",
|
|
537
|
+
"update",
|
|
538
|
+
"contacts",
|
|
539
|
+
"550E8400-E29B-41D4-A716-446655440001",
|
|
540
|
+
"--raw",
|
|
541
|
+
'{"uno":"raw value"}',
|
|
542
|
+
"--set",
|
|
543
|
+
"uno=set value",
|
|
544
|
+
]);
|
|
545
|
+
|
|
546
|
+
const init = fetchMock.mock.calls[1]?.[1];
|
|
547
|
+
|
|
548
|
+
expect(init?.method).toBe("PATCH");
|
|
549
|
+
expect(JSON.parse(String(init?.body))).toEqual({
|
|
550
|
+
set: {
|
|
551
|
+
uno: "set value",
|
|
552
|
+
},
|
|
488
553
|
});
|
|
489
554
|
});
|
|
490
555
|
|
package/src/commands/records.ts
CHANGED
|
@@ -421,50 +421,16 @@ function buildRecordCreateInput(
|
|
|
421
421
|
return { values };
|
|
422
422
|
}
|
|
423
423
|
|
|
424
|
-
function readRawSetPayload(raw: JsonObject): Record<string, unknown> {
|
|
425
|
-
const setValue = raw.set;
|
|
426
|
-
|
|
427
|
-
if (setValue === undefined) {
|
|
428
|
-
return {};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (!isJsonObject(setValue)) {
|
|
432
|
-
throw new CliError(
|
|
433
|
-
"invalid_cli_usage",
|
|
434
|
-
'Expected raw update payload field "set" to be a JSON object.',
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return { ...setValue };
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function readRawUnsetPayload(raw: JsonObject): string[] {
|
|
442
|
-
const unsetValue = raw.unset;
|
|
443
|
-
|
|
444
|
-
if (unsetValue === undefined) {
|
|
445
|
-
return [];
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
if (!Array.isArray(unsetValue) || !unsetValue.every((value) => typeof value === "string")) {
|
|
449
|
-
throw new CliError(
|
|
450
|
-
"invalid_cli_usage",
|
|
451
|
-
'Expected raw update payload field "unset" to be an array of strings.',
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return [...unsetValue];
|
|
456
|
-
}
|
|
457
|
-
|
|
458
424
|
function buildRecordUpdateInput(
|
|
459
425
|
options: RecordsUpdateCommandOptions,
|
|
460
426
|
): UpdateRecordInput {
|
|
461
427
|
const raw = readRawObject(options.raw, options.rawFile);
|
|
462
|
-
const input: UpdateRecordInput = {
|
|
428
|
+
const input: UpdateRecordInput = {};
|
|
463
429
|
const setPayload = {
|
|
464
|
-
...
|
|
430
|
+
...raw,
|
|
465
431
|
...buildAssignmentObject(options.set, options.setJson),
|
|
466
432
|
};
|
|
467
|
-
const unsetPayload = [...
|
|
433
|
+
const unsetPayload = [...(options.unset ?? [])];
|
|
468
434
|
|
|
469
435
|
for (const key of Object.keys(setPayload)) {
|
|
470
436
|
const unsetIndex = unsetPayload.indexOf(key);
|
|
@@ -684,8 +650,8 @@ export function registerRecordsCommands(
|
|
|
684
650
|
.option("--set <field=value>", "set a string field", collectKeyValueAssignments, [])
|
|
685
651
|
.option("--set-json <field=json>", "set a structured field", collectJsonAssignments, [])
|
|
686
652
|
.option("--unset <field>", "unset a field", collectStringValues, [])
|
|
687
|
-
.option("--raw <json>", "raw JSON object
|
|
688
|
-
.option("--raw-file <path>", "path to a
|
|
653
|
+
.option("--raw <json>", "raw JSON object of fields to set")
|
|
654
|
+
.option("--raw-file <path>", "path to a JSON object of fields to set")
|
|
689
655
|
.action(async function action(
|
|
690
656
|
this: Command,
|
|
691
657
|
schema: NormalizedUuidOrSlug,
|