@seljs/env 1.2.0 → 1.3.0-beta.2

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/builder.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  const require_builtins = require("./builtins.cjs");
2
+ const require_feature_registry = require("./feature-registry.cjs");
2
3
  let _seljs_common = require("@seljs/common");
3
4
  let _seljs_types = require("@seljs/types");
4
5
  //#region src/builder.ts
@@ -206,15 +207,47 @@ const buildSchema = (config) => {
206
207
  seen: /* @__PURE__ */ new Set(),
207
208
  types: []
208
209
  };
209
- return {
210
+ const contracts = Object.entries(config.contracts ?? {}).map(([name, input]) => buildContractSchema(name, input, acc));
211
+ const contextVariables = buildVariablesFromContext(config);
212
+ const contextVariableNames = new Set(contextVariables.map((v) => v.name));
213
+ const featureVariables = [];
214
+ const featureFunctions = [];
215
+ const featureTypes = [];
216
+ const enabledFeatures = [];
217
+ if (config.features) for (const [name, value] of Object.entries(config.features)) {
218
+ if (!value) continue;
219
+ const definition = require_feature_registry.getFeatureDefinition(name);
220
+ if (!definition) continue;
221
+ enabledFeatures.push(name);
222
+ if (definition.variables) {
223
+ for (const variable of definition.variables) if (!contextVariableNames.has(variable.name)) featureVariables.push({
224
+ ...variable,
225
+ feature: name
226
+ });
227
+ }
228
+ if (definition.functions) for (const fn of definition.functions) featureFunctions.push({
229
+ ...fn,
230
+ feature: name
231
+ });
232
+ if (definition.types) for (const type of definition.types) featureTypes.push({
233
+ ...type,
234
+ feature: name
235
+ });
236
+ }
237
+ const schema = {
210
238
  version: "1.0.0",
211
- contracts: Object.entries(config.contracts ?? {}).map(([name, input]) => buildContractSchema(name, input, acc)),
212
- variables: buildVariablesFromContext(config),
213
- types: [...require_builtins.SOLIDITY_PRIMITIVE_TYPES, ...acc.types],
214
- functions: require_builtins.CEL_BUILTIN_FUNCTIONS,
239
+ contracts,
240
+ variables: [...contextVariables, ...featureVariables],
241
+ types: [
242
+ ...require_builtins.SOLIDITY_PRIMITIVE_TYPES,
243
+ ...acc.types,
244
+ ...featureTypes
245
+ ],
246
+ functions: [...require_builtins.CEL_BUILTIN_FUNCTIONS, ...featureFunctions],
215
247
  macros: require_builtins.CEL_BUILTIN_MACROS
216
248
  };
249
+ if (enabledFeatures.length > 0) schema.enabledFeatures = enabledFeatures;
250
+ return schema;
217
251
  };
218
252
  //#endregion
219
253
  exports.buildSchema = buildSchema;
220
- exports.buildStructFields = buildStructFields;
@@ -1,24 +1,8 @@
1
- import { SELSchema } from "@seljs/schema";
1
+ import { SELFeatureConfig, SELSchema } from "@seljs/schema";
2
2
  import { ContextDefinition } from "@seljs/types";
3
- import { AbiParameter } from "abitype";
4
3
  import { Abi, Address } from "viem";
5
4
 
6
5
  //#region src/builder.d.ts
