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
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # firstly
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f127fc7`](https://github.com/jycouet/firstly/commit/f127fc78e00f6464d8fbbebc10f3ffb43402fcc3)
8
+ Thanks [@jycouet](https://github.com/jycouet)! - publish firstly for the first time ;)
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2022 Jean-Yves Couët
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the “Software”), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
17
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # ⚡ firstly
2
+
3
+ [![](https://img.shields.io/npm/v/firstly?color=&logo=npm)](https://www.npmjs.com/package/firstly)
4
+ [![](https://img.shields.io/npm/dm/firstly?&logo=npm)](https://www.npmjs.com/package/firstly)
5
+
6
+ ## 📖 Read the doc
7
+
8
+ [![](https://img.shields.io/badge/Documentation%20of-remult%20kit-FF3E00.svg?style=flat&logo=stackblitz&logoColor=FF3E00)](https://firstly.fun)
9
+
10
+ ## ⭐️ Join us
11
+
12
+ [![GitHub Repo stars](https://img.shields.io/github/stars/jycouet/firstly?logo=github&label=firstly&color=#4ACC31)](https://github.com/jycouet/firstly)
@@ -0,0 +1,35 @@
1
+ import { type IdFilter } from 'remult';
2
+ import type { ClassType, FindOptionsBase } from 'remult';
3
+ export type KitIcon = {
4
+ data?: string | string[];
5
+ size?: string | number;
6
+ class?: string | string[];
7
+ style?: string | string[];
8
+ caption?: string;
9
+ };
10
+ export type KitBaseEnumOptions<Entity = any> = {
11
+ caption?: string;
12
+ icon?: KitIcon;
13
+ where?: IdFilter<Entity> | FindOptionsBase<Entity>['where'];
14
+ class?: string;
15
+ };
16
+ export declare class KitBaseEnum<Entity = any> {
17
+ id: string;
18
+ caption?: string;
19
+ icon?: KitIcon;
20
+ where?: IdFilter<Entity> | FindOptionsBase<Entity>['where'];
21
+ class?: string;
22
+ constructor(_id: string | number, options?: KitBaseEnumOptions<Entity>);
23
+ getWhere: () => this | Entity[] | {
24
+ $ne?: Entity | Entity[] | undefined;
25
+ '!='?: Entity | Entity[] | undefined;
26
+ $in?: Entity[] | undefined;
27
+ $nin?: Entity[] | undefined;
28
+ } | {
29
+ $id: import("remult").ValueFilter<Entity extends {
30
+ id?: number | undefined;
31
+ } ? number : string>;
32
+ } | import("remult").EntityFilter<Entity> | NonNullable<Entity>;
33
+ }
34
+ export declare const getEnum: <T extends KitBaseEnum<any>>(baseEnum: ClassType<T>, id: string | undefined | null) => T | undefined;
35
+ export declare const getEnums: <T extends KitBaseEnum<any>>(baseEnum: ClassType<T>) => T[];
@@ -0,0 +1,32 @@
1
+ import { getValueList } from 'remult';
2
+ export class KitBaseEnum {
3
+ id;
4
+ caption;
5
+ icon;
6
+ where;
7
+ class;
8
+ constructor(_id, options) {
9
+ this.id = _id.toString();
10
+ this.caption = options?.caption ?? this.id;
11
+ this.icon = options?.icon;
12
+ this.where = options?.where;
13
+ this.class = options?.class;
14
+ if (options?.icon && options.icon.caption === undefined) {
15
+ options.icon.caption = options?.caption;
16
+ }
17
+ }
18
+ getWhere = () => {
19
+ return this.where ? this.where : this;
20
+ };
21
+ }
22
+ export const getEnum = (baseEnum, id) => {
23
+ if (!id) {
24
+ return undefined;
25
+ }
26
+ // @ts-ignore
27
+ const found = getValueList(baseEnum).find((c) => c.id === id);
28
+ return found;
29
+ };
30
+ export const getEnums = (baseEnum) => {
31
+ return getValueList(baseEnum) || [];
32
+ };
@@ -0,0 +1,2 @@
1
+ import { type EntityOptions } from 'remult';
2
+ export declare function KitEntity<entityType>(key: string, options: EntityOptions<entityType extends new (...args: any) => any ? InstanceType<entityType> : entityType>): (target: any, info?: import("remult/src/remult3/remult3").ClassDecoratorContextStub<entityType extends infer T ? T extends entityType ? T extends new (...args: any) => any ? T : never : never : never> | undefined) => any;
@@ -0,0 +1,24 @@
1
+ import { Entity } from 'remult';
2
+ export function KitEntity(key, options) {
3
+ const toAllow = (permission) => {
4
+ if (permission) {
5
+ if (Array.isArray(permission)) {
6
+ return permission.map((p) => p.id);
7
+ }
8
+ return permission.id;
9
+ }
10
+ return undefined;
11
+ };
12
+ return Entity(key, {
13
+ ...options,
14
+ allowApiCrud: options.allowApiCrud ?? toAllow(options.permissionApiCrud),
15
+ allowApiDelete: options.allowApiDelete ?? toAllow(options.permissionApiDelete),
16
+ allowApiInsert: options.allowApiInsert ?? toAllow(options.permissionApiInsert),
17
+ allowApiRead: options.allowApiRead ?? toAllow(options.permissionApiRead),
18
+ allowApiUpdate: options.allowApiUpdate ?? toAllow(options.permissionApiUpdate),
19
+ // saved: async (item, e) => {
20
+ // console.log('was saved')
21
+ // await options?.saved?.(item, e)
22
+ // },
23
+ });
24
+ }
@@ -0,0 +1,10 @@
1
+ import { type FieldOptions, type FieldValidator, type StringFieldOptions } from 'remult';
2
+ export declare function addValidator(validators: FieldOptions['validate'], newValidator: FieldOptions['validate'], atStart?: boolean): FieldValidator<any, any> | FieldValidator<any, any>[] | undefined;
3
+ export declare class KitFields {
4
+ static string<entityType = unknown, valueType = string>(o?: StringFieldOptions<entityType, valueType> & FieldOptions<entityType, valueType>): import("remult").ClassFieldDecorator<entityType, valueType | undefined>;
5
+ static currency<entityType = any, valueType = any>(o?: FieldOptions<entityType> & FieldOptions<entityType>): import("remult").ClassFieldDecorator<entityType, number | undefined>;
6
+ static dateOnly<entityType = any>(o?: FieldOptions<entityType, Date>): import("remult").ClassFieldDecorator<entityType, Date | undefined>;
7
+ static arrayEnum<enumType = any, entityType = any>(enumClass: enumType, o?: FieldOptions<entityType, any[]>): import("remult").ClassFieldDecorator<entityType, any[] | undefined>;
8
+ static arrayEnumToGql<enumType = any, entityType = any>(enumClass: enumType, o?: FieldOptions<entityType, any[]>): import("remult").ClassFieldDecorator<entityType, any[] | undefined>;
9
+ static arrayValueList<enumType = any, entityType = any>(enumClass: enumType, o?: FieldOptions<entityType, any[]>): import("remult").ClassFieldDecorator<entityType, any[] | undefined>;
10
+ }
@@ -0,0 +1,196 @@
1
+ import { Fields, Validators, } from 'remult';
2
+ import { displayCurrency } from './formats';
3
+ import { getEnums } from './KitBaseEnum';
4
+ // Translate default messages
5
+ // REMULT P3 JYC: I need to set this here the one of my app are not overwriting these...
6
+ // It look like I have 2 remult loaded... But even trying to remove one, I still have the issue
7
+ Validators.unique.defaultMessage = 'Existe déjà!';
8
+ Validators.required.defaultMessage = 'Obligatoire!';
9
+ export function addValidator(validators, newValidator, atStart = false) {
10
+ if (!newValidator)
11
+ return validators;
12
+ const newValidators = Array.isArray(newValidator) ? newValidator : [newValidator];
13
+ const validatorsArray = Array.isArray(validators) ? validators : validators ? [validators] : [];
14
+ return atStart ? [...newValidators, ...validatorsArray] : [...validatorsArray, ...newValidators];
15
+ }
16
+ // static string<entityType = any, valueType = string>(
17
+ // ...param: Parameters<typeof Fields.string<entityType, valueType>>
18
+ // ) {
19
+ export class KitFields {
20
+ static string(o) {
21
+ // const f = Fields.string(...param)
22
+ // f.validate = addValidator(f.validate, Validators.required)
23
+ // return f
24
+ // empty if there is nothing coming here.
25
+ if (o === undefined) {
26
+ o = {};
27
+ }
28
+ const validate = [];
29
+ if (o.includeInApi !== false &&
30
+ (!o.allowNull || o.required) &&
31
+ // if require: false is explicitly set, then we don't need to add required validator
32
+ o.required !== false) {
33
+ // REMULT P2 JYC (Open an issue): to repro + issue type issue? - Probably typescript
34
+ // @ts-ignore
35
+ validate.push(Validators.required);
36
+ }
37
+ // let's add original validate if any
38
+ if (o.validate) {
39
+ if (Array.isArray(o.validate)) {
40
+ validate.push(...o.validate);
41
+ }
42
+ else {
43
+ validate.push(o.validate);
44
+ }
45
+ }
46
+ // let's return the field
47
+ return Fields.string({ ...o, validate });
48
+ }
49
+ static currency(o) {
50
+ // let's return the field
51
+ return Fields.number({
52
+ ...o,
53
+ step: '0.01',
54
+ suffix: undefined,
55
+ suffixEdit: '€',
56
+ inputType: 'number',
57
+ displayValue: displayCurrency,
58
+ // REMULT P2: all default valueConverter are removed if I set one?
59
+ valueConverter: {
60
+ toInput(val, inputType) {
61
+ const valStr = String(val);
62
+ if (valStr.includes('.')) {
63
+ const [left, right] = valStr.split('.');
64
+ // Take only the 2 first digits after the dot
65
+ return `${left}.${right.slice(0, 2)}`;
66
+ }
67
+ return valStr;
68
+ },
69
+ fromDb(val) {
70
+ if (val) {
71
+ return parseFloat(val.toString());
72
+ }
73
+ return val;
74
+ },
75
+ },
76
+ });
77
+ }
78
+ static dateOnly(o) {
79
+ // empty if there is nothing coming here.
80
+ if (o === undefined) {
81
+ o = {};
82
+ }
83
+ const validate = [];
84
+ if (o.includeInApi !== false &&
85
+ (!o.allowNull || o.required) &&
86
+ // if require: false is explicitly set, then we don't need to add required validator
87
+ o.required !== false) {
88
+ // REMULT P2 JYC (Open an issue): to repro + issue type issue? - Probably typescript
89
+ // @ts-ignore
90
+ validate.push(Validators.required);
91
+ }
92
+ // let's add original validate if any
93
+ if (o.validate) {
94
+ if (Array.isArray(o.validate)) {
95
+ validate.push(...o.validate);
96
+ }
97
+ else {
98
+ validate.push(o.validate);
99
+ }
100
+ }
101
+ o.inputType = 'dateOnly';
102
+ // let's return the field
103
+ return Fields.dateOnly({ ...o, validate });
104
+ }
105
+ static arrayEnum(enumClass, o) {
106
+ return Fields.json(() => Array, {
107
+ ...o,
108
+ inputType: 'selectArrayEnum',
109
+ allowNull: false,
110
+ valueConverter: {
111
+ fromDb: (v) => {
112
+ if (!v)
113
+ return [];
114
+ const keys = v
115
+ .slice(1, -1)
116
+ .split(',')
117
+ .map((s) => {
118
+ // @ts-ignore
119
+ return enumClass[s];
120
+ })
121
+ .filter((p) => p !== undefined);
122
+ return keys;
123
+ },
124
+ toDb: (v) => {
125
+ const arr = Array.isArray(v) ? v : [v];
126
+ return `{${[...new Set((arr ?? []).map((c) => c.id))].join(',')}}`;
127
+ },
128
+ displayValue: (v) => {
129
+ // TODO to transform in enum & item one day
130
+ return v.map((c) => c.caption).join(', ');
131
+ },
132
+ // REMULT P2 Noam: how to do this in an official way?
133
+ // @ts-ignore
134
+ values: getEnums(enumClass),
135
+ },
136
+ });
137
+ }
138
+ static arrayEnumToGql(enumClass, o) {
139
+ return Fields.json(() => Array, {
140
+ ...o,
141
+ inputType: 'selectArrayEnum',
142
+ allowNull: false,
143
+ valueConverter: {
144
+ fromDb: (v) => {
145
+ if (!v)
146
+ return [];
147
+ const keys = v.slice(1, -1).split(',');
148
+ return keys;
149
+ },
150
+ toDb: (v) => {
151
+ const arr = Array.isArray(v) ? v : [v];
152
+ return `{${[...new Set((arr ?? []).map((c) => c.id))].join(',')}}`;
153
+ },
154
+ displayValue: (v) => {
155
+ // TODO to transform in enum & item one day
156
+ return v.map((c) => c.caption).join(', ');
157
+ },
158
+ // REMULT P2 Noam: how to do this in an official way?
159
+ // @ts-ignore
160
+ values: getEnums(enumClass),
161
+ },
162
+ });
163
+ }
164
+ static arrayValueList(enumClass, o) {
165
+ return Fields.json(() => Array, {
166
+ ...o,
167
+ inputType: 'selectArrayEnum',
168
+ allowNull: false,
169
+ valueConverter: {
170
+ fromDb: (v) => {
171
+ if (!v)
172
+ return [];
173
+ const keys = v
174
+ // @ts-ignore
175
+ .map((s) => {
176
+ // @ts-ignore
177
+ return enumClass[s];
178
+ })
179
+ .filter((p) => p !== undefined);
180
+ return keys;
181
+ },
182
+ toDb: (v) => {
183
+ const arr = Array.isArray(v) ? v : [v];
184
+ return `{${[...new Set((arr ?? []).map((c) => c.id))].join(',')}}`;
185
+ },
186
+ displayValue: (v) => {
187
+ // Nice to have a oneLiner, but if you want custom style, just take the array and do what you want
188
+ return v.map((c) => c.caption).join(', ');
189
+ },
190
+ // REMULT P2 Noam: how to do this in an official way?
191
+ // @ts-ignore
192
+ values: getEnums(enumClass),
193
+ },
194
+ });
195
+ }
196
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * This file was generated by 'vite-plugin-kit-routes'
3
+ *
4
+ * >> DO NOT EDIT THIS FILE MANUALLY <<
5
+ */
6
+ type ParamValue = string | number | undefined;
7
+ /**
8
+ * Append search params to a string
9
+ */
10
+ export declare const appendSp: (sp?: Record<string, ParamValue | ParamValue[]>, prefix?: '?' | '&') => string;
11
+ /**
12
+ * get the current search params
13
+ *
14
+ * Could be use like this:
15
+ * ```
16
+ * route("/cities", { page: 2 }, { ...currentSP() })
17
+ * ```
18
+ */
19
+ export declare const currentSp: () => Record<string, string>;
20
+ type NonFunctionKeys<T> = {
21
+ [K in keyof T]: T[K] extends Function ? never : K;
22
+ }[keyof T];
23
+ type FunctionKeys<T> = {
24
+ [K in keyof T]: T[K] extends Function ? K : never;
25
+ }[keyof T];
26
+ type FunctionParams<T> = T extends (...args: infer P) => any ? P : never;
27
+ declare const AllObjs: {
28
+ kit_sign_in: string;
29
+ remult_admin: string;
30
+ github: (params?: {
31
+ owner?: (string | number);
32
+ repo?: (string | number);
33
+ }) => string;
34
+ "/": string;
35
+ "/remult": string;
36
+ "/remult/auth": string;
37
+ "/remult/enum": string;
38
+ "/remult/select": string;
39
+ "/ui": string;
40
+ };
41
+ type AllTypes = typeof AllObjs;
42
+ /**
43
+ * To be used like this:
44
+ * ```ts
45
+ * import { route } from './ROUTES'
46
+ *
47
+ * route('site_id', { id: 1 })
48
+ * ```
49
+ */
50
+ export declare function route<T extends FunctionKeys<AllTypes>>(key: T, ...params: FunctionParams<AllTypes[T]>): string;
51
+ export declare function route<T extends NonFunctionKeys<AllTypes>>(key: T): string;
52
+ /**
53
+ * Add this type as a generic of the vite plugin `kitRoutes<KIT_ROUTES>`.
54
+ *
55
+ * Full example:
56
+ * ```ts
57
+ * import type { KIT_ROUTES } from './ROUTES'
58
+ * import { kitRoutes } from 'vite-plugin-kit-routes'
59
+ *
60
+ * kitRoutes<KIT_ROUTES>({
61
+ * PAGES: {
62
+ * // here, key of object will be typed!
63
+ * }
64
+ * })
65
+ * ```
66
+ */
67
+ export type KIT_ROUTES = {
68
+ PAGES: {
69
+ '/': never;
70
+ '/remult': never;
71
+ '/remult/auth': never;
72
+ '/remult/enum': never;
73
+ '/remult/select': never;
74
+ '/ui': never;
75
+ };
76
+ SERVERS: Record<string, never>;
77
+ ACTIONS: Record<string, never>;
78
+ LINKS: {
79
+ 'kit_sign_in': never;
80
+ 'remult_admin': never;
81
+ 'github': 'owner' | 'repo';
82
+ };
83
+ Params: {
84
+ owner: never;
85
+ repo: never;
86
+ };
87
+ };
88
+ export {};
package/esm/ROUTES.js ADDED
@@ -0,0 +1,98 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * This file was generated by 'vite-plugin-kit-routes'
4
+ *
5
+ * >> DO NOT EDIT THIS FILE MANUALLY <<
6
+ */
7
+ /**
8
+ * PAGES
9
+ */
10
+ const PAGES = {
11
+ "/": `/`,
12
+ "/remult": `/remult`,
13
+ "/remult/auth": `/remult/auth`,
14
+ "/remult/enum": `/remult/enum`,
15
+ "/remult/select": `/remult/select`,
16
+ "/ui": `/ui`
17
+ };
18
+ /**
19
+ * SERVERS
20
+ */
21
+ const SERVERS = {};
22
+ /**
23
+ * ACTIONS
24
+ */
25
+ const ACTIONS = {};
26
+ /**
27
+ * LINKS
28
+ */
29
+ const LINKS = {
30
+ "kit_sign_in": `/kit/auth/sign-in`,
31
+ "remult_admin": `/api/admin`,
32
+ "github": (params) => {
33
+ params = params ?? {};
34
+ params.owner = params.owner ?? "jycouet";
35
+ params.repo = params.repo ?? "firstly";
36
+ return `https://github.com/${params.owner}/${params.repo}`;
37
+ }
38
+ };
39
+ /**
40
+ * Append search params to a string
41
+ */
42
+ export const appendSp = (sp, prefix = '?') => {
43
+ if (sp === undefined)
44
+ return '';
45
+ const params = new URLSearchParams();
46
+ const append = (n, v) => {
47
+ if (v !== undefined) {
48
+ params.append(n, String(v));
49
+ }
50
+ };
51
+ for (const [name, val] of Object.entries(sp)) {
52
+ if (Array.isArray(val)) {
53
+ for (const v of val) {
54
+ append(name, v);
55
+ }
56
+ }
57
+ else {
58
+ append(name, val);
59
+ }
60
+ }
61
+ const formatted = params.toString();
62
+ if (formatted) {
63
+ return `${prefix}${formatted}`;
64
+ }
65
+ return '';
66
+ };
67
+ /**
68
+ * get the current search params
69
+ *
70
+ * Could be use like this:
71
+ * ```
72
+ * route("/cities", { page: 2 }, { ...currentSP() })
73
+ * ```
74
+ */
75
+ export const currentSp = () => {
76
+ const params = new URLSearchParams(window.location.search);
77
+ const record = {};
78
+ for (const [key, value] of params.entries()) {
79
+ record[key] = value;
80
+ }
81
+ return record;
82
+ };
83
+ function StringOrUndefined(val) {
84
+ if (val === undefined) {
85
+ return undefined;
86
+ }
87
+ return String(val);
88
+ }
89
+ const AllObjs = { ...PAGES, ...ACTIONS, ...SERVERS, ...LINKS };
90
+ export function route(key, ...params) {
91
+ if (AllObjs[key] instanceof Function) {
92
+ const element = AllObjs[key];
93
+ return element(...params);
94
+ }
95
+ else {
96
+ return AllObjs[key];
97
+ }
98
+ }
@@ -0,0 +1 @@
1
+ export declare const LogToConsoleCustom: (duration: number, query: string, args: Record<string, any>, short?: boolean) => string | undefined;
@@ -0,0 +1,102 @@
1
+ import { bgCyan, cyan, green, Log, magenta, yellow } from '@kitql/helpers';
2
+ const typeQuery = new Map([
3
+ // CRUD
4
+ ['INSERT', '⚪'], // Used to insert new data into a database.
5
+ ['SELECT', '🔵'], // Used to select data from a database and retrieve it.
6
+ ['COUNT ', '🟦'], // Used to count data from a database and retrieve it.
7
+ ['UPDATE', '🟣'], // Used to update existing data within a database.
8
+ ['DELETE', '🟤'], // Used to delete existing data from a database.
9
+ // Additional
10
+ ['CREATE', '🟩'], // Used to create a new table, or database.
11
+ ['ALTER', '🟨'], // Used to modify an existing database object, such as a table.
12
+ ['DROP', '🟥'], // Used to delete an entire table or database.
13
+ ['TRUNCATE', '⬛'], // Used to remove all records from a table, including all spaces allocated for the records are removed.
14
+ ['GRANT', '🟪'], // Used to give a specific user permission to perform certain tasks.
15
+ ['REVOKE', '🟫'], // Used to take back permissions from a user.
16
+ ]);
17
+ const keys = ['FROM', 'WHERE', 'LIMIT', 'OFFSET'];
18
+ const typeQueryKey = Array.from(typeQuery.keys());
19
+ export const LogToConsoleCustom = (duration, query, args, short = true) => {
20
+ const rawSql = query
21
+ .replace(/(\r\n|\n|\r|\t)/gm, ' ')
22
+ .replace(/ +/g, ' ')
23
+ .trim();
24
+ const s = rawSql.split(' ');
25
+ let first = s[0].toUpperCase();
26
+ if (s.includes('count(*)')) {
27
+ first = 'COUNT ';
28
+ }
29
+ const tables = [];
30
+ const listArgs = [];
31
+ for (let i = 0; i < s.length; i++) {
32
+ const up = s[i].toUpperCase();
33
+ if (keys.includes(up)) {
34
+ s[i] = magenta(up);
35
+ }
36
+ else if (typeQueryKey.includes(up)) {
37
+ s[i] = cyan(up);
38
+ }
39
+ if (up === 'FROM') {
40
+ tables.push(s[i + 1]); // let's do it before color
41
+ s[i + 1] = green(s[i + 1]);
42
+ }
43
+ else if (up === 'INSERT') {
44
+ tables.push(s[i + 2]); // let's do it before color
45
+ }
46
+ else if (up === 'UPDATE') {
47
+ tables.push(s[i + 1]); // let's do it before color
48
+ }
49
+ else if (up === 'LIMIT') {
50
+ s[i + 1] = yellow(s[i + 1]);
51
+ }
52
+ else if (up === 'OFFSET') {
53
+ s[i + 1] = yellow(s[i + 1]);
54
+ }
55
+ else if (up === 'ORDER' && s[i + 1].toUpperCase() === 'BY') {
56
+ s[i] = magenta('ORDER');
57
+ s[i + 1] = magenta('BY');
58
+ }
59
+ const regex = /\$\d+/g;
60
+ const matches = s[i].match(regex);
61
+ if (matches && matches.length > 0) {
62
+ // and it's a match with [$ somthing]
63
+ // let newMatches = s[i]
64
+ matches.reverse().forEach((keys) => {
65
+ s[i] = s[i].replace(keys, yellow("'" + args[keys] + "'"));
66
+ });
67
+ listArgs.push(s[i - 2].replaceAll('"', '') + ': ' + s[i]);
68
+ }
69
+ }
70
+ const final_s = s.join(' ').replace(/ +/g, ' ');
71
+ // args replace
72
+ // const listArgs = []
73
+ // for (const arg in args) {
74
+ // listArgs.push(yellow(args[arg]))
75
+ // final_s = final_s.replace(arg, yellow(args[arg]))
76
+ // }
77
+ const uniqueTables = [...new Set(tables)];
78
+ const mainTable = uniqueTables[uniqueTables.length - 1];
79
+ const subTables = uniqueTables.slice(0, -1);
80
+ const time = ` ${bgCyan((duration * 1000).toFixed(0).padStart(3) + ' ms ')}`;
81
+ let toLog = '';
82
+ if (short) {
83
+ toLog =
84
+ `${typeQuery.get(first) || '💢'}` +
85
+ `${time}` +
86
+ ` ${cyan(first)} ${green(mainTable?.replaceAll('"', ''))}` +
87
+ `${listArgs.length > 0 ? ` { ${listArgs.join(', ')} }` : ``}` +
88
+ `${subTables.length > 0 ? magenta(` (sub: ${subTables.join(', ')})`) : ``}`;
89
+ }
90
+ else {
91
+ toLog = `${typeQuery.get(first) || '💢'}` + time + ` ${final_s}`;
92
+ }
93
+ // Filter out a few things
94
+ const filterOutTable = ['"auth_user"', '"auth_user_session"'];
95
+ const OnoOfFiltered = tables.length === 1 && filterOutTable.includes(tables[0]);
96
+ if (!OnoOfFiltered) {
97
+ // console.log(`toLogLong`, toLogLong)
98
+ log.info(toLog);
99
+ return toLog;
100
+ }
101
+ };
102
+ const log = new Log('');