@bleedingdev/modern-js-create 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121

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 (165) hide show
  1. package/README.md +167 -72
  2. package/bin/run.js +0 -0
  3. package/dist/cjs/create-package-root.cjs +63 -0
  4. package/dist/cjs/index.cjs +528 -0
  5. package/dist/cjs/locale/en.cjs +93 -0
  6. package/dist/cjs/locale/index.cjs +50 -0
  7. package/dist/cjs/locale/zh.cjs +93 -0
  8. package/dist/cjs/ultramodern-package-source.cjs +135 -0
  9. package/dist/cjs/ultramodern-workspace/add-vertical.cjs +337 -0
  10. package/dist/cjs/ultramodern-workspace/app-files.cjs +223 -0
  11. package/dist/cjs/ultramodern-workspace/contracts.cjs +836 -0
  12. package/dist/cjs/ultramodern-workspace/demo-components.cjs +422 -0
  13. package/dist/cjs/ultramodern-workspace/descriptors.cjs +222 -0
  14. package/dist/cjs/ultramodern-workspace/effect-api.cjs +952 -0
  15. package/dist/cjs/ultramodern-workspace/fs-io.cjs +191 -0
  16. package/dist/cjs/ultramodern-workspace/index.cjs +48 -0
  17. package/dist/cjs/ultramodern-workspace/locales.cjs +173 -0
  18. package/dist/cjs/ultramodern-workspace/module-federation.cjs +487 -0
  19. package/dist/cjs/ultramodern-workspace/naming.cjs +161 -0
  20. package/dist/cjs/ultramodern-workspace/package-json.cjs +406 -0
  21. package/dist/cjs/ultramodern-workspace/package-source.cjs +59 -0
  22. package/dist/cjs/ultramodern-workspace/policy.cjs +248 -0
  23. package/dist/cjs/ultramodern-workspace/public-surface.cjs +268 -0
  24. package/dist/cjs/ultramodern-workspace/routes.cjs +375 -0
  25. package/dist/cjs/ultramodern-workspace/types.cjs +61 -0
  26. package/dist/cjs/ultramodern-workspace/versions.cjs +153 -0
  27. package/dist/cjs/ultramodern-workspace/workspace-scripts.cjs +153 -0
  28. package/dist/cjs/ultramodern-workspace/write-workspace.cjs +175 -0
  29. package/dist/esm/create-package-root.js +14 -0
  30. package/dist/esm/index.js +491 -0
  31. package/dist/esm/locale/en.js +55 -0
  32. package/dist/esm/locale/index.js +9 -0
  33. package/dist/esm/locale/zh.js +55 -0
  34. package/dist/esm/ultramodern-package-source.js +63 -0
  35. package/dist/esm/ultramodern-workspace/add-vertical.js +252 -0
  36. package/dist/esm/ultramodern-workspace/app-files.js +149 -0
  37. package/dist/esm/ultramodern-workspace/contracts.js +741 -0
  38. package/dist/esm/ultramodern-workspace/demo-components.js +363 -0
  39. package/dist/esm/ultramodern-workspace/descriptors.js +133 -0
  40. package/dist/esm/ultramodern-workspace/effect-api.js +854 -0
  41. package/dist/esm/ultramodern-workspace/fs-io.js +90 -0
  42. package/dist/esm/ultramodern-workspace/index.js +3 -0
  43. package/dist/esm/ultramodern-workspace/locales.js +122 -0
  44. package/dist/esm/ultramodern-workspace/module-federation.js +415 -0
  45. package/dist/esm/ultramodern-workspace/naming.js +71 -0
  46. package/dist/esm/ultramodern-workspace/package-json.js +338 -0
  47. package/dist/esm/ultramodern-workspace/package-source.js +21 -0
  48. package/dist/esm/ultramodern-workspace/policy.js +183 -0
  49. package/dist/esm/ultramodern-workspace/public-surface.js +183 -0
  50. package/dist/esm/ultramodern-workspace/routes.js +280 -0
  51. package/dist/esm/ultramodern-workspace/types.js +16 -0
  52. package/dist/esm/ultramodern-workspace/versions.js +34 -0
  53. package/dist/esm/ultramodern-workspace/workspace-scripts.js +91 -0
  54. package/dist/esm/ultramodern-workspace/write-workspace.js +121 -0
  55. package/dist/esm-node/create-package-root.js +15 -0
  56. package/dist/esm-node/index.js +492 -0
  57. package/dist/esm-node/locale/en.js +56 -0
  58. package/dist/esm-node/locale/index.js +10 -0
  59. package/dist/esm-node/locale/zh.js +56 -0
  60. package/dist/esm-node/ultramodern-package-source.js +64 -0
  61. package/dist/esm-node/ultramodern-workspace/add-vertical.js +253 -0
  62. package/dist/esm-node/ultramodern-workspace/app-files.js +150 -0
  63. package/dist/esm-node/ultramodern-workspace/contracts.js +742 -0
  64. package/dist/esm-node/ultramodern-workspace/demo-components.js +364 -0
  65. package/dist/esm-node/ultramodern-workspace/descriptors.js +134 -0
  66. package/dist/esm-node/ultramodern-workspace/effect-api.js +855 -0
  67. package/dist/esm-node/ultramodern-workspace/fs-io.js +91 -0
  68. package/dist/esm-node/ultramodern-workspace/index.js +4 -0
  69. package/dist/esm-node/ultramodern-workspace/locales.js +123 -0
  70. package/dist/esm-node/ultramodern-workspace/module-federation.js +416 -0
  71. package/dist/esm-node/ultramodern-workspace/naming.js +72 -0
  72. package/dist/esm-node/ultramodern-workspace/package-json.js +339 -0
  73. package/dist/esm-node/ultramodern-workspace/package-source.js +22 -0
  74. package/dist/esm-node/ultramodern-workspace/policy.js +184 -0
  75. package/dist/esm-node/ultramodern-workspace/public-surface.js +184 -0
  76. package/dist/esm-node/ultramodern-workspace/routes.js +281 -0
  77. package/dist/esm-node/ultramodern-workspace/types.js +17 -0
  78. package/dist/esm-node/ultramodern-workspace/versions.js +35 -0
  79. package/dist/esm-node/ultramodern-workspace/workspace-scripts.js +92 -0
  80. package/dist/esm-node/ultramodern-workspace/write-workspace.js +122 -0
  81. package/dist/types/create-package-root.d.ts +1 -0
  82. package/dist/types/locale/en.d.ts +8 -9
  83. package/dist/types/locale/index.d.ts +109 -2
  84. package/dist/types/locale/zh.d.ts +8 -9
  85. package/dist/types/ultramodern-package-source.d.ts +28 -0
  86. package/dist/types/ultramodern-workspace/add-vertical.d.ts +19 -0
  87. package/dist/types/ultramodern-workspace/app-files.d.ts +14 -0
  88. package/dist/types/ultramodern-workspace/contracts.d.ts +21 -0
  89. package/dist/types/ultramodern-workspace/demo-components.d.ts +9 -0
  90. package/dist/types/ultramodern-workspace/descriptors.d.ts +39 -0
  91. package/dist/types/ultramodern-workspace/effect-api.d.ts +73 -0
  92. package/dist/types/ultramodern-workspace/fs-io.d.ts +18 -0
  93. package/dist/types/ultramodern-workspace/index.d.ts +4 -0
  94. package/dist/types/ultramodern-workspace/locales.d.ts +183 -0
  95. package/dist/types/ultramodern-workspace/module-federation.d.ts +16 -0
  96. package/dist/types/ultramodern-workspace/naming.d.ts +16 -0
  97. package/dist/types/ultramodern-workspace/package-json.d.ts +12 -0
  98. package/dist/types/ultramodern-workspace/package-source.d.ts +2 -0
  99. package/dist/types/ultramodern-workspace/policy.d.ts +60 -0
  100. package/dist/types/ultramodern-workspace/public-surface.d.ts +37 -0
  101. package/dist/types/ultramodern-workspace/routes.d.ts +25 -0
  102. package/dist/types/ultramodern-workspace/types.d.ts +95 -0
  103. package/dist/types/ultramodern-workspace/versions.d.ts +38 -0
  104. package/dist/types/ultramodern-workspace/workspace-scripts.d.ts +10 -0
  105. package/dist/types/ultramodern-workspace/write-workspace.d.ts +4 -0
  106. package/package.json +34 -15
  107. package/template-workspace/.agents/agent-reference-repos.json +24 -0
  108. package/template-workspace/.agents/skills-lock.json +19 -0
  109. package/template-workspace/.codex/hooks.json +16 -0
  110. package/template-workspace/.github/renovate.json +29 -0
  111. package/template-workspace/.github/workflows/ultramodern-workspace-gates.yml.handlebars +67 -0
  112. package/template-workspace/.gitignore.handlebars +5 -0
  113. package/template-workspace/.mise.toml.handlebars +3 -0
  114. package/template-workspace/AGENTS.md.handlebars +87 -0
  115. package/template-workspace/README.md.handlebars +132 -11
  116. package/template-workspace/lefthook.yml +24 -0
  117. package/template-workspace/oxfmt.config.ts +1 -0
  118. package/template-workspace/oxlint.config.ts +1 -0
  119. package/template-workspace/pnpm-workspace.yaml.handlebars +40 -0
  120. package/template-workspace/scripts/bootstrap-agent-skills.mjs +184 -21
  121. package/template-workspace/scripts/setup-agent-reference-repos.mjs +370 -0
  122. package/templates/app/shell-frame.tsx +49 -0
  123. package/templates/app/ultramodern-route-head.tsx.handlebars +142 -0
  124. package/templates/packages/shared-contracts-index.ts +466 -0
  125. package/templates/workspace-scripts/assert-mf-types.mjs.handlebars +69 -0
  126. package/templates/workspace-scripts/check-ultramodern-i18n-boundaries.mjs +9 -0
  127. package/templates/workspace-scripts/generate-public-surface-assets.mjs +529 -0
  128. package/templates/workspace-scripts/proof-cloudflare-version.mjs +125 -0
  129. package/templates/workspace-scripts/ultramodern-cloudflare-proof.mjs +851 -0
  130. package/templates/workspace-scripts/ultramodern-performance-readiness.config.mjs +7 -0
  131. package/templates/workspace-scripts/ultramodern-performance-readiness.mjs +223 -0
  132. package/templates/workspace-scripts/validate-ultramodern-workspace.mjs.handlebars +593 -0
  133. package/dist/index.js +0 -2626
  134. package/dist/types/ultramodern-workspace.d.ts +0 -20
  135. package/template/.agents/skills-lock.json +0 -34
  136. package/template/.browserslistrc +0 -4
  137. package/template/.github/workflows/ultramodern-gates.yml.handlebars +0 -30
  138. package/template/.gitignore.handlebars +0 -30
  139. package/template/.nvmrc +0 -2
  140. package/template/AGENTS.md +0 -25
  141. package/template/README.md +0 -79
  142. package/template/api/effect/index.ts.handlebars +0 -23
  143. package/template/api/lambda/hello.ts.handlebars +0 -6
  144. package/template/config/public/locales/cs/translation.json +0 -39
  145. package/template/config/public/locales/en/translation.json +0 -39
  146. package/template/modern.config.ts.handlebars +0 -53
  147. package/template/oxfmt.config.ts +0 -8
  148. package/template/oxlint.config.ts +0 -12
  149. package/template/package.json.handlebars +0 -67
  150. package/template/postcss.config.mjs.handlebars +0 -6
  151. package/template/scripts/bootstrap-agent-skills.mjs +0 -95
  152. package/template/scripts/check-i18n-strings.mjs +0 -83
  153. package/template/scripts/validate-ultramodern.mjs.handlebars +0 -178
  154. package/template/shared/effect/api.ts.handlebars +0 -17
  155. package/template/src/modern-app-env.d.ts +0 -1
  156. package/template/src/modern.runtime.ts.handlebars +0 -23
  157. package/template/src/routes/index.css.handlebars +0 -129
  158. package/template/src/routes/layout.tsx.handlebars +0 -9
  159. package/template/src/routes/page.tsx.handlebars +0 -155
  160. package/template/tailwind.config.ts.handlebars +0 -10
  161. package/template/tsconfig.json +0 -120
  162. package/template-workspace/AGENTS.md +0 -50
  163. package/template-workspace/pnpm-workspace.yaml +0 -17
  164. package/template-workspace/scripts/check-i18n-strings.mjs +0 -83
  165. package/template-workspace/scripts/validate-ultramodern-workspace.mjs.handlebars +0 -433
