tina4-nodejs 3.13.151 → 3.13.153

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.
@@ -155,6 +155,21 @@ function iso(d: Date): string {
155
155
  return d.toISOString();
156
156
  }
157
157
 
158
+ /**
159
+ * Write `key` as an own data property. A plain `obj[key] = value` with the key
160
+ * `__proto__` re-points the object's prototype instead of storing a field, and a
161
+ * path walked that way reaches Object.prototype itself. MongoDB stores
162
+ * `__proto__` as an ordinary field name, so the fallback does the same.
163
+ */
164
+ function setOwn(obj: Record<string, unknown>, key: string, value: unknown): void {
165
+ Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
166
+ }
167
+
168
+ /** The own property `key`, never one inherited through the prototype chain. */
169
+ function getOwn(obj: Record<string, unknown>, key: string): unknown {
170
+ return Object.hasOwn(obj, key) ? obj[key] : undefined;
171
+ }
172
+
158
173
  /** Value -> JSON-serialisable, sortable scalar form (for storage/queries). */
159
174
  export function encodeValue(value: unknown): unknown {
160
175
  if (value instanceof ObjectId) return value.toString();
@@ -163,7 +178,7 @@ export function encodeValue(value: unknown): unknown {
163
178
  if (value !== null && typeof value === "object") {
164
179
  const out: Record<string, unknown> = {};
165
180
  for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
166
- out[k] = encodeValue(v);
181
+ setOwn(out, k, encodeValue(v));
167
182
  }
168
183
  return out;
169
184
  }
@@ -184,7 +199,7 @@ export function decodeValue(value: unknown): unknown {
184
199
  if (value !== null && typeof value === "object") {
185
200
  const out: Record<string, unknown> = {};
186
201
  for (const [k, v] of Object.entries(value as Record<string, unknown>)) {
187
- out[k] = decodeValue(v);
202
+ setOwn(out, k, decodeValue(v));
188
203
  }
189
204
  return out;
190
205
  }
@@ -417,14 +432,14 @@ function project(doc: Record<string, unknown>, projection?: Record<string, unkno
417
432
  const exclude = new Set(Object.entries(projection).filter(([, v]) => !v).map(([k]) => k));
418
433
  if (include.size > 0) {
419
434
  const out: Record<string, unknown> = {};
420
- for (const k of include) if (k in doc) out[k] = doc[k];
435
+ for (const k of include) if (Object.hasOwn(doc, k)) setOwn(out, k, doc[k]);
421
436
  const idVal = projection._id;
422
437
  if ((idVal === undefined || idVal) && "_id" in doc) out._id = doc._id;
423
438
  return out;
424
439
  }
425
440
  // exclusion projection
426
441
  const out: Record<string, unknown> = {};
427
- for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) out[k] = v;
442
+ for (const [k, v] of Object.entries(doc)) if (!exclude.has(k)) setOwn(out, k, v);
428
443
  return out;
429
444
  }
430
445
 
@@ -432,19 +447,20 @@ function setPath(doc: Record<string, unknown>, dotted: string, value: unknown):
432
447
  const parts = dotted.split(".");
433
448
  let node = doc;
434
449
  for (const p of parts.slice(0, -1)) {
435
- if (node[p] === undefined || node[p] === null || typeof node[p] !== "object") {
436
- node[p] = {};
450
+ const child = getOwn(node, p);
451
+ if (child === undefined || child === null || typeof child !== "object") {
452
+ setOwn(node, p, {});
437
453
  }
438
454
  node = node[p] as Record<string, unknown>;
439
455
  }
440
- node[parts[parts.length - 1]] = value;
456
+ setOwn(node, parts[parts.length - 1], value);
441
457
  }
442
458
 
443
459
  function unsetPath(doc: Record<string, unknown>, dotted: string): void {
444
460
  const parts = dotted.split(".");
445
461
  let node: Record<string, unknown> | undefined = doc;
446
462
  for (const p of parts.slice(0, -1)) {
447
- const next = node[p];
463
+ const next = getOwn(node, p);
448
464
  if (next === null || typeof next !== "object") return;
449
465
  node = next as Record<string, unknown>;
450
466
  }
@@ -58,10 +58,14 @@ export declare function runCommands(args?: string[]): void;
58
58
  export interface CommandSpec {
59
59
  handler: (cmdArgs: string[]) => void | Promise<void>;
60
60
  summary: string;
61
+ /** Options main() accepts (name -> takes a value). Absent = none; null = not checked. */
62
+ flags?: OptionMap | null;
61
63
  usage?: string;
62
64
  args?: string[];
63
65
  subcommands?: string[];
64
66
  }
67
+ /** Option name (without `--`) -> whether it takes a value. */
68
+ export type OptionMap = Record<string, boolean>;
65
69
  export declare const COMMANDS: Record<string, CommandSpec>;
66
70
  export interface DelegatedSpec {
67
71
  summary: string;
@@ -81,3 +85,15 @@ export declare const EXIT_UNKNOWN_COMMAND = 1;
81
85
  * came back to a framework CLI (a delegation loop).
82
86
  */
83
87
  export declare function delegateToClient(command: string, args: string[]): number;
88
+ /**
89
+ * The options `command` accepts, or null when its arguments are not ours to
90
+ * check (an unknown generator or queue subcommand is reported by its own handler).
91
+ */
92
+ export declare function acceptedOptions(command: string, args: string[]): OptionMap | null;
93
+ /** The accepted option closest to `name`, when it is close enough to be a typo. */
94
+ export declare function closestOption(name: string, accepted: string[]): string | null;
95
+ /**
96
+ * Judge the argument at `i`: the refusal message (or null when it is fine) and
97
+ * how many arguments it used - 2 for a value option spelled `--name value`.
98
+ */
99
+ export declare function optionProblem(args: string[], i: number, accepted: OptionMap, label: string): [string | null, number];
@@ -138,11 +138,22 @@ export declare function aiFill(fn: string, spec: {
138
138
  export declare function extend(note: string, hint?: string, indent?: string): string;
139
139
  export interface GeneratorSpec {
140
140
  handler: (name: string, flags: Record<string, string | boolean>) => void;
141
+ /**
142
+ * Options this generator reads (name -> takes a value), checked by bin.ts
143
+ * main() before the handler runs. RESOLUTION_FLAGS are added on top.
144
+ */
145
+ flags: Record<string, boolean>;
141
146
  /** Arg/flag hint shown in `tina4nodejs help` (human only). */
142
147
  usage: string;
143
148
  summary: string;
144
149
  }
145
150
  export declare const GENERATORS: Record<string, GeneratorSpec>;
151
+ /**
152
+ * Options every generator accepts on top of its own: the resolution envelope
153
+ * (`--json`) and the write-nothing preview (`--dry-run`) are honoured by every
154
+ * generator here, because writes go through the shared ensureDir/writeFileSafe.
155
+ */
156
+ export declare const RESOLUTION_FLAGS: Record<string, boolean>;
146
157
  export declare function generate(what: string, name: string, extraArgs?: string[]): Promise<void>;
147
158
  /**
148
159
  * Programmatic entry point for in-process consumers (MCP tools, tests, hosted
@@ -1 +1,3 @@
1
+ /** Options migrate:create accepts (name -> takes a value), checked by bin.ts main(). */
2
+ export declare const MIGRATE_CREATE_FLAGS: Record<string, boolean>;
1
3
  export declare function createMigration(args?: string[]): Promise<void>;
@@ -11,6 +11,8 @@ export type QueueHandler = (payload: unknown) => unknown | Promise<unknown>;
11
11
  * `servicesDir` targets this topic. Mirrors Python's _resolve_queue_handler.
12
12
  */
13
13
  export declare function resolveQueueHandler(servicesDir: string, topic: string): Promise<QueueHandler | null>;
14
+ /** Options per queue subcommand (name -> takes a value), checked by bin.ts main(). */
15
+ export declare const QUEUE_FLAGS: Record<string, Record<string, boolean>>;
14
16
  /** Subcommand names, in order — surfaced in `commands --json` for the tina4 client. */
15
17
  export declare const QUEUE_SUBCOMMAND_NAMES: string[];
16
18
  /**
@@ -4,7 +4,8 @@ export interface ParsedFlags {
4
4
  positional: string[];
5
5
  }
6
6
  /**
7
- * Parse `--key value` and bare `--flag` arguments into flags plus positionals.
7
+ * Parse `--key value`, `--key=value` and bare `--flag` arguments into flags
8
+ * plus positionals.
8
9
  *
9
10
  * A name listed in `booleanFlags` never consumes the next token; every other
10
11
  * `--key` takes the following token as its value unless that token is itself a
@@ -14,10 +14,10 @@ export interface AuthGateRoute {
14
14
  * to `res.raw` and the caller must stop (not run the handler). Returns `false`
15
15
  * when the route is public OR a valid token was presented (in which case
16
16
  * `req.user` is populated and, for a body formToken, a `FreshToken` header is
17
- * set). Auth is enforced only for a route that is `secure` and not `noAuth`,
18
- * and never for `/__dev` dev-admin routes.
17
+ * set). Auth is enforced only for a route that is `secure` and not `noAuth`
18
+ * (the dev dashboard registers its own routes `noAuth`).
19
19
  *
20
20
  * Token sources, in priority order: `Authorization: Bearer` header, a
21
21
  * `formToken` in the parsed body, then a session token.
22
22
  */
23
- export declare function enforceRouteAuth(req: Tina4Request, res: Tina4Response, match: AuthGateRoute, isDevAdmin: boolean): boolean;
23
+ export declare function enforceRouteAuth(req: Tina4Request, res: Tina4Response, match: AuthGateRoute): boolean;
@@ -34,6 +34,12 @@ export declare class PostgresAdapter implements DatabaseAdapter {
34
34
  supportsAtomicBatch: boolean;
35
35
  connect(): Promise<void>;
36
36
  private ensureConnected;
37
+ private connectionIsDead;
38
+ private isConnectionError;
39
+ private reconnect;
40
+ private ensureLiveConnection;
41
+ private runQuery;
42
+ private rawQuery;
37
43
  /** Convert ? placeholders to $1, $2, ... for pg. */
38
44
  /** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */
39
45
  private decodeBlobs;