@umituz/web-hono 1.7.2 → 1.7.4
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/org.ts +12 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-hono",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
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/org.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { eq } from 'drizzle-orm';
|
|
1
|
+
import { and, eq, isNull } from 'drizzle-orm';
|
|
2
2
|
import type { PgColumn, PgTable } from 'drizzle-orm/pg-core';
|
|
3
3
|
import type { CrudDb } from './crud';
|
|
4
4
|
|
|
5
5
|
export type UsersLike = PgTable & { id: PgColumn; organizationId: PgColumn };
|
|
6
6
|
export type OrgsLike = PgTable & { id: PgColumn; modes: PgColumn };
|
|
7
|
-
export type NumberedTable = PgTable & { number
|
|
7
|
+
export type NumberedTable = PgTable & { number?: PgColumn; organizationId?: PgColumn; deletedAt?: PgColumn };
|
|
8
8
|
|
|
9
9
|
/** Organization of the acting user; missing actor → fallback. */
|
|
10
10
|
export async function resolveOrg(
|
|
@@ -36,10 +36,17 @@ export async function nextNumber(
|
|
|
36
36
|
db: CrudDb,
|
|
37
37
|
table: NumberedTable,
|
|
38
38
|
prefix: string,
|
|
39
|
-
opts: { orgId?: string; base?: number; year?: boolean; pad?: number } = {},
|
|
39
|
+
opts: { orgId?: string; base?: number; year?: boolean; pad?: number; column?: PgColumn } = {},
|
|
40
40
|
): Promise<string> {
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
const numberCol = opts.column ?? table.number;
|
|
42
|
+
if (!numberCol) throw new Error('nextNumber: no number column (pass opts.column for orderNo-style tables)');
|
|
43
|
+
const conds = [];
|
|
44
|
+
if (opts.orgId && table.organizationId) conds.push(eq(table.organizationId, opts.orgId));
|
|
45
|
+
if (table.deletedAt) conds.push(isNull(table.deletedAt));
|
|
46
|
+
const rows = await db
|
|
47
|
+
.select({ number: numberCol })
|
|
48
|
+
.from(table)
|
|
49
|
+
.where(conds.length > 0 ? and(...conds) : undefined);
|
|
43
50
|
const withYear = opts.year === true;
|
|
44
51
|
const year = new Date().getFullYear();
|
|
45
52
|
const pat = withYear ? new RegExp(`^${prefix}-${year}-(\\d+)$`) : new RegExp(`^${prefix}-(\\d+)$`);
|