@nakedev/go-scaffold 0.1.4 → 0.3.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.
- package/LICENSE +21 -0
- package/README.md +133 -44
- package/dist/commands/auth.js +116 -11
- package/dist/commands/create.js +13 -1
- package/dist/commands/generate.js +21 -11
- package/dist/commands/method.js +32 -3
- package/dist/commands/observability.js +114 -0
- package/dist/commands/rbac.js +19 -2
- package/dist/commands/undo.js +331 -0
- package/dist/commands/worker.js +92 -32
- package/dist/index.js +366 -63
- package/dist/prompts/auth-wizard.js +29 -0
- package/dist/prompts/create-wizard.js +5 -2
- package/dist/prompts/generate-wizard.js +57 -0
- package/dist/prompts/worker-wizard.js +25 -0
- package/dist/templates/auth-manifest.js +20 -3
- package/dist/templates/create-manifest.js +13 -20
- package/dist/templates/observability-manifest.js +24 -0
- package/dist/templates/rbac-manifest.js +1 -0
- package/dist/templates/worker-manifest.js +23 -6
- package/dist/utils/auth-patcher.js +96 -21
- package/dist/utils/config.js +58 -10
- package/dist/utils/gocheck.js +57 -5
- package/dist/utils/golangci-patcher.js +73 -0
- package/dist/utils/gomod-patcher.js +53 -0
- package/dist/utils/main-patcher.js +58 -4
- package/dist/utils/marker-patch.js +125 -3
- package/dist/utils/method-patcher.js +17 -2
- package/dist/utils/module-location.js +37 -1
- package/dist/utils/naming.js +50 -2
- package/dist/utils/observability-patcher.js +107 -0
- package/dist/utils/platform-patcher.js +98 -12
- package/dist/utils/rbac-patcher.js +60 -10
- package/package.json +3 -5
- package/templates/add/auth/internal/app/user/errors.go.hbs +7 -0
- package/templates/add/auth/internal/app/user/handler.go.hbs +64 -23
- package/templates/add/auth/internal/app/user/jwt.go.hbs +31 -7
- package/templates/add/auth/internal/app/user/model/authtoken.go.hbs +39 -0
- package/templates/add/auth/internal/app/user/model/identity.go.hbs +3 -0
- package/templates/add/auth/internal/app/user/model/loginthrottle.go.hbs +26 -0
- package/templates/add/auth/internal/app/user/model/user.go.hbs +9 -1
- package/templates/add/auth/internal/app/user/repository.go.hbs +64 -11
- package/templates/add/auth/internal/app/user/repository_test.go.hbs +192 -0
- package/templates/add/auth/internal/app/user/service.go.hbs +105 -21
- package/templates/add/auth/internal/app/user/service_test.go.hbs +81 -2
- package/templates/add/auth/internal/app/user/tokenstore.go.hbs +9 -138
- package/templates/add/auth/internal/app/user/tokenstore_pg.go.hbs +144 -0
- package/templates/add/auth/internal/app/user/tokenstore_redis.go.hbs +147 -0
- package/templates/add/auth/internal/shared/middleware/ratelimit.go.hbs +21 -19
- package/templates/add/auth/internal/shared/middleware/ratelimit_memory.go.hbs +63 -0
- package/templates/add/auth/internal/shared/middleware/ratelimit_redis.go.hbs +32 -0
- package/templates/add/auth/migrations/create_auth_tokens.down.sql.hbs +1 -0
- package/templates/add/auth/migrations/create_auth_tokens.up.sql.hbs +16 -0
- package/templates/add/auth/migrations/create_identities.down.sql.hbs +1 -1
- package/templates/add/auth/migrations/create_identities.up.sql.hbs +9 -5
- package/templates/add/auth/migrations/create_login_throttle.down.sql.hbs +1 -0
- package/templates/add/auth/migrations/create_login_throttle.up.sql.hbs +10 -0
- package/templates/add/auth/migrations/create_users.down.sql.hbs +1 -1
- package/templates/add/auth/migrations/create_users.up.sql.hbs +13 -2
- package/templates/add/rbac/internal/app/role/dto.go.hbs +8 -3
- package/templates/add/rbac/internal/app/role/handler.go.hbs +4 -1
- package/templates/add/rbac/internal/app/role/model/permission.go.hbs +3 -0
- package/templates/add/rbac/internal/app/role/model/role.go.hbs +4 -0
- package/templates/add/rbac/internal/app/role/model/role_permission.go.hbs +3 -0
- package/templates/add/rbac/internal/app/role/repository.go.hbs +12 -11
- package/templates/add/rbac/internal/app/role/repository_test.go.hbs +176 -0
- package/templates/add/rbac/internal/app/role/service.go.hbs +7 -0
- package/templates/add/rbac/internal/shared/middleware/authz.go.hbs +19 -0
- package/templates/add/rbac/internal/shared/middleware/authz_test.go.hbs +1 -1
- package/templates/add/rbac/migrations/add_roles.down.sql.hbs +5 -5
- package/templates/add/rbac/migrations/add_roles.up.sql.hbs +17 -11
- package/templates/add/worker/cmd/worker/main.go.hbs +30 -24
- package/templates/add/worker/internal/platform/mail/mail.go.hbs +21 -0
- package/templates/add/worker/internal/platform/mail/task.go.hbs +31 -34
- package/templates/add/worker/internal/platform/queue/asynq.go.hbs +140 -0
- package/templates/add/worker/internal/platform/queue/queue.go.hbs +87 -0
- package/templates/add/worker/internal/platform/queue/river.go.hbs +148 -0
- package/templates/create/base/.claude/skills/go-scaffold/SKILL.md.hbs +59 -12
- package/templates/create/base/.dockerignore.hbs +13 -0
- package/templates/create/base/.env.example.hbs +18 -9
- package/templates/create/base/.github/dependabot.yml.hbs +20 -0
- package/templates/create/base/.github/workflows/ci.yml.hbs +12 -2
- package/templates/create/base/.golangci.yml.hbs +27 -0
- package/templates/create/base/AGENTS.md.hbs +8 -4
- package/templates/create/base/Dockerfile.hbs +42 -0
- package/templates/create/base/Makefile.hbs +43 -13
- package/templates/create/base/README.md.hbs +45 -8
- package/templates/create/base/cmd/api/main.go.hbs +17 -130
- package/templates/create/base/cmd/api/wiring.go.hbs +161 -0
- package/templates/create/base/go.mod.hbs +4 -4
- package/templates/create/base/internal/platform/database/database.go.hbs +30 -11
- package/templates/create/base/internal/shared/config/config.go.hbs +13 -7
- package/templates/create/base/internal/shared/pagination/pagination.go.hbs +11 -0
- package/templates/create/base/internal/shared/tx/tx.go.hbs +47 -0
- package/templates/create/base/redocly.yaml.hbs +21 -0
- package/templates/create/features/docs/architecture.md.hbs +32 -11
- package/templates/create/features/docs/openapi.yaml.hbs +0 -4
- package/templates/create/features/docs/patterns.md.hbs +82 -8
- package/templates/create/features/docs/techstack.md.hbs +8 -3
- package/templates/generate/module/dto.go.hbs +8 -1
- package/templates/generate/module/errors.go.hbs +5 -0
- package/templates/generate/module/field-column.down.sql.hbs +2 -0
- package/templates/generate/module/field-column.up.sql.hbs +15 -0
- package/templates/generate/module/handler_test.go.hbs +8 -1
- package/templates/generate/module/migration.down.sql.hbs +3 -1
- package/templates/generate/module/migration.up.sql.hbs +7 -2
- package/templates/generate/module/minimal/dto.go.hbs +3 -1
- package/templates/generate/module/model/model.go.hbs +10 -1
- package/templates/generate/module/permission.up.sql.hbs +3 -1
- package/templates/generate/module/repository.go.hbs +60 -6
- package/templates/generate/module/repository_test.go.hbs +30 -0
- package/templates/generate/module/service.go.hbs +10 -1
- package/templates/generate/module/service_test.go.hbs +45 -0
- package/dist/commands/remove.js +0 -88
- package/scripts/smoke-test.mjs +0 -2058
- package/templates/add/worker/internal/platform/queue/client.go.hbs +0 -31
- package/templates/add/worker/internal/platform/queue/server.go.hbs +0 -68
- package/tests/integration/default-module.test.mjs +0 -46
- package/tests/integration/generator-naming.test.mjs +0 -81
- package/tests/integration/generator-unit-test-seams.test.mjs +0 -91
- package/tests/integration/legacy-method-compat.test.mjs +0 -222
- package/tests/integration/remove-module.test.mjs +0 -58
- package/tests/unit/naming.test.mjs +0 -94
- package/tests/unit/smoke-isolation.test.mjs +0 -35
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
3
|
-
|
|
4
|
-
import naming from "../../dist/utils/naming.js";
|
|
5
|
-
|
|
6
|
-
const { resolveExistingModuleNaming, resolveModuleNaming } = naming;
|
|
7
|
-
|
|
8
|
-
const cases = [
|
|
9
|
-
{
|
|
10
|
-
inputs: ["order", "orders"],
|
|
11
|
-
expected: {
|
|
12
|
-
name: "order",
|
|
13
|
-
pkg: "order",
|
|
14
|
-
pascalName: "Order",
|
|
15
|
-
plural: "orders",
|
|
16
|
-
tableName: "orders",
|
|
17
|
-
errorPrefix: "ORDER",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
inputs: ["category", "categories"],
|
|
22
|
-
expected: {
|
|
23
|
-
name: "category",
|
|
24
|
-
pkg: "category",
|
|
25
|
-
pascalName: "Category",
|
|
26
|
-
plural: "categories",
|
|
27
|
-
tableName: "categories",
|
|
28
|
-
errorPrefix: "CATEGORY",
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
inputs: ["status", "statuses"],
|
|
33
|
-
expected: {
|
|
34
|
-
name: "status",
|
|
35
|
-
pkg: "status",
|
|
36
|
-
pascalName: "Status",
|
|
37
|
-
plural: "statuses",
|
|
38
|
-
tableName: "statuses",
|
|
39
|
-
errorPrefix: "STATUS",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
inputs: ["order-item", "order-items"],
|
|
44
|
-
expected: {
|
|
45
|
-
name: "order-item",
|
|
46
|
-
pkg: "orderitem",
|
|
47
|
-
pascalName: "OrderItem",
|
|
48
|
-
plural: "order-items",
|
|
49
|
-
tableName: "order_items",
|
|
50
|
-
errorPrefix: "ORDER_ITEM",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
for (const { inputs, expected } of cases) {
|
|
56
|
-
for (const input of inputs) {
|
|
57
|
-
test(`resolveModuleNaming normalizes ${input}`, () => {
|
|
58
|
-
assert.deepEqual(resolveModuleNaming(input), expected);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
test("resolveExistingModuleNaming finds a pre-canonical plural package", () => {
|
|
64
|
-
const expected = {
|
|
65
|
-
name: "orders",
|
|
66
|
-
pkg: "orders",
|
|
67
|
-
pascalName: "Orders",
|
|
68
|
-
plural: "orderses",
|
|
69
|
-
tableName: "orderses",
|
|
70
|
-
errorPrefix: "ORDERS",
|
|
71
|
-
};
|
|
72
|
-
assert.deepEqual(resolveExistingModuleNaming("orders", ["orders"]), expected);
|
|
73
|
-
assert.deepEqual(resolveExistingModuleNaming("order", ["orders"]), expected);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("resolveExistingModuleNaming can locate a legacy package whose singular is now reserved", () => {
|
|
77
|
-
assert.deepEqual(resolveExistingModuleNaming("types", ["types"]), {
|
|
78
|
-
name: "types",
|
|
79
|
-
pkg: "types",
|
|
80
|
-
pascalName: "Types",
|
|
81
|
-
plural: "typeses",
|
|
82
|
-
tableName: "typeses",
|
|
83
|
-
errorPrefix: "TYPES",
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("resolveExistingModuleNaming rejects canonical and legacy packages together", () => {
|
|
88
|
-
for (const input of ["order", "orders"]) {
|
|
89
|
-
assert.throws(
|
|
90
|
-
() => resolveExistingModuleNaming(input, ["order", "orders"]),
|
|
91
|
-
/ambiguous module.*internal\/app\/order.*internal\/app\/orders/
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import test from "node:test";
|
|
3
|
-
|
|
4
|
-
import { createSmokeRunConfig } from "../../dist/utils/smoke-run.js";
|
|
5
|
-
|
|
6
|
-
test("smoke runs receive isolated database, app port, database port, log namespace, and resource owner token", () => {
|
|
7
|
-
const alpha = createSmokeRunConfig("alpha-101", 41001, 54101);
|
|
8
|
-
const beta = createSmokeRunConfig("beta-202", 41002, 54102);
|
|
9
|
-
|
|
10
|
-
assert.match(alpha.dbName, /^go_scaffold_smoke_alpha_101$/);
|
|
11
|
-
assert.match(beta.dbName, /^go_scaffold_smoke_beta_202$/);
|
|
12
|
-
assert.notEqual(alpha.dbName, beta.dbName);
|
|
13
|
-
assert.equal(alpha.dbHost, "127.0.0.1");
|
|
14
|
-
assert.equal(alpha.dbPort, 54101);
|
|
15
|
-
assert.equal(beta.dbPort, 54102);
|
|
16
|
-
assert.notEqual(alpha.dbPort, beta.dbPort);
|
|
17
|
-
assert.match(alpha.dbDsn, /127\.0\.0\.1:54101\/go_scaffold_smoke_alpha_101\?sslmode=disable$/);
|
|
18
|
-
|
|
19
|
-
assert.equal(alpha.port, 41001);
|
|
20
|
-
assert.equal(beta.port, 41002);
|
|
21
|
-
assert.notEqual(alpha.baseURL, beta.baseURL);
|
|
22
|
-
assert.equal(alpha.baseURL, "http://127.0.0.1:41001");
|
|
23
|
-
|
|
24
|
-
assert.notEqual(alpha.logPrefix, beta.logPrefix);
|
|
25
|
-
assert.match(alpha.logPrefix, /go-scaffold-smoke-alpha_101$/);
|
|
26
|
-
assert.equal(alpha.ownerToken, "go-scaffold-smoke-alpha_101");
|
|
27
|
-
assert.equal(alpha.dockerLabel, "go-scaffold.smoke.owner=go-scaffold-smoke-alpha_101");
|
|
28
|
-
assert.equal(alpha.containerNamePrefix, "go-scaffold-smoke-alpha_101");
|
|
29
|
-
assert.notEqual(alpha.ownerToken, beta.ownerToken);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("smoke config rejects invalid PostgreSQL ports", () => {
|
|
33
|
-
assert.throws(() => createSmokeRunConfig("alpha", 41001, 0), /invalid smoke-test PostgreSQL port: 0/);
|
|
34
|
-
assert.throws(() => createSmokeRunConfig("alpha", 41001, 65536), /invalid smoke-test PostgreSQL port: 65536/);
|
|
35
|
-
});
|