7
- interface StructTypeDefinition {
8
- typeName: string;
9
- fields: Record<string, string>;
10
- }
11
- interface BuildStructFieldsResult {
12
- fields: Record<string, string>;
13
- nestedTypes: StructTypeDefinition[];
14
- }
15
- /**
16
- * Recursively builds struct field definitions.
17
- *
18
- * @param components Array of ABI parameters representing the components of a tuple type.
19
- * @param parentTypeName Name to use for the struct type representing the current level of nesting.
20
- */
21
- declare const buildStructFields: (components: readonly AbiParameter[], parentTypeName: string) => BuildStructFieldsResult;
22
6
  interface ContractInput {
23
7
  address: Address;
24
8
  abi: Abi;
@@ -27,6 +11,7 @@ interface ContractInput {
27
11
  interface SchemaBuilderConfig {
28
12
  contracts?: Record<string, ContractInput>;
29
13
  context?: ContextDefinition;
14
+ features?: SELFeatureConfig;
30
15
  }
31
16
  /**
32
17
  * Builds a SELSchema based on the provided configuration, which includes contract definitions and an optional context for variables.
@@ -36,4 +21,4 @@ interface SchemaBuilderConfig {
36
21
  */
37
22
  declare const buildSchema: (config: SchemaBuilderConfig) => SELSchema;
38
23
  //#endregion
39
- export { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
24
+ export { ContractInput, SchemaBuilderConfig, buildSchema };
@@ -1,24 +1,8 @@
1
1
  import { ContextDefinition } from "@seljs/types";
2
- import { SELSchema } from "@seljs/schema";
3
- import { AbiParameter } from "abitype";
2
+ import { SELFeatureConfig, SELSchema } from "@seljs/schema";
4
3
  import { Abi, Address } from "viem";
5
4
 
6
5
  //#region src/builder.d.ts
7
- interface StructTypeDefinition {
8
- typeName: string;
9
- fields: Record<string, string>;
10
- }
11
- interface BuildStructFieldsResult {
12
- fields: Record<string, string>;
13
- nestedTypes: StructTypeDefinition[];
14
- }
15
- /**
16
- * Recursively builds struct field definitions.
17
- *
18
- * @param components Array of ABI parameters representing the components of a tuple type.
19
- * @param parentTypeName Name to use for the struct type representing the current level of nesting.
20
- */
21
- declare const buildStructFields: (components: readonly AbiParameter[], parentTypeName: string) => BuildStructFieldsResult;
22
6
  interface ContractInput {
23
7
  address: Address;
24
8
  abi: Abi;
@@ -27,6 +11,7 @@ interface ContractInput {
27
11
  interface SchemaBuilderConfig {
28
12
  contracts?: Record<string, ContractInput>;
29
13
  context?: ContextDefinition;
14
+ features?: SELFeatureConfig;
30
15
  }
31
16
  /**
32
17
  * Builds a SELSchema based on the provided configuration, which includes contract definitions and an optional context for variables.
@@ -36,4 +21,4 @@ interface SchemaBuilderConfig {
36
21
  */
37
22
  declare const buildSchema: (config: SchemaBuilderConfig) => SELSchema;
38
23
  //#endregion
39
- export { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
24
+ export { ContractInput, SchemaBuilderConfig, buildSchema };
package/dist/builder.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.mjs";
2
+ import { getFeatureDefinition } from "./feature-registry.mjs";
2
3
  import { structTypeName } from "@seljs/common";
3
4
  import { mapSolidityTypeToCEL } from "@seljs/types";
4
5
  //#region src/builder.ts
@@ -206,14 +207,47 @@ const buildSchema = (config) => {
206
207
  seen: /* @__PURE__ */ new Set(),
207
208
  types: []
208
209
  };
209
- return {
210
+ const contracts = Object.entries(config.contracts ?? {}).map(([name, input]) => buildContractSchema(name, input, acc));
211
+ const contextVariables = buildVariablesFromContext(config);
212
+ const contextVariableNames = new Set(contextVariables.map((v) => v.name));
213
+ const featureVariables = [];
214
+ const featureFunctions = [];
215
+ const featureTypes = [];
216
+ const enabledFeatures = [];
217
+ if (config.features) for (const [name, value] of Object.entries(config.features)) {
218
+ if (!value) continue;
219
+ const definition = getFeatureDefinition(name);
220
+ if (!definition) continue;
221
+ enabledFeatures.push(name);
222
+ if (definition.variables) {
223
+ for (const variable of definition.variables) if (!contextVariableNames.has(variable.name)) featureVariables.push({
224
+ ...variable,
225
+ feature: name
226
+ });
227
+ }
228
+ if (definition.functions) for (const fn of definition.functions) featureFunctions.push({
229
+ ...fn,
230
+ feature: name
231
+ });
232
+ if (definition.types) for (const type of definition.types) featureTypes.push({
233
+ ...type,
234
+ feature: name
235
+ });
236
+ }
237
+ const schema = {
210
238
  version: "1.0.0",
211
- contracts: Object.entries(config.contracts ?? {}).map(([name, input]) => buildContractSchema(name, input, acc)),
212
- variables: buildVariablesFromContext(config),
213
- types: [...SOLIDITY_PRIMITIVE_TYPES, ...acc.types],
214
- functions: CEL_BUILTIN_FUNCTIONS,
239
+ contracts,
240
+ variables: [...contextVariables, ...featureVariables],
241
+ types: [
242
+ ...SOLIDITY_PRIMITIVE_TYPES,
243
+ ...acc.types,
244
+ ...featureTypes
245
+ ],
246
+ functions: [...CEL_BUILTIN_FUNCTIONS, ...featureFunctions],
215
247
  macros: CEL_BUILTIN_MACROS
216
248
  };
249
+ if (enabledFeatures.length > 0) schema.enabledFeatures = enabledFeatures;
250
+ return schema;
217
251
  };
218
252
  //#endregion
219
- export { buildSchema, buildStructFields };
253
+ export { buildSchema };
@@ -0,0 +1,13 @@
1
+ //#region src/feature-registry.ts
2
+ /**
3
+ * Internal registry of known feature definitions.
4
+ * Feature definitions describe what a feature contributes to the schema (variables, functions, types).
5
+ * This registry is NOT exported from the package — it is internal to @seljs/env.
6
+ */
7
+ const FEATURE_REGISTRY = /* @__PURE__ */ new Map();
8
+ /**
9
+ * Retrieves a feature definition by name from the internal registry.
10
+ */
11
+ const getFeatureDefinition = (name) => FEATURE_REGISTRY.get(name);
12
+ //#endregion
13
+ exports.getFeatureDefinition = getFeatureDefinition;
@@ -0,0 +1,13 @@
1
+ //#region src/feature-registry.ts
2
+ /**
3
+ * Internal registry of known feature definitions.
4
+ * Feature definitions describe what a feature contributes to the schema (variables, functions, types).
5
+ * This registry is NOT exported from the package — it is internal to @seljs/env.
6
+ */
7
+ const FEATURE_REGISTRY = /* @__PURE__ */ new Map();
8
+ /**
9
+ * Retrieves a feature definition by name from the internal registry.
10
+ */
11
+ const getFeatureDefinition = (name) => FEATURE_REGISTRY.get(name);
12
+ //#endregion
13
+ export { getFeatureDefinition };
package/dist/index.cjs CHANGED
@@ -5,4 +5,3 @@ exports.CEL_BUILTIN_FUNCTIONS = require_builtins.CEL_BUILTIN_FUNCTIONS;
5
5
  exports.CEL_BUILTIN_MACROS = require_builtins.CEL_BUILTIN_MACROS;
6
6
  exports.SOLIDITY_PRIMITIVE_TYPES = require_builtins.SOLIDITY_PRIMITIVE_TYPES;
7
7
  exports.buildSchema = require_builder.buildSchema;
8
- exports.buildStructFields = require_builder.buildStructFields;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields } from "./builder.cjs";
1
+ import { ContractInput, SchemaBuilderConfig, buildSchema } from "./builder.cjs";
2
2
  import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.cjs";
3
- export { BuildStructFieldsResult, CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
3
+ export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, buildSchema };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { BuildStructFieldsResult, ContractInput, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields } from "./builder.mjs";
1
+ import { ContractInput, SchemaBuilderConfig, buildSchema } from "./builder.mjs";
2
2
  import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.mjs";
3
- export { BuildStructFieldsResult, CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, StructTypeDefinition, buildSchema, buildStructFields };
3
+ export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, ContractInput, SOLIDITY_PRIMITIVE_TYPES, SchemaBuilderConfig, buildSchema };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES } from "./builtins.mjs";
2
- import { buildSchema, buildStructFields } from "./builder.mjs";
3
- export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES, buildSchema, buildStructFields };
2
+ import { buildSchema } from "./builder.mjs";
3
+ export { CEL_BUILTIN_FUNCTIONS, CEL_BUILTIN_MACROS, SOLIDITY_PRIMITIVE_TYPES, buildSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/env",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-beta.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/abinnovision/seljs"
6
6
  },
@@ -48,9 +48,9 @@
48
48
  ]
49
49
  },
50
50
  "dependencies": {
51
- "@seljs/common": "1.2.0",
51
+ "@seljs/common": "1.3.0-beta.2",
52
52
  "@seljs/schema": "1.2.0",
53
- "@seljs/types": "1.2.0",
53
+ "@seljs/types": "1.3.0-beta.2",
54
54
  "abitype": "^1.2.3",
55
55
  "viem": "^2.47.2"
56
56
  },