NodeJs compatibility with didc?

I’m trying to generate js & ts declarations from candid files using didc. While using dfx generate, dfx.json allows a node_compatibility flag to be enabled but I can’t find that option while using didc.

File generated using didc, configuration.did.js:

export const idlFactory = ({ IDL }) => {
  const KnownPrincipalType = IDL.Variant({
    'CanisterIdUserIndex' : IDL.Null,
    'CanisterIdConfiguration' : IDL.Null,
    'CanisterIdProjectMemberIndex' : IDL.Null,
    'CanisterIdTopicCacheIndex' : IDL.Null,
    'CanisterIdRootCanister' : IDL.Null,
    'CanisterIdDataBackup' : IDL.Null,
    'CanisterIdPostCache' : IDL.Null,
    'CanisterIdSNSController' : IDL.Null,
    'UserIdGlobalSuperAdmin' : IDL.Null,
  });
  const Result = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : IDL.Text });
  return IDL.Service({
    'are_signups_enabled' : IDL.Func([], [IDL.Bool], ['query']),
    'get_current_list_of_all_well_known_principal_values' : IDL.Func(
        [],
        [IDL.Vec(IDL.Tuple(KnownPrincipalType, IDL.Principal))],
        ['query'],
      ),
    'get_well_known_principal_value' : IDL.Func(
        [KnownPrincipalType],
        [IDL.Opt(IDL.Principal)],
        ['query'],
      ),
    'toggle_signups_enabled' : IDL.Func([], [Result], []),
    'update_list_of_well_known_principals' : IDL.Func(
        [KnownPrincipalType, IDL.Principal],
        [Result],
        [],
      ),
  });
};
export const init = ({ IDL }) => { return []; };

File generated using dfx_generate, configuration.did.js:

export const idlFactory = ({ IDL }) => {
  const KnownPrincipalType = IDL.Variant({
    'CanisterIdUserIndex' : IDL.Null,
    'CanisterIdConfiguration' : IDL.Null,
    'CanisterIdProjectMemberIndex' : IDL.Null,
    'CanisterIdTopicCacheIndex' : IDL.Null,
    'CanisterIdRootCanister' : IDL.Null,
    'CanisterIdDataBackup' : IDL.Null,
    'CanisterIdPostCache' : IDL.Null,
    'CanisterIdSNSController' : IDL.Null,
    'UserIdGlobalSuperAdmin' : IDL.Null,
  });
  const ConfigurationInitArgs = IDL.Record({
    'known_principal_ids' : IDL.Opt(
      IDL.Vec(IDL.Tuple(KnownPrincipalType, IDL.Principal))
    ),
    'signups_enabled' : IDL.Opt(IDL.Bool),
  });
  const Result = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : IDL.Text });
  return IDL.Service({
    'are_signups_enabled' : IDL.Func([], [IDL.Bool], ['query']),
    'get_current_list_of_all_well_known_principal_values' : IDL.Func(
        [],
        [IDL.Vec(IDL.Tuple(KnownPrincipalType, IDL.Principal))],
        ['query'],
      ),
    'get_well_known_principal_value' : IDL.Func(
        [KnownPrincipalType],
        [IDL.Opt(IDL.Principal)],
        ['query'],
      ),
    'toggle_signups_enabled' : IDL.Func([], [Result], []),
    'update_list_of_well_known_principals' : IDL.Func(
        [KnownPrincipalType, IDL.Principal],
        [Result],
        [],
      ),
  });
};
export const init = ({ IDL }) => {
  const KnownPrincipalType = IDL.Variant({
    'CanisterIdUserIndex' : IDL.Null,
    'CanisterIdConfiguration' : IDL.Null,
    'CanisterIdProjectMemberIndex' : IDL.Null,
    'CanisterIdTopicCacheIndex' : IDL.Null,
    'CanisterIdRootCanister' : IDL.Null,
    'CanisterIdDataBackup' : IDL.Null,
    'CanisterIdPostCache' : IDL.Null,
    'CanisterIdSNSController' : IDL.Null,
    'UserIdGlobalSuperAdmin' : IDL.Null,
  });
  const ConfigurationInitArgs = IDL.Record({
    'known_principal_ids' : IDL.Opt(
      IDL.Vec(IDL.Tuple(KnownPrincipalType, IDL.Principal))
    ),
    'signups_enabled' : IDL.Opt(IDL.Bool),
  });
  return [ConfigurationInitArgs];
};

So, How do I enable node compatibility with didc?

1 Like