tsondb 0.7.0 → 0.7.1

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.
@@ -1,7 +1,6 @@
1
- import type { DisplayNameResult } from "../../../shared/utils/displayName.ts";
2
1
  import { Lazy } from "../../../shared/utils/lazy.ts";
3
2
  import type { Leaves } from "../../../shared/utils/object.ts";
4
- import type { GetChildInstancesForInstanceId } from "../../utils/displayName.ts";
3
+ import type { DisplayNameCustomizer } from "../../utils/displayName.ts";
5
4
  import type { GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, Validator } from "../Node.ts";
6
5
  import { NodeKind } from "../Node.ts";
7
6
  import type { MemberDecl, ObjectType } from "../types/generic/ObjectType.ts";
@@ -13,15 +12,6 @@ export type GenericEntityDisplayName = string | {
13
12
  pathToLocaleMap?: string;
14
13
  pathInLocaleMap?: string;
15
14
  } | null;
16
- export type DisplayNameFn<T extends ObjectType = ObjectType> = (params: {
17
- instance: AsType<T>;
18
- instanceDisplayName: string;
19
- instanceDisplayNameLocaleId: string | undefined;
20
- locales: string[];
21
- getInstanceById: (id: string) => unknown;
22
- getDisplayNameForInstanceId: (id: string) => string | undefined;
23
- getChildInstancesForInstanceId: GetChildInstancesForInstanceId;
24
- }) => DisplayNameResult;
25
15
  export type EntityDisplayName<T extends TConstraint> = Leaves<AsType<ObjectType<T>>> | {
26
16
  /**
27
17
  * @default "translations"
@@ -42,7 +32,7 @@ export interface EntityDecl<Name extends string = string, T extends TConstraint
42
32
  * @default "name"
43
33
  */
44
34
  displayName?: EntityDisplayName<T>;
45
- displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
35
+ displayNameCustomizer?: DisplayNameCustomizer<ObjectType<T>>;
46
36
  isDeprecated?: boolean;
47
37
  }
48
38
  export interface EntityDeclWithParentReference<Name extends string = string, T extends TConstraint = TConstraint, FK extends keyof T & string = keyof T & string> extends EntityDecl<Name, T, FK> {
@@ -57,7 +47,7 @@ export declare const EntityDecl: {
57
47
  * @default "name"
58
48
  */
59
49
  displayName?: EntityDisplayName<T>;
60
- displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
50
+ displayNameCustomizer?: DisplayNameCustomizer<ObjectType<T>>;
61
51
  isDeprecated?: boolean;
62
52
  }): EntityDecl<Name, T, undefined>;
63
53
  <Name extends string, T extends TConstraint, FK extends keyof T & string>(sourceUrl: string, options: {
@@ -70,7 +60,7 @@ export declare const EntityDecl: {
70
60
  * @default "name"
71
61
  */
72
62
  displayName?: EntityDisplayName<T>;
73
- displayNameCustomizer?: DisplayNameFn<ObjectType<T>>;
63
+ displayNameCustomizer?: DisplayNameCustomizer<ObjectType<T>>;
74
64
  isDeprecated?: boolean;
75
65
  }): EntityDecl<Name, T, FK>;
76
66
  };
