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,169 +1,169 @@
1
- import { toPascalCase } from "../schema/to-pastel-case";
2
-
3
- type MutationOperation = {
4
- operationId: string;
5
- schema: string;
6
- };
7
-
8
- type MutationOperations = {
9
- [path: string]: {
10
- put?: MutationOperation;
11
- post?: MutationOperation;
12
- patch?: MutationOperation;
13
- };
14
- };
15
-
16
- type GroupedMutations = {
17
- [functionName: string]: {
18
- groupDetailClean: string;
19
- mutations: string[];
20
- };
21
- };
22
-
23
- export function generateUpdateFormMethod(
24
- appName: string,
25
- modelName: string,
26
- mutationOperations: MutationOperations,
27
- ) {
28
- const modelDetail = toPascalCase(modelName);
29
- const importStatements = new Set<string>();
30
- const groupedMutations: GroupedMutations = {};
31
-
32
- Object.entries(mutationOperations).forEach(([path, operations]) => {
33
- const pathParts = path.split("/");
34
- const groupDetail = toPascalCase(pathParts.slice(3).join("_"));
35
- const groupDetailClean = cleanGroupDetail(groupDetail);
36
- const functionName = `useUpdate${modelDetail}${groupDetailClean}Form`;
37
-
38
- const mutations = generateMutations(operations);
39
- if (mutations) {
40
- if (!groupedMutations[functionName]) {
41
- groupedMutations[functionName] = {
42
- groupDetailClean,
43
- mutations: [],
44
- };
45
- }
46
- groupedMutations[functionName].mutations.push(mutations);
47
-
48
- Object.values(operations).forEach((operation) => {
49
- if (operation && operation.schema) {
50
- importStatements.add(`Deref${operation.schema}`);
51
- }
52
- });
53
- }
54
- });
55
-
56
- const formCodeGen = Object.entries(groupedMutations)
57
- .map(([functionName, { groupDetailClean, mutations }]) =>
58
- generateFormMethod(groupDetailClean, mutations.join(",\n ")),
59
- )
60
- .join("\n\n");
61
-
62
- return [formCodeGen, importStatements];
63
- }
64
-
65
- function cleanGroupDetail(groupDetail: string): string {
66
- return groupDetail
67
- .replace("V1", "")
68
- .split("_")
69
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
70
- .join("")
71
- .replace(/{([^}]+)}/g, "");
72
- }
73
-
74
- function generateFormMethod(
75
- groupDetailClean: string,
76
- mutations: string,
77
- ): string {
78
- return `
79
- export function useUpdate${groupDetailClean}Form<
80
- TFormValues extends object,
81
- TPostParams,
82
- TPutParams,
83
- TPatchParams,
84
- TPostPayload,
85
- TPutPayload,
86
- TPatchPayload,
87
- TPostResult,
88
- TPutResult,
89
- TPatchResult,
90
- TFormUpdate extends FormUpdate,
91
- TSourceId extends string | undefined,
92
- >({
93
- id,
94
- sourceData = {},
95
- formValues,
96
- formatResponse,
97
- transformRequest,
98
- transformResponse,
99
- mutations = {
100
- ${mutations}
101
- },
102
- updateType,
103
- onSuccess
104
- }: FormProps<
105
- TFormValues,
106
- TPostParams,
107
- TPutParams,
108
- TPatchParams,
109
- TPostPayload,
110
- TPutPayload,
111
- TPatchPayload,
112
- TPostResult,
113
- TPutResult,
114
- TPatchResult,
115
- TFormUpdate,
116
- TSourceId
117
- >) {
118
- return useForm<
119
- TFormValues,
120
- TPostParams,
121
- TPutParams,
122
- TPatchParams,
123
- TPostPayload,
124
- TPutPayload,
125
- TPatchPayload,
126
- TPostResult,
127
- TPutResult,
128
- TPatchResult,
129
- TFormUpdate,
130
- TSourceId
131
- >({
132
- id,
133
- mutations,
134
- formValues,
135
- sourceData,
136
- formatResponse,
137
- transformRequest,
138
- transformResponse,
139
- updateType,
140
- onSuccess
141
- });
142
- }`;
143
- }
144
-
145
- function generateMutations(operations: MutationOperations[string]): string {
146
- const mutationStrings = [];
147
- if (operations.post?.operationId && operations.post?.schema) {
148
- mutationStrings.push(`post: {
149
- // @ts-ignore
150
- mutation: usePost${operations.post.operationId}(),
151
- validation: Deref${operations.post.schema}
152
- }`);
153
- }
154
- if (operations.put?.operationId && operations.put?.schema) {
155
- mutationStrings.push(`put: {
156
- // @ts-ignore
157
- mutation: usePut${operations.put.operationId}(),
158
- validation: Deref${operations.put.schema}
159
- }`);
160
- }
161
- if (operations.patch?.operationId && operations.patch?.schema) {
162
- mutationStrings.push(`patch: {
163
- // @ts-ignore
164
- mutation: usePatch${operations.patch.operationId}(),
165
- validation: Deref${operations.patch.schema}
166
- }`);
167
- }
168
- return mutationStrings.join(",\n ");
169
- }
1
+ import { toPascalCase } from "../schema/to-pastel-case";
2
+
3
+ type MutationOperation = {
4
+ operationId: string;
5
+ schema: string;
6
+ };
7
+
8
+ type MutationOperations = {
9
+ [path: string]: {
10
+ put?: MutationOperation;
11
+ post?: MutationOperation;
12
+ patch?: MutationOperation;
13
+ };
14
+ };
15
+
16
+ type GroupedMutations = {
17
+ [functionName: string]: {
18
+ groupDetailClean: string;
19
+ mutations: string[];
20
+ };
21
+ };
22
+
23
+ export function generateUpdateFormMethod(
24
+ appName: string,
25
+ modelName: string,
26
+ mutationOperations: MutationOperations,
27
+ ) {
28
+ const modelDetail = toPascalCase(modelName);
29
+ const importStatements = new Set<string>();
30
+ const groupedMutations: GroupedMutations = {};
31
+
32
+ Object.entries(mutationOperations).forEach(([path, operations]) => {
33
+ const pathParts = path.split("/");
34
+ const groupDetail = toPascalCase(pathParts.slice(3).join("_"));
35
+ const groupDetailClean = cleanGroupDetail(groupDetail);
36
+ const functionName = `useUpdate${modelDetail}${groupDetailClean}Form`;
37
+
38
+ const mutations = generateMutations(operations);
39
+ if (mutations) {
40
+ if (!groupedMutations[functionName]) {
41
+ groupedMutations[functionName] = {
42
+ groupDetailClean,
43
+ mutations: [],
44
+ };
45
+ }
46
+ groupedMutations[functionName].mutations.push(mutations);
47
+
48
+ Object.values(operations).forEach((operation) => {
49
+ if (operation && operation.schema) {
50
+ importStatements.add(`Deref${operation.schema}`);
51
+ }
52
+ });
53
+ }
54
+ });
55
+
56
+ const formCodeGen = Object.entries(groupedMutations)
57
+ .map(([functionName, { groupDetailClean, mutations }]) =>
58
+ generateFormMethod(groupDetailClean, mutations.join(",\n ")),
59
+ )
60
+ .join("\n\n");
61
+
62
+ return [formCodeGen, importStatements];
63
+ }
64
+
65
+ function cleanGroupDetail(groupDetail: string): string {
66
+ return groupDetail
67
+ .replace("V1", "")
68
+ .split("_")
69
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
70
+ .join("")
71
+ .replace(/{([^}]+)}/g, "");
72
+ }
73
+
74
+ function generateFormMethod(
75
+ groupDetailClean: string,
76
+ mutations: string,
77
+ ): string {
78
+ return `
79
+ export function useUpdate${groupDetailClean}Form<
80
+ TFormValues extends object,
81
+ TPostParams,
82
+ TPutParams,
83
+ TPatchParams,
84
+ TPostPayload,
85
+ TPutPayload,
86
+ TPatchPayload,
87
+ TPostResult,
88
+ TPutResult,
89
+ TPatchResult,
90
+ TFormUpdate extends FormUpdate,
91
+ TSourceId extends string | undefined,
92
+ >({
93
+ id,
94
+ sourceData = {},
95
+ formValues,
96
+ formatResponse,
97
+ transformRequest,
98
+ transformResponse,
99
+ mutations = {
100
+ ${mutations}
101
+ },
102
+ updateType,
103
+ onSuccess
104
+ }: FormProps<
105
+ TFormValues,
106
+ TPostParams,
107
+ TPutParams,
108
+ TPatchParams,
109
+ TPostPayload,
110
+ TPutPayload,
111
+ TPatchPayload,
112
+ TPostResult,
113
+ TPutResult,
114
+ TPatchResult,
115
+ TFormUpdate,
116
+ TSourceId
117
+ >) {
118
+ return useForm<
119
+ TFormValues,
120
+ TPostParams,
121
+ TPutParams,
122
+ TPatchParams,
123
+ TPostPayload,
124
+ TPutPayload,
125
+ TPatchPayload,
126
+ TPostResult,
127
+ TPutResult,
128
+ TPatchResult,
129
+ TFormUpdate,
130
+ TSourceId
131
+ >({
132
+ id,
133
+ mutations,
134
+ formValues,
135
+ sourceData,
136
+ formatResponse,
137
+ transformRequest,
138
+ transformResponse,
139
+ updateType,
140
+ onSuccess
141
+ });
142
+ }`;
143
+ }
144
+
145
+ function generateMutations(operations: MutationOperations[string]): string {
146
+ const mutationStrings = [];
147
+ if (operations.post?.operationId && operations.post?.schema) {
148
+ mutationStrings.push(`post: {
149
+ // @ts-ignore
150
+ mutation: usePost${operations.post.operationId}(),
151
+ validation: Deref${operations.post.schema}
152
+ }`);
153
+ }
154
+ if (operations.put?.operationId && operations.put?.schema) {
155
+ mutationStrings.push(`put: {
156
+ // @ts-ignore
157
+ mutation: usePut${operations.put.operationId}(),
158
+ validation: Deref${operations.put.schema}
159
+ }`);
160
+ }
161
+ if (operations.patch?.operationId && operations.patch?.schema) {
162
+ mutationStrings.push(`patch: {
163
+ // @ts-ignore
164
+ mutation: usePatch${operations.patch.operationId}(),
165
+ validation: Deref${operations.patch.schema}
166
+ }`);
167
+ }
168
+ return mutationStrings.join(",\n ");
169
+ }
@@ -1,80 +1,80 @@
1
- import { capitaliseFirstLetter } from "../schema/capitalise-first-letter";
2
- import { toCamelCase } from "../schema/to-camel-case";
3
-
4
- export function generateGetAPIMethod(
5
- url: string,
6
- model: string,
7
- operationId: string,
8
- responseBody: string | undefined,
9
- isList: boolean,
10
- pathParameters: string[],
11
- requiredParameters: string[],
12
- method: string,
13
- requestBodySchema: string,
14
- ): [string, Set<string>] {
15
- const operationIdUpper = capitaliseFirstLetter(operationId);
16
- const paramNames =
17
- method === "post" ? `I${requestBodySchema}` : `I${operationIdUpper}Params`;
18
- const modelCamel = toCamelCase(model);
19
-
20
- url = url.replace("{", "${");
21
-
22
- const pathParameterString = pathParameters.map((item) => {
23
- return `const ${item} = options?.params?.${item};`;
24
- });
25
-
26
- const importStatements = new Set<string>();
27
-
28
- if (isList) {
29
- importStatements.add(
30
- `ListQueryOptions, useGetPaginatedQueryList, useUpdateQuery`,
31
- );
32
- importStatements.add(paramNames);
33
- importStatements.add(responseBody ?? "");
34
- return [
35
- `
36
- export function use${operationIdUpper}(
37
- options?: ListQueryOptions<${paramNames}, ${responseBody}>
38
- ) {
39
- const { isAuthenticated } = useAuth0();
40
- const pathParameters: (keyof ${paramNames})[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
41
- ${pathParameterString.join("\n")}
42
-
43
- return useGetPaginatedQueryList<${paramNames}, ${responseBody}>({
44
- ${method}Url: \`${url}\`,
45
- queryKey: ${modelCamel}QueriesKeys.${operationId},
46
- pathParameters,
47
- isAuthenticated,
48
- options,
49
- });
50
- }`,
51
- importStatements,
52
- ];
53
- } else {
54
- importStatements.add(`GetQueryOptions, useGetQuery`);
55
- importStatements.add(paramNames);
56
- importStatements.add(responseBody || "");
57
- return [
58
- `
59
- export function use${operationIdUpper}(
60
- options?: GetQueryOptions<${paramNames}>
61
- ) {
62
- const { isAuthenticated } = useAuth0();
63
- const pathParameters: string[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
64
- ${pathParameterString.join("\n")}
65
- const requiredParams: string[] = [${requiredParameters.map((item) => `'${item}'`).join(", ")}]
66
- return useGetQuery<${paramNames}, ${responseBody}>({
67
- ${method}Url: \`${url}\`,
68
- queryKey: ${modelCamel}QueriesKeys.${operationId},
69
- //@ts-ignore
70
- pathParameters,
71
- //@ts-ignore
72
- requiredParams,
73
- isAuthenticated,
74
- options,
75
- });
76
- }`,
77
- importStatements,
78
- ];
79
- }
80
- }
1
+ import { capitaliseFirstLetter } from "../schema/capitalise-first-letter";
2
+ import { toCamelCase } from "../schema/to-camel-case";
3
+
4
+ export function generateGetAPIMethod(
5
+ url: string,
6
+ model: string,
7
+ operationId: string,
8
+ responseBody: string | undefined,
9
+ isList: boolean,
10
+ pathParameters: string[],
11
+ requiredParameters: string[],
12
+ method: string,
13
+ requestBodySchema: string,
14
+ ): [string, Set<string>] {
15
+ const operationIdUpper = capitaliseFirstLetter(operationId);
16
+ const paramNames =
17
+ method === "post" ? `I${requestBodySchema}` : `I${operationIdUpper}Params`;
18
+ const modelCamel = toCamelCase(model);
19
+
20
+ url = url.replace("{", "${");
21
+
22
+ const pathParameterString = pathParameters.map((item) => {
23
+ return `const ${item} = options?.params?.${item};`;
24
+ });
25
+
26
+ const importStatements = new Set<string>();
27
+
28
+ if (isList) {
29
+ importStatements.add(
30
+ `ListQueryOptions, useGetPaginatedQueryList, useUpdateQuery`,
31
+ );
32
+ importStatements.add(paramNames);
33
+ importStatements.add(responseBody ?? "");
34
+ return [
35
+ `
36
+ export function use${operationIdUpper}(
37
+ options?: ListQueryOptions<${paramNames}, ${responseBody}>
38
+ ) {
39
+ const { isAuthenticated } = useAuth0();
40
+ const pathParameters: (keyof ${paramNames})[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
41
+ ${pathParameterString.join("\n")}
42
+
43
+ return useGetPaginatedQueryList<${paramNames}, ${responseBody}>({
44
+ ${method}Url: \`${url}\`,
45
+ queryKey: ${modelCamel}QueriesKeys.${operationId},
46
+ pathParameters,
47
+ isAuthenticated,
48
+ options,
49
+ });
50
+ }`,
51
+ importStatements,
52
+ ];
53
+ } else {
54
+ importStatements.add(`GetQueryOptions, useGetQuery`);
55
+ importStatements.add(paramNames);
56
+ importStatements.add(responseBody || "");
57
+ return [
58
+ `
59
+ export function use${operationIdUpper}(
60
+ options?: GetQueryOptions<${paramNames}>
61
+ ) {
62
+ const { isAuthenticated } = useAuth0();
63
+ const pathParameters: string[] = [${pathParameters.map((item) => `'${item}'`).join(", ")}]
64
+ ${pathParameterString.join("\n")}
65
+ const requiredParams: string[] = [${requiredParameters.map((item) => `'${item}'`).join(", ")}]
66
+ return useGetQuery<${paramNames}, ${responseBody}>({
67
+ ${method}Url: \`${url}\`,
68
+ queryKey: ${modelCamel}QueriesKeys.${operationId},
69
+ //@ts-ignore
70
+ pathParameters,
71
+ //@ts-ignore
72
+ requiredParams,
73
+ isAuthenticated,
74
+ options,
75
+ });
76
+ }`,
77
+ importStatements,
78
+ ];
79
+ }
80
+ }