@sneat/dto 0.1.3 → 0.1.6

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.
Files changed (90) hide show
  1. package/esm2022/index.js +2 -0
  2. package/esm2022/index.js.map +1 -0
  3. package/esm2022/lib/by-user.js +2 -0
  4. package/esm2022/lib/by-user.js.map +1 -0
  5. package/esm2022/lib/dto-app.js +2 -0
  6. package/esm2022/lib/dto-app.js.map +1 -0
  7. package/esm2022/lib/dto-brief.js +2 -0
  8. package/esm2022/lib/dto-brief.js.map +1 -0
  9. package/esm2022/lib/dto-commune.js +89 -0
  10. package/esm2022/lib/dto-commune.js.map +1 -0
  11. package/{src/lib/dto-constants.ts → esm2022/lib/dto-constants.js} +1 -0
  12. package/esm2022/lib/dto-constants.js.map +1 -0
  13. package/esm2022/lib/dto-models.js +23 -0
  14. package/esm2022/lib/dto-models.js.map +1 -0
  15. package/esm2022/lib/dto-pricing.js +2 -0
  16. package/esm2022/lib/dto-pricing.js.map +1 -0
  17. package/esm2022/lib/dto-team-brief.js +9 -0
  18. package/esm2022/lib/dto-team-brief.js.map +1 -0
  19. package/esm2022/lib/dto-team-info.js +4 -0
  20. package/esm2022/lib/dto-team-info.js.map +1 -0
  21. package/esm2022/lib/dto-team-meeting.js +2 -0
  22. package/esm2022/lib/dto-team-meeting.js.map +1 -0
  23. package/esm2022/lib/dto-team-metric.js +2 -0
  24. package/esm2022/lib/dto-team-metric.js.map +1 -0
  25. package/esm2022/lib/dto-team.js +2 -0
  26. package/esm2022/lib/dto-team.js.map +1 -0
  27. package/esm2022/lib/dto-user.js +33 -0
  28. package/esm2022/lib/dto-user.js.map +1 -0
  29. package/esm2022/lib/dto-with-modified.js +2 -0
  30. package/esm2022/lib/dto-with-modified.js.map +1 -0
  31. package/esm2022/lib/index.js +19 -0
  32. package/esm2022/lib/index.js.map +1 -0
  33. package/esm2022/lib/period.js +2 -0
  34. package/esm2022/lib/period.js.map +1 -0
  35. package/esm2022/lib/types.js +2 -0
  36. package/esm2022/lib/types.js.map +1 -0
  37. package/esm2022/lib/ui-state.js +2 -0
  38. package/esm2022/lib/ui-state.js.map +1 -0
  39. package/esm2022/lib/with-related.js +94 -0
  40. package/esm2022/lib/with-related.js.map +1 -0
  41. package/esm2022/sneat-dto.js +5 -0
  42. package/esm2022/sneat-dto.js.map +1 -0
  43. package/lib/by-user.d.ts +4 -0
  44. package/lib/dto-app.d.ts +6 -0
  45. package/{src/lib/dto-brief.ts → lib/dto-brief.d.ts} +2 -2
  46. package/lib/dto-commune.d.ts +53 -0
  47. package/lib/dto-constants.d.ts +2 -0
  48. package/lib/dto-models.d.ts +59 -0
  49. package/lib/dto-pricing.d.ts +5 -0
  50. package/lib/dto-team-brief.d.ts +9 -0
  51. package/lib/dto-team-info.d.ts +8 -0
  52. package/lib/dto-team-meeting.d.ts +6 -0
  53. package/lib/dto-team-metric.d.ts +20 -0
  54. package/lib/dto-team.d.ts +12 -0
  55. package/lib/dto-user.d.ts +31 -0
  56. package/lib/dto-with-modified.d.ts +26 -0
  57. package/lib/types.d.ts +7 -0
  58. package/lib/ui-state.d.ts +5 -0
  59. package/lib/with-related.d.ts +42 -0
  60. package/package.json +14 -2
  61. package/sneat-dto.d.ts +5 -0
  62. package/tsconfig.lib.prod.tsbuildinfo +1 -0
  63. package/eslint.config.js +0 -7
  64. package/ng-package.json +0 -7
  65. package/project.json +0 -38
  66. package/src/lib/by-user.ts +0 -4
  67. package/src/lib/dto-app.ts +0 -9
  68. package/src/lib/dto-commune.ts +0 -158
  69. package/src/lib/dto-constants.spec.ts +0 -7
  70. package/src/lib/dto-models.ts +0 -105
  71. package/src/lib/dto-pricing.ts +0 -5
  72. package/src/lib/dto-team-brief.ts +0 -20
  73. package/src/lib/dto-team-info.ts +0 -15
  74. package/src/lib/dto-team-meeting.ts +0 -6
  75. package/src/lib/dto-team-metric.ts +0 -29
  76. package/src/lib/dto-team.ts +0 -27
  77. package/src/lib/dto-user.ts +0 -85
  78. package/src/lib/dto-with-modified.ts +0 -32
  79. package/src/lib/types.ts +0 -34
  80. package/src/lib/ui-state.ts +0 -5
  81. package/src/lib/with-related.ts +0 -180
  82. package/src/test-setup.ts +0 -1
  83. package/tsconfig.json +0 -13
  84. package/tsconfig.lib.json +0 -19
  85. package/tsconfig.lib.prod.json +0 -7
  86. package/tsconfig.spec.json +0 -31
  87. package/vite.config.mts +0 -10
  88. /package/{src/index.ts → index.d.ts} +0 -0
  89. /package/{src/lib/index.ts → lib/index.d.ts} +0 -0
  90. /package/{src/lib/period.ts → lib/period.d.ts} +0 -0