@@ -18,7 +18,7 @@ instancesApi.get("/", (req, res) => {
18
18
  instances.map(instance => {
19
19
  const { name, localeId } = getDisplayNameFromEntityInstance(
20
20
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
21
- req.entitiesByName[entityName], instance.content, req.getInstanceById, getChildInstancesForInstanceId, req.locales);
21
+ req.entitiesByName[entityName], instance, req.getInstanceById, getChildInstancesForInstanceId, req.locales);
22
22
  return {
23
23
  id: instance.id,
24
24
  name,
@@ -1,5 +1,17 @@
1
- import { type EntityDecl } from "../../node/schema/index.ts";
2
1
  import type { GetInstanceById } from "../../node/server/index.ts";
3
2
  import { type DisplayNameResult } from "../../shared/utils/displayName.ts";
3
+ import type { InstanceContainer } from "../../shared/utils/instances.ts";
4
+ import { type EntityDecl } from "../schema/declarations/EntityDecl.ts";
5
+ import type { AsType, Type } from "../schema/types/Type.ts";
4
6
  export type GetChildInstancesForInstanceId = (parentEntityName: string, parentId: string, childEntityName: string) => unknown[];
5
- export declare const getDisplayNameFromEntityInstance: (entity: EntityDecl, instance: unknown, getInstanceById: GetInstanceById, getChildInstancesForInstanceId: GetChildInstancesForInstanceId, locales: string[], defaultName?: string, useCustomizer?: boolean) => DisplayNameResult;
7
+ export type DisplayNameCustomizer<T extends Type> = (params: {
8
+ instance: AsType<T>;
9
+ instanceId: string;
10
+ instanceDisplayName: string;
11
+ instanceDisplayNameLocaleId: string | undefined;
12
+ locales: string[];
13
+ getInstanceById: (id: string) => unknown;
14
+ getDisplayNameForInstanceId: (id: string) => string | undefined;
15
+ getChildInstancesForInstanceId: GetChildInstancesForInstanceId;
16
+ }) => DisplayNameResult;
17
+ export declare const getDisplayNameFromEntityInstance: (entity: EntityDecl, instanceContainer: InstanceContainer, getInstanceById: GetInstanceById, getChildInstancesForInstanceId: GetChildInstancesForInstanceId, locales: string[], defaultName?: string, useCustomizer?: boolean) => DisplayNameResult;
@@ -1,10 +1,11 @@
1
- import { serializeEntityDecl } from "../../node/schema/index.js";
2
1
  import { getSerializedDisplayNameFromEntityInstance, } from "../../shared/utils/displayName.js";
3
- export const getDisplayNameFromEntityInstance = (entity, instance, getInstanceById, getChildInstancesForInstanceId, locales, defaultName = "", useCustomizer = true) => {
2
+ import { serializeEntityDecl } from "../schema/declarations/EntityDecl.js";
3
+ export const getDisplayNameFromEntityInstance = (entity, instanceContainer, getInstanceById, getChildInstancesForInstanceId, locales, defaultName = "", useCustomizer = true) => {
4
4
  if (useCustomizer && entity.displayNameCustomizer) {
5
- const calculatedName = getDisplayNameFromEntityInstance(entity, instance, getInstanceById, getChildInstancesForInstanceId, locales, defaultName, false);
5
+ const calculatedName = getDisplayNameFromEntityInstance(entity, instanceContainer, getInstanceById, getChildInstancesForInstanceId, locales, defaultName, false);
6
6
  return entity.displayNameCustomizer({
7
- instance: instance,
7
+ instance: instanceContainer.content,
8
+ instanceId: instanceContainer.id,
8
9
  instanceDisplayName: calculatedName.name,
9
10
  instanceDisplayNameLocaleId: calculatedName.localeId,
10
11
  locales,
@@ -13,7 +14,7 @@ export const getDisplayNameFromEntityInstance = (entity, instance, getInstanceBy
13
14
  const result = getInstanceById(id);
14
15
  if (result) {
15
16
  const { entity, instance } = result;
16
- return getDisplayNameFromEntityInstance(entity, instance.content, getInstanceById, getChildInstancesForInstanceId, locales, id).name;
17
+ return getDisplayNameFromEntityInstance(entity, instance, getInstanceById, getChildInstancesForInstanceId, locales, id).name;
17
18
  }
18
19
  else {
19
20
  return undefined;
@@ -23,6 +24,6 @@ export const getDisplayNameFromEntityInstance = (entity, instance, getInstanceBy
23
24
  });
24
25
  }
25
26
  else {
26
- return getSerializedDisplayNameFromEntityInstance(serializeEntityDecl(entity), instance, defaultName, locales);
27
+ return getSerializedDisplayNameFromEntityInstance(serializeEntityDecl(entity), instanceContainer.content, defaultName, locales);
27
28
  }
28
29
  };
@@ -1,7 +1,7 @@
1
1
  import { getDisplayNameFromEntityInstance, } from "../../node/utils/displayName.js";
2
2
  export const getInstanceContainerOverview = (entity, instanceContainer, getInstanceById, getChildInstancesForInstanceId, locales) => {
3
3
  const { content: _, ...rest } = instanceContainer;
4
- const { name: displayName, localeId: displayNameLocaleId } = getDisplayNameFromEntityInstance(entity, instanceContainer.content, getInstanceById, getChildInstancesForInstanceId, locales);
4
+ const { name: displayName, localeId: displayNameLocaleId } = getDisplayNameFromEntityInstance(entity, instanceContainer, getInstanceById, getChildInstancesForInstanceId, locales);
5
5
  return {
6
6
  ...rest,
7
7
  displayName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsondb",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "Lukas Obermann",