@powerlines/plugin-env 0.16.183 → 0.16.184

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 (51) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -1
  2. package/dist/babel/index.cjs +4 -1
  3. package/dist/babel/index.mjs +3 -1
  4. package/dist/babel/plugin.cjs +137 -4
  5. package/dist/babel/plugin.mjs +135 -4
  6. package/dist/babel/plugin.mjs.map +1 -1
  7. package/dist/components/docs.cjs +111 -1
  8. package/dist/components/docs.mjs +108 -1
  9. package/dist/components/docs.mjs.map +1 -1
  10. package/dist/components/env-builtin.cjs +730 -13
  11. package/dist/components/env-builtin.mjs +726 -11
  12. package/dist/components/env-builtin.mjs.map +1 -1
  13. package/dist/components/index.cjs +9 -1
  14. package/dist/components/index.mjs +4 -1
  15. package/dist/helpers/automd-generator.cjs +32 -1
  16. package/dist/helpers/automd-generator.mjs +30 -1
  17. package/dist/helpers/automd-generator.mjs.map +1 -1
  18. package/dist/helpers/create-reflection-resource.cjs +23 -1
  19. package/dist/helpers/create-reflection-resource.mjs +22 -1
  20. package/dist/helpers/create-reflection-resource.mjs.map +1 -1
  21. package/dist/helpers/index.cjs +34 -1
  22. package/dist/helpers/index.mjs +8 -1
  23. package/dist/helpers/load.cjs +141 -1
  24. package/dist/helpers/load.d.cts +1 -1
  25. package/dist/helpers/load.d.mts +1 -1
  26. package/dist/helpers/load.mjs +137 -1
  27. package/dist/helpers/load.mjs.map +1 -1
  28. package/dist/helpers/persistence.cjs +308 -1
  29. package/dist/helpers/persistence.mjs +295 -1
  30. package/dist/helpers/persistence.mjs.map +1 -1
  31. package/dist/helpers/reflect.cjs +290 -1
  32. package/dist/helpers/reflect.mjs +280 -1
  33. package/dist/helpers/reflect.mjs.map +1 -1
  34. package/dist/helpers/source-file-env.cjs +59 -1
  35. package/dist/helpers/source-file-env.mjs +56 -1
  36. package/dist/helpers/source-file-env.mjs.map +1 -1
  37. package/dist/helpers/template-helpers.cjs +70 -1
  38. package/dist/helpers/template-helpers.mjs +68 -1
  39. package/dist/helpers/template-helpers.mjs.map +1 -1
  40. package/dist/index.cjs +310 -7
  41. package/dist/index.mjs +296 -7
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/types/env.cjs +541 -1
  44. package/dist/types/env.mjs +538 -1
  45. package/dist/types/env.mjs.map +1 -1
  46. package/dist/types/index.cjs +11 -1
  47. package/dist/types/index.mjs +4 -1
  48. package/dist/types/plugin.cjs +115 -1
  49. package/dist/types/plugin.mjs +109 -1
  50. package/dist/types/plugin.mjs.map +1 -1
  51. package/package.json +9 -9