@@ -1,158 +0,0 @@
1
- import { IDemoRecord, ITitledRecord, ITotalsHolder } from './dto-models';
2
- import { CommuneType, CountryId } from './types';
3
-
4
- export const enum SpaceCounter {
5
- activities = 'activities',
6
- assets = 'assets',
7
- assetGroups = 'assetGroups',
8
- contacts = 'contacts',
9
- documents = 'documents',
10
- liabilities = 'liabilities',
11
- members = 'members',
12
- // membersByRole = 'membersByRole',
13
- memberGroups = 'memberGroups',
14
- overdues = 'overdues',
15
- pupils = 'pupils',
16
- regularTasks = 'regularTasks',
17
- staff = 'staff',
18
- todos = 'todos',
19
- upcomings = 'upcomings',
20
- }
21
-
22
- // type TeamCounters = {
23
- // [P in EnumAsUnionOfKeys<typeof TeamCounter>]: number;
24
- // };
25
-
26
- export interface SpaceCounts {
27
- [SpaceCounter.activities]?: number;
28
- [SpaceCounter.assets]?: number;
29
- [SpaceCounter.assetGroups]?: number;
30
- [SpaceCounter.contacts]?: number;
31
- [SpaceCounter.documents]?: number;
32
- [SpaceCounter.regularTasks]?: number;
33
- [SpaceCounter.liabilities]?: number;
34
- [SpaceCounter.pupils]?: number;
35
- [SpaceCounter.staff]?: number;
36
- [SpaceCounter.members]?: number;
37
- [SpaceCounter.memberGroups]?: number;
38
- [SpaceCounter.overdues]?: number;
39
- [SpaceCounter.todos]?: number;
40
- [SpaceCounter.upcomings]?: number;
41
- // [CommuneCounter.membersByRole]?: { [role: string]: number }; this does not make sense here
42
- }
43
-
44
- export function incrementNumberOf<
45
- NumberOf,
46
- Dbo extends { numberOf?: NumberOf },
47
- >(dto: Dbo, init: () => NumberOf, counter: keyof NumberOf, v = 1): Dbo {
48
- const current: number = ((dto.numberOf && dto.numberOf[counter]) ||
49
- 0) as unknown as number;
50
- return {
51
- ...dto,
52
- numberOf: {
53
- ...(dto.numberOf || init()),
54
- [counter]: current + v,
55
- },
56
- };
57
- }
58
-
59
- export function newSpaceCounts(numberOf?: SpaceCounts): SpaceCounts {
60
- numberOf = numberOf || {};
61
- return {
62
- activities: numberOf.activities || 0,
63
- assets: numberOf.assets || 0,
64
- assetGroups: numberOf.assetGroups || 0,
65
- contacts: numberOf.contacts || 0,
66
- documents: numberOf.documents || 0,
67
- members: numberOf.members || 0,
68
- memberGroups: numberOf.memberGroups || 0,
69
- liabilities: numberOf.liabilities || 0,
70
- overdues: numberOf.overdues || 0,
71
- regularTasks: numberOf.regularTasks || 0,
72
- todos: numberOf.todos || 0,
73
- upcomings: numberOf.upcomings || 0,
74
- };
75
- }
76
-
77
- export interface ICommuneDbo extends IDemoRecord, ITitledRecord, ITotalsHolder {
78
- readonly countryId?: CountryId;
79
- readonly type: CommuneType;
80
- readonly desc?: string;
81
- readonly userID: string;
82
- readonly order?: number;
83
- readonly numberOf?: SpaceCounts;
84
- readonly membersCountByRole?: Record<string, number>;
85
- readonly noContactRoles?: string[];
86
- // readonly groups?: ICommuneDtoMemberGroupInfo[];
87
- // readonly members?: readonly ITeamMemberInfo[];
88
- }
89
-
90
- export function isCommuneShouldHoldMembersInfo(type: CommuneType): boolean {
91
- return type === 'family' || type === 'cohabit';
92
- }
93
-
94
- // export function findCommuneMemberInfo(
95
- // members: readonly ITeamMemberInfo[],
96
- // member: { readonly id?: string; readonly userID?: string },
97
- // ): ITeamMemberInfo | undefined {
98
- // return (
99
- // members &&
100
- // members.find(
101
- // (m) =>
102
- // (m && !!m.id && m.id === member.id) ||
103
- // (!!m.userID && m.userID === member.userID),
104
- // )
105
- // );
106
- // }
107
-
108
- export const personalCommuneIdPrefix = 'u_';
109
-
110
- export function getUserPersonalCommuneID(userID?: string): string {
111
- if (!userID) {
112
- throw new Error('userID is required parameter');
113
- }
114
- return personalCommuneIdPrefix + userID;
115
- }
116
-
117
- export function isPersonalCommuneId(id: string): boolean {
118
- return !!id && id.startsWith(personalCommuneIdPrefix);
119
- }
120
-
121
- export function isUserPersonalCommune(
122
- communeID: string,
123
- userID?: string,
124
- ): boolean {
125
- return !!userID && communeID === getUserPersonalCommuneID(userID);
126
- }
127
-
128
- // export const CommuneModel = {
129
- // getListInfoByRealId: (dto: ITeamDto, listId: string) => {
130
- // const result =
131
- // dto.listGroups &&
132
- // dto.listGroups
133
- // .map((lg) => lg.lists && lg.lists.find((l) => l.id === listId))
134
- // .find((l) => !!l);
135
- // console.log(
136
- // `CommuneModel.getListInfoByRealId(${listId})`,
137
- // dto.listGroups,
138
- // ' => ',
139
- // result,
140
- // );
141
- // return result;
142
- // },
143
- //
144
- // getListInfoByShortId: (dto: ICommuneDto, shortListId: string) => {
145
- // console.log(
146
- // `CommuneModel.getListInfoByShortId(${shortListId})`,
147
- // dto.listGroups,
148
- // );
149
- // return (
150
- // dto.listGroups &&
151
- // dto.listGroups
152
- // .map(
153
- // (lg) => lg.lists && lg.lists.find((l) => l.shortId === shortListId),
154
- // )
155
- // .find((l) => !!l)
156
- // );
157
- // },
158
- // };
@@ -1,7 +0,0 @@
1
- import { CompoundIndexSeparator } from './dto-constants';
2
-
3
- describe('dto constants', () => {
4
- it('should have CompoundIndexSeparator defined', () => {
5
- expect(CompoundIndexSeparator).toBe(':');
6
- });
7
- });
@@ -1,105 +0,0 @@
1
- import { Restriction } from './types';
2
-
3
- // import {IPersonSize} from '../ui/dto-sizechart';
4
-
5
- export interface ITitled {
6
- title: string;
7
- }
8
-
9
- export interface ITitledRecord {
10
- id?: string;
11
- title?: string;
12
- }
13
-
14
- export interface ITitledRecordInfo {
15
- id: string;
16
- title: string;
17
- }
18
-
19
- // | MemberRoleWork;
20
-
21
- export interface DtoTotal {
22
- count: number;
23
- day?: number;
24
- week?: number;
25
- month?: number;
26
- quarter?: number;
27
- year?: number;
28
- }
29
-
30
- export interface IDemoRecord {
31
- id?: string;
32
- isDemo?: boolean;
33
- isLocal?: boolean;
34
- }
35
-
36
- export interface ITotalsHolder {
37
- totals?: DtoTotals;
38
- }
39
-
40
- export interface DtoTotals {
41
- incomes?: DtoTotal;
42
- expenses?: DtoTotal;
43
- }
44
-
45
- // export interface Category extends ITitledRecord {
46
- // id: string;
47
- // }
48
-
49
- export interface IWithSpaceIDs {
50
- spaceIDs?: string[];
51
- }
52
-
53
- export interface IWithTag {
54
- tags?: string[];
55
- }
56
-
57
- export interface IWithAssetIDs {
58
- assetIDs?: string[];
59
- }
60
-
61
- export interface IWithMemberIDs {
62
- memberIDs?: string[];
63
- }
64
-
65
- export interface IRealEstate {
66
- leaseExpires?: string;
67
- }
68
-
69
- export interface IWithRestrictions {
70
- restrictions?: Restriction[];
71
- }
72
-
73
- function newTotal(): DtoTotal {
74
- return { count: 0, day: 0, week: 0, month: 0, quarter: 0, year: 0 };
75
- }
76
-
77
- export function newTotals(): DtoTotals {
78
- // TODO: Rename to ITotalsDto
79
- return { incomes: newTotal(), expenses: newTotal() };
80
- }
81
-
82
- export function zeroIfEmptyTotals(totals: DtoTotals): DtoTotals {
83
- const f = (t?: DtoTotal) =>
84
- t
85
- ? {
86
- count: t.count || 0,
87
- day: t.day || 0,
88
- week: t.week || 0,
89
- month: t.month || 0,
90
- quarter: t.quarter || 0,
91
- year: t.year || 0,
92
- }
93
- : newTotal();
94
- totals.incomes = f(totals.incomes);
95
- totals.expenses = f(totals.expenses);
96
- return totals;
97
- }
98
-
99
- export interface IVerification {
100
- isVerified?: boolean;
101
- verification?: {
102
- confirmedBy?: string[]; // List of ID of users who confirmed validity of the member
103
- rejectedBy?: string[]; // List of ID of users who questions validity of the member
104
- };
105
- }
@@ -1,5 +0,0 @@
1
- export interface IPrice {
2
- title?: string;
3
- amount: number;
4
- currency?: 'EUR' | 'RUB' | 'USD';
5
- }
@@ -1,20 +0,0 @@
1
- import { SpaceType } from '@sneat/core';
2
-
3
- export interface ISpaceBrief {
4
- readonly title: string;
5
- readonly type: SpaceType;
6
- readonly parentSpaceID?: string;
7
- readonly roles?: string[];
8
- }
9
-
10
- export const equalSpaceBriefs = (
11
- v1?: ISpaceBrief | null | undefined,
12
- v2?: ISpaceBrief | null | undefined,
13
- ): boolean => {
14
- if (v1 === v2) return true;
15
- return v1?.parentSpaceID === v2?.parentSpaceID && v1?.title === v2?.title;
16
- };
17
-
18
- export const isSpaceSupportsMemberGroups = (t: SpaceType): boolean => {
19
- return t === 'educator' || t === 'sport_club' || t === 'cohabit';
20
- };
@@ -1,15 +0,0 @@
1
- import { SpaceType } from '@sneat/core';
2
- import { IUserCommuneInfo } from './dto-user';
3
-
4
- export interface IShortSpaceInfo {
5
- type: SpaceType;
6
- id?: string;
7
- // shortId?: CommuneShortId;
8
- title?: string;
9
- }
10
-
11
- export function createShortCommuneInfoFromUserCommuneInfo(
12
- v: IUserCommuneInfo,
13
- ): IShortSpaceInfo {
14
- return { id: v.id, title: v.title, /*shortId: v.shortId,*/ type: v.type };
15
- }
@@ -1,6 +0,0 @@
1
- export interface IMeetingInfo {
2
- id: string;
3
- stage: string;
4
- started?: string;
5
- finished?: string;
6
- }
@@ -1,29 +0,0 @@
1
- export type MetricColor =
2
- | 'primary'
3
- | 'secondary'
4
- | 'tertiary'
5
- | 'success'
6
- | 'danger'
7
- | 'warning';
8
-
9
- export interface IBoolMetricVal {
10
- label: string;
11
- color: MetricColor;
12
- }
13
-
14
- export interface IBoolMetric {
15
- true: IBoolMetricVal;
16
- false: IBoolMetricVal;
17
- }
18
-
19
- export interface ISpaceMetric {
20
- id?: string;
21
- title: string;
22
- colorTrue?: MetricColor;
23
- colorFalse?: MetricColor;
24
- type: 'bool' | 'integer' | 'options';
25
- mode: 'personal' | 'team';
26
- bool?: IBoolMetric;
27
- min?: number;
28
- max?: number;
29
- }
@@ -1,27 +0,0 @@
1
- import { ITotalsHolder } from './dto-models';
2
- import { ISpaceBrief } from './dto-team-brief';
3
- import { ISpaceMetric } from './dto-team-metric';
4
-
5
- // export interface ITeamMeetings {
6
- // scrum?: IMemberBrief;
7
- // retrospective?: IMeetingInfo;
8
- // }
9
-
10
- export interface ISpaceDbo extends ISpaceBrief, ITotalsHolder {
11
- readonly countryID: string;
12
- readonly userIDs: string[];
13
- // readonly members?: IMemberBrief[];
14
- // readonly assets?: IAssetBrief[];
15
- // readonly contacts?: IContactBrief[];
16
- // readonly numberOf?: TeamCounts;
17
- // readonly recurringHappenings?: { [id: string]: IHappeningBrief }; // TODO: Move to ISchedulusTeamDto
18
-
19
- metrics: ISpaceMetric[];
20
- // active?: ITeamMeetings;
21
- // last?: ITeamMeetings;
22
- upcomingRetro?: {
23
- itemsByUserAndType?: Record<string, Record<string, number>>;
24
- };
25
-
26
- noContactRoles?: string[]; // lists roles that have no contacts. For example families that have no plumber contacts.
27
- }
@@ -1,85 +0,0 @@
1
- // import { MemberRelationship } from './dto-member';
2
- import { ITitledRecord } from './dto-models';
3
- import { ICommuneDbo } from './dto-commune';
4
- import { CommuneType, CountryId } from './types';
5
-
6
- export interface IUserCommuneInfo {
7
- id?: string;
8
- shortId?: string;
9
- title?: string;
10
- type: CommuneType;
11
- // members?: {
12
- // [id: string]: {
13
- // relatedAs: MemberRelationship;
14
- // // title?: string;
15
- // };
16
- // };
17
- }
18
-
19
- export function createUserCommuneInfoFromCommuneDto(
20
- communeDto: ICommuneDbo,
21
- shortId?: string,
22
- ): IUserCommuneInfo {
23
- return {
24
- id: communeDto.id,
25
- shortId,
26
- title: communeDto.title,
27
- type: communeDto.type,
28
- };
29
- }
30
-
31
- export interface IUserDbo extends ITitledRecord {
32
- countryIds?: CountryId[];
33
- created: {
34
- hostOrApp: string;
35
- at: string;
36
- };
37
- readonly communes?: readonly IUserCommuneInfo[]; // Returns real ID and Title, find by shortId
38
- communesCount?: number;
39
- isAnonymous: boolean;
40
- isDemo?: boolean;
41
- autogeneratedPassword?: string;
42
- emailVerified?: boolean;
43
- email?: string;
44
- emailOriginal?: string;
45
- gender?: 'male' | 'female' | 'undisclosed';
46
- }
47
-
48
- export function addCommuneToUserDto(
49
- userDto: IUserDbo,
50
- communeInfo: IUserCommuneInfo,
51
- ): IUserDbo {
52
- const communes = userDto.communes || [];
53
- if (
54
- communeInfo.id &&
55
- communes.find((c) => !!c.id && !!communeInfo.id && c.id === communeInfo.id)
56
- ) {
57
- throw new Error(`Can't add commune with duplicate id: ${communeInfo.id}`);
58
- }
59
- return {
60
- ...userDto,
61
- communes: [...communes, communeInfo],
62
- communesCount: communes.length + 1,
63
- };
64
- }
65
-
66
- export class UserModel {
67
- public static getCommuneInfoByShortId(
68
- id: string,
69
- communes?: readonly IUserCommuneInfo[],
70
- ): IUserCommuneInfo | undefined {
71
- return communes && communes.find((c) => c.shortId === id);
72
- }
73
-
74
- public static getCommuneInfoById(
75
- id: string,
76
- communes: readonly IUserCommuneInfo[],
77
- ): IUserCommuneInfo | undefined {
78
- const ci =
79
- communes && communes.find((c) => c.shortId === id || c.id === id);
80
- if (!ci && id === 'family') {
81
- return { type: 'family', shortId: 'family', title: 'Family' };
82
- }
83
- return ci;
84
- }
85
- }
@@ -1,32 +0,0 @@
1
- export interface timestamp {
2
- seconds: number;
3
- nanoseconds: number;
4
- }
5
- export const emptyTimestamp: timestamp = { seconds: 0, nanoseconds: 0 };
6
-
7
- export interface IWithCreatedShort {
8
- readonly at: string;
9
- readonly by: string;
10
- }
11
-
12
- export interface IWithCreatedOn {
13
- readonly createdOn: string;
14
- }
15
-
16
- export interface IWithCreated {
17
- readonly createdAt: timestamp;
18
- readonly createdBy: string;
19
- }
20
-
21
- export interface IWithUpdated {
22
- readonly updatedAt: timestamp;
23
- readonly updatedBy: string;
24
- }
25
-
26
- export interface IWithDeleted {
27
- readonly deletedAt?: timestamp;
28
- readonly deletedBy?: string;
29
- }
30
-
31
- export interface IWithModified
32
- extends IWithCreated, IWithUpdated, IWithDeleted {}
package/src/lib/types.ts DELETED
@@ -1,34 +0,0 @@
1
- import { SpaceType } from '@sneat/core';
2
-
3
- export { SpaceMemberType } from '@sneat/auth-models';
4
-
5
- export type Restriction = 'adults_only' | 'personal' | string;
6
-
7
- export type SneatRecordStatus = 'active' | 'archived' | 'deleted';
8
-
9
- export type CommuneType = SpaceType;
10
-
11
- export type CountryId =
12
- | 'IE'
13
- | 'US'
14
- | 'UK'
15
- | 'RU'
16
- | 'FR'
17
- | 'ES'
18
- | 'AU'
19
- | 'ZA'
20
- | string;
21
-
22
- export type CommuneItemCounter =
23
- | 'activities'
24
- | 'assets'
25
- | 'assetGroups'
26
- | 'contacts'
27
- | 'documents'
28
- | 'liabilities'
29
- | 'members'
30
- | 'memberGroups'
31
- | 'overdues'
32
- | 'regularTasks'
33
- | 'todos'
34
- | 'upcomings';
@@ -1,5 +0,0 @@
1
- export interface UiState {
2
- readonly isAdding?: boolean;
3
- readonly isDeleting?: boolean;
4
- readonly isReordering?: boolean;
5
- }