@sneat/dto 0.1.2 → 0.1.4

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 (89) 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/eslint.config.js +0 -7
  63. package/ng-package.json +0 -7
  64. package/project.json +0 -38
  65. package/src/lib/by-user.ts +0 -4
  66. package/src/lib/dto-app.ts +0 -9
  67. package/src/lib/dto-commune.ts +0 -158
  68. package/src/lib/dto-constants.spec.ts +0 -7
  69. package/src/lib/dto-models.ts +0 -105
  70. package/src/lib/dto-pricing.ts +0 -5
  71. package/src/lib/dto-team-brief.ts +0 -20
  72. package/src/lib/dto-team-info.ts +0 -15
  73. package/src/lib/dto-team-meeting.ts +0 -6
  74. package/src/lib/dto-team-metric.ts +0 -29
  75. package/src/lib/dto-team.ts +0 -27
  76. package/src/lib/dto-user.ts +0 -85
  77. package/src/lib/dto-with-modified.ts +0 -32
  78. package/src/lib/types.ts +0 -34
  79. package/src/lib/ui-state.ts +0 -5
  80. package/src/lib/with-related.ts +0 -180
  81. package/src/test-setup.ts +0 -1
  82. package/tsconfig.json +0 -13
  83. package/tsconfig.lib.json +0 -19
  84. package/tsconfig.lib.prod.json +0 -7
  85. package/tsconfig.spec.json +0 -31
  86. package/vite.config.mts +0 -10
  87. /package/{src/index.ts → index.d.ts} +0 -0
  88. /package/{src/lib/index.ts → lib/index.d.ts} +0 -0
  89. /package/{src/lib/period.ts → lib/period.d.ts} +0 -0
