@deessejs/functions 0.0.4 → 0.0.5

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.
@@ -1,4 +1,2 @@
1
1
  import { API, APIConfig } from "./types";
2
2
  export declare const createAPI: <TContext extends Record<string, unknown>>(config: APIConfig<TContext>, contextName?: string) => API<TContext>;
3
- export declare const clearGeneratedContextCache: () => void;
4
- export declare const getGeneratedContexts: () => string[];
package/dist/api/index.js CHANGED
@@ -1,20 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGeneratedContexts = exports.clearGeneratedContextCache = exports.createAPI = void 0;
4
- const generator_1 = require("../context/generator");
5
- // Cache pour éviter de générer plusieurs fois le même contexte
6
- const generatedContexts = new Set();
3
+ exports.createAPI = void 0;
7
4
  const createAPI = (config, contextName = 'App') => {
8
- // Générer les types de contexte si ce n'est pas déjà fait
9
- if (!generatedContexts.has(contextName)) {
10
- (0, generator_1.generateContextDeclarationFile)(contextName, config.context)
11
- .then(() => {
12
- generatedContexts.add(contextName);
13
- })
14
- .catch((error) => {
15
- console.error(`Failed to generate context types for ${contextName}:`, error);
16
- });
17
- }
18
5
  let context = { ...config.context };
19
6
  const addContext = (key, value) => {
20
7
  context = { ...context, [key]: value };
@@ -29,11 +16,3 @@ const createAPI = (config, contextName = 'App') => {
29
16
  return api;
30
17
  };
31
18
  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;
@@ -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;
@@ -1,8 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertContextProperties = exports.getValidatedContext = exports.createContextValidator = exports.setContextPropertyTyped = exports.getContextPropertyTyped = exports.assertContextProperty = exports.getSafeTypedContext = exports.getTypedContext = void 0;
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
- // Type utilities for context access
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: This would require updating the global context
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
- const createContextValidator = (validator) => {
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...
@@ -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 with strong typing
28
+ // Query builder
30
29
  const createQuery = () => {
31
30
  return (options) => {
32
31
  return query(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/functions",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "A powerful utility library for building type-safe APIs and functions with context management",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",