akanjs 2.3.2-rc.0 → 2.3.2-rc.2

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.
@@ -200,7 +200,7 @@ export class ConstantRegistry {
200
200
  _StateLight: null as unknown as GetStateObject<Light>,
201
201
  _StateInsight: null as unknown as GetStateObject<Insight>,
202
202
  };
203
- ConstantRegistry.setDatabase(refName, cnst);
203
+ ConstantRegistry.setDatabase(refName, cnst as ConstantModel);
204
204
  Object.entries(constExports).forEach(([key, value]) => {
205
205
  if ((modelRefSet as Set<unknown>).has(value)) return;
206
206
  else if (typeof value === "function" && isEnum(value as Cls))
@@ -48,10 +48,10 @@ export type FieldToValue<Field, MapValue = any> = Field extends null
48
48
  export interface FieldInfoObject {
49
49
  [key: string]: FieldInfo<any, ConstantFieldTypeInput | null, any>;
50
50
  }
51
- export type ExtractFieldInfoObject<Obj extends FieldInfoObject, NullableType extends string = "hidden" | "secret"> = {
52
- [K in keyof Obj]: Obj[K] extends FieldInfo<infer FieldType, infer FieldValue, infer ExplicitType, infer MapValue>
51
+ export type ExtractFieldInfoObject<Obj extends FieldInfoObject> = {
52
+ [K in keyof Obj]: Obj[K] extends FieldInfo<any, infer FieldValue, infer ExplicitType, infer MapValue>
53
53
  ? unknown extends ExplicitType
54
- ? FieldToValue<FieldValue | (FieldType extends NullableType ? null : never), MapValue>
54
+ ? FieldToValue<FieldValue, MapValue>
55
55
  : ExplicitType
56
56
  : never;
57
57
  };
@@ -381,7 +381,7 @@ field.hidden = <
381
381
  value: Value,
382
382
  option: FieldOption<Value, MapValue> = {},
383
383
  ) =>
384
- new FieldInfo<"hidden", Value, ExplicitType, MapValue>(value, {
384
+ new FieldInfo<"hidden", Value | null, ExplicitType | null, MapValue>(value, {
385
385
  ...option,
386
386
  fieldType: "hidden",
387
387
  nullable: true,
@@ -394,7 +394,7 @@ field.secret = <
394
394
  value: Value,
395
395
  option: FieldOption<Value, MapValue> = {},
396
396
  ) =>
397
- new FieldInfo<"secret", Value, ExplicitType, MapValue>(value, {
397
+ new FieldInfo<"secret", Value | null, ExplicitType | null, MapValue>(value, {
398
398
  ...option,
399
399
  fieldType: "secret",
400
400
  select: false,
package/constant/via.ts CHANGED
@@ -172,6 +172,15 @@ export interface ConstantStatics<Schema = any, FieldObj extends FieldObject = Fi
172
172
  relations: Set<ConstantCls>;
173
173
  enums: Set<EnumInstance>;
174
174
  text: { search: Set<string>; filter: Set<string>; children: { search: Set<string>; filter: Set<string> } };
175
+ _DatabaseSchema: {
176
+ [K in keyof Schema]: K extends keyof FieldObj
177
+ ? FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any>
178
+ ? FieldType extends "hidden"
179
+ ? NonNullable<Schema[K]>
180
+ : Schema[K]
181
+ : Schema[K]
182
+ : Schema[K];
183
+ };
175
184
  }
176
185
  export type ConstantCls<Schema = any, FieldObj extends FieldObject = FieldObject> = (new (
177
186
  obj?: Partial<Schema>,
package/document/by.ts CHANGED
@@ -3,7 +3,6 @@ import { applyMixins } from "akanjs/common";
3
3
  import {
4
4
  type BaseObject,
5
5
  type ConstantCls,
6
- type ConstantField,
7
6
  ConstantRegistry,
8
7
  type DocumentModel,
9
8
  type FieldObject,
@@ -23,19 +22,12 @@ type HydratedDocumentWithId<TDocument> = TDocument & { id: string } & DefaultDoc
23
22
  export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
24
23
 
25
24
  export const by = <
26
- Schema,
27
- FieldObj extends FieldObject,
25
+ ModelCls,
28
26
  AddDbModels extends DatabaseCls[],
29
- _DatabaseSchema = Schema & {
30
- [K in keyof FieldObj & keyof Schema as FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any>
31
- ? FieldType extends "hidden"
32
- ? K
33
- : never
34
- : never]: NonNullable<Schema[K]>;
35
- },
36
- _DocModel = Schema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
27
+ _DatabaseSchema = ModelCls extends { _DatabaseSchema: infer Schema } ? Schema : never,
28
+ _DocModel = _DatabaseSchema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>,
37
29
  >(
38
- modelRef: ConstantCls<Schema, FieldObj>,
30
+ modelRef: ModelCls,
39
31
  ...addRefs: AddDbModels
40
32
  ): DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel> => {
41
33
  const refName = ConstantRegistry.getRefName(modelRef as Cls);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "2.3.2-rc.0",
3
+ "version": "2.3.2-rc.2",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -11,8 +11,8 @@ export type FieldToValue<Field, MapValue = any> = Field extends null ? FieldToVa
11
11
  export interface FieldInfoObject {
12
12
  [key: string]: FieldInfo<any, ConstantFieldTypeInput | null, any>;
13
13
  }
14
- export type ExtractFieldInfoObject<Obj extends FieldInfoObject, NullableType extends string = "hidden" | "secret"> = {
15
- [K in keyof Obj]: Obj[K] extends FieldInfo<infer FieldType, infer FieldValue, infer ExplicitType, infer MapValue> ? unknown extends ExplicitType ? FieldToValue<FieldValue | (FieldType extends NullableType ? null : never), MapValue> : ExplicitType : never;
14
+ export type ExtractFieldInfoObject<Obj extends FieldInfoObject> = {
15
+ [K in keyof Obj]: Obj[K] extends FieldInfo<any, infer FieldValue, infer ExplicitType, infer MapValue> ? unknown extends ExplicitType ? FieldToValue<FieldValue, MapValue> : ExplicitType : never;
16
16
  };
17
17
  export type ConstantFieldKind = "property" | "hidden" | "secret" | "resolve";
18
18
  export interface ConstantFieldProps<FieldType extends ConstantFieldKind = ConstantFieldKind, FieldValue = any, MapValue = any, Metadata = {
@@ -144,8 +144,8 @@ export type PlainTypeToFieldType<PlainType> = PlainType extends [infer First, ..
144
144
  /** Builds a stored property field with optional validation, default, ref, text, and metadata options. */
145
145
  export declare const field: {
146
146
  <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"property", Value, ExplicitType, MapValue>;
147
- hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"hidden", Value, ExplicitType, MapValue>;
148
- secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"secret", Value, ExplicitType, MapValue>;
147
+ hidden<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"hidden", Value | null, ExplicitType | null, MapValue>;
148
+ secret<ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>): FieldInfo<"secret", Value | null, ExplicitType | null, MapValue>;
149
149
  };
150
150
  /** Builds a resolved field that is derived rather than treated as a stored property. */
151
151
  export declare const resolve: <ExplicitType, Value extends ConstantFieldTypeInput = PlainTypeToFieldType<ExplicitType>, MapValue = Value extends MapConstructor ? typeof PrimitiveScalar : never>(value: Value, option?: FieldOption<Value, MapValue>) => FieldInfo<"resolve", Value, ExplicitType, MapValue>;
@@ -1,5 +1,5 @@
1
1
  import { type Cls, type EnumInstance, FIELD_META, type MergeAllKeyOfObjects, type MergeAllTypes } from "akanjs/base";
2
- import { type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, type FieldInfoObjectToFieldObject, type FieldObject, type FieldResolver } from "./fieldInfo.d.ts";
2
+ import { ConstantField, type ExtractFieldInfoObject, type FieldBuilder, type FieldInfoObject, type FieldInfoObjectToFieldObject, type FieldObject, type FieldResolver } from "./fieldInfo.d.ts";
3
3
  import { type PurifyFunc } from "./purify.d.ts";
4
4
  import type { BaseInsight, BaseObject, ConstantType, DefaultOf, NonFunctionalKeys } from "./types.d.ts";
5
5
  type BaseFields = "id" | "createdAt" | "updatedAt" | "removedAt";
@@ -23,6 +23,9 @@ export interface ConstantStatics<Schema = any, FieldObj extends FieldObject = Fi
23
23
  filter: Set<string>;
24
24
  };
25
25
  };
26
+ _DatabaseSchema: {
27
+ [K in keyof Schema]: K extends keyof FieldObj ? FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any> ? FieldType extends "hidden" ? NonNullable<Schema[K]> : Schema[K] : Schema[K] : Schema[K];
28
+ };
26
29
  }
27
30
  export type ConstantCls<Schema = any, FieldObj extends FieldObject = FieldObject> = (new (obj?: Partial<Schema>) => Schema & ConstantMethods<Schema>) & ConstantStatics<Schema, FieldObj>;
28
31
  declare global {
@@ -1,5 +1,5 @@
1
1
  import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
2
- import { type BaseObject, type ConstantCls, type ConstantField, type DocumentModel, type FieldObject } from "akanjs/constant";
2
+ import { type BaseObject, type DocumentModel, type FieldObject } from "akanjs/constant";
3
3
  export type DatabaseCls<Schema = any> = Cls<Schema, {
4
4
  refName: string;
5
5
  [FIELD_META]: FieldObject;
@@ -16,5 +16,7 @@ type HydratedDocumentWithId<TDocument> = TDocument & {
16
16
  id: string;
17
17
  } & DefaultDocMtds<TDocument>;
18
18
  export type Doc<M = any> = HydratedDocumentWithId<DocumentModel<M>>;
19
- export declare const by: <Schema, FieldObj extends FieldObject, AddDbModels extends DatabaseCls[], _DatabaseSchema = Schema & { [K in keyof FieldObj & keyof Schema as FieldObj[K] extends ConstantField<infer FieldType, any, any, any, any, any> ? FieldType extends "hidden" ? K : never : never]: NonNullable<Schema[K]>; }, _DocModel = Schema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>>(modelRef: ConstantCls<Schema, FieldObj>, ...addRefs: AddDbModels) => DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel>;
19
+ export declare const by: <ModelCls, AddDbModels extends DatabaseCls[], _DatabaseSchema = ModelCls extends {
20
+ _DatabaseSchema: infer Schema;
21
+ } ? Schema : never, _DocModel = _DatabaseSchema extends BaseObject ? Doc<_DatabaseSchema> : DocumentModel<_DatabaseSchema>>(modelRef: ModelCls, ...addRefs: AddDbModels) => DatabaseCls<MergeAllActionTypes<AddDbModels, keyof _DocModel & string> & _DocModel>;
20
22
  export {};
package/ui/Field.tsx CHANGED
@@ -1345,10 +1345,7 @@ const ParentId = <T extends string, State, Input, Full extends { id: string }, L
1345
1345
  labelClassName={labelClassName}
1346
1346
  selectClassName={selectClassName}
1347
1347
  value={value}
1348
- options={modelList.map((model) => {
1349
- const label = renderOption?.(model) ?? model.id;
1350
- return { label: typeof label === "string" ? label : model.id, value: model.id };
1351
- })}
1348
+ options={modelList.map((model) => model.id)}
1352
1349
  renderOption={(renderId) => {
1353
1350
  if (!renderId) return null;
1354
1351
  const model = modelList.get(renderId);