@candlerip/shared3 0.0.150 → 0.0.151

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/package.json +1 -1
  2. package/src/backend/api/api-response/index.d.ts +1 -0
  3. package/src/backend/api/api-response/index.js +1 -0
  4. package/src/backend/api/api-response/persons-map/compose-persons-map-page-api-response/index.d.ts +2 -0
  5. package/src/backend/api/api-response/persons-map/compose-persons-map-page-api-response/index.js +22 -0
  6. package/src/backend/api/api-response/persons-map/compose-persons-map-page-api-response/type.d.ts +10 -0
  7. package/src/backend/api/api-response/persons-map/compose-persons-map-page-api-response/type.js +1 -0
  8. package/src/backend/api/api-response/persons-map/index.d.ts +2 -0
  9. package/src/backend/api/api-response/persons-map/index.js +2 -0
  10. package/src/backend/api/api-response/persons-map/type.d.ts +6 -0
  11. package/src/backend/api/api-response/persons-map/type.js +1 -0
  12. package/src/backend/cache/cache/config.d.ts +2 -0
  13. package/src/backend/cache/cache/config.js +2 -0
  14. package/src/backend/cache/cache/type.d.ts +2 -1
  15. package/src/backend/database/aggregate/country-persons-count-aggregate/index.d.ts +2 -0
  16. package/src/backend/database/aggregate/country-persons-count-aggregate/index.js +27 -0
  17. package/src/backend/database/aggregate/index.d.ts +1 -0
  18. package/src/backend/database/aggregate/index.js +1 -0
  19. package/src/backend/database/model/country/country-db-schema.d.ts +48 -0
  20. package/src/backend/database/model/country/country-db-schema.js +31 -0
  21. package/src/backend/database/model/country/get-country-db-model.d.ts +2 -0
  22. package/src/backend/database/model/country/get-country-db-model.js +3 -0
  23. package/src/backend/database/model/country/index.d.ts +2 -0
  24. package/src/backend/database/model/country/index.js +2 -0
  25. package/src/backend/database/model/index.d.ts +1 -0
  26. package/src/backend/database/model/index.js +1 -0
  27. package/src/backend/database/mutation/candle/get-candles/type.d.ts +9 -4
  28. package/src/backend/database/mutation/country/get-countries/index.d.ts +2 -0
  29. package/src/backend/database/mutation/country/get-countries/index.js +30 -0
  30. package/src/backend/database/mutation/country/get-countries/type.d.ts +16 -0
  31. package/src/backend/database/mutation/country/get-countries/type.js +1 -0
  32. package/src/backend/database/mutation/country/get-country/index.d.ts +2 -0
  33. package/src/backend/database/mutation/country/get-country/index.js +33 -0
  34. package/src/backend/database/mutation/country/get-country/type.d.ts +17 -0
  35. package/src/backend/database/mutation/country/get-country/type.js +1 -0
  36. package/src/backend/database/mutation/country/index.d.ts +2 -0
  37. package/src/backend/database/mutation/country/index.js +2 -0
  38. package/src/backend/database/mutation/index.d.ts +1 -0
  39. package/src/backend/database/mutation/index.js +1 -0
  40. package/src/backend/page/page-data/index.d.ts +1 -0
  41. package/src/backend/page/page-data/index.js +1 -0
  42. package/src/backend/page/page-data/persons-map/compose-persons-map-page-data/index.d.ts +2 -0
  43. package/src/backend/page/page-data/persons-map/compose-persons-map-page-data/index.js +15 -0
  44. package/src/backend/page/page-data/persons-map/compose-persons-map-page-data/type.d.ts +7 -0
  45. package/src/backend/page/page-data/persons-map/compose-persons-map-page-data/type.js +1 -0
  46. package/src/backend/page/page-data/persons-map/index.d.ts +2 -0
  47. package/src/backend/page/page-data/persons-map/index.js +2 -0
  48. package/src/backend/page/page-data/persons-map/type.d.ts +8 -0
  49. package/src/backend/page/page-data/persons-map/type.js +1 -0
  50. package/src/geographical/country/index.d.ts +1 -0
  51. package/src/geographical/country/index.js +1 -0
  52. package/src/geographical/country/type.d.ts +13 -0
  53. package/src/geographical/country/type.js +1 -0
  54. package/src/geographical/index.d.ts +1 -0
  55. package/src/geographical/index.js +1 -0
  56. package/src/type/index.d.ts +1 -0
  57. package/src/type/index.js +1 -0
  58. package/src/type/number/index.d.ts +1 -0
  59. package/src/type/number/index.js +1 -0
  60. package/src/type/number/type-guard.d.ts +1 -0
  61. package/src/type/number/type-guard.js +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.150",
