@shivaedev/identity 0.23.0 → 0.24.0

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +64 -1
  3. package/dist/accountPreferences.d.ts +112 -0
  4. package/dist/accountPreferences.d.ts.map +1 -0
  5. package/dist/accountPreferences.js +37 -0
  6. package/dist/accountPreferences.js.map +1 -0
  7. package/dist/server/AccountClock.d.ts +11 -0
  8. package/dist/server/AccountClock.d.ts.map +1 -0
  9. package/dist/server/AccountClock.js +14 -0
  10. package/dist/server/AccountClock.js.map +1 -0
  11. package/dist/server/AccountPreferencesStore.d.ts +25 -0
  12. package/dist/server/AccountPreferencesStore.d.ts.map +1 -0
  13. package/dist/server/AccountPreferencesStore.js +13 -0
  14. package/dist/server/AccountPreferencesStore.js.map +1 -0
  15. package/dist/server/account-clock/dayRange.d.ts +7 -0
  16. package/dist/server/account-clock/dayRange.d.ts.map +1 -0
  17. package/dist/server/account-clock/dayRange.js +11 -0
  18. package/dist/server/account-clock/dayRange.js.map +1 -0
  19. package/dist/server/account-clock/initialize.d.ts +7 -0
  20. package/dist/server/account-clock/initialize.d.ts.map +1 -0
  21. package/dist/server/account-clock/initialize.js +18 -0
  22. package/dist/server/account-clock/initialize.js.map +1 -0
  23. package/dist/server/account-clock/logicalDay.d.ts +4 -0
  24. package/dist/server/account-clock/logicalDay.d.ts.map +1 -0
  25. package/dist/server/account-clock/logicalDay.js +10 -0
  26. package/dist/server/account-clock/logicalDay.js.map +1 -0
  27. package/dist/server/account-clock/settings.d.ts +5 -0
  28. package/dist/server/account-clock/settings.d.ts.map +1 -0
  29. package/dist/server/account-clock/settings.js +8 -0
  30. package/dist/server/account-clock/settings.js.map +1 -0
  31. package/dist/server/account-preferences/capture.d.ts +8 -0
  32. package/dist/server/account-preferences/capture.d.ts.map +1 -0
  33. package/dist/server/account-preferences/capture.js +8 -0
  34. package/dist/server/account-preferences/capture.js.map +1 -0
  35. package/dist/server/account-preferences/get.d.ts +12 -0
  36. package/dist/server/account-preferences/get.d.ts.map +1 -0
  37. package/dist/server/account-preferences/get.js +8 -0
  38. package/dist/server/account-preferences/get.js.map +1 -0
  39. package/dist/server/account-preferences/initialize.d.ts +59 -0
  40. package/dist/server/account-preferences/initialize.d.ts.map +1 -0
  41. package/dist/server/account-preferences/initialize.js +16 -0
  42. package/dist/server/account-preferences/initialize.js.map +1 -0
  43. package/dist/server/account-preferences/set.d.ts +8 -0
  44. package/dist/server/account-preferences/set.d.ts.map +1 -0
  45. package/dist/server/account-preferences/set.js +10 -0
  46. package/dist/server/account-preferences/set.js.map +1 -0
  47. package/dist/server/accountPreferencesHandlers.d.ts +2 -0
  48. package/dist/server/accountPreferencesHandlers.d.ts.map +1 -0
  49. package/dist/server/accountPreferencesHandlers.js +19 -0
  50. package/dist/server/accountPreferencesHandlers.js.map +1 -0
  51. package/dist/server/adapters/accountPreferencesMigration.d.ts +4 -0
  52. package/dist/server/adapters/accountPreferencesMigration.d.ts.map +1 -0
  53. package/dist/server/adapters/accountPreferencesMigration.js +12 -0
  54. package/dist/server/adapters/accountPreferencesMigration.js.map +1 -0
  55. package/dist/server/better-auth/adapters/accountPreferenceOptions.d.ts +14 -0
  56. package/dist/server/better-auth/adapters/accountPreferenceOptions.d.ts.map +1 -0
  57. package/dist/server/better-auth/adapters/accountPreferenceOptions.js +32 -0
  58. package/dist/server/better-auth/adapters/accountPreferenceOptions.js.map +1 -0
  59. package/dist/server/better-auth/adapters/mount.d.ts +45 -41
  60. package/dist/server/better-auth/adapters/mount.d.ts.map +1 -1
  61. package/dist/server/better-auth/adapters/mount.js +8 -25
  62. package/dist/server/better-auth/adapters/mount.js.map +1 -1
  63. package/dist/server/better-auth/adapters/mountSettings.d.ts +51 -0
  64. package/dist/server/better-auth/adapters/mountSettings.d.ts.map +1 -0
  65. package/dist/server/better-auth/adapters/mountSettings.js +26 -0
  66. package/dist/server/better-auth/adapters/mountSettings.js.map +1 -0
  67. package/dist/server/better-auth/adapters/preferencesClient.d.ts +3 -0
  68. package/dist/server/better-auth/adapters/preferencesClient.d.ts.map +1 -0
  69. package/dist/server/better-auth/adapters/preferencesClient.js +24 -0
  70. package/dist/server/better-auth/adapters/preferencesClient.js.map +1 -0
  71. package/package.json +16 -15
  72. package/src/accountPreferences.ts +42 -0
  73. package/src/server/AccountClock.ts +14 -0
  74. package/src/server/AccountPreferencesStore.ts +13 -0
  75. package/src/server/account-clock/dayRange.ts +12 -0
  76. package/src/server/account-clock/initialize.ts +20 -0
  77. package/src/server/account-clock/logicalDay.ts +11 -0
  78. package/src/server/account-clock/settings.ts +15 -0
  79. package/src/server/account-preferences/capture.ts +10 -0
  80. package/src/server/account-preferences/get.ts +13 -0
  81. package/src/server/account-preferences/initialize.ts +18 -0
  82. package/src/server/account-preferences/set.ts +12 -0
  83. package/src/server/accountPreferencesHandlers.ts +22 -0
  84. package/src/server/adapters/accountPreferencesMigration.ts +12 -0
  85. package/src/server/better-auth/adapters/accountPreferenceOptions.ts +33 -0
  86. package/src/server/better-auth/adapters/mount.ts +10 -27
  87. package/src/server/better-auth/adapters/mountSettings.ts +28 -0
  88. package/src/server/better-auth/adapters/preferencesClient.ts +25 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - store account timezone, locale and units through authenticated preference contracts. Browser sign-in capture preserves subsequent edits.
