@power-plant/core 0.0.25 → 0.0.28

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/config.cjs CHANGED
@@ -1 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return e}exports.defineConfig=e;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/config.ts
4
+ function defineConfig(config) {
5
+ return config;
6
+ }
7
+
8
+ //#endregion
9
+ exports.defineConfig = defineConfig;
package/dist/config.mjs CHANGED
@@ -1,2 +1,8 @@
1
- function e(e){return e}export{e as defineConfig};
1
+ //#region src/config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
6
+ //#endregion
7
+ export { defineConfig };
2
8
  //# sourceMappingURL=config.mjs.map
package/dist/context.cjs CHANGED
@@ -1 +1,189 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@stryke/string-format/snake-case"),t=require("@stryke/string-format/title-case"),n=require("node:async_hooks");const r=globalThis;function i(i){let a=`$$__power_plant_{key}_context__`.replace(`{key}`,(0,e.snakeCase)(i.trim().replace(/^[_-]*/g,``).replace(/[_-]*$/g,``)));return r[a]??(r[a]={asyncLocalStorage:new n.AsyncLocalStorage,use(){let e=this.asyncLocalStorage.getStore();if(e===void 0)throw Error(`The ${(0,t.titleCase)(i.trim().replace(/^[_-]*/g,``).replace(/[_-]*$/g,``))} context is not available. Please ensure that the context has been initialized before using it.`);return e},tryUse(){return this.asyncLocalStorage.getStore()},call(e,t){return this.asyncLocalStorage.run(e,t)},async callAsync(e,t){return this.asyncLocalStorage.run(e,t)}}),r[a]}const a=i(`session`),o=a.asyncLocalStorage,s=a.use,c=s,l=a.tryUse,u=l,d=a.call,f=d,p=a.callAsync,m=p,h=i(`execution`),g=h.asyncLocalStorage;function _(){return h.use()}function v(){return _()}function y(){return _()}const b=h.tryUse,x=b,S=h.call,C=S,w=h.callAsync,T=w;exports.callAsyncExecution=T,exports.callAsyncExecutionContext=w,exports.callAsyncSession=m,exports.callAsyncSessionContext=p,exports.callExecution=C,exports.callExecutionContext=S,exports.callSession=f,exports.callSessionContext=d,exports.executionAsyncLocalStorage=g,exports.executionContext=h,exports.sessionAsyncLocalStorage=o,exports.sessionContext=a,exports.tryUseExecution=x,exports.tryUseExecutionContext=b,exports.tryUseSession=u,exports.tryUseSessionContext=l,exports.useContext=y,exports.useExecution=v,exports.useExecutionContext=_,exports.useSession=c,exports.useSessionContext=s;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _stryke_string_format_snake_case = require("@stryke/string-format/snake-case");
3
+ let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
4
+ let node_async_hooks = require("node:async_hooks");
5
+
6
+ //#region src/context.ts
7
+ const globalStore = globalThis;
8
+ const GLOBAL_CONTEXT_KEY = "$$__power_plant_{key}_context__";
9
+ function createContextStore(key) {
10
+ const contextKey = GLOBAL_CONTEXT_KEY.replace("{key}", (0, _stryke_string_format_snake_case.snakeCase)(key.trim().replace(/^[_-]*/g, "").replace(/[_-]*$/g, "")));
11
+ globalStore[contextKey] ?? (globalStore[contextKey] = {
12
+ asyncLocalStorage: new node_async_hooks.AsyncLocalStorage(),
13
+ use() {
14
+ const instance = this.asyncLocalStorage.getStore();
15
+ if (instance === void 0) throw new Error(`The ${(0, _stryke_string_format_title_case.titleCase)(key.trim().replace(/^[_-]*/g, "").replace(/[_-]*$/g, ""))} context is not available. Please ensure that the context has been initialized before using it.`);
16
+ return instance;
17
+ },
18
+ tryUse() {
19
+ return this.asyncLocalStorage.getStore();
20
+ },
21
+ call(instance, callback) {
22
+ return this.asyncLocalStorage.run(instance, callback);
23
+ },
24
+ async callAsync(instance, callback) {
25
+ return this.asyncLocalStorage.run(instance, callback);
26
+ }
27
+ });
28
+ return globalStore[contextKey];
29
+ }
30
+ /**
31
+ * The context store for the session context.
32
+ */
33
+ const sessionContext = createContextStore("session");
34
+ /**
35
+ * The async local storage for the session context.
36
+ */
37
+ const sessionAsyncLocalStorage = sessionContext.asyncLocalStorage;
38
+ /**
39
+ * The function to use the session context.
40
+ *
41
+ * @returns The session context.
42
+ * @throws An error if the session context is not available.
43
+ */
44
+ const useSessionContext = sessionContext.use;
45
+ /**
46
+ * Alias for {@link useSessionContext}.
47
+ */
48
+ const useSession = useSessionContext;
49
+ /**
50
+ * The function to try to use the session context.
51
+ *
52
+ * @returns The session context or undefined if the session context is not available.
53
+ */
54
+ const tryUseSessionContext = sessionContext.tryUse;
55
+ /**
56
+ * Alias for {@link tryUseSessionContext}.
57
+ */
58
+ const tryUseSession = tryUseSessionContext;
59
+ /**
60
+ * The function to call the session context.
61
+ *
62
+ * @param instance - The instance of the session context.
63
+ * @param callback - The callback to call.
64
+ * @returns The result of the callback.
65
+ */
66
+ const callSessionContext = sessionContext.call;
67
+ /**
68
+ * Alias for {@link callSessionContext}.
69
+ */
70
+ const callSession = callSessionContext;
71
+ /**
72
+ * The function to call the session context asynchronously.
73
+ *
74
+ * @param instance - The instance of the session context.
75
+ * @param callback - The callback to call.
76
+ * @returns The result of the callback.
77
+ */
78
+ const callAsyncSessionContext = sessionContext.callAsync;
79
+ /**
80
+ * Alias for {@link callAsyncSessionContext}.
81
+ */
82
+ const callAsyncSession = callAsyncSessionContext;
83
+ /**
84
+ * The context store for the execution context. This is used to store the execution context for a specific execution.
85
+ */
86
+ const executionContext = createContextStore("execution");
87
+ /**
88
+ * The async local storage for the execution context. This is used to store the execution context for a specific execution.
89
+ */
90
+ const executionAsyncLocalStorage = executionContext.asyncLocalStorage;
91
+ /**
92
+ * A hook to allow access to the execution context.
93
+ *
94
+ * @template TSpec - The type of the specification that the generator will produce.
95
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
96
+ * @template TReturns - The type of the returns that the generator will produce.
97
+ * @returns The execution context.
98
+ * @throws An error if the execution context is not available.
99
+ */
100
+ function useExecutionContext() {
101
+ return executionContext.use();
102
+ }
103
+ /**
104
+ * A hook to allow access to the execution context.
105
+ *
106
+ * @remarks
107
+ * Alias for {@link useExecutionContext}.
108
+ *
109
+ * @template TSpec - The type of the specification that the generator will produce.
110
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
111
+ * @template TReturns - The type of the returns that the generator will produce.
112
+ * @returns The execution context.
113
+ * @throws An error if the execution context is not available.
114
+ */
115
+ function useExecution() {
116
+ return useExecutionContext();
117
+ }
118
+ /**
119
+ * A hook to allow access to the execution context.
120
+ *
121
+ * @remarks
122
+ * Alias for {@link useExecutionContext}.
123
+ *
124
+ * @template TSpec - The type of the specification that the generator will produce.
125
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
126
+ * @template TReturns - The type of the returns that the generator will produce.
127
+ * @returns The execution context.
128
+ * @throws An error if the execution context is not available.
129
+ */
130
+ function useContext() {
131
+ return useExecutionContext();
132
+ }
133
+ /**
134
+ * The function to try to use the execution context.
135
+ *
136
+ * @returns The execution context or undefined if the execution context is not available.
137
+ */
138
+ const tryUseExecutionContext = executionContext.tryUse;
139
+ /**
140
+ * Alias for {@link tryUseExecutionContext}.
141
+ */
142
+ const tryUseExecution = tryUseExecutionContext;
143
+ /**
144
+ * The function to call the execution context.
145
+ *
146
+ * @param instance - The instance of the execution context.
147
+ * @param callback - The callback to call.
148
+ * @returns The result of the callback.
149
+ */
150
+ const callExecutionContext = executionContext.call;
151
+ /**
152
+ * Alias for {@link callExecutionContext}.
153
+ */
154
+ const callExecution = callExecutionContext;
155
+ /**
156
+ * The function to call the execution context asynchronously.
157
+ *
158
+ * @param instance - The instance of the execution context.
159
+ * @param callback - The callback to call.
160
+ * @returns The result of the callback.
161
+ */
162
+ const callAsyncExecutionContext = executionContext.callAsync;
163
+ /**
164
+ * Alias for {@link callAsyncExecutionContext}.
165
+ */
166
+ const callAsyncExecution = callAsyncExecutionContext;
167
+
168
+ //#endregion
169
+ exports.callAsyncExecution = callAsyncExecution;
170
+ exports.callAsyncExecutionContext = callAsyncExecutionContext;
171
+ exports.callAsyncSession = callAsyncSession;
172
+ exports.callAsyncSessionContext = callAsyncSessionContext;
173
+ exports.callExecution = callExecution;
174
+ exports.callExecutionContext = callExecutionContext;
175
+ exports.callSession = callSession;
176
+ exports.callSessionContext = callSessionContext;
177
+ exports.executionAsyncLocalStorage = executionAsyncLocalStorage;
178
+ exports.executionContext = executionContext;
179
+ exports.sessionAsyncLocalStorage = sessionAsyncLocalStorage;
180
+ exports.sessionContext = sessionContext;
181
+ exports.tryUseExecution = tryUseExecution;
182
+ exports.tryUseExecutionContext = tryUseExecutionContext;
183
+ exports.tryUseSession = tryUseSession;
184
+ exports.tryUseSessionContext = tryUseSessionContext;
185
+ exports.useContext = useContext;
186
+ exports.useExecution = useExecution;
187
+ exports.useExecutionContext = useExecutionContext;
188
+ exports.useSession = useSession;
189
+ exports.useSessionContext = useSessionContext;
package/dist/context.mjs CHANGED
@@ -1,2 +1,169 @@
1
- import{snakeCase as e}from"@stryke/string-format/snake-case";import{titleCase as t}from"@stryke/string-format/title-case";import{AsyncLocalStorage as n}from"node:async_hooks";const r=globalThis;function i(i){let a=`$$__power_plant_{key}_context__`.replace(`{key}`,e(i.trim().replace(/^[_-]*/g,``).replace(/[_-]*$/g,``)));return r[a]??(r[a]={asyncLocalStorage:new n,use(){let e=this.asyncLocalStorage.getStore();if(e===void 0)throw Error(`The ${t(i.trim().replace(/^[_-]*/g,``).replace(/[_-]*$/g,``))} context is not available. Please ensure that the context has been initialized before using it.`);return e},tryUse(){return this.asyncLocalStorage.getStore()},call(e,t){return this.asyncLocalStorage.run(e,t)},async callAsync(e,t){return this.asyncLocalStorage.run(e,t)}}),r[a]}const a=i(`session`),o=a.asyncLocalStorage,s=a.use,c=s,l=a.tryUse,u=l,d=a.call,f=d,p=a.callAsync,m=p,h=i(`execution`),g=h.asyncLocalStorage;function _(){return h.use()}function v(){return _()}function y(){return _()}const b=h.tryUse,x=b,S=h.call,C=S,w=h.callAsync,T=w;export{T as callAsyncExecution,w as callAsyncExecutionContext,m as callAsyncSession,p as callAsyncSessionContext,C as callExecution,S as callExecutionContext,f as callSession,d as callSessionContext,g as executionAsyncLocalStorage,h as executionContext,o as sessionAsyncLocalStorage,a as sessionContext,x as tryUseExecution,b as tryUseExecutionContext,u as tryUseSession,l as tryUseSessionContext,y as useContext,v as useExecution,_ as useExecutionContext,c as useSession,s as useSessionContext};
1
+ import { snakeCase } from "@stryke/string-format/snake-case";
2
+ import { titleCase } from "@stryke/string-format/title-case";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
+
5
+ //#region src/context.ts
6
+ const globalStore = globalThis;
7
+ const GLOBAL_CONTEXT_KEY = "$$__power_plant_{key}_context__";
8
+ function createContextStore(key) {
9
+ const contextKey = GLOBAL_CONTEXT_KEY.replace("{key}", snakeCase(key.trim().replace(/^[_-]*/g, "").replace(/[_-]*$/g, "")));
10
+ globalStore[contextKey] ?? (globalStore[contextKey] = {
11
+ asyncLocalStorage: new AsyncLocalStorage(),
12
+ use() {
13
+ const instance = this.asyncLocalStorage.getStore();
14
+ if (instance === void 0) throw new Error(`The ${titleCase(key.trim().replace(/^[_-]*/g, "").replace(/[_-]*$/g, ""))} context is not available. Please ensure that the context has been initialized before using it.`);
15
+ return instance;
16
+ },
17
+ tryUse() {
18
+ return this.asyncLocalStorage.getStore();
19
+ },
20
+ call(instance, callback) {
21
+ return this.asyncLocalStorage.run(instance, callback);
22
+ },
23
+ async callAsync(instance, callback) {
24
+ return this.asyncLocalStorage.run(instance, callback);
25
+ }
26
+ });
27
+ return globalStore[contextKey];
28
+ }
29
+ /**
30
+ * The context store for the session context.
31
+ */
32
+ const sessionContext = createContextStore("session");
33
+ /**
34
+ * The async local storage for the session context.
35
+ */
36
+ const sessionAsyncLocalStorage = sessionContext.asyncLocalStorage;
37
+ /**
38
+ * The function to use the session context.
39
+ *
40
+ * @returns The session context.
41
+ * @throws An error if the session context is not available.
42
+ */
43
+ const useSessionContext = sessionContext.use;
44
+ /**
45
+ * Alias for {@link useSessionContext}.
46
+ */
47
+ const useSession = useSessionContext;
48
+ /**
49
+ * The function to try to use the session context.
50
+ *
51
+ * @returns The session context or undefined if the session context is not available.
52
+ */
53
+ const tryUseSessionContext = sessionContext.tryUse;
54
+ /**
55
+ * Alias for {@link tryUseSessionContext}.
56
+ */
57
+ const tryUseSession = tryUseSessionContext;
58
+ /**
59
+ * The function to call the session context.
60
+ *
61
+ * @param instance - The instance of the session context.
62
+ * @param callback - The callback to call.
63
+ * @returns The result of the callback.
64
+ */
65
+ const callSessionContext = sessionContext.call;
66
+ /**
67
+ * Alias for {@link callSessionContext}.
68
+ */
69
+ const callSession = callSessionContext;
70
+ /**
71
+ * The function to call the session context asynchronously.
72
+ *
73
+ * @param instance - The instance of the session context.
74
+ * @param callback - The callback to call.
75
+ * @returns The result of the callback.
76
+ */
77
+ const callAsyncSessionContext = sessionContext.callAsync;
78
+ /**
79
+ * Alias for {@link callAsyncSessionContext}.
80
+ */
81
+ const callAsyncSession = callAsyncSessionContext;
82
+ /**
83
+ * The context store for the execution context. This is used to store the execution context for a specific execution.
84
+ */
85
+ const executionContext = createContextStore("execution");
86
+ /**
87
+ * The async local storage for the execution context. This is used to store the execution context for a specific execution.
88
+ */
89
+ const executionAsyncLocalStorage = executionContext.asyncLocalStorage;
90
+ /**
91
+ * A hook to allow access to the execution context.
92
+ *
93
+ * @template TSpec - The type of the specification that the generator will produce.
94
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
95
+ * @template TReturns - The type of the returns that the generator will produce.
96
+ * @returns The execution context.
97
+ * @throws An error if the execution context is not available.
98
+ */
99
+ function useExecutionContext() {
100
+ return executionContext.use();
101
+ }
102
+ /**
103
+ * A hook to allow access to the execution context.
104
+ *
105
+ * @remarks
106
+ * Alias for {@link useExecutionContext}.
107
+ *
108
+ * @template TSpec - The type of the specification that the generator will produce.
109
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
110
+ * @template TReturns - The type of the returns that the generator will produce.
111
+ * @returns The execution context.
112
+ * @throws An error if the execution context is not available.
113
+ */
114
+ function useExecution() {
115
+ return useExecutionContext();
116
+ }
117
+ /**
118
+ * A hook to allow access to the execution context.
119
+ *
120
+ * @remarks
121
+ * Alias for {@link useExecutionContext}.
122
+ *
123
+ * @template TSpec - The type of the specification that the generator will produce.
124
+ * @template TOptions - The type of the options that will be passed to the generator during generation.
125
+ * @template TReturns - The type of the returns that the generator will produce.
126
+ * @returns The execution context.
127
+ * @throws An error if the execution context is not available.
128
+ */
129
+ function useContext() {
130
+ return useExecutionContext();
131
+ }
132
+ /**
133
+ * The function to try to use the execution context.
134
+ *
135
+ * @returns The execution context or undefined if the execution context is not available.
136
+ */
137
+ const tryUseExecutionContext = executionContext.tryUse;
138
+ /**
139
+ * Alias for {@link tryUseExecutionContext}.
140
+ */
141
+ const tryUseExecution = tryUseExecutionContext;
142
+ /**
143
+ * The function to call the execution context.
144
+ *
145
+ * @param instance - The instance of the execution context.
146
+ * @param callback - The callback to call.
147
+ * @returns The result of the callback.
148
+ */
149
+ const callExecutionContext = executionContext.call;
150
+ /**
151
+ * Alias for {@link callExecutionContext}.
152
+ */
153
+ const callExecution = callExecutionContext;
154
+ /**
155
+ * The function to call the execution context asynchronously.
156
+ *
157
+ * @param instance - The instance of the execution context.
158
+ * @param callback - The callback to call.
159
+ * @returns The result of the callback.
160
+ */
161
+ const callAsyncExecutionContext = executionContext.callAsync;
162
+ /**
163
+ * Alias for {@link callAsyncExecutionContext}.
164
+ */
165
+ const callAsyncExecution = callAsyncExecutionContext;
166
+
167
+ //#endregion
168
+ export { callAsyncExecution, callAsyncExecutionContext, callAsyncSession, callAsyncSessionContext, callExecution, callExecutionContext, callSession, callSessionContext, executionAsyncLocalStorage, executionContext, sessionAsyncLocalStorage, sessionContext, tryUseExecution, tryUseExecutionContext, tryUseSession, tryUseSessionContext, useContext, useExecution, useExecutionContext, useSession, useSessionContext };
2
169
  //# sourceMappingURL=context.mjs.map
