firstly 0.2.1 → 0.4.0

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 (210) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/esm/SqlDatabase/FF_LogToConsole.js +9 -14
  3. package/esm/carbone/CarboneController.js +2 -1
  4. package/esm/changeLog/index.d.ts +0 -10
  5. package/esm/{internals → core}/BaseEnum.d.ts +1 -1
  6. package/esm/core/FF_Entity.js +5 -0
  7. package/esm/core/helper.d.ts +2 -0
  8. package/esm/core/helper.js +3 -0
  9. package/esm/core/index.d.ts +0 -0
  10. package/esm/core/index.js +5 -0
  11. package/esm/core/tailwind.d.ts +21 -0
  12. package/esm/core/tailwind.js +22 -0
  13. package/esm/core/tryCatch.d.ts +44 -0
  14. package/esm/core/tryCatch.js +34 -0
  15. package/esm/cron/server/index.js +1 -1
  16. package/esm/feedback/FeedbackController.js +3 -2
  17. package/esm/feedback/index.d.ts +7 -2
  18. package/esm/feedback/index.js +1 -2
  19. package/esm/feedback/server/index.d.ts +0 -5
  20. package/esm/feedback/server/index.js +1 -1
  21. package/esm/formats/strings.js +2 -2
  22. package/esm/index.d.ts +16 -0
  23. package/esm/index.js +13 -0
  24. package/esm/svelte/FF_Repo.svelte.d.ts +9 -2
  25. package/esm/svelte/FF_Repo.svelte.js +40 -17
  26. package/esm/svelte/class/SP.svelte.js +14 -2
  27. package/esm/svelte/helpers/debounce.js +1 -1
  28. package/esm/svelte/index.d.ts +2 -24
  29. package/esm/svelte/index.js +2 -22
  30. package/esm/{ui → svelte/ui}/Icon.svelte +1 -1
  31. package/esm/virtual/StateDemoEnum.d.ts +3 -3
  32. package/esm/virtual/StateDemoEnum.js +3 -3
  33. package/esm/virtual/UIEntity.js +1 -2
  34. package/package.json +8 -39
  35. package/esm/auth/AuthController.d.ts +0 -58
  36. package/esm/auth/AuthController.js +0 -114
  37. package/esm/auth/Entities.d.ts +0 -47
  38. package/esm/auth/Entities.js +0 -182
  39. package/esm/auth/README.md +0 -3
  40. package/esm/auth/index.d.ts +0 -5
  41. package/esm/auth/index.js +0 -5
  42. package/esm/auth/server/AuthController.server.d.ts +0 -58
  43. package/esm/auth/server/AuthController.server.js +0 -518
  44. package/esm/auth/server/handleAuth.d.ts +0 -4
  45. package/esm/auth/server/handleAuth.js +0 -142
  46. package/esm/auth/server/handleGuard.d.ts +0 -22
  47. package/esm/auth/server/handleGuard.js +0 -34
  48. package/esm/auth/server/helperDb.d.ts +0 -10
  49. package/esm/auth/server/helperDb.js +0 -56
  50. package/esm/auth/server/helperFirstly.d.ts +0 -1
  51. package/esm/auth/server/helperFirstly.js +0 -9
  52. package/esm/auth/server/helperOslo.d.ts +0 -7
  53. package/esm/auth/server/helperOslo.js +0 -24
  54. package/esm/auth/server/helperRemultServer.d.ts +0 -5
  55. package/esm/auth/server/helperRemultServer.js +0 -44
  56. package/esm/auth/server/helperRole.d.ts +0 -19
  57. package/esm/auth/server/helperRole.js +0 -57
  58. package/esm/auth/server/index.d.ts +0 -8
  59. package/esm/auth/server/index.js +0 -8
  60. package/esm/auth/server/module.d.ts +0 -300
  61. package/esm/auth/server/module.js +0 -230
  62. package/esm/auth/server/providers/github.d.ts +0 -33
  63. package/esm/auth/server/providers/github.js +0 -87
  64. package/esm/auth/server/providers/helperProvider.d.ts +0 -1
  65. package/esm/auth/server/providers/helperProvider.js +0 -25
  66. package/esm/auth/static/assets/Page-BHW08QWz.css +0 -1
  67. package/esm/auth/static/assets/Page-BRNWcY5Z.d.ts +0 -2
  68. package/esm/auth/static/assets/Page-BRNWcY5Z.js +0 -1
  69. package/esm/auth/static/assets/Page-CFcEsGK8.d.ts +0 -2
  70. package/esm/auth/static/assets/Page-CFcEsGK8.js +0 -7
  71. package/esm/auth/static/assets/Page-tLVs5slF.d.ts +0 -2
  72. package/esm/auth/static/assets/Page-tLVs5slF.js +0 -1
  73. package/esm/auth/static/assets/index-D38rqu4x.d.ts +0 -201
  74. package/esm/auth/static/assets/index-D38rqu4x.js +0 -2
  75. package/esm/auth/static/assets/index-DKWpA6v7.css +0 -4
  76. package/esm/auth/static/favicon.svg +0 -79
  77. package/esm/auth/static/index.html +0 -13
  78. package/esm/auth/types.d.ts +0 -73
  79. package/esm/bin/cmd.d.ts +0 -1
  80. package/esm/bin/cmd.js +0 -793
  81. package/esm/feedback/ui/DialogIssue.svelte +0 -149
  82. package/esm/feedback/ui/DialogIssue.svelte.d.ts +0 -22
  83. package/esm/feedback/ui/DialogIssues.svelte +0 -114
  84. package/esm/feedback/ui/DialogIssues.svelte.d.ts +0 -22
  85. package/esm/feedback/ui/DialogMilestones.svelte +0 -43
  86. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +0 -20
  87. package/esm/feedback/ui/Feedback.svelte +0 -16
  88. package/esm/feedback/ui/Feedback.svelte.d.ts +0 -18
  89. package/esm/internals/FF_Entity.d.ts +0 -2
  90. package/esm/internals/FF_Entity.js +0 -21
  91. package/esm/internals/FF_Fields.d.ts +0 -11
  92. package/esm/internals/FF_Fields.js +0 -144
  93. package/esm/internals/cellsBuildor.d.ts +0 -47
  94. package/esm/internals/cellsBuildor.js +0 -140
  95. package/esm/internals/helper.d.ts +0 -49
  96. package/esm/internals/helper.js +0 -162
  97. package/esm/internals/index.d.ts +0 -82
  98. package/esm/internals/index.js +0 -45
  99. package/esm/internals/storeItem.d.ts +0 -28
  100. package/esm/internals/storeItem.js +0 -176
  101. package/esm/internals/storeList.d.ts +0 -34
  102. package/esm/internals/storeList.js +0 -108
  103. package/esm/internals/theme.d.ts +0 -4
  104. package/esm/internals/theme.js +0 -4
  105. package/esm/server/index.d.ts +0 -52
  106. package/esm/server/index.js +0 -87
  107. package/esm/svelte/FF_Cell.svelte +0 -103
  108. package/esm/svelte/FF_Cell.svelte.d.ts +0 -33
  109. package/esm/svelte/FF_Cell_Caption.svelte +0 -20
  110. package/esm/svelte/FF_Cell_Caption.svelte.d.ts +0 -31
  111. package/esm/svelte/FF_Cell_Display.svelte +0 -61
  112. package/esm/svelte/FF_Cell_Display.svelte.d.ts +0 -29
  113. package/esm/svelte/FF_Cell_Edit.svelte +0 -104
  114. package/esm/svelte/FF_Cell_Edit.svelte.d.ts +0 -32
  115. package/esm/svelte/FF_Cell_Error.svelte +0 -20
  116. package/esm/svelte/FF_Cell_Error.svelte.d.ts +0 -31
  117. package/esm/svelte/FF_Cell_Hint.svelte +0 -20
  118. package/esm/svelte/FF_Cell_Hint.svelte.d.ts +0 -31
  119. package/esm/svelte/FF_Config.svelte +0 -29
  120. package/esm/svelte/FF_Config.svelte.d.ts +0 -9
  121. package/esm/svelte/FF_Form.svelte +0 -155
  122. package/esm/svelte/FF_Form.svelte.d.ts +0 -37
  123. package/esm/svelte/FF_Grid.svelte +0 -257
  124. package/esm/svelte/FF_Grid.svelte.d.ts +0 -37
  125. package/esm/svelte/FF_Layout.svelte +0 -62
  126. package/esm/svelte/FF_Layout.svelte.d.ts +0 -31
  127. package/esm/svelte/actions/intersection.d.ts +0 -6
  128. package/esm/svelte/actions/intersection.js +0 -17
  129. package/esm/svelte/customField.d.ts +0 -69
  130. package/esm/svelte/customField.js +0 -4
  131. package/esm/svelte/dialog/DialogManagement.svelte +0 -98
  132. package/esm/svelte/dialog/DialogManagement.svelte.d.ts +0 -18
  133. package/esm/svelte/dialog/DialogPrimitive.svelte +0 -156
  134. package/esm/svelte/dialog/DialogPrimitive.svelte.d.ts +0 -38
  135. package/esm/svelte/dialog/dialog.d.ts +0 -58
  136. package/esm/svelte/dialog/dialog.js +0 -130
  137. package/esm/svelte/ff_Config.svelte.d.ts +0 -91
  138. package/esm/svelte/ff_Config.svelte.js +0 -111
  139. package/esm/svelte/firstly.css +0 -14
  140. package/esm/svelte/helpers.d.ts +0 -30
  141. package/esm/svelte/helpers.js +0 -38
  142. package/esm/svelte/tryCatch.d.ts +0 -12
  143. package/esm/svelte/tryCatch.js +0 -18
  144. package/esm/sveltekit/server/index.d.ts +0 -5
  145. package/esm/sveltekit/server/index.js +0 -24
  146. package/esm/ui/Button.svelte +0 -138
  147. package/esm/ui/Button.svelte.d.ts +0 -13
  148. package/esm/ui/Clipboardable.svelte +0 -25
  149. package/esm/ui/Clipboardable.svelte.d.ts +0 -12
  150. package/esm/ui/Field.svelte +0 -382
  151. package/esm/ui/Field.svelte.d.ts +0 -40
  152. package/esm/ui/FieldGroup.svelte +0 -117
  153. package/esm/ui/FieldGroup.svelte.d.ts +0 -44
  154. package/esm/ui/Grid.svelte +0 -265
  155. package/esm/ui/Grid.svelte.d.ts +0 -57
  156. package/esm/ui/Grid2.svelte +0 -293
  157. package/esm/ui/Grid2.svelte.d.ts +0 -57
  158. package/esm/ui/GridLoading.svelte +0 -58
  159. package/esm/ui/GridLoading.svelte.d.ts +0 -23
  160. package/esm/ui/GridPaginate.svelte +0 -69
  161. package/esm/ui/GridPaginate.svelte.d.ts +0 -23
  162. package/esm/ui/GridPaginate2.svelte +0 -25
  163. package/esm/ui/GridPaginate2.svelte.d.ts +0 -7
  164. package/esm/ui/Loading.svelte +0 -16
  165. package/esm/ui/Loading.svelte.d.ts +0 -31
  166. package/esm/ui/Tooltip.svelte +0 -45
  167. package/esm/ui/Tooltip.svelte.d.ts +0 -32
  168. package/esm/ui/dialog/DialogForm.svelte +0 -76
  169. package/esm/ui/dialog/DialogForm.svelte.d.ts +0 -21
  170. package/esm/ui/dialog/DialogManagement.svelte +0 -96
  171. package/esm/ui/dialog/DialogManagement.svelte.d.ts +0 -26
  172. package/esm/ui/dialog/DialogPrimitive.svelte +0 -90
  173. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +0 -38
  174. package/esm/ui/dialog/FormEditAction.svelte +0 -62
  175. package/esm/ui/dialog/FormEditAction.svelte.d.ts +0 -31
  176. package/esm/ui/dialog/dialog.d.ts +0 -60
  177. package/esm/ui/dialog/dialog.js +0 -100
  178. package/esm/ui/index.d.ts +0 -6
  179. package/esm/ui/index.js +0 -20
  180. package/esm/ui/internals/FieldContainer.svelte +0 -39
  181. package/esm/ui/internals/FieldContainer.svelte.d.ts +0 -18
  182. package/esm/ui/internals/Input.svelte +0 -143
  183. package/esm/ui/internals/Input.svelte.d.ts +0 -37
  184. package/esm/ui/internals/Textarea.svelte +0 -66
  185. package/esm/ui/internals/Textarea.svelte.d.ts +0 -33
  186. package/esm/ui/internals/select/MultiSelectMelt.svelte +0 -260
  187. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +0 -32
  188. package/esm/ui/internals/select/Select2.svelte +0 -88
  189. package/esm/ui/internals/select/Select2.svelte.d.ts +0 -12
  190. package/esm/ui/internals/select/SelectMelt.svelte +0 -280
  191. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +0 -40
  192. package/esm/ui/internals/select/SelectRadio.svelte +0 -43
  193. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +0 -27
  194. package/esm/ui/link/Link.svelte +0 -33
  195. package/esm/ui/link/Link.svelte.d.ts +0 -33
  196. package/esm/ui/link/LinkPlus.svelte +0 -63
  197. package/esm/ui/link/LinkPlus.svelte.d.ts +0 -9
  198. package/esm/utils/tailwind.d.ts +0 -2
  199. package/esm/utils/tailwind.js +0 -3
  200. package/esm/utils/transition.d.ts +0 -9
  201. package/esm/utils/transition.js +0 -33
  202. package/esm/utils/types.js +0 -1
  203. /package/esm/{internals → core}/BaseEnum.js +0 -0
  204. /package/esm/{internals → core}/common.d.ts +0 -0
  205. /package/esm/{internals → core}/common.js +0 -0
  206. /package/esm/{utils → core}/types.d.ts +0 -0
  207. /package/esm/{auth → core}/types.js +0 -0
  208. /package/esm/{ui → svelte/ui}/Icon.svelte.d.ts +0 -0
  209. /package/esm/{ui → svelte/ui}/LibIcon.d.ts +0 -0
  210. /package/esm/{ui → svelte/ui}/LibIcon.js +0 -0
