@umituz/web-hono 1.7.7 → 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 +1 -1
- package/src/activity.ts +19 -2
- package/src/org.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-hono",
|
|
3
|
-
"version": "1.7.
|
|
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
|
|
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
|
|
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
|
@@ -32,14 +32,18 @@ export async function orgHasMode(db: CrudDb, orgs: OrgsLike, orgId: string, mode
|
|
|
32
32
|
/** Next `PREFIX-n` (or `PREFIX-YYYY-NNNN` with year: true) document number:
|
|
33
33
|
* max numeric suffix +1 among the current year's live rows. Not a
|
|
34
34
|
* reservation — the partial-unique on number turns races into a 409.
|
|
35
|
-
*
|
|
36
|
-
*
|
|
35
|
+
* pad applies in EVERY mode — plain `pad: 4` yields `PRD-0001` and reads
|
|
36
|
+
* padded/legacy rows alike (`PRD-9` still counts as 9). digitsOnly: true
|
|
37
|
+
* serves prefix-less columns that store the bare integer ("101") — prefix
|
|
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. */
|
|
37
40
|
export async function nextNumber(
|
|
38
41
|
db: CrudDb,
|
|
39
42
|
table: NumberedTable,
|
|
40
43
|
prefix: string,
|
|
41
44
|
opts: {
|
|
42
45
|
orgId?: string;
|
|
46
|
+
scope?: { column: PgColumn; value: string };
|
|
43
47
|
base?: number;
|
|
44
48
|
year?: boolean;
|
|
45
49
|
pad?: number;
|
|
@@ -52,6 +56,7 @@ export async function nextNumber(
|
|
|
52
56
|
if (!numberCol) throw new Error('nextNumber: no number column (pass opts.column for orderNo-style tables)');
|
|
53
57
|
const conds = [];
|
|
54
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));
|
|
55
60
|
if (table.deletedAt) conds.push(isNull(table.deletedAt));
|
|
56
61
|
const rows = await db
|
|
57
62
|
.select({ number: numberCol })
|
|
@@ -68,5 +73,6 @@ export async function nextNumber(
|
|
|
68
73
|
}, opts.base ?? (bare ? 0 : withYear ? 0 : 2000));
|
|
69
74
|
const n = max + 1;
|
|
70
75
|
if (bare) return opts.pad ? String(n).padStart(opts.pad, '0') : String(n);
|
|
71
|
-
|
|
76
|
+
const body = String(n).padStart(opts.pad ?? (withYear ? 4 : 0), '0');
|
|
77
|
+
return withYear ? `${prefix}-${year}-${body}` : `${prefix}${opts.separator ?? '-'}${body}`;
|
|
72
78
|
}
|