@deessejs/functions 0.0.4 → 0.0.6
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/api/index.d.ts +11 -4
- package/dist/api/index.js +17 -32
- package/dist/context/typing.d.ts +6 -6
- package/dist/context/typing.js +26 -28
- package/dist/errors/index.d.ts +1 -1
- package/dist/functions/query.js +1 -2
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
1
|
+
import { z, ZodType } from "zod";
|
|
2
|
+
import { AsyncResult } from "../types";
|
|
3
|
+
export declare const createAPI: <TContext extends Record<string, unknown>>(config: {
|
|
4
|
+
context: TContext;
|
|
5
|
+
}) => {
|
|
6
|
+
readonly context: TContext;
|
|
7
|
+
readonly query: <TArgs extends ZodType, TOutput, TError = Error>(options: {
|
|
8
|
+
args: TArgs;
|
|
9
|
+
handler: (args: z.infer<TArgs>, ctx: TContext) => AsyncResult<TOutput, TError>;
|
|
10
|
+
}) => (input: z.infer<TArgs>) => AsyncResult<TOutput, TError>;
|
|
11
|
+
};
|
package/dist/api/index.js
CHANGED
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
exports.createAPI = void 0;
|
|
4
|
+
const createAPI = (config) => {
|
|
5
|
+
const ctx = { ...config.context };
|
|
6
|
+
const query = (options) => {
|
|
7
|
+
const fn = (input) => {
|
|
8
|
+
const parsed = options.args.safeParse(input);
|
|
9
|
+
if (!parsed.success) {
|
|
10
|
+
return Promise.resolve({ error: parsed.error });
|
|
11
|
+
}
|
|
12
|
+
return options.handler(parsed.data, ctx);
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(fn, "name", {
|
|
15
|
+
value: options.handler.name || "query",
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
let context = { ...config.context };
|
|
19
|
-
const addContext = (key, value) => {
|
|
20
|
-
context = { ...context, [key]: value };
|
|
21
|
-
return api;
|
|
17
|
+
return fn;
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
context,
|
|
25
|
-
|
|
26
|
-
commands: config.commands,
|
|
27
|
-
events: config.events,
|
|
19
|
+
return {
|
|
20
|
+
context: ctx,
|
|
21
|
+
query,
|
|
28
22
|
};
|
|
29
|
-
return api;
|
|
30
23
|
};
|
|
31
24
|
exports.createAPI = createAPI;
|
|
32
|
-
const clearGeneratedContextCache = () => {
|
|
33
|
-
generatedContexts.clear();
|
|
34
|
-
};
|
|
35
|
-
exports.clearGeneratedContextCache = clearGeneratedContextCache;
|
|
36
|
-
const getGeneratedContexts = () => {
|
|
37
|
-
return Array.from(generatedContexts);
|
|
38
|
-
};
|
|
39
|
-
exports.getGeneratedContexts = getGeneratedContexts;
|
package/dist/context/typing.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type AppContext = Record<string, unknown>;
|
|
2
|
-
export declare const getTypedContext: <TContext = AppContext>() => TContext;
|
|
3
|
-
export declare const getSafeTypedContext: <TContext = AppContext>() => TContext | null;
|
|
4
|
-
export declare const assertContextProperty: <K extends string>(key: K) => asserts key is Extract<keyof AppContext, K>;
|
|
5
|
-
export declare const getContextPropertyTyped: <K extends string, T>(key: K) => T | undefined;
|
|
6
|
-
export declare const setContextPropertyTyped: <K extends string, T>(key: K, value: T) => void;
|
|
7
1
|
export type ContextValidator<TContext> = (context: unknown) => context is TContext;
|
|
8
2
|
export declare const createContextValidator: <TContext>(validator: ContextValidator<TContext>) => ContextValidator<TContext>;
|
|
9
3
|
export declare const getValidatedContext: <TContext>(validator: ContextValidator<TContext>) => TContext;
|
|
10
4
|
export declare const assertContextProperties: <TContext extends Record<string, unknown>, TKeys extends readonly (keyof TContext)[]>(keys: TKeys) => asserts keys is TKeys;
|
|
5
|
+
export type AppContext = Record<string, unknown>;
|
|
6
|
+
export declare const getTypedContext: <TContext extends AppContext = AppContext>() => TContext;
|
|
7
|
+
export declare const getSafeTypedContext: <TContext extends AppContext = AppContext>() => TContext | null;
|
|
8
|
+
export declare const assertContextProperty: <K extends keyof AppContext>(key: K) => asserts key is K;
|
|
9
|
+
export declare const getContextPropertyTyped: <K extends keyof AppContext, T>(key: K) => T | undefined;
|
|
10
|
+
export declare const setContextPropertyTyped: <K extends string, T>(key: K, value: T) => void;
|
package/dist/context/typing.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.setContextPropertyTyped = exports.getContextPropertyTyped = exports.assertContextProperty = exports.getSafeTypedContext = exports.getTypedContext = exports.assertContextProperties = exports.getValidatedContext = exports.createContextValidator = void 0;
|
|
4
4
|
const index_1 = require("./index");
|
|
5
|
-
|
|
5
|
+
const createContextValidator = (validator) => {
|
|
6
|
+
return validator;
|
|
7
|
+
};
|
|
8
|
+
exports.createContextValidator = createContextValidator;
|
|
9
|
+
// Generic context access with validation
|
|
10
|
+
const getValidatedContext = (validator) => {
|
|
11
|
+
const context = (0, index_1.getContext)();
|
|
12
|
+
if (validator(context)) {
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
throw new Error("Context validation failed");
|
|
16
|
+
};
|
|
17
|
+
exports.getValidatedContext = getValidatedContext;
|
|
18
|
+
// Utility for partial context validation
|
|
19
|
+
const assertContextProperties = (keys) => {
|
|
20
|
+
const context = (0, index_1.getContext)();
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
if (!(key in context)) {
|
|
23
|
+
throw new Error(`Required context property '${String(key)}' is missing`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.assertContextProperties = assertContextProperties;
|
|
6
28
|
const getTypedContext = () => {
|
|
7
29
|
return (0, index_1.getContext)();
|
|
8
30
|
};
|
|
@@ -32,31 +54,7 @@ exports.getContextPropertyTyped = getContextPropertyTyped;
|
|
|
32
54
|
const setContextPropertyTyped = (key, value) => {
|
|
33
55
|
const context = (0, index_1.getContext)();
|
|
34
56
|
const updatedContext = { ...context, [key]: value };
|
|
35
|
-
// Note:
|
|
36
|
-
// For now, this is a utility that shows how it could work
|
|
37
|
-
// In a real implementation, you might want to pass the context explicitly
|
|
57
|
+
// Note: Update global context as needed
|
|
38
58
|
};
|
|
39
59
|
exports.setContextPropertyTyped = setContextPropertyTyped;
|
|
40
|
-
|
|
41
|
-
return validator;
|
|
42
|
-
};
|
|
43
|
-
exports.createContextValidator = createContextValidator;
|
|
44
|
-
// Generic context access with validation
|
|
45
|
-
const getValidatedContext = (validator) => {
|
|
46
|
-
const context = (0, index_1.getContext)();
|
|
47
|
-
if (validator(context)) {
|
|
48
|
-
return context;
|
|
49
|
-
}
|
|
50
|
-
throw new Error('Context validation failed');
|
|
51
|
-
};
|
|
52
|
-
exports.getValidatedContext = getValidatedContext;
|
|
53
|
-
// Utility for partial context validation
|
|
54
|
-
const assertContextProperties = (keys) => {
|
|
55
|
-
const context = (0, index_1.getContext)();
|
|
56
|
-
for (const key of keys) {
|
|
57
|
-
if (!(key in context)) {
|
|
58
|
-
throw new Error(`Required context property '${String(key)}' is missing`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.assertContextProperties = assertContextProperties;
|
|
60
|
+
// Other utilities (validator, etc.) remain unchanged...
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Exception, ExceptionConfig, ExceptionSpaceConfig, ExceptionGroup } from
|
|
|
2
2
|
export declare const exception: (config: ExceptionConfig) => Exception;
|
|
3
3
|
export declare const exceptionSpace: (space: ExceptionSpaceConfig) => {
|
|
4
4
|
define: (config: Omit<ExceptionConfig, "namespace">) => Exception;
|
|
5
|
-
severity: "
|
|
5
|
+
severity: "info" | "warning" | "error" | "critical";
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
8
|
export declare const raise: (exception: Exception) => Exception;
|
package/dist/functions/query.js
CHANGED
|
@@ -12,7 +12,6 @@ function query(options) {
|
|
|
12
12
|
const parsed = (0, parse_1.parseArgs)(options.args, input);
|
|
13
13
|
return parsed.match({
|
|
14
14
|
onSuccess: (data) => {
|
|
15
|
-
// If context is provided, use it; otherwise get from global context
|
|
16
15
|
const ctx = context ?? (0, typing_1.getTypedContext)();
|
|
17
16
|
return options.handler(data, ctx);
|
|
18
17
|
},
|
|
@@ -26,7 +25,7 @@ function query(options) {
|
|
|
26
25
|
});
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
|
-
// Query builder
|
|
28
|
+
// Query builder
|
|
30
29
|
const createQuery = () => {
|
|
31
30
|
return (options) => {
|
|
32
31
|
return query(options);
|
package/package.json
CHANGED