@apso/cli 0.28.0 → 0.29.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.
Files changed (35) hide show
  1. package/README.md +28 -1
  2. package/dist/commands/config.js +29 -0
  3. package/dist/commands/dev.d.ts +9 -0
  4. package/dist/commands/dev.js +29 -2
  5. package/dist/commands/generate.js +26 -14
  6. package/dist/commands/github/connect.js +3 -1
  7. package/dist/commands/link.js +1 -0
  8. package/dist/commands/update.js +1 -1
  9. package/dist/commands/use.js +2 -1
  10. package/dist/hooks/init/telemetry.js +6 -0
  11. package/dist/lib/api/services.js +7 -5
  12. package/dist/lib/config/types.d.ts +10 -0
  13. package/dist/lib/config/types.js +1 -0
  14. package/dist/lib/deploy/server-push.d.ts +1 -0
  15. package/dist/lib/generators/base.d.ts +1 -0
  16. package/dist/lib/generators/go.d.ts +22 -1
  17. package/dist/lib/generators/go.js +47 -6
  18. package/dist/lib/generators/python.d.ts +18 -0
  19. package/dist/lib/generators/python.js +33 -0
  20. package/dist/lib/generators/typescript.js +4 -1
  21. package/dist/lib/git.js +1 -1
  22. package/dist/lib/migrate/sandbox.js +3 -1
  23. package/dist/lib/telemetry/telemetry.d.ts +20 -1
  24. package/dist/lib/telemetry/telemetry.js +68 -12
  25. package/dist/lib/templates/entities/entity.eta +1 -1
  26. package/dist/lib/templates/go/events/event-emitting-entities.eta +21 -0
  27. package/dist/lib/templates/go/index-module.eta +6 -6
  28. package/dist/lib/templates/python/events/event-emitting-entities.eta +22 -0
  29. package/dist/lib/types/entity.d.ts +6 -0
  30. package/dist/lib/types/generator.d.ts +1 -0
  31. package/dist/lib/utils/template.d.ts +10 -0
  32. package/dist/lib/utils/template.js +25 -1
  33. package/npm-shrinkwrap.json +266 -425
  34. package/oclif.manifest.json +2 -1
  35. package/package.json +5 -5
package/README.md CHANGED
@@ -314,7 +314,7 @@ apso config reset # Reset to defaults
314
314
  | `webUrl` | string | Platform web URL |
315
315
  | `verbose` | boolean | Enable verbose output |
316
316
  | `noColor` | boolean | Disable colored output |
317
- | `telemetryDisabled` | boolean | Opt out of anonymous telemetry |
317
+ | `telemetryDisabled` | boolean | Opt out of anonymous telemetry (or `apso config set telemetry off`) |
318
318
  | `defaultWorkspace` | string | Default workspace slug |
319
319
 
320
320
  Boolean values accept `true`/`false` or `1`/`0`.
@@ -327,6 +327,7 @@ Environment variables override config file values:
327
327
  | `APSO_WEB_URL` | `webUrl` |
328
328
  | `APSO_DEBUG=true` | `verbose` |
329
329
  | `NO_COLOR` or `APSO_NO_COLOR=true` | `noColor` |
330
+ | `APSO_TELEMETRY=0` / `DO_NOT_TRACK=1` | `telemetryDisabled` |
330
331
 
331
332
  ### `apso schema`
332
333
 
@@ -348,6 +349,32 @@ apso [command] --help # Show command help
348
349
  apso [command] --version # Show CLI version