package/dist/define.cjs CHANGED
@@ -1 +1,97 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./helpers/type-checks.cjs");function t(t){return e.isInputConfigObject(t)?t:{input:t}}function n(t){return e.isOutputConfigObject(t)?t:{output:t}}function r(t){return e.isSchemaConfigObject(t)?t:{schema:t}}function i(t){if(!e.isGeneratorConfigObject(t))throw TypeError(`An invalid generator configuration was provided - at minimum, a generator function is required.`);return t}exports.defineGenerator=i,exports.defineInput=t,exports.defineOutput=n,exports.defineSchema=r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_helpers_type_checks = require('./helpers/type-checks.cjs');
3
+
4
+ //#region src/define.ts
5
+ /**
6
+ * Defines a input configuration object. If the provided input is already a input configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `input` property.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { defineInput } from "@power-plant/core";
11
+ *
12
+ * // Define a input from a input function
13
+ * export default defineInput((options) => {
14
+ * // Your input logic here
15
+ * });
16
+ *
17
+ * // Define a input from an existing input input object
18
+ * export default defineInput({
19
+ * meta: {
20
+ * name: "My Input",
21
+ * version: "1.0.0",
22
+ * description: "A input that does something.",
23
+ * },
24
+ * schema: z.object({
25
+ * // Your schema definition here
26
+ * }),
27
+ * input: (options) => {
28
+ * // Your input logic here
29
+ * },
30
+ * });
31
+ * ```
32
+ *
33
+ * @param input - The input input to define. This can be either a input input object or a input function.
34
+ * @returns A input input object that contains the provided input. If the input was already a input input object, it will be returned unchanged.
35
+ */
36
+ function defineInput(input) {
37
+ if (require_helpers_type_checks.isInputConfigObject(input)) return input;
38
+ return { input };
39
+ }
40
+ /**
41
+ * Defines a output configuration object. If the provided output is already a output configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `output` property.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { defineOutput } from "@power-plant/core";
46
+ *
47
+ * // Define a output from a output function
48
+ * export default defineOutput((result, spec, options) => {
49
+ * // Your output logic here
50
+ * });
51
+ *
52
+ * // Define a output from an existing output configuration object
53
+ * export default defineOutput({
54
+ * meta: {
55
+ * name: "My Output",
56
+ * version: "1.0.0",
57
+ * description: "A output that does something.",
58
+ * },
59
+ * output: (result, spec, options) => {
60
+ * // Your output logic here
61
+ * },
62
+ * });
63
+ * ```
64
+ *
65
+ * @param output - The output configuration to define. This can be either a output configuration object or a output function.
66
+ * @returns A output configuration object that contains the provided output. If the input was already a output configuration object, it will be returned unchanged.
67
+ */
68
+ function defineOutput(output) {
69
+ if (require_helpers_type_checks.isOutputConfigObject(output)) return output;
70
+ return { output };
71
+ }
72
+ /**
73
+ * Defines a schema configuration object. If the provided schema is already a schema configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `schema` property.
74
+ *
75
+ * @param schema - The schema configuration to define. This can be either a schema source configuration, a schema envelope, or a schema configuration object.
76
+ * @returns A schema configuration object that contains the provided schema. If the input was already a schema configuration object, it will be returned unchanged.
77
+ */
78
+ function defineSchema(schema) {
79
+ if (require_helpers_type_checks.isSchemaConfigObject(schema)) return schema;
80
+ return { schema };
81
+ }
82
+ /**
83
+ * Defines a schema configuration object. If the provided schema is already a schema configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `schema` property.
84
+ *
85
+ * @param generator - The schema configuration to define. This can be either a schema source configuration, a schema envelope, or a schema configuration object.
86
+ * @returns A schema configuration object that contains the provided schema. If the input was already a schema configuration object, it will be returned unchanged.
87
+ */
88
+ function defineGenerator(generator) {
89
+ if (!require_helpers_type_checks.isGeneratorConfigObject(generator)) throw new TypeError("An invalid generator configuration was provided - at minimum, a generator function is required.");
90
+ return generator;
91
+ }
92
+
93
+ //#endregion
94
+ exports.defineGenerator = defineGenerator;
95
+ exports.defineInput = defineInput;
96
+ exports.defineOutput = defineOutput;
97
+ exports.defineSchema = defineSchema;
package/dist/define.mjs CHANGED
@@ -1,2 +1,94 @@
1
- import{isGeneratorConfigObject as e,isInputConfigObject as t,isOutputConfigObject as n,isSchemaConfigObject as r}from"./helpers/type-checks.mjs";function i(e){return t(e)?e:{input:e}}function a(e){return n(e)?e:{output:e}}function o(e){return r(e)?e:{schema:e}}function s(t){if(!e(t))throw TypeError(`An invalid generator configuration was provided - at minimum, a generator function is required.`);return t}export{s as defineGenerator,i as defineInput,a as defineOutput,o as defineSchema};
1
+ import { isGeneratorConfigObject, isInputConfigObject, isOutputConfigObject, isSchemaConfigObject } from "./helpers/type-checks.mjs";
2
+
3
+ //#region src/define.ts
4
+ /**
5
+ * Defines a input configuration object. If the provided input is already a input configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `input` property.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { defineInput } from "@power-plant/core";
10
+ *
11
+ * // Define a input from a input function
12
+ * export default defineInput((options) => {
13
+ * // Your input logic here
14
+ * });
15
+ *
16
+ * // Define a input from an existing input input object
17
+ * export default defineInput({
18
+ * meta: {
19
+ * name: "My Input",
20
+ * version: "1.0.0",
21
+ * description: "A input that does something.",
22
+ * },
23
+ * schema: z.object({
24
+ * // Your schema definition here
25
+ * }),
26
+ * input: (options) => {
27
+ * // Your input logic here
28
+ * },
29
+ * });
30
+ * ```
31
+ *
32
+ * @param input - The input input to define. This can be either a input input object or a input function.
33
+ * @returns A input input object that contains the provided input. If the input was already a input input object, it will be returned unchanged.
34
+ */
35
+ function defineInput(input) {
36
+ if (isInputConfigObject(input)) return input;
37
+ return { input };
38
+ }
39
+ /**
40
+ * Defines a output configuration object. If the provided output is already a output configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `output` property.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { defineOutput } from "@power-plant/core";
45
+ *
46
+ * // Define a output from a output function
47
+ * export default defineOutput((result, spec, options) => {
48
+ * // Your output logic here
49
+ * });
50
+ *
51
+ * // Define a output from an existing output configuration object
52
+ * export default defineOutput({
53
+ * meta: {
54
+ * name: "My Output",
55
+ * version: "1.0.0",
56
+ * description: "A output that does something.",
57
+ * },
58
+ * output: (result, spec, options) => {
59
+ * // Your output logic here
60
+ * },
61
+ * });
62
+ * ```
63
+ *
64
+ * @param output - The output configuration to define. This can be either a output configuration object or a output function.
65
+ * @returns A output configuration object that contains the provided output. If the input was already a output configuration object, it will be returned unchanged.
66
+ */
67
+ function defineOutput(output) {
68
+ if (isOutputConfigObject(output)) return output;
69
+ return { output };
70
+ }
71
+ /**
72
+ * Defines a schema configuration object. If the provided schema is already a schema configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `schema` property.
73
+ *
74
+ * @param schema - The schema configuration to define. This can be either a schema source configuration, a schema envelope, or a schema configuration object.
75
+ * @returns A schema configuration object that contains the provided schema. If the input was already a schema configuration object, it will be returned unchanged.
76
+ */
77
+ function defineSchema(schema) {
78
+ if (isSchemaConfigObject(schema)) return schema;
79
+ return { schema };
80
+ }
81
+ /**
82
+ * Defines a schema configuration object. If the provided schema is already a schema configuration object, it will be returned as-is. Otherwise, it will be wrapped in an object with a `schema` property.
83
+ *
84
+ * @param generator - The schema configuration to define. This can be either a schema source configuration, a schema envelope, or a schema configuration object.
85
+ * @returns A schema configuration object that contains the provided schema. If the input was already a schema configuration object, it will be returned unchanged.
86
+ */
87
+ function defineGenerator(generator) {
88
+ if (!isGeneratorConfigObject(generator)) throw new TypeError("An invalid generator configuration was provided - at minimum, a generator function is required.");
89
+ return generator;
90
+ }
91
+
92
+ //#endregion
93
+ export { defineGenerator, defineInput, defineOutput, defineSchema };
2
94
  //# sourceMappingURL=define.mjs.map