@umituz/web-hono 1.8.1 → 1.8.3

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.8.1",
3
+ "version": "1.8.3",
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/docstore.ts CHANGED
@@ -40,6 +40,8 @@ export interface DocCollectionSpec {
40
40
  singletonId?: string;
41
41
  /** Status state machine: allowed targets per current status. */
42
42
  transitions?: Record<string, string[]>;
43
+ /** Doc field the transitions guard reads. Default 'status' (fuelora: state, franchisia: stage). */
44
+ statusKey?: string;
43
45
  }
44
46
 
45
47
  export interface DocStoreSpec {
@@ -101,14 +103,15 @@ export function docStore(spec: DocStoreSpec) {
101
103
  }
102
104
  const guard = col.transitions;
103
105
  if (guard) {
106
+ const statusKey = col.statusKey ?? 'status';
104
107
  const [existing] = await db
105
108
  .select({ data: col.table.data })
106
109
  .from(col.table)
107
110
  .where(and(eq(col.table.id, String(doc.id)), isNull(col.table.deletedAt)))
108
111
  .limit(1);
109
112
  if (existing) {
110
- const from = (existing.data as Doc).status;
111
- const to = doc.status;
113
+ const from = (existing.data as Doc)[statusKey];
114
+ const to = doc[statusKey];
112
115
  if (typeof from === 'string' && typeof to === 'string' && !canTransition(guard, from, to)) {
113
116
  throw new WorkflowError(`Invalid ${key} transition ${from} → ${to}`);
114
117
  }
package/src/errors.ts CHANGED
@@ -48,7 +48,7 @@ export class ApiError extends Error {
48
48
  * node-postgres) or nested in a driver cause-chain (neon-http). Depth-capped
49
49
  * walk so malformed causes can't loop.
50
50
  */
51
- function isUniqueViolation(err: unknown): boolean {
51
+ export function isUniqueViolation(err: unknown): boolean {
52
52
  let e: unknown = err;
53
53
  for (let depth = 0; e !== null && typeof e === 'object' && depth < 3; depth += 1) {
54
54
  if ((e as { code?: unknown }).code === '23505') return true;
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  export { createApi } from './api';
23
23
  export type { ApiConfig } from './api';
24
24
  export { healthRouter } from './health';
25
- export { ApiError, apiOnError } from './errors';
25
+ export { ApiError, apiOnError, isUniqueViolation } from './errors';
26
26
  export { crudRoutes, listRoutes } from './crud';
27
27
  export type { CrudSpec, CrudTable, CrudDb, CrudDbFactory, CreateSpec, ListSpec } from './crud';
28
28
  export { docStore, canTransition, epoch, WorkflowError, UnknownCollectionError } from './docstore';