3
+ "version": "0.0.151",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.js",
@@ -1 +1,2 @@
1
1
  export * from './candles/index.js';
2
+ export * from './persons-map/index.js';
@@ -1 +1,2 @@
1
1
  export * from './candles/index.js';
2
+ export * from './persons-map/index.js';
@@ -0,0 +1,2 @@
1
+ import { ComposePersonsMapPageApiResponse } from './type.js';
2
+ export declare const composePersonsMapPageApiResponse: ComposePersonsMapPageApiResponse;
@@ -0,0 +1,22 @@
1
+ import { DICTIONARY_CONFIG } from '../../../../../dictionary/index.js';
2
+ import { getTranslationsAsDictionary } from '../../../../database/index.js';
3
+ import { composePersonsMapPageData } from '../../../../page/index.js';
4
+ export const composePersonsMapPageApiResponse = async ({ language }) => {
5
+ let resp;
6
+ resp = await getTranslationsAsDictionary(language, DICTIONARY_CONFIG['persons-map-page'].translationIds);
7
+ if ('customError' in resp) {
8
+ return resp;
9
+ }
10
+ const dictionary = resp.data;
11
+ resp = await composePersonsMapPageData();
12
+ if ('customError' in resp) {
13
+ return resp;
14
+ }
15
+ const pageData = resp.data;
16
+ return {
17
+ data: {
18
+ dictionary,
19
+ pageData,
20
+ },
21
+ };
22
+ };
@@ -0,0 +1,10 @@
1
+ import { Language } from '../../../../../dictionary/index.js';
2
+ import { CustomError } from '../../../../../error/index.js';
3
+ import { PersonsMapPageApiResponse } from '../type.js';
4
+ export type ComposePersonsMapPageApiResponse = (props: {
5
+ language: Language;
6
+ }) => Promise<{
7
+ data: PersonsMapPageApiResponse;
8
+ } | {
9
+ customError: CustomError;
10
+ }>;
@@ -0,0 +1,2 @@
1
+ export * from './compose-persons-map-page-api-response/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,2 @@
1
+ export * from './compose-persons-map-page-api-response/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,6 @@
1
+ import { Dictionary } from '../../../../dictionary/index.js';
2
+ import { PersonsMapPageData } from '../../../page/index.js';
3
+ export interface PersonsMapPageApiResponse {
4
+ dictionary: Dictionary;
5
+ pageData: PersonsMapPageData;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -27,6 +27,8 @@ export declare const CACHE: {
27
27
  readonly 'person-details-page-dictionary-hu': "Dictionary";
28
28
  readonly 'persons-page-dictionary-en': "Dictionary";
29
29
  readonly 'persons-page-dictionary-hu': "Dictionary";
30
+ readonly 'persons-map-page-api-response-en': "PersonsMapPageApiResponse";
31
+ readonly 'persons-map-page-api-response-hu': "PersonsMapPageApiResponse";
30
32
  readonly 'persons-map-page-dictionary-en': "Dictionary";
31
33
  readonly 'persons-map-page-dictionary-hu': "Dictionary";
32
34
  readonly 'terms-and-conditions-page-dictionary-en': "Dictionary";
@@ -27,6 +27,8 @@ export const CACHE = {
27
27
  'person-details-page-dictionary-hu': 'Dictionary',
28
28
  'persons-page-dictionary-en': 'Dictionary',
29
29
  'persons-page-dictionary-hu': 'Dictionary',
30
+ 'persons-map-page-api-response-en': 'PersonsMapPageApiResponse',
31
+ 'persons-map-page-api-response-hu': 'PersonsMapPageApiResponse',
30
32
  'persons-map-page-dictionary-en': 'Dictionary',
31
33
  'persons-map-page-dictionary-hu': 'Dictionary',
32
34
  'terms-and-conditions-page-dictionary-en': 'Dictionary',
@@ -1,5 +1,5 @@
1
1
  import { Dictionary } from '../../../dictionary/index.js';
2
- import { CandlesPageApiResponse } from '../../api/index.js';
2
+ import { CandlesPageApiResponse, PersonsMapPageApiResponse } from '../../api/index.js';
3
3
  import { CACHE } from './config.js';
4
4
  export type Cache = {
5
5
  [key in keyof typeof CACHE]: TypeMap[(typeof CACHE)[key]];
@@ -7,5 +7,6 @@ export type Cache = {
7
7
  interface TypeMap {
8
8
  CandlesPageApiResponse: CandlesPageApiResponse;
9
9
  Dictionary: Dictionary;
10
+ PersonsMapPageApiResponse: PersonsMapPageApiResponse;
10
11
  }
11
12
  export {};
@@ -0,0 +1,2 @@
1
+ import { PipelineStage } from 'mongoose';
2
+ export declare const COUNTRY_PERSONS_COUNT_AGGREGATE: PipelineStage[];
@@ -0,0 +1,27 @@
1
+ export const COUNTRY_PERSONS_COUNT_AGGREGATE = [
2
+ {
3
+ $lookup: {
4
+ from: 'persons',
5
+ localField: 'code',
6
+ foreignField: 'birth.place.countryCode',
7
+ as: 'persons',
8
+ },
9
+ },
10
+ {
11
+ $addFields: {
12
+ personsCount: {
13
+ $size: '$persons',
14
+ },
15
+ },
16
+ },
17
+ {
18
+ $match: {
19
+ personsCount: {
20
+ $ne: 0,
21
+ },
22
+ },
23
+ },
24
+ {
25
+ $unset: 'persons',
26
+ },
27
+ ];
@@ -1 +1,2 @@
1
1
  export * from './candle-person/index.js';
2
+ export * from './country-persons-count-aggregate/index.js';
@@ -1 +1,2 @@
1
1
  export * from './candle-person/index.js';
2
+ export * from './country-persons-count-aggregate/index.js';
@@ -0,0 +1,48 @@
1
+ import * as mongoose from 'mongoose';
2
+ export declare const CountryDbSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
3
+ timestamps: true;
4
+ versionKey: false;
5
+ }, {
6
+ createdAt: NativeDate;
7
+ updatedAt: NativeDate;
8
+ } & {
9
+ code: string;
10
+ location?: {
11
+ type: "Point";
12
+ coordinates: number[];
13
+ } | null | undefined;
14
+ translation?: {
15
+ en: string;
16
+ hu: string;
17
+ } | null | undefined;
18
+ }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
19
+ createdAt: NativeDate;
20
+ updatedAt: NativeDate;
21
+ } & {
22
+ code: string;
23
+ location?: {
24
+ type: "Point";
25
+ coordinates: number[];
26
+ } | null | undefined;
27
+ translation?: {
28
+ en: string;
29
+ hu: string;
30
+ } | null | undefined;
31
+ }>> & mongoose.FlatRecord<{
32
+ createdAt: NativeDate;
33
+ updatedAt: NativeDate;
34
+ } & {
35
+ code: string;
36
+ location?: {
37
+ type: "Point";
38
+ coordinates: number[];
39
+ } | null | undefined;
40
+ translation?: {
41
+ en: string;
42
+ hu: string;
43
+ } | null | undefined;
44
+ }> & {
45
+ _id: mongoose.Types.ObjectId;
46
+ } & {
47
+ __v: number;
48
+ }>;
@@ -0,0 +1,31 @@
1
+ import * as mongoose from 'mongoose';
2
+ export const CountryDbSchema = new mongoose.Schema({
3
+ code: {
4
+ required: true,
5
+ type: String,
6
+ },
7
+ location: {
8
+ coordinates: {
9
+ type: [Number],
10
+ required: true,
11
+ },
12
+ type: {
13
+ type: String,
14
+ enum: ['Point'],
15
+ required: true,
16
+ },
17
+ },
18
+ translation: {
19
+ en: {
20
+ required: true,
21
+ type: String,
22
+ },
23
+ hu: {
24
+ required: true,
25
+ type: String,
26
+ },
27
+ },
28
+ }, {
29
+ timestamps: true,
30
+ versionKey: false,
31
+ });
@@ -0,0 +1,2 @@
1
+ import * as mongoose from 'mongoose';
2
+ export declare const getCountryDbModel: () => mongoose.Model<any, {}, {}, {}, any, any>;
@@ -0,0 +1,3 @@
1
+ import * as mongoose from 'mongoose';
2
+ import { CountryDbSchema } from './country-db-schema.js';
3
+ export const getCountryDbModel = () => mongoose.models?.countries || mongoose.model('countries', CountryDbSchema);
@@ -0,0 +1,2 @@
1
+ export * from './country-db-schema.js';
2
+ export * from './get-country-db-model.js';
@@ -0,0 +1,2 @@
1
+ export * from './country-db-schema.js';
2
+ export * from './get-country-db-model.js';
@@ -1,3 +1,4 @@
1
1
  export * from './candle/index.js';
2
+ export * from './country/index.js';
2
3
  export * from './error-log/index.js';
3
4
  export * from './translation/index.js';
@@ -1,3 +1,4 @@
1
1
  export * from './candle/index.js';
2
+ export * from './country/index.js';
2
3
  export * from './error-log/index.js';
3
4
  export * from './translation/index.js';
@@ -2,16 +2,21 @@ import { Candle } from '../../../../../candle/index.js';
2
2
  import { CustomError } from '../../../../../error/index.js';
3
3
  import { CandleFilterSort } from '../../../../../filter-sort/index.js';
4
4
  import { Person } from '../../../../../person/index.js';
5
- export type GetCandles = <T extends Candle | (Candle & {
6
- person?: Person;
7
- }) = never>(props: {
5
+ export type GetCandles = <T extends keyof TypeMap = never>(props: {
8
6
  filterSort: CandleFilterSort;
9
7
  withPerson?: boolean;
10
8
  }) => Promise<{
11
9
  data: {
12
- candles: T[];
10
+ candles: TypeMap[T];
13
11
  candlesCount: number;
14
12
  };
15
13
  } | {
16
14
  customError: CustomError;
17
15
  }>;
16
+ type TypeMap = {
17
+ candle: Candle[];
18
+ candleWithPerson: Array<Candle & {
19
+ person?: Person;
20
+ }>;
21
+ };
22
+ export {};
@@ -0,0 +1,2 @@
1
+ import { GetCountries } from './type.js';
2
+ export declare const getCountries: GetCountries;
@@ -0,0 +1,30 @@
1
+ import { COUNTRY_PERSONS_COUNT_AGGREGATE } from '../../../aggregate/index.js';
2
+ import { customErrorWorker } from '@candlerip/shared3';
3
+ import { getCountryDbModel } from '../../../model/index.js';
4
+ export const getCountries = async (props) => {
5
+ const { composeCustomError } = customErrorWorker(props);
6
+ const aggregates = [];
7
+ if (props) {
8
+ const { withPersonsCount } = props;
9
+ if (withPersonsCount) {
10
+ aggregates.push(...COUNTRY_PERSONS_COUNT_AGGREGATE);
11
+ }
12
+ }
13
+ let data;
14
+ try {
15
+ if (aggregates.length > 0) {
16
+ data = await getCountryDbModel().aggregate(aggregates);
17
+ }
18
+ else {
19
+ data = await getCountryDbModel().find();
20
+ }
21
+ }
22
+ catch (err) {
23
+ return {
24
+ customError: composeCustomError('Get countries failed', { err }),
25
+ };
26
+ }
27
+ return {
28
+ data,
29
+ };
30
+ };
@@ -0,0 +1,16 @@
1
+ import { Country } from '../../../../../geographical/index.js';
2
+ import { CustomError } from '../../../../../error/index.js';
3
+ export type GetCountries = <T extends keyof TypeMap = never>(props?: {
4
+ withPersonsCount?: boolean;
5
+ }) => Promise<{
6
+ data: TypeMap[T];
7
+ } | {
8
+ customError: CustomError;
9
+ }>;
10
+ type TypeMap = {
11
+ countries: Country[] | null;
12
+ countriesWithPersonsCount: Array<Country & {
13
+ personsCount: number;
14
+ }>;
15
+ };
16
+ export {};
@@ -0,0 +1,2 @@
1
+ import { GetCountry } from './type.js';
2
+ export declare const getCountry: GetCountry;
@@ -0,0 +1,33 @@
1
+ import { COUNTRY_PERSONS_COUNT_AGGREGATE } from '../../../aggregate/index.js';
2
+ import { getCountryDbModel } from '../../../model/index.js';
3
+ import { customErrorWorker } from '../../../../../error/index.js';
4
+ export const getCountry = async (props) => {
5
+ const aggregates = [];
6
+ const { code, withPersonsCount } = props;
7
+ const { composeCustomError } = customErrorWorker(props);
8
+ aggregates.push({
9
+ $match: {
10
+ code,
11
+ },
12
+ });
13
+ if (withPersonsCount) {
14
+ aggregates.push(...COUNTRY_PERSONS_COUNT_AGGREGATE);
15
+ }
16
+ let data;
17
+ try {
18
+ data = await getCountryDbModel().aggregate(aggregates);
19
+ }
20
+ catch (err) {
21
+ return {
22
+ customError: composeCustomError('Get countries failed', { err }),
23
+ };
24
+ }
25
+ if (!data || data.length === 0) {
26
+ return {
27
+ data: null,
28
+ };
29
+ }
30
+ return {
31
+ data: data[0],
32
+ };
33
+ };
@@ -0,0 +1,17 @@
1
+ import { Country, CountryCode } from '../../../../../geographical/index.js';
2
+ import { CustomError } from '../../../../../error/index.js';
3
+ export type GetCountry = <T extends keyof TypeMap = never>(props: {
4
+ code: CountryCode;
5
+ withPersonsCount?: boolean;
6
+ }) => Promise<{
7
+ data: TypeMap[T];
8
+ } | {
9
+ customError: CustomError;
10
+ }>;
11
+ type TypeMap = {
12
+ country: Country | null;
13
+ countryWithPersonsCount: (Country & {
14
+ personsCount: number;
15
+ }) | null;
16
+ };
17
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './get-country/index.js';
2
+ export * from './get-countries/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './get-country/index.js';
2
+ export * from './get-countries/index.js';
@@ -1,3 +1,4 @@
1
1
  export * from './candle/index.js';
2
+ export * from './country/index.js';
2
3
  export * from './error-log/index.js';
3
4
  export * from './translation/index.js';
@@ -1,3 +1,4 @@
1
1
  export * from './candle/index.js';
2
+ export * from './country/index.js';
2
3
  export * from './error-log/index.js';
3
4
  export * from './translation/index.js';
@@ -1 +1,2 @@
1
1
  export * from './candles/index.js';
2
+ export * from './persons-map/index.js';
@@ -1 +1,2 @@
1
1
  export * from './candles/index.js';
2
+ export * from './persons-map/index.js';
@@ -0,0 +1,2 @@
1
+ import { ComposePersonsMapPageData } from './type.js';
2
+ export declare const composePersonsMapPageData: ComposePersonsMapPageData;
@@ -0,0 +1,15 @@
1
+ import { getCountries } from '../../../../database/index.js';
2
+ export const composePersonsMapPageData = async () => {
3
+ const resp = await getCountries({ withPersonsCount: true });
4
+ if ('customError' in resp) {
5
+ return resp;
6
+ }
7
+ const { data: countries } = resp;
8
+ return {
9
+ data: {
10
+ map: {
11
+ countries,
12
+ },
13
+ },
14
+ };
15
+ };
@@ -0,0 +1,7 @@
1
+ import { CustomError } from '../../../../../error/index.js';
2
+ import { PersonsMapPageData } from '../type.js';
3
+ export type ComposePersonsMapPageData = () => Promise<{
4
+ data: PersonsMapPageData;
5
+ } | {
6
+ customError: CustomError;
7
+ }>;
@@ -0,0 +1,2 @@
1
+ export * from './compose-persons-map-page-data/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,2 @@
1
+ export * from './compose-persons-map-page-data/index.js';
2
+ export * from './type.js';
@@ -0,0 +1,8 @@
1
+ import { Country } from '../../../../geographical/index.js';
2
+ export interface PersonsMapPageData {
3
+ map: {
4
+ countries: Array<Country & {
5
+ personsCount: number;
6
+ }>;
7
+ };
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './type.js';
@@ -0,0 +1 @@
1
+ export * from './type.js';
@@ -0,0 +1,13 @@
1
+ import { CountryCode } from '../county-code/index.js';
2
+ export interface Country {
3
+ _id: string;
4
+ code: CountryCode;
5
+ location: {
6
+ coordinates: number[];
7
+ type: 'Point';
8
+ };
9
+ translation: {
10
+ en: string;
11
+ hu: string;
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,2 @@
1
+ export * from './country/index.js';
1
2
  export * from './county-code/index.js';
@@ -1 +1,2 @@
1
+ export * from './country/index.js';
1
2
  export * from './county-code/index.js';
@@ -1,4 +1,5 @@
1
1
  export * from './array/index.js';
2
+ export * from './number/index.js';
2
3
  export * from './object/index.js';
3
4
  export * from './readonly/index.js';
4
5
  export * from './string/index.js';
package/src/type/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './array/index.js';
2
+ export * from './number/index.js';
2
3
  export * from './object/index.js';
3
4
  export * from './readonly/index.js';
4
5
  export * from './string/index.js';
@@ -0,0 +1 @@
1
+ export * from './type-guard.js';
@@ -0,0 +1 @@
1
+ export * from './type-guard.js';
@@ -0,0 +1 @@
1
+ export declare const isNumber: (data?: unknown) => data is number;
@@ -0,0 +1 @@
1
+ export const isNumber = (data) => typeof data === 'number';