349
350
  ```
350
351
 
352
+ ## Telemetry & privacy
353
+
354
+ The CLI sends anonymous usage data so we can see which commands are used and
355
+ prioritize accordingly. It is opt-out and carries no personal data.
356
+
357
+ **What is collected:** command name (`generate`, `init`, `deploy`, …), CLI
358
+ version, OS and architecture, Node version, command duration and success, and
359
+ an anonymous install id (a random UUID stored in your CLI config — not derived
360
+ from any machine identifier). If you are logged in, events attribute to your
361
+ Apso account, the same as the web app.
362
+
363
+ **What is never collected:** your source code, your `.apsorc` or schema
364
+ contents, file paths, environment variable values, or any other file contents.
365
+
366
+ **Opt out** any of these ways:
367
+
368
+ ```bash
369
+ apso config set telemetry off # persisted in your CLI config
370
+ export APSO_TELEMETRY=0 # per-shell
371
+ export DO_NOT_TRACK=1 # honors the consoledonottrack.com standard
372
+ ```
373
+
374
+ On first run the CLI prints a one-time notice pointing at these opt-outs.
375
+ See [`docs/telemetry.md`](docs/telemetry.md) for full detail. Aggregate
376
+ public download stats (npm/PyPI) are available via `node scripts/usage-stats.mjs`.
377
+
351
378
  ## Supported languages
352
379
 
353
380
  | Language | Framework | ORM | Status |
@@ -26,6 +26,19 @@ function parseBoolean(value) {
26
26
  return false;
27
27
  return null;
28
28
  }
29
+ /**
30
+ * Parse the friendly `telemetry on|off` value into the underlying
31
+ * `telemetryDisabled` boolean. `off` (opt out) => disabled = true.
32
+ * Accepts on/off, enabled/disabled, and true/false/1/0.
33
+ */
34
+ function parseTelemetryToggle(value) {
35
+ const lower = value.toLowerCase();
36
+ if (["off", "false", "0", "disabled", "no"].includes(lower))
37
+ return true;
38
+ if (["on", "true", "1", "enabled", "yes"].includes(lower))
39
+ return false;
40
+ return null;
41
+ }
29
42
  class Config extends base_command_1.default {
30
43
  async run() {
31
44
  const { args, argv } = await this.parse(Config);
@@ -46,6 +59,11 @@ class Config extends base_command_1.default {
46
59
  if (!key) {
47
60
  this.error("Usage: apso config get <key>");
48
61
  }
62
+ // Friendly read-alias: `telemetry` reports on/off from telemetryDisabled.
63
+ if (key === "telemetry") {
64
+ this.log(config_1.globalConfig.read().telemetryDisabled ? "off" : "on");
65
+ return;
66
+ }
49
67
  if (!VALID_KEYS.includes(key)) {
50
68
  this.error(`Unknown key: ${key}\nValid keys: ${VALID_KEYS.join(", ")}`);
51
69
  }
@@ -59,6 +77,16 @@ class Config extends base_command_1.default {
59
77
  if (!key || value === undefined) {
60
78
  this.error("Usage: apso config set <key> <value>");
61
79
  }
80
+ // Friendly write-alias: `telemetry on|off` maps to telemetryDisabled.
81
+ if (key === "telemetry") {
82
+ const disabled = parseTelemetryToggle(value);
83
+ if (disabled === null) {
84
+ this.error(`Invalid telemetry value: ${value}. Use on or off.`);
85
+ }
86
+ config_1.globalConfig.set("telemetryDisabled", disabled);
87
+ this.log(`telemetry = ${disabled ? "off" : "on"}`);
88
+ return;
89
+ }
62
90
  if (!VALID_KEYS.includes(key)) {
63
91
  this.error(`Unknown key: ${key}\nValid keys: ${VALID_KEYS.join(", ")}`);
64
92
  }
@@ -94,6 +122,7 @@ Config.examples = [
94
122
  `$ apso config`,
95
123
  `$ apso config get apiUrl`,
96
124
  `$ apso config set verbose true`,
125
+ `$ apso config set telemetry off`,
97
126
  `$ apso config reset`,
98
127
  ];
99
128
  Config.strict = false;
@@ -13,8 +13,17 @@ export default class Dev extends BaseCommand {
13
13
  /**
14
14
  * TypeScript: run `npm run dev` which reads DATABASE_TYPE from .env.
15
15
  * PGlite is handled natively by the NestJS app -- no sidecar needed.
16
+ *
17
+ * Prefer the `dev` script, but fall back to `start:dev` for templates that
18
+ * only define the latter (e.g. the v1 service template). See apsoai/cli#102.
16
19
  */
17
20
  private runTypeScript;
21
+ /**
22
+ * Return the first script from `candidates` that exists in the local
23
+ * package.json. If package.json is missing or unparseable, fall back to the
24
+ * first candidate so behavior is unchanged when we cannot inspect it.
25
+ */
26
+ private resolveNpmScript;
18
27
  /**
19
28
  * Python: if pglite, start the pglite-server sidecar first, then uvicorn.
20
29
  */
@@ -52,10 +52,37 @@ class Dev extends base_command_1.default {
52
52
  /**
53
53
  * TypeScript: run `npm run dev` which reads DATABASE_TYPE from .env.
54
54
  * PGlite is handled natively by the NestJS app -- no sidecar needed.
55
+ *
56
+ * Prefer the `dev` script, but fall back to `start:dev` for templates that
57
+ * only define the latter (e.g. the v1 service template). See apsoai/cli#102.
55
58
  */
56
59
  async runTypeScript() {
57
- this.log("Starting TypeScript dev server...");
58
- await this.spawnAndWait("npm", ["run", "dev"]);
60
+ const script = this.resolveNpmScript(["dev", "start:dev"]);
61
+ if (!script) {
62
+ this.error('No "dev" or "start:dev" script found in package.json.\n' +
63
+ "Make sure you are in an Apso TypeScript project root.");
64
+ }
65
+ this.log(`Starting TypeScript dev server (npm run ${script})...`);
66
+ await this.spawnAndWait("npm", ["run", script]);
67
+ }
68
+ /**
69
+ * Return the first script from `candidates` that exists in the local
70
+ * package.json. If package.json is missing or unparseable, fall back to the
71
+ * first candidate so behavior is unchanged when we cannot inspect it.
72
+ */
73
+ resolveNpmScript(candidates) {
74
+ const pkgPath = path.resolve("package.json");
75
+ if (!fs.existsSync(pkgPath))
76
+ return candidates[0];
77
+ try {
78
+ // eslint-disable-next-line unicorn/prefer-json-parse-buffer -- JSON.parse's TS type requires a string, not a Buffer
79
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
80
+ const scripts = (pkg.scripts || {});
81
+ return candidates.find((c) => typeof scripts[c] === "string");
82
+ }
83
+ catch {
84
+ return candidates[0];
85
+ }
59
86
  }
60
87
  /**
61
88
  * Python: if pglite, start the pglite-server sidecar first, then uvicorn.
@@ -96,19 +96,31 @@ class Generate extends base_command_1.default {
96
96
  console.log(`[apso] Building... ${entity.name}`);
97
97
  const entityBuildStart = perf_hooks_1.performance.now();
98
98
  const entityRelationships = relationshipMap[entity.name] || [];
99
- // Effective HTTP-controller flag (TypeScript REST only for now): entity
100
- // overrides the top-level default, which defaults to true. When false, the
101
- // controller is neither generated nor wired into the module (a hand-written
102
- // controller owns the route). GraphQL uses resolvers, so the flag doesn't
103
- // apply there. Python (FastAPI) and Go (Gin) wire routers differently and
104
- // don't yet honor this flag — keep it a no-op for them (controllers always
105
- // generated) so we never emit broken wiring (a skipped router still
106
- // referenced by the index module). Tracked separately for Python/Go.
107
- const includeController = language === "typescript" && lowerCaseApiType === "rest"
108
- ? ((_b = (_a = entity.http) !== null && _a !== void 0 ? _a : http) !== null && _b !== void 0 ? _b : true)
109
- : true;
110
- if (!includeController) {
111
- console.log(`[apso] ${entity.name}: http=false — skipping generated controller`);
99
+ // Effective HTTP flag: entity overrides the top-level default, which
100
+ // defaults to true. GraphQL uses resolvers, so the flag doesn't apply
101
+ // there. The flag only does real suppression where a generated route
102
+ // can't be cleanly overridden without removing it (see apsoai/cli#95):
103
+ // - TypeScript (NestJS): suppress the controller + its module wiring.
104
+ // - Go (Gin): suppress the handler + its route registration (Gin
105
+ // panics on a duplicate method+path, so overriding needs removal).
106
+ // - Python (FastAPI): NO-OP. FastAPI matches in registration order, so
107
+ // a hand-written APIRouter included before autogen_router in main.py
108
+ // shadows the generated route without removing it. We only emit an
109
+ // informational notice pointing at that pattern.
110
+ const effectiveHttp = (_b = (_a = entity.http) !== null && _a !== void 0 ? _a : http) !== null && _b !== void 0 ? _b : true;
111
+ const httpSuppressible = (language === "typescript" || language === "go") &&
112
+ lowerCaseApiType === "rest";
113
+ const includeController = httpSuppressible ? effectiveHttp : true;
114
+ if (httpSuppressible && !includeController) {
115
+ const artifact = language === "go" ? "handler + routes" : "controller";
116
+ console.log(`[apso] ${entity.name}: http=false — skipping generated ${artifact}`);
117
+ }
118
+ else if (language === "python" &&
119
+ lowerCaseApiType === "rest" &&
120
+ effectiveHttp === false) {
121
+ console.log(`[apso] ${entity.name}: http=false is a no-op for FastAPI — to replace a ` +
122
+ `generated route, include your own APIRouter before autogen_router in main.py ` +
123
+ `(first match wins). See the custom-endpoints skill.`);
112
124
  }
113
125
  const generationTasks = [
114
126
  generator.generateEntity({
@@ -177,7 +189,7 @@ class Generate extends base_command_1.default {
177
189
  await (0, file_system_1.createFile)(fullPath, file.content);
178
190
  }
179
191
  // Generate index module
180
- const indexFiles = await generator.generateIndexModule(entities, lowerCaseApiType, { emitEvents });
192
+ const indexFiles = await generator.generateIndexModule(entities, lowerCaseApiType, { emitEvents, http });
181
193
  for (const file of indexFiles) {
182
194
  const fullPath = path.join(autogenPath, file.path);
183
195
  // eslint-disable-next-line no-await-in-loop
@@ -20,7 +20,9 @@ function openBrowser(url) {
20
20
  (0, child_process_1.exec)(command, () => resolve());
21
21
  });
22
22
  }
23
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
23
+ const sleep = (ms) => new Promise((r) => {
24
+ setTimeout(r, ms);
25
+ });
24
26
  /**
25
27
  * `apso github connect` — walk the user through connecting their GitHub
26
28
  * account so the CLI can push generated code to a real repository.
@@ -81,6 +81,7 @@ class Link extends base_command_1.default {
81
81
  else if (flags.create) {
82
82
  this.log(`Creating service "${flags.create}"...`);
83
83
  service = await (0, upgrade_1.withUpgradeRetry)(() => services_1.servicesApi.create(workspace.id, { name: flags.create }));
84
+ // eslint-disable-next-line no-negated-condition -- clearer as a non-interactive guard in this else-if chain
84
85
  }
85
86
  else if (!(0, interactive_1.isInteractive)()) {
86
87
  this.error((0, interactive_1.missingFlag)("Pass --service <slug> to link an existing service, or --create <name> to make a new one."));
@@ -40,7 +40,7 @@ class Update extends base_command_1.default {
40
40
  }
41
41
  // Pick the upgrade command based on how the CLI was installed.
42
42
  const installRoot = `${this.config.root || ""} ${process.execPath}`;
43
- const isBrew = /(?:Cellar|homebrew|\/opt\/homebrew)/i.test(installRoot);
43
+ const isBrew = /cellar|homebrew|\/opt\/homebrew/i.test(installRoot);
44
44
  const cmd = isBrew
45
45
  ? "brew upgrade apsoai/tap/apso"
46
46
  : "npm install -g @apso/cli@latest";
@@ -55,7 +55,8 @@ class Use extends base_command_1.default {
55
55
  this.log(` Now using workspace: ${ws.name} (${ws.slug})`);
56
56
  // Show what's in the workspace so the next step is obvious.
57
57
  try {
58
- const services = (await services_1.servicesApi.list(ws.id)).data;
58
+ const listed = await services_1.servicesApi.list(ws.id);
59
+ const services = listed.data;
59
60
  this.log("");
60
61
  if (services.length > 0) {
61
62
  this.log(" Services:");
@@ -7,6 +7,12 @@ const telemetry_1 = require("../../lib/telemetry/telemetry");
7
7
  */
8
8
  const hook = async function (opts) {
9
9
  (0, telemetry_1.initTelemetry)();
10
+ // First-run transparency notice (issue #96). Printed to stderr so it never
11
+ // pollutes stdout / piped output, shown once per install.
12
+ if ((0, telemetry_1.shouldShowFirstRunNotice)()) {
13
+ process.stderr.write(`\n${telemetry_1.FIRST_RUN_NOTICE}\n\n`);
14
+ (0, telemetry_1.markFirstRunNoticeShown)();
15
+ }
10
16
  if (opts.id) {
11
17
  (0, telemetry_1.track)("cli_command_started", { command: opts.id });
12
18
  }
@@ -72,9 +72,9 @@ function adaptPaginated(raw, mapItem) {
72
72
  const items = Array.isArray(raw) ? raw : (_a = raw === null || raw === void 0 ? void 0 : raw.data) !== null && _a !== void 0 ? _a : [];
73
73
  const total = (_b = raw === null || raw === void 0 ? void 0 : raw.total) !== null && _b !== void 0 ? _b : items.length;
74
74
  const page = (_c = raw === null || raw === void 0 ? void 0 : raw.page) !== null && _c !== void 0 ? _c : 1;
75
- const pageSize = items.length || 1;
75
+ const pageSize = items.length > 0 ? items.length : 1;
76
76
  return {
77
- data: items.map(mapItem),
77
+ data: items.map((item) => mapItem(item)),
78
78
  meta: {
79
79
  total,
80
80
  page,
@@ -98,7 +98,7 @@ exports.authApi = {
98
98
  * clears stored credentials). Best-effort, never throws.
99
99
  */
100
100
  async logout() {
101
- return;
101
+ // no-op: logout clears local credentials elsewhere; best-effort, never throws.
102
102
  },
103
103
  };
104
104
  /**
@@ -109,7 +109,7 @@ exports.workspacesApi = {
109
109
  var _a;
110
110
  const raw = await client_1.api.get("/api/workspaces");
111
111
  const items = Array.isArray(raw) ? raw : (_a = raw === null || raw === void 0 ? void 0 : raw.data) !== null && _a !== void 0 ? _a : [];
112
- return items.map(adaptWorkspace);
112
+ return items.map((workspace) => adaptWorkspace(workspace));
113
113
  },
114
114
  async getById(id) {
115
115
  const raw = await client_1.api.get(`/api/workspaces/${id}`);
@@ -261,7 +261,9 @@ exports.buildApi = {
261
261
  options.onProgress(status);
262
262
  if (status.status === "success" || status.status === "failed")
263
263
  return status;
264
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
264
+ await new Promise((resolve) => {
265
+ setTimeout(resolve, pollInterval);
266
+ });
265
267
  }
266
268
  /* eslint-enable no-await-in-loop */
267
269
  throw new Error("Build timed out");
@@ -123,6 +123,16 @@ export interface GlobalConfigFile {
123
123
  * Disable telemetry
124
124
  */
125
125
  telemetryDisabled: boolean;
126
+ /**
127
+ * Anonymous install id (random UUID) for opt-out CLI telemetry. Generated
128
+ * once on first run and persisted here. Not derived from any machine
129
+ * identifier; carries no PII.
130
+ */
131
+ installId?: string;
132
+ /**
133
+ * Whether the first-run telemetry transparency notice has been shown.
134
+ */
135
+ telemetryNoticeShown: boolean;
126
136
  }
127
137
  /**
128
138
  * Project link stored in .apso/link.json
@@ -19,6 +19,7 @@ exports.DEFAULT_GLOBAL_CONFIG = {
19
19
  verbose: false,
20
20
  noColor: false,
21
21
  telemetryDisabled: false,
22
+ telemetryNoticeShown: false,
22
23
  };
23
24
  /**
24
25
  * Environment variables that can override configuration
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /** Zip the project source into a buffer, skipping build/vcs/dependency dirs. */
3
4
  export declare function zipProject(cwd: string): Buffer;
4
5
  /**
@@ -54,6 +54,7 @@ export declare abstract class BaseGenerator implements LanguageGenerator {
54
54
  */
55
55
  abstract generateIndexModule(entities: Entity[], apiType: string, opts?: {
56
56
  emitEvents?: boolean;
57
+ http?: boolean;
57
58
  }): Promise<GeneratedFile[]>;
58
59
  /**
59
60
  * Generate guard files (auth, scope, etc.)
@@ -32,7 +32,28 @@ export declare class GoGenerator extends BaseGenerator {
32
32
  generateModule(_options: EntityGenerationOptions): Promise<GeneratedFile[]>;
33
33
  generateMigration(options: MigrationGenerationOptions): Promise<GeneratedFile[]>;
34
34
  generateEnums(entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
35
- generateIndexModule(entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
35
+ generateIndexModule(entities: Entity[], _apiType: string, opts?: {
36
+ emitEvents?: boolean;
37
+ http?: boolean;
38
+ }): Promise<GeneratedFile[]>;
39
+ /**
40
+ * Emits a schema-derived manifest of the entities that opted in to
41
+ * domain-event emission (`.apsorc` `emitEvents`), mirroring the TypeScript
42
+ * generator. See apsoai/cli#82.
43
+ *
44
+ * Per the Apso Distribution Model the domain-event engine (the transactional
45
+ * GORM hook/callback, mapper, relay, delivery) is NOT generated here; it
46
+ * ships as a versioned library wired by the `domain-events` skill. The CLI's
47
+ * only job is to declare WHICH entities participate, via a single generated
48
+ * file: `events/event_emitting_entities.go`.
49
+ *
50
+ * Returns an empty array when no entity is opted in.
51
+ *
52
+ * Resolution mirrors TS: `entity.emitEvents ?? <top-level emitEvents> ?? false`.
53
+ */
54
+ generateDomainEvents(entities: Entity[], _apiType?: string, opts?: {
55
+ emitEvents?: boolean;
56
+ }): Promise<GeneratedFile[]>;
36
57
  generateGuards(_entities: Entity[], auth?: AuthConfig): Promise<GeneratedFile[]>;
37
58
  generateQueryUtils(_entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
38
59
  }
@@ -8,6 +8,7 @@ const base_1 = require("./base");
8
8
  const field_1 = require("../utils/field");
9
9
  const relationships_1 = require("../utils/relationships");
10
10
  const casing_1 = require("../utils/casing");
11
+ const events_1 = require("../events");
11
12
  const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
12
13
  /**
13
14
  * Go/Gin generator that produces GORM models, DTOs, Gin handlers,
@@ -336,12 +337,20 @@ ${downStatements}
336
337
  },
337
338
  ];
338
339
  }
339
- async generateIndexModule(entities, _apiType) {
340
- const entitiesData = entities.map((entity) => ({
341
- name: entity.name,
342
- camelName: (0, casing_1.camelCase)(entity.name),
343
- kebabName: (0, casing_1.kebabCase)(entity.name),
344
- }));
340
+ async generateIndexModule(entities, _apiType, opts) {
341
+ // Effective HTTP flag per entity (entity override > top-level default >
342
+ // true). When false we skip the handler + route registration but keep the
343
+ // service and model, matching the handler suppression in generate.ts.
344
+ // See apsoai/cli#95.
345
+ const entitiesData = entities.map((entity) => {
346
+ var _a, _b;
347
+ return ({
348
+ name: entity.name,
349
+ camelName: (0, casing_1.camelCase)(entity.name),
350
+ kebabName: (0, casing_1.kebabCase)(entity.name),
351
+ http: (_b = (_a = entity.http) !== null && _a !== void 0 ? _a : opts === null || opts === void 0 ? void 0 : opts.http) !== null && _b !== void 0 ? _b : true,
352
+ });
353
+ });
345
354
  const content = await this.renderTemplate("./index-module", {
346
355
  entities: entitiesData,
347
356
  });
@@ -370,6 +379,38 @@ ${modelRefs}
370
379
  },
371
380
  ];
372
381
  }
382
+ /**
383
+ * Emits a schema-derived manifest of the entities that opted in to
384
+ * domain-event emission (`.apsorc` `emitEvents`), mirroring the TypeScript
385
+ * generator. See apsoai/cli#82.
386
+ *
387
+ * Per the Apso Distribution Model the domain-event engine (the transactional
388
+ * GORM hook/callback, mapper, relay, delivery) is NOT generated here; it
389
+ * ships as a versioned library wired by the `domain-events` skill. The CLI's
390
+ * only job is to declare WHICH entities participate, via a single generated
391
+ * file: `events/event_emitting_entities.go`.
392
+ *
393
+ * Returns an empty array when no entity is opted in.
394
+ *
395
+ * Resolution mirrors TS: `entity.emitEvents ?? <top-level emitEvents> ?? false`.
396
+ */
397
+ async generateDomainEvents(entities, _apiType, opts) {
398
+ const emittingEntities = (0, events_1.getEventEmittingEntities)(entities, opts === null || opts === void 0 ? void 0 : opts.emitEvents);
399
+ if (emittingEntities.length === 0) {
400
+ return [];
401
+ }
402
+ const content = await this.renderTemplate("./events/event-emitting-entities", {
403
+ emittingEntities: emittingEntities.map((entity) => ({
404
+ name: entity.name,
405
+ })),
406
+ });
407
+ return [
408
+ {
409
+ path: "events/event_emitting_entities.go",
410
+ content,
411
+ },
412
+ ];
413
+ }
373
414
  async generateGuards(_entities, auth) {
374
415
  const content = await this.renderTemplate("./middleware/auth", {
375
416
  auth,
@@ -17,6 +17,24 @@ export declare class PythonGenerator extends BaseGenerator {
17
17
  generateMigration(options: MigrationGenerationOptions): Promise<GeneratedFile[]>;
18
18
  generateEnums(entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
19
19
  generateIndexModule(entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
20
+ /**
21
+ * Emits a schema-derived manifest of the entities that opted in to
22
+ * domain-event emission (`.apsorc` `emitEvents`), mirroring the TypeScript
23
+ * generator. See apsoai/cli#81.
24
+ *
25
+ * Per the Apso Distribution Model the domain-event engine (the transactional
26
+ * SQLAlchemy session hook, mapper, relay, delivery) is NOT generated here; it
27
+ * ships as a versioned library wired by the `domain-events` skill. The CLI's
28
+ * only job is to declare WHICH entities participate, via a single generated
29
+ * file: `events/event_emitting_entities.py`.
30
+ *
31
+ * Returns an empty array when no entity is opted in.
32
+ *
33
+ * Resolution mirrors TS: `entity.emitEvents ?? <top-level emitEvents> ?? false`.
34
+ */
35
+ generateDomainEvents(entities: Entity[], _apiType?: string, opts?: {
36
+ emitEvents?: boolean;
37
+ }): Promise<GeneratedFile[]>;
20
38
  generateGuards(_entities: Entity[], _auth?: AuthConfig): Promise<GeneratedFile[]>;
21
39
  generateQueryUtils(_entities: Entity[], _apiType: string): Promise<GeneratedFile[]>;
22
40
  }
@@ -8,6 +8,7 @@ const base_1 = require("./base");
8
8
  const field_1 = require("../utils/field");
9
9
  const relationships_1 = require("../utils/relationships");
10
10
  const casing_1 = require("../utils/casing");
11
+ const events_1 = require("../events");
11
12
  const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
12
13
  /**
13
14
  * Python/FastAPI generator that produces SQLAlchemy models, Pydantic schemas,
@@ -281,6 +282,38 @@ ${downStatements || " pass"}
281
282
  },
282
283
  ];
283
284
  }
285
+ /**
286
+ * Emits a schema-derived manifest of the entities that opted in to
287
+ * domain-event emission (`.apsorc` `emitEvents`), mirroring the TypeScript
288
+ * generator. See apsoai/cli#81.
289
+ *
290
+ * Per the Apso Distribution Model the domain-event engine (the transactional
291
+ * SQLAlchemy session hook, mapper, relay, delivery) is NOT generated here; it
292
+ * ships as a versioned library wired by the `domain-events` skill. The CLI's
293
+ * only job is to declare WHICH entities participate, via a single generated
294
+ * file: `events/event_emitting_entities.py`.
295
+ *
296
+ * Returns an empty array when no entity is opted in.
297
+ *
298
+ * Resolution mirrors TS: `entity.emitEvents ?? <top-level emitEvents> ?? false`.
299
+ */
300
+ async generateDomainEvents(entities, _apiType, opts) {
301
+ const emittingEntities = (0, events_1.getEventEmittingEntities)(entities, opts === null || opts === void 0 ? void 0 : opts.emitEvents);
302
+ if (emittingEntities.length === 0) {
303
+ return [];
304
+ }
305
+ const content = await this.renderTemplate("./events/event-emitting-entities", {
306
+ emittingEntities: emittingEntities.map((entity) => ({
307
+ name: entity.name,
308
+ })),
309
+ });
310
+ return [
311
+ {
312
+ path: "events/event_emitting_entities.py",
313
+ content,
314
+ },
315
+ ];
316
+ }
284
317
  async generateGuards(_entities, _auth) {
285
318
  // Python auth/guards would be implemented differently (e.g., FastAPI dependencies)
286
319
  // This is a placeholder for future implementation
@@ -85,6 +85,9 @@ class TypeScriptGenerator extends base_1.BaseGenerator {
85
85
  createPrimaryKey,
86
86
  primaryKeyType,
87
87
  snakeCasedName: (0, casing_1.snakeCase)(name),
88
+ // Honor an explicit per-entity `table` override; otherwise derive from
89
+ // the entity name. See apsoai/cli#98.
90
+ tableName: entity.table || (0, casing_1.snakeCase)(name),
88
91
  createdAt,
89
92
  updatedAt,
90
93
  pluralizedName: (0, casing_1.camelCase)((0, pluralize_1.default)(name)),
@@ -118,7 +121,7 @@ class TypeScriptGenerator extends base_1.BaseGenerator {
118
121
  await (0, parse_1.streamNestedRelationships)(entityName, relationshipMap, nestedJoinsStream);
119
122
  nestedJoinsStream.end();
120
123
  await new Promise((resolve) => {
121
- nestedJoinsStream.on("finish", resolve);
124
+ nestedJoinsStream.on("finish", () => resolve());
122
125
  });
123
126
  const svcName = `${entityName}Service`;
124
127
  const ctrlName = `${entityName}Controller`;
package/dist/lib/git.js CHANGED
@@ -55,7 +55,7 @@ exports.getOriginUrl = getOriginUrl;
55
55
  function parseRepoFullName(url) {
56
56
  if (!url)
57
57
  return null;
58
- const m = url.match(/github\.com[:/]([^/]+)\/(.+?)(?:\.git)?\/?$/i);
58
+ const m = url.match(/github\.com[/:]([^/]+)\/(.+?)(?:\.git)?\/?$/i);
59
59
  return m ? `${m[1]}/${m[2]}` : null;
60
60
  }
61
61
  exports.parseRepoFullName = parseRepoFullName;
@@ -67,7 +67,9 @@ function buildEntityClasses(entities, relationshipMap = {}) {
67
67
  const classMap = new Map();
68
68
  for (const entityDef of entities) {
69
69
  const className = entityDef.name;
70
- const tableName = (0, casing_1.snakeCase)(entityDef.name);
70
+ // Honor an explicit per-entity `table` override so local migration tests
71
+ // match the generated entity's table name. See apsoai/cli#98.
72
+ const tableName = entityDef.table || (0, casing_1.snakeCase)(entityDef.name);
71
73
  const EntityClass = { [className]: class {
72
74
  } }[className];
73
75
  typeorm.Entity(tableName)(EntityClass);
@@ -1,11 +1,29 @@
1
1
  declare function isDisabled(telemetryDisabled: boolean): boolean;
2
- /** Stable, non-PII fallback id for logged-out users (no username, no MAC). */
2
+ /** Stable, non-PII fallback id (only used if the config write fails). */
3
3
  declare function anonMachineId(): string;
4
+ /**
5
+ * Read (or lazily create + persist) the anonymous install id: a random UUID
6
+ * stored in the CLI config. Not derived from any machine identifier. Falls
7
+ * back to a stable hashed id only if the config can't be written.
8
+ */
9
+ declare function getOrCreateInstallId(currentInstallId?: string): string;
4
10
  /**
5
11
  * Initialize telemetry. Call once at process start (init hook). Safe to call
6
12
  * when disabled — it just no-ops everything downstream.
7
13
  */
8
14
  export declare function initTelemetry(): void;
15
+ /**
16
+ * The one-time transparency notice text (issue #96). Printed to stderr by the
17
+ * init hook so it never pollutes stdout / piped output.
18
+ */
19
+ export declare const FIRST_RUN_NOTICE: string;
20
+ /**
21
+ * True once per install: telemetry is enabled and the notice hasn't been shown
22
+ * yet. The init hook prints the notice and then calls markFirstRunNoticeShown().
23
+ */
24
+ export declare function shouldShowFirstRunNotice(): boolean;
25
+ /** Persist that the transparency notice has been shown. Best-effort. */
26
+ export declare function markFirstRunNoticeShown(): void;
9
27
  /** Emit a PostHog event. No-op when disabled. */
10
28
  export declare function track(event: string, properties?: Record<string, unknown>): void;
11
29
  /** Report an exception to Sentry. No-op when disabled. */
@@ -17,5 +35,6 @@ export declare function shutdownTelemetry(): Promise<void>;
17
35
  export declare const __testing: {
18
36
  isDisabled: typeof isDisabled;
19
37
  anonMachineId: typeof anonMachineId;
38
+ getOrCreateInstallId: typeof getOrCreateInstallId;
20
39
  };
21
40
  export {};