@umituz/web-hono 1.7.4 → 1.7.6

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.7.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)",
3
+ "version": "1.7.6",
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\u2192client 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",
7
7
  "types": "./src/index.ts",
package/src/activity.ts CHANGED
@@ -16,7 +16,7 @@ export interface AuditWrite {
16
16
  }
17
17
 
18
18
  export interface NotificationWrite {
19
- type: string;
19
+ type?: string;
20
20
  severity: string;
21
21
  title: string;
22
22
  body: string;
package/src/errors.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ErrorHandler } from 'hono';
2
2
  import type { ContentfulStatusCode } from 'hono/utils/http-status';
3
+ import { HTTPException } from 'hono/http-exception';
3
4
  import { ZodError } from 'zod';
4
5
  import type { ApiEnv } from './env';
5
6
 
@@ -64,6 +65,9 @@ export const apiOnError: ErrorHandler<{ Bindings: ApiEnv }> = (err, c) => {
64
65
  err.status,
65
66
  );
66
67
  }
68
+ if (err instanceof HTTPException) {
69
+ return c.json({ error: err.message }, err.status);
70
+ }
67
71
  if (err instanceof ZodError) {
68
72
  // Safety net: validateJson normally answers inline, but a hand-rolled
69
73
  // safeParse that throws lands here with the same contract.
package/src/org.ts CHANGED
@@ -31,12 +31,22 @@ export async function orgHasMode(db: CrudDb, orgs: OrgsLike, orgId: string, mode
31
31
 
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
- * reservation — the partial-unique on number turns races into a 409. */
34
+ * reservation — the partial-unique on number turns races into a 409.
35
+ * digitsOnly: true serves prefix-less columns that store the bare integer
36
+ * ("101") — prefix is ignored, non-numeric rows don't count. */
35
37
  export async function nextNumber(
36
38
  db: CrudDb,
37
39
  table: NumberedTable,
38
40
  prefix: string,
39
- opts: { orgId?: string; base?: number; year?: boolean; pad?: number; column?: PgColumn } = {},
41
+ opts: {
42
+ orgId?: string;
43
+ base?: number;
44
+ year?: boolean;
45
+ pad?: number;
46
+ column?: PgColumn;
47
+ digitsOnly?: boolean;
48
+ separator?: string;
49
+ } = {},
40
50
  ): Promise<string> {
41
51
  const numberCol = opts.column ?? table.number;
42
52
  if (!numberCol) throw new Error('nextNumber: no number column (pass opts.column for orderNo-style tables)');
@@ -47,13 +57,16 @@ export async function nextNumber(
47
57
  .select({ number: numberCol })
48
58
  .from(table)
49
59
  .where(conds.length > 0 ? and(...conds) : undefined);
50
- const withYear = opts.year === true;
60
+ const bare = opts.digitsOnly === true;
61
+ const withYear = !bare && opts.year === true;
51
62
  const year = new Date().getFullYear();
52
- const pat = withYear ? new RegExp(`^${prefix}-${year}-(\\d+)$`) : new RegExp(`^${prefix}-(\\d+)$`);
63
+ const sep = bare ? '' : (opts.separator ?? '-').replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
64
+ const pat = bare ? /^(\d+)$/ : withYear ? new RegExp(`^${prefix}-${year}-(\\d+)$`) : new RegExp(`^${prefix}${sep}(\\d+)$`);
53
65
  const max = rows.reduce((m, r) => {
54
66
  const n = pat.exec(String(r.number ?? ''))?.[1];
55
67
  return n ? Math.max(m, Number(n)) : m;
56
- }, opts.base ?? (withYear ? 0 : 2000));
68
+ }, opts.base ?? (bare ? 0 : withYear ? 0 : 2000));
57
69
  const n = max + 1;
58
- return withYear ? `${prefix}-${year}-${String(n).padStart(opts.pad ?? 4, '0')}` : `${prefix}-${n}`;
70
+ if (bare) return opts.pad ? String(n).padStart(opts.pad, '0') : String(n);
71
+ return withYear ? `${prefix}-${year}-${String(n).padStart(opts.pad ?? 4, '0')}` : `${prefix}${opts.separator ?? '-'}${n}`;
59
72
  }