rastack 0.0.16 → 0.0.20

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 (105) hide show
  1. package/CHANGELOG.md +43876 -43013
  2. package/dist/.prettierrc +7 -7
  3. package/dist/compile/analyze.js +19 -11
  4. package/dist/compile/index.js +26 -17
  5. package/dist/compile/manifest.js +2 -3
  6. package/dist/compile/openapi.js +5 -8
  7. package/dist/compile/program.js +19 -10
  8. package/dist/csv-schema.js +5 -6
  9. package/dist/define/index.js +2 -2
  10. package/dist/entity-generation/delete-method.js +8 -10
  11. package/dist/entity-generation/form.js +80 -82
  12. package/dist/entity-generation/get-method.js +35 -36
  13. package/dist/entity-generation/imports.js +24 -20
  14. package/dist/entity-generation/sync-method.d.ts +1 -1
  15. package/dist/entity-generation/sync-method.js +45 -46
  16. package/dist/entity-generation/update-method.js +9 -10
  17. package/dist/rad-wasm-build.d.ts +1 -1
  18. package/dist/rad-wasm-build.js +15 -6
  19. package/dist/rad.js +9 -2
  20. package/dist/schema/camel-to-pastel.js +1 -2
  21. package/dist/schema/capitalise-first-letter.js +1 -2
  22. package/dist/schema/extract-response.js +3 -4
  23. package/dist/schema/fetch-schema.js +4 -16
  24. package/dist/schema/remove-non-model-paths.js +1 -2
  25. package/dist/schema/to-camel-case.js +1 -2
  26. package/dist/schema/to-pastel-case.js +1 -2
  27. package/dist/schema-convert.js +22 -33
  28. package/dist/schema-entities.js +177 -189
  29. package/dist/schema-fetch.js +46 -63
  30. package/dist/schema-full.js +23 -36
  31. package/dist/schema-index.js +16 -27
  32. package/dist/schema-params.js +11 -22
  33. package/dist/seed.js +95 -97
  34. package/hooks/form/form.ts +207 -207
  35. package/hooks/form/index.ts +8 -8
  36. package/hooks/form/interfaces.ts +217 -217
  37. package/hooks/form/structure.ts +39 -39
  38. package/hooks/form/validate-schema.ts +49 -49
  39. package/hooks/index.ts +3 -3
  40. package/hooks/query/api.ts +42 -42
  41. package/hooks/query/delete.ts +45 -45
  42. package/hooks/query/fetch.ts +48 -48
  43. package/hooks/query/index.ts +21 -21
  44. package/hooks/query/interfaces.ts +111 -111
  45. package/hooks/query/list.ts +286 -286
  46. package/hooks/query/update.ts +88 -88
  47. package/hooks/query/url.ts +31 -31
  48. package/hooks/real-time/index.ts +1 -1
  49. package/hooks/real-time/pusher.ts +43 -43
  50. package/jest.config.cjs +6 -6
  51. package/package.json +57 -57
  52. package/provider/index.ts +13 -13
  53. package/provider/provider.tsx +187 -187
  54. package/provider/types.ts +114 -114
  55. package/provider/warehouse.ts +167 -167
  56. package/provider/wasm.ts +124 -124
  57. package/runtime.ts +3 -3
  58. package/src/.prettierrc +7 -7
  59. package/src/compile/analyze.ts +224 -224
  60. package/src/compile/index.ts +86 -86
  61. package/src/compile/manifest.ts +10 -10
  62. package/src/compile/model.ts +69 -69
  63. package/src/compile/openapi.ts +266 -266
  64. package/src/compile/program.ts +40 -40
  65. package/src/csv-schema.ts +187 -187
  66. package/src/define/index.ts +162 -162
  67. package/src/entity-generation/delete-method.ts +37 -37
  68. package/src/entity-generation/form.ts +169 -169
  69. package/src/entity-generation/get-method.ts +80 -80
  70. package/src/entity-generation/imports.ts +110 -110
  71. package/src/entity-generation/sync-method.ts +222 -222
  72. package/src/entity-generation/update-method.ts +38 -38
  73. package/src/index.ts +77 -77
  74. package/src/rad-compile.ts +88 -88
  75. package/src/rad-wasm-build.ts +102 -102
  76. package/src/rad.ts +101 -101
  77. package/src/scan.ts +89 -89
  78. package/src/schema/camel-to-pastel.ts +3 -3
  79. package/src/schema/capitalise-first-letter.ts +3 -3
  80. package/src/schema/extract-response.ts +38 -38
  81. package/src/schema/fetch-schema.ts +12 -12
  82. package/src/schema/remove-non-model-paths.ts +13 -13
  83. package/src/schema/to-camel-case.ts +7 -7
  84. package/src/schema/to-pastel-case.ts +6 -6
  85. package/src/schema-convert.ts +61 -61
  86. package/src/schema-entities.ts +401 -401
  87. package/src/schema-fetch.ts +82 -82
  88. package/src/schema-full.ts +38 -38
  89. package/src/schema-index.ts +29 -29
  90. package/src/schema-params.ts +116 -116
  91. package/src/seed.ts +297 -297
  92. package/sync/engine.ts +392 -392
  93. package/sync/hooks.ts +450 -450
  94. package/sync/index.ts +8 -8
  95. package/sync/persistence.ts +237 -237
  96. package/sync/provider.tsx +91 -91
  97. package/sync/registry.ts +36 -36
  98. package/sync/store.ts +126 -126
  99. package/sync/transactions.ts +300 -300
  100. package/sync/types.ts +94 -94
  101. package/test/compile.spec.ts +192 -192
  102. package/test/csv-schema.spec.ts +143 -143
  103. package/test/schema-entities.spec.ts +688 -688
  104. package/tsconfig.json +24 -24
  105. package/types.ts +18 -18