@@ -0,0 +1,854 @@
1
+ import { appHasEffectApi, effectApiPrefix, effectApiStem, verticalEffectApps } from "./descriptors.js";
2
+ import { packageName, toCamelCase, toPascalCase } from "./naming.js";
3
+ function verticalEffectApiExport(service) {
4
+ return `${toCamelCase(effectApiStem(service))}EffectApi`;
5
+ }
6
+ function verticalEffectGroupName(service) {
7
+ return toCamelCase(effectApiStem(service));
8
+ }
9
+ function verticalEffectApiName(service) {
10
+ return `${toPascalCase(effectApiStem(service))}EffectApi`;
11
+ }
12
+ function verticalEffectSchemaExport(service) {
13
+ return `${toCamelCase(effectApiStem(service))}ItemSchema`;
14
+ }
15
+ function verticalEffectMarkerSchemaExport(service) {
16
+ return `${toCamelCase(effectApiStem(service))}MarkerSchema`;
17
+ }
18
+ function verticalEffectReadinessSchemaExport(service) {
19
+ return `${toCamelCase(effectApiStem(service))}ReadinessSchema`;
20
+ }
21
+ function verticalEffectErrorStem(service) {
22
+ return effectApiStem(service);
23
+ }
24
+ function verticalEffectCreatePayloadSchemaExport(service) {
25
+ return `${toCamelCase(effectApiStem(service))}CreatePayloadSchema`;
26
+ }
27
+ function verticalEffectNotFoundErrorExport(service) {
28
+ return `${toPascalCase(verticalEffectErrorStem(service))}NotFound`;
29
+ }
30
+ function verticalEffectNotFoundSchemaExport(service) {
31
+ return `${toCamelCase(verticalEffectErrorStem(service))}NotFoundSchema`;
32
+ }
33
+ function serviceHasCheckoutCartState(service) {
34
+ return 'checkout' === effectApiStem(service);
35
+ }
36
+ function createCheckoutCartSharedSchemas(service) {
37
+ if (!serviceHasCheckoutCartState(service)) return '';
38
+ return `
39
+ export const checkoutCartLineSchema = Schema.Struct({
40
+ sku: Schema.String,
41
+ name: Schema.String,
42
+ quantity: Schema.Finite,
43
+ unitPriceCents: Schema.Finite,
44
+ });
45
+
46
+ export const checkoutCartSchema = Schema.Struct({
47
+ lines: Schema.Array(checkoutCartLineSchema),
48
+ subtotalCents: Schema.Finite,
49
+ totalQuantity: Schema.Finite,
50
+ });
51
+
52
+ export const checkoutAddCartItemPayloadSchema = Schema.Struct({
53
+ sku: Schema.String,
54
+ name: Schema.optional(Schema.String),
55
+ quantity: Schema.Finite,
56
+ unitPriceCents: Schema.optional(Schema.Finite),
57
+ });
58
+
59
+ export const checkoutRemoveCartItemPayloadSchema = Schema.Struct({
60
+ sku: Schema.String,
61
+ });
62
+ `;
63
+ }
64
+ function createCheckoutCartEndpointDefinitions(service) {
65
+ if (!serviceHasCheckoutCartState(service)) return '';
66
+ return `
67
+ .add(
68
+ HttpApiEndpoint.get('getCart', '/effect/checkout/cart', {
69
+ success: checkoutCartSchema,
70
+ }),
71
+ )
72
+ .add(
73
+ HttpApiEndpoint.post('addCartItem', '/effect/checkout/cart/items', {
74
+ payload: checkoutAddCartItemPayloadSchema,
75
+ success: checkoutCartSchema,
76
+ }),
77
+ )
78
+ .add(
79
+ HttpApiEndpoint.post('removeCartItem', '/effect/checkout/cart/remove', {
80
+ payload: checkoutRemoveCartItemPayloadSchema,
81
+ success: checkoutCartSchema,
82
+ }),
83
+ )
84
+ .add(
85
+ HttpApiEndpoint.post('clearCart', '/effect/checkout/cart/clear', {
86
+ success: checkoutCartSchema,
87
+ }),
88
+ )`;
89
+ }
90
+ function createCheckoutCartOperationContexts(service) {
91
+ const apiName = verticalEffectApiName(service);
92
+ const groupName = verticalEffectGroupName(service);
93
+ if (!serviceHasCheckoutCartState(service)) return '';
94
+ return `
95
+ addCartItem: {
96
+ method: 'POST',
97
+ operationId: '${apiName}:${groupName}:addCartItem',
98
+ routePath: '/effect/checkout/cart/items',
99
+ source: 'generated-client',
100
+ },
101
+ clearCart: {
102
+ method: 'POST',
103
+ operationId: '${apiName}:${groupName}:clearCart',
104
+ routePath: '/effect/checkout/cart/clear',
105
+ source: 'generated-client',
106
+ },
107
+ getCart: {
108
+ method: 'GET',
109
+ operationId: '${apiName}:${groupName}:getCart',
110
+ routePath: '/effect/checkout/cart',
111
+ source: 'generated-client',
112
+ },
113
+ removeCartItem: {
114
+ method: 'POST',
115
+ operationId: '${apiName}:${groupName}:removeCartItem',
116
+ routePath: '/effect/checkout/cart/remove',
117
+ source: 'generated-client',
118
+ },`;
119
+ }
120
+ function createCheckoutCartApiContractFields(service) {
121
+ if (!serviceHasCheckoutCartState(service)) return '';
122
+ return ` checkoutCartPath: '${effectApiPrefix(service)}/effect/checkout/cart',
123
+ `;
124
+ }
125
+ function createCheckoutCartServerState(service) {
126
+ if (!serviceHasCheckoutCartState(service)) return '';
127
+ return `
128
+ type CheckoutCartLine = {
129
+ sku: string;
130
+ name: string;
131
+ quantity: number;
132
+ unitPriceCents: number;
133
+ };
134
+
135
+ const checkoutCartLines = new Map<string, CheckoutCartLine>();
136
+
137
+ const createCheckoutCartSnapshot = () => {
138
+ const lines = [...checkoutCartLines.values()].sort((left, right) =>
139
+ left.sku.localeCompare(right.sku),
140
+ );
141
+ return {
142
+ lines,
143
+ subtotalCents: lines.reduce(
144
+ (total, line) => total + line.quantity * line.unitPriceCents,
145
+ 0,
146
+ ),
147
+ totalQuantity: lines.reduce((total, line) => total + line.quantity, 0),
148
+ };
149
+ };
150
+ `;
151
+ }
152
+ function createCheckoutCartServerHandlers(service) {
153
+ const groupName = verticalEffectGroupName(service);
154
+ if (!serviceHasCheckoutCartState(service)) return '';
155
+ return `
156
+ .handle('getCart', () =>
157
+ Effect.sync(() => createCheckoutCartSnapshot()).pipe(
158
+ Effect.withSpan('ultramodern.effect.${groupName}.checkout.getCart', {
159
+ attributes: operationAttributes(${groupName}OperationContexts.getCart),
160
+ kind: 'server',
161
+ }),
162
+ ),
163
+ )
164
+ .handle('addCartItem', ({ payload }) =>
165
+ Effect.sync(() => {
166
+ const existingLine = checkoutCartLines.get(payload.sku);
167
+ checkoutCartLines.set(payload.sku, {
168
+ sku: payload.sku,
169
+ name: payload.name ?? existingLine?.name ?? payload.sku,
170
+ quantity: (existingLine?.quantity ?? 0) + payload.quantity,
171
+ unitPriceCents:
172
+ payload.unitPriceCents ?? existingLine?.unitPriceCents ?? 0,
173
+ });
174
+ return createCheckoutCartSnapshot();
175
+ }).pipe(
176
+ Effect.withSpan('ultramodern.effect.${groupName}.checkout.addCartItem', {
177
+ attributes: operationAttributes(${groupName}OperationContexts.addCartItem),
178
+ kind: 'server',
179
+ }),
180
+ ),
181
+ )
182
+ .handle('removeCartItem', ({ payload }) =>
183
+ Effect.sync(() => {
184
+ checkoutCartLines.delete(payload.sku);
185
+ return createCheckoutCartSnapshot();
186
+ }).pipe(
187
+ Effect.withSpan('ultramodern.effect.${groupName}.checkout.removeCartItem', {
188
+ attributes: operationAttributes(${groupName}OperationContexts.removeCartItem),
189
+ kind: 'server',
190
+ }),
191
+ ),
192
+ )
193
+ .handle('clearCart', () =>
194
+ Effect.sync(() => {
195
+ checkoutCartLines.clear();
196
+ return createCheckoutCartSnapshot();
197
+ }).pipe(
198
+ Effect.withSpan('ultramodern.effect.${groupName}.checkout.clearCart', {
199
+ attributes: operationAttributes(${groupName}OperationContexts.clearCart),
200
+ kind: 'server',
201
+ }),
202
+ ),
203
+ )`;
204
+ }
205
+ function createCheckoutCartClientExports(service) {
206
+ if (!serviceHasCheckoutCartState(service)) return '';
207
+ const stem = effectApiStem(service);
208
+ const groupName = verticalEffectGroupName(service);
209
+ const pascalStem = toPascalCase(stem);
210
+ const clientOptionsName = `${pascalStem}ClientOptions`;
211
+ const createClientName = `create${pascalStem}Client`;
212
+ return `
213
+ export interface CheckoutCartLine {
214
+ sku: string;
215
+ name: string;
216
+ quantity: number;
217
+ unitPriceCents: number;
218
+ }
219
+
220
+ export interface CheckoutCart {
221
+ lines: readonly CheckoutCartLine[];
222
+ subtotalCents: number;
223
+ totalQuantity: number;
224
+ }
225
+
226
+ export interface CheckoutAddCartItemInput {
227
+ sku: string;
228
+ name?: string;
229
+ quantity: number;
230
+ unitPriceCents?: number;
231
+ }
232
+
233
+ export const getCheckoutCart = (
234
+ options: ${clientOptionsName} = {},
235
+ ) =>
236
+ ${createClientName}({
237
+ ...options,
238
+ operationContext:
239
+ options.operationContext ?? ${groupName}OperationContexts.getCart,
240
+ }).pipe(
241
+ Effect.flatMap(client => client.${groupName}.getCart({})),
242
+ );
243
+
244
+ export const addCheckoutCartItem = (
245
+ payload: CheckoutAddCartItemInput,
246
+ options: ${clientOptionsName} = {},
247
+ ) =>
248
+ ${createClientName}({
249
+ ...options,
250
+ operationContext:
251
+ options.operationContext ?? ${groupName}OperationContexts.addCartItem,
252
+ }).pipe(
253
+ Effect.flatMap(client =>
254
+ client.${groupName}.addCartItem({ payload }),
255
+ ),
256
+ );
257
+
258
+ export const removeCheckoutCartItem = (
259
+ sku: string,
260
+ options: ${clientOptionsName} = {},
261
+ ) =>
262
+ ${createClientName}({
263
+ ...options,
264
+ operationContext:
265
+ options.operationContext ?? ${groupName}OperationContexts.removeCartItem,
266
+ }).pipe(
267
+ Effect.flatMap(client =>
268
+ client.${groupName}.removeCartItem({ payload: { sku } }),
269
+ ),
270
+ );
271
+
272
+ export const clearCheckoutCart = (
273
+ options: ${clientOptionsName} = {},
274
+ ) =>
275
+ ${createClientName}({
276
+ ...options,
277
+ operationContext:
278
+ options.operationContext ?? ${groupName}OperationContexts.clearCart,
279
+ }).pipe(
280
+ Effect.flatMap(client => client.${groupName}.clearCart({})),
281
+ );
282
+ `;
283
+ }
284
+ function createEffectSharedApiImports() {
285
+ return `import {
286
+ HttpApi,
287
+ HttpApiEndpoint,
288
+ HttpApiGroup,
289
+ HttpApiSchema,
290
+ Schema,
291
+ } from '@modern-js/plugin-bff/effect-client';
292
+ `;
293
+ }
294
+ function createEffectSharedApiContract(service) {
295
+ const schemaExport = verticalEffectSchemaExport(service);
296
+ const markerSchemaExport = verticalEffectMarkerSchemaExport(service);
297
+ const readinessSchemaExport = verticalEffectReadinessSchemaExport(service);
298
+ const createPayloadSchemaExport = verticalEffectCreatePayloadSchemaExport(service);
299
+ const notFoundErrorExport = verticalEffectNotFoundErrorExport(service);
300
+ const notFoundSchemaExport = verticalEffectNotFoundSchemaExport(service);
301
+ const apiExport = verticalEffectApiExport(service);
302
+ const apiName = verticalEffectApiName(service);
303
+ const groupName = verticalEffectGroupName(service);
304
+ const stem = effectApiStem(service);
305
+ const apiPrefix = effectApiPrefix(service);
306
+ const checkoutCartSharedSchemas = createCheckoutCartSharedSchemas(service);
307
+ const checkoutCartSharedSchemaSection = '' === checkoutCartSharedSchemas ? '' : `${checkoutCartSharedSchemas}\n`;
308
+ const checkoutCartOperationContexts = createCheckoutCartOperationContexts(service).trimStart();
309
+ const checkoutCartOperationContextEntries = '' === checkoutCartOperationContexts ? '' : `${checkoutCartOperationContexts}\n`;
310
+ return `export const ${markerSchemaExport} = Schema.Struct({
311
+ appId: Schema.String,
312
+ build: Schema.String,
313
+ deployProfile: Schema.String,
314
+ packageName: Schema.String,
315
+ surface: Schema.String,
316
+ version: Schema.String,
317
+ });
318
+
319
+ export const ${schemaExport} = Schema.Struct({
320
+ id: Schema.String,
321
+ marker: ${markerSchemaExport},
322
+ title: Schema.String,
323
+ });
324
+
325
+ export const ${readinessSchemaExport} = Schema.Struct({
326
+ checks: Schema.Struct({
327
+ effectBff: Schema.Literal('ready'),
328
+ moduleFederation: Schema.Literal('ready'),
329
+ ssr: Schema.Literal('ready'),
330
+ translations: Schema.Literal('ready'),
331
+ }),
332
+ marker: ${markerSchemaExport},
333
+ status: Schema.Literal('ready'),
334
+ versionSkew: Schema.Literal('none'),
335
+ });
336
+
337
+ export const ${createPayloadSchemaExport} = Schema.Struct({
338
+ title: Schema.String,
339
+ });
340
+
341
+ ${checkoutCartSharedSchemaSection}export class ${notFoundErrorExport} extends Schema.TaggedErrorClass<${notFoundErrorExport}>()(
342
+ '${notFoundErrorExport}',
343
+ {
344
+ id: Schema.String,
345
+ },
346
+ ) {}
347
+
348
+ export const ${notFoundSchemaExport} = ${notFoundErrorExport}.pipe(
349
+ HttpApiSchema.status(404),
350
+ );
351
+
352
+ export interface OperationContext {
353
+ method: string;
354
+ operationId: string;
355
+ routePath: string;
356
+ source:
357
+ | 'client'
358
+ | 'server'
359
+ | 'generated-client'
360
+ | 'effect-adapter'
361
+ | 'data-platform'
362
+ | 'unknown';
363
+ traceId?: string;
364
+ }
365
+
366
+ export const ${apiExport} = HttpApi.make('${apiName}').add(
367
+ HttpApiGroup.make('${groupName}')
368
+ .add(
369
+ HttpApiEndpoint.get('list', '/effect/${stem}', {
370
+ query: {
371
+ limit: Schema.optional(Schema.FiniteFromString),
372
+ },
373
+ success: Schema.Struct({
374
+ items: Schema.Array(${schemaExport}),
375
+ }),
376
+ }),
377
+ )
378
+ .add(
379
+ HttpApiEndpoint.get('readiness', '/effect/${stem}/readiness', {
380
+ success: ${readinessSchemaExport},
381
+ }),
382
+ )
383
+ .add(
384
+ HttpApiEndpoint.get('get', '/effect/${stem}/:id', {
385
+ error: ${notFoundSchemaExport},
386
+ params: {
387
+ id: Schema.String,
388
+ },
389
+ success: ${schemaExport},
390
+ }),
391
+ )
392
+ .add(
393
+ HttpApiEndpoint.post('create', '/effect/${stem}', {
394
+ payload: ${createPayloadSchemaExport},
395
+ success: Schema.Struct({
396
+ item: ${schemaExport},
397
+ }),
398
+ }),
399
+ )${createCheckoutCartEndpointDefinitions(service)},
400
+ );
401
+
402
+ export const ${groupName}OperationContexts = {
403
+ ${checkoutCartOperationContextEntries} create: {
404
+ method: 'POST',
405
+ operationId: '${apiName}:${groupName}:create',
406
+ routePath: '/effect/${stem}',
407
+ source: 'generated-client',
408
+ },
409
+ get: {
410
+ method: 'GET',
411
+ operationId: '${apiName}:${groupName}:get',
412
+ routePath: '/effect/${stem}/:id',
413
+ source: 'generated-client',
414
+ },
415
+ list: {
416
+ method: 'GET',
417
+ operationId: '${apiName}:${groupName}:list',
418
+ routePath: '/effect/${stem}',
419
+ source: 'generated-client',
420
+ },
421
+ readiness: {
422
+ method: 'GET',
423
+ operationId: '${apiName}:${groupName}:readiness',
424
+ routePath: '/effect/${stem}/readiness',
425
+ source: 'generated-client',
426
+ },
427
+ } satisfies Record<string, OperationContext>;
428
+
429
+ export const ${groupName}ApiContract = {
430
+ apiPrefix: '${apiPrefix}',
431
+ basePath: '${apiPrefix}/effect/${stem}',
432
+ ${createCheckoutCartApiContractFields(service)} ownerId: '${service.id}',
433
+ readinessPath: '${apiPrefix}/effect/${stem}/readiness',
434
+ } as const;
435
+ `;
436
+ }
437
+ function createEffectSharedApi(service) {
438
+ return `${createEffectSharedApiImports()}
439
+ ${createEffectSharedApiContract(service)}`;
440
+ }
441
+ function createEffectServiceEntry(service, contractImportPath) {
442
+ const apiExport = verticalEffectApiExport(service);
443
+ const groupName = verticalEffectGroupName(service);
444
+ const notFoundErrorExport = verticalEffectNotFoundErrorExport(service);
445
+ const stem = effectApiStem(service);
446
+ return `import {
447
+ defineEffectBff,
448
+ Effect,
449
+ HttpApiBuilder,
450
+ Layer,
451
+ } from '@modern-js/plugin-bff/effect-edge';
452
+ import { ultramodernApiMarker } from '../../src/ultramodern-build.ts';
453
+ import {
454
+ ${apiExport},
455
+ ${groupName}OperationContexts,
456
+ ${notFoundErrorExport},
457
+ } from '${contractImportPath}';
458
+ import type { OperationContext } from '${contractImportPath}';
459
+
460
+ const ${groupName}Items = [
461
+ {
462
+ id: 'starter-${stem}',
463
+ marker: ultramodernApiMarker,
464
+ title: 'Wire a real ${stem} source here',
465
+ },
466
+ ];
467
+ ${createCheckoutCartServerState(service)}
468
+
469
+ const operationAttributes = (operationContext: OperationContext) => ({
470
+ 'modernjs.operation.id': operationContext.operationId,
471
+ 'modernjs.operation.method': operationContext.method,
472
+ 'modernjs.operation.route': operationContext.routePath,
473
+ 'modernjs.operation.source': operationContext.source,
474
+ ...(typeof operationContext.traceId === 'string'
475
+ ? { 'modernjs.trace.id': operationContext.traceId }
476
+ : {}),
477
+ });
478
+
479
+ const ${groupName}Layer = HttpApiBuilder.group(
480
+ ${apiExport},
481
+ '${groupName}',
482
+ (handlers) =>
483
+ handlers
484
+ .handle('list', ({ query }) =>
485
+ Effect.succeed({
486
+ items:
487
+ typeof query.limit === 'number'
488
+ ? ${groupName}Items.slice(0, query.limit)
489
+ : ${groupName}Items,
490
+ }).pipe(
491
+ Effect.withSpan('ultramodern.effect.${groupName}.list', {
492
+ attributes: operationAttributes(${groupName}OperationContexts.list),
493
+ kind: 'server',
494
+ }),
495
+ ),
496
+ )
497
+ .handle('readiness', () =>
498
+ Effect.succeed({
499
+ checks: {
500
+ effectBff: 'ready' as const,
501
+ moduleFederation: 'ready' as const,
502
+ ssr: 'ready' as const,
503
+ translations: 'ready' as const,
504
+ },
505
+ marker: ultramodernApiMarker,
506
+ status: 'ready' as const,
507
+ versionSkew: 'none' as const,
508
+ }).pipe(
509
+ Effect.withSpan('ultramodern.effect.${groupName}.readiness', {
510
+ attributes: operationAttributes(${groupName}OperationContexts.readiness),
511
+ kind: 'server',
512
+ }),
513
+ ),
514
+ )
515
+ .handle('get', ({ params }) => {
516
+ const matchedItem = ${groupName}Items.find(
517
+ candidate => candidate.id === params.id,
518
+ );
519
+ const result =
520
+ matchedItem === undefined
521
+ ? Effect.fail(new ${notFoundErrorExport}({ id: params.id }))
522
+ : Effect.succeed(matchedItem);
523
+
524
+ return result.pipe(
525
+ Effect.withSpan('ultramodern.effect.${groupName}.get', {
526
+ attributes: operationAttributes(${groupName}OperationContexts.get),
527
+ kind: 'server',
528
+ }),
529
+ );
530
+ })
531
+ .handle('create', ({ payload }) =>
532
+ Effect.succeed({
533
+ item: {
534
+ id: \`generated-${stem}-\${payload.title
535
+ .toLowerCase()
536
+ .replaceAll(/[^a-z0-9]+/gu, '-')
537
+ .replaceAll(/^-|-$/gu, '')}\`,
538
+ marker: ultramodernApiMarker,
539
+ title: payload.title,
540
+ },
541
+ }).pipe(
542
+ Effect.withSpan('ultramodern.effect.${groupName}.create', {
543
+ attributes: operationAttributes(${groupName}OperationContexts.create),
544
+ kind: 'server',
545
+ }),
546
+ ),
547
+ )${createCheckoutCartServerHandlers(service)},
548
+ );
549
+
550
+ const layer = HttpApiBuilder.layer(${apiExport}).pipe(
551
+ Layer.provide(${groupName}Layer),
552
+ );
553
+
554
+ export default defineEffectBff({
555
+ api: ${apiExport},
556
+ layer,
557
+ });
558
+ `;
559
+ }
560
+ function createEffectClient(service, contractImportPath) {
561
+ const apiExport = verticalEffectApiExport(service);
562
+ const contractExport = verticalEffectGroupName(service);
563
+ const stem = effectApiStem(service);
564
+ const groupName = verticalEffectGroupName(service);
565
+ const singular = verticalEffectErrorStem(service);
566
+ const clientOptionsName = `${toPascalCase(stem)}ClientOptions`;
567
+ const createClientName = `create${toPascalCase(stem)}Client`;
568
+ const listName = `list${toPascalCase(stem)}`;
569
+ const readinessName = `get${toPascalCase(stem)}Readiness`;
570
+ const getName = `get${toPascalCase(singular)}`;
571
+ const createName = `create${toPascalCase(singular)}`;
572
+ const checkoutCartClientExports = createCheckoutCartClientExports(service);
573
+ return `import {
574
+ Effect,
575
+ makeEffectHttpApiClient,
576
+ runEffectRequest,
577
+ } from '@modern-js/plugin-bff/effect-client';
578
+ import {
579
+ ${contractExport}ApiContract,
580
+ ${apiExport},
581
+ ${groupName}OperationContexts,
582
+ } from '${contractImportPath}';
583
+ import type { OperationContext } from '${contractImportPath}';
584
+
585
+ export { Effect, runEffectRequest };
586
+
587
+ export interface ${clientOptionsName} {
588
+ baseUrl?: string | URL;
589
+ locale?: string;
590
+ operationContext?: OperationContext;
591
+ traceparent?: string;
592
+ }
593
+
594
+ export const ${createClientName} = (
595
+ options: ${clientOptionsName} = {},
596
+ ) =>
597
+ makeEffectHttpApiClient(${apiExport}, {
598
+ baseUrl: options.baseUrl ?? ${contractExport}ApiContract.apiPrefix,
599
+ requestContext: {
600
+ ...(options.locale === undefined ? {} : { locale: options.locale }),
601
+ ...(options.operationContext === undefined
602
+ ? {}
603
+ : { operationContext: options.operationContext }),
604
+ ...(options.traceparent === undefined
605
+ ? {}
606
+ : { traceparent: options.traceparent }),
607
+ },
608
+ });
609
+
610
+ export const ${listName} = (
611
+ options: ${clientOptionsName} & { limit?: number } = {},
612
+ ) =>
613
+ ${createClientName}({
614
+ ...options,
615
+ operationContext:
616
+ options.operationContext ?? ${groupName}OperationContexts.list,
617
+ }).pipe(
618
+ Effect.flatMap(client =>
619
+ client.${groupName}.list({ query: { limit: options.limit } }),
620
+ ),
621
+ );
622
+
623
+ export const ${readinessName} = (
624
+ options: ${clientOptionsName} = {},
625
+ ) =>
626
+ ${createClientName}({
627
+ ...options,
628
+ operationContext:
629
+ options.operationContext ?? ${groupName}OperationContexts.readiness,
630
+ }).pipe(
631
+ Effect.flatMap(client => client.${groupName}.readiness({})),
632
+ );
633
+
634
+ export const ${getName} = (
635
+ id: string,
636
+ options: ${clientOptionsName} = {},
637
+ ) =>
638
+ ${createClientName}({
639
+ ...options,
640
+ operationContext:
641
+ options.operationContext ?? ${groupName}OperationContexts.get,
642
+ }).pipe(
643
+ Effect.flatMap(client => client.${groupName}.get({ params: { id } })),
644
+ );
645
+
646
+ export const ${createName} = (
647
+ title: string,
648
+ options: ${clientOptionsName} = {},
649
+ ) =>
650
+ ${createClientName}({
651
+ ...options,
652
+ operationContext:
653
+ options.operationContext ?? ${groupName}OperationContexts.create,
654
+ }).pipe(
655
+ Effect.flatMap(client =>
656
+ client.${groupName}.create({ payload: { title } }),
657
+ ),
658
+ );${checkoutCartClientExports}
659
+ `;
660
+ }
661
+ function createShellEffectClient(scope, remotes = []) {
662
+ const exports = verticalEffectApps(remotes).map((remote)=>{
663
+ const stem = effectApiStem(remote);
664
+ const pascalStem = toPascalCase(stem);
665
+ const pascalSingular = toPascalCase(verticalEffectErrorStem(remote));
666
+ const checkoutCartExports = serviceHasCheckoutCartState(remote) ? ` addCheckoutCartItem,
667
+ clearCheckoutCart,
668
+ getCheckoutCart,
669
+ removeCheckoutCartItem,
670
+ type CheckoutAddCartItemInput,
671
+ type CheckoutCart,
672
+ type CheckoutCartLine,
673
+ ` : '';
674
+ return `export {
675
+ ${checkoutCartExports} create${pascalSingular},
676
+ create${pascalStem}Client,
677
+ get${pascalSingular},
678
+ get${pascalStem}Readiness,
679
+ list${pascalStem},
680
+ type ${pascalStem}ClientOptions,
681
+ } from '${packageName(scope, remote.packageSuffix)}/effect/client';`;
682
+ }).join('\n\n');
683
+ return exports ? `${exports}\n` : `export const ultramodernVerticalClients = [] as const;
684
+ `;
685
+ }
686
+ function createEffectReadinessContract(app) {
687
+ const stem = effectApiStem(app);
688
+ return {
689
+ endpoint: `/effect/${stem}/readiness`,
690
+ marker: {
691
+ ui: 'ultramodernUiMarker',
692
+ api: 'ultramodernApiMarker',
693
+ skew: 'none'
694
+ },
695
+ checks: [
696
+ 'moduleFederation',
697
+ 'ssr',
698
+ 'translations',
699
+ 'effectBff'
700
+ ]
701
+ };
702
+ }
703
+ function createEffectRequestContextContract() {
704
+ return {
705
+ propagatedHeaders: [
706
+ 'accept-language',
707
+ 'authorization',
708
+ 'traceparent',
709
+ 'x-correlation-id',
710
+ 'x-tenant-id',
711
+ 'x-ultramodern-env',
712
+ 'x-vertical-version-id'
713
+ ],
714
+ source: 'shell-to-vertical-effect-client'
715
+ };
716
+ }
717
+ function createEffectDomainOperations(app) {
718
+ const stem = effectApiStem(app);
719
+ const group = verticalEffectGroupName(app);
720
+ const basePath = `/effect/${stem}`;
721
+ const checkoutCartOperations = serviceHasCheckoutCartState(app) ? {
722
+ checkoutCartAddItem: {
723
+ client: 'addCheckoutCartItem',
724
+ method: 'POST',
725
+ path: '/effect/checkout/cart/items',
726
+ resource: 'checkout-cart',
727
+ owner: app.id
728
+ },
729
+ checkoutCartClear: {
730
+ client: 'clearCheckoutCart',
731
+ method: 'POST',
732
+ path: '/effect/checkout/cart/clear',
733
+ resource: 'checkout-cart',
734
+ owner: app.id
735
+ },
736
+ checkoutCartRead: {
737
+ client: 'getCheckoutCart',
738
+ method: 'GET',
739
+ path: '/effect/checkout/cart',
740
+ resource: 'checkout-cart',
741
+ owner: app.id
742
+ },
743
+ checkoutCartRemoveItem: {
744
+ client: 'removeCheckoutCartItem',
745
+ method: 'POST',
746
+ path: '/effect/checkout/cart/remove',
747
+ resource: 'checkout-cart',
748
+ owner: app.id
749
+ }
750
+ } : {};
751
+ return {
752
+ ...checkoutCartOperations,
753
+ workspaceFeed: {
754
+ client: `list${toPascalCase(stem)}`,
755
+ method: 'GET',
756
+ path: basePath,
757
+ resource: 'workspace-items',
758
+ owner: app.id
759
+ },
760
+ workspaceDetail: {
761
+ client: `get${toPascalCase(verticalEffectErrorStem(app))}`,
762
+ method: 'GET',
763
+ path: `${basePath}/:id`,
764
+ resource: 'workspace-item',
765
+ owner: app.id
766
+ },
767
+ workspaceCreate: {
768
+ client: `create${toPascalCase(verticalEffectErrorStem(app))}`,
769
+ method: 'POST',
770
+ path: basePath,
771
+ resource: group,
772
+ owner: app.id
773
+ }
774
+ };
775
+ }
776
+ function effectApiTopologyMetadata(app) {
777
+ if (!appHasEffectApi(app)) return;
778
+ return {
779
+ effect: {
780
+ runtime: 'effect',
781
+ bff: {
782
+ prefix: app.effectApi.prefix,
783
+ openapi: '/openapi.json'
784
+ },
785
+ contract: {
786
+ export: './shared/effect/api',
787
+ path: `${app.directory}/shared/effect/api.ts`
788
+ },
789
+ client: {
790
+ export: './effect/client',
791
+ path: `${app.directory}/src/effect/${app.effectApi.stem}-client.ts`
792
+ },
793
+ serverEntry: `${app.directory}/api/effect/index.ts`,
794
+ basePath: `${app.effectApi.prefix}/effect/${app.effectApi.stem}`,
795
+ consumedBy: app.effectApi.consumedBy,
796
+ readiness: createEffectReadinessContract(app),
797
+ requestContext: createEffectRequestContextContract(),
798
+ domainOperations: createEffectDomainOperations(app)
799
+ }
800
+ };
801
+ }
802
+ function createEffectOperationContract(target) {
803
+ const stem = effectApiStem(target);
804
+ const checkoutCartOperations = serviceHasCheckoutCartState(target) ? {
805
+ addCartItem: {
806
+ method: 'POST',
807
+ path: '/effect/checkout/cart/items',
808
+ source: 'generated-client'
809
+ },
810
+ clearCart: {
811
+ method: 'POST',
812
+ path: '/effect/checkout/cart/clear',
813
+ source: 'generated-client'
814
+ },
815
+ getCart: {
816
+ method: 'GET',
817
+ path: '/effect/checkout/cart',
818
+ source: 'generated-client'
819
+ },
820
+ removeCartItem: {
821
+ method: 'POST',
822
+ path: '/effect/checkout/cart/remove',
823
+ source: 'generated-client'
824
+ }
825
+ } : {};
826
+ return {
827
+ group: verticalEffectGroupName(target),
828
+ notFound: verticalEffectNotFoundErrorExport(target),
829
+ operations: {
830
+ ...checkoutCartOperations,
831
+ list: {
832
+ method: 'GET',
833
+ path: `/effect/${stem}`,
834
+ source: 'generated-client'
835
+ },
836
+ readiness: {
837
+ method: 'GET',
838
+ path: `/effect/${stem}/readiness`,
839
+ source: 'generated-client'
840
+ },
841
+ get: {
842
+ method: 'GET',
843
+ path: `/effect/${stem}/:id`,
844
+ source: 'generated-client'
845
+ },
846
+ create: {
847
+ method: 'POST',
848
+ path: `/effect/${stem}`,
849
+ source: 'generated-client'
850
+ }
851
+ }
852
+ };
853
+ }
854
+ export { createEffectClient, createEffectDomainOperations, createEffectOperationContract, createEffectReadinessContract, createEffectRequestContextContract, createEffectServiceEntry, createEffectSharedApi, createEffectSharedApiContract, createEffectSharedApiImports, createShellEffectClient, effectApiTopologyMetadata, verticalEffectApiExport, verticalEffectApiName, verticalEffectCreatePayloadSchemaExport, verticalEffectErrorStem, verticalEffectGroupName, verticalEffectMarkerSchemaExport, verticalEffectNotFoundErrorExport, verticalEffectNotFoundSchemaExport, verticalEffectReadinessSchemaExport, verticalEffectSchemaExport };