@sneat/extension-budgetus-contract 0.1.0 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @sneat/extension-budgetus-contract
2
+
3
+ Budgetus extension contract library.
4
+
5
+ ## Provenance
6
+
7
+ Migrated from sneat-co/budgetus (npm continuity from @sneat/extension-budgetus-contract@0.1.0).
@@ -1,9 +1,6 @@
1
1
  import { InjectionToken } from '@angular/core';
2
2
 
3
- var ListPage;
4
- (function (ListPage) {
5
- ListPage["list"] = "list";
6
- })(ListPage || (ListPage = {}));
3
+ const BUDGETUS_SERVICE = new InjectionToken('BudgetusService');
7
4
 
8
5
  class ListItemInfoModel {
9
6
  static trackBy = (index, item) => !item
@@ -26,6 +23,12 @@ class ListItemModel {
26
23
  });
27
24
  }
28
25
  }
26
+
27
+ var ListPage;
28
+ (function (ListPage) {
29
+ ListPage["list"] = "list";
30
+ })(ListPage || (ListPage = {}));
31
+
29
32
  function getListShortUrlId(communeId, shortId, id) {
30
33
  if (shortId) {
31
34
  return `${communeId}-${shortId}`;
@@ -64,51 +67,9 @@ function createListInfoFromDto(dto, shortId) {
64
67
  }
65
68
  return listInfo;
66
69
  }
67
- // export function createListItemInfoFromListInfo(listInfo: IListInfo): IListItemBrief {
68
- // return {
69
- // id: listInfo.id || '',
70
- // title: listInfo.title || '',
71
- // subListType: listInfo.type,
72
- // subListId: listInfo.id || `${listInfo.team && listInfo.team.id}-${listInfo.shortId}`,
73
- // emoji: listInfo.emoji,
74
- // img: listInfo.img,
75
- // };
76
- // }
77
- // export function createListItemInfo(listItem: IListItemDto): IListItemBrief {
78
- // const v: IListItemBrief = {
79
- // id: listItem.id,
80
- // title: listItem.title,
81
- // };
82
- // if (listItem.emoji) {
83
- // v.emoji = listItem.emoji;
84
- // }
85
- // if (listItem.done) {
86
- // v.done = true;
87
- // }
88
- // return v;
89
- // }
90
-
91
- // Budget tab read-model types (see backstage roadmap:
92
- // docs/roadmaps/budget-tab-mvp.md, Section 3 "Data model").
93
- //
94
- // IBudgetLineItem is a COMPUTED projection, not a persisted record: it is
95
- // derived from Assetus asset renewals + Calendarius happenings and re-derived
96
- // on every read. Only per-line overrides (targetAmount / isSurprise) are
97
- // persisted (see IBudgetOverridePatch below + the overrides store in
98
- // @sneat/extension-budgetus).
99
70
  function monthISOOf(dateISO) {
100
71
  return dateISO.slice(0, 7);
101
72
  }
102
- // Surprise-hiding (Surpriseless mechanic — budget-tab-mvp.md Section 1 and
103
- // Open Question 5). A gift line item flagged `isSurprise` must not reveal its
104
- // real title to the person it is a surprise for.
105
- //
106
- // This prototype has no recipient-linking yet (Open Question 1 in the plan is
107
- // still unresolved — there's no "this gift is for user X" edge to compare
108
- // against the current viewer), so for now it masks every `isSurprise` line
109
- // uniformly rather than per-viewer. `reveal: true` is a demo-only escape hatch
110
- // the Budget page uses so a reviewer/owner can see the underlying data
111
- // without needing a second signed-in user.
112
73
  function maskSurpriseLineItems(items, options) {
113
74
  if (options?.reveal) {
114
75
  return items;
@@ -118,8 +79,6 @@ function maskSurpriseLineItems(items, options) {
118
79
  : item);
119
80
  }
120
81
 
121
- const BUDGETUS_SERVICE = new InjectionToken('BudgetusService');
122
-
123
82
  /**
124
83
  * Generated bundle index. Do not edit.
125
84
  */
@@ -1 +1 @@
1
- {"version":3,"file":"sneat-extension-budgetus-contract.mjs","sources":["../../../../../../libs/extensions/budgetus/contract/src/constants.ts","../../../../../../libs/extensions/budgetus/contract/src/dto/list.ts","../../../../../../libs/extensions/budgetus/contract/src/dto/budget.ts","../../../../../../libs/extensions/budgetus/contract/src/services/budgetus-service.ts","../../../../../../libs/extensions/budgetus/contract/src/sneat-extension-budgetus-contract.ts"],"sourcesContent":["import { EnumAsUnionOfKeys } from '@sneat/core';\n\nexport const enum ListPage {\n list = 'list',\n}\n\nexport type ListPages = EnumAsUnionOfKeys<typeof ListPage>;\n","import { IRecord } from '@sneat/data';\nimport {\n IShortSpaceInfo,\n IWithCreated,\n IWithRestrictions,\n IWithSpaceIDs,\n SneatRecordStatus,\n} from '@sneat/dto';\n\nexport type ListStatus = SneatRecordStatus;\n\nexport interface IQuantity {\n value: number;\n unit: string;\n}\n\nexport interface IListItemCommon extends IListCommon {\n subListId?: string;\n subListType?: ListType;\n quantity?: IQuantity;\n category?: string;\n}\n\nexport type IListItemBase = IListItemCommon;\n\nexport type ListItemStatus = 'done' | 'active';\n\nexport interface IListItemBrief extends IListItemBase {\n id: string;\n readonly created?: string; // UTC datetime\n readonly emoji?: string;\n readonly status?: ListItemStatus;\n readonly img?: string;\n}\n\nexport interface ListCounts {\n // TODO: Use some enumerator as IDB library does.\n active?: number;\n completed?: number;\n}\n\nexport type ListType =\n | 'buy'\n | 'watch'\n | 'cook'\n | 'do'\n | 'other'\n | 'recipes'\n | 'rsvp';\n\n// IListCommon is a common base class for a List & ListItem\nexport interface IListCommon {\n // Do not extend from IWithCreated as it is not applicable for ICreateListItemRequest\n title: string;\n img?: string;\n emoji?: string;\n isDone?: boolean;\n}\n\nexport interface IListBase extends IListCommon, IWithSpaceIDs {\n type: ListType;\n shortId?: string;\n status?: ListStatus;\n}\n\nexport interface IListDbo extends IListBase, IWithRestrictions, IWithCreated {\n dtClosed?: number;\n note?: string; // Is used for example for recipe text\n numberOf?: ListCounts;\n items?: IListItemBrief[];\n commune?: IShortSpaceInfo; // Used just for in-memory columns?\n}\n\nexport class ListItemInfoModel {\n static trackBy: (\n index: number,\n item: IListItemBrief,\n ) => string | number | undefined = (index, item) =>\n !item\n ? index\n : (!!item.id && `id:${item.id}`) ||\n (item.subListId && `subList:${item.subListId}`) ||\n item.title;\n}\n\nexport class ListItemModel {\n static equalListItems(...items: IListItemBrief[]): boolean {\n const { id, title, subListId, category, subListType } = items[0];\n return !items.some((item) => {\n if (id) {\n return item.id !== id;\n }\n return (\n (!!title && item.title !== title) ||\n (!!subListId && item.subListId !== subListId) ||\n (!!category && item.category !== category) ||\n (!!subListType && item.subListType !== subListType)\n );\n });\n }\n}\n\nexport interface IListItemDbo extends IListBase, IListItemCommon {\n listId?: string;\n score?: number;\n subListItems?: IListItemBrief[];\n}\n\nexport function getListShortUrlId(\n communeId: string,\n shortId?: string,\n id?: string,\n): string | undefined {\n if (shortId) {\n return `${communeId}-${shortId}`;\n }\n if (id) {\n return id;\n }\n return undefined;\n}\n\nexport interface IListInfo extends IWithRestrictions {\n parentListId?: string;\n parentListType?: ListType;\n type: ListType;\n id?: string;\n shortId?: string;\n title?: string;\n hidden?: boolean;\n space?: IShortSpaceInfo;\n emoji?: string;\n img?: string;\n note?: string;\n itemsCount?: number;\n}\n\nexport interface IListBrief extends IListBase, IWithCreated {\n emoji?: string;\n}\n\nexport function isListInfoMatchesListDto(\n i: IListInfo,\n l: IRecord<IListDbo>,\n): boolean {\n return (\n (!!i.id && i.id === l.id) ||\n (i.type === l.dbo?.type && !!i.shortId && i.shortId === l.dbo?.shortId)\n );\n}\n\nexport function createListInfoFromDto(\n dto: IListDbo,\n shortId?: string,\n): IListInfo {\n if (!dto.title) {\n throw new Error('!title');\n }\n const listInfo: IListInfo = {\n type: dto.type,\n title: dto.title,\n };\n if (shortId) {\n listInfo.shortId = shortId;\n }\n if (dto.items && dto.items.length) {\n listInfo.itemsCount = dto.items.length;\n }\n if (dto.emoji) {\n listInfo.emoji = dto.emoji;\n }\n if (dto.restrictions) {\n listInfo.restrictions = dto.restrictions;\n }\n if (dto.commune) {\n listInfo.space = dto.commune;\n }\n return listInfo;\n}\n\n// export function createListItemInfoFromListInfo(listInfo: IListInfo): IListItemBrief {\n// \treturn {\n// \t\tid: listInfo.id || '',\n// \t\ttitle: listInfo.title || '',\n// \t\tsubListType: listInfo.type,\n// \t\tsubListId: listInfo.id || `${listInfo.team && listInfo.team.id}-${listInfo.shortId}`,\n// \t\temoji: listInfo.emoji,\n// \t\timg: listInfo.img,\n// \t};\n// }\n\n// export function createListItemInfo(listItem: IListItemDto): IListItemBrief {\n// \tconst v: IListItemBrief = {\n// \t\tid: listItem.id,\n// \t\ttitle: listItem.title,\n// \t};\n// \tif (listItem.emoji) {\n// \t\tv.emoji = listItem.emoji;\n// \t}\n// \tif (listItem.done) {\n// \t\tv.done = true;\n// \t}\n// \treturn v;\n// }\n","// Budget tab read-model types (see backstage roadmap:\n// docs/roadmaps/budget-tab-mvp.md, Section 3 \"Data model\").\n//\n// IBudgetLineItem is a COMPUTED projection, not a persisted record: it is\n// derived from Assetus asset renewals + Calendarius happenings and re-derived\n// on every read. Only per-line overrides (targetAmount / isSurprise) are\n// persisted (see IBudgetOverridePatch below + the overrides store in\n// @sneat/extension-budgetus).\n\nexport interface IMoney {\n currency: string;\n value: number;\n}\n\n// Where a budget line item was derived from. 'gift' is a specialisation of\n// 'happening' — a yearly happening (birthday/anniversary) tagged as a gift\n// occasion, which is the flagship Surpriseless scenario.\nexport type BudgetLineSource = 'asset-renewal' | 'happening' | 'gift';\n\nexport interface IBudgetLineItem {\n id: string;\n title: string;\n dateISO: string; // ISO date (yyyy-mm-dd) of the next occurrence/due date\n amount: IMoney;\n source: BudgetLineSource;\n sourceRef?: string; // id of the source asset/happening, for drill-through\n targetAmount?: IMoney; // user-set override (esp. gift lines)\n isSurprise?: boolean; // Surpriseless \"surprise-hiding\" flag (gift lines)\n}\n\nexport interface IBudgetMonthGroup {\n monthISO: string; // 'YYYY-MM'\n total: IMoney;\n items: IBudgetLineItem[];\n}\n\nexport interface IBudgetRollup {\n byMonth: IBudgetMonthGroup[];\n annualTotal: IMoney;\n mostExpensiveMonthISO: string;\n}\n\n// The only fields a budgetus overrides record may patch onto a computed line\n// item. Kept separate from IBudgetLineItem so the wire/storage shape can't\n// accidentally include projection-only computed fields (title, amount, ...).\nexport interface IBudgetOverridePatch {\n targetAmount?: IMoney;\n isSurprise?: boolean;\n}\n\nexport function monthISOOf(dateISO: string): string {\n return dateISO.slice(0, 7);\n}\n\n// Surprise-hiding (Surpriseless mechanic — budget-tab-mvp.md Section 1 and\n// Open Question 5). A gift line item flagged `isSurprise` must not reveal its\n// real title to the person it is a surprise for.\n//\n// This prototype has no recipient-linking yet (Open Question 1 in the plan is\n// still unresolved — there's no \"this gift is for user X\" edge to compare\n// against the current viewer), so for now it masks every `isSurprise` line\n// uniformly rather than per-viewer. `reveal: true` is a demo-only escape hatch\n// the Budget page uses so a reviewer/owner can see the underlying data\n// without needing a second signed-in user.\nexport function maskSurpriseLineItems(\n items: IBudgetLineItem[],\n options?: { reveal?: boolean },\n): IBudgetLineItem[] {\n if (options?.reveal) {\n return items;\n }\n return items.map((item) =>\n item.isSurprise\n ? { ...item, title: '🎁 Hidden surprise', sourceRef: undefined }\n : item,\n );\n}\n","import { InjectionToken } from '@angular/core';\nimport { ISpaceContext } from '@sneat/space-models';\nimport { Observable } from 'rxjs';\nimport { IListContext } from '../contexts';\nimport { IBudgetOverridePatch, IBudgetRollup, ListType } from '../dto';\nimport {\n ICreateListRequest,\n IDeleteListItemsRequest,\n IListItemResult,\n IListItemsCommandParams,\n IReorderListItemsRequest,\n ISetListItemsIsComplete,\n} from './interfaces';\n\n// IBudgetusService is the runtime-light contract Budgetus pages and components\n// depend on. Members mirror the concrete ListService public surface used by the\n// UI; the implementation lives in the private runtime and is provided via the\n// BUDGETUS_SERVICE token below. The UI BaseListPage additionally needs the\n// inherited ModuleSpaceItemService surface, so it types the injected token as\n// an intersection with ModuleSpaceItemService<IListBrief, IListDbo>.\nexport interface IBudgetusService {\n createList(request: ICreateListRequest): Observable<IListContext>;\n deleteList(space: ISpaceContext, listId: string): Observable<void>;\n reorderListItems(request: IReorderListItemsRequest): Observable<void>;\n createListItems(\n params: IListItemsCommandParams,\n ): Observable<IListItemResult>;\n setListItemsIsCompleted(\n request: ISetListItemsIsComplete,\n ): Observable<void>;\n deleteListItems(request: IDeleteListItemsRequest): Observable<void>;\n getListById(\n space: ISpaceContext,\n listType: ListType,\n listID: string,\n ): Observable<IListContext>;\n\n // --- Budget tab (the read-model projection over renewals + happenings; see\n // budget-tab-mvp.md Section 3/4). Recomputed on every read, not a plain CRUD\n // collection — hence Observable rather than a one-shot fetch. ---\n\n /** Watches the derived+overridden budget rollup for a space. */\n watchBudget(spaceID: string): Observable<IBudgetRollup>;\n\n /**\n * Persists a user override (target amount and/or surprise-hide flag) for a\n * single computed budget line item, keyed by its `IBudgetLineItem.id`.\n * Triggers a re-emission on the `watchBudget()` observable.\n */\n setOverride(\n spaceID: string,\n lineItemId: string,\n patch: IBudgetOverridePatch,\n ): Promise<void>;\n}\n\nexport const BUDGETUS_SERVICE = new InjectionToken<IBudgetusService>(\n 'BudgetusService',\n);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;IAEkB;AAAlB,CAAA,UAAkB,QAAQ,EAAA;AACxB,IAAA,QAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACf,CAAC,EAFiB,QAAQ,KAAR,QAAQ,GAAA,EAAA,CAAA,CAAA;;MCuEb,iBAAiB,CAAA;IAC5B,OAAO,OAAO,GAGqB,CAAC,KAAK,EAAE,IAAI,KAC7C,CAAC;AACC,UAAE;AACF,UAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAA,GAAA,EAAM,IAAI,CAAC,EAAE,EAAE;aAC5B,IAAI,CAAC,SAAS,IAAI,WAAW,IAAI,CAAC,SAAS,CAAA,CAAE,CAAC;YAC/C,IAAI,CAAC,KAAK;;MAGL,aAAa,CAAA;AACxB,IAAA,OAAO,cAAc,CAAC,GAAG,KAAuB,EAAA;AAC9C,QAAA,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QAChE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAI;YAC1B,IAAI,EAAE,EAAE;AACN,gBAAA,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE;YACvB;YACA,QACE,CAAC,CAAC,CAAC,KAA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AAC,MAAM,EAAE;QACjC,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM;IACxC;AACA,IAAA,IAAI,GAAG,CAAC,KAAK,EAAE;AACb,QAAA,QAAQ,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK;IAC5B;AACA,IAAA,IAAI,GAAG,CAAC,YAAY,EAAE;AACpB,QAAA,QAAQ,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY;IAC1C;AACA,IAAA,IAAI,GAAG,CAAC,OAAO,EAAE;AACf,QAAA,QAAQ,CAAC,KAAK,GAAG,GAAG,CAAC,OAAO;IAC9B;AACA,IAAA,OAAO,QAAQ;AACjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3MA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA2CM,SAAU,UAAU,CAAC,OAAe,EAAA;IACxC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;AAC5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACM,SAAU,qBAAqB,CACnC,KAAwB,EACxB,OAA8B,EAAA;AAE9B,IAAA,IAAI,OAAO,EAAE,MAAM,EAAE;AACnB,QAAA,OAAO,KAAK;IACd;IACA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KACpB,IAAI,CAAC;AACH,UAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS;UAC5D,IAAI,CACT;AACH;;MCpBa,gBAAgB,GAAG,IAAI,cAAc,CAChD,iBAAiB;;ACzDnB;;AAEG;;;;"}
1
+ {"version":3,"file":"sneat-extension-budgetus-contract.mjs","sources":["../../../../libs/budgetus/src/services.ts","../../../../libs/budgetus/src/models.ts","../../../../libs/budgetus/src/enums.ts","../../../../libs/budgetus/src/utils.ts","../../../../libs/budgetus/src/sneat-extension-budgetus-contract.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { Observable } from 'rxjs';\nimport {\n IListDbo,\n IListBrief,\n IListKey,\n IBudgetRollup,\n IBudgetOverridePatch,\n ListType,\n IListItemBrief,\n IListContext,\n ICreateListRequest,\n IListRequest,\n ICreateListItemsRequest,\n IListItemIDsRequest,\n IReorderListItemsRequest,\n IDeleteListItemsRequest,\n ISetListItemsIsComplete,\n IListItemsCommandParams,\n IListItemResult,\n} from './dto';\n\nexport interface GetOrCreateCommuneItemIds {\n id?: string;\n shortId?: string;\n communeShortId?: string;\n}\n\nexport interface IProgress {\n current: number;\n total: number;\n state?: string;\n}\n\nexport type ReorderListItemsWorker = (listDto: IListDbo) => void;\n\nexport interface IBudgetusService {\n createList(request: ICreateListRequest): Observable<IListContext>;\n deleteList(space: any, listId: string): Observable<void>;\n reorderListItems(request: IReorderListItemsRequest): Observable<void>;\n createListItems(params: IListItemsCommandParams): Observable<IListItemResult>;\n setListItemsIsCompleted(request: ISetListItemsIsComplete): Observable<void>;\n deleteListItems(request: IDeleteListItemsRequest): Observable<void>;\n getListById(space: any, listType: ListType, listID: string): Observable<IListContext>;\n watchBudget(spaceID: string): Observable<IBudgetRollup>;\n setOverride(spaceID: string, lineItemId: string, patch: IBudgetOverridePatch): Promise<void>;\n}\n\nexport const BUDGETUS_SERVICE = new InjectionToken<IBudgetusService>('BudgetusService');\n","import { IListItemBrief } from './dto/list-item';\n\nexport class ListItemInfoModel {\n static trackBy = (index: number, item: IListItemBrief | null | undefined): string | number | undefined =>\n !item\n ? index\n : (!!item.id && `id:${item.id}`) ||\n (item.subListId && `subList:${item.subListId}`) ||\n item.title;\n}\n\nexport class ListItemModel {\n static equalListItems(...items: IListItemBrief[]): boolean {\n const { id, title, subListId, category, subListType } = items[0];\n return !items.some((item) => {\n if (id) {\n return item.id !== id;\n }\n return (\n (!!title && item.title !== title) ||\n (!!subListId && item.subListId !== subListId) ||\n (!!category && item.category !== category) ||\n (!!subListType && item.subListType !== subListType)\n );\n });\n }\n}\n","import { EnumAsUnionOfKeys } from '@sneat/core';\n\nexport const enum ListPage {\n list = 'list',\n}\nexport type ListPages = EnumAsUnionOfKeys<typeof ListPage>;\n","import { IRecord } from '@sneat/data';\nimport { IListDbo, IListInfo } from './dto/list';\n\nexport function getListShortUrlId(communeId: string, shortId?: string, id?: string): string | undefined {\n if (shortId) {\n return `${communeId}-${shortId}`;\n }\n if (id) {\n return id;\n }\n return undefined;\n}\n\nexport function isListInfoMatchesListDto(i: IListInfo, l: IRecord<IListDbo>): boolean {\n return (\n (!!i.id && i.id === l.id) ||\n (i.type === l.dbo?.type && !!i.shortId && i.shortId === l.dbo?.shortId)\n );\n}\n\nexport function createListInfoFromDto(dto: IListDbo, shortId?: string): IListInfo {\n if (!dto.title) {\n throw new Error('!title');\n }\n const listInfo: IListInfo = {\n type: dto.type,\n title: dto.title,\n };\n if (shortId) {\n listInfo.shortId = shortId;\n }\n if (dto.items && dto.items.length) {\n listInfo.itemsCount = dto.items.length;\n }\n if (dto.emoji) {\n listInfo.emoji = dto.emoji;\n }\n if (dto.restrictions) {\n listInfo.restrictions = dto.restrictions;\n }\n if (dto.commune) {\n listInfo.space = dto.commune;\n }\n return listInfo;\n}\n\nexport function monthISOOf(dateISO: string): string {\n return dateISO.slice(0, 7);\n}\n\nexport function maskSurpriseLineItems(\n items: any[],\n options?: {\n reveal?: boolean;\n }\n): any[] {\n if (options?.reveal) {\n return items;\n }\n return items.map((item) =>\n item.isSurprise\n ? { ...item, title: '🎁 Hidden surprise', sourceRef: undefined }\n : item\n );\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;MAgDa,gBAAgB,GAAG,IAAI,cAAc,CAAmB,iBAAiB;;MC9CzE,iBAAiB,CAAA;IAC5B,OAAO,OAAO,GAAG,CAAC,KAAa,EAAE,IAAuC,KACtE,CAAC;AACC,UAAE;AACF,UAAE,CA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B,CACnC,KAAY,EACZ,OAEC,EAAA;AAED,IAAA,IAAI,OAAO,EAAE,MAAM,EAAE;AACnB,QAAA,OAAO,KAAK;IACd;IACA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KACpB,IAAI,CAAC;AACH,UAAE,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS;UAC5D,IAAI,CACT;AACH;;AChEA;;AAEG;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/extension-budgetus-contract",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,25 +1,26 @@
1
- import { EnumAsUnionOfKeys } from '@sneat/core';
2
- import { ISpaceItemNavContext, ISpaceRequest, ISpaceContext } from '@sneat/space-models';
3
- import { IRecord } from '@sneat/data';
4
- import { IWithSpaceIDs, SneatRecordStatus, IWithCreated, IWithRestrictions, IShortSpaceInfo, ICommuneDbo } from '@sneat/dto';
1
+ import { SneatRecordStatus, IWithSpaceIDs, IWithCreated, IWithRestrictions, IShortSpaceInfo } from '@sneat/dto';
2
+ import { ISpaceItemNavContext, ISpaceContext } from '@sneat/space-models';
5
3
  import { InjectionToken } from '@angular/core';
6
4
  import { Observable } from 'rxjs';
5
+ import { EnumAsUnionOfKeys } from '@sneat/core';
6
+ import { IRecord } from '@sneat/data';
7
7
 
8
- declare const enum ListPage {
9
- list = "list"
10
- }
11
- type ListPages = EnumAsUnionOfKeys<typeof ListPage>;
8
+ type ListType = 'buy' | 'watch' | 'cook' | 'do' | 'other' | 'recipes' | 'rsvp';
12
9
 
13
10
  type ListStatus = SneatRecordStatus;
14
11
  interface IQuantity {
15
12
  value: number;
16
13
  unit: string;
17
14
  }
18
- interface IListItemCommon extends IListCommon {
15
+ interface IListItemCommon {
19
16
  subListId?: string;
20
17
  subListType?: ListType;
21
18
  quantity?: IQuantity;
22
19
  category?: string;
20
+ title: string;
21
+ img?: string;
22
+ emoji?: string;
23
+ isDone?: boolean;
23
24
  }
24
25
  type IListItemBase = IListItemCommon;
25
26
  type ListItemStatus = 'done' | 'active';
@@ -34,7 +35,12 @@ interface ListCounts {
34
35
  active?: number;
35
36
  completed?: number;
36
37
  }
37
- type ListType = 'buy' | 'watch' | 'cook' | 'do' | 'other' | 'recipes' | 'rsvp';
38
+ interface IListItemDbo extends IWithSpaceIDs, IListItemCommon {
39
+ listId?: string;
40
+ score?: number;
41
+ subListItems?: IListItemBrief[];
42
+ }
43
+
38
44
  interface IListCommon {
39
45
  title: string;
40
46
  img?: string;
@@ -53,18 +59,6 @@ interface IListDbo extends IListBase, IWithRestrictions, IWithCreated {
53
59
  items?: IListItemBrief[];
54
60
  commune?: IShortSpaceInfo;
55
61
  }
56
- declare class ListItemInfoModel {
57
- static trackBy: (index: number, item: IListItemBrief) => string | number | undefined;
58
- }
59
- declare class ListItemModel {
60
- static equalListItems(...items: IListItemBrief[]): boolean;
61
- }
62
- interface IListItemDbo extends IListBase, IListItemCommon {
63
- listId?: string;
64
- score?: number;
65
- subListItems?: IListItemBrief[];
66
- }
67
- declare function getListShortUrlId(communeId: string, shortId?: string, id?: string): string | undefined;
68
62
  interface IListInfo extends IWithRestrictions {
69
63
  parentListId?: string;
70
64
  parentListType?: ListType;
@@ -82,9 +76,10 @@ interface IListInfo extends IWithRestrictions {
82
76
  interface IListBrief extends IListBase, IWithCreated {
83
77
  emoji?: string;
84
78
  }
85
- declare function isListInfoMatchesListDto(i: IListInfo, l: IRecord<IListDbo>): boolean;
86
- declare function createListInfoFromDto(dto: IListDbo, shortId?: string): IListInfo;
87
-
79
+ interface IListKey {
80
+ id: string;
81
+ type: ListType;
82
+ }
88
83
  interface IListGroup {
89
84
  id: string;
90
85
  title?: string;
@@ -94,9 +89,8 @@ interface IListGroup {
94
89
  }
95
90
 
96
91
  interface IBudgetusSpaceDbo {
97
- listGroups?: IListGroup[];
92
+ listGroups?: any[];
98
93
  }
99
-
100
94
  interface IMoney {
101
95
  currency: string;
102
96
  value: number;
@@ -126,49 +120,20 @@ interface IBudgetOverridePatch {
126
120
  targetAmount?: IMoney;
127
121
  isSurprise?: boolean;
128
122
  }
129
- declare function monthISOOf(dateISO: string): string;
130
- declare function maskSurpriseLineItems(items: IBudgetLineItem[], options?: {
131
- reveal?: boolean;
132
- }): IBudgetLineItem[];
133
123
 
134
- interface IListKey {
135
- id: string;
124
+ interface IListContext extends ISpaceItemNavContext<IListBrief, any> {
136
125
  type: ListType;
137
126
  }
138
- interface IListContext extends ISpaceItemNavContext<IListBrief, IListDbo> {
139
- type: ListType;
140
- }
141
-
142
- interface GetOrCreateCommuneItemIds {
127
+ interface ICreateListRequest {
143
128
  id?: string;
144
- shortId?: string;
145
- communeShortId?: string;
146
- }
147
- interface IProgress {
148
- current: number;
149
- total: number;
150
- state?: string;
151
- }
152
- interface IListItemResult {
153
- message?: string;
154
- changed?: boolean;
155
- success: boolean;
156
- listDto: IListDbo;
157
- communeDto?: ICommuneDbo;
158
- listItemDto?: IListItemDbo;
159
- }
160
- interface IListItemsCommandParams {
161
- space: ISpaceContext;
162
- list: IListContext;
163
- items: IListItemBrief[];
164
- }
165
- type ReorderListItemsWorker = (listDto: IListDbo) => void;
166
- interface ICreateListRequest extends ISpaceRequest, IListBrief {
129
+ title: string;
130
+ type: ListType;
131
+ emoji?: string;
167
132
  }
168
- interface IListRequest extends ISpaceRequest {
133
+ interface IListRequest {
169
134
  readonly listID: string;
170
135
  }
171
- interface ICreateListItemRequest extends IListItemBase {
136
+ interface ICreateListItemRequest extends IListItemBrief {
172
137
  id: string;
173
138
  }
174
139
  interface ICreateListItemsRequest extends IListRequest {
@@ -187,25 +152,63 @@ type IDeleteListItemsRequest = IListItemIDsRequest;
187
152
  interface ISetListItemsIsComplete extends IListItemIDsRequest {
188
153
  isDone: boolean;
189
154
  }
155
+ interface IListItemsCommandParams {
156
+ space: ISpaceContext;
157
+ list: IListContext;
158
+ items: IListItemBrief[];
159
+ }
160
+ interface IListItemResult {
161
+ message?: string;
162
+ changed?: boolean;
163
+ success: boolean;
164
+ listDto: any;
165
+ communeDto?: any;
166
+ listItemDto?: IListItemDbo;
167
+ }
190
168
 
169
+ interface GetOrCreateCommuneItemIds {
170
+ id?: string;
171
+ shortId?: string;
172
+ communeShortId?: string;
173
+ }
174
+ interface IProgress {
175
+ current: number;
176
+ total: number;
177
+ state?: string;
178
+ }
179
+ type ReorderListItemsWorker = (listDto: IListDbo) => void;
191
180
  interface IBudgetusService {
192
181
  createList(request: ICreateListRequest): Observable<IListContext>;
193
- deleteList(space: ISpaceContext, listId: string): Observable<void>;
182
+ deleteList(space: any, listId: string): Observable<void>;
194
183
  reorderListItems(request: IReorderListItemsRequest): Observable<void>;
195
184
  createListItems(params: IListItemsCommandParams): Observable<IListItemResult>;
196
185
  setListItemsIsCompleted(request: ISetListItemsIsComplete): Observable<void>;
197
186
  deleteListItems(request: IDeleteListItemsRequest): Observable<void>;
198
- getListById(space: ISpaceContext, listType: ListType, listID: string): Observable<IListContext>;
199
- /** Watches the derived+overridden budget rollup for a space. */
187
+ getListById(space: any, listType: ListType, listID: string): Observable<IListContext>;
200
188
  watchBudget(spaceID: string): Observable<IBudgetRollup>;
201
- /**
202
- * Persists a user override (target amount and/or surprise-hide flag) for a
203
- * single computed budget line item, keyed by its `IBudgetLineItem.id`.
204
- * Triggers a re-emission on the `watchBudget()` observable.
205
- */
206
189
  setOverride(spaceID: string, lineItemId: string, patch: IBudgetOverridePatch): Promise<void>;
207
190
  }
208
191
  declare const BUDGETUS_SERVICE: InjectionToken<IBudgetusService>;
209
192
 
193
+ declare class ListItemInfoModel {
194
+ static trackBy: (index: number, item: IListItemBrief | null | undefined) => string | number | undefined;
195
+ }
196
+ declare class ListItemModel {
197
+ static equalListItems(...items: IListItemBrief[]): boolean;
198
+ }
199
+
200
+ declare const enum ListPage {
201
+ list = "list"
202
+ }
203
+ type ListPages = EnumAsUnionOfKeys<typeof ListPage>;
204
+
205
+ declare function getListShortUrlId(communeId: string, shortId?: string, id?: string): string | undefined;
206
+ declare function isListInfoMatchesListDto(i: IListInfo, l: IRecord<IListDbo>): boolean;
207
+ declare function createListInfoFromDto(dto: IListDbo, shortId?: string): IListInfo;
208
+ declare function monthISOOf(dateISO: string): string;
209
+ declare function maskSurpriseLineItems(items: any[], options?: {
210
+ reveal?: boolean;
211
+ }): any[];
212
+
210
213
  export { BUDGETUS_SERVICE, ListItemInfoModel, ListItemModel, ListPage, createListInfoFromDto, getListShortUrlId, isListInfoMatchesListDto, maskSurpriseLineItems, monthISOOf };
211
214
  export type { BudgetLineSource, GetOrCreateCommuneItemIds, IBudgetLineItem, IBudgetMonthGroup, IBudgetOverridePatch, IBudgetRollup, IBudgetusService, IBudgetusSpaceDbo, ICreateListItemRequest, ICreateListItemsRequest, ICreateListRequest, IDeleteListItemsRequest, IListBase, IListBrief, IListCommon, IListContext, IListDbo, IListGroup, IListInfo, IListItemBase, IListItemBrief, IListItemCommon, IListItemDbo, IListItemIDsRequest, IListItemRequest, IListItemResult, IListItemsCommandParams, IListKey, IListRequest, IMoney, IProgress, IQuantity, IReorderListItemsRequest, ISetListItemsIsComplete, ListCounts, ListItemStatus, ListPages, ListStatus, ListType, ReorderListItemsWorker };