@axium/core 0.15.1 → 0.16.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.
@@ -2,14 +2,14 @@ import * as z from 'zod';
2
2
  /** @internal Used so we can narrow using `type` and get access to type-specific properties (e.g. `ZodNumber.minValue`) */
3
3
  type StringFormatTypes = z.ZodGUID | z.ZodUUID | z.ZodEmail | z.ZodURL | z.ZodEmoji | z.ZodNanoID | z.ZodCUID | z.ZodCUID2 | z.ZodULID | z.ZodXID | z.ZodKSUID | z.ZodISODateTime | z.ZodISODate | z.ZodISOTime | z.ZodISODuration | z.ZodIPv4 | z.ZodIPv6 | z.ZodCIDRv4 | z.ZodCIDRv6 | z.ZodBase64 | z.ZodBase64URL | z.ZodE164 | z.ZodJWT;
4
4
  type ZodPrefPrimitive = z.ZodString | z.ZodNumber | z.ZodBigInt | z.ZodBoolean | z.ZodDate | z.ZodLiteral | z.ZodTemplateLiteral | z.ZodFile | z.ZodEnum | StringFormatTypes;
5
- type ZodPrefComposite = ZodPrefPrimitive | z.ZodNullable<ZodPrefPrimitive> | z.ZodOptional<ZodPrefPrimitive> | z.ZodArray<ZodPrefPrimitive> | z.ZodTuple<ZodPrefPrimitive[]> | z.ZodRecord<z.ZodString, ZodPrefPrimitive> | z.ZodObject<Readonly<Record<string, ZodPrefPrimitive>>>;
5
+ type ZodPrefComposite = ZodPrefPrimitive | z.ZodNullable<ZodPrefPrimitive> | z.ZodOptional<ZodPrefPrimitive> | z.ZodDefault<ZodPrefPrimitive> | z.ZodArray<ZodPrefPrimitive> | z.ZodTuple<ZodPrefPrimitive[]> | z.ZodRecord<z.ZodString, ZodPrefPrimitive> | z.ZodObject<Readonly<Record<string, ZodPrefPrimitive>>>;
6
6
  /** @internal Used so we can narrow using `type` and get access to type-specific properties (e.g. `ZodNumber.minValue`) */
7
7
  export type ZodPref = ZodPrefComposite | z.ZodObject<Readonly<Record<string, ZodPrefComposite>>>;
8
8
  /**
9
9
  * @internal
10
10
  */
11
11
  export declare let Preferences: z.ZodObject<{
12
- debug: z.ZodBoolean;
12
+ debug: z.ZodDefault<z.ZodBoolean>;
13
13
  }, z.core.$strip>;
14
14
  /**
15
15
  * Interface for the user preferences schema shape.
@@ -17,10 +17,6 @@ export declare let Preferences: z.ZodObject<{
17
17
  */
18
18
  export interface Preferences extends z.infer<typeof Preferences> {
19
19
  }
20
- /**
21
- * @internal
22
- */
23
- export declare const preferenceDefaults: Preferences;
24
20
  /**
25
21
  * @internal
26
22
  * @todo Implement proper localization
@@ -30,7 +26,6 @@ export declare const preferenceDescriptions: Partial<Record<keyof Preferences, s
30
26
  export interface PreferenceInit<T extends keyof Preferences = keyof Preferences, S extends ZodPref = ZodPref> {
31
27
  name: T;
32
28
  schema: S;
33
- initial: z.infer<S> & Preferences[T];
34
29
  label: string;
35
30
  descriptions?: string;
36
31
  }
@@ -3,14 +3,8 @@ import * as z from 'zod';
3
3
  * @internal
4
4
  */
5
5
  export let Preferences = z.object({
6
- debug: z.boolean(),
6
+ debug: z.boolean().default(false),
7
7
  });
8
- /**
9
- * @internal
10
- */
11
- export const preferenceDefaults = {
12
- debug: false,
13
- };
14
8
  /**
15
9
  * @internal
16
10
  * @todo Implement proper localization
@@ -21,7 +15,6 @@ export const preferenceLabels = {
21
15
  export const preferenceDescriptions = {};
22
16
  export function addPreference(init) {
23
17
  Preferences = z.object({ ...Preferences.shape, [init.name]: init.schema });
24
- preferenceDefaults[init.name] = init.initial;
25
18
  preferenceLabels[init.name] = init.label;
26
19
  preferenceDescriptions[init.name] = init.descriptions;
27
20
  }
package/dist/schemas.d.ts CHANGED
@@ -1,7 +1,3 @@
1
1
  import * as z from 'zod';
2
- /** Needed for discriminated union type narrowing */
3
- export declare function zIs<const T extends z.core.$ZodTypeDef['type']>(schema: z.ZodType, type: T): schema is z.ZodType & {
4
- type: T;
5
- };
6
2
  export declare function zFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implement"]>[0], Parameters<T["implement"]>[0]>;
