akanjs 2.3.1-rc.3 → 2.3.1-rc.4

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": "akanjs",
3
- "version": "2.3.1-rc.3",
3
+ "version": "2.3.1-rc.4",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -3,7 +3,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { mkdir } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import type { InArgs, InValue, Client as LibsqlClient } from "@libsql/client";
6
- import { type BaseEnv, dayjs, FIELD_META, type PromiseOrObject } from "akanjs/base";
6
+ import { type BaseEnv, dayjs, FIELD_META, PRIMITIVE_DEFAULT_VALUE, type PromiseOrObject } from "akanjs/base";
7
7
  import { type ConstantModel, getDefault } from "akanjs/constant";
8
8
  import {
9
9
  createDocumentId,
@@ -951,9 +951,16 @@ export class SqliteDocumentStore {
951
951
  for (const [idx, field] of jsonFields.entries()) {
952
952
  const value = this.parseProjectedValue(row[this.projectionAlias(idx)]);
953
953
  const props = (this.database.doc[FIELD_META] as unknown as FieldMap)[field]?.getProps?.();
954
- if (value === null && props?.default !== undefined && props.default !== null && !props.nullable) {
955
- doc[field] =
956
- typeof props.default === "function" ? (props.default as (data: unknown) => unknown)(doc) : props.default;
954
+ if (value === null && !props?.nullable) {
955
+ if (props?.default != null) {
956
+ doc[field] =
957
+ typeof props.default === "function" ? (props.default as (data: unknown) => unknown)(doc) : props.default;
958
+ } else {
959
+ doc[field] =
960
+ ((props as Record<string, unknown>).modelRef as { [PRIMITIVE_DEFAULT_VALUE]?: unknown })?.[
961
+ PRIMITIVE_DEFAULT_VALUE
962
+ ] ?? null;
963
+ }
957
964
  } else {
958
965
  doc[field] = props ? this.decodeFieldValue(value, props) : value;
959
966
  }
@@ -1022,10 +1029,15 @@ export class SqliteDocumentStore {
1022
1029
  const value = payload[key];
1023
1030
  if (value === undefined) {
1024
1031
  const def = props.default;
1025
- if (def !== undefined && def !== null) {
1032
+ if (def != null) {
1026
1033
  result[key] = typeof def === "function" ? (def as (data: unknown) => unknown)(payload) : def;
1027
1034
  } else if (props.nullable) {
1028
1035
  result[key] = null;
1036
+ } else {
1037
+ result[key] =
1038
+ ((props as Record<string, unknown>).modelRef as { [PRIMITIVE_DEFAULT_VALUE]?: unknown })?.[
1039
+ PRIMITIVE_DEFAULT_VALUE
1040
+ ] ?? null;
1029
1041
  }
1030
1042
  } else {
1031
1043
  result[key] = this.decodeFieldValue(value, props);