8
+ - provide an account clock with a configurable local day start and DST-aware logical days and half-open day ranges.
9
+
10
+ ### Breaking
11
+
12
+ - import `AccountDayStart` and `LogicalDay` from `@shivaedev/identity/server/account-clock/settings.ts`. `server/AccountClock.ts` exports the service only.
13
+ - TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
14
+
15
+ ## 0.23.1 - 2026-11-04
16
+
17
+ ### Changed
18
+
19
+ - Support externally migrated Better Auth tables as a transition to identity's frozen auth migrations. Run `assertBetterAuthSchema` before `betterAuthMount` at startup to refuse schema drift with typed diagnostics naming missing tables or columns.
20
+
3
21
  ## 0.23.0 - 2026-11-04
4
22
 
5
23
  ### Added
package/README.md CHANGED
@@ -73,6 +73,40 @@ Pass `subject: delegated` to the contract. A delegated request selects the accou
73
73
 
74
74
  `appHost` installs `subjectResolverLayer()` from `@shivaedev/identity/server/subjectResolverLayer.ts` for session hosts. Custom native RPC hosts provide that Layer with their `SessionPolicy` and install `subjectLayers(group)` from `@shivaedev/contract/subjectLayers.ts` when building the native RPC server. The subject declaration includes authentication failures in the client's error type; it needs no separate authentication middleware.
75
75
 
