@umituz/web-hono 1.7.8 → 1.7.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "API backend platform for Cloudflare Workers + Neon Postgres: createApi skeleton + error envelope layer, full-CRUD resource factory (opt-in create/remove, list params), schema→client type bridge (ClientRow), apiFetch/apiWrite client, reactive fetch-backed store (+React hooks), and db lifecycle scripts (reset / snapshot / seed)",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/activity.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { getTableColumns } from 'drizzle-orm';
1
2
  import type { PgColumn, PgTable } from 'drizzle-orm/pg-core';
2
3
  import { uid } from './lib';
3
4
  import type { CrudDb } from './crud';
@@ -25,8 +26,24 @@ export interface NotificationWrite {
25
26
  [extra: string]: unknown;
26
27
  }
27
28
 
29
+ type Columns = Record<string, { columnType: string }>;
30
+
31
+ /** Stamps the first present time column — the fleet's `at` plain tables and
32
+ * the trio-convention (`createdAt`) tables are both served; tables with
33
+ * neither rely on their column defaults. */
34
+ function timeStamp(table: ActivityTable, candidates: string[]): Record<string, Date> {
35
+ const columns = getTableColumns(table) as unknown as Columns;
36
+ for (const name of candidates) if (columns[name]) return { [name]: new Date() };
37
+ return {};
38
+ }
39
+
40
+ function boolStamp(table: ActivityTable, name: string, value: boolean): Record<string, boolean> {
41
+ const columns = getTableColumns(table) as unknown as Columns;
42
+ return columns[name] ? { [name]: value } : {};
43
+ }
44
+
28
45
  export async function writeAudit(db: CrudDb, table: ActivityTable, entry: AuditWrite, prefix = 'aud'): Promise<void> {
29
- await db.insert(table).values({ id: uid(prefix), at: new Date(), changes: entry.changes ?? [], ...entry } as never);
46
+ await db.insert(table).values({ id: uid(prefix), ...timeStamp(table, ['at', 'createdAt']), changes: entry.changes ?? [], ...entry } as never);
30
47
  }
31
48
 
32
49
  export async function writeNotification(
@@ -35,5 +52,5 @@ export async function writeNotification(
35
52
  n: NotificationWrite,
36
53
  prefix = 'ntf',
37
54
  ): Promise<void> {
38
- await db.insert(table).values({ id: uid(prefix), at: new Date(), read: false, ...n } as never);
55
+ await db.insert(table).values({ id: uid(prefix), ...timeStamp(table, ['at', 'createdAt']), ...boolStamp(table, 'read', false), ...n } as never);
39
56
  }
package/src/org.ts CHANGED
@@ -35,13 +35,15 @@ export async function orgHasMode(db: CrudDb, orgs: OrgsLike, orgId: string, mode
35
35
  * pad applies in EVERY mode — plain `pad: 4` yields `PRD-0001` and reads
36
36
  * padded/legacy rows alike (`PRD-9` still counts as 9). digitsOnly: true
37
37
  * serves prefix-less columns that store the bare integer ("101") — prefix
38
- * is ignored, non-numeric rows don't count. */
38
+ * is ignored, non-numeric rows don't count. scope: numbers per an arbitrary
39
+ * FK column (workspaceId…) — orgId is the common instance of the same form. */
39
40
  export async function nextNumber(
40
41
  db: CrudDb,
41
42
  table: NumberedTable,
42
43
  prefix: string,
43
44
  opts: {
44
45
  orgId?: string;
46
+ scope?: { column: PgColumn; value: string };
45
47
  base?: number;
46
48
  year?: boolean;
47
49
  pad?: number;
@@ -54,6 +56,7 @@ export async function nextNumber(
54
56
  if (!numberCol) throw new Error('nextNumber: no number column (pass opts.column for orderNo-style tables)');
55
57
  const conds = [];
56
58
  if (opts.orgId && table.organizationId) conds.push(eq(table.organizationId, opts.orgId));
59
+ if (opts.scope) conds.push(eq(opts.scope.column, opts.scope.value));
57
60
  if (table.deletedAt) conds.push(isNull(table.deletedAt));
58
61
  const rows = await db
59
62
  .select({ number: numberCol })