@umituz/web-hono 1.8.5 → 1.8.7
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/dates.ts +46 -0
- package/src/index.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-hono",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.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)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
package/src/dates.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO date-string primitives for TEXT datetime columns and doc-wire dates.
|
|
3
|
+
*
|
|
4
|
+
* Fleet schemas split into two worlds: timestamptz columns (drizzle wants a
|
|
5
|
+
* Date — see pickPatch/stampUpdate) and TEXT/date-string columns whose wire
|
|
6
|
+
* format is a truncated ISO string the client renders verbatim. These helpers
|
|
7
|
+
* are the canon for the second world: one precision-parameterized formatter
|
|
8
|
+
* so each domain keeps its historical wire format byte-identical, plus the
|
|
9
|
+
* calendar-day arithmetic (today / base-date shifts) that deadline features
|
|
10
|
+
* keep re-implementing. All UTC — the local-calendar branch inside
|
|
11
|
+
* stampUpdate is the only local-time stamp in the package and stays that way.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type IsoPrecision = 'ms' | 's' | 'm' | 'd';
|
|
15
|
+
|
|
16
|
+
const ISO_LENGTH: Record<Exclude<IsoPrecision, 'ms'>, number> = { s: 19, m: 16, d: 10 };
|
|
17
|
+
|
|
18
|
+
function trunc(iso: string, precision: IsoPrecision): string {
|
|
19
|
+
return precision === 'ms' ? iso : iso.slice(0, ISO_LENGTH[precision]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Current instant truncated to the requested precision:
|
|
23
|
+
* 'ms' → 2026-10-18T05:28:47.941Z (full), 's' → …:47, 'm' → …:28, 'd' → 2026-10-18. */
|
|
24
|
+
export function isoNow(precision: IsoPrecision = 'ms'): string {
|
|
25
|
+
return trunc(new Date().toISOString(), precision);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Any instant truncated to the requested precision — the formatter for
|
|
29
|
+
* stored Dates and computed offsets (`isoAt(new Date(Date.now() + 5 * DAY), 's')`). */
|
|
30
|
+
export function isoAt(d: Date, precision: IsoPrecision = 'ms'): string {
|
|
31
|
+
return trunc(d.toISOString(), precision);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** UTC calendar day as 'YYYY-MM-DD' — equals isoNow('d'). */
|
|
35
|
+
export function todayISO(): string {
|
|
36
|
+
return new Date().toISOString().slice(0, 10);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Day-shifted UTC calendar day from a base date: addDaysISO(base, 3) is
|
|
40
|
+
* three days out, negative values reach back. Month/year rollovers ride
|
|
41
|
+
* Date's own calendar math. */
|
|
42
|
+
export function addDaysISO(iso: string, days: number): string {
|
|
43
|
+
const d = new Date(`${iso.slice(0, 10)}T00:00:00Z`);
|
|
44
|
+
d.setUTCDate(d.getUTCDate() + days);
|
|
45
|
+
return d.toISOString().slice(0, 10);
|
|
46
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* and business rules — this package owns the cross-cutting skeleton:
|
|
7
7
|
* the createApi app factory, the error envelope layer, the full-CRUD
|
|
8
8
|
* resource factory, getDb, the uid/pickPatch/stampUpdate/trio/actor
|
|
9
|
-
* helpers, the
|
|
9
|
+
* helpers, the ISO date-string primitives (isoNow/todayISO/addDaysISO),
|
|
10
|
+
* the org-scoped lookups (resolveOrg/orgHasMode/nextNumber),
|
|
10
11
|
* the audit and notification writes, findRow/softDelete, the JSON-404
|
|
11
12
|
* and SPA-fallback handlers, and the ApiEnv binding types.
|
|
12
13
|
*
|
|
@@ -29,6 +30,8 @@ export { docStore, canTransition, epoch, WorkflowError, UnknownCollectionError }
|
|
|
29
30
|
export type { Doc, DocTable, DocCollectionSpec, DocStoreSpec, DocValidateFn } from './docstore';
|
|
30
31
|
export { getDb } from './db';
|
|
31
32
|
export { uid, pickPatch, patchTypeErrors, normalizeRow, stampUpdate, trio, actor } from './lib';
|
|
33
|
+
export { isoNow, isoAt, todayISO, addDaysISO } from './dates';
|
|
34
|
+
export type { IsoPrecision } from './dates';
|
|
32
35
|
export { resolveOrg, orgHasMode, nextNumber } from './org';
|
|
33
36
|
export type { UsersLike, OrgsLike, NumberedTable } from './org';
|
|
34
37
|
export { writeAudit, writeNotification } from './activity';
|