firstly 0.0.1 → 0.0.2

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 (156) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +18 -0
  3. package/README.md +12 -0
  4. package/esm/KitBaseEnum.d.ts +35 -0
  5. package/esm/KitBaseEnum.js +32 -0
  6. package/esm/KitEntity.d.ts +2 -0
  7. package/esm/KitEntity.js +24 -0
  8. package/esm/KitFields.d.ts +10 -0
  9. package/esm/KitFields.js +196 -0
  10. package/esm/ROUTES.d.ts +88 -0
  11. package/esm/ROUTES.js +98 -0
  12. package/esm/SqlDatabase/LogToConsoleCustom.d.ts +1 -0
  13. package/esm/SqlDatabase/LogToConsoleCustom.js +102 -0
  14. package/esm/api/index.d.ts +42 -0
  15. package/esm/api/index.js +97 -0
  16. package/esm/auth/Adapter.d.ts +10 -0
  17. package/esm/auth/Adapter.js +54 -0
  18. package/esm/auth/AuthController.d.ts +59 -0
  19. package/esm/auth/AuthController.js +434 -0
  20. package/esm/auth/Entities.d.ts +39 -0
  21. package/esm/auth/Entities.js +154 -0
  22. package/esm/auth/RoleController.d.ts +14 -0
  23. package/esm/auth/RoleController.js +57 -0
  24. package/esm/auth/helper.d.ts +1 -0
  25. package/esm/auth/helper.js +7 -0
  26. package/esm/auth/index.d.ts +153 -0
  27. package/esm/auth/index.js +279 -0
  28. package/esm/auth/providers/github.d.ts +25 -0
  29. package/esm/auth/providers/github.js +51 -0
  30. package/esm/auth/providers/index.d.ts +3 -0
  31. package/esm/auth/providers/index.js +26 -0
  32. package/esm/auth/providers/strava.d.ts +25 -0
  33. package/esm/auth/providers/strava.js +51 -0
  34. package/esm/auth/static/assets/Page-BMFREPjF.d.ts +5 -0
  35. package/esm/auth/static/assets/Page-BMFREPjF.js +18 -0
  36. package/esm/auth/static/assets/Page-BMOLAIFx.d.ts +5 -0
  37. package/esm/auth/static/assets/Page-BMOLAIFx.js +1 -0
  38. package/esm/auth/static/assets/Page-BwHye0GW.d.ts +5 -0
  39. package/esm/auth/static/assets/Page-BwHye0GW.js +1 -0
  40. package/esm/auth/static/assets/Page-gV58jf2r.css +1 -0
  41. package/esm/auth/static/assets/index-CKmKKRRL.d.ts +53 -0
  42. package/esm/auth/static/assets/index-CKmKKRRL.js +2 -0
  43. package/esm/auth/static/assets/index-R27C_TlP.css +4 -0
  44. package/esm/auth/static/favicon.svg +79 -0
  45. package/esm/auth/static/index.html +14 -0
  46. package/esm/auth/types.d.ts +33 -0
  47. package/esm/auth/types.js +1 -0
  48. package/esm/bin/cmd.d.ts +1 -0
  49. package/esm/bin/cmd.js +408 -0
  50. package/esm/changeLog/index.d.ts +55 -0
  51. package/esm/changeLog/index.js +179 -0
  52. package/esm/cron/index.d.ts +60 -0
  53. package/esm/cron/index.js +102 -0
  54. package/esm/feedback/FeedbackController.d.ts +30 -0
  55. package/esm/feedback/FeedbackController.js +313 -0
  56. package/esm/feedback/index.d.ts +18 -0
  57. package/esm/feedback/index.js +14 -0
  58. package/esm/feedback/ui/DialogIssue.svelte +102 -0
  59. package/esm/feedback/ui/DialogIssue.svelte.d.ts +20 -0
  60. package/esm/feedback/ui/DialogIssues.svelte +91 -0
  61. package/esm/feedback/ui/DialogIssues.svelte.d.ts +20 -0
  62. package/esm/feedback/ui/DialogMilestones.svelte +38 -0
  63. package/esm/feedback/ui/DialogMilestones.svelte.d.ts +18 -0
  64. package/esm/feedback/ui/Feedback.svelte +12 -0
  65. package/esm/feedback/ui/Feedback.svelte.d.ts +16 -0
  66. package/esm/formats/dates.d.ts +18 -0
  67. package/esm/formats/dates.js +35 -0
  68. package/esm/formats/index.d.ts +4 -0
  69. package/esm/formats/index.js +3 -0
  70. package/esm/formats/numbers.d.ts +4 -0
  71. package/esm/formats/numbers.js +34 -0
  72. package/esm/formats/strings.d.ts +11 -0
  73. package/esm/formats/strings.js +109 -0
  74. package/esm/handle/index.d.ts +7 -0
  75. package/esm/handle/index.js +40 -0
  76. package/esm/helper.d.ts +50 -0
  77. package/esm/helper.js +118 -0
  78. package/esm/index.d.ts +103 -0
  79. package/esm/index.js +42 -0
  80. package/esm/kitCellsBuildor.d.ts +45 -0
  81. package/esm/kitCellsBuildor.js +105 -0
  82. package/esm/kitStoreItem.d.ts +28 -0
  83. package/esm/kitStoreItem.js +170 -0
  84. package/esm/kitStoreList.d.ts +33 -0
  85. package/esm/kitStoreList.js +98 -0
  86. package/esm/mail/index.d.ts +11 -0
  87. package/esm/mail/index.js +51 -0
  88. package/esm/theme.d.ts +4 -0
  89. package/esm/theme.js +4 -0
  90. package/esm/ui/Button.svelte +102 -0
  91. package/esm/ui/Button.svelte.d.ts +27 -0
  92. package/esm/ui/Clipboardable.svelte +19 -0
  93. package/esm/ui/Clipboardable.svelte.d.ts +25 -0
  94. package/esm/ui/Field.svelte +288 -0
  95. package/esm/ui/Field.svelte.d.ts +29 -0
  96. package/esm/ui/FieldGroup.svelte +91 -0
  97. package/esm/ui/FieldGroup.svelte.d.ts +30 -0
  98. package/esm/ui/Grid.svelte +246 -0
  99. package/esm/ui/Grid.svelte.d.ts +46 -0
  100. package/esm/ui/GridLoading.svelte +32 -0
  101. package/esm/ui/GridLoading.svelte.d.ts +20 -0
  102. package/esm/ui/GridPaginate.svelte +66 -0
  103. package/esm/ui/GridPaginate.svelte.d.ts +22 -0
  104. package/esm/ui/Icon.svelte +86 -0
  105. package/esm/ui/Icon.svelte.d.ts +46 -0
  106. package/esm/ui/LibIcon.d.ts +23 -0
  107. package/esm/ui/LibIcon.js +28 -0
  108. package/esm/ui/Loading.svelte +11 -0
  109. package/esm/ui/Loading.svelte.d.ts +20 -0
  110. package/esm/ui/Tooltip.svelte +42 -0
  111. package/esm/ui/Tooltip.svelte.d.ts +22 -0
  112. package/esm/ui/dialog/DialogForm.svelte +70 -0
  113. package/esm/ui/dialog/DialogForm.svelte.d.ts +19 -0
  114. package/esm/ui/dialog/DialogManagement.svelte +87 -0
  115. package/esm/ui/dialog/DialogManagement.svelte.d.ts +25 -0
  116. package/esm/ui/dialog/DialogPrimitive.svelte +89 -0
  117. package/esm/ui/dialog/DialogPrimitive.svelte.d.ts +28 -0
  118. package/esm/ui/dialog/FormEditAction.svelte +54 -0
  119. package/esm/ui/dialog/FormEditAction.svelte.d.ts +24 -0
  120. package/esm/ui/dialog/dialog.d.ts +51 -0
  121. package/esm/ui/dialog/dialog.js +98 -0
  122. package/esm/ui/index.d.ts +5 -0
  123. package/esm/ui/index.js +19 -0
  124. package/esm/ui/internals/FieldContainer.svelte +22 -0
  125. package/esm/ui/internals/FieldContainer.svelte.d.ts +30 -0
  126. package/esm/ui/internals/Input.svelte +98 -0
  127. package/esm/ui/internals/Input.svelte.d.ts +35 -0
  128. package/esm/ui/internals/Textarea.svelte +61 -0
  129. package/esm/ui/internals/Textarea.svelte.d.ts +30 -0
  130. package/esm/ui/internals/select/MultiSelectMelt.svelte +217 -0
  131. package/esm/ui/internals/select/MultiSelectMelt.svelte.d.ts +30 -0
  132. package/esm/ui/internals/select/SelectMelt.svelte +238 -0
  133. package/esm/ui/internals/select/SelectMelt.svelte.d.ts +35 -0
  134. package/esm/ui/internals/select/SelectRadio.svelte +37 -0
  135. package/esm/ui/internals/select/SelectRadio.svelte.d.ts +25 -0
  136. package/esm/ui/link/Link.svelte +28 -0
  137. package/esm/ui/link/Link.svelte.d.ts +25 -0
  138. package/esm/ui/link/LinkPlus.svelte +44 -0
  139. package/esm/ui/link/LinkPlus.svelte.d.ts +21 -0
  140. package/esm/utils/tailwind.d.ts +2 -0
  141. package/esm/utils/tailwind.js +3 -0
  142. package/esm/utils/transition.d.ts +10 -0
  143. package/esm/utils/transition.js +33 -0
  144. package/esm/utils/types.d.ts +17 -0
  145. package/esm/utils/types.js +17 -0
  146. package/esm/virtual/Customer.d.ts +4 -0
  147. package/esm/virtual/Customer.js +24 -0
  148. package/esm/virtual/FilterEntity.d.ts +7 -0
  149. package/esm/virtual/FilterEntity.js +34 -0
  150. package/esm/virtual/StateDemoEnum.d.ts +9 -0
  151. package/esm/virtual/StateDemoEnum.js +42 -0
  152. package/esm/virtual/UIEntity.d.ts +16 -0
  153. package/esm/virtual/UIEntity.js +84 -0
  154. package/esm/vite/index.d.ts +8 -0
  155. package/esm/vite/index.js +47 -0
  156. package/package.json +94 -10
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ dialogId: number;
5
+ milestoneNumber: number;
6
+ milestoneId: string;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {};
12
+ exports?: {} | undefined;
13
+ bindings?: string | undefined;
14
+ };
15
+ export type DialogIssuesProps = typeof __propDef.props;
16
+ export type DialogIssuesEvents = typeof __propDef.events;
17
+ export type DialogIssuesSlots = typeof __propDef.slots;
18
+ export default class DialogIssues extends SvelteComponent<DialogIssuesProps, DialogIssuesEvents, DialogIssuesSlots> {
19
+ }
20
+ export {};
@@ -0,0 +1,38 @@
1
+ <script>import { onMount } from "svelte";
2
+ import { FeedbackController } from "..";
3
+ import { Button, dialog, Loading } from "../..";
4
+ import DialogIssues from "./DialogIssues.svelte";
5
+ export let dialogId;
6
+ const rmvWarning = dialogId;
7
+ let state = "loading";
8
+ let milestones = [];
9
+ onMount(async () => {
10
+ milestones = await FeedbackController.getMilestones();
11
+ state = "done";
12
+ });
13
+ </script>
14
+
15
+ <div class="mb-4 grid gap-4">
16
+ {#each milestones as milestone}
17
+ <Button
18
+ on:click={() =>
19
+ dialog.show({
20
+ component: DialogIssues,
21
+ classes: { root: 'overflow-auto w-5/6 h-5/6' },
22
+ props: { milestoneNumber: milestone.number, milestoneId: milestone.id },
23
+ detail: { caption: milestone.title },
24
+ })}
25
+ class="btn-neutral"
26
+ >
27
+ {milestone.title}
28
+ </Button>
29
+ {:else}
30
+ {#if state === 'loading'}
31
+ <Loading class="h-12"></Loading>
32
+ <Loading class="h-12"></Loading>
33
+ <Loading class="h-12"></Loading>
34
+ {:else}
35
+ <p>No milestones found / Filter too strict!</p>
36
+ {/if}
37
+ {/each}
38
+ </div>
@@ -0,0 +1,18 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ dialogId: number;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ exports?: {} | undefined;
11
+ bindings?: string | undefined;
12
+ };
13
+ export type DialogMilestonesProps = typeof __propDef.props;
14
+ export type DialogMilestonesEvents = typeof __propDef.events;
15
+ export type DialogMilestonesSlots = typeof __propDef.slots;
16
+ export default class DialogMilestones extends SvelteComponent<DialogMilestonesProps, DialogMilestonesEvents, DialogMilestonesSlots> {
17
+ }
18
+ export {};
@@ -0,0 +1,12 @@
1
+ <script>import { dialog } from "../../";
2
+ import DialogMilestones from "./DialogMilestones.svelte";
3
+ const list = async () => {
4
+ await dialog.show({
5
+ component: DialogMilestones,
6
+ classes: { root: "overflow-auto w-5/6 h-5/6" },
7
+ detail: { caption: "Feedback" }
8
+ });
9
+ };
10
+ </script>
11
+
12
+ <button class="text-secondary" on:click={list}>Feedback</button>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {};
8
+ exports?: {} | undefined;
9
+ bindings?: string | undefined;
10
+ };
11
+ export type FeedbackProps = typeof __propDef.props;
12
+ export type FeedbackEvents = typeof __propDef.events;
13
+ export type FeedbackSlots = typeof __propDef.slots;
14
+ export default class Feedback extends SvelteComponent<FeedbackProps, FeedbackEvents, FeedbackSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,18 @@
1
+ export declare const dateISOToPlainDate: (iso: string) => string;
2
+ export declare const offsetedToPlainDate: (dt: Date) => string;
3
+ export type KitPlainDateRange = {
4
+ from: string;
5
+ to: string;
6
+ };
7
+ /**
8
+ * in `range`, `from` is inclusive and `to` is exclusive
9
+ */
10
+ export declare const isBetween: (dt: string, range: KitPlainDateRange) => boolean;
11
+ export declare const plainDateCompare: (dt: string, op: {
12
+ $gt?: string;
13
+ /** From */
14
+ $gte?: string;
15
+ /** to */
16
+ $lt?: string;
17
+ $lte?: string;
18
+ }) => boolean;
@@ -0,0 +1,35 @@
1
+ import { logFirstly } from '../';
2
+ export const dateISOToPlainDate = (iso) => {
3
+ try {
4
+ // const ti = Temporal.Instant.from(iso)
5
+ // return ti.toZonedDateTimeISO('UTC').toPlainDate()
6
+ if (iso.includes('T')) {
7
+ return iso.split('T')[0];
8
+ }
9
+ }
10
+ catch (error) { }
11
+ const msg = `fn dateISOToPlainDate -> "${iso}" is not valid iso`;
12
+ logFirstly.error(msg);
13
+ throw new Error(msg);
14
+ };
15
+ export const offsetedToPlainDate = (dt) => {
16
+ const userTimezoneOffset = dt.getTimezoneOffset() * 60000;
17
+ const adjustedDate = new Date(dt.getTime() - userTimezoneOffset);
18
+ return adjustedDate.toISOString().split('T')[0];
19
+ // Huge performance issue! (check: filterAndRowSpan)
20
+ // const ti = Temporal.Instant.from(adjustedDate.toISOString())
21
+ // return ti.toZonedDateTimeISO('UTC').toPlainDate()
22
+ };
23
+ /**
24
+ * in `range`, `from` is inclusive and `to` is exclusive
25
+ */
26
+ export const isBetween = (dt, range) => {
27
+ return plainDateCompare(dt, { $gte: range.from, $lt: range.to });
28
+ };
29
+ export const plainDateCompare = (dt, op) => {
30
+ const gt = op.$gt ? new Date(op.$gt) < new Date(dt) : true;
31
+ const gte = op.$gte ? new Date(op.$gte) <= new Date(dt) : true;
32
+ const lt = op.$lt ? new Date(dt) < new Date(op.$lt) : true;
33
+ const lte = op.$lte ? new Date(dt) <= new Date(op.$lte) : true;
34
+ return gt && gte && lt && lte;
35
+ };
@@ -0,0 +1,4 @@
1
+ export { displayCurrency, displayCurrencyK, displayPercent, displayCurrencyWOSuffix, } from './numbers.js';
2
+ export { formatNumber, extractMailInfo } from './strings.js';
3
+ export { offsetedToPlainDate, plainDateCompare, isBetween, dateISOToPlainDate } from './dates.js';
4
+ export type { KitPlainDateRange } from './dates.js';
@@ -0,0 +1,3 @@
1
+ export { displayCurrency, displayCurrencyK, displayPercent, displayCurrencyWOSuffix, } from './numbers.js';
2
+ export { formatNumber, extractMailInfo } from './strings.js';
3
+ export { offsetedToPlainDate, plainDateCompare, isBetween, dateISOToPlainDate } from './dates.js';
@@ -0,0 +1,4 @@
1
+ export declare function displayCurrencyWOSuffix(_entity: any, value: number | undefined): string;
2
+ export declare function displayCurrency(_entity: any, value: number | undefined): string;
3
+ export declare function displayCurrencyK(_entity: any, value: number | undefined): string;
4
+ export declare function displayPercent(value: number | undefined): string;
@@ -0,0 +1,34 @@
1
+ import { formatNumber } from './strings.js';
2
+ export function displayCurrencyWOSuffix(_entity, value) {
3
+ if (value === undefined)
4
+ return '-';
5
+ return new Intl.NumberFormat('fr', { currency: 'EUR', style: 'currency' })
6
+ .format(value ?? 0)
7
+ .replace('€', '')
8
+ .trim();
9
+ }
10
+ export function displayCurrency(_entity, value) {
11
+ if (value === undefined)
12
+ return '- €';
13
+ return new Intl.NumberFormat('fr', { currency: 'EUR', style: 'currency' }).format(value ?? 0);
14
+ }
15
+ export function displayCurrencyK(_entity, value) {
16
+ if (value === undefined)
17
+ return '- €';
18
+ if (Math.abs(value) < 1000) {
19
+ return displayCurrency(_entity, value);
20
+ }
21
+ return new Intl.NumberFormat('fr', {
22
+ currency: 'EUR',
23
+ style: 'currency',
24
+ maximumFractionDigits: 0,
25
+ })
26
+ .format(value / 1000)
27
+ .replace('€', 'k€');
28
+ }
29
+ export function displayPercent(value) {
30
+ if (value === undefined) {
31
+ return '- %';
32
+ }
33
+ return formatNumber(value) + ' %';
34
+ }
@@ -0,0 +1,11 @@
1
+ export declare const formatNumber: (number: number, digitNumber?: number) => string;
2
+ export declare function displayPhone(_entity: any, value: string | undefined): string;
3
+ export declare const arrToStr: (arr: string | undefined | (string | undefined)[]) => string;
4
+ export declare const mask: (str: string | undefined) => string;
5
+ export declare const suffixWithS: (value: number, str: string) => string;
6
+ export declare const toTitleCase: (str: string) => string;
7
+ export declare const extractMailInfo: (mail: string, withThrow?: boolean) => {
8
+ firstName: string;
9
+ lastName: string;
10
+ email: string;
11
+ };
@@ -0,0 +1,109 @@
1
+ export const formatNumber = (number, digitNumber = 2) => {
2
+ if (number === undefined || number === null || isNaN(number)) {
3
+ const value = 0;
4
+ return value.toFixed(digitNumber);
5
+ }
6
+ return number
7
+ .toFixed(digitNumber) // decimal digits
8
+ .replace('.', ',') // replace decimal point character with ,
9
+ .replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ');
10
+ };
11
+ export function displayPhone(_entity, value) {
12
+ return formatPhone(value ?? '');
13
+ }
14
+ const formatPhone = (phone) => {
15
+ if (!phone) {
16
+ return '';
17
+ }
18
+ return phone;
19
+ // TODO: Let's be smart one day... and add a ton of tests!
20
+ // const replaced = phone.replaceAll(' ', '').replaceAll('.', '')
21
+ // let formatted: string = replaced
22
+ // if (replaced.charAt(0) === '+') {
23
+ // return formatted
24
+ // } else if (replaced.slice(0, 2) === '00') {
25
+ // return `+${formatted.slice(2)}`
26
+ // } else if (replaced.length > 10) {
27
+ // formatted = replaced.slice(0, 10)
28
+ // }
29
+ // return `+33${formatted.slice(1)}`
30
+ };
31
+ export const arrToStr = (arr) => {
32
+ if (!arr)
33
+ return '';
34
+ if (typeof arr === 'string')
35
+ return arr;
36
+ return arr.filter((c) => c).join(' - ');
37
+ };
38
+ export const mask = (str) => {
39
+ if (str === undefined)
40
+ return '';
41
+ return str.slice(0, -4).replace(/./g, '*') + str.slice(-4);
42
+ };
43
+ export const suffixWithS = (value, str) => {
44
+ if (value) {
45
+ if (value <= 1) {
46
+ return `${str}`;
47
+ }
48
+ else {
49
+ if (str.endsWith('²')) {
50
+ return `${str}`;
51
+ }
52
+ else {
53
+ return `${str}s`;
54
+ }
55
+ }
56
+ }
57
+ else {
58
+ return `${str}`;
59
+ }
60
+ };
61
+ export const toTitleCase = (str) => {
62
+ // Replace dashes and underscores with spaces
63
+ const stringWithSpaces = str.replace(/[-_]/g, ' ');
64
+ // Add a space before each capital letter (for camelCase)
65
+ const titleCaseString = stringWithSpaces.replace(/([a-z])([A-Z])/g, '$1 $2');
66
+ // Capitalize the first letter of each word and join them back
67
+ const words = titleCaseString.split(' ');
68
+ const titleCaseWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
69
+ return titleCaseWords.join(' ');
70
+ };
71
+ const rmvChars = (str, chars = ['<', '>', ',']) => {
72
+ return chars.reduce((acc, char) => acc.replaceAll(char, ''), str).trim();
73
+ };
74
+ export const extractMailInfo = (mail, withThrow = true) => {
75
+ if (!mail) {
76
+ if (withThrow) {
77
+ throw new Error('No mail provided');
78
+ }
79
+ return {
80
+ firstName: '',
81
+ lastName: '',
82
+ email: '',
83
+ };
84
+ }
85
+ const regex = /(.+)\s(.+)\s<(.+)>/i;
86
+ const match = mail.match(regex);
87
+ if (match) {
88
+ const firstName = toTitleCase(rmvChars(match[1].trim())).replaceAll(' ', '-');
89
+ const lastName = rmvChars(match[2].trim()).toUpperCase();
90
+ const email = rmvChars(match[3]).toLowerCase();
91
+ return { firstName, lastName, email };
92
+ }
93
+ if (mail.includes('@')) {
94
+ const clean = rmvChars(mail);
95
+ const [left] = clean.split('@');
96
+ const names = left.split('.');
97
+ return {
98
+ firstName: names.length > 1 ? toTitleCase(names[0]).replaceAll(' ', '-') : '',
99
+ lastName: (names.length > 1 ? names[1] : names[0]).toUpperCase(),
100
+ email: rmvChars(mail).toLowerCase(),
101
+ };
102
+ }
103
+ const clean = rmvChars(mail);
104
+ return {
105
+ firstName: '',
106
+ lastName: clean,
107
+ email: '',
108
+ };
109
+ };
@@ -0,0 +1,7 @@
1
+ import type { Handle } from '@sveltejs/kit';
2
+ import type { RemultSveltekitServer } from 'remult/remult-sveltekit';
3
+ import type { Module } from '../api';
4
+ export declare const firstly: (api: {
5
+ server: RemultSveltekitServer;
6
+ modulesSorted: Module[];
7
+ }) => Handle;
@@ -0,0 +1,40 @@
1
+ import { sequence } from '@sveltejs/kit/hooks';
2
+ // const log = new Log('firstly')
3
+ /**
4
+ * to bring `remult.` on the server side (after this hook, you have assess to `remult.user` for example !)
5
+ */
6
+ const internalRemultHandle = (api, modules) => async (h) => {
7
+ return await api.withRemult(h.event, async () => {
8
+ if (modules !== undefined) {
9
+ for (let i = 0; i < modules.length; i++) {
10
+ const early = modules[i].earlyReturn;
11
+ if (early) {
12
+ const ret = await early(h);
13
+ if (ret.early) {
14
+ return ret.resolve;
15
+ }
16
+ }
17
+ }
18
+ }
19
+ return await h.resolve(h.event);
20
+ });
21
+ };
22
+ export const firstly = ({ server, modulesSorted }) => {
23
+ const handlesPre = [];
24
+ const handlesPost = [];
25
+ for (let i = 0; i < modulesSorted.length; i++) {
26
+ if (modulesSorted[i].handlePreRemult) {
27
+ handlesPre.push(modulesSorted[i].handlePreRemult);
28
+ }
29
+ if (modulesSorted[i].handlePosRemult) {
30
+ handlesPost.push(modulesSorted[i].handlePosRemult);
31
+ }
32
+ }
33
+ return sequence(
34
+ // First
35
+ sequence(...handlesPre),
36
+ // Then
37
+ internalRemultHandle(server, modulesSorted),
38
+ // Finally
39
+ sequence(...handlesPost));
40
+ };
@@ -0,0 +1,50 @@
1
+ import { type ErrorInfo, type FieldMetadata, type Repository } from 'remult';
2
+ import { type KitBaseItem } 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) => KitBaseItem;
6
+ export declare const getFieldLinkDisplayValue: (field: FieldMetadata, row: any) => import("./KitBaseEnum.js").KitBaseEnumOptions & {
7
+ id: string;
8
+ captionSub?: string | (string | undefined)[] | undefined;
9
+ href?: string | undefined;
10
+ repo?: Repository<any> | undefined;
11
+ sub?: {
12
+ captionPre?: string | undefined;
13
+ repo?: Repository<any> | undefined;
14
+ item?: any;
15
+ } | undefined;
16
+ } & {
17
+ href: string;
18
+ };
19
+ export declare const getEntityDisplayValueFromField: (field: FieldMetadata, row: any) => KitBaseItem & {
20
+ href: string;
21
+ };
22
+ export type MetaTypeRelation = {
23
+ kind: 'relation';
24
+ subKind: 'reference' | 'toOne' | 'toMany';
25
+ repoTarget: Repository<any>;
26
+ field: FieldMetadata;
27
+ };
28
+ type MetaTypeEnum = {
29
+ kind: 'enum';
30
+ subKind: 'single' | 'multi';
31
+ values: KitBaseItem[];
32
+ field: FieldMetadata;
33
+ };
34
+ type MetaTypePrimitive = {
35
+ kind: 'primitive';
36
+ subKind: string;
37
+ field: FieldMetadata;
38
+ };
39
+ type MetaTypeSlot = {
40
+ kind: 'slot';
41
+ subKind: '???';
42
+ };
43
+ export type FieldMetaType = MetaTypeRelation | MetaTypeEnum | MetaTypePrimitive | MetaTypeSlot;
44
+ export declare const getFieldMetaType: (field?: FieldMetadata) => FieldMetaType;
45
+ export declare const displayWithDefaultAndSuffix: (field: FieldMetadata<any, any> | undefined, value: any) => string;
46
+ /**
47
+ * same as `dbNamesOf` but with `tableName` set to `true` by default
48
+ */
49
+ export declare const kitDbNamesOf: <Entity>(repo: import("remult/src/remult3/RepositoryImplementation.js").EntityMetadataOverloads<Entity>, wrapIdentifierOrOptions?: ((name: string) => string) | import("remult").dbNamesOfOptions | undefined) => Promise<import("remult").EntityDbNames<Entity>>;
50
+ export {};
package/esm/helper.js ADDED
@@ -0,0 +1,118 @@
1
+ import { dbNamesOf, getEntityRef, } from 'remult';
2
+ import { getRelationFieldInfo } from 'remult/internals';
3
+ import { suffixWithS } from './formats/strings.js';
4
+ import {} from './index.js';
5
+ export function isError(object) {
6
+ return object;
7
+ }
8
+ export const getFirstInterestingField = (repo) => {
9
+ const fields = repo.metadata.fields.toArray();
10
+ for (let i = 0; i < fields.length; i++) {
11
+ // Let's find the most relevant field to display...
12
+ if (fields[i].key !== 'id' &&
13
+ fields[i].key !== 'createdAt' &&
14
+ fields[i].options.skipForDefaultField !== true) {
15
+ return fields[i];
16
+ }
17
+ }
18
+ return fields[0];
19
+ };
20
+ export const getEntityDisplayValue = (repo, row) => {
21
+ if (repo.metadata.options.displayValue) {
22
+ return repo.metadata.options.displayValue(row);
23
+ }
24
+ const field = getFirstInterestingField(repo);
25
+ // REMULT P3 JYC: If it's an enum, it's not working...
26
+ return { caption: row ? field.displayValue(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) => {
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: getEnums(field.target) as KitBaseItem[],
64
+ // @ts-ignore
65
+ values: field.options.valueConverter.values,
66
+ field,
67
+ };
68
+ }
69
+ // REMULT P2 JYC: Any idea to know if it's an enum? and extract values?
70
+ // const ttt = getValueList(field)
71
+ // console.log(`ttt`, ttt)
72
+ // Error: ValueType not yet initialized, did you forget to call @ValueListFieldType on function String()
73
+ // is it an enum?
74
+ // @ts-ignore
75
+ if (field.options?.valueConverter?.values) {
76
+ // console.log(`field.options.valueConverter.values`, field.options.valueConverter.values)
77
+ return {
78
+ kind: 'enum',
79
+ subKind: 'single',
80
+ // @ts-ignore
81
+ values: field.options.valueConverter.values,
82
+ field,
83
+ };
84
+ }
85
+ // it's a primitive
86
+ return { kind: 'primitive', subKind: field.inputType ?? 'text', field };
87
+ };
88
+ export const displayWithDefaultAndSuffix = (field, value) => {
89
+ const toRet = [];
90
+ // TODO: This method should be reviewed. Specifically, server expression & Field.date have
91
+ // valueConverter by defualt, so we can't use displayValue if checking for valueConverter
92
+ // Hummm... JYC: I didn't understand the above comment.
93
+ if (field && field.valueConverter?.displayValue && !field.isServerExpression) {
94
+ toRet.push(field.valueConverter?.displayValue(value) ?? '-');
95
+ }
96
+ else {
97
+ // toRet.push(value ?? '-')
98
+ toRet.push(field?.displayValue ? field?.displayValue({ [field.key]: value }) : value ?? '-');
99
+ }
100
+ if (value === undefined || value === null) {
101
+ return '';
102
+ }
103
+ if (field?.options.suffix) {
104
+ if (field.options.suffixWithS) {
105
+ toRet.push(suffixWithS(value, field.options.suffix));
106
+ }
107
+ else {
108
+ toRet.push(field.options.suffix);
109
+ }
110
+ }
111
+ return toRet.join(' ');
112
+ };
113
+ /**
114
+ * same as `dbNamesOf` but with `tableName` set to `true` by default
115
+ */
116
+ export const kitDbNamesOf = async (...p) => {
117
+ return dbNamesOf(p[0], { tableName: true, ...p[1] });
118
+ };
package/esm/index.d.ts ADDED
@@ -0,0 +1,103 @@
1
+ import type { FindOptionsBase, Repository } from 'remult';
2
+ import 'remult';
3
+ import type { RequestEvent } from '@sveltejs/kit';
4
+ import { Log } from '@kitql/helpers';
5
+ import type { KitBaseEnum, KitBaseEnumOptions, KitIcon } from './KitBaseEnum.js';
6
+ import type { KitCellsInput as KitCellsInputForExport } from './kitCellsBuildor.js';
7
+ import { kitStoreItem } from './kitStoreItem.js';
8
+ import { kitStoreList } from './kitStoreList.js';
9
+ import { default as Button } from './ui/Button.svelte';
10
+ import { default as Clipboardable } from './ui/Clipboardable.svelte';
11
+ import { default as DialogManagement } from './ui/dialog/DialogManagement.svelte';
12
+ import { default as FormEditAction } from './ui/dialog/FormEditAction.svelte';
13
+ import { default as Field } from './ui/Field.svelte';
14
+ import { default as FieldGroup } from './ui/FieldGroup.svelte';
15
+ import { default as Grid } from './ui/Grid.svelte';
16
+ import { default as GridPaginate } from './ui/GridPaginate.svelte';
17
+ import { default as Icon } from './ui/Icon.svelte';
18
+ import { default as FieldContainer } from './ui/internals/FieldContainer.svelte';
19
+ import { default as SelectMelt } from './ui/internals/select/SelectMelt.svelte';
20
+ import { default as Link } from './ui/link/Link.svelte';
21
+ import { default as LinkPlus } from './ui/link/LinkPlus.svelte';
22
+ import { default as Loading } from './ui/Loading.svelte';
23
+ import { default as Tooltip } from './ui/Tooltip.svelte';
24
+ export declare const logFirstly: Log;
25
+ export declare const KitRole: {
26
+ Admin: string;
27
+ };
28
+ export { Field, FormEditAction, Grid, GridPaginate, FieldGroup, Icon, Link, LinkPlus, Loading, Button, Tooltip, DialogManagement, FieldContainer, SelectMelt, Clipboardable, };
29
+ export { dialog } from './ui/dialog/dialog.js';
30
+ export type { DialogMetaDataInternal } from './ui/dialog/dialog.js';
31
+ export { KitBaseEnum, getEnum, getEnums } from './KitBaseEnum.js';
32
+ export type { KitBaseEnumOptions } from './KitBaseEnum.js';
33
+ export { KitFields } from './KitFields.js';
34
+ export { KitEntity } from './KitEntity.js';
35
+ export { LogToConsoleCustom } from './SqlDatabase/LogToConsoleCustom.js';
36
+ export { getEntityDisplayValue, isError, kitDbNamesOf, getFieldLinkDisplayValue } from './helper.js';
37
+ export { buildWhere, getPlaceholder, buildSearchWhere, kitCellsBuildor, kitCellBuildor, fieldsOf, } from './kitCellsBuildor.js';
38
+ export { kitStoreItem };
39
+ export { kitStoreList };
40
+ export type KitCellsInput<entityType> = KitCellsInputForExport<entityType>;
41
+ export type { KitCell, VisibilityMode } from './kitCellsBuildor.js';
42
+ export type { FindOptionsPlus } from './kitStoreList.js';
43
+ export type KitBaseItem = KitBaseEnumOptions & {
44
+ id: string;
45
+ captionSub?: string | (string | undefined)[];
46
+ href?: string;
47
+ repo?: Repository<any>;
48
+ sub?: {
49
+ captionPre?: string;
50
+ repo?: Repository<any>;
51
+ item?: any;
52
+ };
53
+ };
54
+ export type KitStoreItem<T> = ReturnType<typeof kitStoreItem<T>>;
55
+ export type KitStoreList<T> = ReturnType<typeof kitStoreList<T>>;
56
+ export type KitBaseItemLight = Partial<KitBaseItem>;
57
+ export { FilterEntity } from './virtual/FilterEntity.js';
58
+ export { UIEntity } from './virtual/UIEntity.js';
59
+ 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';
60
+ export type { KitIcon };
61
+ export { displayPhone, arrToStr } from './formats/strings.js';
62
+ export { displayCurrency } from './formats/numbers.js';
63
+ export { tw } from './utils/tailwind.js';
64
+ export { litOrStr } from './utils/types.js';
65
+ export type { ResolvedType, UnArray } from './utils/types.js';
66
+ declare module 'remult' {
67
+ interface RemultContext {
68
+ url: URL;
69
+ setHeaders(headers: Record<string, string>): void;
70
+ setCookie(...args: Parameters<RequestEvent['cookies']['set']>): void;
71
+ deleteCookie(...args: Parameters<RequestEvent['cookies']['delete']>): void;
72
+ }
73
+ interface FieldOptions<entityType, valueType> {
74
+ placeholder?: string;
75
+ suffix?: string;
76
+ suffixWithS?: boolean;
77
+ suffixEdit?: string;
78
+ suffixEditWithS?: boolean;
79
+ styleRadioUntil?: number;
80
+ step?: '1' | '0.1' | '0.01';
81
+ href?: (item: entityType) => string;
82
+ findOptionsForEdit?: ((entity: entityType) => FindOptionsBase<valueType>) | FindOptionsBase<valueType>;
83
+ findOptionsLimit?: number;
84
+ createOptionWhenNoResult?: boolean;
85
+ multiSelect?: boolean;
86
+ skipForDefaultField?: boolean;
87
+ }
88
+ interface EntityOptions<entityType> {
89
+ searchableFind?: (str: string) => FindOptionsBase<entityType>;
90
+ displayValue?: (item: entityType) => KitBaseItem;
91
+ permissionApiCrud?: KitBaseEnum[] | KitBaseEnum;
92
+ permissionApiDelete?: KitBaseEnum[] | KitBaseEnum;
93
+ permissionApiInsert?: KitBaseEnum[] | KitBaseEnum;
94
+ permissionApiRead?: KitBaseEnum[] | KitBaseEnum;
95
+ permissionApiUpdate?: KitBaseEnum[] | KitBaseEnum;
96
+ }
97
+ interface UserInfo {
98
+ session: {
99
+ id: string;
100
+ expiresAt: Date;
101
+ };
102
+ }
103
+ }