7
3
  export declare function zAsyncFunction<T extends z.core.$ZodFunction>(schema: T): z.ZodCustom<Parameters<T["implementAsync"]>[0], Parameters<T["implementAsync"]>[0]>;
package/dist/schemas.js CHANGED
@@ -1,8 +1,4 @@
1
1
  import * as z from 'zod';
2
- /** Needed for discriminated union type narrowing */
3
- export function zIs(schema, type) {
4
- return schema.def.type == type;
5
- }
6
2
  export function zFunction(schema) {
7
3
  return z.custom((fn) => schema.implement(fn));
8
4
  }
package/dist/user.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const User: z.ZodObject<{
7
7
  emailVerified: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
8
8
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
9
9
  preferences: z.ZodObject<{
10
- debug: z.ZodBoolean;
10
+ debug: z.ZodDefault<z.ZodBoolean>;
11
11
  }, z.core.$strip>;
12
12
  roles: z.ZodArray<z.ZodString>;
13
13
  registeredAt: z.ZodCoercedDate<unknown>;
@@ -29,7 +29,7 @@ export declare const UserPublic: z.ZodObject<{
29
29
  emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodDate>>>;
30
30
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
31
31
  preferences: z.ZodOptional<z.ZodObject<{
32
- debug: z.ZodBoolean;
32
+ debug: z.ZodDefault<z.ZodBoolean>;
33
33
  }, z.core.$strip>>;
34
34
  roles: z.ZodArray<z.ZodString>;
35
35
  registeredAt: z.ZodCoercedDate<unknown>;
@@ -39,14 +39,15 @@ export interface UserPublic extends z.infer<typeof UserPublic> {
39
39
  }
40
40
  export declare const userProtectedFields: ["email", "emailVerified", "preferences", "isAdmin"];
41
41
  export declare const UserChangeable: z.ZodObject<{
42
+ preferences: z.ZodOptional<z.ZodObject<{
43
+ debug: z.ZodDefault<z.ZodBoolean>;
44
+ }, z.core.$strip>>;
42
45
  email: z.ZodOptional<z.ZodEmail>;
43
46
  name: z.ZodOptional<z.ZodString>;
44
47
  image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
45
- preferences: z.ZodOptional<z.ZodObject<{
46
- debug: z.ZodBoolean;
47
- }, z.core.$strip>>;
48
48
  }, z.core.$strip>;
49
49
  export interface UserChangeable extends z.infer<typeof UserChangeable> {
50
+ preferences?: Preferences;
50
51
  }
51
52
  export declare function getUserImage(user: Partial<User>): string;
52
53
  export declare const UserRegistration: z.ZodObject<{
package/dist/user.js CHANGED
@@ -2,6 +2,7 @@ import * as z from 'zod';
2
2
  import { Preferences } from './preferences.js';
3
3
  import { PasskeyRegistration } from './passkeys.js';
4
4
  import { colorHash } from './color.js';
5
+ import { pick } from 'utilium';
5
6
  export const User = z.object({
6
7
  id: z.uuid(),
7
8
  name: z.string().min(1, 'Name is required').max(255, 'Name is too long'),
@@ -20,12 +21,14 @@ export const UserPublic = User.partial(Object.fromEntries(Object.keys(User.shape
20
21
  .filter((key) => !userPublicFields.includes(key))
21
22
  .map(key => [key, true])));
22
23
  export const userProtectedFields = ['email', 'emailVerified', 'preferences', 'isAdmin'];
23
- export const UserChangeable = User.pick({
24
- name: true,
25
- email: true,
26
- image: true,
27
- preferences: true,
28
- }).partial();
24
+ export const UserChangeable = z
25
+ .object({
26
+ ...pick(User.shape, 'name', 'email', 'image'),
27
+ get preferences() {
28
+ return Preferences;
29
+ },
30
+ })
31
+ .partial();
29
32
  export function getUserImage(user) {
30
33
  if (user.image)
31
34
  return user.image;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",