akanjs 2.3.2-rc.1 → 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.
- package/constant/constantRegistry.ts +1 -1
- package/constant/via.ts +9 -0
- package/document/by.ts +4 -12
- package/package.json +1 -1
- package/types/constant/via.d.ts +4 -1
- package/types/document/by.d.ts +4 -2
|
@@ -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))
|
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
|
-
|
|
27
|
-
FieldObj extends FieldObject,
|
|
25
|
+
ModelCls,
|
|
28
26
|
AddDbModels extends DatabaseCls[],
|
|
29
|
-
_DatabaseSchema = Schema
|
|
30
|
-
|
|
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:
|
|
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
package/types/constant/via.d.ts
CHANGED
|
@@ -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 {
|
package/types/document/by.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Cls, FIELD_META, type MergeAllActionTypes } from "akanjs/base";
|
|
2
|
-
import { type BaseObject, type
|
|
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: <
|
|
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 {};
|