@@ -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
- }
@@ -1,180 +0,0 @@
1
- import { IWithCreatedShort } from './dto-with-modified';
2
-
3
- export interface IRelatedItemKey {
4
- readonly itemID: string;
5
- readonly spaceID?: string;
6
- }
7
-
8
- export interface ISpaceModuleItemRef {
9
- readonly module: string;
10
- readonly collection: string;
11
- readonly spaceID: string;
12
- readonly itemID: string;
13
- }
14
-
15
- export interface IRelationshipRole {
16
- readonly created: IWithCreatedShort;
17
- }
18
-
19
- export type WritableRelationshipRoles = Record<string, IRelationshipRole>;
20
- // {
21
- // // -readonly [K in keyof IRelationshipRoles]: IRelationshipRoles[K];
22
- // };
23
- export type IRelationshipRoles = Readonly<WritableRelationshipRoles>;
24
-
25
- export interface IRelatedItem {
26
- // readonly keys: readonly IRelatedItemKey[];
27
- readonly rolesOfItem?: IRelationshipRoles; // if related item is a child of the current record, then rolesOfItem = {"child": ...}
28
- readonly rolesToItem?: IRelationshipRoles; // if related item is a child of the current contact, then rolesToItem = {"parent": ...}
29
- }
30
-
31
- export type IRelatedItems = Readonly<Record<string, IRelatedItem>>;
32
- export type IRelatedCollections = Readonly<Record<string, IRelatedItems>>;
33
- export type IRelatedModules = Readonly<Record<string, IRelatedCollections>>;
34
-
35
- export interface IRelatedTo extends IWithRelatedOnly {
36
- readonly key: ISpaceModuleItemRef;
37
- readonly title: string; // pass empty string if you don't want to display name
38
- }
39
-
40
- export function getRelatedItems(
41
- moduleId: string,
42
- collectionId: string,
43
- related?: IRelatedModules,
44
- ): IRelatedItems {
45
- return (related && related[moduleId]?.[collectionId]) || {};
46
- }
47
-
48
- export interface IWithRelatedOnly {
49
- readonly related?: IRelatedModules;
50
- }
51
-
52
- export function validateRelated(related?: IRelatedModules): void {
53
- if (!related) {
54
- return;
55
- }
56
- Object.entries(related).forEach(([, collections]) => {
57
- Object.entries(collections).forEach(([, items]) => {
58
- if (!items) {
59
- return;
60
- }
61
- Object.entries(items).forEach(([itemID]) => {
62
- if (!itemID) {
63
- throw new Error('ItemID is not set');
64
- }
65
- });
66
- });
67
- });
68
- }
69
-
70
- export interface IWithRelatedAndRelatedIDs extends IWithRelatedOnly {
71
- readonly relatedIDs?: readonly string[];
72
- }
73
-
74
- export const addRelatedItem = (
75
- related: IRelatedModules | undefined,
76
- key: ISpaceModuleItemRef,
77
- rolesOfItem?: IRelationshipRoles,
78
- ) => {
79
- related = related || {};
80
- let collectionRelated = related[key.module] || {};
81
- let relatedItems = collectionRelated[key.collection] || {};
82
- if (!hasRelated(related, key)) {
83
- relatedItems = {
84
- ...relatedItems,
85
- [key.itemID]: { rolesOfItem },
86
- };
87
- collectionRelated = {
88
- ...collectionRelated,
89
- [key.collection]: relatedItems,
90
- };
91
- related = { ...related, [key.module]: collectionRelated };
92
- }
93
- return related;
94
- };
95
-
96
- export const removeRelatedItem = (
97
- related: IRelatedModules | undefined,
98
- key: ISpaceModuleItemRef,
99
- ) => {
100
- if (!related) {
101
- return related;
102
- }
103
- let collectionRelated = related[key.module];
104
- if (!collectionRelated) {
105
- return related;
106
- }
107
- const relatedItems = collectionRelated[key.collection];
108
- if (!relatedItems) {
109
- return related;
110
- }
111
- if (hasRelated(related, key)) {
112
- const collectionItems = { ...relatedItems };
113
- delete collectionItems[key.itemID];
114
- collectionRelated = {
115
- ...collectionRelated,
116
- [key.collection]: collectionItems,
117
- };
118
- related = { ...related, [key.module]: collectionRelated };
119
- }
120
- return related;
121
- };
122
-
123
- export const getLongRelatedItemID = (itemID: string, spaceID: string) =>
124
- `${itemID}@${spaceID}`;
125
-
126
- export const getRelatedItemByIDs = (
127
- relatedItems: Readonly<Record<string, IRelatedItem>> | undefined,
128
- itemID: string,
129
- spaceID?: string,
130
- ) =>
131
- relatedItems &&
132
- (relatedItems[itemID] ||
133
- (spaceID && relatedItems[getLongRelatedItemID(itemID, spaceID)]));
134
-
135
- export const getRelatedItemByKey = (
136
- related: IRelatedModules | undefined,
137
- key: ISpaceModuleItemRef,
138
- ): IRelatedItem | undefined => {
139
- const items = related?.[key.module]?.[key.collection];
140
- const { itemID, spaceID } = key;
141
- return getRelatedItemByIDs(items, itemID, spaceID);
142
- };
143
-
144
- export const getRelatedItemIDs = (
145
- related: IRelatedModules | undefined,
146
- module: string,
147
- collection: string,
148
- spaceID?: string,
149
- ): readonly string[] => {
150
- if (!related) {
151
- return [];
152
- }
153
- // console.log('getRelatedItemIDs', module, collection, spaceID, related);
154
- const collectionRelated = (related || {})[module] || {};
155
- const relatedItems = collectionRelated[collection];
156
- const keys = Object.keys(relatedItems);
157
- return spaceID
158
- ? keys.filter((k) => !k.includes('@') || k.endsWith(`@${spaceID}`))
159
- : keys;
160
- };
161
-
162
- export const hasRelated = (
163
- related: IRelatedModules | undefined,
164
- key: ISpaceModuleItemRef,
165
- ): boolean => {
166
- if (!related) {
167
- return false;
168
- }
169
- const collectionRelated = (related || {})[key.module] || {};
170
- const relatedItems = collectionRelated[key.collection];
171
- return hasRelatedItem(relatedItems, key);
172
- };
173
-
174
- const hasRelatedItem = (
175
- relatedItems: IRelatedItems,
176
- itemKey: IRelatedItemKey,
177
- ): boolean => {
178
- const { itemID, spaceID } = itemKey;
179
- return !!getRelatedItemByIDs(relatedItems, itemID, spaceID);
180
- };
package/src/test-setup.ts DELETED
@@ -1 +0,0 @@
1
- import '@sneat/core/testing-light';
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.angular.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "./tsconfig.lib.json"
8
- },
9
- {
10
- "path": "./tsconfig.spec.json"
11
- }
12
- ]
13
- }
package/tsconfig.lib.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.lib.base.json",
3
- "exclude": [
4
- "vite.config.ts",
5
- "vite.config.mts",
6
- "vitest.config.ts",
7
- "vitest.config.mts",
8
- "src/**/*.test.ts",
9
- "src/**/*.spec.ts",
10
- "src/**/*.test.tsx",
11
- "src/**/*.spec.tsx",
12
- "src/**/*.test.js",
13
- "src/**/*.spec.js",
14
- "src/**/*.test.jsx",
15
- "src/**/*.spec.jsx",
16
- "src/test-setup.ts",
17
- "src/lib/testing/**/*"
18
- ]
19
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {}
7
- }
@@ -1,31 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "types": [
6
- "vitest/globals",
7
- "vitest/importMeta",
8
- "vite/client",
9
- "node",
10
- "vitest"
11
- ]
12
- },
13
- "include": [
14
- "vite.config.ts",
15
- "vite.config.mts",
16
- "vitest.config.ts",
17
- "vitest.config.mts",
18
- "src/**/*.test.ts",
19
- "src/**/*.spec.ts",
20
- "src/**/*.test.tsx",
21
- "src/**/*.spec.tsx",
22
- "src/**/*.test.js",
23
- "src/**/*.spec.js",
24
- "src/**/*.test.jsx",
25
- "src/**/*.spec.jsx",
26
- "src/**/*.d.ts"
27
- ],
28
- "files": [
29
- "src/test-setup.ts"
30
- ]
31
- }
package/vite.config.mts DELETED
@@ -1,10 +0,0 @@
1
- /// <reference types='vitest' />
2
- import { defineConfig } from 'vitest/config';
3
- import { createBaseViteConfig } from '../../vite.config.base';
4
-
5
- export default defineConfig(() =>
6
- createBaseViteConfig({
7
- dirname: __dirname,
8
- name: 'dto',
9
- }),
10
- );
File without changes
File without changes
File without changes