All files / src/clauses namespace.types.ts

91.3% Statements 21/23
100% Branches 0/0
33.33% Functions 1/3
91.3% Lines 21/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84  15x 15x 15x 15x 15x 15x 15x 15x       15x   6x     15x 15x       15x 15x       15x 15x       15x       15x       15x             15x 15x                                                                      
import { or, cat, fclause, shape, zeroOrOne, ExprClause, maybe } from '../core';
import { delayed, isNamespacePath, isClauseRef } from '../utils';
export {isNamespacePath} from "../utils";
import { isObj, isBool, isUndefined } from '../preds';
import isExpr from "../utils/isExpr";
 
const ExprOrPartialRefMapClause =
 // or(
 //  'expression',
  delayed( () => {
    //TODO
    return ExprClause;
  } );
// );
 
export const GetArgClause = cat( 'nsPath', isNamespacePath );
 
export const GetNSFnClause = fclause( {
  args: GetArgClause,
  ret: isClauseRef,
} );
 
export const SetArgClause = cat(
  'nsPath', isNamespacePath,
  'expression', ExprOrPartialRefMapClause );
 
export const SetNSFnClause = fclause( {
  args: SetArgClause,
  ret: isBool,
} );
 
export const NamespaceArgsCLause = or(
  'register', SetArgClause,
  'retrieve', GetArgClause
);
 
export const NamespaceFnClause = fclause( {
  args: NamespaceArgsCLause,
  ret: or( isUndefined, isClauseRef )
} );
 
export const SetMetaFnClause = fclause( {
  args: cat( 'source',
            or(
              'namespacePath', isNamespacePath,
              'expression', ExprClause
            ),
            'metaObj', isObj,
            'registry', zeroOrOne( isObj ) ),
  ret: isUndefined,
} );

export const GetMetaFnClause = fclause( {
  args: cat(
    'source', or(
      'namespacePath', isNamespacePath,
      'expression', ExprClause
    ),
    'registry', zeroOrOne( isObj ) ),
  ret: maybe( isObj )
} );
 
export const ResolveFnClause = fclause( {
  args: cat( 'expression', ExprClause,
            'registry', zeroOrOne( isObj ) ),
  ret: isNamespacePath,
} );
 
export function isNamespaceFragment( x ) {
  return !!/^[^.@%\&\*#]+/.test( x );
}
 
export const NamespaceObjClause = shape( {
  optional: {
    subNamespaces: [ isNamespaceFragment, delayed( () => {
      return NamespaceObjClause;
    } ) ],
    '.meta': isObj,
    '.expr': isExpr,
  }
} );
 
export { isClauseRef };