@powerlines/plugin-env 0.16.62 → 0.16.63
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.
- package/dist/babel/plugin.cjs +11 -83
- package/dist/babel/plugin.mjs +11 -83
- package/dist/babel/plugin.mjs.map +1 -1
- package/dist/components/docs.cjs +22 -47
- package/dist/components/docs.mjs +22 -47
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/env-builtin.cjs +219 -419
- package/dist/components/env-builtin.mjs +219 -419
- package/dist/components/env-builtin.mjs.map +1 -1
- package/dist/helpers/automd-generator.cjs +4 -14
- package/dist/helpers/automd-generator.d.mts +1 -1
- package/dist/helpers/automd-generator.mjs +4 -14
- package/dist/helpers/automd-generator.mjs.map +1 -1
- package/dist/helpers/create-reflection-resource.cjs +0 -8
- package/dist/helpers/create-reflection-resource.mjs +0 -9
- package/dist/helpers/create-reflection-resource.mjs.map +1 -1
- package/dist/helpers/docs-helper.cjs +0 -8
- package/dist/helpers/docs-helper.mjs +0 -8
- package/dist/helpers/docs-helper.mjs.map +1 -1
- package/dist/helpers/index.cjs +0 -1
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/load.cjs +7 -58
- package/dist/helpers/load.mjs +7 -58
- package/dist/helpers/load.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +1 -108
- package/dist/helpers/persistence.mjs +1 -108
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/reflect.cjs +16 -156
- package/dist/helpers/reflect.mjs +17 -156
- package/dist/helpers/reflect.mjs.map +1 -1
- package/dist/helpers/source-file-env.cjs +4 -34
- package/dist/helpers/source-file-env.mjs +4 -34
- package/dist/helpers/source-file-env.mjs.map +1 -1
- package/dist/helpers/template-helpers.cjs +5 -33
- package/dist/helpers/template-helpers.mjs +5 -33
- package/dist/helpers/template-helpers.mjs.map +1 -1
- package/dist/index.cjs +2 -12
- package/dist/index.mjs +2 -12
- package/dist/index.mjs.map +1 -1
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/rolldown-runtime.mjs +0 -2
- package/dist/node_modules/.pnpm/confbox@0.2.4/node_modules/confbox/dist/_chunks/rolldown-runtime.mjs.map +1 -1
- package/dist/node_modules/.pnpm/giget@2.0.0/node_modules/giget/dist/index.mjs +0 -4
- package/dist/node_modules/.pnpm/giget@2.0.0/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs +0 -1
- package/dist/node_modules/.pnpm/giget@2.0.0/node_modules/giget/dist/shared/giget.OCaTp9b-.mjs.map +1 -1
- package/dist/types/index.cjs +0 -11
- package/dist/types/index.mjs +1 -4
- package/dist/types/plugin.cjs +0 -137
- package/dist/types/plugin.d.mts +4 -4
- package/dist/types/plugin.mjs +1 -132
- package/dist/types/runtime.cjs +0 -244
- package/dist/types/runtime.mjs +1 -242
- package/package.json +10 -10
- package/dist/types/plugin.mjs.map +0 -1
- package/dist/types/runtime.mjs.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { loadEnvFromContext } from "../helpers/load.mjs";
|
|
2
|
-
import { ReflectionClass, ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
3
2
|
import { titleCase } from "@stryke/string-format/title-case";
|
|
3
|
+
import { ReflectionClass, ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
4
4
|
import defu from "defu";
|
|
5
|
-
import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
6
5
|
import { For, Show, code, computed, splitProps } from "@alloy-js/core";
|
|
7
6
|
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
8
7
|
import { usePowerlines } from "@powerlines/plugin-alloy/core/contexts/context";
|
|
@@ -20,32 +19,22 @@ import { TSDoc, TSDocExample, TSDocLink, TSDocParam, TSDocRemarks, TSDocReturns,
|
|
|
20
19
|
function EnvTypeDefinition(props) {
|
|
21
20
|
const [{ defaultValue, reflection }] = splitProps(props, ["defaultValue", "reflection"]);
|
|
22
21
|
const context = usePowerlines();
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
get children() {
|
|
34
|
-
return createComponent(TSDocRemarks, { children: `The \`Env\` type extends the \`EnvBase\` 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.` });
|
|
35
|
-
}
|
|
36
|
-
}),
|
|
37
|
-
createComponent(TypeDeclaration, {
|
|
38
|
-
name: "Env",
|
|
39
|
-
"export": true,
|
|
40
|
-
get children() {
|
|
41
|
-
return code` {
|
|
22
|
+
return <>
|
|
23
|
+
<InterfaceDeclaration name=" EnvBase" defaultValue={defaultValue} reflection={reflection} export={true} />
|
|
24
|
+
<Spacing />
|
|
25
|
+
<TSDoc heading="The environment configuration object with prefixed keys.">
|
|
26
|
+
<TSDocRemarks>
|
|
27
|
+
{`The \`Env\` type extends the \`EnvBase\` 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.`}
|
|
28
|
+
</TSDocRemarks>
|
|
29
|
+
</TSDoc>
|
|
30
|
+
<TypeDeclaration name="Env" export={true}>
|
|
31
|
+
{code` {
|
|
42
32
|
[Key in keyof EnvBase as Key ${context.config.env.prefix.map((prefix) => `| \`${prefix.replace(/_$/g, "")}_\${Key}\``).join(" ")}]: EnvBase[Key];
|
|
43
33
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
];
|
|
34
|
+
`}
|
|
35
|
+
</TypeDeclaration>
|
|
36
|
+
<Spacing />
|
|
37
|
+
</>;
|
|
49
38
|
}
|
|
50
39
|
function ConfigPropertyConditional(props) {
|
|
51
40
|
const [{ context, name }] = splitProps(props, ["context", "name"]);
|
|
@@ -57,63 +46,29 @@ function ConfigPropertyGet(props) {
|
|
|
57
46
|
"property",
|
|
58
47
|
"index"
|
|
59
48
|
]);
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})];
|
|
84
|
-
},
|
|
85
|
-
get children() {
|
|
86
|
-
return code`return target["${property.getNameAsString()}"];`;
|
|
87
|
-
}
|
|
88
|
-
}) : createComponent(ElseIfClause, {
|
|
89
|
-
get condition() {
|
|
90
|
-
return [createComponent(ConfigPropertyConditional, {
|
|
91
|
-
get name() {
|
|
92
|
-
return property.getNameAsString();
|
|
93
|
-
},
|
|
94
|
-
context
|
|
95
|
-
}), createComponent(Show, {
|
|
96
|
-
get when() {
|
|
97
|
-
return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
|
|
98
|
-
},
|
|
99
|
-
get children() {
|
|
100
|
-
return [code` || `, createComponent(For, {
|
|
101
|
-
get each() {
|
|
102
|
-
return property.getAlias();
|
|
103
|
-
},
|
|
104
|
-
joiner: code` || `,
|
|
105
|
-
children: (alias) => createComponent(ConfigPropertyConditional, {
|
|
106
|
-
name: alias,
|
|
107
|
-
context
|
|
108
|
-
})
|
|
109
|
-
})];
|
|
110
|
-
}
|
|
111
|
-
})];
|
|
112
|
-
},
|
|
113
|
-
get children() {
|
|
114
|
-
return code`return target["${property.getNameAsString()}"];`;
|
|
115
|
-
}
|
|
116
|
-
})];
|
|
49
|
+
return <>
|
|
50
|
+
{index === 0 ? <IfStatement condition={<>
|
|
51
|
+
<ConfigPropertyConditional name={property.getNameAsString()} context={context} />
|
|
52
|
+
<Show when={property.getAlias() && property.getAlias().length > 0}>
|
|
53
|
+
{code` || `}
|
|
54
|
+
<For each={property.getAlias()} joiner={code` || `}>
|
|
55
|
+
{(alias) => <ConfigPropertyConditional name={alias} context={context} />}
|
|
56
|
+
</For>
|
|
57
|
+
</Show>
|
|
58
|
+
</>}>
|
|
59
|
+
{code`return target["${property.getNameAsString()}"];`}
|
|
60
|
+
</IfStatement> : <ElseIfClause condition={<>
|
|
61
|
+
<ConfigPropertyConditional name={property.getNameAsString()} context={context} />
|
|
62
|
+
<Show when={property.getAlias() && property.getAlias().length > 0}>
|
|
63
|
+
{code` || `}
|
|
64
|
+
<For each={property.getAlias()} joiner={code` || `}>
|
|
65
|
+
{(alias) => <ConfigPropertyConditional name={alias} context={context} />}
|
|
66
|
+
</For>
|
|
67
|
+
</Show>
|
|
68
|
+
</>}>
|
|
69
|
+
{code`return target["${property.getNameAsString()}"];`}
|
|
70
|
+
</ElseIfClause>}
|
|
71
|
+
</>;
|
|
117
72
|
}
|
|
118
73
|
function ConfigPropertySet(props) {
|
|
119
74
|
const [{ context, property, index }] = splitProps(props, [
|
|
@@ -121,69 +76,35 @@ function ConfigPropertySet(props) {
|
|
|
121
76
|
"property",
|
|
122
77
|
"index"
|
|
123
78
|
]);
|
|
124
|
-
return
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
get children() {
|
|
136
|
-
return [code` || `, createComponent(For, {
|
|
137
|
-
get each() {
|
|
138
|
-
return property.getAlias();
|
|
139
|
-
},
|
|
140
|
-
joiner: code` || `,
|
|
141
|
-
children: (alias) => createComponent(ConfigPropertyConditional, {
|
|
142
|
-
name: alias,
|
|
143
|
-
context
|
|
144
|
-
})
|
|
145
|
-
})];
|
|
146
|
-
}
|
|
147
|
-
})];
|
|
148
|
-
},
|
|
149
|
-
get children() {
|
|
150
|
-
return code`
|
|
79
|
+
return <>
|
|
80
|
+
{index === 0 ? <IfStatement condition={<>
|
|
81
|
+
<ConfigPropertyConditional name={property.getNameAsString()} context={context} />
|
|
82
|
+
<Show when={property.getAlias() && property.getAlias().length > 0}>
|
|
83
|
+
{code` || `}
|
|
84
|
+
<For each={property.getAlias()} joiner={code` || `}>
|
|
85
|
+
{(alias) => <ConfigPropertyConditional name={alias} context={context} />}
|
|
86
|
+
</For>
|
|
87
|
+
</Show>
|
|
88
|
+
</>}>
|
|
89
|
+
{code`
|
|
151
90
|
target["${property.getNameAsString()}"] = newValue;
|
|
152
91
|
return true;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return memo(() => !!property.getAlias())() && property.getAlias().length > 0;
|
|
165
|
-
},
|
|
166
|
-
get children() {
|
|
167
|
-
return [code` || `, createComponent(For, {
|
|
168
|
-
get each() {
|
|
169
|
-
return property.getAlias();
|
|
170
|
-
},
|
|
171
|
-
joiner: code` || `,
|
|
172
|
-
children: (alias) => createComponent(ConfigPropertyConditional, {
|
|
173
|
-
name: alias,
|
|
174
|
-
context
|
|
175
|
-
})
|
|
176
|
-
})];
|
|
177
|
-
}
|
|
178
|
-
})];
|
|
179
|
-
},
|
|
180
|
-
get children() {
|
|
181
|
-
return code`
|
|
92
|
+
`}
|
|
93
|
+
</IfStatement> : <ElseIfClause condition={<>
|
|
94
|
+
<ConfigPropertyConditional name={property.getNameAsString()} context={context} />
|
|
95
|
+
<Show when={property.getAlias() && property.getAlias().length > 0}>
|
|
96
|
+
{code` || `}
|
|
97
|
+
<For each={property.getAlias()} joiner={code` || `}>
|
|
98
|
+
{(alias) => <ConfigPropertyConditional name={alias} context={context} />}
|
|
99
|
+
</For>
|
|
100
|
+
</Show>
|
|
101
|
+
</>}>
|
|
102
|
+
{code`
|
|
182
103
|
target["${property.getNameAsString()}"] = newValue;
|
|
183
104
|
return true;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
105
|
+
`}
|
|
106
|
+
</ElseIfClause>}
|
|
107
|
+
</>;
|
|
187
108
|
}
|
|
188
109
|
const createEnvRefkey = refkey("createEnv");
|
|
189
110
|
const envRefkey = refkey("env");
|
|
@@ -208,74 +129,41 @@ function EnvBuiltin(props) {
|
|
|
208
129
|
});
|
|
209
130
|
const reflectionGetProperties = computed(() => reflection?.getProperties().filter((property) => !property.isIgnored()).sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())) ?? []);
|
|
210
131
|
const reflectionSetProperties = computed(() => reflection?.getProperties().filter((property) => !property.isIgnored() && !property.isReadonly()).sort((a, b) => a.getNameAsString().localeCompare(b.getNameAsString())) ?? []);
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
}),
|
|
248
|
-
createComponent(ObjectDeclaration, {
|
|
249
|
-
name: "initialEnv",
|
|
250
|
-
type: "Partial<EnvBase>",
|
|
251
|
-
defaultValue,
|
|
252
|
-
reflection: envInstance,
|
|
253
|
-
"export": true,
|
|
254
|
-
"const": true,
|
|
255
|
-
doc: "The initial environment configuration object values for the runtime."
|
|
256
|
-
}),
|
|
257
|
-
createComponent(Spacing, {}),
|
|
258
|
-
createComponent(TSDoc, {
|
|
259
|
-
heading: "The environment configuration serializer for the Powerlines application.",
|
|
260
|
-
get children() {
|
|
261
|
-
return [
|
|
262
|
-
createComponent(TSDocLink, { children: `https://deepkit.io/docs/serialization/serializers` }),
|
|
263
|
-
createComponent(TSDocLink, { children: `https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918` }),
|
|
264
|
-
createComponent(TSDocRemarks, { children: `This serializer is used to serialize and deserialize the Powerlines environment configuration.` })
|
|
265
|
-
];
|
|
266
|
-
}
|
|
267
|
-
}),
|
|
268
|
-
createComponent(ClassDeclaration, {
|
|
269
|
-
refkey: envSerializerRefkey,
|
|
270
|
-
name: "EnvSerializer",
|
|
271
|
-
"extends": "Serializer",
|
|
272
|
-
"export": true,
|
|
273
|
-
get children() {
|
|
274
|
-
return createComponent(ClassMethod, {
|
|
275
|
-
name: "constructor",
|
|
276
|
-
"public": true,
|
|
277
|
-
doc: "Initializes a new instance of the `EnvSerializer` class.",
|
|
278
|
-
children: code`super("env");
|
|
132
|
+
return <BuiltinFile id="env" description="The environment configuration module provides an interface to define environment configuration parameters." {...rest} imports={defu({ "@powerlines/deepkit/vendor/type": [
|
|
133
|
+
"stringify",
|
|
134
|
+
"serializer",
|
|
135
|
+
"serializeFunction",
|
|
136
|
+
"deserializeFunction",
|
|
137
|
+
"ReflectionKind",
|
|
138
|
+
"Serializer",
|
|
139
|
+
"TemplateState",
|
|
140
|
+
"Type",
|
|
141
|
+
"TypeProperty",
|
|
142
|
+
"TypePropertySignature"
|
|
143
|
+
] }, rest.imports ?? {})}>
|
|
144
|
+
<Show when={Boolean(reflection)}>
|
|
145
|
+
<EnvTypeDefinition defaultValue={defaultValue.value} reflection={reflection} />
|
|
146
|
+
<hbr />
|
|
147
|
+
<hbr />
|
|
148
|
+
</Show>
|
|
149
|
+
|
|
150
|
+
<ObjectDeclaration name="initialEnv" type="Partial<EnvBase>" defaultValue={defaultValue} reflection={envInstance} export={true} const={true} doc="The initial environment configuration object values for the runtime." />
|
|
151
|
+
<Spacing />
|
|
152
|
+
|
|
153
|
+
<TSDoc heading="The environment configuration serializer for the Powerlines application.">
|
|
154
|
+
<TSDocLink>
|
|
155
|
+
{`https://deepkit.io/docs/serialization/serializers`}
|
|
156
|
+
</TSDocLink>
|
|
157
|
+
<TSDocLink>
|
|
158
|
+
{`https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918`}
|
|
159
|
+
</TSDocLink>
|
|
160
|
+
<TSDocRemarks>
|
|
161
|
+
{`This serializer is used to serialize and deserialize the Powerlines environment configuration.`}
|
|
162
|
+
</TSDocRemarks>
|
|
163
|
+
</TSDoc>
|
|
164
|
+
<ClassDeclaration refkey={envSerializerRefkey} name="EnvSerializer" extends="Serializer" export={true}>
|
|
165
|
+
<ClassMethod name="constructor" public={true} doc="Initializes a new instance of the `EnvSerializer` class.">
|
|
166
|
+
{code`super("env");
|
|
279
167
|
|
|
280
168
|
this.deserializeRegistry.register(
|
|
281
169
|
ReflectionKind.boolean,
|
|
@@ -284,167 +172,112 @@ function EnvBuiltin(props) {
|
|
|
284
172
|
\`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()}\`
|
|
285
173
|
);
|
|
286
174
|
}
|
|
287
|
-
); `
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
heading: "Initializes the Powerlines environment configuration module.",
|
|
350
|
-
get children() {
|
|
351
|
-
return [
|
|
352
|
-
createComponent(TSDocRemarks, { children: `This function initializes the Powerlines environment configuration object.` }),
|
|
353
|
-
createComponent(TSDocParam, {
|
|
354
|
-
name: "environmentConfig",
|
|
355
|
-
children: `The dynamic/runtime configuration - this could include the current environment variables or any other environment-specific settings provided by the runtime.`
|
|
356
|
-
}),
|
|
357
|
-
createComponent(TSDocReturns, { children: `The initialized Powerlines configuration object.` })
|
|
358
|
-
];
|
|
359
|
-
}
|
|
360
|
-
}),
|
|
361
|
-
createComponent(Show, {
|
|
362
|
-
get when() {
|
|
363
|
-
return Boolean(context?.entryPath);
|
|
364
|
-
},
|
|
365
|
-
get children() {
|
|
366
|
-
return createComponent(FunctionDeclaration, {
|
|
367
|
-
refkey: createEnvRefkey,
|
|
368
|
-
async: false,
|
|
369
|
-
"export": true,
|
|
370
|
-
name: "createEnv",
|
|
371
|
-
parameters: [{
|
|
372
|
-
name: "environmentConfig",
|
|
373
|
-
type: `Partial<Env>`,
|
|
374
|
-
optional: false,
|
|
375
|
-
default: "{}"
|
|
376
|
-
}],
|
|
377
|
-
returnType: "Env",
|
|
378
|
-
get children() {
|
|
379
|
-
return [
|
|
380
|
-
code`
|
|
175
|
+
); `}
|
|
176
|
+
</ClassMethod>
|
|
177
|
+
</ClassDeclaration>
|
|
178
|
+
<Spacing />
|
|
179
|
+
|
|
180
|
+
<TSDoc heading="A {@link EnvSerializer | environment configuration serializer} instance for the Powerlines application.">
|
|
181
|
+
<TSDocLink>
|
|
182
|
+
{`https://deepkit.io/docs/serialization/serializers`}
|
|
183
|
+
</TSDocLink>
|
|
184
|
+
<TSDocLink>
|
|
185
|
+
{`https://github.com/marcj/untitled-code/blob/master/packages/type/src/serializer.ts#L1918`}
|
|
186
|
+
</TSDocLink>
|
|
187
|
+
<TSDocRemarks>
|
|
188
|
+
{`This serializer is used to serialize and deserialize the Powerlines environment configuration.`}
|
|
189
|
+
</TSDocRemarks>
|
|
190
|
+
</TSDoc>
|
|
191
|
+
<VarDeclaration name="envSerializer" export={false} const={true} initializer={<NewExpression args={[]} target="EnvSerializer" />} />
|
|
192
|
+
<Spacing />
|
|
193
|
+
|
|
194
|
+
<TSDoc heading="Serialize a environment configuration object to JSON data objects (not a JSON string).">
|
|
195
|
+
<TSDocRemarks>
|
|
196
|
+
{`The resulting JSON object can be stringified using \`JSON.stringify()\`.`}
|
|
197
|
+
</TSDocRemarks>
|
|
198
|
+
<TSDocExample>{`const json = serializeEnv(env);`}</TSDocExample>
|
|
199
|
+
<TSDocThrows>
|
|
200
|
+
{`ValidationError when serialization or validation fails.`}
|
|
201
|
+
</TSDocThrows>
|
|
202
|
+
</TSDoc>
|
|
203
|
+
<VarDeclaration name="serializeEnv" export={true} const={true} initializer={"serializeFunction<EnvBase>(envSerializer)"} />
|
|
204
|
+
<Spacing />
|
|
205
|
+
|
|
206
|
+
<TSDoc heading="Deserialize a environment configuration object from JSON data objects to JavaScript objects, without running any validators.">
|
|
207
|
+
<TSDocRemarks>
|
|
208
|
+
{`Types that are already correct will be used as-is.`}
|
|
209
|
+
</TSDocRemarks>
|
|
210
|
+
<TSDocExample>{`const env = deserializeEnv(json);`}</TSDocExample>
|
|
211
|
+
<TSDocThrows>
|
|
212
|
+
{`ValidationError when deserialization fails.`}
|
|
213
|
+
</TSDocThrows>
|
|
214
|
+
</TSDoc>
|
|
215
|
+
<VarDeclaration name="deserializeEnv" export={true} const={true} initializer="deserializeFunction<EnvBase>(envSerializer)" />
|
|
216
|
+
<Spacing />
|
|
217
|
+
|
|
218
|
+
<TSDoc heading="Initializes the Powerlines environment configuration module.">
|
|
219
|
+
<TSDocRemarks>
|
|
220
|
+
{`This function initializes the Powerlines environment configuration object.`}
|
|
221
|
+
</TSDocRemarks>
|
|
222
|
+
<TSDocParam name="environmentConfig">
|
|
223
|
+
{`The dynamic/runtime configuration - this could include the current environment variables or any other environment-specific settings provided by the runtime.`}
|
|
224
|
+
</TSDocParam>
|
|
225
|
+
<TSDocReturns>
|
|
226
|
+
{`The initialized Powerlines configuration object.`}
|
|
227
|
+
</TSDocReturns>
|
|
228
|
+
</TSDoc>
|
|
229
|
+
<Show when={Boolean(context?.entryPath)}>
|
|
230
|
+
<FunctionDeclaration refkey={createEnvRefkey} async={false} export={true} name="createEnv" parameters={[{
|
|
231
|
+
name: "environmentConfig",
|
|
232
|
+
type: `Partial<Env>`,
|
|
233
|
+
optional: false,
|
|
234
|
+
default: "{}"
|
|
235
|
+
}]} returnType="Env">
|
|
236
|
+
{code`
|
|
381
237
|
return new Proxy<Env>(
|
|
382
238
|
deserializeEnv({
|
|
383
239
|
...initialEnv,
|
|
384
240
|
...environmentConfig
|
|
385
241
|
}) as Env,
|
|
386
242
|
{
|
|
387
|
-
get: (target: EnvBase, propertyName: string) => {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
property
|
|
395
|
-
})
|
|
396
|
-
}),
|
|
397
|
-
code`
|
|
243
|
+
get: (target: EnvBase, propertyName: string) => { `}
|
|
244
|
+
<hbr />
|
|
245
|
+
|
|
246
|
+
<For each={reflectionGetProperties}>
|
|
247
|
+
{(property, index) => <ConfigPropertyGet index={index} context={context} property={property} />}
|
|
248
|
+
</For>
|
|
249
|
+
{code`
|
|
398
250
|
return undefined;
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}),
|
|
412
|
-
createIntrinsic("hbr", {}),
|
|
413
|
-
code`return false;
|
|
251
|
+
}, `}
|
|
252
|
+
|
|
253
|
+
<Spacing />
|
|
254
|
+
{code` set: (target: EnvBase, propertyName: string, newValue: any) => { `}
|
|
255
|
+
<hbr />
|
|
256
|
+
|
|
257
|
+
<For each={reflectionSetProperties} ender={code` else `}>
|
|
258
|
+
{(property, index) => <ConfigPropertySet index={index} context={context} property={property} />}
|
|
259
|
+
</For>
|
|
260
|
+
|
|
261
|
+
<hbr />
|
|
262
|
+
{code`return false;
|
|
414
263
|
}
|
|
415
264
|
}
|
|
416
265
|
);
|
|
417
|
-
`
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
refkey: envRefkey,
|
|
433
|
-
name: "env",
|
|
434
|
-
type: "Env",
|
|
435
|
-
"export": true,
|
|
436
|
-
"const": true,
|
|
437
|
-
get initializer() {
|
|
438
|
-
return [code`createEnv(${defaultConfig || "{}"} as Partial<Env>);`];
|
|
439
|
-
}
|
|
440
|
-
}),
|
|
441
|
-
createComponent(Spacing, {}),
|
|
442
|
-
createComponent(VarDeclaration, {
|
|
443
|
-
"export": true,
|
|
444
|
-
"const": true,
|
|
445
|
-
name: "isCI",
|
|
446
|
-
doc: "Detect if the application is running in a continuous integration (CI) environment.",
|
|
447
|
-
initializer: code`Boolean(
|
|
266
|
+
`}
|
|
267
|
+
</FunctionDeclaration>
|
|
268
|
+
</Show>
|
|
269
|
+
<Spacing />
|
|
270
|
+
<hbr />
|
|
271
|
+
|
|
272
|
+
<TSDoc heading="The environment configuration object.">
|
|
273
|
+
<TSDocRemarks>
|
|
274
|
+
{`This object provides access to the environment configuration parameters in the application runtime.`}
|
|
275
|
+
</TSDocRemarks>
|
|
276
|
+
</TSDoc>
|
|
277
|
+
<VarDeclaration refkey={envRefkey} name="env" type="Env" export={true} const={true} initializer={<>{code`createEnv(${defaultConfig || "{}"} as Partial<Env>);`}</>} />
|
|
278
|
+
<Spacing />
|
|
279
|
+
|
|
280
|
+
<VarDeclaration export const name="isCI" doc="Detect if the application is running in a continuous integration (CI) environment." initializer={code`Boolean(
|
|
448
281
|
env.CI ||
|
|
449
282
|
env.RUN_ID ||
|
|
450
283
|
env.AGOLA_GIT_REF ||
|
|
@@ -497,67 +330,34 @@ function EnvBuiltin(props) {
|
|
|
497
330
|
env.CI_XCODE_PROJECT ||
|
|
498
331
|
env.XCS || false
|
|
499
332
|
);
|
|
500
|
-
`
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
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:
|
|
333
|
+
`} />
|
|
334
|
+
<Spacing />
|
|
335
|
+
|
|
336
|
+
<TSDoc heading="Detect the \`mode\` of the current runtime environment.">
|
|
337
|
+
<TSDocRemarks>
|
|
338
|
+
{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:
|
|
507
339
|
- \`production\`
|
|
508
340
|
- \`test\`
|
|
509
341
|
- \`development\`
|
|
510
|
-
`
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
"export": true,
|
|
530
|
-
"const": true,
|
|
531
|
-
name: "isTest",
|
|
532
|
-
doc: "Detect if the application is running in `\"test\"` mode",
|
|
533
|
-
initializer: code`["tst", "test", "testing", "stg", "stage", "staging"].includes(mode.toLowerCase()) || env.TEST; `
|
|
534
|
-
}),
|
|
535
|
-
createComponent(Spacing, {}),
|
|
536
|
-
createComponent(VarDeclaration, {
|
|
537
|
-
"export": true,
|
|
538
|
-
"const": true,
|
|
539
|
-
name: "isDevelopment",
|
|
540
|
-
doc: "Detect if the application is running in `\"development\"` mode",
|
|
541
|
-
initializer: code`["dev", "development"].includes(mode.toLowerCase()); `
|
|
542
|
-
}),
|
|
543
|
-
createComponent(Spacing, {}),
|
|
544
|
-
createComponent(VarDeclaration, {
|
|
545
|
-
"export": true,
|
|
546
|
-
"const": true,
|
|
547
|
-
name: "isDebug",
|
|
548
|
-
doc: "Detect if the application is currently being debugged",
|
|
549
|
-
initializer: code`Boolean(isDevelopment && env.DEBUG); `
|
|
550
|
-
}),
|
|
551
|
-
createComponent(Spacing, {}),
|
|
552
|
-
createComponent(Show, {
|
|
553
|
-
get when() {
|
|
554
|
-
return Boolean(children);
|
|
555
|
-
},
|
|
556
|
-
children
|
|
557
|
-
})
|
|
558
|
-
];
|
|
559
|
-
}
|
|
560
|
-
}));
|
|
342
|
+
`}
|
|
343
|
+
</TSDocRemarks>
|
|
344
|
+
</TSDoc>
|
|
345
|
+
<VarDeclaration export const name="mode" initializer={code`String(env.MODE) || "production"; `} />
|
|
346
|
+
<Spacing />
|
|
347
|
+
|
|
348
|
+
<VarDeclaration export const name="isProduction" doc='Detect if the application is running in `"production"` mode' initializer={code`["prd", "prod", "production"].includes(mode.toLowerCase()); `} />
|
|
349
|
+
<Spacing />
|
|
350
|
+
|
|
351
|
+
<VarDeclaration export const name="isTest" doc='Detect if the application is running in `"test"` mode' initializer={code`["tst", "test", "testing", "stg", "stage", "staging"].includes(mode.toLowerCase()) || env.TEST; `} />
|
|
352
|
+
<Spacing />
|
|
353
|
+
|
|
354
|
+
<VarDeclaration export const name="isDevelopment" doc='Detect if the application is running in `"development"` mode' initializer={code`["dev", "development"].includes(mode.toLowerCase()); `} />
|
|
355
|
+
<Spacing />
|
|
356
|
+
|
|
357
|
+
<VarDeclaration export const name="isDebug" doc="Detect if the application is currently being debugged" initializer={code`Boolean(isDevelopment && env.DEBUG); `} />
|
|
358
|
+
<Spacing />
|
|
359
|
+
<Show when={Boolean(children)}>{children}</Show>
|
|
360
|
+
</BuiltinFile>;
|
|
561
361
|
}
|
|
562
362
|
|
|
563
363
|
//#endregion
|