@quickback-dev/cli 0.56.11 → 0.57.1

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.
@@ -0,0 +1,174 @@
1
+ /**
2
+ * visible-columns codemod (`quickback migrate visible-columns`).
3
+ *
4
+ * Contract: q-DSL files gain `...q.audit()` / `...q.softDelete()` spreads;
5
+ * raw Drizzle files gain the canonical column block under the managed
6
+ * marker; hand-declared columns are never rewritten; idempotent.
7
+ */
8
+ import { describe, expect, test } from 'bun:test';
9
+ import { applyVisibleColumns } from './migrate.js';
10
+ const featureFile = `
11
+ import { feature, q } from "@quickback/compiler";
12
+
13
+ export default feature("contacts", {
14
+ columns: {
15
+ id: q.id(),
16
+ name: q.text({ maxLength: 200 }).required(),
17
+ organizationId: q.scope("organization"),
18
+ },
19
+ crud: {
20
+ create: { access: { roles: ["member"] } },
21
+ },
22
+ });
23
+ `;
24
+ describe('applyVisibleColumns — q DSL', () => {
25
+ test('inserts both spreads into the columns object', () => {
26
+ const result = applyVisibleColumns(featureFile);
27
+ if (result.kind !== 'updated')
28
+ throw new Error(`expected update, got ${result.kind}`);
29
+ expect(result.source).toContain('...q.audit(),');
30
+ expect(result.source).toContain('...q.softDelete(),');
31
+ // Inside the columns object, before its closing brace.
32
+ const colsEnd = result.source.indexOf('},\n crud');
33
+ expect(result.source.indexOf('...q.audit(),')).toBeLessThan(colsEnd);
34
+ });
35
+ test('idempotent — second run is unchanged', () => {
36
+ const first = applyVisibleColumns(featureFile);
37
+ if (first.kind !== 'updated')
38
+ throw new Error('expected update');
39
+ const second = applyVisibleColumns(first.source);
40
+ expect(second.kind).toBe('unchanged');
41
+ });
42
+ test('hard-delete files skip the soft-delete spread', () => {
43
+ const hard = featureFile.replace(`create: { access: { roles: ["member"] } },`, `create: { access: { roles: ["member"] } },\n delete: { mode: "hard" },`);
44
+ const result = applyVisibleColumns(hard);
45
+ if (result.kind !== 'updated')
46
+ throw new Error('expected update');
47
+ expect(result.source).toContain('...q.audit(),');
48
+ expect(result.source).not.toContain('...q.softDelete()');
49
+ });
50
+ test('fully hand-declared audit columns are left alone', () => {
51
+ const declared = featureFile.replace(`organizationId: q.scope("organization"),`, `organizationId: q.scope("organization"),
52
+ createdAt: q.timestamp().defaultNow().required(),
53
+ modifiedAt: q.timestamp().defaultNow().required(),
54
+ createdBy: q.text().optional(),
55
+ modifiedBy: q.text().optional(),
56
+ deletedAt: q.timestamp().optional(),
57
+ deletedBy: q.text().optional(),`);
58
+ expect(applyVisibleColumns(declared).kind).toBe('unchanged');
59
+ });
60
+ });
61
+ describe('applyVisibleColumns — raw Drizzle', () => {
62
+ const rawFile = `
63
+ import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
64
+ import { defineTable } from "@quickback/compiler";
65
+
66
+ export const scores = sqliteTable("scores", {
67
+ id: text("id").primaryKey(),
68
+ value: integer("value").notNull()
69
+ });
70
+
71
+ export default defineTable(scores, {
72
+ firewall: [{ field: "organization_id", equals: "ctx.activeOrgId" }],
73
+ });
74
+ `;
75
+ test('splices the canonical block with the managed marker', () => {
76
+ const result = applyVisibleColumns(rawFile);
77
+ if (result.kind !== 'updated')
78
+ throw new Error(`expected update, got ${result.kind}`);
79
+ expect(result.source).toContain('── quickback:audit (compiler-managed');
80
+ expect(result.source).toContain(`createdAt: text("created_at").notNull().default('1970-01-01T00:00:00.000Z')`);
81
+ expect(result.source).toContain('deletedAt: text("deleted_at"),');
82
+ // The missing trailing comma on the last entry was repaired.
83
+ expect(result.source).toContain('integer("value").notNull(),');
84
+ });
85
+ test('pg dialect uses timestamp lines', () => {
86
+ const pg = rawFile
87
+ .replace(/sqliteTable/g, 'pgTable')
88
+ .replace('drizzle-orm/sqlite-core', 'drizzle-orm/pg-core');
89
+ const result = applyVisibleColumns(pg);
90
+ if (result.kind !== 'updated')
91
+ throw new Error('expected update');
92
+ expect(result.source).toContain('createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),');
93
+ });
94
+ test('idempotent on raw files', () => {
95
+ const first = applyVisibleColumns(rawFile);
96
+ if (first.kind !== 'updated')
97
+ throw new Error('expected update');
98
+ expect(applyVisibleColumns(first.source).kind).toBe('unchanged');
99
+ });
100
+ test('docblock mentions do not suppress insertion', () => {
101
+ const withDoc = rawFile.replace('export const scores', `/**\n * createdAt: managed elsewhere — see docs.\n */\nexport const scores`);
102
+ const result = applyVisibleColumns(withDoc);
103
+ expect(result.kind).toBe('updated');
104
+ });
105
+ });
106
+ describe('applyVisibleColumns — raw-path import widening', () => {
107
+ // Mirrors recruitment-neon's interview_scores.ts as it stood BEFORE the
108
+ // codemod ever ran: pg-core import without `timestamp`, no audit block.
109
+ // The committed hand-fix (46695cdc) is the expected output line — this
110
+ // test pins the codemod to producing it on its own.
111
+ const interviewScoresShape = `
112
+ import { integer, pgTable, text } from "drizzle-orm/pg-core";
113
+ import { defineTable } from "@quickback/compiler";
114
+
115
+ export const interview_scores = pgTable("interview_scores", {
116
+ id: text("id").primaryKey(),
117
+ score: integer("score").notNull(),
118
+ });
119
+
120
+ export default defineTable(interview_scores, {
121
+ firewall: [{ field: "organization_id", equals: "ctx.activeOrgId" }],
122
+ });
123
+ `;
124
+ test('pg file missing timestamp gets the import widened (interview_scores shape)', () => {
125
+ const result = applyVisibleColumns(interviewScoresShape);
126
+ if (result.kind !== 'updated')
127
+ throw new Error(`expected update, got ${result.kind}`);
128
+ expect(result.source).toContain('import { integer, pgTable, text, timestamp } from "drizzle-orm/pg-core"');
129
+ // Exactly one drizzle-core import — widened in place, not duplicated.
130
+ expect(result.source.match(/from "drizzle-orm\/pg-core"/g)?.length).toBe(1);
131
+ // And the splice still landed.
132
+ expect(result.source).toContain('── quickback:audit (compiler-managed');
133
+ });
134
+ test('sqlite files need only text — already-present import is untouched', () => {
135
+ const sqlite = `
136
+ import { sqliteTable, text } from "drizzle-orm/sqlite-core";
137
+
138
+ export const notes = sqliteTable("notes", {
139
+ id: text("id").primaryKey(),
140
+ });
141
+ `;
142
+ const result = applyVisibleColumns(sqlite);
143
+ if (result.kind !== 'updated')
144
+ throw new Error(`expected update, got ${result.kind}`);
145
+ expect(result.source).toContain('import { sqliteTable, text } from "drizzle-orm/sqlite-core"');
146
+ expect(result.source.match(/import\s*\{/g)?.length).toBe(1);
147
+ });
148
+ test('unusual import shape bails to manual naming the identifiers', () => {
149
+ const namespaced = `
150
+ import * as pg from "drizzle-orm/pg-core";
151
+
152
+ export const odd = pg.pgTable("odd", {
153
+ id: pg.text("id").primaryKey(),
154
+ });
155
+ `;
156
+ const result = applyVisibleColumns(namespaced);
157
+ if (result.kind !== 'manual')
158
+ throw new Error(`expected manual, got ${result.kind}`);
159
+ expect(result.reason).toContain('text');
160
+ expect(result.reason).toContain('timestamp');
161
+ expect(result.reason).toContain('drizzle-orm/pg-core');
162
+ });
163
+ test('aliased entries survive widening — bare canon name added alongside the alias', () => {
164
+ // `text as t` binds only `t`; the spliced canon lines call bare `text(`,
165
+ // so widening must add `text` itself (double-importing an export under
166
+ // two names is legal ES) in addition to keeping the alias.
167
+ const aliased = interviewScoresShape.replace('import { integer, pgTable, text }', 'import { integer, pgTable, text as t }');
168
+ const result = applyVisibleColumns(aliased.replace(/\btext\(/g, 't('));
169
+ if (result.kind !== 'updated')
170
+ throw new Error(`expected update, got ${result.kind}`);
171
+ expect(result.source).toContain('import { integer, pgTable, text, text as t, timestamp } from "drizzle-orm/pg-core"');
172
+ });
173
+ });
174
+ //# sourceMappingURL=migrate.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.test.js","sourceRoot":"","sources":["../../src/commands/migrate.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,WAAW,GAAG;;;;;;;;;;;;;CAanB,CAAC;AAEF,QAAQ,CAAC,6BAA6B,EAAE,GAAG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