@@ -1,207 +1,207 @@
1
- import { useFormik, FormikErrors } from "formik";
2
- import {
3
- FormFieldStructure,
4
- FormProps,
5
- FormStructure,
6
- FormUpdate,
7
- FormValuesType,
8
- } from "./interfaces";
9
- import { FlattenedRecord } from "../../types";
10
- import { formikJSONSchemaValidation } from "./validate-schema";
11
- import { getFieldStructure } from "./structure";
12
-
13
- export function useForm<
14
- TFormValues extends object,
15
- TPostParams,
16
- TPutParams,
17
- TPatchParams,
18
- TPostPayload,
19
- TPutPayload,
20
- TPatchPayload,
21
- TPostResult,
22
- TPutResult,
23
- TPatchResult,
24
- TFormUpdate extends FormUpdate,
25
- TSourceId extends string | undefined,
26
- >({
27
- id,
28
- sourceData,
29
- formValues,
30
- formatResponse,
31
- transformRequest,
32
- transformResponse,
33
- mutations,
34
- updateType,
35
- onSuccess,
36
- }: FormProps<
37
- TFormValues,
38
- TPostParams,
39
- TPutParams,
40
- TPatchParams,
41
- TPostPayload,
42
- TPutPayload,
43
- TPatchPayload,
44
- TPostResult,
45
- TPutResult,
46
- TPatchResult,
47
- TFormUpdate,
48
- TSourceId
49
- >): FormStructure<
50
- TFormValues,
51
- FormValuesType<
52
- TFormUpdate,
53
- TSourceId,
54
- TPutParams,
55
- TPutPayload,
56
- TPostParams,
57
- TPostPayload,
58
- TPatchParams,
59
- TPatchPayload
60
- >
61
- > {
62
- const updateMethod = id ? (updateType === "put" ? "put" : "patch") : "post";
63
-
64
- const formatRequestValues = (values: TFormValues) => {
65
- if (formatResponse) {
66
- return (Object.keys(values) as Array<keyof TFormValues>).reduce(
67
- (acc, key) => {
68
- const formattedValue = formatResponse[key](values[key]);
69
- return {
70
- ...acc,
71
- ...formattedValue,
72
- };
73
- },
74
- {} as FormValuesType<
75
- TFormUpdate,
76
- TSourceId,
77
- TPutParams,
78
- TPutPayload,
79
- TPostParams,
80
- TPostPayload,
81
- TPatchParams,
82
- TPatchPayload
83
- >,
84
- );
85
- } else if (transformRequest) {
86
- return transformRequest(values);
87
- } else {
88
- return values;
89
- }
90
- };
91
-
92
- const isSourceDataLoading = sourceData
93
- ? Object.values(sourceData).some((source) =>
94
- // @ts-ignore create a base type for list and fetch data extending react query. This will ensure that the isLoading property is available
95
- source ? source.isLoading : false,
96
- )
97
- : false;
98
-
99
- const formik = useFormik<TFormValues>({
100
- initialValues: formValues,
101
- validate: (values) => {
102
- if (mutations) {
103
- const payload = formatRequestValues(values);
104
- return formikJSONSchemaValidation(
105
- payload,
106
- mutations[updateMethod]?.validation,
107
- );
108
- } else {
109
- return {} as FormikErrors<TFormValues>;
110
- }
111
- },
112
- onSubmit: (values, formikHelpers) => {
113
- const mutation = mutations ? mutations[updateMethod].mutation : undefined;
114
- const formattedResponse = formatRequestValues(values);
115
- if (mutation) {
116
- mutation.mutate(
117
- {
118
- //@ts-ignore
119
- params: {
120
- id,
121
- ...formattedResponse,
122
- },
123
- //@ts-ignore
124
- payload: formattedResponse,
125
- },
126
- {
127
- onSuccess: (result) => {
128
- if (onSuccess) {
129
- // @ts-ignore
130
- onSuccess(result);
131
- }
132
- formikHelpers.setSubmitting(false);
133
- },
134
- onError: () => {
135
- formikHelpers.setSubmitting(false);
136
- },
137
- },
138
- );
139
- }
140
- },
141
- enableReinitialize: true,
142
- });
143
-
144
- const isSubmitDisabled =
145
- formik.isValid === undefined ? false : !formik.isValid;
146
- const isSubmitting = formik.isSubmitting;
147
- const submitForm = () => {
148
- formik.handleSubmit();
149
- };
150
-
151
- const getFormField = <
152
- TFieldName extends Extract<keyof FlattenedRecord<TFormValues>, string>,
153
- >(
154
- fieldName: TFieldName,
155
- ): FormFieldStructure<FlattenedRecord<TFormValues>[TFieldName]> => {
156
- const { value: value, checked: isCheckedValue } =
157
- formik.getFieldProps(fieldName);
158
- const { touched: isTouched, error: errorMessage } =
159
- formik.getFieldMeta(fieldName);
160
- const { setValue: setFormValue, setTouched } =
161
- formik.getFieldHelpers(fieldName);
162
-
163
- let { type, isRequired } = getFieldStructure(
164
- mutations ? mutations[updateMethod]?.validation : undefined,
165
- fieldName,
166
- );
167
-
168
- const error = errorMessage ?? "";
169
- const isError = errorMessage !== undefined;
170
- const isDisabled = false;
171
- const isChecked = isCheckedValue ?? false;
172
- const setValue = (value: FlattenedRecord<TFormValues>[TFieldName]) => {
173
- if (type === "number" && value) {
174
- const numericValue = Number(value);
175
- if (!isNaN(numericValue)) {
176
- setFormValue(numericValue);
177
- }
178
- } else {
179
- setFormValue(value);
180
- }
181
- };
182
- return {
183
- type,
184
- value,
185
- error,
186
- isChecked,
187
- isError,
188
- isDisabled,
189
- isRequired,
190
- setValue,
191
- setTouched,
192
- };
193
- };
194
-
195
- return {
196
- formValues: formik.values,
197
- // @ts-ignore
198
- responseValues: formatRequestValues(formik.values),
199
- errors: formik.errors,
200
- getFormField,
201
- onSubmit: submitForm,
202
- resetForm: formik.resetForm,
203
- isSubmitDisabled,
204
- isSourceDataLoading,
205
- isSubmitting,
206
- };
207
- }
1
+ import { useFormik, FormikErrors } from "formik";
2
+ import {
3
+ FormFieldStructure,
4
+ FormProps,
5
+ FormStructure,
6
+ FormUpdate,
7
+ FormValuesType,
8
+ } from "./interfaces";
9
+ import { FlattenedRecord } from "../../types";
10
+ import { formikJSONSchemaValidation } from "./validate-schema";
11
+ import { getFieldStructure } from "./structure";
12
+
13
+ export function useForm<
14
+ TFormValues extends object,
15
+ TPostParams,
16
+ TPutParams,
17
+ TPatchParams,
18
+ TPostPayload,
19
+ TPutPayload,
20
+ TPatchPayload,
21
+ TPostResult,
22
+ TPutResult,
23
+ TPatchResult,
24
+ TFormUpdate extends FormUpdate,
25
+ TSourceId extends string | undefined,
26
+ >({
27
+ id,
28
+ sourceData,
29
+ formValues,
30
+ formatResponse,
31
+ transformRequest,
32
+ transformResponse,
33
+ mutations,
34
+ updateType,
35
+ onSuccess,
36
+ }: FormProps<
37
+ TFormValues,
38
+ TPostParams,
39
+ TPutParams,
40
+ TPatchParams,
41
+ TPostPayload,
42
+ TPutPayload,
43
+ TPatchPayload,
44
+ TPostResult,
45
+ TPutResult,
46
+ TPatchResult,
47
+ TFormUpdate,
48
+ TSourceId
49
+ >): FormStructure<
50
+ TFormValues,
51
+ FormValuesType<
52
+ TFormUpdate,
53
+ TSourceId,
54
+ TPutParams,
55
+ TPutPayload,
56
+ TPostParams,
57
+ TPostPayload,
58
+ TPatchParams,
59
+ TPatchPayload
60
+ >
61
+ > {
62
+ const updateMethod = id ? (updateType === "put" ? "put" : "patch") : "post";
63
+
64
+ const formatRequestValues = (values: TFormValues) => {
65
+ if (formatResponse) {
66
+ return (Object.keys(values) as Array<keyof TFormValues>).reduce(
67
+ (acc, key) => {
68
+ const formattedValue = formatResponse[key](values[key]);
69
+ return {
70
+ ...acc,
71
+ ...formattedValue,
72
+ };
73
+ },
74
+ {} as FormValuesType<
75
+ TFormUpdate,
76
+ TSourceId,
77
+ TPutParams,
78
+ TPutPayload,
79
+ TPostParams,
80
+ TPostPayload,
81
+ TPatchParams,
82
+ TPatchPayload
83
+ >,
84
+ );
85
+ } else if (transformRequest) {
86
+ return transformRequest(values);
87
+ } else {
88
+ return values;
89
+ }
90
+ };
91
+
92
+ const isSourceDataLoading = sourceData
93
+ ? Object.values(sourceData).some((source) =>
94
+ // @ts-ignore create a base type for list and fetch data extending react query. This will ensure that the isLoading property is available
95
+ source ? source.isLoading : false,
96
+ )
97
+ : false;
98
+
99
+ const formik = useFormik<TFormValues>({
100
+ initialValues: formValues,
101
+ validate: (values) => {
102
+ if (mutations) {
103
+ const payload = formatRequestValues(values);
104
+ return formikJSONSchemaValidation(
105
+ payload,
106
+ mutations[updateMethod]?.validation,
107
+ );
108
+ } else {
109
+ return {} as FormikErrors<TFormValues>;
110
+ }
111
+ },
112
+ onSubmit: (values, formikHelpers) => {
113
+ const mutation = mutations ? mutations[updateMethod].mutation : undefined;
114
+ const formattedResponse = formatRequestValues(values);
115
+ if (mutation) {
116
+ mutation.mutate(
117
+ {
118
+ //@ts-ignore
119
+ params: {
120
+ id,
121
+ ...formattedResponse,
122
+ },
123
+ //@ts-ignore
124
+ payload: formattedResponse,
125
+ },
126
+ {
127
+ onSuccess: (result) => {
128
+ if (onSuccess) {
129
+ // @ts-ignore
130
+ onSuccess(result);
131
+ }
132
+ formikHelpers.setSubmitting(false);
133
+ },
134
+ onError: () => {
135
+ formikHelpers.setSubmitting(false);
136
+ },
137
+ },
138
+ );
139
+ }
140
+ },
141
+ enableReinitialize: true,
142
+ });
143
+
144
+ const isSubmitDisabled =
145
+ formik.isValid === undefined ? false : !formik.isValid;
146
+ const isSubmitting = formik.isSubmitting;
147
+ const submitForm = () => {
148
+ formik.handleSubmit();
149
+ };
150
+
151
+ const getFormField = <
152
+ TFieldName extends Extract<keyof FlattenedRecord<TFormValues>, string>,
153
+ >(
154
+ fieldName: TFieldName,
155
+ ): FormFieldStructure<FlattenedRecord<TFormValues>[TFieldName]> => {
156
+ const { value: value, checked: isCheckedValue } =
157
+ formik.getFieldProps(fieldName);
158
+ const { touched: isTouched, error: errorMessage } =
159
+ formik.getFieldMeta(fieldName);
160
+ const { setValue: setFormValue, setTouched } =
161
+ formik.getFieldHelpers(fieldName);
162
+
163
+ let { type, isRequired } = getFieldStructure(
164
+ mutations ? mutations[updateMethod]?.validation : undefined,
165
+ fieldName,
166
+ );
167
+
168
+ const error = errorMessage ?? "";
169
+ const isError = errorMessage !== undefined;
170
+ const isDisabled = false;
171
+ const isChecked = isCheckedValue ?? false;
172
+ const setValue = (value: FlattenedRecord<TFormValues>[TFieldName]) => {
173
+ if (type === "number" && value) {
174
+ const numericValue = Number(value);
175
+ if (!isNaN(numericValue)) {
176
+ setFormValue(numericValue);
177
+ }
178
+ } else {
179
+ setFormValue(value);
180
+ }
181
+ };
182
+ return {
183
+ type,
184
+ value,
185
+ error,
186
+ isChecked,
187
+ isError,
188
+ isDisabled,
189
+ isRequired,
190
+ setValue,
191
+ setTouched,
192
+ };
193
+ };
194
+
195
+ return {
196
+ formValues: formik.values,
197
+ // @ts-ignore
198
+ responseValues: formatRequestValues(formik.values),
199
+ errors: formik.errors,
200
+ getFormField,
201
+ onSubmit: submitForm,
202
+ resetForm: formik.resetForm,
203
+ isSubmitDisabled,
204
+ isSourceDataLoading,
205
+ isSubmitting,
206
+ };
207
+ }
@@ -1,8 +1,8 @@
1
- export { useForm } from "./form";
2
- export type {
3
- FormStructure,
4
- FormUpdateMethod,
5
- SetupUpdateEndpointReturn,
6
- FormProps,
7
- FormUpdate,
8
- } from "./interfaces";
1
+ export { useForm } from "./form";
2
+ export type {
3
+ FormStructure,
4
+ FormUpdateMethod,
5
+ SetupUpdateEndpointReturn,
6
+ FormProps,
7
+ FormUpdate,
8
+ } from "./interfaces";