76
+ ### Account preferences and logical days
77
+
78
+ `AccountPreferences` from `@shivaedev/identity/accountPreferences.ts` exposes authenticated `get`, `set` and `capture` operations for the caller's timezone, locale and units (`metric` or `imperial`). `set` replaces all three values. `capture` only creates a missing record, preserving saved preferences on subsequent sign-ins. An account without a record reads `UTC`, `en` and `metric`. The contract uses `selfSubject`, so a caller cannot select another account with a transport header.
79
+
80
+ Apply `accountPreferencesMigration` from `@shivaedev/identity/server/adapters/accountPreferencesMigration.ts` as a numbered migration through `migratePostgres`. Provide `AccountPreferencesStore.layer` from `@shivaedev/identity/server/AccountPreferencesStore.ts` with the application's `SqlClient`, merge `AccountPreferences` into the RPC group, and install `accountPreferencesHandlers` from `@shivaedev/identity/server/accountPreferencesHandlers.ts`. The host supplies subject middleware as for other subject contracts.
81
+
82
+ To capture browser defaults, enable `{ accountPreferences: true }` in `betterAuthMount` and install the optional Better Auth client plugin:
83
+
84
+ ```ts
85
+ import { createAuthClient } from "better-auth/client";
86
+ import { preferencesClient } from "@shivaedev/identity/server/better-auth/adapters/preferencesClient.ts";
87
+
88
+ export const auth = createAuthClient({ plugins: [preferencesClient()] });
89
+ ```
90
+
91
+ The browser sends its `Intl.DateTimeFormat` timezone and locale to the auth mount. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the browser's first `getSession` captures them. Missing or invalid browser timezone data leaves preferences uncaptured; a later browser session can capture them. Other clients can call the `capture` contract with their own defaults.
92
+
93
+ `AccountClock` from `@shivaedev/identity/server/AccountClock.ts` reads the current subject's saved timezone when its Layer is built. Build that Layer within the subject's request, providing `AccountPreferencesStore.layer`. Each new request sees the current saved timezone. Configure `AccountDayStart` from `@shivaedev/identity/server/account-clock/settings.ts` in minutes after local midnight; it defaults to zero and accepts integers from 0 through 1439. The same module exports `LogicalDay`.
94
+
95
+ ```ts
96
+ import { DateTime, Effect, Layer } from "effect";
97
+ import { AccountClock } from "@shivaedev/identity/server/AccountClock.ts";
98
+ import { AccountDayStart } from "@shivaedev/identity/server/account-clock/settings.ts";
99
+
100
+ const clockLayer = AccountClock.layer.pipe(Layer.provide(Layer.succeed(AccountDayStart, 240)));
101
+ const today = Effect.gen(function* () {
102
+ const clock = yield* AccountClock;
103
+ const day = yield* clock.logicalDay(yield* DateTime.now);
104
+ return yield* clock.dayRange(day);
105
+ }).pipe(Effect.provide(clockLayer));
106
+ ```
107
+
108
+ `logicalDay(instant)` returns an ISO calendar date; omitting the instant uses Effect's current clock. `dayRange(day)` returns UTC `DateTime` values `{ start, end }`, with an inclusive start and exclusive end. Endpoints are constructed separately in local calendar time: a 04:00 New York day spanning spring DST lasts 23 hours, and one spanning autumn DST lasts 25 hours. The exact boundary belongs to the new logical day. Applications use `timestamp >= start && timestamp < end` when grouping records. Day starts within a DST gap use Effect's compatible disambiguation (later in a gap, earlier in an overlap).
109
+
76
110
  ### Once per application: contracts and session policy
77
111
 
78
112
  Declare authentication middleware for actor-only boundaries. When a request acts on an account's data, declare its subject on the contract instead of accepting an owner id and checking it in each handler.
@@ -148,7 +182,7 @@ const authentication = Effect.gen(function* () {
148
182
  });