@@ -1,140 +0,0 @@
1
- import {} from 'remult';
2
- import { getRelationFieldInfo } from 'remult/internals';
3
- import { BaseEnum } from './BaseEnum.js';
4
- import { getEnum } from './helper.js';
5
- /**
6
- * cellsBuildor is a function to build cells for a <Grid /> or <FieldGroup /> component.
7
- *
8
- * ```html
9
- * <script lang="ts">
10
- * import { repo } from 'remult'
11
- *
12
- * const cells = cellsBuildor(repo(Site), ['name', 'description'])
13
- * const store = storeList( repo(Site) )
14
- * $: store.fetch()
15
- * </script>
16
- *
17
- * <Grid {cells} {store} />
18
- * ```
19
- *
20
- */
21
- export function cellsBuildor(repo, inputBuildor) {
22
- const buildor = [];
23
- for (let i = 0; i < inputBuildor.length; i++) {
24
- const item = inputBuildor[i];
25
- let b;
26
- if (item instanceof Object) {
27
- b = { ...item, field: repo.fields[item.col] };
28
- }
29
- else {
30
- b = { col: item, field: repo.fields[item] };
31
- }
32
- // Let's tweak defaults...
33
- if (b.kind === undefined) {
34
- if (b.field?.options.href) {
35
- b.kind = 'field_link';
36
- }
37
- }
38
- buildor.push(b);
39
- }
40
- return buildor;
41
- }
42
- export function cellBuildor(repo, inputBuildor) {
43
- return cellsBuildor(repo, [inputBuildor])[0];
44
- }
45
- export const fieldsOf = (b) => {
46
- return b.filter((c) => c.field).map((c) => c.field) ?? [];
47
- };
48
- export const getPlaceholder = (fields) => {
49
- return fields.map((c) => c.caption).join(', ');
50
- };
51
- export const buildSearchWhere = (entity, fields, search) => {
52
- if (!search) {
53
- return [];
54
- }
55
- const f = [
56
- {
57
- $or: fields.map((f) => {
58
- const fnName = f.key + 'Filter';
59
- // @ts-ignore
60
- if (entity && entity[fnName]) {
61
- // @ts-ignore
62
- return entity[fnName](search);
63
- }
64
- // let's continue with the default behavior
65
- // return {}
66
- // }
67
- if (f.inputType === 'number') {
68
- return { [f.key]: search };
69
- }
70
- return containsWords([f], search);
71
- }),
72
- },
73
- ];
74
- return f;
75
- };
76
- export const containsWords = (fields, search) => {
77
- if (!search) {
78
- return {};
79
- }
80
- const sSplitted = search.split(' ').filter((s) => s.length > 0);
81
- if (fields.length === 1) {
82
- return {
83
- $and: sSplitted.map((s) => ({ [fields[0].key]: { $contains: s } })),
84
- };
85
- }
86
- return {
87
- $and: sSplitted.map((s) => {
88
- return { $or: fields.map((f) => ({ [f.key]: { $contains: s } })) };
89
- }),
90
- };
91
- };
92
- export const buildWhere = (entity, defaultWhere, fields_filter, fields_search, obj) => {
93
- const and = [];
94
- if (defaultWhere) {
95
- and.push(defaultWhere);
96
- }
97
- if (obj && obj.search) {
98
- and.push(...buildSearchWhere(entity, fields_search, obj.search));
99
- }
100
- for (const field of fields_filter) {
101
- // if there is a value
102
- if (obj && obj[field.key]) {
103
- const rfi = getRelationFieldInfo(field);
104
- if (field.inputType === 'checkbox') {
105
- // @ts-ignore
106
- and.push({ [field.key]: obj[field.key] });
107
- }
108
- else if (field.inputType === 'selectEnum') {
109
- const fnName = field.key + 'Filter';
110
- // @ts-ignore
111
- if (entity && entity[fnName]) {
112
- // @ts-ignore
113
- and.push(entity[fnName](obj[field.key]));
114
- }
115
- else {
116
- // @ts-ignore
117
- const theEnum = getEnum(field, obj[field.key]);
118
- // Take the where of the enum if it exists, or it's using this selection as a filter
119
- if (theEnum?.where) {
120
- and.push(theEnum.where);
121
- }
122
- else {
123
- const wheretoUse = theEnum?.where ?? new BaseEnum(obj[field.key]);
124
- // @ts-ignore
125
- and.push({ [field.key]: wheretoUse });
126
- }
127
- }
128
- }
129
- else if (rfi?.type === 'toOne') {
130
- // @ts-ignore (setting the id of the relation)
131
- and.push({ [field.key]: obj[field.key] });
132
- }
133
- else {
134
- console.info(`Not handled filter field ${field.key} ${field.inputType}`);
135
- }
136
- }
137
- }
138
- // @ts-ignore
139
- return { $and: and };
140
- };
@@ -1,49 +0,0 @@
1
- import type { ClassType, ErrorInfo, FieldMetadata, LifecycleEvent, Repository } from 'remult';
2
- import type { BaseEnum, BaseItem } from './index.js';
3
- export declare function isError<T>(object: any): object is ErrorInfo<T>;
4
- export declare const getFirstInterestingField: <Entity>(repo: Repository<Entity>) => FieldMetadata<any, Entity>;
5
- export declare const getEntityDisplayValue: <Entity>(repo: Repository<Entity>, row: Entity) => BaseItem;
6
- export declare const getFieldLinkDisplayValue: (field: FieldMetadata, row: any) => BaseItem & {
7
- href: string;
8
- };
9
- export declare const getEntityDisplayValueFromField: (field: FieldMetadata, row: any) => BaseItem & {
10
- href: string;
11
- };
12
- export type MetaTypeRelation = {
13
- kind: 'relation';
14
- subKind: 'reference' | 'toOne' | 'toMany';
15
- repoTarget: Repository<any>;
16
- field: FieldMetadata;
17
- };
18
- type MetaTypeEnum = {
19
- kind: 'enum';
20
- subKind: 'single' | 'multi';
21
- values: BaseItem[];
22
- field: FieldMetadata;
23
- };
24
- type MetaTypePrimitive = {
25
- kind: 'primitive';
26
- subKind: string;
27
- field: FieldMetadata;
28
- };
29
- type MetaTypeSlot = {
30
- kind: 'slot';
31
- subKind: '???';
32
- };
33
- export type FieldMetaType = MetaTypeRelation | MetaTypeEnum | MetaTypePrimitive | MetaTypeSlot;
34
- export declare const getFieldMetaType: (field?: FieldMetadata, withHidden?: boolean) => FieldMetaType;
35
- export declare const displayWithDefaultAndSuffix: (field: FieldMetadata<any, any> | undefined, value: any) => string;
36
- export declare const getEnum: <T extends BaseEnum>(baseEnum: ClassType<T>, id: string | undefined | null) => T | undefined;
37
- export declare const getEnums: <T extends BaseEnum>(baseEnum: ClassType<T>) => T[];
38
- /**
39
- * To be used like:
40
- * ```ts
41
- * \@Entity('tasks', {
42
- * async deleting(item, e) {
43
- * await onDelete(item, e, 'prevent')
44
- * },
45
- * }
46
- * ```
47
- */
48
- export declare const onDelete: <T>(item: T, e: LifecycleEvent<T>, mode?: "prevent" | "cascade") => Promise<void>;
49
- export {};
@@ -1,162 +0,0 @@
1
- import { EntityError, getEntityRef, getValueList } from 'remult';
2
- import { getRelationFieldInfo } from 'remult/internals';
3
- import { suffixWithS } from '../formats/strings.js';
4
- export function isError(object) {
5
- return object;
6
- }
7
- export const getFirstInterestingField = (repo) => {
8
- const fields = repo.metadata.fields.toArray();
9
- for (let i = 0; i < fields.length; i++) {
10
- // Let's find the most relevant field to display...
11
- if (fields[i].key !== 'id' &&
12
- fields[i].key !== 'createdAt' &&
13
- fields[i].options.skipForDefaultField !== true) {
14
- return fields[i];
15
- }
16
- }
17
- return fields[0];
18
- };
19
- export const getEntityDisplayValue = (repo, row) => {
20
- if (repo.metadata.options.displayValue) {
21
- return repo.metadata.options.displayValue(row);
22
- }
23
- const field = getFirstInterestingField(repo);
24
- // REMULT P3 JYC: If it's an enum, it's not working...
25
- // @ts-ignore (added for row?.id)
26
- return { caption: row ? field.displayValue(row) : '-', id: row?.id ? row.id : '' };
27
- };
28
- export const getFieldLinkDisplayValue = (field, row) => {
29
- const caption = field.displayValue(row);
30
- let href = '';
31
- if (field.options.href) {
32
- href = field.options.href(row);
33
- }
34
- return { id: '', caption, href };
35
- };
36
- export const getEntityDisplayValueFromField = (field, row) => {
37
- if (row === null || row === undefined) {
38
- return { href: '/', id: '', caption: '-' };
39
- }
40
- const repo = getEntityRef(row).repository;
41
- return { href: '', ...getEntityDisplayValue(repo, row) };
42
- };
43
- // or it's a slot or it will return the field
44
- export const getFieldMetaType = (field, withHidden = false) => {
45
- if (field === undefined) {
46
- return { kind: 'slot', subKind: '???' };
47
- }
48
- // is it a relation?
49
- const fieldRelationInfo = getRelationFieldInfo(field);
50
- if (fieldRelationInfo) {
51
- return {
52
- kind: 'relation',
53
- subKind: fieldRelationInfo.type,
54
- repoTarget: fieldRelationInfo.toRepo,
55
- field,
56
- };
57
- }
58
- if (field.options?.inputType === 'selectArrayEnum') {
59
- return {
60
- kind: 'enum',
61
- subKind: 'multi',
62
- // @ts-ignore
63
- values: field.options.valueConverter.values,
64
- field,
65
- };
66
- }
67
- // REMULT P2 JYC: Any idea to know if it's an enum? and extract values?
68
- // const ttt = getValueList(field)
69
- // console.log(`ttt`, ttt)
70
- // Error: ValueType not yet initialized, did you forget to call @ValueListFieldType on function String()
71
- // is it an enum?
72
- // @ts-ignore
73
- if (field.options?.valueConverter?.values) {
74
- // console.log(`field.options.valueConverter.values`, field.options.valueConverter.values)
75
- // @ts-ignore
76
- const values = field.options.valueConverter.values;
77
- return {
78
- kind: 'enum',
79
- subKind: 'single',
80
- values: withHidden ? values : values.filter((v) => !v.hide),
81
- field,
82
- };
83
- }
84
- // it's a primitive
85
- return { kind: 'primitive', subKind: field.inputType ?? 'text', field };
86
- };
87
- export const displayWithDefaultAndSuffix = (field, value) => {
88
- const toRet = [];
89
- if (field && field.valueConverter?.displayValue && !field.isServerExpression) {
90
- toRet.push(field.valueConverter?.displayValue(value) ?? '-');
91
- }
92
- else {
93
- // toRet.push(value ?? '-')
94
- toRet.push(field?.displayValue ? field?.displayValue({ [field.key]: value }) : (value ?? '-'));
95
- }
96
- if (value === undefined || value === null) {
97
- return '';
98
- }
99
- if (field?.options.suffix) {
100
- if (field.options.suffixWithS) {
101
- toRet.push(suffixWithS(value, field.options.suffix));
102
- }
103
- else {
104
- toRet.push(field.options.suffix);
105
- }
106
- }
107
- return toRet.join(' ');
108
- };
109
- // FIXME: to remove ?
110
- export const getEnum = (baseEnum, id) => {
111
- if (!id) {
112
- return undefined;
113
- }
114
- // @ts-ignore
115
- const found = getValueList(baseEnum).find((c) => c.id === id);
116
- return found;
117
- };
118
- // FIXME: to remove ?
119
- export const getEnums = (baseEnum) => {
120
- return getValueList(baseEnum) || [];
121
- };
122
- /**
123
- * To be used like:
124
- * ```ts
125
- * \@Entity('tasks', {
126
- * async deleting(item, e) {
127
- * await onDelete(item, e, 'prevent')
128
- * },
129
- * }
130
- * ```
131
- */
132
- export const onDelete = async (item, e, mode = 'prevent') => {
133
- const toManies = e.repository.fields
134
- .toArray()
135
- .map((f) => {
136
- return {
137
- f: f,
138
- fi: getRelationFieldInfo(f),
139
- };
140
- })
141
- .filter((f) => f.fi?.type === 'toMany');
142
- const checks = await Promise.all(toManies.map(async (f_fi) => {
143
- // @ts-ignore
144
- const count = await e.repository.relations(item)[f_fi.f.key].count();
145
- return { ...f_fi, count };
146
- }));
147
- const nonEmptyRelations = checks.filter((check) => check.count > 0);
148
- if (nonEmptyRelations.length > 0) {
149
- if (mode === 'prevent') {
150
- const relationNames = nonEmptyRelations.map((r) => r.f.caption).join(', ');
151
- throw new EntityError({ message: `Can't with existing: ${relationNames}` });
152
- }
153
- else if (mode === 'cascade') {
154
- nonEmptyRelations.forEach(async (r) => {
155
- const where = Object.entries(r.fi?.getFields().fields ?? {}).map(([key, value]) => {
156
- return { [key]: item[value] };
157
- });
158
- await r.fi?.toRepo.deleteMany({ where });
159
- });
160
- }
161
- }
162
- };
@@ -1,82 +0,0 @@
1
- import type { FindOptionsBase } from 'remult';
2
- import type { ColumnDeciderArgs } from '../changeLog/index.js';
3
- import { default as Button } from '../ui/Button.svelte';
4
- import { default as Clipboardable } from '../ui/Clipboardable.svelte';
5
- import type { dialog } from '../ui/dialog/dialog.js';
6
- import { default as DialogManagement } from '../ui/dialog/DialogManagement.svelte';
7
- import { default as FormEditAction } from '../ui/dialog/FormEditAction.svelte';
8
- import { default as Field } from '../ui/Field.svelte';
9
- import { default as FieldGroup } from '../ui/FieldGroup.svelte';
10
- import { default as Grid } from '../ui/Grid.svelte';
11
- import { default as Grid2 } from '../ui/Grid2.svelte';
12
- import { default as GridPaginate } from '../ui/GridPaginate.svelte';
13
- import { default as GridPaginate2 } from '../ui/GridPaginate2.svelte';
14
- import { default as Icon } from '../ui/Icon.svelte';
15
- import { default as FieldContainer } from '../ui/internals/FieldContainer.svelte';
16
- import { default as SelectMelt } from '../ui/internals/select/SelectMelt.svelte';
17
- import { default as Link } from '../ui/link/Link.svelte';
18
- import { default as LinkPlus } from '../ui/link/LinkPlus.svelte';
19
- import { default as Loading } from '../ui/Loading.svelte';
20
- import { default as Tooltip } from '../ui/Tooltip.svelte';
21
- import type { BaseEnum, BaseItem, BaseItemLight, FF_Icon } from './BaseEnum.js';
22
- import type { CellsInput } from './cellsBuildor.js';
23
- import { FF_Role } from './common.js';
24
- import { storeItem, type StoreItem } from './storeItem.js';
25
- import { storeList } from './storeList.js';
26
- export { Field, FormEditAction, Grid, Grid2, GridPaginate, GridPaginate2, FieldGroup, Icon, Link, LinkPlus, Loading, Button, Tooltip, DialogManagement, FieldContainer, SelectMelt, Clipboardable, };
27
- export type { BaseEnumOptions } from './BaseEnum.js';
28
- export type { BaseItem, BaseItemLight };
29
- export type { DialogMetaDataInternal } from '../ui/dialog/dialog.js';
30
- export type { CellsInput };
31
- export type { Cell, VisibilityMode } from './cellsBuildor.js';
32
- export type { FF_FindOptions } from './storeList.js';
33
- export type { StoreItem };
34
- export type StoreList<T> = ReturnType<typeof storeList<T>>;
35
- export type { ResolvedType, UnArray, RecursivePartial } from '../utils/types.js';
36
- export { FF_Fields } from './FF_Fields.js';
37
- export { FF_Entity } from './FF_Entity.js';
38
- export { FF_LogToConsole } from '../SqlDatabase/FF_LogToConsole.js';
39
- export { BaseEnum } from './BaseEnum.js';
40
- export { dialog } from '../ui/dialog/dialog.js';
41
- export { getEntityDisplayValue, displayWithDefaultAndSuffix, isError, getFieldLinkDisplayValue, getEnum, getEnums, onDelete, } from './helper.js';
42
- export { buildWhere, getPlaceholder, buildSearchWhere, cellsBuildor, cellBuildor, fieldsOf, containsWords, } from './cellsBuildor.js';
43
- export { storeItem };
44
- export { storeList };
45
- export { tw } from '../utils/tailwind.js';
46
- export { FF_Role };
47
- export { FilterEntity } from '../virtual/FilterEntity.js';
48
- export { UIEntity } from '../virtual/UIEntity.js';
49
- export { LibIcon_Empty, LibIcon_Forbidden, LibIcon_ChevronDown, LibIcon_ChevronUp, LibIcon_ChevronLeft, LibIcon_ChevronRight, LibIcon_Search, LibIcon_Check, LibIcon_MultiCheck, LibIcon_Add, LibIcon_MultiAdd, LibIcon_Edit, LibIcon_Delete, LibIcon_Cross, LibIcon_Save, LibIcon_Man, LibIcon_Woman, LibIcon_Send, LibIcon_Load, LibIcon_Settings, LibIcon_Sort, LibIcon_SortAsc, LibIcon_SortDesc, } from '../ui/LibIcon.js';
50
- export type { FF_Icon };
51
- declare module 'remult' {
52
- interface FieldOptions<entityType, valueType> {
53
- placeholder?: string;
54
- suffix?: string;
55
- suffixWithS?: boolean;
56
- suffixEdit?: string;
57
- suffixEditWithS?: boolean;
58
- styleRadioUntil?: number;
59
- step?: '1' | '0.1' | '0.01' | '0.5';
60
- href?: (item: entityType) => string;
61
- findOptionsForEdit?: ((entity: entityType) => FindOptionsBase<valueType>) | FindOptionsBase<valueType>;
62
- findOptionsLimit?: number;
63
- createOptionWhenNoResult?: {
64
- onCreateRequest: (item: entityType, strCreateNew: string) => Parameters<typeof dialog.form>;
65
- onSuccess: (entity: entityType, newItem: any) => Promise<void>;
66
- onError?: () => void;
67
- };
68
- default_select_if_one_item?: boolean;
69
- multiSelect?: boolean;
70
- skipForDefaultField?: boolean;
71
- }
72
- interface EntityOptions<entityType> {
73
- searchableFind?: (str: string) => FindOptionsBase<entityType>;
74
- displayValue?: (item: entityType) => BaseItem;
75
- permissionApiCrud?: BaseEnum[] | BaseEnum;
76
- permissionApiDelete?: BaseEnum[] | BaseEnum;
77
- permissionApiInsert?: BaseEnum[] | BaseEnum;
78
- permissionApiRead?: BaseEnum[] | BaseEnum;
79
- permissionApiUpdate?: BaseEnum[] | BaseEnum;
80
- changeLog?: false | ColumnDeciderArgs<entityType>;
81
- }
82
- }
@@ -1,45 +0,0 @@
1
- import { default as Button } from '../ui/Button.svelte';
2
- import { default as Clipboardable } from '../ui/Clipboardable.svelte';
3
- import { default as DialogManagement } from '../ui/dialog/DialogManagement.svelte';
4
- import { default as FormEditAction } from '../ui/dialog/FormEditAction.svelte';
5
- import { default as Field } from '../ui/Field.svelte';
6
- import { default as FieldGroup } from '../ui/FieldGroup.svelte';
7
- import { default as Grid } from '../ui/Grid.svelte';
8
- import { default as Grid2 } from '../ui/Grid2.svelte';
9
- import { default as GridPaginate } from '../ui/GridPaginate.svelte';
10
- import { default as GridPaginate2 } from '../ui/GridPaginate2.svelte';
11
- import { default as Icon } from '../ui/Icon.svelte';
12
- import { default as FieldContainer } from '../ui/internals/FieldContainer.svelte';
13
- import { default as SelectMelt } from '../ui/internals/select/SelectMelt.svelte';
14
- import { default as Link } from '../ui/link/Link.svelte';
15
- import { default as LinkPlus } from '../ui/link/LinkPlus.svelte';
16
- import { default as Loading } from '../ui/Loading.svelte';
17
- import { default as Tooltip } from '../ui/Tooltip.svelte';
18
- import { FF_Role } from './common.js';
19
- import { storeItem } from './storeItem.js';
20
- import { storeList } from './storeList.js';
21
- // ******************************
22
- // Svelte Components
23
- // ******************************
24
- export { Field, FormEditAction, Grid, Grid2, GridPaginate, GridPaginate2, FieldGroup, Icon, Link, LinkPlus, Loading, Button, Tooltip, DialogManagement, FieldContainer, SelectMelt, Clipboardable, };
25
- // ******************************
26
- // Helpers
27
- // ******************************
28
- export { FF_Fields } from './FF_Fields.js';
29
- export { FF_Entity } from './FF_Entity.js';
30
- export { FF_LogToConsole } from '../SqlDatabase/FF_LogToConsole.js';
31
- export { BaseEnum } from './BaseEnum.js';
32
- export { dialog } from '../ui/dialog/dialog.js';
33
- export { getEntityDisplayValue, displayWithDefaultAndSuffix, isError, getFieldLinkDisplayValue, getEnum, getEnums, onDelete, } from './helper.js';
34
- export { buildWhere, getPlaceholder, buildSearchWhere, cellsBuildor, cellBuildor, fieldsOf, containsWords, } from './cellsBuildor.js';
35
- export { storeItem };
36
- export { storeList };
37
- export { tw } from '../utils/tailwind.js';
38
- export { FF_Role };
39
- // Hummm... I don't know if we should keep it...
40
- export { FilterEntity } from '../virtual/FilterEntity.js';
41
- export { UIEntity } from '../virtual/UIEntity.js';
42
- // ******************************
43
- // Icons
44
- // ******************************
45
- export { LibIcon_Empty, LibIcon_Forbidden, LibIcon_ChevronDown, LibIcon_ChevronUp, LibIcon_ChevronLeft, LibIcon_ChevronRight, LibIcon_Search, LibIcon_Check, LibIcon_MultiCheck, LibIcon_Add, LibIcon_MultiAdd, LibIcon_Edit, LibIcon_Delete, LibIcon_Cross, LibIcon_Save, LibIcon_Man, LibIcon_Woman, LibIcon_Send, LibIcon_Load, LibIcon_Settings, LibIcon_Sort, LibIcon_SortAsc, LibIcon_SortDesc, } from '../ui/LibIcon.js';
@@ -1,28 +0,0 @@
1
- import type { ErrorInfo, FindOptions, Repository } from 'remult';
2
- export type StoreItem<T> = ReturnType<typeof storeItem<T>>;
3
- type TheStoreItem<T> = {
4
- item: T | undefined;
5
- loading?: boolean;
6
- errors: ErrorInfo<T> | undefined;
7
- globalError?: string | undefined;
8
- };
9
- export declare const storeItem: <T>(repo: Repository<T>, initValues?: TheStoreItem<T>) => {
10
- subscribe: (this: void, run: import("svelte/store").Subscriber<TheStoreItem<T>>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
11
- create: (item: Partial<T>) => void;
12
- set: (newItem: TheStoreItem<T>) => void;
13
- /**
14
- * if you have keys, build the id with
15
- * ```ts
16
- * const id = repo.metadata.idMetadata.getId({a:1,b:2})
17
- * store.fetch(id)
18
- * ```
19
- */
20
- fetch: (id: Parameters<Repository<T>["findId"]>[0], options?: FindOptions<T>, onNewData?: (item: T) => void) => Promise<void>;
21
- /**
22
- * `.save()` will `update` or `insert` the current item.
23
- */
24
- save: () => Promise<T | undefined>;
25
- delete: () => Promise<void>;
26
- onChange: (prop: keyof T, callback: (newValue: any, oldValue: any) => void) => void;
27
- };
28
- export {};
@@ -1,176 +0,0 @@
1
- import { BROWSER } from 'esm-env';
2
- import { derived, get, writable } from 'svelte/store';
3
- import { ff_Log } from '../index.js';
4
- import { isError } from './helper.js';
5
- export const storeItem = (repo, initValues = {
6
- item: undefined,
7
- loading: true,
8
- errors: undefined,
9
- globalError: undefined,
10
- }) => {
11
- const internalStore = writable(initValues);
12
- // Function to watch changes on a specific property of `item`
13
- const onChange = (prop, callback) => {
14
- const itemProperty = derived(internalStore, ($s) => $s.item && $s.item[prop]);
15
- let oldValue;
16
- // Subscribe to the derived store to monitor changes
17
- itemProperty.subscribe((newValue) => {
18
- if (newValue !== oldValue) {
19
- if (oldValue !== undefined) {
20
- // to avoid running on initial undefined state
21
- callback(newValue, oldValue);
22
- }
23
- oldValue = newValue;
24
- }
25
- });
26
- };
27
- return {
28
- subscribe: internalStore.subscribe,
29
- create: (item) => {
30
- internalStore.set({
31
- item: repo.create(item),
32
- loading: false,
33
- errors: {},
34
- globalError: undefined,
35
- });
36
- },
37
- // set: internalStore.set,
38
- set: (newItem) => {
39
- internalStore.update((s) => {
40
- return { ...newItem };
41
- });
42
- },
43
- /**
44
- * if you have keys, build the id with
45
- * ```ts
46
- * const id = repo.metadata.idMetadata.getId({a:1,b:2})
47
- * store.fetch(id)
48
- * ```
49
- */
50
- fetch: async (id, options, onNewData) => {
51
- if (BROWSER) {
52
- internalStore.update((s) => ({ ...s, loading: true }));
53
- try {
54
- const item = await repo.findId(id, options);
55
- // lastOptions = options
56
- internalStore.update((s) => ({
57
- ...s,
58
- loading: false,
59
- item: item ?? {},
60
- errors: undefined,
61
- globalError: undefined,
62
- }));
63
- if (onNewData) {
64
- onNewData(item ?? {});
65
- }
66
- }
67
- catch (error) {
68
- if (isError(error)) {
69
- internalStore.update((s) => ({
70
- ...s,
71
- loading: false,
72
- item: {},
73
- errors: {},
74
- // @ts-ignore
75
- globalError: error.message,
76
- }));
77
- }
78
- }
79
- }
80
- },
81
- /**
82
- * `.save()` will `update` or `insert` the current item.
83
- */
84
- save: async () => {
85
- const s = get(internalStore);
86
- try {
87
- if (!s.item) {
88
- return;
89
- }
90
- internalStore.update((s) => ({ ...s, loading: true }));
91
- const item = await repo.save(s.item);
92
- internalStore.update((s) => ({
93
- ...s,
94
- loading: false,
95
- item,
96
- errors: undefined,
97
- globalError: undefined,
98
- }));
99
- return item;
100
- }
101
- catch (error) {
102
- if (isError(error)) {
103
- if (!error.modelState) {
104
- internalStore.update((s) => ({
105
- ...s,
106
- loading: false,
107
- item: s.item,
108
- errors: undefined,
109
- globalError: error.message,
110
- }));
111
- }
112
- else {
113
- const errors = {};
114
- for (const key in error.modelState) {
115
- // @ts-ignore
116
- errors[key] = error.modelState[key];
117
- }
118
- internalStore.update((s) => ({
119
- ...s,
120
- loading: false,
121
- item: s.item,
122
- errors,
123
- globalError: undefined,
124
- }));
125
- }
126
- }
127
- // After we updated everything, let's throw the error
128
- throw error;
129
- }
130
- },
131
- delete: async () => {
132
- const s = get(internalStore);
133
- if (!s.item) {
134
- ff_Log.error(`To delete an item, you need set it first.`);
135
- return;
136
- }
137
- try {
138
- internalStore.update((s) => ({ ...s, loading: true }));
139
- await repo.delete(s.item);
140
- internalStore.update((s) => ({
141
- ...s,
142
- loading: false,
143
- }));
144
- }
145
- catch (error) {
146
- if (isError(error)) {
147
- if (!error.modelState) {
148
- internalStore.update((s) => ({
149
- ...s,
150
- loading: false,
151
- item: s.item,
152
- errors: undefined,
153
- globalError: error.message,
154
- }));
155
- }
156
- else {
157
- const errors = {};
158
- for (const key in error.modelState) {
159
- // @ts-ignore
160
- errors[key] = error.modelState[key];
161
- }
162
- internalStore.update((s) => ({
163
- ...s,
164
- loading: false,
165
- item: s.item,
166
- errors,
167
- globalError: undefined,
168
- }));
169
- }
170
- }
171
- throw error;
172
- }
173
- },
174
- onChange,
175
- };
176
- };