@@ -1,7 +1,458 @@
1
- import{__ΩEnvPluginContext as e}from"../types/plugin.mjs";import{loadEnvFromContext as t}from"../helpers/load.mjs";import{titleCase as n}from"@stryke/string-format/title-case";import{ReflectionClass as r,ReflectionKind as i}from"@powerlines/deepkit/vendor/type";import a from"defu";import{createComponent as o,createIntrinsic as s,memo as c,mergeProps as l}from"@alloy-js/core/jsx-runtime";import{For as u,Show as d,code as f,computed as p,splitProps as m}from"@alloy-js/core";import{Spacing as h}from"@powerlines/plugin-alloy/core/components/spacing";import{usePowerlines as g}from"@powerlines/plugin-alloy/core/contexts/context";import{ClassDeclaration as _,ClassMethod as v,ElseIfClause as y,FunctionDeclaration as b,IfStatement as x,InterfaceDeclaration as S,InterfaceMember as C,NewExpression as w,VarDeclaration as T}from"@alloy-js/typescript";import{refkey as E}from"@powerlines/plugin-alloy/helpers/refkey";import{BuiltinFile as D}from"@powerlines/plugin-alloy/typescript/components/builtin-file";import{InterfaceDeclaration as O}from"@powerlines/plugin-alloy/typescript/components/interface-declaration";import{ObjectDeclaration as k}from"@powerlines/plugin-alloy/typescript/components/object-declaration";import{TSDoc as A,TSDocExample as j,TSDocLink as M,TSDocParam as N,TSDocRemarks as P,TSDocReturns as F,TSDocThrows as I}from"@powerlines/plugin-alloy/typescript/components/tsdoc";import{TSDocReflectionProperty as L}from"@powerlines/plugin-alloy/typescript/components/tsdoc-reflection";import{getUnique as R}from"@stryke/helpers/get-unique";const z=[`T`,`K`,()=>B,()=>V,`Omit`,`b!b"e!!e!!ge!"o$#o##w%y`],B=[`T`,`K`,`Pick`,`l+e#!e"!fRb!b"Pde""N#!w#y`],V=[`T`,`U`,`Exclude`,`l6!Re$!RPe#!e$"qk#%QRb!b"Pde"!p)w#y`];function H(e,t){return e.__type=t,e}function U(t){let[{defaultValue:n,reflection:r}]=m(t,[`defaultValue`,`reflection`]),i=(g.Ω=[[()=>e,`n!`]],g());return[o(O,{name:`UnprefixedEnv`,defaultValue:n,reflection:r,export:!0}),o(h,{}),o(A,{heading:`The environment configuration object with prefixed keys.`,get children(){return o(P,{children:"The `Env` type extends the `UnprefixedEnv` interface by including additional keys that are prefixed according to the project's configuration. This allows for flexibility in accessing environment variables with different naming conventions."})}}),o(S,{name:`Env`,export:!0,extends:`UnprefixedEnv`,get children(){return o(u,{get each(){return R(i.config.env.prefix).map(H(e=>e.replace(/_$/,``),[`prefix`,``,`P"2!"/"`]))},doubleHardline:!0,get children(){return H(e=>o(u,{get each(){return r?.getProperties().filter(H(e=>!e.isIgnored(),[`property`,``,`P"2!"/"`]))??[]},doubleHardline:!0,get children(){return H(t=>[o(L,{reflection:t}),o(C,{get name(){return`${e}_${t.getNameAsString()}`},get type(){return`UnprefixedEnv["${t.getNameAsString()}"]`},get readonly(){return t.isReadonly()}})],[`property`,``,`P"2!"/"`])}}),[`prefix`,``,`P"2!"/"`])}})}}),o(h,{})]}U.__type=[()=>z,`name`,`props`,`EnvTypeDefinition`,`Generates the environment configuration typescript definition for the Powerlines project.`,`P!."o!#2#"/$?%`];const W=[()=>e,`context`,`name`,`ConfigPropertyConditionalProps`,`P!n!4"&4#Mw$y`];function G(e){let[{context:t,name:n}]=m(e,[`context`,`name`]);return f`propertyName === "${n}" || propertyName.replace(/^(${R(t.config.env.prefix.sort(H((e,t)=>e.startsWith(t)?-1:t.startsWith(e)?1:e.localeCompare(t),[`a`,`b`,``,`P"2!"2""/#`])).map(H(e=>`${e.replace(/_$/,``)}_`,[`prefix`,``,`P"2!"/"`]))).join(`|`)})/g, "").toLowerCase().replace(/[\\s\\-_]+/g, "") === "${n.toLowerCase().replace(/[\s\-_]+/g,``)}"`}G.__type=[()=>W,`props`,`ConfigPropertyConditional`,`Pn!2""/#`];const K=[`index`,()=>e,`context`,`property`,`ConfigPropertyProps`,`P!'4!n"4#!4$Mw%y`];function q(e){let[{context:t,property:n,index:r}]=m(e,[`context`,`property`,`index`]);return[o(r===0?x:y,{get condition(){return[o(G,{get name(){return n.getNameAsString()},context:t}),o(d,{get when(){return c(()=>!!n.getAlias())()&&n.getAlias().length>0},get children(){return[f` || `,o(u,{get each(){return n.getAlias()},joiner:f` || `,get children(){return H(e=>o(G,{name:e,context:t}),[`alias`,``,`P"2!"/"`])}})]}})]},get children(){return f`return target["${n.getNameAsString()}"];`}})]}q.__type=[()=>K,`props`,`ConfigPropertyGet`,`Pn!2""/#`];function J(e){let[{context:t,property:n,index:r}]=m(e,[`context`,`property`,`index`]);return[o(r===0?x:y,{get condition(){return[o(G,{get name(){return n.getNameAsString()},context:t}),o(d,{get when(){return c(()=>!!n.getAlias())()&&n.getAlias().length>0},get children(){return[f` || `,o(u,{get each(){return n.getAlias()},joiner:f` || `,get children(){return H(e=>o(G,{name:e,context:t}),[`alias`,``,`P"2!"/"`])}})]}})]},get children(){return f`
2
- target["${n.getNameAsString()}"] = newValue;
1
+ import { __ΩEnvPluginContext } from "../types/plugin.mjs";
2
+ import { loadEnvFromContext } from "../helpers/load.mjs";
3
+ import { titleCase } from "@stryke/string-format/title-case";
4
+ import { ReflectionClass, ReflectionKind } from "@powerlines/deepkit/vendor/type";
5
+ import defu from "defu";
6
+ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
7
+ import { For, Show, code, computed, splitProps } from "@alloy-js/core";
8
+ import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
9
+ import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
10
+ import { ClassDeclaration, ClassMethod, ElseIfClause, FunctionDeclaration, IfStatement, InterfaceDeclaration, InterfaceMember, NewExpression, VarDeclaration } from "@alloy-js/typescript";
11
+ import { refkey } from "@powerlines/plugin-alloy/helpers/refkey";
12
+ import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
13
+ import { InterfaceDeclaration as InterfaceDeclaration$1 } from "@powerlines/plugin-alloy/typescript/components/interface-declaration";
14
+ import { ObjectDeclaration } from "@powerlines/plugin-alloy/typescript/components/object-declaration";
15
+ import { TSDoc, TSDocExample, TSDocLink, TSDocParam, TSDocRemarks, TSDocReturns, TSDocThrows } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
16
+ import { TSDocReflectionProperty } from "@powerlines/plugin-alloy/typescript/components/tsdoc-reflection";
17
+ import { getUnique } from "@stryke/helpers/get-unique";
18
+
19
+ //#region src/components/env-builtin.tsx
20
+ const __ΩOmit = [
21
+ "T",
22
+ "K",
23
+ () => __ΩPick,
24
+ () => __ΩExclude,
25
+ "Omit",
26
+ "b!b\"e!!e!!ge!\"o$#o##w%y"
27
+ ];
28
+ const __ΩPick = [
29
+ "T",
30
+ "K",
31
+ "Pick",
32
+ "l+e#!e\"!fRb!b\"Pde\"\"N#!w#y"
33
+ ];
34
+ const __ΩExclude = [
35
+ "T",
36
+ "U",
37
+ "Exclude",
38
+ "l6!Re$!RPe#!e$\"qk#%QRb!b\"Pde\"!p)w#y"
39
+ ];
40
+ function __assignType(fn, args) {
41
+ fn.__type = args;
42
+ return fn;
43
+ }
44
+ /**
45
+ * Generates the environment configuration typescript definition for the Powerlines project.
46
+ */
47
+ function EnvTypeDefinition(props) {
48
+ const [{ defaultValue, reflection }] = splitProps(props, ["defaultValue", "reflection"]);
49
+ const context = (usePowerlines.Ω = [[() => __ΩEnvPluginContext, "n!"]], usePowerlines());
50
+ return [
51
+ createComponent(InterfaceDeclaration$1, {
52
+ name: "UnprefixedEnv",
53
+ defaultValue,
54
+ reflection,
55
+ "export": true
56
+ }),
57
+ createComponent(Spacing, {}),
58
+ createComponent(TSDoc, {
59
+ heading: "The environment configuration object with prefixed keys.",
60
+ get children() {
61
+ return createComponent(TSDocRemarks, { children: `The \`Env\` type extends the \`UnprefixedEnv\` interface by including additional keys that are prefixed according to the project's configuration. This allows for flexibility in accessing environment variables with different naming conventions.` });
62
+ }
63
+ }),
64
+ createComponent(InterfaceDeclaration, {
65
+ name: "Env",
66
+ "export": true,
67
+ "extends": "UnprefixedEnv",
68
+ get children() {
69
+ return createComponent(For, {
70
+ get each() {
71
+ return getUnique(context.config.env.prefix).map(__assignType((prefix) => prefix.replace(/_$/, ""), [
72
+ "prefix",
73
+ "",
74
+ "P\"2!\"/\""
75
+ ]));
76
+ },
77
+ doubleHardline: true,
78
+ get children() {
79
+ return __assignType((prefix) => createComponent(For, {
80
+ get each() {
81
+ return reflection?.getProperties().filter(__assignType((property) => !property.isIgnored(), [
82
+ "property",
83
+ "",
84
+ "P\"2!\"/\""
85
+ ])) ?? [];
86
+ },
87
+ doubleHardline: true,
88
+ get children() {
89
+ return __assignType((property) => [createComponent(TSDocReflectionProperty, { reflection: property }), createComponent(InterfaceMember, {
90
+ get name() {
91
+ return `${prefix}_${property.getNameAsString()}`;
92
+ },
93
+ get type() {
94
+ return `UnprefixedEnv["${property.getNameAsString()}"]`;
95
+ },
96
+ get readonly() {
97
+ return property.isReadonly();
98
+ }
99
+ })], [
100
+ "property",
101
+ "",
102
+ "P\"2!\"/\""
103
+ ]);
104
+ }
105
+ }), [
106
+ "prefix",
107
+ "",
108
+ "P\"2!\"/\""
109
+ ]);
110
+ }
111
+ });
112
+ }
113
+ }),
114
+ createComponent(Spacing, {})
115
+ ];
116
+ }
117
+ EnvTypeDefinition.__type = [
118
+ () => __ΩOmit,
119
+ "name",
120
+ "props",
121
+ "EnvTypeDefinition",
122
+ "Generates the environment configuration typescript definition for the Powerlines project.",
123
+ "P!.\"o!#2#\"/$?%"
124
+ ];
125
+ const __ΩConfigPropertyConditionalProps = [
126
+ () => __ΩEnvPluginContext,
127
+ "context",
128
+ "name",
129
+ "ConfigPropertyConditionalProps",
130
+ "P!n!4\"&4#Mw$y"
131
+ ];
132
+ function ConfigPropertyConditional(props) {
133
+ const [{ context, name }] = splitProps(props, ["context", "name"]);
134
+ return code`propertyName === "${name}" || propertyName.replace(/^(${getUnique(context.config.env.prefix.sort(__assignType((a, b) => a.startsWith(b) ? -1 : b.startsWith(a) ? 1 : a.localeCompare(b), [
135
+ "a",
136
+ "b",
137
+ "",
138
+ "P\"2!\"2\"\"/#"
139
+ ])).map(__assignType((prefix) => `${prefix.replace(/_$/, "")}_`, [
140
+ "prefix",
141
+ "",
142
+ "P\"2!\"/\""
143
+ ]))).join("|")})/g, "").toLowerCase().replace(/[\\s\\-_]+/g, "") === "${name.toLowerCase().replace(/[\s\-_]+/g, "")}"`;
144
+ }
145
+ ConfigPropertyConditional.__type = [
146
+ () => __ΩConfigPropertyConditionalProps,
147
+ "props",
148
+ "ConfigPropertyConditional",
149
+ "Pn!2\"\"/#"
150
+ ];
151
+ const __ΩConfigPropertyProps = [
152
+ "index",
153
+ () => __ΩEnvPluginContext,
154
+ "context",
155
+ "property",
156
+ "ConfigPropertyProps",
157
+ "P!'4!n\"4#!4$Mw%y"
158
+ ];
159
+ function ConfigPropertyGet(props) {
160
+ const [{ context, property, index }] = splitProps(props, [
161
+ "context",
162
+ "property",
163
+ "index"
164
+ ]);
165
+ return [index === 0 ? createComponent(IfStatement, {
166
+ get condition() {
167
+ return [createComponent(ConfigPropertyConditional, {
168
+ get name() {
169
+ return property.getNameAsString();
170
+ },
171
+ context
172
+ }), createComponent(Show, {
173
+ get when() {
174
+ return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
175
+ },
176
+ get children() {
177
+ return [code` || `, createComponent(For, {
178
+ get each() {
179
+ return property.getAlias();
180
+ },
181
+ joiner: code` || `,
182
+ get children() {
183
+ return __assignType((alias) => createComponent(ConfigPropertyConditional, {
184
+ name: alias,
185
+ context
186
+ }), [
187
+ "alias",
188
+ "",
189
+ "P\"2!\"/\""
190
+ ]);
191
+ }
192
+ })];
193
+ }
194
+ })];
195
+ },
196
+ get children() {
197
+ return code`return target["${property.getNameAsString()}"];`;
198
+ }
199
+ }) : createComponent(ElseIfClause, {
200
+ get condition() {
201
+ return [createComponent(ConfigPropertyConditional, {
202
+ get name() {
203
+ return property.getNameAsString();
204
+ },
205
+ context
206
+ }), createComponent(Show, {
207
+ get when() {
208
+ return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
209
+ },
210
+ get children() {
211
+ return [code` || `, createComponent(For, {
212
+ get each() {
213
+ return property.getAlias();
214
+ },
215
+ joiner: code` || `,
216
+ get children() {
217
+ return __assignType((alias) => createComponent(ConfigPropertyConditional, {
218
+ name: alias,
219
+ context
220
+ }), [
221
+ "alias",
222
+ "",
223
+ "P\"2!\"/\""
224
+ ]);
225
+ }
226
+ })];
227
+ }
228
+ })];
229
+ },
230
+ get children() {
231
+ return code`return target["${property.getNameAsString()}"];`;
232
+ }
233
+ })];
234
+ }
235
+ ConfigPropertyGet.__type = [
236
+ () => __ΩConfigPropertyProps,
237
+ "props",
238
+ "ConfigPropertyGet",
239
+ "Pn!2\"\"/#"
240
+ ];
241
+ function ConfigPropertySet(props) {
242
+ const [{ context, property, index }] = splitProps(props, [
243
+ "context",
244
+ "property",
245
+ "index"
246
+ ]);
247
+ return [index === 0 ? createComponent(IfStatement, {
248
+ get condition() {
249
+ return [createComponent(ConfigPropertyConditional, {
250
+ get name() {
251
+ return property.getNameAsString();
252
+ },
253
+ context
254
+ }), createComponent(Show, {
255
+ get when() {
256
+ return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
257
+ },
258
+ get children() {
259
+ return [code` || `, createComponent(For, {
260
+ get each() {
261
+ return property.getAlias();
262
+ },
263
+ joiner: code` || `,
264
+ get children() {
265
+ return __assignType((alias) => createComponent(ConfigPropertyConditional, {
266
+ name: alias,
267
+ context
268
+ }), [
269
+ "alias",
270
+ "",
271
+ "P\"2!\"/\""
272
+ ]);
273
+ }
274
+ })];
275
+ }
276
+ })];
277
+ },
278
+ get children() {
279
+ return code`
280
+ target["${property.getNameAsString()}"] = newValue;
281
+ return true;
282
+ `;
283
+ }
284
+ }) : createComponent(ElseIfClause, {
285
+ get condition() {
286
+ return [createComponent(ConfigPropertyConditional, {
287
+ get name() {
288
+ return property.getNameAsString();
289
+ },
290
+ context
291
+ }), createComponent(Show, {
292
+ get when() {
293
+ return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
294
+ },
295
+ get children() {
296
+ return [code` || `, createComponent(For, {
297
+ get each() {
298
+ return property.getAlias();
299
+ },
300
+ joiner: code` || `,
301
+ get children() {
302
+ return __assignType((alias) => createComponent(ConfigPropertyConditional, {
303
+ name: alias,
304
+ context
305
+ }), [
306
+ "alias",
307
+ "",
308
+ "P\"2!\"/\""
309
+ ]);
310
+ }
311
+ })];
312
+ }
313
+ })];
314
+ },
315
+ get children() {
316
+ return code`
317
+ target["${property.getNameAsString()}"] = newValue;
3
318
  return true;
4
- `}})]}J.__type=[()=>K,`props`,`ConfigPropertySet`,`Pn!2""/#`];const Y=[()=>z,`id`,`Children`,`defaultConfig`,`reflection`,`EnvBuiltinProps`,`P!."o!#"w#4$8!4%Mw&y`],X=E(`createEnv`),Z=E(`env`),Q=E(`EnvSerializer`);function $(c){let[{defaultConfig:y,reflection:x,children:S},C]=m(c,[`defaultConfig`,`reflection`,`children`]),E=(g.Ω=[[()=>e,`n!`]],g()),O=p(()=>E&&t(E,process.env)),L=p(()=>{let e=new r({kind:i.objectLiteral,description:`The initial environment configuration state for the ${n(E?.config?.name)} project.`,types:[]},x);return e.getProperties().filter(H(e=>e.isRuntime()||e.getTags().runtime===!0,[`property`,``,`P"2!"/"`])).forEach(H(t=>{e.removeProperty(t.getNameAsString())},[`property`,``,`P"2!"/"`])),e}),z=p(()=>x?.getProperties().filter(H(e=>!e.isIgnored(),[`property`,``,`P"2!"/"`])).sort(H((e,t)=>e.getNameAsString().localeCompare(t.getNameAsString()),[`a`,`b`,``,`P"2!"2""/#`]))??[]),B=p(()=>x?.getProperties().filter(H(e=>!e.isIgnored()&&!e.isReadonly(),[`property`,``,`P"2!"/"`])).sort(H((e,t)=>e.getNameAsString().localeCompare(t.getNameAsString()),[`a`,`b`,``,`P"2!"2""/#`]))??[]);return o(D,l({id:`env`,description:`The environment configuration module provides an interface to define environment configuration parameters.`},C,{get imports(){return a({"@powerlines/deepkit/vendor/type":[`serializeFunction`,`deserializeFunction`,`ReflectionKind`,`Serializer`,`NamingStrategy`,`TemplateState`,`Type`,`TypeProperty`,`TypePropertySignature`]},C.imports??{})},get children(){return[o(d,{get when(){return!!x},get children(){return[o(U,{defaultValue:O,reflection:x}),s(`hbr`,{}),s(`hbr`,{})]}}),o(k,{name:`initialEnv`,type:`Partial<Env>`,defaultValue:O,reflection:L,export:!0,const:!0,doc:`The initial environment configuration object values for the runtime.`}),o(h,{}),o(A,{heading:`The environment configuration serializer for the Powerlines application.`,get children(){return[o(M,{children:`https://deepkit.io/docs/serialization/serializers`}),o(M,{children:`https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918`}),o(P,{children:`This serializer is used to serialize and deserialize the Powerlines environment configuration.`})]}}),o(_,{refkey:Q,name:`EnvSerializer`,extends:`Serializer`,export:!0,get children(){return o(v,{name:`constructor`,public:!0,doc:"Initializes a new instance of the `EnvSerializer` class.",children:f`super("env");
319
+ `;
320
+ }
321
+ })];
322
+ }
323
+ ConfigPropertySet.__type = [
324
+ () => __ΩConfigPropertyProps,
325
+ "props",
326
+ "ConfigPropertySet",
327
+ "Pn!2\"\"/#"
328
+ ];
329
+ const __ΩEnvBuiltinProps = [
330
+ () => __ΩOmit,
331
+ "id",
332
+ "Children",
333
+ "defaultConfig",
334
+ "reflection",
335
+ "EnvBuiltinProps",
336
+ "P!.\"o!#\"w#4$8!4%Mw&y"
337
+ ];
338
+ const createEnvRefkey = refkey("createEnv");
339
+ const envRefkey = refkey("env");
340
+ const envSerializerRefkey = refkey("EnvSerializer");
341
+ /**
342
+ * Generates the environment configuration module for the Powerlines project.
343
+ */
344
+ function EnvBuiltin(props) {
345
+ const [{ defaultConfig, reflection, children }, rest] = splitProps(props, [
346
+ "defaultConfig",
347
+ "reflection",
348
+ "children"
349
+ ]);
350
+ const context = (usePowerlines.Ω = [[() => __ΩEnvPluginContext, "n!"]], usePowerlines());
351
+ const defaultValue = computed(() => context && loadEnvFromContext(context, process.env));
352
+ const envInstance = computed(() => {
353
+ const result = new ReflectionClass({
354
+ kind: ReflectionKind.objectLiteral,
355
+ description: `The initial environment configuration state for the ${titleCase(context?.config?.name)} project.`,
356
+ types: []
357
+ }, reflection);
358
+ result.getProperties().filter(__assignType((property) => property.isRuntime() || property.getTags().runtime === true, [
359
+ "property",
360
+ "",
361
+ "P\"2!\"/\""
362
+ ])).forEach(__assignType((property) => {
363
+ result.removeProperty(property.getNameAsString());
364
+ }, [
365
+ "property",
366
+ "",
367
+ "P\"2!\"/\""
368
+ ]));
369
+ return result;
370
+ });
371
+ const reflectionGetProperties = computed(() => reflection?.getProperties().filter(__assignType((property) => !property.isIgnored(), [
372
+ "property",
373
+ "",
374
+ "P\"2!\"/\""
375
+ ])).sort(__assignType((a, b) => a.getNameAsString().localeCompare(b.getNameAsString()), [
376
+ "a",
377
+ "b",
378
+ "",
379
+ "P\"2!\"2\"\"/#"
380
+ ])) ?? []);
381
+ const reflectionSetProperties = computed(() => reflection?.getProperties().filter(__assignType((property) => !property.isIgnored() && !property.isReadonly(), [
382
+ "property",
383
+ "",
384
+ "P\"2!\"/\""
385
+ ])).sort(__assignType((a, b) => a.getNameAsString().localeCompare(b.getNameAsString()), [
386
+ "a",
387
+ "b",
388
+ "",
389
+ "P\"2!\"2\"\"/#"
390
+ ])) ?? []);
391
+ return createComponent(BuiltinFile, mergeProps({
392
+ id: "env",
393
+ description: "The environment configuration module provides an interface to define environment configuration parameters."
394
+ }, rest, {
395
+ get imports() {
396
+ return defu({ "@powerlines/deepkit/vendor/type": [
397
+ "serializeFunction",
398
+ "deserializeFunction",
399
+ "ReflectionKind",
400
+ "Serializer",
401
+ "NamingStrategy",
402
+ "TemplateState",
403
+ "Type",
404
+ "TypeProperty",
405
+ "TypePropertySignature"
406
+ ] }, rest.imports ?? {});
407
+ },
408
+ get children() {
409
+ return [
410
+ createComponent(Show, {
411
+ get when() {
412
+ return Boolean(reflection);
413
+ },
414
+ get children() {
415
+ return [
416
+ createComponent(EnvTypeDefinition, {
417
+ defaultValue,
418
+ reflection
419
+ }),
420
+ createIntrinsic("hbr", {}),
421
+ createIntrinsic("hbr", {})
422
+ ];
423
+ }
424
+ }),
425
+ createComponent(ObjectDeclaration, {
426
+ name: "initialEnv",
427
+ type: "Partial<Env>",
428
+ defaultValue,
429
+ reflection: envInstance,
430
+ "export": true,
431
+ "const": true,
432
+ doc: "The initial environment configuration object values for the runtime."
433
+ }),
434
+ createComponent(Spacing, {}),
435
+ createComponent(TSDoc, {
436
+ heading: "The environment configuration serializer for the Powerlines application.",
437
+ get children() {
438
+ return [
439
+ createComponent(TSDocLink, { children: `https://deepkit.io/docs/serialization/serializers` }),
440
+ createComponent(TSDocLink, { children: `https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918` }),
441
+ createComponent(TSDocRemarks, { children: `This serializer is used to serialize and deserialize the Powerlines environment configuration.` })
442
+ ];
443
+ }
444
+ }),
445
+ createComponent(ClassDeclaration, {
446
+ refkey: envSerializerRefkey,
447
+ name: "EnvSerializer",
448
+ "extends": "Serializer",
449
+ "export": true,
450
+ get children() {
451
+ return createComponent(ClassMethod, {
452
+ name: "constructor",
453
+ "public": true,
454
+ doc: "Initializes a new instance of the `EnvSerializer` class.",
455
+ children: code`super("env");
5
456
 
6
457
  this.deserializeRegistry.register(
7
458
  ReflectionKind.boolean,
@@ -10,7 +461,17 @@ import{__ΩEnvPluginContext as e}from"../types/plugin.mjs";import{loadEnvFromCon
10
461
  \`typeof \${state.accessor.toString()} !== "boolean" ? \${state.accessor.toString()} === 1 || \${state.accessor.toString()} === "1" || \${state.accessor.toString()}.toLowerCase() === "t" || \${state.accessor.toString()}.toLowerCase() === "true" || \${state.accessor.toString()}.toLowerCase() === "y" || \${state.accessor.toString()}.toLowerCase() === "yes" : \${state.accessor.toString()}\`
11
462
  );
12
463
  }
13
- ); `})}}),o(h,{}),o(T,{name:`envNamingStrategy`,const:!0,doc:`The environment naming strategy for the runtime.`,get initializer(){return f`new class extends NamingStrategy {
464
+ ); `
465
+ });
466
+ }
467
+ }),
468
+ createComponent(Spacing, {}),
469
+ createComponent(VarDeclaration, {
470
+ name: "envNamingStrategy",
471
+ "const": true,
472
+ doc: "The environment naming strategy for the runtime.",
473
+ get initializer() {
474
+ return code`new class extends NamingStrategy {
14
475
  constructor() {
15
476
  super("env");
16
477
  }
@@ -21,22 +482,209 @@ import{__ΩEnvPluginContext as e}from"../types/plugin.mjs";import{loadEnvFromCon
21
482
  return name;
22
483
  }
23
484
 
24
- return name.replace(/^(${R(E.config.env.prefix).map(H(e=>e.replace(/_$/,``),[`prefix`,``,`P"2!"/"`])).join(`|`)})_/, "");
485
+ return name.replace(/^(${getUnique(context.config.env.prefix).map(__assignType((prefix) => prefix.replace(/_$/, ""), [
486
+ "prefix",
487
+ "",
488
+ "P\"2!\"/\""
489
+ ])).join("|")})_/, "");
25
490
  }
26
- }; `}}),o(h,{}),o(A,{heading:`A {@link EnvSerializer | environment configuration serializer} instance for the Powerlines application.`,get children(){return[o(M,{children:`https://deepkit.io/docs/serialization/serializers`}),o(M,{children:`https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918`}),o(P,{children:`This serializer is used to serialize and deserialize the Powerlines environment configuration.`})]}}),o(T,{name:`envSerializer`,const:!0,get initializer(){return o(w,{args:[],target:`EnvSerializer`})}}),o(h,{}),o(T,{name:`_serializeEnv`,const:!0,initializer:`serializeFunction<Env>(envSerializer, envNamingStrategy)`}),o(h,{}),o(A,{heading:`Serialize a environment configuration object to JSON data objects (not a JSON string).`,get children(){return[o(P,{children:"The resulting JSON object can be stringified using `JSON.stringify()`."}),o(j,{children:`const json = serializeEnv(env);`}),o(h,{}),o(N,{name:`input`,children:`The environment configuration object to serialize.`}),o(F,{children:`The serialized environment configuration as JSON data objects.`}),o(I,{children:`ValidationError when serialization or validation fails.`})]}}),o(b,{name:`serializeEnv`,export:!0,parameters:[{name:`input`,type:`Env`}],children:f` return _serializeEnv(input, { loosely: true }); `}),o(h,{}),o(T,{name:`_deserializeEnv`,const:!0,initializer:`deserializeFunction<Env>(envSerializer, envNamingStrategy)`}),o(h,{}),o(A,{heading:`Deserialize a environment configuration object from JSON data objects to JavaScript objects, without running any validators.`,get children(){return[o(P,{children:`Types that are already correct will be used as-is.`}),o(j,{children:`const env = deserializeEnv(json);`}),o(I,{children:`ValidationError when deserialization fails.`})]}}),o(b,{name:`deserializeEnv`,export:!0,parameters:[{name:`input`,type:`Env`}],children:f` return _deserializeEnv(input, { loosely: true }); `}),o(h,{}),o(A,{heading:`Initializes the Powerlines environment configuration module.`,get children(){return[o(P,{children:`This function initializes the Powerlines environment configuration object.`}),o(N,{name:`environmentConfig`,children:`The dynamic/runtime configuration - this could include the current environment variables or any other environment-specific settings provided by the runtime.`}),o(F,{children:`The initialized Powerlines configuration object.`})]}}),o(d,{get when(){return!!E?.entryPath},get children(){return o(b,{refkey:X,async:!1,export:!0,name:`createEnv`,parameters:[{name:`environmentConfig`,type:`Partial<Env>`,optional:!1,default:`{}`}],returnType:`Env`,get children(){return[f`
491
+ }; `;
492
+ }
493
+ }),
494
+ createComponent(Spacing, {}),
495
+ createComponent(TSDoc, {
496
+ heading: "A {@link EnvSerializer | environment configuration serializer} instance for the Powerlines application.",
497
+ get children() {
498
+ return [
499
+ createComponent(TSDocLink, { children: `https://deepkit.io/docs/serialization/serializers` }),
500
+ createComponent(TSDocLink, { children: `https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918` }),
501
+ createComponent(TSDocRemarks, { children: `This serializer is used to serialize and deserialize the Powerlines environment configuration.` })
502
+ ];
503
+ }
504
+ }),
505
+ createComponent(VarDeclaration, {
506
+ name: "envSerializer",
507
+ "const": true,
508
+ get initializer() {
509
+ return createComponent(NewExpression, {
510
+ args: [],
511
+ target: "EnvSerializer"
512
+ });
513
+ }
514
+ }),
515
+ createComponent(Spacing, {}),
516
+ createComponent(VarDeclaration, {
517
+ name: "_serializeEnv",
518
+ "const": true,
519
+ initializer: "serializeFunction<Env>(envSerializer, envNamingStrategy)"
520
+ }),
521
+ createComponent(Spacing, {}),
522
+ createComponent(TSDoc, {
523
+ heading: "Serialize a environment configuration object to JSON data objects (not a JSON string).",
524
+ get children() {
525
+ return [
526
+ createComponent(TSDocRemarks, { children: `The resulting JSON object can be stringified using \`JSON.stringify()\`.` }),
527
+ createComponent(TSDocExample, { children: `const json = serializeEnv(env);` }),
528
+ createComponent(Spacing, {}),
529
+ createComponent(TSDocParam, {
530
+ name: "input",
531
+ children: `The environment configuration object to serialize.`
532
+ }),
533
+ createComponent(TSDocReturns, { children: `The serialized environment configuration as JSON data objects.` }),
534
+ createComponent(TSDocThrows, { children: `ValidationError when serialization or validation fails.` })
535
+ ];
536
+ }
537
+ }),
538
+ createComponent(FunctionDeclaration, {
539
+ name: "serializeEnv",
540
+ "export": true,
541
+ parameters: [{
542
+ name: "input",
543
+ type: "Env"
544
+ }],
545
+ children: code` return _serializeEnv(input, { loosely: true }); `
546
+ }),
547
+ createComponent(Spacing, {}),
548
+ createComponent(VarDeclaration, {
549
+ name: "_deserializeEnv",
550
+ "const": true,
551
+ initializer: "deserializeFunction<Env>(envSerializer, envNamingStrategy)"
552
+ }),
553
+ createComponent(Spacing, {}),
554
+ createComponent(TSDoc, {
555
+ heading: "Deserialize a environment configuration object from JSON data objects to JavaScript objects, without running any validators.",
556
+ get children() {
557
+ return [
558
+ createComponent(TSDocRemarks, { children: `Types that are already correct will be used as-is.` }),
559
+ createComponent(TSDocExample, { children: `const env = deserializeEnv(json);` }),
560
+ createComponent(TSDocThrows, { children: `ValidationError when deserialization fails.` })
561
+ ];
562
+ }
563
+ }),
564
+ createComponent(FunctionDeclaration, {
565
+ name: "deserializeEnv",
566
+ "export": true,
567
+ parameters: [{
568
+ name: "input",
569
+ type: "Env"
570
+ }],
571
+ children: code` return _deserializeEnv(input, { loosely: true }); `
572
+ }),
573
+ createComponent(Spacing, {}),
574
+ createComponent(TSDoc, {
575
+ heading: "Initializes the Powerlines environment configuration module.",
576
+ get children() {
577
+ return [
578
+ createComponent(TSDocRemarks, { children: `This function initializes the Powerlines environment configuration object.` }),
579
+ createComponent(TSDocParam, {
580
+ name: "environmentConfig",
581
+ children: `The dynamic/runtime configuration - this could include the current environment variables or any other environment-specific settings provided by the runtime.`
582
+ }),
583
+ createComponent(TSDocReturns, { children: `The initialized Powerlines configuration object.` })
584
+ ];
585
+ }
586
+ }),
587
+ createComponent(Show, {
588
+ get when() {
589
+ return Boolean(context?.entryPath);
590
+ },
591
+ get children() {
592
+ return createComponent(FunctionDeclaration, {
593
+ refkey: createEnvRefkey,
594
+ async: false,
595
+ "export": true,
596
+ name: "createEnv",
597
+ parameters: [{
598
+ name: "environmentConfig",
599
+ type: `Partial<Env>`,
600
+ optional: false,
601
+ default: "{}"
602
+ }],
603
+ returnType: "Env",
604
+ get children() {
605
+ return [
606
+ code`
27
607
  return new Proxy<Env>(
28
608
  deserializeEnv({
29
609
  ...initialEnv,
30
610
  ...environmentConfig
31
611
  } as Env),
32
612
  {
33
- get: (target: UnprefixedEnv, propertyName: string) => { `,s(`hbr`,{}),o(u,{each:z,get children(){return H((e,t)=>o(q,{index:t,context:E,property:e}),[`property`,`index`,``,`P!2!'2""/#`])}}),f`
613
+ get: (target: UnprefixedEnv, propertyName: string) => { `,
614
+ createIntrinsic("hbr", {}),
615
+ createComponent(For, {
616
+ each: reflectionGetProperties,
617
+ get children() {
618
+ return __assignType((property, index) => createComponent(ConfigPropertyGet, {
619
+ index,
620
+ context,
621
+ property
622
+ }), [
623
+ "property",
624
+ "index",
625
+ "",
626
+ "P!2!'2\"\"/#"
627
+ ]);
628
+ }
629
+ }),
630
+ code`
34
631
  return undefined;
35
- }, `,o(h,{}),f` set: (target: UnprefixedEnv, propertyName: string, newValue: any) => { `,s(`hbr`,{}),o(u,{each:B,ender:f` else `,get children(){return H((e,t)=>o(J,{index:t,context:E,property:e}),[`property`,`index`,``,`P!2!'2""/#`])}}),s(`hbr`,{}),f`return false;
632
+ }, `,
633
+ createComponent(Spacing, {}),
634
+ code` set: (target: UnprefixedEnv, propertyName: string, newValue: any) => { `,
635
+ createIntrinsic("hbr", {}),
636
+ createComponent(For, {
637
+ each: reflectionSetProperties,
638
+ ender: code` else `,
639
+ get children() {
640
+ return __assignType((property, index) => createComponent(ConfigPropertySet, {
641
+ index,
642
+ context,
643
+ property
644
+ }), [
645
+ "property",
646
+ "index",
647
+ "",
648
+ "P!2!'2\"\"/#"
649
+ ]);
650
+ }
651
+ }),
652
+ createIntrinsic("hbr", {}),
653
+ code`return false;
36
654
  }
37
655
  }
38
656
  );
39
- `]}})}}),o(h,{}),s(`hbr`,{}),o(A,{heading:`The environment configuration object.`,get children(){return o(P,{children:`This object provides access to the environment configuration parameters in the application runtime.`})}}),o(T,{refkey:Z,name:`env`,type:`Env`,export:!0,const:!0,get initializer(){return[f`createEnv(${y||`{}`} as Partial<Env>);`]}}),o(h,{}),o(T,{export:!0,const:!0,name:`isCI`,doc:`Detect if the application is running in a continuous integration (CI) environment.`,initializer:f`Boolean(
657
+ `
658
+ ];
659
+ }
660
+ });
661
+ }
662
+ }),
663
+ createComponent(Spacing, {}),
664
+ createIntrinsic("hbr", {}),
665
+ createComponent(TSDoc, {
666
+ heading: "The environment configuration object.",
667
+ get children() {
668
+ return createComponent(TSDocRemarks, { children: `This object provides access to the environment configuration parameters in the application runtime.` });
669
+ }
670
+ }),
671
+ createComponent(VarDeclaration, {
672
+ refkey: envRefkey,
673
+ name: "env",
674
+ type: "Env",
675
+ "export": true,
676
+ "const": true,
677
+ get initializer() {
678
+ return [code`createEnv(${defaultConfig || "{}"} as Partial<Env>);`];
679
+ }
680
+ }),
681
+ createComponent(Spacing, {}),
682
+ createComponent(VarDeclaration, {
683
+ "export": true,
684
+ "const": true,
685
+ name: "isCI",
686
+ doc: "Detect if the application is running in a continuous integration (CI) environment.",
687
+ initializer: code`Boolean(
40
688
  env.CI ||
41
689
  env.RUN_ID ||
42
690
  env.AGOLA_GIT_REF ||
@@ -88,9 +736,76 @@ import{__ΩEnvPluginContext as e}from"../types/plugin.mjs";import{loadEnvFromCon
88
736
  env.APPCENTER_BUILD_ID ||
89
737
  env.CI_XCODE_PROJECT ||
90
738
  env.XCS || false
91
- ); `}),o(h,{}),o(A,{heading:"Detect the \\`mode\\` of the current runtime environment.",get children(){return o(P,{children:f`The \`mode\` is determined by the \`MODE\` environment variable, or falls back to the \`NEXT_PUBLIC_VERCEL_ENV\`, \`NODE_ENV\`, or defaults to \`production\`. While the value can potentially be any string, it is generally recommended to only allow a value in the following list:
739
+ ); `
740
+ }),
741
+ createComponent(Spacing, {}),
742
+ createComponent(TSDoc, {
743
+ heading: "Detect the \\`mode\\` of the current runtime environment.",
744
+ get children() {
745
+ return createComponent(TSDocRemarks, { children: code`The \`mode\` is determined by the \`MODE\` environment variable, or falls back to the \`NEXT_PUBLIC_VERCEL_ENV\`, \`NODE_ENV\`, or defaults to \`production\`. While the value can potentially be any string, it is generally recommended to only allow a value in the following list:
92
746
  - \`production\`
93
747
  - \`test\`
94
748
  - \`development\`
95
- `})}}),o(T,{export:!0,const:!0,name:`mode`,initializer:f`String(env.MODE) || "production"; `}),o(h,{}),o(T,{export:!0,const:!0,name:`isProduction`,doc:'Detect if the application is running in `"production"` mode',initializer:f`["prd", "prod", "production"].includes(mode.toLowerCase()); `}),o(h,{}),o(T,{export:!0,const:!0,name:`isTest`,doc:'Detect if the application is running in `"test"` mode',initializer:f`["tst", "test", "testing", "stg", "stage", "staging"].includes(mode.toLowerCase()) || env.TEST; `}),o(h,{}),o(T,{export:!0,const:!0,name:`isDevelopment`,doc:'Detect if the application is running in `"development"` mode',initializer:f`["dev", "development"].includes(mode.toLowerCase()); `}),o(h,{}),o(T,{export:!0,const:!0,name:`isDebug`,doc:`Detect if the application is currently being debugged`,initializer:f`Boolean(isDevelopment && env.DEBUG); `}),o(h,{}),o(d,{get when(){return!!S},children:S})]}}))}$.__type=[()=>Y,`props`,`EnvBuiltin`,`Generates the environment configuration module for the Powerlines project.`,`Pn!2""/#?$`];export{$ as EnvBuiltin,U as EnvTypeDefinition,Y as __ΩEnvBuiltinProps};
749
+ ` });
750
+ }
751
+ }),
752
+ createComponent(VarDeclaration, {
753
+ "export": true,
754
+ "const": true,
755
+ name: "mode",
756
+ initializer: code`String(env.MODE) || "production"; `
757
+ }),
758
+ createComponent(Spacing, {}),
759
+ createComponent(VarDeclaration, {
760
+ "export": true,
761
+ "const": true,
762
+ name: "isProduction",
763
+ doc: "Detect if the application is running in `\"production\"` mode",
764
+ initializer: code`["prd", "prod", "production"].includes(mode.toLowerCase()); `
765
+ }),
766
+ createComponent(Spacing, {}),
767
+ createComponent(VarDeclaration, {
768
+ "export": true,
769
+ "const": true,
770
+ name: "isTest",
771
+ doc: "Detect if the application is running in `\"test\"` mode",
772
+ initializer: code`["tst", "test", "testing", "stg", "stage", "staging"].includes(mode.toLowerCase()) || env.TEST; `
773
+ }),
774
+ createComponent(Spacing, {}),
775
+ createComponent(VarDeclaration, {
776
+ "export": true,
777
+ "const": true,
778
+ name: "isDevelopment",
779
+ doc: "Detect if the application is running in `\"development\"` mode",
780
+ initializer: code`["dev", "development"].includes(mode.toLowerCase()); `
781
+ }),
782
+ createComponent(Spacing, {}),
783
+ createComponent(VarDeclaration, {
784
+ "export": true,
785
+ "const": true,
786
+ name: "isDebug",
787
+ doc: "Detect if the application is currently being debugged",
788
+ initializer: code`Boolean(isDevelopment && env.DEBUG); `
789
+ }),
790
+ createComponent(Spacing, {}),
791
+ createComponent(Show, {
792
+ get when() {
793
+ return Boolean(children);
794
+ },
795
+ children
796
+ })
797
+ ];
798
+ }
799
+ }));
800
+ }
801
+ EnvBuiltin.__type = [
802
+ () => __ΩEnvBuiltinProps,
803
+ "props",
804
+ "EnvBuiltin",
805
+ "Generates the environment configuration module for the Powerlines project.",
806
+ "Pn!2\"\"/#?$"
807
+ ];
808
+
809
+ //#endregion
810
+ export { EnvBuiltin, EnvTypeDefinition, __ΩEnvBuiltinProps };
96
811
  //# sourceMappingURL=env-builtin.mjs.map