149
183
  ```
150
184
 
151
- `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. Generate frozen numbered auth migrations as described below. The application SQL Layer owns shutdown.
185
+ `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. The mount does not run migrations or require identity's migration history. Use frozen numbered auth migrations as described below, or keep an existing migrator during the transition described in [Auth tables owned by another migrator](#auth-tables-owned-by-another-migrator). The application SQL Layer owns shutdown.
152
186
 
153
187
  The adapter captures the SQL transaction at creation. An adapter created at startup does not join a later `transact` around an `auth.api` call: its auth writes commit independently and survive the application's rollback. For a shared boundary, create the adapter inside `transact`, and use it only within that transaction. Create the mount there too when its Effect hooks must share the application transaction:
154
188
 
@@ -579,6 +613,35 @@ The failure's `_tag` remains `AuthFailure`; its `code` union includes the declar
579
613
 
580
614
  React's `authAction`, `authQuery` and `authSession` consume these Effects to create atoms. See [React's Better Auth usage](https://github.com/ShivaeDev/platform/blob/main/packages/react/README.md#better-auth-actions).
581
615
 
616
+ ### Auth tables owned by another migrator
617
+
618
+ An application moving from Prisma can keep Prisma in charge of its auth tables while adopting identity's mount. Apply the existing migrator first, then run `assertBetterAuthSchema` as a startup guard before `betterAuthMount`. Both use the same application `SqlClient`; keep Better Auth's table and field mappings aligned with the existing schema.
619
+
620
+ ```ts
621
+ import { Effect } from "effect";
622
+ import { assertBetterAuthSchema } from "@shivaedev/identity/server/better-auth/adapters/assertSchema.ts";
623
+ import { betterAuthDatabase } from "@shivaedev/identity/server/better-auth/adapters/database.ts";
624
+ import { betterAuthMount } from "@shivaedev/identity/server/better-auth/adapters/mount.ts";
625
+
626
+ const authOptions = {
627
+ account: { modelName: "Account" },
628
+ emailAndPassword: { enabled: true },
629
+ session: { modelName: "Session" },
630
+ user: { modelName: "User" },
631
+ verification: { modelName: "Verification" },
632
+ };
633
+
634
+ const authentication = Effect.gen(function* () {
635
+ yield* assertBetterAuthSchema(authOptions);
636
+ const database = yield* betterAuthDatabase();
637
+ return yield* betterAuthMount({ ...authOptions, database });
638
+ });
639
+ ```
640
+
641
+ Provide the SQL Layer and `memoryStore`, and supply the secret as for any mount. The guard fails in the Effect error channel with `BetterAuthSchemaDrift` from the assertion module; its `missing` array names missing tables and columns, such as `column User.emailVerified`. This failure stops acquisition before the mount starts, preserving the actionable schema diagnostic instead of the provider's generic `AuthUnavailable`. Extra application columns can stay in the auth tables. The mount reads existing sessions without changing the schema or taking over its migrations.
642
+
643
+ This is a migration step towards identity's frozen auth migrations. While Prisma owns the tables, make schema corrections in Prisma. When ownership moves, preserve the existing schema baseline in the application's migration history and use the frozen workflow below for subsequent auth changes. Generate each addition against a disposable database with the previously shipped schema applied, and register it with the application's numbered SQL migrations. Keep one migrator responsible for each auth schema change.
644
+
582
645
  ### Frozen auth migrations
583
646
 
584
647
  Generate each auth migration once, review its SQL and commit the generated module. `generateBetterAuthMigration(options, roleOptions?)` reads the current PostgreSQL schema through `SqlClient` and returns a TypeScript migration module. It does not apply the migration. The module imports only native Effect and executes fixed SQL on the migrator's transaction connection. Later auth option changes and Better Auth upgrades cannot change its SQL.
@@ -0,0 +1,112 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
3
+ export declare const AccountTimezone: Schema.String;
4
+ export declare const AccountPreferenceValues: Schema.Struct<{
5
+ readonly locale: Schema.NonEmptyString;
6
+ readonly timezone: Schema.String;
7
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
8
+ }>;
9
+ export declare const accountPreferenceKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.accountPreferences", string, Record<never, never>>;
10
+ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts").Contract<"identity.accountPreferences", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"get", Schema.Void, Schema.Struct<{
11
+ readonly locale: Schema.NonEmptyString;
12
+ readonly timezone: Schema.String;
13
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
14
+ }>, {
15
+ readonly AuthUnavailable: typeof AuthUnavailable;
16
+ }, never, undefined>>], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"capture", Schema.Struct<{
17
+ readonly locale: Schema.NonEmptyString;
18
+ readonly timezone: Schema.String;
19
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
20
+ }>, Schema.Void, {
21
+ readonly AuthUnavailable: typeof AuthUnavailable;
22
+ }>>, NoInfer<import("@shivaedev/contract/operation.ts").Command<"set", Schema.Struct<{
23
+ readonly locale: Schema.NonEmptyString;
24
+ readonly timezone: Schema.String;
25
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
26
+ }>, Schema.Void, {
27
+ readonly AuthUnavailable: typeof AuthUnavailable;
28
+ }>>], import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.capture", Schema.Struct<{
29
+ readonly locale: Schema.NonEmptyString;
30
+ readonly timezone: Schema.String;
31
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
32
+ }>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
33
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
34
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
35
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
36
+ "@shivaedev/contract/SubjectDeclaration": {
37
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
38
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
39
+ };
40
+ }, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.set", Schema.Struct<{
41
+ readonly locale: Schema.NonEmptyString;
42
+ readonly timezone: Schema.String;
43
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
44
+ }>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
45
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
46
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
47
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
48
+ "@shivaedev/contract/SubjectDeclaration": {
49
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
50
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
51
+ };
52
+ }, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.$changes", Schema.Struct<{
53
+ queries: Schema.$Array<Schema.Union<readonly Schema.Struct<{
54
+ query: Schema.Literal<"get">;
55
+ payload: Schema.Void;
56
+ }>[]>>;
57
+ }>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
58
+ readonly _tag: Schema.Literal<"Changed">;
59
+ readonly keys: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
60
+ readonly _tag: Schema.Literal<"Bucket">;
61
+ readonly collection: Schema.String;
62
+ readonly field: Schema.String;
63
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Number]>;
64
+ }>, Schema.Struct<{
65
+ readonly _tag: Schema.Literal<"List">;
66
+ readonly collection: Schema.String;
67
+ }>, Schema.Struct<{
68
+ readonly _tag: Schema.Literal<"Item">;
69
+ readonly collection: Schema.String;
70
+ readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
71
+ }>]>>;
72
+ readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
73
+ }>, Schema.Struct<{
74
+ readonly _tag: Schema.Literal<"Resync">;
75
+ }>]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof AuthUnavailable)[]>[]]>>, Schema.Never, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
76
+ readonly rpc: import("effect/rpc/Rpc").Any;
77
+ readonly payload: unknown;
78
+ }) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
79
+ "~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
80
+ "~ClientError": never;
81
+ error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
82
+ requiredForClient: false;
83
+ }) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
84
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
85
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
86
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
87
+ "@shivaedev/contract/SubjectDeclaration": {
88
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
89
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
90
+ };
91
+ }), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.get", Schema.Void, Schema.Struct<{
92
+ readonly locale: Schema.NonEmptyString;
93
+ readonly timezone: Schema.String;
94
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
95
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
96
+ readonly rpc: import("effect/rpc/Rpc").Any;
97
+ readonly payload: unknown;
98
+ }) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
99
+ "~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
100
+ "~ClientError": never;
101
+ error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
102
+ requiredForClient: false;
103
+ }) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
104
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
105
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
106
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
107
+ "@shivaedev/contract/SubjectDeclaration": {
108
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
109
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
110
+ };
111
+ }), never>, readonly [], undefined>;
112
+ //# sourceMappingURL=accountPreferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferences.d.ts","sourceRoot":"","sources":["../src/accountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,eAAO,MAAM,eAAe,eAE3B,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;EAIlC,CAAC;AAEH,eAAO,MAAM,qBAAqB,8GAA2D,CAAC;AAE9F,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAsB7B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { DateTime, Effect, Option, Schema } from "effect";
2
+ import { collection } from "@shivaedev/changes/keys.ts";
3
+ import { contract } from "@shivaedev/contract/contract.ts";
4
+ import { command, query } from "@shivaedev/contract/operation.ts";
5
+ import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
6
+ import { selfSubject } from "#subject.ts";
7
+ export const AccountTimezone = Schema.String.check(Schema.makeFilter((value) => Option.isSome(DateTime.zoneMakeNamed(value)), { expected: "an IANA timezone" }));
8
+ export const AccountPreferenceValues = Schema.Struct({
9
+ locale: Schema.NonEmptyString,
10
+ timezone: AccountTimezone,
11
+ units: Schema.Literals(["metric", "imperial"]),
12
+ });
13
+ export const accountPreferenceKeys = collection("identity.accountPreferences", Schema.String);
14
+ export const AccountPreferences = contract("identity.accountPreferences", {
15
+ commands: [
16
+ command("capture", {
17
+ invalidates: () => [accountPreferenceKeys.list],
18
+ payload: AccountPreferenceValues.fields,
19
+ rejections: { AuthUnavailable },
20
+ }),
21
+ command("set", {
22
+ invalidates: () => [accountPreferenceKeys.list],
23
+ payload: AccountPreferenceValues.fields,
24
+ rejections: { AuthUnavailable },
25
+ }),
26
+ ],
27
+ queries: [
28
+ query("get", {
29
+ readPolicy: () => Effect.succeed(true),
30
+ reads: () => [accountPreferenceKeys.list],
31
+ rejections: { AuthUnavailable },
32
+ success: AccountPreferenceValues,
33
+ }),
34
+ ],
35
+ subject: selfSubject,
36
+ });
37
+ //# sourceMappingURL=accountPreferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferences.js","sourceRoot":"","sources":["../src/accountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CACjD,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,CAC5G,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC,cAAc;IAC7B,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CAC9C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC,6BAA6B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,6BAA6B,EAAE;IACzE,QAAQ,EAAE;QACT,OAAO,CAAC,SAAS,EAAE;YAClB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YAC/C,OAAO,EAAE,uBAAuB,CAAC,MAAM;YACvC,UAAU,EAAE,EAAE,eAAe,EAAE;SAC/B,CAAC;QACF,OAAO,CAAC,KAAK,EAAE;YACd,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YAC/C,OAAO,EAAE,uBAAuB,CAAC,MAAM;YACvC,UAAU,EAAE,EAAE,eAAe,EAAE;SAC/B,CAAC;KACF;IACD,OAAO,EAAE;QACR,KAAK,CAAC,KAAK,EAAE;YACZ,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YACzC,UAAU,EAAE,EAAE,eAAe,EAAE;YAC/B,OAAO,EAAE,uBAAuB;SAChC,CAAC;KACF;IACD,OAAO,EAAE,WAAW;CACpB,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Subject } from "#subject.ts";
2
+ export declare const AccountClock: import("effect/Context").Service<"@shivaedev/identity/AccountClock", Readonly<{
3
+ readonly dayRange: (day: string) => import("effect/Effect").Effect<{
4
+ end: import("effect/DateTime").Utc;
5
+ start: import("effect/DateTime").Utc;
6
+ }, import("effect/Schema").SchemaError, never>;
7
+ readonly logicalDay: (instant?: import("effect/DateTime").Utc | undefined) => import("effect/Effect").Effect<string, never, never>;
8
+ }>> & {
9
+ readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountClock", import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("effect/Schema").SchemaError, "@shivaedev/identity/AccountPreferencesStore" | Subject>;
10
+ };
11
+ //# sourceMappingURL=AccountClock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountClock.d.ts","sourceRoot":"","sources":["../../src/server/AccountClock.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,eAAO,MAAM,YAAY;;;;;;;;CAKvB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { defineService } from "@shivaedev/service/defineService.ts";
2
+ import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
3
+ import { dayRange } from "#server/account-clock/dayRange.ts";
4
+ import { initialize } from "#server/account-clock/initialize.ts";
5
+ import { logicalDay } from "#server/account-clock/logicalDay.ts";
6
+ import { AccountDayStart } from "#server/account-clock/settings.ts";
7
+ import { Subject } from "#subject.ts";
8
+ export const AccountClock = defineService({
9
+ id: "@shivaedev/identity/AccountClock",
10
+ initialize,
11
+ methods: (state) => ({ dayRange: dayRange(state), logicalDay: logicalDay(state) }),
12
+ requires: [AccountPreferencesStore, Subject, AccountDayStart],
13
+ });
14
+ //# sourceMappingURL=AccountClock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountClock.js","sourceRoot":"","sources":["../../src/server/AccountClock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;IACzC,EAAE,EAAE,kCAAkC;IACtC,UAAU;IACV,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAClF,QAAQ,EAAE,CAAC,uBAAuB,EAAE,OAAO,EAAE,eAAe,CAAC;CAC7D,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { SqlClient } from "effect/sql";
2
+ export declare const AccountPreferencesStore: import("effect/Context").Service<"@shivaedev/identity/AccountPreferencesStore", Readonly<{
3
+ readonly capture: (id: string, values: {
4
+ readonly locale: string;
5
+ readonly timezone: string;
6
+ readonly units: "imperial" | "metric";
7
+ }) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
8
+ readonly get: (id: string) => import("effect/Effect").Effect<{
9
+ locale: string;
10
+ timezone: string;
11
+ units: "imperial" | "metric";
12
+ } | {
13
+ locale: string;
14
+ timezone: string;
15
+ units: "metric";
16
+ }, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
17
+ readonly set: (id: string, values: {
18
+ readonly locale: string;
19
+ readonly timezone: string;
20
+ readonly units: "imperial" | "metric";
21
+ }) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
22
+ }>> & {
23
+ readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountPreferencesStore", import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError, SqlClient.SqlClient>;
24
+ };
25
+ //# sourceMappingURL=AccountPreferencesStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountPreferencesStore.d.ts","sourceRoot":"","sources":["../../src/server/AccountPreferencesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOvC,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CAKlC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { SqlClient } from "effect/sql";
2
+ import { defineService } from "@shivaedev/service/defineService.ts";
3
+ import { capture } from "#server/account-preferences/capture.ts";
4
+ import { get } from "#server/account-preferences/get.ts";
5
+ import { initialize } from "#server/account-preferences/initialize.ts";
6
+ import { set } from "#server/account-preferences/set.ts";
7
+ export const AccountPreferencesStore = defineService({
8
+ id: "@shivaedev/identity/AccountPreferencesStore",
9
+ initialize,
10
+ methods: (state) => ({ capture: capture(state), get: get(state), set: set(state) }),
11
+ requires: [SqlClient.SqlClient],
12
+ });
13
+ //# sourceMappingURL=AccountPreferencesStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountPreferencesStore.js","sourceRoot":"","sources":["../../src/server/AccountPreferencesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AAEzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;IACpD,EAAE,EAAE,6CAA6C;IACjD,UAAU;IACV,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;IACnF,QAAQ,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC;CAC/B,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import type { initialize } from "./initialize.ts";
3
+ export declare function dayRange({ boundary }: Effect.Success<typeof initialize>): (day: string) => Effect.Effect<{
4
+ end: DateTime.Utc;
5
+ start: DateTime.Utc;
6
+ }, Schema.SchemaError, never>;
7
+ //# sourceMappingURL=dayRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dayRange.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC;;;8BAOvE"}
@@ -0,0 +1,11 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { LogicalDay } from "./settings.js";
3
+ export function dayRange({ boundary }) {
4
+ const decodeDay = Schema.decodeUnknownEffect(LogicalDay);
5
+ return Effect.fnUntraced(function* (day) {
6
+ yield* decodeDay(day);
7
+ const next = DateTime.makeUnsafe(day).pipe(DateTime.add({ days: 1 }), DateTime.formatIsoDateUtc);
8
+ return { end: boundary(next), start: boundary(day) };
9
+ });
10
+ }
11
+ //# sourceMappingURL=dayRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dayRange.js","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAqC;IACvE,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAW;QAC9C,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QACjG,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { Subject } from "#subject.ts";
3
+ export declare const initialize: Effect.Effect<{
4
+ boundary: (day: string) => DateTime.Utc;
5
+ timezone: string;
6
+ }, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Schema.SchemaError, "@shivaedev/identity/AccountPreferencesStore" | Subject>;
7
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,eAAO,MAAM,UAAU;oBAIC,MAAM;;yIAU5B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
3
+ import { Subject } from "#subject.ts";
4
+ import { AccountDayStart, DayStart } from "./settings.js";
5
+ export const initialize = Effect.gen(function* () {
6
+ const { id } = yield* Subject;
7
+ const { timezone } = yield* (yield* AccountPreferencesStore).get(id);
8
+ const minutes = yield* Schema.decodeUnknownEffect(DayStart)(yield* AccountDayStart);
9
+ function boundary(day) {
10
+ return DateTime.toUtc(DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
11
+ adjustForTimeZone: true,
12
+ disambiguation: "compatible",
13
+ timeZone: timezone,
14
+ }).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })));
15
+ }
16
+ return { boundary, timezone };
17
+ });
18
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC7C,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC;IAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC;IACpF,SAAS,QAAQ,CAAC,GAAW;QAC5B,OAAO,QAAQ,CAAC,KAAK,CACpB,QAAQ,CAAC,eAAe,CAAC,GAAG,GAAG,gBAAgB,EAAE;YAChD,iBAAiB,EAAE,IAAI;YACvB,cAAc,EAAE,YAAY;YAC5B,QAAQ,EAAE,QAAQ;SAClB,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,CAAC,CAAC,CACpF,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { DateTime, Effect } from "effect";
2
+ import type { initialize } from "./initialize.ts";
3
+ export declare function logicalDay({ boundary, timezone }: Effect.Success<typeof initialize>): (instant?: DateTime.Utc | undefined) => Effect.Effect<string, never, never>;
4
+ //# sourceMappingURL=logicalDay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logicalDay.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC,+EAOnF"}
@@ -0,0 +1,10 @@
1
+ import { DateTime, Effect } from "effect";
2
+ export function logicalDay({ boundary, timezone }) {
3
+ return Effect.fnUntraced(function* (instant) {
4
+ const now = instant ?? (yield* DateTime.now);
5
+ const local = DateTime.setZoneNamedUnsafe(now, timezone);
6
+ const day = DateTime.formatIsoDate(local);
7
+ return DateTime.isLessThan(now, boundary(day)) ? DateTime.makeUnsafe(day).pipe(DateTime.subtract({ days: 1 }), DateTime.formatIsoDateUtc) : day;
8
+ });
9
+ }
10
+ //# sourceMappingURL=logicalDay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logicalDay.js","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG1C,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAqC;IACnF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAsB;QACzD,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Context, Schema } from "effect";
2
+ export declare const LogicalDay: Schema.String;
3
+ export declare const AccountDayStart: Context.Reference<number>;
4
+ export declare const DayStart: Schema.Int;
5
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAoB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3D,eAAO,MAAM,UAAU,eAStB,CAAC;AAEF,eAAO,MAAM,eAAe,2BAA8F,CAAC;AAC3H,eAAO,MAAM,QAAQ,YAAoE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Context, DateTime, Option, Schema } from "effect";
2
+ export const LogicalDay = Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}$/u), Schema.makeFilter((value) => {
3
+ const parsed = DateTime.make(value);
4
+ return Option.isSome(parsed) && DateTime.formatIsoDateUtc(parsed.value) === value;
5
+ }, { expected: "an ISO calendar date" }));
6
+ export const AccountDayStart = Context.Reference("@shivaedev/identity/AccountDayStart", { defaultValue: () => 0 });
7
+ export const DayStart = Schema.Int.check(Schema.isBetween({ maximum: 1439, minimum: 0 }));
8
+ //# sourceMappingURL=settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/server/account-clock/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAC5C,MAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,EACxC,MAAM,CAAC,UAAU,CAChB,CAAC,KAAK,EAAE,EAAE;IACT,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AACnF,CAAC,EACD,EAAE,QAAQ,EAAE,sBAAsB,EAAE,CACpC,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS,CAAS,qCAAqC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAC3H,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import type { PreferencesRepository } from "./initialize.ts";
3
+ export declare function capture(repository: PreferencesRepository): (id: string, values: {
4
+ readonly locale: string;
5
+ readonly timezone: string;
6
+ readonly units: "imperial" | "metric";
7
+ }) => Effect.Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
8
+ //# sourceMappingURL=capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../../src/server/account-preferences/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,wBAAgB,OAAO,CAAC,UAAU,EAAE,qBAAqB;;;;0FAIxD"}
@@ -0,0 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import { providerFailure } from "#server/providerFailure.ts";
3
+ export function capture(repository) {
4
+ return Effect.fnUntraced(function* (id, values) {
5
+ return yield* repository.insertOrIgnore({ id, ...values }).pipe(Effect.asVoid, Effect.catch(providerFailure));
6
+ });
7
+ }
8
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/server/account-preferences/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,MAAM,UAAU,OAAO,CAAC,UAAiC;IACxD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAU,EAAE,MAA2C;QAC1F,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IAC/G,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Effect } from "effect";
2
+ import type { PreferencesRepository } from "./initialize.ts";
3
+ export declare function get(repository: PreferencesRepository): (id: string) => Effect.Effect<{
4
+ locale: string;
5
+ timezone: string;
6
+ units: "imperial" | "metric";
7
+ } | {
8
+ locale: string;
9
+ timezone: string;
10
+ units: "metric";
11
+ }, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
12
+ //# sourceMappingURL=get.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/server/account-preferences/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,wBAAgB,GAAG,CAAC,UAAU,EAAE,qBAAqB;;;;;;;WAIiD,QAAQ;mEAI7G"}
@@ -0,0 +1,8 @@
1
+ import { Effect } from "effect";
2
+ import { providerFailure } from "#server/providerFailure.ts";
3
+ export function get(repository) {
4
+ return Effect.fnUntraced(function* (id) {
5
+ return yield* repository.findById(id).pipe(Effect.map(({ locale, timezone, units }) => ({ locale, timezone, units })), Effect.catchTag("NoSuchElementError", () => Effect.succeed({ locale: "en", timezone: "UTC", units: "metric" })), Effect.catch(providerFailure));
6
+ });
7
+ }
8
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/server/account-preferences/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,MAAM,UAAU,GAAG,CAAC,UAAiC;IACpD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAU;QAC7C,OAAO,KAAK,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CACzC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,EAC1E,MAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAiB,EAAE,CAAC,CAAC,EACxH,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAC7B,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC"}